@@ -108,69 +108,112 @@ class TextTokenRetokenizer {
108
108
}
109
109
}
110
110
111
+ bool continueInt (SmallString<32 > &NextToken) {
112
+ return NextToken.ends_with (StringRef (" char" )) ||
113
+ NextToken.ends_with (StringRef (" int" )) ||
114
+ NextToken.ends_with (StringRef (" char*" )) ||
115
+ NextToken.ends_with (StringRef (" int*" )) ||
116
+ NextToken.ends_with (StringRef (" char&" )) ||
117
+ NextToken.ends_with (StringRef (" int&" ));
118
+ }
119
+
120
+ bool lexInt (SmallString<32 > &WordText, SmallString<32 > &NextToken) {
121
+ unsigned LongCounter = (WordText.ends_with (StringRef (" long" ))) ? 1 : 0 ;
122
+ bool complete = false ;
123
+
124
+ while (!isEnd ()) {
125
+ const char C = peek ();
126
+ if (!isWhitespace (C)) {
127
+ WordText.push_back (C);
128
+ consumeChar ();
129
+ } else {
130
+
131
+ NextToken.clear ();
132
+ peekNextToken (NextToken);
133
+
134
+ if (WordText.ends_with (StringRef (" long" ))) {
135
+ LongCounter++;
136
+ if (continueInt (NextToken)) {
137
+ WordText.push_back (C);
138
+ consumeChar ();
139
+ complete = true ;
140
+ continue ;
141
+ } else {
142
+ if (LongCounter == 2 ) {
143
+ return true ;
144
+ }
145
+ }
146
+ } else {
147
+
148
+ if (complete || continueInt (WordText)) {
149
+ return true ;
150
+ }
151
+ }
152
+
153
+ if (NextToken.ends_with (StringRef (" long" ))) {
154
+ WordText.push_back (C);
155
+ consumeChar ();
156
+ } else {
157
+ return true ;
158
+ }
159
+ }
160
+ }
161
+
162
+ return false ;
163
+ }
164
+
111
165
// / Extract a template type
112
- bool lexTemplateType (SmallString<32 > &WordText) {
166
+ bool lexTemplate (SmallString<32 > &WordText) {
113
167
unsigned IncrementCounter = 0 ;
114
168
while (!isEnd ()) {
115
169
const char C = peek ();
116
170
WordText.push_back (C);
117
171
consumeChar ();
118
172
switch (C) {
119
- default :
120
- break ;
121
173
case ' <' : {
122
174
IncrementCounter++;
123
- } break ;
175
+ break ;
176
+ }
124
177
case ' >' : {
125
178
IncrementCounter--;
126
179
if (!IncrementCounter)
127
180
return true ;
128
- } break ;
181
+ break ;
182
+ }
183
+ default :
184
+ break ;
129
185
}
130
186
}
131
187
return false ;
132
188
}
133
189
134
- bool isDataTypeQualifier (SmallString<32 > &WordText) {
135
- if (WordText.ends_with (StringRef (" const" )))
136
- return true ;
137
- if (WordText.ends_with (StringRef (" volatile" )))
138
- return true ;
139
- if (WordText.ends_with (StringRef (" unsigned" )))
140
- return true ;
141
- if (WordText.ends_with (StringRef (" signed" )))
142
- return true ;
143
- if (WordText.ends_with (StringRef (" long" )))
144
- return true ;
145
- if (WordText.ends_with (StringRef (" short" )))
146
- return true ;
147
- if (WordText.ends_with (StringRef (" restrict" )))
148
- return true ;
149
- if (WordText.ends_with (StringRef (" auto" )))
150
- return true ;
151
- if (WordText.ends_with (StringRef (" register" )))
152
- return true ;
153
- if (WordText.ends_with (StringRef (" static" )))
154
- return true ;
155
- if (WordText.ends_with (StringRef (" extern" )))
156
- return true ;
157
- if (WordText.ends_with (StringRef (" struct" )))
158
- return true ;
159
- if (WordText.ends_with (StringRef (" typedef" )))
160
- return true ;
161
- if (WordText.ends_with (StringRef (" union" )))
162
- return true ;
163
- if (WordText.ends_with (StringRef (" void" )))
164
- return true ;
165
- return false ;
190
+ bool isTypeQualifier (SmallString<32 > &WordText) {
191
+ return WordText.ends_with (StringRef (" const" )) ||
192
+ WordText.ends_with (StringRef (" volatile" )) ||
193
+ WordText.ends_with (StringRef (" short" )) ||
194
+ WordText.ends_with (StringRef (" restrict" )) ||
195
+ WordText.ends_with (StringRef (" auto" )) ||
196
+ WordText.ends_with (StringRef (" register" )) ||
197
+ WordText.ends_with (StringRef (" static" )) ||
198
+ WordText.ends_with (StringRef (" extern" )) ||
199
+ WordText.ends_with (StringRef (" struct" )) ||
200
+ WordText.ends_with (StringRef (" typedef" )) ||
201
+ WordText.ends_with (StringRef (" union" )) ||
202
+ WordText.ends_with (StringRef (" void" ));
166
203
}
167
204
168
205
bool isScopeResolutionOperator (SmallString<32 > &WordText) {
169
206
return WordText.ends_with (StringRef (" ::" ));
170
207
}
171
208
209
+ bool isInt (SmallString<32 > &WordText) {
210
+ return WordText.ends_with (StringRef (" unsigned" )) ||
211
+ WordText.ends_with (StringRef (" long" )) ||
212
+ WordText.ends_with (StringRef (" signed" ));
213
+ }
214
+
172
215
bool continueParsing (SmallString<32 > &WordText) {
173
- return isDataTypeQualifier (WordText) || isScopeResolutionOperator (WordText);
216
+ return isTypeQualifier (WordText) || isScopeResolutionOperator (WordText);
174
217
}
175
218
176
219
// / Add a token.
@@ -252,7 +295,7 @@ class TextTokenRetokenizer {
252
295
const char C = peek ();
253
296
if (!isWhitespace (C)) {
254
297
if (C == ' <' ) {
255
- if (!lexTemplateType (WordText))
298
+ if (!lexTemplate (WordText))
256
299
return false ;
257
300
} else {
258
301
WordText.push_back (C);
@@ -263,6 +306,12 @@ class TextTokenRetokenizer {
263
306
consumeChar ();
264
307
break ;
265
308
} else {
309
+ if (isInt (WordText)) {
310
+ WordText.push_back (C);
311
+ consumeChar ();
312
+ if (!lexInt (WordText, NextToken))
313
+ return false ;
314
+ }
266
315
if (continueParsing (WordText)) {
267
316
WordText.push_back (C);
268
317
consumeChar ();
0 commit comments