diff 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
line wrap: on
line diff
--- a/tools/clang/lib/Parse/ParseCbC.cpp	Sun Feb 02 20:10:53 2014 +0900
+++ b/tools/clang/lib/Parse/ParseCbC.cpp	Mon Feb 03 18:02:13 2014 +0900
@@ -105,7 +105,7 @@
   StmtVector CompoundStmts; 
 
   // create code segment for return to C's function
-  if (CreateRetCS()) { // error check : function type is void or not.
+  if (CreateRetCS(retcsII)) { // error check : function type is void or not.
     Diag(Tok, diag::err_cannot_use_goto_with_env);
     return ExprError();
   }
@@ -153,8 +153,8 @@
 ExprResult Parser::Prepare__envForGotoWithTheEnvExpr(){
   StmtResult innerRes;
   SourceLocation Loc = Tok.getLocation();
-  IdentifierInfo *bufII = CreateUniqueIdentifierInfo(__CBC_BUF_NAME, Loc);
-  IdentifierInfo *retvalII = CreateUniqueIdentifierInfo(__CBC_RETVAL_NAME, Loc);
+  IdentifierInfo *bufII = CreateIdentifierInfo(__CBC_BUF_NAME, Loc);
+  IdentifierInfo *retvalII = CreateIdentifierInfo(__CBC_RETVAL_NAME, Loc);
   IdentifierInfo *structII = CreateIdentifierInfo(__CBC_STRUCT_NAME, Loc);
   IdentifierInfo *__CbC_envII = CreateIdentifierInfo(__CBC_ENVIRONMENT_NAME, Loc);
   IdentifierInfo *envII = CreateIdentifierInfo(__CBC_STRUCT_ENV_NAME, Loc);
@@ -426,7 +426,7 @@
   StmtVector innerStmts;
   StmtResult innerStmtRes;
   ExprResult innerExprRes;
-  innerExprRes = LookupNameAndBuildExpr(CreateUniqueIdentifierInfo(__CBC_RETVAL_NAME, Loc));
+  innerExprRes = LookupNameAndBuildExpr(CreateIdentifierInfo(__CBC_RETVAL_NAME, Loc));
   innerStmtRes = Actions.ActOnReturnStmt(Loc, innerExprRes.take());
   if (innerStmtRes.isUsable())
     innerStmts.push_back(innerStmtRes.release());
@@ -588,13 +588,16 @@
 
 /// CreateUniqueIdentifierInfo - Create unique IdentifierInfo.
 /// IdentifierInfos have unique name which were created by this function.
-/// Naming conventions is current function's name '..' variable name
+/// Naming conventions : 
+///   current 'function name' '..' 'variable name' 'uniqueID'
 /// For example, if current function's name is 'main' and variable name is 'auaua', IdentifierInfo's name is 'main..auaua'.
 IdentifierInfo* Parser::CreateUniqueIdentifierInfo(const char* Name, SourceLocation Loc){
   IdentifierInfo *II;
   std::ostringstream os;
-  os << curFuncName << ".." /* separator */ << Name;
+  
+  os << curFuncName << ".." /* separator */ << Name << UniqueId;
   II = CreateIdentifierInfo(os.str().c_str(), Loc);
+  UniqueId++; // Modify the unique ID.
   return II;
 }
 
@@ -605,7 +608,7 @@
 ///           *(return_type)((struct CbC_environment *)(env))->ret_p = n;
 ///             longjmp((int*)(((struct __CbC_environment *)env)->env),1);
 ///         }
-bool Parser::CreateRetCS(){
+bool Parser::CreateRetCS(IdentifierInfo *csName){
   FunctionDecl *CurFunctionDecl = Actions.getCurFunctionDecl();
   QualType CurFuncResQT = CurFunctionDecl->getResultType();
   if (CurFuncResQT.getTypePtr()->isVoidType()) // this function cannot use continuation with the environment.
@@ -627,7 +630,7 @@
   ParsingDeclSpec PDS(*this);
   setTST(&PDS, DeclSpec::TST___code);
   ParsingDeclarator D(*this, PDS, static_cast<Declarator::TheContext>(Declarator::FileContext));
-  D.SetIdentifier(CreateUniqueIdentifierInfo(__CBC_RET_CODE_BASE_NAME, Loc),Loc);
+  D.SetIdentifier(csName, Loc);
   ParseScope PrototypeScope(this,Scope::FunctionPrototypeScope|Scope::DeclScope|Scope::FunctionDeclarationScope);
   bool IsAmbiguous = false;
   bool HasProto = true;