@@ -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}
@@ -251,6 +259,10 @@ lltok::Kind LLLexer::LexToken() {
251259 case ' ,' : return lltok::comma;
252260 case ' *' : return lltok::star;
253261 case ' |' : return lltok::bar;
262+ case ' /' :
263+ if (peekNextChar () == ' *' && SkipCComment ())
264+ return lltok::Error;
265+ continue ;
254266 }
255267 }
256268}
@@ -262,6 +274,26 @@ void LLLexer::SkipLineComment() {
262274 }
263275}
264276
277+ // / SkipCComment - This skips C-style /**/ comments.
278+ bool LLLexer::SkipCComment () {
279+ getNextChar (); // skip the star.
280+
281+ while (true ) {
282+ int CurChar = getNextChar ();
283+ switch (CurChar) {
284+ case EOF:
285+ LexError (" unterminated comment" );
286+ return true ;
287+ case ' *' :
288+ // End of the comment?
289+ if (peekNextChar () == ' /' ) {
290+ getNextChar (); // Eat the '/'.
291+ return false ;
292+ }
293+ }
294+ }
295+ }
296+
265297// / Lex all tokens that start with an @ character.
266298// / GlobalVar @\"[^\"]*\"
267299// / GlobalVar @[-a-zA-Z$._][-a-zA-Z$._0-9]*
0 commit comments