# HG changeset patch # User Shinji KONO # Date 1622600521 -32400 # Node ID af96f86c1b6d70da9957e11b711a2db670002021 # Parent ccaec67bcdbb118ad9755d1a2f62ced306024f17 ... diff -r ccaec67bcdbb -r af96f86c1b6d clang/include/clang/Lex/Preprocessor.h --- a/clang/include/clang/Lex/Preprocessor.h Tue Jun 01 22:16:31 2021 +0900 +++ b/clang/include/clang/Lex/Preprocessor.h Wed Jun 02 11:22:01 2021 +0900 @@ -2366,6 +2366,7 @@ #ifndef noCbC bool IncludeHeader(Token Tok, const char* Name); + Token ReadFromString(const char *src ) ; unsigned int SavedDepth; Token SavedToken; bool SavedTokenFlag; diff -r ccaec67bcdbb -r af96f86c1b6d clang/include/clang/Parse/Parser.h --- a/clang/include/clang/Parse/Parser.h Tue Jun 01 22:16:31 2021 +0900 +++ b/clang/include/clang/Parse/Parser.h Wed Jun 02 11:22:01 2021 +0900 @@ -2070,7 +2070,6 @@ StmtResult ParseGotoStatement(); #ifndef noCbC StmtResult ParseCbCGotoStatement(ParsedAttributesWithRange &Attrs,StmtVector &Stmts); - void ExprFromString(const char *src ) ; #endif StmtResult ParseContinueStatement(); StmtResult ParseBreakStatement(); diff -r ccaec67bcdbb -r af96f86c1b6d clang/lib/Lex/Preprocessor.cpp --- a/clang/lib/Lex/Preprocessor.cpp Tue Jun 01 22:16:31 2021 +0900 +++ b/clang/lib/Lex/Preprocessor.cpp Wed Jun 02 11:22:01 2021 +0900 @@ -1432,3 +1432,21 @@ Record = new PreprocessingRecord(getSourceManager()); addPPCallbacks(std::unique_ptr(Record)); } + +#ifndef noCbC + +Token Preprocessor::ReadFromString(const char *src ) { + // Push the ( "string" ) tokens into the token stream. + Token StrTok,Result ; + std::string str(src); + CreateString(str, StrTok); + auto ToksCopy = std::make_unique(1); + ToksCopy[0] = StrTok; + EnterTokenStream(std::move(ToksCopy), 1, + /*DisableMacroExpansion*/ true, + /*IsReinject*/ true); + Lex(Result); + return Result; +} + +#endif diff -r ccaec67bcdbb -r af96f86c1b6d clang/lib/Parse/ParseCbC.cpp --- a/clang/lib/Parse/ParseCbC.cpp Tue Jun 01 22:16:31 2021 +0900 +++ b/clang/lib/Parse/ParseCbC.cpp Wed Jun 02 11:22:01 2021 +0900 @@ -94,18 +94,6 @@ }; } -void Parser::ExprFromString(const char *src ) { - // Push the ( "string" ) tokens into the token stream. - SmallVector Tokens; - Token Tok ; - PP.CurLexer->FormTokenWithChars(Tok, src, tok::unknown); - auto Toks = std::make_unique(Tokens.size()); - std::copy(Tokens.begin() + 1, Tokens.end(), Toks.get()); - Toks[Tokens.size() - 1] = Tok; - PP.EnterTokenStream(std::move(Toks), Tokens.size(), - /*DisableMacroExpansion*/ true, - /*IsReinject*/ true); -} /// goto with environment with out logjmp /// basic idea is prepare struct containes pointer to return value variable and stack pointer @@ -253,9 +241,11 @@ CompoundStmts.push_back(innerRes.get()); // jmp_buf env_buf; --> int env_buf[64]; - ExprFromString("int env_buf[64];"); + Tok = PP.ReadFromString("int env_buf[64];"); + if (Tok.getKind() == tok::TokenKind::eof) ConsumeToken(); // innerRes = CreateDeclStmt(bufII, false, false, 64, DeclSpec::TST_typename, CreateIdentifierInfo("int", Loc)); - innerRes = ParseCompoundStatementBody(); + StmtVector Stmts; + innerRes = ParseStatementOrDeclaration(Stmts,ParsedStmtContext::Compound); if (innerRes.isUsable()) CompoundStmts.push_back(innerRes.get());