OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / shared / cplusplus / QtContextKeywords.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 (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #include "QtContextKeywords.h"
34
35 using namespace CPlusPlus;
36
37 static inline int classify4(const char *s) {
38   if (s[0] == 'R') {
39     if (s[1] == 'E') {
40       if (s[2] == 'A') {
41         if (s[3] == 'D') {
42           return Token_READ;
43         }
44       }
45     }
46   }
47   else if (s[0] == 'U') {
48     if (s[1] == 'S') {
49       if (s[2] == 'E') {
50         if (s[3] == 'R') {
51           return Token_USER;
52         }
53       }
54     }
55   }
56   return Token_not_Qt_context_keyword;
57 }
58
59 static inline int classify5(const char *s) {
60   if (s[0] == 'F') {
61     if (s[1] == 'I') {
62       if (s[2] == 'N') {
63         if (s[3] == 'A') {
64           if (s[4] == 'L') {
65             return Token_FINAL;
66           }
67         }
68       }
69     }
70   }
71   else if (s[0] == 'R') {
72     if (s[1] == 'E') {
73       if (s[2] == 'S') {
74         if (s[3] == 'E') {
75           if (s[4] == 'T') {
76             return Token_RESET;
77           }
78         }
79       }
80     }
81   }
82   else if (s[0] == 'W') {
83     if (s[1] == 'R') {
84       if (s[2] == 'I') {
85         if (s[3] == 'T') {
86           if (s[4] == 'E') {
87             return Token_WRITE;
88           }
89         }
90       }
91     }
92   }
93   return Token_not_Qt_context_keyword;
94 }
95
96 static inline int classify6(const char *s) {
97   if (s[0] == 'N') {
98     if (s[1] == 'O') {
99       if (s[2] == 'T') {
100         if (s[3] == 'I') {
101           if (s[4] == 'F') {
102             if (s[5] == 'Y') {
103               return Token_NOTIFY;
104             }
105           }
106         }
107       }
108     }
109   }
110   else if (s[0] == 'S') {
111     if (s[1] == 'T') {
112       if (s[2] == 'O') {
113         if (s[3] == 'R') {
114           if (s[4] == 'E') {
115             if (s[5] == 'D') {
116               return Token_STORED;
117             }
118           }
119         }
120       }
121     }
122   }
123   return Token_not_Qt_context_keyword;
124 }
125
126 static inline int classify8(const char *s) {
127   if (s[0] == 'C') {
128     if (s[1] == 'O') {
129       if (s[2] == 'N') {
130         if (s[3] == 'S') {
131           if (s[4] == 'T') {
132             if (s[5] == 'A') {
133               if (s[6] == 'N') {
134                 if (s[7] == 'T') {
135                   return Token_CONSTANT;
136                 }
137               }
138             }
139           }
140         }
141       }
142     }
143   }
144   return Token_not_Qt_context_keyword;
145 }
146
147 static inline int classify10(const char *s) {
148   if (s[0] == 'D') {
149     if (s[1] == 'E') {
150       if (s[2] == 'S') {
151         if (s[3] == 'I') {
152           if (s[4] == 'G') {
153             if (s[5] == 'N') {
154               if (s[6] == 'A') {
155                 if (s[7] == 'B') {
156                   if (s[8] == 'L') {
157                     if (s[9] == 'E') {
158                       return Token_DESIGNABLE;
159                     }
160                   }
161                 }
162               }
163             }
164           }
165         }
166       }
167     }
168   }
169   else if (s[0] == 'S') {
170     if (s[1] == 'C') {
171       if (s[2] == 'R') {
172         if (s[3] == 'I') {
173           if (s[4] == 'P') {
174             if (s[5] == 'T') {
175               if (s[6] == 'A') {
176                 if (s[7] == 'B') {
177                   if (s[8] == 'L') {
178                     if (s[9] == 'E') {
179                       return Token_SCRIPTABLE;
180                     }
181                   }
182                 }
183               }
184             }
185           }
186         }
187       }
188     }
189   }
190   return Token_not_Qt_context_keyword;
191 }
192
193 int CPlusPlus::classifyQtContextKeyword(const char *s, int n) {
194   switch (n) {
195     case 4: return classify4(s);
196     case 5: return classify5(s);
197     case 6: return classify6(s);
198     case 8: return classify8(s);
199     case 10: return classify10(s);
200     default: return Token_not_Qt_context_keyword;
201   } // switch
202 }