Mercurial > hg > CbC > CbC_llvm
comparison tools/clang/lib/Parse/ParseCbC.cpp @ 64:0aa33659e8e4
modified Parser::CreateUniqueIdentifierInfo(). add unique id
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 03 Feb 2014 18:02:13 +0900 |
parents | 0d1cf6cb7029 |
children | 35ab9e3560be |
comparison
equal
deleted
inserted
replaced
63:0d1cf6cb7029 | 64:0aa33659e8e4 |
---|---|
103 ParseScope CompoundScope(this, Scope::DeclScope); | 103 ParseScope CompoundScope(this, Scope::DeclScope); |
104 PrettyStackTraceLoc CrashInfo(PP.getSourceManager(),Loc,"in compound statement ('{}')"); | 104 PrettyStackTraceLoc CrashInfo(PP.getSourceManager(),Loc,"in compound statement ('{}')"); |
105 StmtVector CompoundStmts; | 105 StmtVector CompoundStmts; |
106 | 106 |
107 // create code segment for return to C's function | 107 // create code segment for return to C's function |
108 if (CreateRetCS()) { // error check : function type is void or not. | 108 if (CreateRetCS(retcsII)) { // error check : function type is void or not. |
109 Diag(Tok, diag::err_cannot_use_goto_with_env); | 109 Diag(Tok, diag::err_cannot_use_goto_with_env); |
110 return ExprError(); | 110 return ExprError(); |
111 } | 111 } |
112 | 112 |
113 // __code (*__CbC_return)(); | 113 // __code (*__CbC_return)(); |
151 /// void *ret_p,*env; | 151 /// void *ret_p,*env; |
152 /// } | 152 /// } |
153 ExprResult Parser::Prepare__envForGotoWithTheEnvExpr(){ | 153 ExprResult Parser::Prepare__envForGotoWithTheEnvExpr(){ |
154 StmtResult innerRes; | 154 StmtResult innerRes; |
155 SourceLocation Loc = Tok.getLocation(); | 155 SourceLocation Loc = Tok.getLocation(); |
156 IdentifierInfo *bufII = CreateUniqueIdentifierInfo(__CBC_BUF_NAME, Loc); | 156 IdentifierInfo *bufII = CreateIdentifierInfo(__CBC_BUF_NAME, Loc); |
157 IdentifierInfo *retvalII = CreateUniqueIdentifierInfo(__CBC_RETVAL_NAME, Loc); | 157 IdentifierInfo *retvalII = CreateIdentifierInfo(__CBC_RETVAL_NAME, Loc); |
158 IdentifierInfo *structII = CreateIdentifierInfo(__CBC_STRUCT_NAME, Loc); | 158 IdentifierInfo *structII = CreateIdentifierInfo(__CBC_STRUCT_NAME, Loc); |
159 IdentifierInfo *__CbC_envII = CreateIdentifierInfo(__CBC_ENVIRONMENT_NAME, Loc); | 159 IdentifierInfo *__CbC_envII = CreateIdentifierInfo(__CBC_ENVIRONMENT_NAME, Loc); |
160 IdentifierInfo *envII = CreateIdentifierInfo(__CBC_STRUCT_ENV_NAME, Loc); | 160 IdentifierInfo *envII = CreateIdentifierInfo(__CBC_STRUCT_ENV_NAME, Loc); |
161 IdentifierInfo *ret_pII = CreateIdentifierInfo(__CBC_STRUCT_POINTER_NAME, Loc); | 161 IdentifierInfo *ret_pII = CreateIdentifierInfo(__CBC_STRUCT_POINTER_NAME, Loc); |
162 Create__CbC_envStruct(Loc, AS_none); | 162 Create__CbC_envStruct(Loc, AS_none); |
424 ParseScope CompoundScope(this, Scope::DeclScope); | 424 ParseScope CompoundScope(this, Scope::DeclScope); |
425 PrettyStackTraceLoc CrashInfo(PP.getSourceManager(),Loc,"in create setjmp statement for CbC"); | 425 PrettyStackTraceLoc CrashInfo(PP.getSourceManager(),Loc,"in create setjmp statement for CbC"); |
426 StmtVector innerStmts; | 426 StmtVector innerStmts; |
427 StmtResult innerStmtRes; | 427 StmtResult innerStmtRes; |
428 ExprResult innerExprRes; | 428 ExprResult innerExprRes; |
429 innerExprRes = LookupNameAndBuildExpr(CreateUniqueIdentifierInfo(__CBC_RETVAL_NAME, Loc)); | 429 innerExprRes = LookupNameAndBuildExpr(CreateIdentifierInfo(__CBC_RETVAL_NAME, Loc)); |
430 innerStmtRes = Actions.ActOnReturnStmt(Loc, innerExprRes.take()); | 430 innerStmtRes = Actions.ActOnReturnStmt(Loc, innerExprRes.take()); |
431 if (innerStmtRes.isUsable()) | 431 if (innerStmtRes.isUsable()) |
432 innerStmts.push_back(innerStmtRes.release()); | 432 innerStmts.push_back(innerStmtRes.release()); |
433 StmtRes = Actions.ActOnCompoundStmt(Loc, Loc,innerStmts, false); | 433 StmtRes = Actions.ActOnCompoundStmt(Loc, Loc,innerStmts, false); |
434 StmtResult ThenStmt(StmtRes); | 434 StmtResult ThenStmt(StmtRes); |
586 return II; | 586 return II; |
587 } | 587 } |
588 | 588 |
589 /// CreateUniqueIdentifierInfo - Create unique IdentifierInfo. | 589 /// CreateUniqueIdentifierInfo - Create unique IdentifierInfo. |
590 /// IdentifierInfos have unique name which were created by this function. | 590 /// IdentifierInfos have unique name which were created by this function. |
591 /// Naming conventions is current function's name '..' variable name | 591 /// Naming conventions : |
592 /// current 'function name' '..' 'variable name' 'uniqueID' | |
592 /// For example, if current function's name is 'main' and variable name is 'auaua', IdentifierInfo's name is 'main..auaua'. | 593 /// For example, if current function's name is 'main' and variable name is 'auaua', IdentifierInfo's name is 'main..auaua'. |
593 IdentifierInfo* Parser::CreateUniqueIdentifierInfo(const char* Name, SourceLocation Loc){ | 594 IdentifierInfo* Parser::CreateUniqueIdentifierInfo(const char* Name, SourceLocation Loc){ |
594 IdentifierInfo *II; | 595 IdentifierInfo *II; |
595 std::ostringstream os; | 596 std::ostringstream os; |
596 os << curFuncName << ".." /* separator */ << Name; | 597 |
598 os << curFuncName << ".." /* separator */ << Name << UniqueId; | |
597 II = CreateIdentifierInfo(os.str().c_str(), Loc); | 599 II = CreateIdentifierInfo(os.str().c_str(), Loc); |
600 UniqueId++; // Modify the unique ID. | |
598 return II; | 601 return II; |
599 } | 602 } |
600 | 603 |
601 | 604 |
602 /// CreateRetCS - Create code segment which is used for continuation with the environment. | 605 /// CreateRetCS - Create code segment which is used for continuation with the environment. |
603 /// create these codes: | 606 /// create these codes: |
604 /// __code ret(return_type retval, void *env){ | 607 /// __code ret(return_type retval, void *env){ |
605 /// *(return_type)((struct CbC_environment *)(env))->ret_p = n; | 608 /// *(return_type)((struct CbC_environment *)(env))->ret_p = n; |
606 /// longjmp((int*)(((struct __CbC_environment *)env)->env),1); | 609 /// longjmp((int*)(((struct __CbC_environment *)env)->env),1); |
607 /// } | 610 /// } |
608 bool Parser::CreateRetCS(){ | 611 bool Parser::CreateRetCS(IdentifierInfo *csName){ |
609 FunctionDecl *CurFunctionDecl = Actions.getCurFunctionDecl(); | 612 FunctionDecl *CurFunctionDecl = Actions.getCurFunctionDecl(); |
610 QualType CurFuncResQT = CurFunctionDecl->getResultType(); | 613 QualType CurFuncResQT = CurFunctionDecl->getResultType(); |
611 if (CurFuncResQT.getTypePtr()->isVoidType()) // this function cannot use continuation with the environment. | 614 if (CurFuncResQT.getTypePtr()->isVoidType()) // this function cannot use continuation with the environment. |
612 return true; | 615 return true; |
613 | 616 |
625 DeclGroupPtrTy returnDecl = DeclGroupPtrTy(); | 628 DeclGroupPtrTy returnDecl = DeclGroupPtrTy(); |
626 SourceLocation Loc = Tok.getLocation(); | 629 SourceLocation Loc = Tok.getLocation(); |
627 ParsingDeclSpec PDS(*this); | 630 ParsingDeclSpec PDS(*this); |
628 setTST(&PDS, DeclSpec::TST___code); | 631 setTST(&PDS, DeclSpec::TST___code); |
629 ParsingDeclarator D(*this, PDS, static_cast<Declarator::TheContext>(Declarator::FileContext)); | 632 ParsingDeclarator D(*this, PDS, static_cast<Declarator::TheContext>(Declarator::FileContext)); |
630 D.SetIdentifier(CreateUniqueIdentifierInfo(__CBC_RET_CODE_BASE_NAME, Loc),Loc); | 633 D.SetIdentifier(csName, Loc); |
631 ParseScope PrototypeScope(this,Scope::FunctionPrototypeScope|Scope::DeclScope|Scope::FunctionDeclarationScope); | 634 ParseScope PrototypeScope(this,Scope::FunctionPrototypeScope|Scope::DeclScope|Scope::FunctionDeclarationScope); |
632 bool IsAmbiguous = false; | 635 bool IsAmbiguous = false; |
633 bool HasProto = true; | 636 bool HasProto = true; |
634 SmallVector<DeclaratorChunk::ParamInfo, 16> ParamInfo; | 637 SmallVector<DeclaratorChunk::ParamInfo, 16> ParamInfo; |
635 SourceLocation EllipsisLoc, RefQualifierLoc, ConstQualifierLoc, VolatileQualifierLoc; | 638 SourceLocation EllipsisLoc, RefQualifierLoc, ConstQualifierLoc, VolatileQualifierLoc; |