Mercurial > hg > CbC > CbC_llvm
changeset 198:cef006dc7fd5
CurLexer vanish after EnterMacro finish
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 02 Jun 2021 23:09:47 +0900 |
parents | af96f86c1b6d |
children | 5784c86f13b3 |
files | clang/include/clang/Lex/Preprocessor.h clang/lib/Lex/Preprocessor.cpp clang/lib/Parse/ParseCbC.cpp |
diffstat | 3 files changed, 17 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/clang/include/clang/Lex/Preprocessor.h Wed Jun 02 11:22:01 2021 +0900 +++ b/clang/include/clang/Lex/Preprocessor.h Wed Jun 02 23:09:47 2021 +0900 @@ -2366,7 +2366,7 @@ #ifndef noCbC bool IncludeHeader(Token Tok, const char* Name); - Token ReadFromString(const char *src ) ; + Token ReadFromString(const char *src , SourceLocation Loc) ; unsigned int SavedDepth; Token SavedToken; bool SavedTokenFlag;
--- a/clang/lib/Lex/Preprocessor.cpp Wed Jun 02 11:22:01 2021 +0900 +++ b/clang/lib/Lex/Preprocessor.cpp Wed Jun 02 23:09:47 2021 +0900 @@ -1435,17 +1435,20 @@ #ifndef noCbC -Token Preprocessor::ReadFromString(const char *src ) { +Token Preprocessor::ReadFromString(const char *src , SourceLocation Loc) { // Push the ( "string" ) tokens into the token stream. - Token StrTok,Result ; - std::string str(src); - CreateString(str, StrTok); - auto ToksCopy = std::make_unique<Token[]>(1); - ToksCopy[0] = StrTok; - EnterTokenStream(std::move(ToksCopy), 1, - /*DisableMacroExpansion*/ true, - /*IsReinject*/ true); - Lex(Result); + MacroInfo *MI = AllocateMacroInfo(Loc); + Token Tok,FirstTok,Result; + bool Invalid = false; + Lexer lx(CurLexer->getFileID(),getSourceManager().getBuffer(CurLexer->getFileID(), Loc, &Invalid),*this); + lx.InitLexer(src,src,src + strlen(src)); + lx.Lex(Tok); + FirstTok = Tok; + while (Tok.getKind() != tok::TokenKind::eof) { + MI->AddTokenToBody(Tok); + lx.Lex(Tok); + } + EnterMacro(Result, Loc, MI , 0 ); return Result; }
--- a/clang/lib/Parse/ParseCbC.cpp Wed Jun 02 11:22:01 2021 +0900 +++ b/clang/lib/Parse/ParseCbC.cpp Wed Jun 02 23:09:47 2021 +0900 @@ -241,11 +241,11 @@ CompoundStmts.push_back(innerRes.get()); // jmp_buf env_buf; --> int env_buf[64]; - Tok = PP.ReadFromString("int env_buf[64];"); - if (Tok.getKind() == tok::TokenKind::eof) ConsumeToken(); + Tok = PP.ReadFromString("int env_buf[64];",Loc); + ConsumeAnyToken(); // innerRes = CreateDeclStmt(bufII, false, false, 64, DeclSpec::TST_typename, CreateIdentifierInfo("int", Loc)); StmtVector Stmts; - innerRes = ParseStatementOrDeclaration(Stmts,ParsedStmtContext::Compound); + innerRes = ParseStatementOrDeclaration(Stmts,( ParsedStmtContext::Compound | ParsedStmtContext::AllowDeclarationsInC)); if (innerRes.isUsable()) CompoundStmts.push_back(innerRes.get());