@@ -175,17 +175,25 @@ LLLexer::LLLexer(StringRef StartBuf, SourceMgr &SM, SMDiagnostic &Err,
175175}
176176
177177int LLLexer::getNextChar () {
178- char CurChar = *CurPtr++;
178+ int NextChar = peekNextChar ();
179+ // Keeping CurPtr unchanged at EOF, so that another call to `getNextChar`
180+ // returns EOF again.
181+ if (NextChar != EOF)
182+ ++CurPtr;
183+ return NextChar;
184+ }
185+
186+ int LLLexer::peekNextChar () const {
187+ char CurChar = *CurPtr;
179188 switch (CurChar) {
180189 default : return (unsigned char )CurChar;
181190 case 0 :
182191 // A nul character in the stream is either the end of the current buffer or
183192 // a random nul in the file. Disambiguate that here.
184- if (CurPtr- 1 != CurBuf.end ())
193+ if (CurPtr != CurBuf.end ())
185194 return 0 ; // Just whitespace.
186195
187196 // Otherwise, return end of file.
188- --CurPtr; // Another call to lex will return EOF again.
189197 return EOF;
190198 }
191199}
@@ -200,7 +208,6 @@ lltok::Kind LLLexer::LexToken() {
200208 // Handle letters: [a-zA-Z_]
201209 if (isalpha (static_cast <unsigned char >(CurChar)) || CurChar == ' _' )
202210 return LexIdentifier ();
203-
204211 return lltok::Error;
205212 case EOF: return lltok::Eof;
206213 case 0 :
@@ -251,6 +258,12 @@ lltok::Kind LLLexer::LexToken() {
251258 case ' ,' : return lltok::comma;
252259 case ' *' : return lltok::star;
253260 case ' |' : return lltok::bar;
261+ case ' /' :
262+ if (peekNextChar () != ' *' )
263+ return lltok::Error;
264+ if (SkipCComment ())
265+ return lltok::Error;
266+ continue ;
254267 }
255268 }
256269}
@@ -262,6 +275,27 @@ void LLLexer::SkipLineComment() {
262275 }
263276}
264277
278+ // / SkipCComment - This skips C-style /**/ comments. Returns true if there
279+ // / was an error.
280+ bool LLLexer::SkipCComment () {
281+ getNextChar (); // skip the star.
282+
283+ while (true ) {
284+ int CurChar = getNextChar ();
285+ switch (CurChar) {
286+ case EOF:
287+ LexError (" unterminated comment" );
288+ return true ;
289+ case ' *' :
290+ // End of the comment?
291+ if (peekNextChar () == ' /' ) {
292+ getNextChar (); // Eat the '/'.
293+ return false ;
294+ }
295+ }
296+ }
297+ }
298+
265299// / Lex all tokens that start with an @ character.
266300// / GlobalVar @\"[^\"]*\"
267301// / GlobalVar @[-a-zA-Z$._][-a-zA-Z$._0-9]*
0 commit comments