Mercurial > hg > CbC > CbC_llvm
changeset 30:1f391bea5bc8
devide a Create__CbC_env method in some small methods
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 08 Dec 2013 16:06:10 +0900 |
parents | 00b59dd660f7 |
children | d22a1cf4041c |
files | tools/clang/include/clang/Parse/Parser.h tools/clang/lib/Parse/ParseDecl.cpp |
diffstat | 2 files changed, 63 insertions(+), 98 deletions(-) [+] |
line wrap: on
line diff
--- a/tools/clang/include/clang/Parse/Parser.h Sun Dec 08 00:47:45 2013 +0900 +++ b/tools/clang/include/clang/Parse/Parser.h Sun Dec 08 16:06:10 2013 +0900 @@ -1662,6 +1662,9 @@ #ifndef noCbC bool Create__CbC_envStruct(SourceLocation Loc, AccessSpecifier AS); + IdentifierInfo* CreateIdentifierInfo(const char* Name, int NameLen); + Decl* Create__CbC_envBody(Decl* TagDecl, DeclSpec::TST T, SourceLocation Loc, bool* isInvalid, + const char* PrevSpec, unsigned* DiagID, const char* Name, int NameLen); #endif bool isDeclarationSpecifier(bool DisambiguatingWithExpression = false);
--- a/tools/clang/lib/Parse/ParseDecl.cpp Sun Dec 08 00:47:45 2013 +0900 +++ b/tools/clang/lib/Parse/ParseDecl.cpp Sun Dec 08 16:06:10 2013 +0900 @@ -2878,7 +2878,7 @@ case tok::kw___code: { // create __CbC_env bool isInvalid__CbC_env = false; - if (getCurScope()->getParent() == NULL) + if (getCurScope()->getParent() == NULL) // If the current scope has parent scope, it is not the glabal scope. isInvalid__CbC_env = Create__CbC_envStruct(Loc,AS); if (DS.getSourceRange().isInvalid()) { @@ -5665,28 +5665,22 @@ } #ifndef noCbC + +/// Create__CbC_envStruct - This method create "struct __CbC_env" which is used to continuation with environment. +/// If the __CbC_env has been already defined, it doesn't create __CbC_env again and just return "false". bool Parser::Create__CbC_envStruct(SourceLocation Loc, AccessSpecifier AS) { ParsingDeclSpec SDS(*this); if (SDS.getSourceRange().isInvalid()) { SDS.SetRangeStart(Loc); SDS.SetRangeEnd(Loc); } - Token identifierToken; - identifierToken.startToken(); - const char *CbC_envId = "__CbC_env"; - identifierToken.setLength(9); //length of __CbC_env - identifierToken.setKind(tok::raw_identifier); - identifierToken.setRawIdentifierData(CbC_envId); - IdentifierInfo *Name; - Name = PP.getIdentifierInfo(StringRef(identifierToken.getRawIdentifierData(),identifierToken.getLength())); - identifierToken.setIdentifierInfo(Name); - identifierToken.setKind(Name->getTokenID()); - + IdentifierInfo *Name = CreateIdentifierInfo("__CbC_env", /* length of the name */ 9);; + // 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); if(Actions.LookupName(Previous, getCurScope())) return false; - + // start ParseClassSpecifier DeclSpec::TST TagType = DeclSpec::TST_struct; DeclResult TagOrTempResult = true; // invalid @@ -5697,100 +5691,23 @@ TagOrTempResult = Actions.ActOnTag(getCurScope(), TagType, Sema::TUK_Definition, Loc, SDS.getTypeSpecScope(), Name, Loc, attrs.getList(), AS, - SDS.getModulePrivateSpecLoc(), - TParams, Owned, IsDependent, - SourceLocation(), false, - clang::TypeResult()); + SDS.getModulePrivateSpecLoc(), TParams, Owned, IsDependent, + SourceLocation(), false, clang::TypeResult()); // start ParseStructUnionBody Decl *TagDecl = TagOrTempResult.get(); PrettyDeclStackTraceEntry CrashInfo(Actions, TagDecl, Loc, "parsing struct/union body"); ParseScope StructScope(this, Scope::ClassScope|Scope::DeclScope); Actions.ActOnTagStartDefinition(getCurScope(), TagDecl); SmallVector<Decl *, 32> FieldDecls; - ParsingDeclSpec ret_pPDS(*this); - - if (ret_pPDS.getSourceRange().isInvalid()) { - ret_pPDS.SetRangeStart(Loc); - ret_pPDS.SetRangeEnd(Loc); - } + bool isInvalid = false; const char *PrevSpec = 0; unsigned DiagID = 0; - isInvalid = ret_pPDS.SetTypeSpecType(DeclSpec::TST_void, Loc, PrevSpec, - DiagID); - ret_pPDS.SetRangeEnd(Loc); - - // ここまでで void読み込んだ。 PreSpeとDiagIDは未使用。 - // TokenKindがstar(*)になる。 - ret_pPDS.Finish(Diags, PP); //これは consumeTokenでTokenがstarになったあとのもの。 - - ret_pPDS.getParsedSpecifiers(); - SourceLocation CommaLoc; - ParsingFieldDeclarator ret_pDeclaratorInfo(*this, ret_pPDS); - ret_pDeclaratorInfo.D.setCommaLoc(CommaLoc); - ColonProtectionRAIIObject ret_pX(*this); - Token ret_pToken; - ret_pToken.startToken(); - const char *ret_pId = "ret_p"; - ret_pToken.setLength(5); //length of ret_p - ret_pToken.setKind(tok::raw_identifier); - ret_pToken.setRawIdentifierData(ret_pId); - IdentifierInfo *II; - II = PP.getIdentifierInfo(StringRef(ret_pToken.getRawIdentifierData(),ret_pToken.getLength())); - ret_pToken.setIdentifierInfo(II); - ret_pToken.setKind(II->getTokenID()); - ret_pDeclaratorInfo.D.SetRangeEnd(Loc); - DeclSpec ret_pDS(AttrFactory); - ret_pDS.Finish(Diags,PP); - ret_pDeclaratorInfo.D.SetIdentifier(II,Loc); - // ここでConsumeToken()が入る。Kindはsemi(;)に。 - ret_pDeclaratorInfo.D.AddTypeInfo(DeclaratorChunk::getPointer(ret_pDS.getTypeQualifiers(), Loc,ret_pDS.getConstSpecLoc(), - ret_pDS.getVolatileSpecLoc(),ret_pDS.getRestrictSpecLoc()), - ret_pDS.getAttributes(),SourceLocation()); - Decl *Field = Actions.ActOnField(getCurScope(), TagDecl, - ret_pDeclaratorInfo.D.getDeclSpec().getSourceRange().getBegin(), - ret_pDeclaratorInfo.D, ret_pDeclaratorInfo.BitfieldSize); - FieldDecls.push_back(Field); - ret_pDeclaratorInfo.complete(Field); - // こっからjmp_buf(intのポインタ)の作成。 - ParsingDeclSpec jmp_bufPDS(*this); - - if (jmp_bufPDS.getSourceRange().isInvalid()) { - jmp_bufPDS.SetRangeStart(Loc); - jmp_bufPDS.SetRangeEnd(Loc); - } - DiagID = 0; - isInvalid = (jmp_bufPDS.SetTypeSpecType(DeclSpec::TST_int, Loc, PrevSpec, DiagID) || isInvalid); - jmp_bufPDS.SetRangeEnd(Loc); - jmp_bufPDS.Finish(Diags, PP); - jmp_bufPDS.getParsedSpecifiers(); - CommaLoc = SourceLocation(); - ParsingFieldDeclarator jmp_bufDeclaratorInfo(*this, jmp_bufPDS); - jmp_bufDeclaratorInfo.D.setCommaLoc(CommaLoc); - ColonProtectionRAIIObject env_pX(*this); - jmp_bufDeclaratorInfo.D.SetRangeEnd(Loc); - Token envToken; - envToken.startToken(); - const char *env_pId = "env"; - envToken.setLength(3); //length of env - envToken.setKind(tok::raw_identifier); - envToken.setRawIdentifierData(env_pId); - II = PP.getIdentifierInfo(StringRef(envToken.getRawIdentifierData(),envToken.getLength())); - envToken.setIdentifierInfo(II); - envToken.setKind(II->getTokenID()); - jmp_bufDeclaratorInfo.D.SetRangeEnd(Loc); - DeclSpec jmp_bufDS(AttrFactory); - jmp_bufDS.Finish(Diags,PP); - jmp_bufDeclaratorInfo.D.SetIdentifier(II,Loc); - // ここでConsumeToken()が入る。Kindはsemi(;)に。 - jmp_bufDeclaratorInfo.D.AddTypeInfo(DeclaratorChunk::getPointer(jmp_bufDS.getTypeQualifiers(), Loc,jmp_bufDS.getConstSpecLoc(), - jmp_bufDS.getVolatileSpecLoc(),jmp_bufDS.getRestrictSpecLoc()), - jmp_bufDS.getAttributes(),SourceLocation()); - Field = Actions.ActOnField(getCurScope(), TagDecl, - jmp_bufDeclaratorInfo.D.getDeclSpec().getSourceRange().getBegin(), - jmp_bufDeclaratorInfo.D, jmp_bufDeclaratorInfo.BitfieldSize); - FieldDecls.push_back(Field); - jmp_bufDeclaratorInfo.complete(Field); + + // create struct body (void* ret_p, int* env) + FieldDecls.push_back(Create__CbC_envBody(TagDecl, DeclSpec::TST_void, Loc, &isInvalid, PrevSpec, &DiagID, "ret_p", /* length of the name */ 5)); + FieldDecls.push_back(Create__CbC_envBody(TagDecl, DeclSpec::TST_int, Loc, &isInvalid, PrevSpec, &DiagID, "env", /* length of the name */ 3)); + Actions.ActOnFields(getCurScope(),Loc, TagDecl, FieldDecls,Loc, Loc,attrs.getList()); StructScope.Exit(); Actions.ActOnTagFinishDefinition(getCurScope(), TagDecl,Loc); @@ -5805,4 +5722,49 @@ Actions.ConvertDeclToDeclGroup(TheDecl); return isInvalid; } + +Decl* Parser::Create__CbC_envBody(Decl* TagDecl, DeclSpec::TST T, SourceLocation Loc, bool* isInvalid, + const char* PrevSpec, unsigned* DiagID, const char* Name, int NameLen){ + ParsingDeclSpec PDS(*this); + if (PDS.getSourceRange().isInvalid()) { + PDS.SetRangeStart(Loc); + PDS.SetRangeEnd(Loc); + } + *isInvalid = (PDS.SetTypeSpecType(T, Loc, PrevSpec, *DiagID) || *isInvalid); + PDS.SetRangeEnd(Loc); + + // star(*) + PDS.Finish(Diags, PP); + SourceLocation CommaLoc; + ParsingFieldDeclarator DeclaratorInfo(*this, PDS); + DeclaratorInfo.D.setCommaLoc(CommaLoc); + DeclaratorInfo.D.SetRangeEnd(Loc); + DeclSpec DS(AttrFactory); + DS.Finish(Diags,PP); + DeclaratorInfo.D.SetIdentifier(CreateIdentifierInfo(Name, NameLen),Loc); + // end of check star(*) + + DeclaratorInfo.D.AddTypeInfo(DeclaratorChunk::getPointer(DS.getTypeQualifiers(), Loc,DS.getConstSpecLoc(), + DS.getVolatileSpecLoc(),DS.getRestrictSpecLoc()), + DS.getAttributes(),SourceLocation()); + Decl *Field = Actions.ActOnField(getCurScope(), TagDecl, + DeclaratorInfo.D.getDeclSpec().getSourceRange().getBegin(), + DeclaratorInfo.D, DeclaratorInfo.BitfieldSize); + DeclaratorInfo.complete(Field); + return Field; +} + +IdentifierInfo* Parser::CreateIdentifierInfo(const char* Name, int NameLen) { + Token TokenForII; + TokenForII.startToken(); + TokenForII.setLength(NameLen); + TokenForII.setKind(tok::raw_identifier); + TokenForII.setRawIdentifierData(Name); + IdentifierInfo *II; + II = PP.getIdentifierInfo(StringRef(TokenForII.getRawIdentifierData(),TokenForII.getLength())); + TokenForII.setIdentifierInfo(II); + TokenForII.setKind(II->getTokenID()); + return II; +} + #endif