From: Daniel Dunbar Date: Tue, 5 Aug 2008 16:28:08 +0000 (+0000) Subject: Move AsmLabel into Declarator instead of just a parameter to X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=914701ed49f31323176a784b49df05a0d177d1ad;p=clang Move AsmLabel into Declarator instead of just a parameter to ActOnDeclarator. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54353 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Driver/PrintParserCallbacks.cpp b/Driver/PrintParserCallbacks.cpp index 2de16144d5..fec13e3909 100644 --- a/Driver/PrintParserCallbacks.cpp +++ b/Driver/PrintParserCallbacks.cpp @@ -30,7 +30,7 @@ namespace { /// and 'Init' specifies the initializer if any. This is for things like: /// "int X = 4" or "typedef int foo". virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D, - DeclTy *LastInGroup, ExprTy *AsmLabel) { + DeclTy *LastInGroup) { llvm::cout << __FUNCTION__ << " "; if (IdentifierInfo *II = D.getIdentifier()) { llvm::cout << "'" << II->getName() << "'"; @@ -40,7 +40,7 @@ namespace { llvm::cout << "\n"; // Pass up to EmptyActions so that the symbol table is maintained right. - return MinimalAction::ActOnDeclarator(S, D, LastInGroup, AsmLabel); + return MinimalAction::ActOnDeclarator(S, D, LastInGroup); } /// ActOnPopScope - This callback is called immediately before the specified /// scope is popped and deleted. diff --git a/include/clang/Parse/Action.h b/include/clang/Parse/Action.h index 4f7937a36c..2b6f713441 100644 --- a/include/clang/Parse/Action.h +++ b/include/clang/Parse/Action.h @@ -105,12 +105,7 @@ public: /// LastInGroup is non-null for cases where one declspec has multiple /// declarators on it. For example in 'int A, B', ActOnDeclarator will be /// called with LastInGroup=A when invoked for B. - /// - /// AsmLabel is non-null only for top-level function declarations - /// which use the GCC asm-label extension (the expression must be a - /// constant string). - virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup, - ExprTy *AsmLabel) { + virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D,DeclTy *LastInGroup) { return 0; } @@ -144,7 +139,7 @@ public: virtual DeclTy *ActOnStartOfFunctionDef(Scope *FnBodyScope, Declarator &D) { // Default to ActOnDeclarator. return ActOnStartOfFunctionDef(FnBodyScope, - ActOnDeclarator(FnBodyScope, D, 0, 0)); + ActOnDeclarator(FnBodyScope, D, 0)); } /// ActOnStartOfFunctionDef - This is called at the start of a function @@ -839,8 +834,7 @@ public: /// ActOnDeclarator - If this is a typedef declarator, we modify the /// IdentifierInfo::FETokenInfo field to keep track of this fact, until S is /// popped. - virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup, - ExprTy *AsmLabel); + virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup); /// ActOnPopScope - When a scope is popped, if any typedefs are now /// out-of-scope, they are removed from the IdentifierInfo::FETokenInfo field. diff --git a/include/clang/Parse/DeclSpec.h b/include/clang/Parse/DeclSpec.h index 68509145b9..979f0204c5 100644 --- a/include/clang/Parse/DeclSpec.h +++ b/include/clang/Parse/DeclSpec.h @@ -580,11 +580,16 @@ private: // InvalidType - Set by Sema::GetTypeForDeclarator(). bool InvalidType; - // attributes. + /// AttrList - Attributes. AttributeList *AttrList; + + /// AsmLabel - The asm label, if specified. + Action::ExprTy *AsmLabel; + public: Declarator(DeclSpec &ds, TheContext C) - : DS(ds), Identifier(0), Context(C), InvalidType(false), AttrList(0) { + : DS(ds), Identifier(0), Context(C), InvalidType(false), AttrList(0), + AsmLabel(0) { } ~Declarator() { @@ -694,7 +699,10 @@ public: } const AttributeList *getAttributes() const { return AttrList; } AttributeList *getAttributes() { return AttrList; } - + + void setAsmLabel(Action::ExprTy *E) { AsmLabel = E; } + Action::ExprTy *getAsmLabel() const { return AsmLabel; } + void setInvalidType(bool flag) { InvalidType = flag; } bool getInvalidType() const { return InvalidType; } }; diff --git a/lib/Parse/MinimalAction.cpp b/lib/Parse/MinimalAction.cpp index 352925535d..cb130c3d26 100644 --- a/lib/Parse/MinimalAction.cpp +++ b/lib/Parse/MinimalAction.cpp @@ -63,8 +63,7 @@ MinimalAction::isTypeName(const IdentifierInfo &II, Scope *S) { /// IdentifierInfo::FETokenInfo field to keep track of this fact, until S is /// popped. Action::DeclTy * -MinimalAction::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup, - ExprTy *AsmLabel) { +MinimalAction::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup) { IdentifierInfo *II = D.getIdentifier(); // If there is no identifier associated with this declarator, bail out. diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 33482c5700..1cf331702d 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -256,13 +256,14 @@ ParseInitDeclaratorListAfterFirstDeclarator(Declarator &D) { // rest of the init-declarator-list. while (1) { // If a simple-asm-expr is present, parse it. - ExprResult AsmLabel; if (Tok.is(tok::kw_asm)) { - AsmLabel = ParseSimpleAsm(); + ExprResult AsmLabel = ParseSimpleAsm(); if (AsmLabel.isInvalid) { SkipUntil(tok::semi); return 0; } + + D.setAsmLabel(AsmLabel.Val); } // If attributes are present, parse them. @@ -271,8 +272,7 @@ ParseInitDeclaratorListAfterFirstDeclarator(Declarator &D) { // Inform the current actions module that we just parsed this declarator. // FIXME: pass asm & attributes. - LastDeclInGroup = Actions.ActOnDeclarator(CurScope, D, LastDeclInGroup, - AsmLabel.Val); + LastDeclInGroup = Actions.ActOnDeclarator(CurScope, D, LastDeclInGroup); // Parse declarator '=' initializer. if (Tok.is(tok::equal)) { diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp index b18c7eb3d4..007970190b 100644 --- a/lib/Parse/ParseObjc.cpp +++ b/lib/Parse/ParseObjc.cpp @@ -1222,7 +1222,7 @@ Parser::StmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { ParseDeclarator(DeclaratorInfo); if (DeclaratorInfo.getIdentifier()) { DeclTy *aBlockVarDecl = Actions.ActOnDeclarator(CurScope, - DeclaratorInfo, 0, 0); + DeclaratorInfo, 0); StmtResult stmtResult = Actions.ActOnDeclStmt(aBlockVarDecl, DS.getSourceRange().getBegin(), diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index 864b464d5f..0fda782fcb 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -211,8 +211,7 @@ private: // Symbol table / Decl tracking callbacks: SemaDecl.cpp. // virtual TypeTy *isTypeName(const IdentifierInfo &II, Scope *S); - virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup, - ExprTy *AsmLabel); + virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup); virtual DeclTy *ActOnParamDeclarator(Scope *S, Declarator &D); virtual void ActOnParamDefaultArgument(DeclTy *param, SourceLocation EqualLoc, diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 64e62369e7..19a2c28e26 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -609,7 +609,7 @@ bool Sema::CheckInitializerTypes(Expr *&Init, QualType &DeclType) { } Sema::DeclTy * -Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl, ExprTy *AsmLabel) { +Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl) { ScopedDecl *LastDeclarator = dyn_cast_or_null((Decl *)lastDecl); IdentifierInfo *II = D.getIdentifier(); @@ -701,7 +701,7 @@ Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl, ExprTy *AsmLabe ProcessDeclAttributes(NewFD, D); // Handle GNU asm-label extension (encoded as an attribute). - if (Expr *E = (Expr*) AsmLabel) { + if (Expr *E = (Expr*) D.getAsmLabel()) { // The parser guarantees this is a string. StringLiteral *SE = cast(E); NewFD->addAttr(new AsmLabelAttr(std::string(SE->getStrData(), @@ -1577,7 +1577,7 @@ Sema::DeclTy *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Declarator &D) { } return ActOnStartOfFunctionDef(FnBodyScope, - ActOnDeclarator(GlobalScope, D, 0, 0)); + ActOnDeclarator(GlobalScope, D, 0)); } Sema::DeclTy *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, DeclTy *D) { @@ -1669,7 +1669,7 @@ ScopedDecl *Sema::ImplicitlyDefineFunction(SourceLocation Loc, CurContext = Context.getTranslationUnitDecl(); FunctionDecl *FD = - dyn_cast(static_cast(ActOnDeclarator(TUScope, D, 0, 0))); + dyn_cast(static_cast(ActOnDeclarator(TUScope, D, 0))); FD->setImplicit(); CurContext = PrevDC; diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index d5603166d8..9dc62dcc4a 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -371,7 +371,7 @@ Sema::ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, Declarator &D, if (isInstField) Member = static_cast(ActOnField(S, Loc, D, BitWidth)); else - Member = static_cast(ActOnDeclarator(S, D, LastInGroup, 0)); + Member = static_cast(ActOnDeclarator(S, D, LastInGroup)); if (!Member) return LastInGroup;