# HG changeset patch # User Shinji KONO # Date 1622537898 -32400 # Node ID c7eaafae97e2600019769edb4f82a6f02bf59baa # Parent f2ef29ba5fe27e3bf0884301f4ef41bba1136d1f add ExprFromString diff -r f2ef29ba5fe2 -r c7eaafae97e2 clang/include/clang/Parse/Parser.h --- a/clang/include/clang/Parse/Parser.h Mon Mar 22 18:10:23 2021 +0900 +++ b/clang/include/clang/Parse/Parser.h Tue Jun 01 17:58:18 2021 +0900 @@ -2070,6 +2070,7 @@ StmtResult ParseGotoStatement(); #ifndef noCbC StmtResult ParseCbCGotoStatement(ParsedAttributesWithRange &Attrs,StmtVector &Stmts); + void ExprFromString(char *src ) ; #endif StmtResult ParseContinueStatement(); StmtResult ParseBreakStatement(); diff -r f2ef29ba5fe2 -r c7eaafae97e2 clang/lib/Parse/ParseCbC.cpp --- a/clang/lib/Parse/ParseCbC.cpp Mon Mar 22 18:10:23 2021 +0900 +++ b/clang/lib/Parse/ParseCbC.cpp Tue Jun 01 17:58:18 2021 +0900 @@ -94,6 +94,19 @@ }; } +void Parser::ExprFromString(char *src ) { + // Push the ( "string" ) tokens into the token stream. + SmallVector Tokens; + Token &Tok; + 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 /// @@ -240,7 +253,9 @@ CompoundStmts.push_back(innerRes.get()); // jmp_buf env_buf; --> int env_buf[64]; - innerRes = CreateDeclStmt(bufII, false, false, 64, DeclSpec::TST_typename, CreateIdentifierInfo("int", Loc)); + ExprFromString("int env_buf[64];"); + // innerRes = CreateDeclStmt(bufII, false, false, 64, DeclSpec::TST_typename, CreateIdentifierInfo("int", Loc)); + nnerRes = ParseCompoundStatementBody(); if (innerRes.isUsable()) CompoundStmts.push_back(innerRes.get());