Mercurial > hg > CbC > CbC_llvm
changeset 92:8a1cd0ffee6e
Create prototype declaration automatically if prototype was not found when parsing continuation arguments.
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 17 Apr 2015 13:54:34 +0900 |
parents | ae2ab28b985c |
children | 15fe73fee027 |
files | tools/clang/include/clang/Parse/Parser.h tools/clang/lib/Parse/ParseCbC.cpp tools/clang/lib/Parse/ParseExpr.cpp tools/clang/lib/Parse/ParseStmt.cpp |
diffstat | 4 files changed, 23 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/tools/clang/include/clang/Parse/Parser.h Thu Apr 16 19:49:22 2015 +0900 +++ b/tools/clang/include/clang/Parse/Parser.h Fri Apr 17 13:54:34 2015 +0900 @@ -1805,8 +1805,9 @@ ExprResult Prepare__envForGotoWithTheEnvExpr(); bool isVoidFunction(); bool SearchCodeSegmentDeclaration(std::string Name); - void CreatePrototypeDeclaration(Token IITok); + void CreatePrototypeDeclaration(); bool SkipAnyUntil(tok::TokenKind T, SkipUntilFlags Flags = static_cast<SkipUntilFlags>(0)); + bool NeedPrototypeDeclaration(Token IITok); #endif bool isDeclarationSpecifier(bool DisambiguatingWithExpression = false);
--- a/tools/clang/lib/Parse/ParseCbC.cpp Thu Apr 16 19:49:22 2015 +0900 +++ b/tools/clang/lib/Parse/ParseCbC.cpp Fri Apr 17 13:54:34 2015 +0900 @@ -901,6 +901,7 @@ Stmtsp = &Stmts; gotoRes = ParseStatementOrDeclaration(Stmts, false); + if (gotoRes.get() == NULL) return StmtError(); else if (gotoRes.get()->getStmtClass() != Stmt::CallExprClass) { // if it is not function call @@ -938,8 +939,16 @@ return false; } +bool Parser::NeedPrototypeDeclaration(Token IITok){ + LookupResult LR(Actions, IITok.getIdentifierInfo(), IITok.getLocation(), Actions.LookupOrdinaryName); + CXXScopeSpec SS; + Actions.LookupParsedName(LR, getCurScope(), &SS, !(Actions.getCurMethodDecl())); + + return (LR.getResultKind() == LookupResult::NotFound); +} + /// CreatePrototypeDeclaration - Create prototype declaration by it's definition. -void Parser::CreatePrototypeDeclaration(Token IITok){ +void Parser::CreatePrototypeDeclaration(){ // move to the top level scope Scope *SavedScope = getCurScope(); DeclContext *SavedContext = Actions.CurContext; @@ -950,8 +959,10 @@ TopScope = TopScope->getParent(); Actions.CurScope = TopScope; - Token CachedTokens[3] = {IITok, PP.LookAhead(1)}; + Token Next = NextToken(); + Token CachedTokens[3] = {Next, PP.LookAhead(1)}; Token SavedToken = Tok; + Token IITok = Tok.is(tok::identifier) ? Tok : Next; PP.ClearCache(); ProtoParsing = true;
--- a/tools/clang/lib/Parse/ParseExpr.cpp Thu Apr 16 19:49:22 2015 +0900 +++ b/tools/clang/lib/Parse/ParseExpr.cpp Fri Apr 17 13:54:34 2015 +0900 @@ -2550,6 +2550,10 @@ else if (Tok.is(tok::kw___environment)){ Expr = Prepare__envForGotoWithTheEnvExpr(); } + else if (Tok.is(tok::identifier) && NeedPrototypeDeclaration(Tok)){ // check code segment declaration. + CreatePrototypeDeclaration(); + Expr = ParseAssignmentExpression(); + } #endif else Expr = ParseAssignmentExpression();
--- a/tools/clang/lib/Parse/ParseStmt.cpp Thu Apr 16 19:49:22 2015 +0900 +++ b/tools/clang/lib/Parse/ParseStmt.cpp Fri Apr 17 13:54:34 2015 +0900 @@ -25,10 +25,6 @@ #include "clang/Sema/TypoCorrection.h" #include "llvm/ADT/SmallString.h" -#ifndef noCbC -#include "clang/Sema/Lookup.h" -#endif - using namespace clang; //===----------------------------------------------------------------------===// @@ -258,16 +254,11 @@ if (!(Next.is(tok::identifier) && PP.LookAhead(1).is(tok::semi)) && // C: 'goto' identifier ';' Next.isNot(tok::star)) { // C: 'goto' '*' expression ';' SemiError = "goto code segment"; - if(Next.is(tok::identifier)){ // Probably, direct continuation. goto csName(); - LookupResult LR(Actions, Next.getIdentifierInfo(), Next.getLocation(), Actions.LookupOrdinaryName); - CXXScopeSpec SS; - Actions.LookupParsedName(LR, getCurScope(), &SS, !(Actions.getCurMethodDecl())); - if(LR.getResultKind() == LookupResult::NotFound){ - CreatePrototypeDeclaration(Next); - } - + + if(Next.is(tok::identifier) && NeedPrototypeDeclaration(Next)){ // Probably, direct continuation. goto csName(); + CreatePrototypeDeclaration(); } - + return ParseCbCGotoStatement(Attrs, Stmts); // CbC: goto codesegment statement } }