Mercurial > hg > CbC > CbC_llvm
changeset 52:c22698ecb2a9
modified CreateIdentifierInfo and create new function which was named 'CreateUniqueIdentifierInfo'.
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 15 Jan 2014 21:01:33 +0900 |
parents | c8f628ba8e9a |
children | f679cc5126db |
files | tools/clang/include/clang/Parse/Parser.h tools/clang/lib/Parse/CbCHelper.h tools/clang/lib/Parse/ParseCbC.cpp tools/clang/lib/Parse/ParseExpr.cpp tools/clang/lib/Parse/Parser.cpp |
diffstat | 5 files changed, 56 insertions(+), 61 deletions(-) [+] |
line wrap: on
line diff
--- a/tools/clang/include/clang/Parse/Parser.h Tue Jan 14 16:55:06 2014 +0900 +++ b/tools/clang/include/clang/Parse/Parser.h Wed Jan 15 21:01:33 2014 +0900 @@ -1504,7 +1504,7 @@ #ifndef noCbC // for CbC StmtVector* Stmtsp; - IdentifierInfo *bufII, *retvalII; + const char* curFuncName; bool preparedGotoWithTheEnv; #endif @@ -1707,8 +1707,8 @@ void PrepareForGotoWithTheEnv(); void CreateRetFunction(); void Create__CbC_envStruct(SourceLocation Loc, AccessSpecifier AS); - IdentifierInfo* CreateIdentifierInfo(const char* Name, int NameLen, SourceLocation Loc); - Decl* Create__CbC_envBody(Decl* TagDecl, DeclSpec::TST T, SourceLocation Loc, const char* Name, int NameLen); + IdentifierInfo* CreateIdentifierInfo(const char* Name, SourceLocation Loc); + Decl* Create__CbC_envBody(Decl* TagDecl, DeclSpec::TST T, SourceLocation Loc, const char* Name); ExprResult LookupAndDeclareName(IdentifierInfo *II); ExprResult LookupMemberAndBuildExpr(IdentifierInfo *II, Expr* Base, bool IsArrow); StmtResult CreateSjForContinuationWithEnv(); @@ -1716,7 +1716,7 @@ unsigned RHSFlags = 0, IdentifierInfo* extraLHSII = 0, IdentifierInfo* extraRHSII = 0); void CreateArrayDecl(ParsingDeclarator &D, SourceLocation Loc); StmtResult CreateDeclStmt(IdentifierInfo *II = 0, unsigned DeclFlags = 0, DeclSpec::TST valueType = DeclSpec::TST_int, IdentifierInfo* Name = 0); - IdentifierInfo* CreateSingleIdentifierInfo(const char* Name, int length, SourceLocation Loc); + IdentifierInfo* CreateUniqueIdentifierInfo(const char* Name, SourceLocation Loc); void CreateParam(DeclSpec::TST T, IdentifierInfo *II, int pointerNum, SmallVector<DeclaratorChunk::ParamInfo, 16> *ParamInfo); void setTST(DeclSpec *DS=0, DeclSpec::TST T = DeclSpec::TST_int, IdentifierInfo *Name=0); #endif
--- a/tools/clang/lib/Parse/CbCHelper.h Tue Jan 14 16:55:06 2014 +0900 +++ b/tools/clang/lib/Parse/CbCHelper.h Wed Jan 15 21:01:33 2014 +0900 @@ -2,20 +2,13 @@ #define _CBC_HELPER_IS_INCLUDED #define __CBC_ENVIRONMENT_NAME "__CbC_environment" -#define __CBC_ENVIRONMENT_LENGTH 17 #define __CBC_RETURN_NAME "__CbC_return" -#define __CBC_RETURN_LENGTH 12 #define __JMP_BUF_SIZE "128" -#define __JMP_BUF_SIZE_LENGTH 3 #define __CBC_BUF_NAME "env_buf" -#define __CBC_BUF_LENGTH 7 #define __CBC_RETVAL_NAME "retval" -#define __CBC_RETVAL_LENGTH 6 #define __CBC_STRUCT_NAME "__CbC_env" -#define __CBC_STRUCT_LENGTH 9 #define __CBC_STRUCT_ENV_NAME "env" -#define __CBC_STRUCT_ENV_LENGTH 3 #define __CBC_STRUCT_POINTER_NAME "ret_p" -#define __CBC_STRUCT_POINTER_LENGTH 5 +#define __CBC_RET_CODE_BASE_NAME "ret" #endif
--- a/tools/clang/lib/Parse/ParseCbC.cpp Tue Jan 14 16:55:06 2014 +0900 +++ b/tools/clang/lib/Parse/ParseCbC.cpp Wed Jan 15 21:01:33 2014 +0900 @@ -29,7 +29,7 @@ #include <cmath> #include <sstream> - +#include <string> #include "CbCHelper.h" using namespace clang; @@ -116,33 +116,38 @@ StmtResult Res; SourceLocation Loc = Tok.getLocation(); + IdentifierInfo *bufII, *retvalII, *structII, *__CbC_envII, *__CbC_retII,*envII, *ret_pII, *retcsII; + bufII = CreateUniqueIdentifierInfo(__CBC_BUF_NAME, Loc); + retvalII = CreateUniqueIdentifierInfo(__CBC_RETVAL_NAME, Loc); + structII = CreateIdentifierInfo(__CBC_STRUCT_NAME, Loc); + __CbC_envII = CreateIdentifierInfo(__CBC_ENVIRONMENT_NAME, Loc); + __CbC_retII = CreateIdentifierInfo(__CBC_RETURN_NAME, Loc); + envII = CreateIdentifierInfo(__CBC_STRUCT_ENV_NAME, Loc); + ret_pII = CreateIdentifierInfo(__CBC_STRUCT_POINTER_NAME, Loc); + retcsII = CreateUniqueIdentifierInfo(__CBC_RET_CODE_BASE_NAME, Loc); + CreateRetFunction(); - Res = CreateDeclStmt(CreateIdentifierInfo(__CBC_STRUCT_NAME, __CBC_STRUCT_LENGTH, Loc), CbCSpace::FunctionType, DeclSpec::TST___code); + Res = CreateDeclStmt(structII, CbCSpace::FunctionType, DeclSpec::TST___code); if (Res.isUsable()) Stmtsp->push_back(Res.release()); - Res = CreateDeclStmt(CreateIdentifierInfo(__CBC_ENVIRONMENT_NAME, __CBC_ENVIRONMENT_LENGTH, Loc), 0, DeclSpec::TST_struct, - CreateIdentifierInfo(__CBC_STRUCT_NAME, __CBC_STRUCT_LENGTH, Loc)); + Res = CreateDeclStmt(__CbC_envII, 0, DeclSpec::TST_struct, structII); if (Res.isUsable()) Stmtsp->push_back(Res.release()); - bufII = CreateSingleIdentifierInfo(__CBC_BUF_NAME, __CBC_BUF_LENGTH, Loc); Res = CreateDeclStmt(bufII, CbCSpace::ArrayType, DeclSpec::TST_int); if (Res.isUsable()) Stmtsp->push_back(Res.release()); - retvalII = CreateSingleIdentifierInfo(__CBC_RETVAL_NAME, __CBC_RETVAL_LENGTH, Loc); Res = CreateDeclStmt(retvalII, 0, DeclSpec::TST_int); if (Res.isUsable()) Stmtsp->push_back(Res.release()); - Res = CreateAssignmentStmt(CreateIdentifierInfo(__CBC_ENVIRONMENT_NAME, __CBC_ENVIRONMENT_LENGTH, Loc), - retvalII, CbCSpace::HasPeriod, CbCSpace::HasAmp, CreateIdentifierInfo(__CBC_STRUCT_POINTER_NAME, __CBC_STRUCT_POINTER_LENGTH, Loc)); + Res = CreateAssignmentStmt(__CbC_envII, retvalII, CbCSpace::HasPeriod, CbCSpace::HasAmp, ret_pII); if (Res.isUsable()) Stmtsp->push_back(Res.release()); - Res = CreateAssignmentStmt(CreateIdentifierInfo(__CBC_ENVIRONMENT_NAME, __CBC_ENVIRONMENT_LENGTH, Loc), - bufII, CbCSpace::HasPeriod, 0, CreateIdentifierInfo(__CBC_STRUCT_ENV_NAME, __CBC_STRUCT_ENV_LENGTH, Loc)); + Res = CreateAssignmentStmt(__CbC_envII, bufII, CbCSpace::HasPeriod, 0, envII); if (Res.isUsable()) Stmtsp->push_back(Res.release()); @@ -150,8 +155,7 @@ if (Res.isUsable()) Stmtsp->push_back(Res.release()); - Res = CreateAssignmentStmt(CreateIdentifierInfo(__CBC_RETURN_NAME, __CBC_RETURN_LENGTH, Loc), - CreateIdentifierInfo("return1", 7, Loc)); + Res = CreateAssignmentStmt(__CbC_retII, retcsII); if (Res.isUsable()) Stmtsp->push_back(Res.release()); } @@ -195,20 +199,6 @@ return Actions.ActOnExprStmt(Expr); } -IdentifierInfo* Parser::CreateSingleIdentifierInfo(const char* Name, int length, SourceLocation Loc){ - IdentifierInfo *II; - int i = 0; - std::ostringstream os; - - while (true) { - i++; - os << Name << i; - II = CreateIdentifierInfo(os.str().c_str(),length + (int)(floor(log10(i))+1),Loc); - LookupResult Previous(Actions, II, Loc, Actions.LookupOrdinaryName, Actions.ForRedeclaration); - if (!Actions.LookupName(Previous, getCurScope())) - return II; - } -} StmtResult Parser::CreateDeclStmt(IdentifierInfo *II, unsigned DeclFlags, DeclSpec::TST valueType, IdentifierInfo* Name){ SourceLocation Loc = Tok.getLocation(); @@ -225,7 +215,7 @@ D.setEllipsisLoc(SourceLocation()); bool hadGroupingParens = D.hasGroupingParens(); D.setGroupingParens(true); - IdentifierInfo* II = CreateIdentifierInfo(__CBC_RETURN_NAME, __CBC_RETURN_LENGTH, Loc); + IdentifierInfo* II = CreateIdentifierInfo(__CBC_RETURN_NAME, Loc); D.SetRangeEnd(Loc); DeclSpec FDS(AttrFactory); @@ -277,8 +267,8 @@ ExprResult ExprRes; ParsedAttributesWithRange attrs(AttrFactory); SmallString<128> SpellingBuffer; - SpellingBuffer.resize(__JMP_BUF_SIZE_LENGTH + 1); - StringRef TokSpelling = StringRef(__JMP_BUF_SIZE,__JMP_BUF_SIZE_LENGTH); + SpellingBuffer.resize(strlen(__JMP_BUF_SIZE) + 1); + StringRef TokSpelling = StringRef(__JMP_BUF_SIZE, strlen(__JMP_BUF_SIZE)); NumericLiteralParser Literal(TokSpelling, Loc, PP); Expr *sizeRes; QualType Ty; @@ -302,12 +292,12 @@ ExprResult CondExp; Decl *CondVar = 0; - CondExp = LookupAndDeclareName(CreateIdentifierInfo("setjmp",6,Loc)); + CondExp = LookupAndDeclareName(CreateIdentifierInfo("setjmp", Loc)); ExprVector ArgExprs; ExprResult __envExprRes = CondExp.get(); - __envExprRes = LookupAndDeclareName(CreateIdentifierInfo(__CBC_ENVIRONMENT_NAME, __CBC_ENVIRONMENT_LENGTH, Loc)); - __envExprRes = LookupMemberAndBuildExpr(CreateIdentifierInfo(__CBC_STRUCT_ENV_NAME, __CBC_STRUCT_ENV_LENGTH,Loc), __envExprRes.take(), false); + __envExprRes = LookupAndDeclareName(CreateIdentifierInfo(__CBC_ENVIRONMENT_NAME, Loc)); + __envExprRes = LookupMemberAndBuildExpr(CreateIdentifierInfo(__CBC_STRUCT_ENV_NAME, Loc), __envExprRes.take(), false); ArgExprs.push_back(__envExprRes.release()); CondExp = Actions.ActOnCallExpr(getCurScope(), CondExp.take(), Loc, ArgExprs, Loc, 0); @@ -338,8 +328,8 @@ pointerDS.getRestrictSpecLoc()), pointerDS.getAttributes(),SourceLocation()); - innerExprRes = LookupAndDeclareName(CreateIdentifierInfo(__CBC_ENVIRONMENT_NAME, __CBC_ENVIRONMENT_LENGTH, Loc)); - innerExprRes = LookupMemberAndBuildExpr(CreateIdentifierInfo(__CBC_STRUCT_POINTER_NAME,__CBC_STRUCT_POINTER_LENGTH,Loc), innerExprRes.take(), false); + innerExprRes = LookupAndDeclareName(CreateIdentifierInfo(__CBC_ENVIRONMENT_NAME, Loc)); + innerExprRes = LookupMemberAndBuildExpr(CreateIdentifierInfo(__CBC_STRUCT_POINTER_NAME, Loc), innerExprRes.take(), false); Expr *CastExpr = innerExprRes.take(); TypeSourceInfo *castTInfo = Actions.GetTypeForDeclaratorCast(CastDeclaratorInfo, CastExpr->getType()); Actions.checkUnusedDeclAttributes(CastDeclaratorInfo); @@ -414,7 +404,7 @@ SDS.SetRangeStart(Loc); SDS.SetRangeEnd(Loc); } - IdentifierInfo *Name = CreateIdentifierInfo(__CBC_STRUCT_NAME, __CBC_STRUCT_LENGTH, Loc); + IdentifierInfo *Name = CreateIdentifierInfo(__CBC_STRUCT_NAME, Loc); // Check previous definition. If the __CbC_env has been already defined, we have not to create again. LookupResult Previous(Actions, Name, Loc, Actions.LookupTagName, Actions.ForRedeclaration); @@ -443,8 +433,8 @@ const char *PrevSpec = 0; unsigned DiagID = 0; - FieldDecls.push_back(Create__CbC_envBody(TagDecl, DeclSpec::TST_void, Loc, __CBC_STRUCT_POINTER_NAME, __CBC_STRUCT_POINTER_LENGTH)); - FieldDecls.push_back(Create__CbC_envBody(TagDecl, DeclSpec::TST_int, Loc, __CBC_STRUCT_ENV_NAME, __CBC_STRUCT_ENV_LENGTH)); + FieldDecls.push_back(Create__CbC_envBody(TagDecl, DeclSpec::TST_void, Loc, __CBC_STRUCT_POINTER_NAME)); + FieldDecls.push_back(Create__CbC_envBody(TagDecl, DeclSpec::TST_int, Loc, __CBC_STRUCT_ENV_NAME)); Actions.ActOnFields(getCurScope(),Loc, TagDecl, FieldDecls,Loc, Loc,attrs.getList()); StructScope.Exit(); @@ -461,7 +451,7 @@ Actions.ConvertDeclToDeclGroup(TheDecl); } -Decl* Parser::Create__CbC_envBody(Decl* TagDecl, DeclSpec::TST T, SourceLocation Loc, const char* Name, int NameLen){ +Decl* Parser::Create__CbC_envBody(Decl* TagDecl, DeclSpec::TST T, SourceLocation Loc, const char* Name){ ParsingDeclSpec PDS(*this); setTST(&PDS, T); SourceLocation CommaLoc; @@ -470,7 +460,7 @@ DeclaratorInfo.D.SetRangeEnd(Loc); DeclSpec DS(AttrFactory); DS.Finish(Diags,PP); - DeclaratorInfo.D.SetIdentifier(CreateIdentifierInfo(Name, NameLen,Loc),Loc); + DeclaratorInfo.D.SetIdentifier(CreateIdentifierInfo(Name, Loc),Loc); DeclaratorInfo.D.AddTypeInfo(DeclaratorChunk::getPointer(DS.getTypeQualifiers(), Loc,DS.getConstSpecLoc(), DS.getVolatileSpecLoc(),DS.getRestrictSpecLoc()), @@ -482,11 +472,12 @@ return Field; } -IdentifierInfo* Parser::CreateIdentifierInfo(const char* Name, int NameLen, SourceLocation Loc) { +IdentifierInfo* Parser::CreateIdentifierInfo(const char* Name, SourceLocation Loc) { + int length = strlen(Name); Token TokenForII; TokenForII.startToken(); TokenForII.setLocation(Loc); - TokenForII.setLength(NameLen); + TokenForII.setLength(length); TokenForII.setKind(tok::raw_identifier); TokenForII.setRawIdentifierData(Name); IdentifierInfo *II; @@ -496,6 +487,14 @@ return II; } +IdentifierInfo* Parser::CreateUniqueIdentifierInfo(const char* Name, SourceLocation Loc){ + IdentifierInfo *II; + std::ostringstream os; + os << curFuncName << ".." /* separator */ << Name; + II = CreateIdentifierInfo(os.str().c_str(), Loc); + return II; +} + void Parser::CreateRetFunction(){ Scope *SavedScope = getCurScope(); DeclContext *SavedContext = Actions.CurContext; @@ -512,7 +511,7 @@ ParsingDeclSpec PDS(*this); setTST(&PDS, DeclSpec::TST___code); ParsingDeclarator D(*this, PDS, static_cast<Declarator::TheContext>(Declarator::FileContext)); - D.SetIdentifier(CreateIdentifierInfo("return1", 7, Loc),Loc); + D.SetIdentifier(CreateUniqueIdentifierInfo(__CBC_RET_CODE_BASE_NAME, Loc),Loc); ParseScope PrototypeScope(this,Scope::FunctionPrototypeScope|Scope::DeclScope|Scope::FunctionDeclarationScope); bool IsAmbiguous = false; bool HasProto = true; @@ -529,10 +528,10 @@ TypeResult TrailingReturnType; - IdentifierInfo *retvalII = CreateIdentifierInfo(__CBC_RETVAL_NAME, __CBC_RETVAL_LENGTH, Loc); + IdentifierInfo *retvalII = CreateIdentifierInfo(__CBC_RETVAL_NAME, Loc); // TODO : We should change retval type to a destination function's return type. CreateParam(retvalType, retvalII, 0, &ParamInfo); - IdentifierInfo *envII = CreateIdentifierInfo(__CBC_STRUCT_ENV_NAME, __CBC_STRUCT_ENV_LENGTH, Loc); + IdentifierInfo *envII = CreateIdentifierInfo(__CBC_STRUCT_ENV_NAME, Loc); CreateParam(DeclSpec::TST_void, envII, 1, &ParamInfo); D.AddTypeInfo(DeclaratorChunk::getFunction(HasProto, IsAmbiguous, Loc, ParamInfo.data(), ParamInfo.size(), EllipsisLoc, Loc, @@ -572,7 +571,7 @@ ExprVector ArgExprs; CommaLocsTy CommaLocs; DeclSpec envDS(AttrFactory); - IdentifierInfo *structName = CreateIdentifierInfo(__CBC_STRUCT_NAME, __CBC_STRUCT_LENGTH, Loc); + IdentifierInfo *structName = CreateIdentifierInfo(__CBC_STRUCT_NAME, Loc); setTST(&envDS, DeclSpec::TST_struct, structName); Declarator envDInfo(envDS, Declarator::TypeNameContext); @@ -597,7 +596,7 @@ LHS = Actions.BuildCStyleCastExpr(Loc, castTInfo, Loc, envCastExpr); ArgExprs.push_back(LHS.release()); LHS = Actions.ActOnParenListExpr(Loc, Loc, ArgExprs); - LHS = LookupMemberAndBuildExpr(CreateIdentifierInfo(__CBC_STRUCT_POINTER_NAME, __CBC_STRUCT_POINTER_LENGTH, Loc), + LHS = LookupMemberAndBuildExpr(CreateIdentifierInfo(__CBC_STRUCT_POINTER_NAME, Loc), LHS.take(), true); Expr *ret_pCastExpr = LHS.take(); TypeSourceInfo *castTInfo2 = Actions.GetTypeForDeclaratorCast(retvalTypeDInfo, ret_pCastExpr->getType()); @@ -615,7 +614,7 @@ Next.setKind(tok::l_paren); ExternalSpace::StatementFilterCCC CCCValidator(Next); CXXScopeSpec SS; - IdentifierInfo *ljName = CreateIdentifierInfo("longjmp", 7, Loc); + IdentifierInfo *ljName = CreateIdentifierInfo("longjmp", Loc); Sema::NameClassification Classification = Actions.ClassifyName(getCurScope(), SS, ljName, Loc, Next, false, &CCCValidator); ljTok.startToken(); ljTok.setLocation(Loc);
--- a/tools/clang/lib/Parse/ParseExpr.cpp Tue Jan 14 16:55:06 2014 +0900 +++ b/tools/clang/lib/Parse/ParseExpr.cpp Wed Jan 15 21:01:33 2014 +0900 @@ -2438,9 +2438,9 @@ preparedGotoWithTheEnv = false; if (isKw__env) - II = CreateIdentifierInfo(__CBC_ENVIRONMENT_NAME, __CBC_ENVIRONMENT_LENGTH, Tok.getLocation()); + II = CreateIdentifierInfo(__CBC_ENVIRONMENT_NAME, Tok.getLocation()); else - II = CreateIdentifierInfo(__CBC_RETURN_NAME, __CBC_RETURN_LENGTH, Tok.getLocation()); + II = CreateIdentifierInfo(__CBC_RETURN_NAME, Tok.getLocation()); SourceLocation ILoc = ConsumeToken(); UnqualifiedId Name;
--- a/tools/clang/lib/Parse/Parser.cpp Tue Jan 14 16:55:06 2014 +0900 +++ b/tools/clang/lib/Parse/Parser.cpp Wed Jan 15 21:01:33 2014 +0900 @@ -1186,6 +1186,9 @@ if (LateParsedAttrs) ParseLexedAttributeList(*LateParsedAttrs, Res, false, true); +#ifndef noCbC + curFuncName = D.getIdentifier()->getName().data(); +#endif return ParseFunctionStatementBody(Res, BodyScope); }