OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / shared / cplusplus / ObjectiveCAtKeywords.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #include "Lexer.h"
35 #include "Token.h"
36
37 using namespace CPlusPlus;
38
39 static inline int classify3(const char *s) {
40   if (s[0] == 'e') {
41     if (s[1] == 'n') {
42       if (s[2] == 'd') {
43         return T_AT_END;
44       }
45     }
46   }
47   else if (s[0] == 't') {
48     if (s[1] == 'r') {
49       if (s[2] == 'y') {
50         return T_AT_TRY;
51       }
52     }
53   }
54   return T_ERROR;
55 }
56
57 static inline int classify4(const char *s) {
58   if (s[0] == 'd') {
59     if (s[1] == 'e') {
60       if (s[2] == 'f') {
61         if (s[3] == 's') {
62           return T_AT_DEFS;
63         }
64       }
65     }
66   }
67   return T_ERROR;
68 }
69
70 static inline int classify5(const char *s) {
71   if (s[0] == 'c') {
72     if (s[1] == 'a') {
73       if (s[2] == 't') {
74         if (s[3] == 'c') {
75           if (s[4] == 'h') {
76             return T_AT_CATCH;
77           }
78         }
79       }
80     }
81     else if (s[1] == 'l') {
82       if (s[2] == 'a') {
83         if (s[3] == 's') {
84           if (s[4] == 's') {
85             return T_AT_CLASS;
86           }
87         }
88       }
89     }
90   }
91   else if (s[0] == 't') {
92     if (s[1] == 'h') {
93       if (s[2] == 'r') {
94         if (s[3] == 'o') {
95           if (s[4] == 'w') {
96             return T_AT_THROW;
97           }
98         }
99       }
100     }
101   }
102   return T_ERROR;
103 }
104
105 static inline int classify6(const char *s) {
106   if (s[0] == 'e') {
107     if (s[1] == 'n') {
108       if (s[2] == 'c') {
109         if (s[3] == 'o') {
110           if (s[4] == 'd') {
111             if (s[5] == 'e') {
112               return T_AT_ENCODE;
113             }
114           }
115         }
116       }
117     }
118   }
119   else if (s[0] == 'p') {
120     if (s[1] == 'u') {
121       if (s[2] == 'b') {
122         if (s[3] == 'l') {
123           if (s[4] == 'i') {
124             if (s[5] == 'c') {
125               return T_AT_PUBLIC;
126             }
127           }
128         }
129       }
130     }
131   }
132   return T_ERROR;
133 }
134
135 static inline int classify7(const char *s) {
136   if (s[0] == 'd') {
137     if (s[1] == 'y') {
138       if (s[2] == 'n') {
139         if (s[3] == 'a') {
140           if (s[4] == 'm') {
141             if (s[5] == 'i') {
142               if (s[6] == 'c') {
143                 return T_AT_DYNAMIC;
144               }
145             }
146           }
147         }
148       }
149     }
150   }
151   else if (s[0] == 'f') {
152     if (s[1] == 'i') {
153       if (s[2] == 'n') {
154         if (s[3] == 'a') {
155           if (s[4] == 'l') {
156             if (s[5] == 'l') {
157               if (s[6] == 'y') {
158                 return T_AT_FINALLY;
159               }
160             }
161           }
162         }
163       }
164     }
165   }
166   else if (s[0] == 'p') {
167     if (s[1] == 'a') {
168       if (s[2] == 'c') {
169         if (s[3] == 'k') {
170           if (s[4] == 'a') {
171             if (s[5] == 'g') {
172               if (s[6] == 'e') {
173                 return T_AT_PACKAGE;
174               }
175             }
176           }
177         }
178       }
179     }
180     else if (s[1] == 'r') {
181       if (s[2] == 'i') {
182         if (s[3] == 'v') {
183           if (s[4] == 'a') {
184             if (s[5] == 't') {
185               if (s[6] == 'e') {
186                 return T_AT_PRIVATE;
187               }
188             }
189           }
190         }
191       }
192     }
193   }
194   return T_ERROR;
195 }
196
197 static inline int classify8(const char *s) {
198   if (s[0] == 'o') {
199     if (s[1] == 'p') {
200       if (s[2] == 't') {
201         if (s[3] == 'i') {
202           if (s[4] == 'o') {
203             if (s[5] == 'n') {
204               if (s[6] == 'a') {
205                 if (s[7] == 'l') {
206                   return T_AT_OPTIONAL;
207                 }
208               }
209             }
210           }
211         }
212       }
213     }
214   }
215   else if (s[0] == 'p') {
216     if (s[1] == 'r') {
217       if (s[2] == 'o') {
218         if (s[3] == 'p') {
219           if (s[4] == 'e') {
220             if (s[5] == 'r') {
221               if (s[6] == 't') {
222                 if (s[7] == 'y') {
223                   return T_AT_PROPERTY;
224                 }
225               }
226             }
227           }
228         }
229         else if (s[3] == 't') {
230           if (s[4] == 'o') {
231             if (s[5] == 'c') {
232               if (s[6] == 'o') {
233                 if (s[7] == 'l') {
234                   return T_AT_PROTOCOL;
235                 }
236               }
237             }
238           }
239         }
240       }
241     }
242   }
243   else if (s[0] == 'r') {
244     if (s[1] == 'e') {
245       if (s[2] == 'q') {
246         if (s[3] == 'u') {
247           if (s[4] == 'i') {
248             if (s[5] == 'r') {
249               if (s[6] == 'e') {
250                 if (s[7] == 'd') {
251                   return T_AT_REQUIRED;
252                 }
253               }
254             }
255           }
256         }
257       }
258     }
259   }
260   else if (s[0] == 's') {
261     if (s[1] == 'e') {
262       if (s[2] == 'l') {
263         if (s[3] == 'e') {
264           if (s[4] == 'c') {
265             if (s[5] == 't') {
266               if (s[6] == 'o') {
267                 if (s[7] == 'r') {
268                   return T_AT_SELECTOR;
269                 }
270               }
271             }
272           }
273         }
274       }
275     }
276   }
277   return T_ERROR;
278 }
279
280 static inline int classify9(const char *s) {
281   if (s[0] == 'i') {
282     if (s[1] == 'n') {
283       if (s[2] == 't') {
284         if (s[3] == 'e') {
285           if (s[4] == 'r') {
286             if (s[5] == 'f') {
287               if (s[6] == 'a') {
288                 if (s[7] == 'c') {
289                   if (s[8] == 'e') {
290                     return T_AT_INTERFACE;
291                   }
292                 }
293               }
294             }
295           }
296         }
297       }
298     }
299   }
300   else if (s[0] == 'p') {
301     if (s[1] == 'r') {
302       if (s[2] == 'o') {
303         if (s[3] == 't') {
304           if (s[4] == 'e') {
305             if (s[5] == 'c') {
306               if (s[6] == 't') {
307                 if (s[7] == 'e') {
308                   if (s[8] == 'd') {
309                     return T_AT_PROTECTED;
310                   }
311                 }
312               }
313             }
314           }
315         }
316       }
317     }
318   }
319   return T_ERROR;
320 }
321
322 static inline int classify10(const char *s) {
323   if (s[0] == 's') {
324     if (s[1] == 'y') {
325       if (s[2] == 'n') {
326         if (s[3] == 't') {
327           if (s[4] == 'h') {
328             if (s[5] == 'e') {
329               if (s[6] == 's') {
330                 if (s[7] == 'i') {
331                   if (s[8] == 'z') {
332                     if (s[9] == 'e') {
333                       return T_AT_SYNTHESIZE;
334                     }
335                   }
336                 }
337               }
338             }
339           }
340         }
341       }
342     }
343   }
344   return T_ERROR;
345 }
346
347 static inline int classify11(const char *s) {
348   if (s[0] == 'n') {
349     if (s[1] == 'o') {
350       if (s[2] == 't') {
351         if (s[3] == '_') {
352           if (s[4] == 'k') {
353             if (s[5] == 'e') {
354               if (s[6] == 'y') {
355                 if (s[7] == 'w') {
356                   if (s[8] == 'o') {
357                     if (s[9] == 'r') {
358                       if (s[10] == 'd') {
359                         return T_AT_NOT_KEYWORD;
360                       }
361                     }
362                   }
363                 }
364               }
365             }
366           }
367         }
368       }
369     }
370   }
371   return T_ERROR;
372 }
373
374 static inline int classify12(const char *s) {
375   if (s[0] == 's') {
376     if (s[1] == 'y') {
377       if (s[2] == 'n') {
378         if (s[3] == 'c') {
379           if (s[4] == 'h') {
380             if (s[5] == 'r') {
381               if (s[6] == 'o') {
382                 if (s[7] == 'n') {
383                   if (s[8] == 'i') {
384                     if (s[9] == 'z') {
385                       if (s[10] == 'e') {
386                         if (s[11] == 'd') {
387                           return T_AT_SYNCHRONIZED;
388                         }
389                       }
390                     }
391                   }
392                 }
393               }
394             }
395           }
396         }
397       }
398     }
399   }
400   return T_ERROR;
401 }
402
403 static inline int classify14(const char *s) {
404   if (s[0] == 'i') {
405     if (s[1] == 'm') {
406       if (s[2] == 'p') {
407         if (s[3] == 'l') {
408           if (s[4] == 'e') {
409             if (s[5] == 'm') {
410               if (s[6] == 'e') {
411                 if (s[7] == 'n') {
412                   if (s[8] == 't') {
413                     if (s[9] == 'a') {
414                       if (s[10] == 't') {
415                         if (s[11] == 'i') {
416                           if (s[12] == 'o') {
417                             if (s[13] == 'n') {
418                               return T_AT_IMPLEMENTATION;
419                             }
420                           }
421                         }
422                       }
423                     }
424                   }
425                 }
426               }
427             }
428           }
429         }
430       }
431     }
432   }
433   return T_ERROR;
434 }
435
436 static inline int classify19(const char *s) {
437   if (s[0] == 'c') {
438     if (s[1] == 'o') {
439       if (s[2] == 'm') {
440         if (s[3] == 'p') {
441           if (s[4] == 'a') {
442             if (s[5] == 't') {
443               if (s[6] == 'i') {
444                 if (s[7] == 'b') {
445                   if (s[8] == 'i') {
446                     if (s[9] == 'l') {
447                       if (s[10] == 'i') {
448                         if (s[11] == 't') {
449                           if (s[12] == 'y') {
450                             if (s[13] == '_') {
451                               if (s[14] == 'a') {
452                                 if (s[15] == 'l') {
453                                   if (s[16] == 'i') {
454                                     if (s[17] == 'a') {
455                                       if (s[18] == 's') {
456                                         return T_AT_COMPATIBILITY_ALIAS;
457                                       }
458                                     }
459                                   }
460                                 }
461                               }
462                             }
463                           }
464                         }
465                       }
466                     }
467                   }
468                 }
469               }
470             }
471           }
472         }
473       }
474     }
475   }
476   return T_ERROR;
477 }
478
479 int Lexer::classifyObjCAtKeyword(const char *s, int n) {
480   switch (n) {
481     case 3: return classify3(s);
482     case 4: return classify4(s);
483     case 5: return classify5(s);
484     case 6: return classify6(s);
485     case 7: return classify7(s);
486     case 8: return classify8(s);
487     case 9: return classify9(s);
488     case 10: return classify10(s);
489     case 11: return classify11(s);
490     case 12: return classify12(s);
491     case 14: return classify14(s);
492     case 19: return classify19(s);
493     default: return T_ERROR;
494   } // switch
495 }