Mercurial > hg > CbC > CbC_llvm
changeset 197:af96f86c1b6d
...
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 02 Jun 2021 11:22:01 +0900 |
parents | ccaec67bcdbb |
children | cef006dc7fd5 |
files | clang/include/clang/Lex/Preprocessor.h clang/include/clang/Parse/Parser.h clang/lib/Lex/Preprocessor.cpp clang/lib/Parse/ParseCbC.cpp |
diffstat | 4 files changed, 23 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- 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;
--- 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();
--- 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<PPCallbacks>(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<Token[]>(1); + ToksCopy[0] = StrTok; + EnterTokenStream(std::move(ToksCopy), 1, + /*DisableMacroExpansion*/ true, + /*IsReinject*/ true); + Lex(Result); + return Result; +} + +#endif
--- 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<Token, 3> Tokens; - Token Tok ; - PP.CurLexer->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 @@ -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());