Mercurial > hg > CbC > CbC_llvm
diff tools/clang/lib/Parse/ParseCbC.cpp @ 89:9020ffd06b8b
Create prototype declaration automatically (only support direct continuation)
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 14 Apr 2015 03:55:39 +0900 |
parents | e471d82fb99b |
children | 2ddce554fef0 |
line wrap: on
line diff
--- a/tools/clang/lib/Parse/ParseCbC.cpp Mon Apr 13 18:34:22 2015 +0900 +++ b/tools/clang/lib/Parse/ParseCbC.cpp Tue Apr 14 03:55:39 2015 +0900 @@ -931,9 +931,51 @@ /// If we can't find it , return false; bool Parser::SearchCodeSegmentDeclaration(std::string Name){ while(SkipUntil(tok::kw___code,StopBeforeMatch)){ - if(NextToken().getIdentifierInfo()->getName().str() == Name) + if(NextToken().is(tok::identifier) && NextToken().getIdentifierInfo()->getName().str() == Name) return true; + ConsumeToken(); } return false; } + +/// CreatePrototypeDeclaration - Create prototype declaration by it's definition. +void Parser::CreatePrototypeDeclaration(Token IITok){ + // move to the top level scope + Scope *SavedScope = getCurScope(); + DeclContext *SavedContext = Actions.CurContext; + sema::FunctionScopeInfo *SavedFSI = Actions.FunctionScopes.pop_back_val(); + Actions.CurContext = static_cast<DeclContext *>(Actions.Context.getTranslationUnitDecl()); + Scope *TopScope = getCurScope(); + while(TopScope->getParent() != NULL) + TopScope = TopScope->getParent(); + Actions.CurScope = TopScope; + + Token CachedTokens[] = {IITok, PP.LookAhead(1)}; + Token SavedToken = Tok; + PP.ClearCache(); + ProtoParsing = true; + + StringRef Filename; + Filename = StringRef("proto.h",7); + const DirectoryLookup *CurDir; + FileID FID = PP.getSourceManager().createFileID(PP.getCurrentFileLexer()->getFileEntry(), IITok.getLocation(), SrcMgr::C_User); + PP.EnterSourceFile(FID,CurDir,IITok.getLocation()); + ConsumeToken(); + SearchCodeSegmentDeclaration(IITok.getIdentifierInfo()->getName().str()); + + // move to the previous scope. + DeclGroupPtrTy ProtoDecl; + ParseTopLevelDecl(ProtoDecl); + (&Actions.getASTConsumer())->HandleTopLevelDecl(ProtoDecl.get()); + Actions.CurScope = SavedScope; + Actions.CurContext = SavedContext; + Actions.FunctionScopes.push_back(SavedFSI); + + // recover tokens + Tok = SavedToken; + PP.RestoreTokens(CachedTokens, 2); + + ProtoParsing = false; +} + #endif