comparison clang/lib/Lex/Preprocessor.cpp @ 200:40b1cab18437

swap CurLexer
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Fri, 04 Jun 2021 20:14:29 +0900
parents 5784c86f13b3
children a96fbbdf2d0f
comparison
equal deleted inserted replaced
199:5784c86f13b3 200:40b1cab18437
1438 Token Preprocessor::ReadFromString(const char *src , SourceLocation Loc) { 1438 Token Preprocessor::ReadFromString(const char *src , SourceLocation Loc) {
1439 // Push the ( "string" ) tokens into the token stream. 1439 // Push the ( "string" ) tokens into the token stream.
1440 MacroInfo *MI = AllocateMacroInfo(Loc); 1440 MacroInfo *MI = AllocateMacroInfo(Loc);
1441 Token Tok,FirstTok,Result; 1441 Token Tok,FirstTok,Result;
1442 bool Invalid = false; 1442 bool Invalid = false;
1443 Lexer lx(CurLexer->getFileID(),getSourceManager().getBuffer(CurLexer->getFileID(), Loc, &Invalid),*this); 1443 std::unique_ptr<Lexer> lx(new Lexer(CurLexer->getFileID(),getSourceManager().getBuffer(CurLexer->getFileID(), Loc, &Invalid),*this));
1444 lx.InitLexer(src,src,src + strlen(src)); 1444 lx->InitLexer(src,src,src + strlen(src));
1445 lx.ParsingPreprocessorDirective = true ; // to prevent from EOF sucide of CurLexer in PP 1445 // lx.ParsingPreprocessorDirective = true ; // to prevent from EOF sucide of CurLexer in PP
1446 lx.Lex(Tok); 1446 lx->Lex(Tok);
1447 FirstTok = Tok; 1447 FirstTok = Tok;
1448 CurLexer.swap(lx);
1448 while (Tok.getKind() != tok::TokenKind::eof) { 1449 while (Tok.getKind() != tok::TokenKind::eof) {
1449 MI->AddTokenToBody(Tok); 1450 MI->AddTokenToBody(Tok);
1450 lx.Lex(Tok); 1451 Lex(Tok);
1451 } 1452 }
1453 CurLexer = std::move(lx);
1452 EnterMacro(Result, Loc, MI , 0 ); 1454 EnterMacro(Result, Loc, MI , 0 );
1453 // EnterTokenStream(&MI->ReplacementTokens,MI->getNumTokens(),true,true,false); 1455 // EnterTokenStream(&MI->ReplacementTokens,MI->getNumTokens(),true,true,false);
1454 return Result; 1456 return Result;
1455 } 1457 }
1456 1458