changeset 195:c7eaafae97e2

add ExprFromString
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 01 Jun 2021 17:58:18 +0900
parents f2ef29ba5fe2
children ccaec67bcdbb
files clang/include/clang/Parse/Parser.h clang/lib/Parse/ParseCbC.cpp
diffstat 2 files changed, 17 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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();
--- 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<Token, 3> Tokens;
+    Token &Tok;
+    FormTokenWithChars(Tok, src, tok::unknown);
+    auto Toks = std::make_unique<Token[]>(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());