From: Chris Lattner Date: Sat, 28 Mar 2009 19:18:32 +0000 (+0000) Subject: Introduce a new OpaquePtr struct type, which is a simple POD wrapper for a X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2;p=clang Introduce a new OpaquePtr struct type, which is a simple POD wrapper for a pointer. Its purpose in life is to be a glorified void*, but which does not implicitly convert to void* or other OpaquePtr's with a different UID. Introduce Action::DeclPtrTy which is a typedef for OpaquePtr<0>. Change the entire parser/sema interface to use DeclPtrTy instead of DeclTy*. This makes the C++ compiler enforce that these aren't convertible to other opaque types. We should also convert ExprTy, StmtTy, TypeTy, AttrTy, BaseTy, etc, but I don't plan to do that in the short term. The one outstanding known problem with this patch is that we lose the bitmangling optimization where ActionResult doesn't know how to bitmangle the success bit into the low bit of DeclPtrTy. I will rectify this with a subsequent patch. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67952 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Parse/Action.h b/include/clang/Parse/Action.h index 2f4d283950..f758d05792 100644 --- a/include/clang/Parse/Action.h +++ b/include/clang/Parse/Action.h @@ -47,7 +47,7 @@ namespace clang { template<> struct IsResultPtrLowBitFree<1> { static const bool value = true;}; template<> struct IsResultPtrLowBitFree<3> { static const bool value = true;}; template<> struct IsResultPtrLowBitFree<4> { static const bool value = true;}; - + /// Action - As the parser reads the input file and recognizes the productions /// of the grammar, it invokes methods on this class to turn the parsed input /// into something useful: e.g. a parse tree. @@ -69,7 +69,7 @@ public: // what types are required to be identical for the actions. typedef ActionBase::ExprTy ExprTy; typedef ActionBase::StmtTy StmtTy; - typedef void DeclTy; + typedef OpaquePtr<0> DeclPtrTy; typedef void TypeTy; typedef void AttrTy; typedef void BaseTy; @@ -85,7 +85,7 @@ public: typedef ActionResult<2> TypeResult; typedef ActionResult<3> BaseResult; typedef ActionResult<4> MemInitResult; - typedef ActionResult<5> DeclResult; + typedef ActionResult<5, DeclPtrTy> DeclResult; /// Same, but with ownership. typedef ASTOwningResult<&ActionBase::DeleteExpr> OwningExprResult; @@ -123,7 +123,7 @@ public: /// getDeclName - Return a pretty name for the specified decl if possible, or /// an empty string if not. This is used for pretty crash reporting. - virtual std::string getDeclName(DeclTy *D) { return ""; } + virtual std::string getDeclName(DeclPtrTy D) { return ""; } //===--------------------------------------------------------------------===// // Declaration Tracking Callbacks. @@ -134,7 +134,7 @@ public: /// An optional CXXScopeSpec can be passed to indicate the C++ scope (class or /// namespace) that the identifier must be a member of. /// i.e. for "foo::bar", 'II' will be "bar" and 'SS' will be "foo::". - virtual DeclTy *getTypeName(IdentifierInfo &II, SourceLocation NameLoc, + virtual TypeTy *getTypeName(IdentifierInfo &II, SourceLocation NameLoc, Scope *S, const CXXScopeSpec *SS = 0) = 0; /// isCurrentClassName - Return true if the specified name is the @@ -148,7 +148,7 @@ public: /// optional CXXScope can be passed to indicate the C++ scope in /// which the identifier will be found. virtual TemplateNameKind isTemplateName(IdentifierInfo &II, Scope *S, - DeclTy *&TemplateDecl, + DeclPtrTy &TemplateDecl, const CXXScopeSpec *SS = 0) = 0; /// ActOnCXXGlobalScopeSpecifier - Return the object that represents the @@ -212,16 +212,17 @@ 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. - virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D,DeclTy *LastInGroup) { - return 0; + virtual DeclPtrTy ActOnDeclarator(Scope *S, Declarator &D, + DeclPtrTy LastInGroup) { + return DeclPtrTy(); } /// ActOnParamDeclarator - This callback is invoked when a parameter /// declarator is parsed. This callback only occurs for functions /// with prototypes. S is the function prototype scope for the /// parameters (C++ [basic.scope.proto]). - virtual DeclTy *ActOnParamDeclarator(Scope *S, Declarator &D) { - return 0; + virtual DeclPtrTy ActOnParamDeclarator(Scope *S, Declarator &D) { + return DeclPtrTy(); } /// AddInitializerToDecl - This action is called immediately after @@ -231,7 +232,7 @@ public: /// This allows ActOnDeclarator to register "xx" prior to parsing the /// initializer. The declaration above should still result in a warning, /// since the reference to "xx" is uninitialized. - virtual void AddInitializerToDecl(DeclTy *Dcl, ExprArg Init) { + virtual void AddInitializerToDecl(DeclPtrTy Dcl, ExprArg Init) { return; } @@ -239,19 +240,19 @@ public: /// if =delete is parsed. C++0x [dcl.fct.def]p10 /// Note that this can be called even for variable declarations. It's the /// action's job to reject it. - virtual void SetDeclDeleted(DeclTy *Dcl, SourceLocation DelLoc) { + virtual void SetDeclDeleted(DeclPtrTy Dcl, SourceLocation DelLoc) { return; } /// ActOnUninitializedDecl - This action is called immediately after /// ActOnDeclarator (when an initializer is *not* present). - virtual void ActOnUninitializedDecl(DeclTy *Dcl) { + virtual void ActOnUninitializedDecl(DeclPtrTy Dcl) { return; } /// FinalizeDeclaratorGroup - After a sequence of declarators are parsed, this /// gives the actions implementation a chance to process the group as a whole. - virtual DeclTy *FinalizeDeclaratorGroup(Scope *S, DeclTy *Group) { + virtual DeclPtrTy FinalizeDeclaratorGroup(Scope *S, DeclPtrTy Group) { return Group; } @@ -265,30 +266,31 @@ public: /// ActOnStartOfFunctionDef - This is called at the start of a function /// definition, instead of calling ActOnDeclarator. The Declarator includes /// information about formal arguments that are part of this function. - virtual DeclTy *ActOnStartOfFunctionDef(Scope *FnBodyScope, Declarator &D) { + virtual DeclPtrTy ActOnStartOfFunctionDef(Scope *FnBodyScope, Declarator &D) { // Default to ActOnDeclarator. return ActOnStartOfFunctionDef(FnBodyScope, - ActOnDeclarator(FnBodyScope, D, 0)); + ActOnDeclarator(FnBodyScope, D,DeclPtrTy())); } /// ActOnStartOfFunctionDef - This is called at the start of a function /// definition, after the FunctionDecl has already been created. - virtual DeclTy *ActOnStartOfFunctionDef(Scope *FnBodyScope, DeclTy *D) { + virtual DeclPtrTy ActOnStartOfFunctionDef(Scope *FnBodyScope, DeclPtrTy D) { return D; } - virtual void ActOnStartOfObjCMethodDef(Scope *FnBodyScope, DeclTy *D) { + virtual void ActOnStartOfObjCMethodDef(Scope *FnBodyScope, DeclPtrTy D) { return; } /// ActOnFinishFunctionBody - This is called when a function body has - /// completed parsing. Decl is the DeclTy returned by ParseStartOfFunctionDef. - virtual DeclTy *ActOnFinishFunctionBody(DeclTy *Decl, StmtArg Body) { + /// completed parsing. Decl is returned by ParseStartOfFunctionDef. + virtual DeclPtrTy ActOnFinishFunctionBody(DeclPtrTy Decl, StmtArg Body) { return Decl; } - virtual DeclTy *ActOnFileScopeAsmDecl(SourceLocation Loc, ExprArg AsmString) { - return 0; + virtual DeclPtrTy ActOnFileScopeAsmDecl(SourceLocation Loc, + ExprArg AsmString) { + return DeclPtrTy(); } /// ActOnPopScope - This callback is called immediately before the specified @@ -301,8 +303,8 @@ public: /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with /// no declarator (e.g. "struct foo;") is parsed. - virtual DeclTy *ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS) { - return 0; + virtual DeclPtrTy ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS) { + return DeclPtrTy(); } /// ActOnStartLinkageSpecification - Parsed the beginning of a C++ @@ -312,22 +314,22 @@ public: /// by Lang/StrSize. LBraceLoc, if valid, provides the location of /// the '{' brace. Otherwise, this linkage specification does not /// have any braces. - virtual DeclTy *ActOnStartLinkageSpecification(Scope *S, - SourceLocation ExternLoc, - SourceLocation LangLoc, - const char *Lang, - unsigned StrSize, - SourceLocation LBraceLoc) { - return 0; + virtual DeclPtrTy ActOnStartLinkageSpecification(Scope *S, + SourceLocation ExternLoc, + SourceLocation LangLoc, + const char *Lang, + unsigned StrSize, + SourceLocation LBraceLoc) { + return DeclPtrTy(); } /// ActOnFinishLinkageSpecification - Completely the definition of /// the C++ linkage specification LinkageSpec. If RBraceLoc is /// valid, it's the position of the closing '}' brace in a linkage /// specification that uses braces. - virtual DeclTy *ActOnFinishLinkageSpecification(Scope *S, - DeclTy *LinkageSpec, - SourceLocation RBraceLoc) { + virtual DeclPtrTy ActOnFinishLinkageSpecification(Scope *S, + DeclPtrTy LinkageSpec, + SourceLocation RBraceLoc) { return LinkageSpec; } @@ -342,7 +344,7 @@ public: /// ActOnTypeName - A type-name (type-id in C++) was parsed. virtual TypeResult ActOnTypeName(Scope *S, Declarator &D) { - return 0; + return TypeResult(); } enum TagKind { @@ -350,53 +352,54 @@ public: TK_Declaration, // Fwd decl of a tag: 'struct foo;' TK_Definition // Definition of a tag: 'struct foo { int X; } Y;' }; - virtual DeclTy *ActOnTag(Scope *S, unsigned TagSpec, TagKind TK, - SourceLocation KWLoc, const CXXScopeSpec &SS, - IdentifierInfo *Name, SourceLocation NameLoc, - AttributeList *Attr, AccessSpecifier AS) { + virtual DeclPtrTy ActOnTag(Scope *S, unsigned TagSpec, TagKind TK, + SourceLocation KWLoc, const CXXScopeSpec &SS, + IdentifierInfo *Name, SourceLocation NameLoc, + AttributeList *Attr, AccessSpecifier AS) { // TagType is an instance of DeclSpec::TST, indicating what kind of tag this // is (struct/union/enum/class). - return 0; + return DeclPtrTy(); } /// Act on @defs() element found when parsing a structure. ClassName is the /// name of the referenced class. - virtual void ActOnDefs(Scope *S, DeclTy *TagD, SourceLocation DeclStart, + virtual void ActOnDefs(Scope *S, DeclPtrTy TagD, SourceLocation DeclStart, IdentifierInfo *ClassName, - llvm::SmallVectorImpl &Decls) {} - virtual DeclTy *ActOnField(Scope *S, DeclTy *TagD, SourceLocation DeclStart, - Declarator &D, ExprTy *BitfieldWidth) { - return 0; + llvm::SmallVectorImpl &Decls) {} + virtual DeclPtrTy ActOnField(Scope *S, DeclPtrTy TagD, + SourceLocation DeclStart, + Declarator &D, ExprTy *BitfieldWidth) { + return DeclPtrTy(); } - virtual DeclTy *ActOnIvar(Scope *S, SourceLocation DeclStart, - Declarator &D, ExprTy *BitfieldWidth, - tok::ObjCKeywordKind visibility) { - return 0; + virtual DeclPtrTy ActOnIvar(Scope *S, SourceLocation DeclStart, + Declarator &D, ExprTy *BitfieldWidth, + tok::ObjCKeywordKind visibility) { + return DeclPtrTy(); } - virtual void ActOnFields(Scope* S, SourceLocation RecLoc, DeclTy *TagDecl, - DeclTy **Fields, unsigned NumFields, + virtual void ActOnFields(Scope* S, SourceLocation RecLoc, DeclPtrTy TagDecl, + DeclPtrTy *Fields, unsigned NumFields, SourceLocation LBrac, SourceLocation RBrac, AttributeList *AttrList) {} /// ActOnTagStartDefinition - Invoked when we have entered the /// scope of a tag's definition (e.g., for an enumeration, class, /// struct, or union). - virtual void ActOnTagStartDefinition(Scope *S, DeclTy *TagDecl) { } + virtual void ActOnTagStartDefinition(Scope *S, DeclPtrTy TagDecl) { } /// ActOnTagFinishDefinition - Invoked once we have finished parsing /// the definition of a tag (enumeration, class, struct, or union). - virtual void ActOnTagFinishDefinition(Scope *S, DeclTy *TagDecl) { } + virtual void ActOnTagFinishDefinition(Scope *S, DeclPtrTy TagDecl) { } - virtual DeclTy *ActOnEnumConstant(Scope *S, DeclTy *EnumDecl, - DeclTy *LastEnumConstant, - SourceLocation IdLoc, IdentifierInfo *Id, - SourceLocation EqualLoc, ExprTy *Val) { - return 0; + virtual DeclPtrTy ActOnEnumConstant(Scope *S, DeclPtrTy EnumDecl, + DeclPtrTy LastEnumConstant, + SourceLocation IdLoc, IdentifierInfo *Id, + SourceLocation EqualLoc, ExprTy *Val) { + return DeclPtrTy(); } - virtual void ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDecl, - DeclTy **Elements, unsigned NumElements) {} + virtual void ActOnEnumBody(SourceLocation EnumLoc, DeclPtrTy EnumDecl, + DeclPtrTy *Elements, unsigned NumElements) {} //===--------------------------------------------------------------------===// // Statement Parsing Callbacks. @@ -411,8 +414,8 @@ public: bool isStmtExpr) { return StmtEmpty(); } - virtual OwningStmtResult ActOnDeclStmt(DeclTy *Decl, SourceLocation StartLoc, - SourceLocation EndLoc) { + virtual OwningStmtResult ActOnDeclStmt(DeclPtrTy Decl,SourceLocation StartLoc, + SourceLocation EndLoc) { return StmtEmpty(); } @@ -521,7 +524,7 @@ public: // Objective-c statements virtual OwningStmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen, - DeclTy *Parm, StmtArg Body, + DeclPtrTy Parm, StmtArg Body, StmtArg CatchList) { return StmtEmpty(); } @@ -550,12 +553,12 @@ public: } // C++ Statements - virtual DeclTy *ActOnExceptionDeclarator(Scope *S, Declarator &D) { - return 0; + virtual DeclPtrTy ActOnExceptionDeclarator(Scope *S, Declarator &D) { + return DeclPtrTy(); } virtual OwningStmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc, - DeclTy *ExceptionDecl, + DeclPtrTy ExceptionDecl, StmtArg HandlerBlock) { return StmtEmpty(); } @@ -658,7 +661,7 @@ public: tok::TokenKind OpKind, SourceLocation MemberLoc, IdentifierInfo &Member, - DeclTy *ObjCImpDecl) { + DeclPtrTy ObjCImpDecl) { return ExprEmpty(); } @@ -821,40 +824,40 @@ public: /// ActOnStartNamespaceDef - This is called at the start of a namespace /// definition. - virtual DeclTy *ActOnStartNamespaceDef(Scope *S, SourceLocation IdentLoc, - IdentifierInfo *Ident, - SourceLocation LBrace) { - return 0; + virtual DeclPtrTy ActOnStartNamespaceDef(Scope *S, SourceLocation IdentLoc, + IdentifierInfo *Ident, + SourceLocation LBrace) { + return DeclPtrTy(); } /// ActOnFinishNamespaceDef - This callback is called after a namespace is - /// exited. Decl is the DeclTy returned by ActOnStartNamespaceDef. - virtual void ActOnFinishNamespaceDef(DeclTy *Dcl,SourceLocation RBrace) { + /// exited. Decl is returned by ActOnStartNamespaceDef. + virtual void ActOnFinishNamespaceDef(DeclPtrTy Dcl, SourceLocation RBrace) { return; } /// ActOnUsingDirective - This is called when using-directive is parsed. - virtual DeclTy *ActOnUsingDirective(Scope *CurScope, - SourceLocation UsingLoc, - SourceLocation NamespcLoc, - const CXXScopeSpec &SS, - SourceLocation IdentLoc, - IdentifierInfo *NamespcName, - AttributeList *AttrList); + virtual DeclPtrTy ActOnUsingDirective(Scope *CurScope, + SourceLocation UsingLoc, + SourceLocation NamespcLoc, + const CXXScopeSpec &SS, + SourceLocation IdentLoc, + IdentifierInfo *NamespcName, + AttributeList *AttrList); /// ActOnNamespaceAliasDef - This is called when a namespace alias definition /// is parsed. - virtual DeclTy *ActOnNamespaceAliasDef(Scope *CurScope, - SourceLocation AliasLoc, - IdentifierInfo *Alias, - const CXXScopeSpec &SS, - SourceLocation NamespaceLoc, - IdentifierInfo *NamespaceName) { - return 0; + virtual DeclPtrTy ActOnNamespaceAliasDef(Scope *CurScope, + SourceLocation AliasLoc, + IdentifierInfo *Alias, + const CXXScopeSpec &SS, + SourceLocation NamespaceLoc, + IdentifierInfo *NamespaceName) { + return DeclPtrTy(); } /// ActOnParamDefaultArgument - Parse default argument for function parameter - virtual void ActOnParamDefaultArgument(DeclTy *param, + virtual void ActOnParamDefaultArgument(DeclPtrTy param, SourceLocation EqualLoc, ExprArg defarg) { } @@ -863,17 +866,17 @@ public: /// argument for a function parameter, but we can't parse it yet /// because we're inside a class definition. Note that this default /// argument will be parsed later. - virtual void ActOnParamUnparsedDefaultArgument(DeclTy *param, + virtual void ActOnParamUnparsedDefaultArgument(DeclPtrTy param, SourceLocation EqualLoc) { } /// ActOnParamDefaultArgumentError - Parsing or semantic analysis of /// the default argument for the parameter param failed. - virtual void ActOnParamDefaultArgumentError(DeclTy *param) { } + virtual void ActOnParamDefaultArgumentError(DeclPtrTy param) { } /// AddCXXDirectInitializerToDecl - This action is called immediately after /// ActOnDeclarator, when a C++ direct initializer is present. /// e.g: "int x(1);" - virtual void AddCXXDirectInitializerToDecl(DeclTy *Dcl, + virtual void AddCXXDirectInitializerToDecl(DeclPtrTy Dcl, SourceLocation LParenLoc, MultiExprArg Exprs, SourceLocation *CommaLocs, @@ -889,7 +892,8 @@ public: /// Method declaration as if we had just parsed the qualified method /// name. However, it should not bring the parameters into scope; /// that will be performed by ActOnDelayedCXXMethodParameter. - virtual void ActOnStartDelayedCXXMethodDeclaration(Scope *S, DeclTy *Method) { + virtual void ActOnStartDelayedCXXMethodDeclaration(Scope *S, + DeclPtrTy Method) { } /// ActOnDelayedCXXMethodParameter - We've already started a delayed @@ -897,7 +901,7 @@ public: /// function parameter into scope for use in parsing later parts of /// the method declaration. For example, we could see an /// ActOnParamDefaultArgument event for this parameter. - virtual void ActOnDelayedCXXMethodParameter(Scope *S, DeclTy *Param) { + virtual void ActOnDelayedCXXMethodParameter(Scope *S, DeclPtrTy Param) { } /// ActOnFinishDelayedCXXMethodDeclaration - We have finished @@ -906,14 +910,15 @@ public: /// ActOnStartOfFunctionDef action later (not necessarily /// immediately!) for this method, if it was also defined inside the /// class body. - virtual void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, DeclTy *Method){ + virtual void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, + DeclPtrTy Method) { } /// ActOnStaticAssertDeclaration - Parse a C++0x static_assert declaration. - virtual DeclTy *ActOnStaticAssertDeclaration(SourceLocation AssertLoc, - ExprArg AssertExpr, - ExprArg AssertMessageExpr) { - return 0; + virtual DeclPtrTy ActOnStaticAssertDeclaration(SourceLocation AssertLoc, + ExprArg AssertExpr, + ExprArg AssertMessageExpr) { + return DeclPtrTy(); } @@ -1014,7 +1019,7 @@ public: //===---------------------------- C++ Classes ---------------------------===// /// ActOnBaseSpecifier - Parsed a base specifier - virtual BaseResult ActOnBaseSpecifier(DeclTy *classdecl, + virtual BaseResult ActOnBaseSpecifier(DeclPtrTy classdecl, SourceRange SpecifierRange, bool Virtual, AccessSpecifier Access, TypeTy *basetype, @@ -1022,7 +1027,7 @@ public: return 0; } - virtual void ActOnBaseSpecifiers(DeclTy *ClassDecl, BaseTy **Bases, + virtual void ActOnBaseSpecifiers(DeclPtrTy ClassDecl, BaseTy **Bases, unsigned NumBases) { } @@ -1031,13 +1036,15 @@ public: /// specifies the bitfield width if there is one and 'Init' specifies the /// initializer if any. 'LastInGroup' is non-null for cases where one declspec /// has multiple declarators on it. - virtual DeclTy *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, - Declarator &D, ExprTy *BitfieldWidth, - ExprTy *Init, DeclTy *LastInGroup) { - return 0; + virtual DeclPtrTy ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, + Declarator &D, + ExprTy *BitfieldWidth, + ExprTy *Init, + DeclPtrTy LastInGroup) { + return DeclPtrTy(); } - virtual MemInitResult ActOnMemInitializer(DeclTy *ConstructorDecl, + virtual MemInitResult ActOnMemInitializer(DeclPtrTy ConstructorDecl, Scope *S, IdentifierInfo *MemberOrBase, SourceLocation IdLoc, @@ -1054,15 +1061,15 @@ public: /// a well-formed program), ColonLoc is the location of the ':' that /// starts the constructor initializer, and MemInit/NumMemInits /// contains the individual member (and base) initializers. - virtual void ActOnMemInitializers(DeclTy *ConstructorDecl, + virtual void ActOnMemInitializers(DeclPtrTy ConstructorDecl, SourceLocation ColonLoc, - MemInitTy **MemInits, unsigned NumMemInits) { + MemInitTy **MemInits, unsigned NumMemInits){ } /// ActOnFinishCXXMemberSpecification - Invoked after all member declarators /// are parsed but *before* parsing of inline method definitions. virtual void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc, - DeclTy *TagDecl, + DeclPtrTy TagDecl, SourceLocation LBrac, SourceLocation RBrac) { } @@ -1081,17 +1088,17 @@ public: /// the number of enclosing templates (see /// ActOnTemplateParameterList) and the number of previous /// parameters within this template parameter list. - virtual DeclTy *ActOnTypeParameter(Scope *S, bool Typename, - SourceLocation KeyLoc, - IdentifierInfo *ParamName, - SourceLocation ParamNameLoc, - unsigned Depth, unsigned Position) { - return 0; + virtual DeclPtrTy ActOnTypeParameter(Scope *S, bool Typename, + SourceLocation KeyLoc, + IdentifierInfo *ParamName, + SourceLocation ParamNameLoc, + unsigned Depth, unsigned Position) { + return DeclPtrTy(); } /// ActOnTypeParameterDefault - Adds a default argument (the type /// Default) to the given template type parameter (TypeParam). - virtual void ActOnTypeParameterDefault(DeclTy *TypeParam, + virtual void ActOnTypeParameterDefault(DeclPtrTy TypeParam, SourceLocation EqualLoc, SourceLocation DefaultLoc, TypeTy *Default) { @@ -1104,15 +1111,15 @@ public: /// enclosing templates (see /// ActOnTemplateParameterList) and the number of previous /// parameters within this template parameter list. - virtual DeclTy *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, - unsigned Depth, - unsigned Position) { - return 0; + virtual DeclPtrTy ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, + unsigned Depth, + unsigned Position) { + return DeclPtrTy(); } /// \brief Adds a default argument to the given non-type template /// parameter. - virtual void ActOnNonTypeTemplateParameterDefault(DeclTy *TemplateParam, + virtual void ActOnNonTypeTemplateParameterDefault(DeclPtrTy TemplateParam, SourceLocation EqualLoc, ExprArg Default) { } @@ -1123,19 +1130,19 @@ public: /// TemplateParams is the sequence of parameters required by the template, /// ParamName is the name of the parameter (null if unnamed), and ParamNameLoc /// is the source location of the identifier (if given). - virtual DeclTy *ActOnTemplateTemplateParameter(Scope *S, - SourceLocation TmpLoc, - TemplateParamsTy *Params, - IdentifierInfo *ParamName, - SourceLocation ParamNameLoc, - unsigned Depth, - unsigned Position) { - return 0; + virtual DeclPtrTy ActOnTemplateTemplateParameter(Scope *S, + SourceLocation TmpLoc, + TemplateParamsTy *Params, + IdentifierInfo *ParamName, + SourceLocation ParamNameLoc, + unsigned Depth, + unsigned Position) { + return DeclPtrTy(); } /// \brief Adds a default argument to the given template template /// parameter. - virtual void ActOnTemplateTemplateParameterDefault(DeclTy *TemplateParam, + virtual void ActOnTemplateTemplateParameterDefault(DeclPtrTy TemplateParam, SourceLocation EqualLoc, ExprArg Default) { } @@ -1174,7 +1181,7 @@ public: SourceLocation ExportLoc, SourceLocation TemplateLoc, SourceLocation LAngleLoc, - DeclTy **Params, unsigned NumParams, + DeclPtrTy *Params, unsigned NumParams, SourceLocation RAngleLoc) { return 0; } @@ -1188,7 +1195,7 @@ public: AttributeList *Attr, MultiTemplateParamsArg TemplateParameterLists, AccessSpecifier AS) { - return 0; + return DeclResult(); } /// \brief Form a class template specialization from a template and @@ -1204,14 +1211,14 @@ public: /// \param IsSpecialization true when we are naming the class /// template specialization as part of an explicit class /// specialization or class template partial specialization. - virtual TypeResult ActOnClassTemplateId(DeclTy *Template, + virtual TypeResult ActOnClassTemplateId(DeclPtrTy Template, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ASTTemplateArgsPtr TemplateArgs, SourceLocation *TemplateArgLocs, SourceLocation RAngleLoc, const CXXScopeSpec *SS) { - return 0; + return TypeResult(); }; /// \brief Process the declaration or definition of an explicit @@ -1264,7 +1271,7 @@ public: ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagKind TK, SourceLocation KWLoc, const CXXScopeSpec &SS, - DeclTy *Template, + DeclPtrTy Template, SourceLocation TemplateNameLoc, SourceLocation LAngleLoc, ASTTemplateArgsPtr TemplateArgs, @@ -1272,7 +1279,7 @@ public: SourceLocation RAngleLoc, AttributeList *Attr, MultiTemplateParamsArg TemplateParameterLists) { - return 0; + return DeclResult(); } /// \brief Called when the parser has parsed a C++ typename @@ -1285,7 +1292,7 @@ public: virtual TypeResult ActOnTypenameType(SourceLocation TypenameLoc, const CXXScopeSpec &SS, const IdentifierInfo &II, SourceLocation IdLoc) { - return 0; + return TypeResult(); } //===----------------------- Obj-C Declarations -------------------------===// @@ -1293,89 +1300,89 @@ public: // ActOnStartClassInterface - this action is called immediately after parsing // the prologue for a class interface (before parsing the instance // variables). Instance variables are processed by ActOnFields(). - virtual DeclTy *ActOnStartClassInterface(SourceLocation AtInterfaceLoc, - IdentifierInfo *ClassName, - SourceLocation ClassLoc, - IdentifierInfo *SuperName, - SourceLocation SuperLoc, - DeclTy * const *ProtoRefs, - unsigned NumProtoRefs, - SourceLocation EndProtoLoc, - AttributeList *AttrList) { - return 0; + virtual DeclPtrTy ActOnStartClassInterface(SourceLocation AtInterfaceLoc, + IdentifierInfo *ClassName, + SourceLocation ClassLoc, + IdentifierInfo *SuperName, + SourceLocation SuperLoc, + const DeclPtrTy *ProtoRefs, + unsigned NumProtoRefs, + SourceLocation EndProtoLoc, + AttributeList *AttrList) { + return DeclPtrTy(); } /// ActOnCompatiblityAlias - this action is called after complete parsing of /// @compaatibility_alias declaration. It sets up the alias relationships. - virtual DeclTy *ActOnCompatiblityAlias( + virtual DeclPtrTy ActOnCompatiblityAlias( SourceLocation AtCompatibilityAliasLoc, IdentifierInfo *AliasName, SourceLocation AliasLocation, IdentifierInfo *ClassName, SourceLocation ClassLocation) { - return 0; + return DeclPtrTy(); } // ActOnStartProtocolInterface - this action is called immdiately after // parsing the prologue for a protocol interface. - virtual DeclTy *ActOnStartProtocolInterface(SourceLocation AtProtoLoc, - IdentifierInfo *ProtocolName, - SourceLocation ProtocolLoc, - DeclTy * const *ProtoRefs, - unsigned NumProtoRefs, - SourceLocation EndProtoLoc, - AttributeList *AttrList) { - return 0; + virtual DeclPtrTy ActOnStartProtocolInterface(SourceLocation AtProtoLoc, + IdentifierInfo *ProtocolName, + SourceLocation ProtocolLoc, + const DeclPtrTy *ProtoRefs, + unsigned NumProtoRefs, + SourceLocation EndProtoLoc, + AttributeList *AttrList) { + return DeclPtrTy(); } // ActOnStartCategoryInterface - this action is called immdiately after // parsing the prologue for a category interface. - virtual DeclTy *ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc, - IdentifierInfo *ClassName, - SourceLocation ClassLoc, - IdentifierInfo *CategoryName, - SourceLocation CategoryLoc, - DeclTy * const *ProtoRefs, - unsigned NumProtoRefs, - SourceLocation EndProtoLoc) { - return 0; + virtual DeclPtrTy ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc, + IdentifierInfo *ClassName, + SourceLocation ClassLoc, + IdentifierInfo *CategoryName, + SourceLocation CategoryLoc, + const DeclPtrTy *ProtoRefs, + unsigned NumProtoRefs, + SourceLocation EndProtoLoc) { + return DeclPtrTy(); } // ActOnStartClassImplementation - this action is called immdiately after // parsing the prologue for a class implementation. Instance variables are // processed by ActOnFields(). - virtual DeclTy *ActOnStartClassImplementation( + virtual DeclPtrTy ActOnStartClassImplementation( SourceLocation AtClassImplLoc, IdentifierInfo *ClassName, SourceLocation ClassLoc, IdentifierInfo *SuperClassname, SourceLocation SuperClassLoc) { - return 0; + return DeclPtrTy(); } // ActOnStartCategoryImplementation - this action is called immdiately after // parsing the prologue for a category implementation. - virtual DeclTy *ActOnStartCategoryImplementation( + virtual DeclPtrTy ActOnStartCategoryImplementation( SourceLocation AtCatImplLoc, IdentifierInfo *ClassName, SourceLocation ClassLoc, IdentifierInfo *CatName, SourceLocation CatLoc) { - return 0; + return DeclPtrTy(); } // ActOnPropertyImplDecl - called for every property implementation - virtual DeclTy *ActOnPropertyImplDecl( + virtual DeclPtrTy ActOnPropertyImplDecl( SourceLocation AtLoc, // location of the @synthesize/@dynamic SourceLocation PropertyNameLoc, // location for the property name bool ImplKind, // true for @synthesize, false for // @dynamic - DeclTy *ClassImplDecl, // class or category implementation + DeclPtrTy ClassImplDecl, // class or category implementation IdentifierInfo *propertyId, // name of property IdentifierInfo *propertyIvar) { // name of the ivar - return 0; + return DeclPtrTy(); } // ActOnMethodDeclaration - called for all method declarations. - virtual DeclTy *ActOnMethodDeclaration( + virtual DeclPtrTy ActOnMethodDeclaration( SourceLocation BeginLoc, // location of the + or -. SourceLocation EndLoc, // location of the ; or {. tok::TokenKind MethodType, // tok::minus for instance, tok::plus for class. - DeclTy *ClassDecl, // class this methods belongs to. + DeclPtrTy ClassDecl, // class this methods belongs to. ObjCDeclSpec &ReturnQT, // for return type's in inout etc. TypeTy *ReturnType, // the method return type. Selector Sel, // a unique name for the method. @@ -1387,31 +1394,30 @@ public: // tok::objc_not_keyword, tok::objc_optional, tok::objc_required tok::ObjCKeywordKind impKind, bool isVariadic = false) { - return 0; + return DeclPtrTy(); } // ActOnAtEnd - called to mark the @end. For declarations (interfaces, // protocols, categories), the parser passes all methods/properties. // For class implementations, these values default to 0. For implementations, // methods are processed incrementally (by ActOnMethodDeclaration above). - virtual void ActOnAtEnd( - SourceLocation AtEndLoc, - DeclTy *classDecl, - DeclTy **allMethods = 0, - unsigned allNum = 0, - DeclTy **allProperties = 0, - unsigned pNum = 0, - DeclTy **allTUVars = 0, - unsigned tuvNum = 0) { + virtual void ActOnAtEnd(SourceLocation AtEndLoc, + DeclPtrTy classDecl, + DeclPtrTy *allMethods = 0, + unsigned allNum = 0, + DeclPtrTy *allProperties = 0, + unsigned pNum = 0, + DeclPtrTy *allTUVars = 0, + unsigned tuvNum = 0) { return; } // ActOnProperty - called to build one property AST - virtual DeclTy *ActOnProperty (Scope *S, SourceLocation AtLoc, - FieldDeclarator &FD, ObjCDeclSpec &ODS, - Selector GetterSel, Selector SetterSel, - DeclTy *ClassCategory, - bool *OverridingProperty, - tok::ObjCKeywordKind MethodImplKind) { - return 0; + virtual DeclPtrTy ActOnProperty(Scope *S, SourceLocation AtLoc, + FieldDeclarator &FD, ObjCDeclSpec &ODS, + Selector GetterSel, Selector SetterSel, + DeclPtrTy ClassCategory, + bool *OverridingProperty, + tok::ObjCKeywordKind MethodImplKind) { + return DeclPtrTy(); } virtual OwningExprResult ActOnClassPropertyRefExpr( @@ -1444,18 +1450,18 @@ public: ExprTy **ArgExprs, unsigned NumArgs) { return 0; } - virtual DeclTy *ActOnForwardClassDeclaration( + virtual DeclPtrTy ActOnForwardClassDeclaration( SourceLocation AtClassLoc, IdentifierInfo **IdentList, unsigned NumElts) { - return 0; + return DeclPtrTy(); } - virtual DeclTy *ActOnForwardProtocolDeclaration( + virtual DeclPtrTy ActOnForwardProtocolDeclaration( SourceLocation AtProtocolLoc, const IdentifierLocPair*IdentList, unsigned NumElts, AttributeList *AttrList) { - return 0; + return DeclPtrTy(); } /// FindProtocolDeclaration - This routine looks up protocols and @@ -1464,7 +1470,7 @@ public: virtual void FindProtocolDeclaration(bool WarnOnDeclarations, const IdentifierLocPair *ProtocolId, unsigned NumProtocols, - llvm::SmallVectorImpl &ResProtos) { + llvm::SmallVectorImpl &ResProtos) { } //===----------------------- Obj-C Expressions --------------------------===// @@ -1547,7 +1553,7 @@ public: /// getTypeName - This looks at the IdentifierInfo::FETokenInfo field to /// determine whether the name is a typedef or not in this scope. - virtual DeclTy *getTypeName(IdentifierInfo &II, SourceLocation NameLoc, + virtual TypeTy *getTypeName(IdentifierInfo &II, SourceLocation NameLoc, Scope *S, const CXXScopeSpec *SS); /// isCurrentClassName - Always returns false, because MinimalAction @@ -1556,45 +1562,46 @@ public: const CXXScopeSpec *SS); virtual TemplateNameKind isTemplateName(IdentifierInfo &II, Scope *S, - DeclTy *&TemplateDecl, + DeclPtrTy &TemplateDecl, const CXXScopeSpec *SS = 0); /// 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); + virtual DeclPtrTy ActOnDeclarator(Scope *S, Declarator &D, + DeclPtrTy LastInGroup); /// ActOnPopScope - When a scope is popped, if any typedefs are now /// out-of-scope, they are removed from the IdentifierInfo::FETokenInfo field. virtual void ActOnPopScope(SourceLocation Loc, Scope *S); virtual void ActOnTranslationUnitScope(SourceLocation Loc, Scope *S); - virtual DeclTy *ActOnForwardClassDeclaration(SourceLocation AtClassLoc, - IdentifierInfo **IdentList, - unsigned NumElts); + virtual DeclPtrTy ActOnForwardClassDeclaration(SourceLocation AtClassLoc, + IdentifierInfo **IdentList, + unsigned NumElts); - virtual DeclTy *ActOnStartClassInterface(SourceLocation interLoc, - IdentifierInfo *ClassName, - SourceLocation ClassLoc, - IdentifierInfo *SuperName, - SourceLocation SuperLoc, - DeclTy * const *ProtoRefs, - unsigned NumProtoRefs, - SourceLocation EndProtoLoc, - AttributeList *AttrList); + virtual DeclPtrTy ActOnStartClassInterface(SourceLocation interLoc, + IdentifierInfo *ClassName, + SourceLocation ClassLoc, + IdentifierInfo *SuperName, + SourceLocation SuperLoc, + const DeclPtrTy *ProtoRefs, + unsigned NumProtoRefs, + SourceLocation EndProtoLoc, + AttributeList *AttrList); }; /// PrettyStackTraceActionsDecl - If a crash occurs in the parser while parsing /// something related to a virtualized decl, include that virtualized decl in /// the stack trace. class PrettyStackTraceActionsDecl : public llvm::PrettyStackTraceEntry { - Action::DeclTy *TheDecl; + Action::DeclPtrTy TheDecl; SourceLocation Loc; Action &Actions; SourceManager &SM; const char *Message; public: - PrettyStackTraceActionsDecl(Action::DeclTy *Decl, SourceLocation L, + PrettyStackTraceActionsDecl(Action::DeclPtrTy Decl, SourceLocation L, Action &actions, SourceManager &sm, const char *Msg) : TheDecl(Decl), Loc(L), Actions(actions), SM(sm), Message(Msg) {} diff --git a/include/clang/Parse/DeclSpec.h b/include/clang/Parse/DeclSpec.h index 659a10817d..2a3cc11985 100644 --- a/include/clang/Parse/DeclSpec.h +++ b/include/clang/Parse/DeclSpec.h @@ -133,7 +133,7 @@ private: // List of protocol qualifiers for objective-c classes. Used for // protocol-qualified interfaces "NString" and protocol-qualified id // "id". - Action::DeclTy * const *ProtocolQualifiers; + const Action::DeclPtrTy *ProtocolQualifiers; unsigned NumProtocolQualifiers; // SourceLocation info. These are null if the item wasn't specified or if @@ -266,7 +266,7 @@ public: bool SetTypeSpecComplex(TSC C, SourceLocation Loc, const char *&PrevSpec); bool SetTypeSpecSign(TSS S, SourceLocation Loc, const char *&PrevSpec); bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, - Action::TypeTy *TypeRep = 0); + void *Rep = 0); bool SetTypeSpecError(); bool SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec, @@ -308,18 +308,18 @@ public: return AL; } - typedef const Action::DeclTy * const * ProtocolQualifierListTy; + typedef const Action::DeclPtrTy *ProtocolQualifierListTy; ProtocolQualifierListTy getProtocolQualifiers() const { return ProtocolQualifiers; } unsigned getNumProtocolQualifiers() const { return NumProtocolQualifiers; } - void setProtocolQualifiers(Action::DeclTy* const *Protos, unsigned NumProtos){ - if (NumProtos == 0) return; - ProtocolQualifiers = new Action::DeclTy*[NumProtos]; - memcpy((void*)ProtocolQualifiers, Protos,sizeof(Action::DeclTy*)*NumProtos); - NumProtocolQualifiers = NumProtos; + void setProtocolQualifiers(const Action::DeclPtrTy *Protos, unsigned NP) { + if (NP == 0) return; + ProtocolQualifiers = new Action::DeclPtrTy[NP]; + memcpy((void*)ProtocolQualifiers, Protos, sizeof(Action::DeclPtrTy)*NP); + NumProtocolQualifiers = NP; } /// Finish - This does final analysis of the declspec, issuing diagnostics for @@ -489,7 +489,7 @@ struct DeclaratorChunk { struct ParamInfo { IdentifierInfo *Ident; SourceLocation IdentLoc; - Action::DeclTy *Param; + Action::DeclPtrTy Param; /// DefaultArgTokens - When the parameter's default argument /// cannot be parsed immediately (because it occurs within the @@ -499,7 +499,8 @@ struct DeclaratorChunk { CachedTokens *DefaultArgTokens; ParamInfo() {} - ParamInfo(IdentifierInfo *ident, SourceLocation iloc, Action::DeclTy *param, + ParamInfo(IdentifierInfo *ident, SourceLocation iloc, + Action::DeclPtrTy param, CachedTokens *DefArgTokens = 0) : Ident(ident), IdentLoc(iloc), Param(param), DefaultArgTokens(DefArgTokens) {} diff --git a/include/clang/Parse/Ownership.h b/include/clang/Parse/Ownership.h index ce0707e9bf..496138d380 100644 --- a/include/clang/Parse/Ownership.h +++ b/include/clang/Parse/Ownership.h @@ -14,6 +14,54 @@ #ifndef LLVM_CLANG_PARSE_OWNERSHIP_H #define LLVM_CLANG_PARSE_OWNERSHIP_H +//===----------------------------------------------------------------------===// +// OpaquePtr +//===----------------------------------------------------------------------===// + +namespace llvm { + template + class PointerLikeTypeInfo; +} + +namespace clang { + /// OpaquePtr - This is a very simple POD type that wraps a pointer that the + /// Parser doesn't know about but that Sema or another client does. The UID + /// template argument is used to make sure that "Decl" pointers are not + /// compatible with "Type" pointers for example. + template + class OpaquePtr { + void *Ptr; + public: + OpaquePtr() : Ptr(0) {} + + template + T* getAs() const { return static_cast(Ptr); } + + void *get() const { return Ptr; } + + static OpaquePtr make(void *P) { OpaquePtr R; R.Ptr = P; return R; } + void set(void *P) { Ptr = P; } + + operator bool() const { return Ptr != 0; } + }; +} + +namespace llvm { + template + class PointerLikeTypeInfo > { + public: + static inline void *getAsVoidPointer(clang::OpaquePtr P) { + // FIXME: Doesn't work? return P.getAs< void >(); + return P.get(); + } + static inline clang::OpaquePtr getFromVoidPointer(void *P) { + return clang::OpaquePtr::make(P); + } + }; +} + + + // -------------------------- About Move Emulation -------------------------- // // The smart pointer classes in this file attempt to emulate move semantics // as they appear in C++0x with rvalue references. Since C++03 doesn't have @@ -138,33 +186,37 @@ namespace clang /// the action, plus a sense of whether or not it is valid. /// When CompressInvalid is true, the "invalid" flag will be /// stored in the low bit of the Val pointer. - template::value> class ActionResult { - void *Val; + PtrTy Val; bool Invalid; public: - ActionResult(bool Invalid = false) : Val(0), Invalid(Invalid) {} + ActionResult(bool Invalid = false) : Val(PtrTy()), Invalid(Invalid) {} template - ActionResult(ActualExprTy *val) : Val(val), Invalid(false) {} - ActionResult(const DiagnosticBuilder &) : Val(0), Invalid(true) {} + ActionResult(ActualExprTy val) : Val(val), Invalid(false) {} + ActionResult(const DiagnosticBuilder &) : Val(PtrTy()), Invalid(true) {} - void *get() const { return Val; } - void set(void *V) { Val = V; } + PtrTy get() const { return Val; } + void set(PtrTy V) { Val = V; } bool isInvalid() const { return Invalid; } - const ActionResult &operator=(void *RHS) { + const ActionResult &operator=(PtrTy RHS) { Val = RHS; Invalid = false; return *this; } }; + ///// FIXME: We just lost the ability to bitmangle into DeclPtrTy's and + ///// friends! + // This ActionResult partial specialization places the "invalid" // flag into the low bit of the pointer. template - class ActionResult { + class ActionResult { // A pointer whose low bit is 1 if this result is invalid, 0 // otherwise. uintptr_t PtrWithInvalid; diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index f502b3e4aa..f2f3ccf00b 100644 --- a/include/clang/Parse/Parser.h +++ b/include/clang/Parse/Parser.h @@ -119,7 +119,7 @@ public: // different actual classes based on the actions in place. typedef Action::ExprTy ExprTy; typedef Action::StmtTy StmtTy; - typedef Action::DeclTy DeclTy; + typedef Action::DeclPtrTy DeclPtrTy; typedef Action::TypeTy TypeTy; typedef Action::BaseTy BaseTy; typedef Action::MemInitTy MemInitTy; @@ -167,7 +167,7 @@ public: /// ParseTopLevelDecl - Parse one top-level declaration. Returns true if /// the EOF was encountered. - bool ParseTopLevelDecl(DeclTy*& Result); + bool ParseTopLevelDecl(DeclPtrTy &Result); private: //===--------------------------------------------------------------------===// @@ -453,9 +453,9 @@ private: // Lexing and parsing of C++ inline methods. struct LexedMethod { - Action::DeclTy *D; + Action::DeclPtrTy D; CachedTokens Toks; - explicit LexedMethod(Action::DeclTy *MD) : D(MD) {} + explicit LexedMethod(Action::DeclPtrTy MD) : D(MD) {} }; /// LateParsedDefaultArgument - Keeps track of a parameter that may @@ -463,12 +463,12 @@ private: /// occurs within a member function declaration inside the class /// (C++ [class.mem]p2). struct LateParsedDefaultArgument { - explicit LateParsedDefaultArgument(Action::DeclTy *P, + explicit LateParsedDefaultArgument(Action::DeclPtrTy P, CachedTokens *Toks = 0) : Param(P), Toks(Toks) { } /// Param - The parameter declaration for this parameter. - Action::DeclTy *Param; + Action::DeclPtrTy Param; /// Toks - The sequence of tokens that comprises the default /// argument expression, not including the '=' or the terminating @@ -482,10 +482,10 @@ private: /// until the class itself is completely-defined, such as a default /// argument (C++ [class.mem]p2). struct LateParsedMethodDeclaration { - explicit LateParsedMethodDeclaration(Action::DeclTy *M) : Method(M) { } + explicit LateParsedMethodDeclaration(Action::DeclPtrTy M) : Method(M) { } /// Method - The method declaration. - Action::DeclTy *Method; + Action::DeclPtrTy Method; /// DefaultArgs - Contains the parameters of the function and /// their default arguments. At least one of the parameters will @@ -537,7 +537,7 @@ private: } void PopTopClassStack() { TopClassStacks.pop(); } - DeclTy *ParseCXXInlineMethodDef(AccessSpecifier AS, Declarator &D); + DeclPtrTy ParseCXXInlineMethodDef(AccessSpecifier AS, Declarator &D); void ParseLexedMethodDeclarations(); void ParseLexedMethodDefs(); bool ConsumeAndStoreUntil(tok::TokenKind T1, tok::TokenKind T2, @@ -547,12 +547,12 @@ private: //===--------------------------------------------------------------------===// // C99 6.9: External Definitions. - DeclTy *ParseExternalDeclaration(); - DeclTy *ParseDeclarationOrFunctionDefinition( + DeclPtrTy ParseExternalDeclaration(); + DeclPtrTy ParseDeclarationOrFunctionDefinition( TemplateParameterLists *TemplateParams = 0, AccessSpecifier AS = AS_none); - DeclTy *ParseFunctionDefinition(Declarator &D); + DeclPtrTy ParseFunctionDefinition(Declarator &D); void ParseKNRParamDeclarations(Declarator &D); // EndLoc, if non-NULL, is filled with the location of the last token of // the simple-asm. @@ -560,27 +560,27 @@ private: OwningExprResult ParseAsmStringLiteral(); // Objective-C External Declarations - DeclTy *ParseObjCAtDirectives(); - DeclTy *ParseObjCAtClassDeclaration(SourceLocation atLoc); - DeclTy *ParseObjCAtInterfaceDeclaration(SourceLocation atLoc, + DeclPtrTy ParseObjCAtDirectives(); + DeclPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc); + DeclPtrTy ParseObjCAtInterfaceDeclaration(SourceLocation atLoc, AttributeList *prefixAttrs = 0); - void ParseObjCClassInstanceVariables(DeclTy *interfaceDecl, + void ParseObjCClassInstanceVariables(DeclPtrTy interfaceDecl, SourceLocation atLoc); - bool ParseObjCProtocolReferences(llvm::SmallVectorImpl &P, + bool ParseObjCProtocolReferences(llvm::SmallVectorImpl &P, bool WarnOnDeclarations, SourceLocation &EndProtoLoc); - void ParseObjCInterfaceDeclList(DeclTy *interfaceDecl, + void ParseObjCInterfaceDeclList(DeclPtrTy interfaceDecl, tok::ObjCKeywordKind contextKey); - DeclTy *ParseObjCAtProtocolDeclaration(SourceLocation atLoc, - AttributeList *prefixAttrs = 0); + DeclPtrTy ParseObjCAtProtocolDeclaration(SourceLocation atLoc, + AttributeList *prefixAttrs = 0); - DeclTy *ObjCImpDecl; + DeclPtrTy ObjCImpDecl; - DeclTy *ParseObjCAtImplementationDeclaration(SourceLocation atLoc); - DeclTy *ParseObjCAtEndDeclaration(SourceLocation atLoc); - DeclTy *ParseObjCAtAliasDeclaration(SourceLocation atLoc); - DeclTy *ParseObjCPropertySynthesize(SourceLocation atLoc); - DeclTy *ParseObjCPropertyDynamic(SourceLocation atLoc); + DeclPtrTy ParseObjCAtImplementationDeclaration(SourceLocation atLoc); + DeclPtrTy ParseObjCAtEndDeclaration(SourceLocation atLoc); + DeclPtrTy ParseObjCAtAliasDeclaration(SourceLocation atLoc); + DeclPtrTy ParseObjCPropertySynthesize(SourceLocation atLoc); + DeclPtrTy ParseObjCPropertyDynamic(SourceLocation atLoc); IdentifierInfo *ParseObjCSelector(SourceLocation &MethodLocation); // Definitions for Objective-c context sensitive keywords recognition. @@ -594,14 +594,14 @@ private: TypeTy *ParseObjCTypeName(ObjCDeclSpec &DS); void ParseObjCMethodRequirement(); - DeclTy *ParseObjCMethodPrototype(DeclTy *classOrCat, + DeclPtrTy ParseObjCMethodPrototype(DeclPtrTy classOrCat, tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword); - DeclTy *ParseObjCMethodDecl(SourceLocation mLoc, tok::TokenKind mType, - DeclTy *classDecl, + DeclPtrTy ParseObjCMethodDecl(SourceLocation mLoc, tok::TokenKind mType, + DeclPtrTy classDecl, tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword); void ParseObjCPropertyAttribute(ObjCDeclSpec &DS); - DeclTy *ParseObjCMethodDefinition(); + DeclPtrTy ParseObjCMethodDefinition(); //===--------------------------------------------------------------------===// // C99 6.5: Expressions. @@ -807,10 +807,10 @@ private: //===--------------------------------------------------------------------===// // C99 6.7: Declarations. - DeclTy *ParseDeclaration(unsigned Context); - DeclTy *ParseSimpleDeclaration(unsigned Context); - DeclTy *ParseInitDeclaratorListAfterFirstDeclarator(Declarator &D); - DeclTy *ParseFunctionStatementBody(DeclTy *Decl); + DeclPtrTy ParseDeclaration(unsigned Context); + DeclPtrTy ParseSimpleDeclaration(unsigned Context); + DeclPtrTy ParseInitDeclaratorListAfterFirstDeclarator(Declarator &D); + DeclPtrTy ParseFunctionStatementBody(DeclPtrTy Decl); void ParseDeclarationSpecifiers(DeclSpec &DS, TemplateParameterLists *TemplateParams = 0, AccessSpecifier AS = AS_none); @@ -822,9 +822,9 @@ private: void ParseObjCTypeQualifierList(ObjCDeclSpec &DS); void ParseEnumSpecifier(DeclSpec &DS, AccessSpecifier AS = AS_none); - void ParseEnumBody(SourceLocation StartLoc, DeclTy *TagDecl); + void ParseEnumBody(SourceLocation StartLoc, DeclPtrTy TagDecl); void ParseStructUnionBody(SourceLocation StartLoc, unsigned TagType, - DeclTy *TagDecl); + DeclPtrTy TagDecl); void ParseStructDeclaration(DeclSpec &DS, llvm::SmallVectorImpl &Fields); @@ -991,13 +991,13 @@ private: //===--------------------------------------------------------------------===// // C++ 7: Declarations [dcl.dcl] - DeclTy *ParseNamespace(unsigned Context); - DeclTy *ParseLinkage(unsigned Context); - DeclTy *ParseUsingDirectiveOrDeclaration(unsigned Context); - DeclTy *ParseUsingDirective(unsigned Context, SourceLocation UsingLoc); - DeclTy *ParseUsingDeclaration(unsigned Context, SourceLocation UsingLoc); - DeclTy *ParseStaticAssertDeclaration(); - DeclTy *ParseNamespaceAlias(SourceLocation AliasLoc, IdentifierInfo *Alias); + DeclPtrTy ParseNamespace(unsigned Context); + DeclPtrTy ParseLinkage(unsigned Context); + DeclPtrTy ParseUsingDirectiveOrDeclaration(unsigned Context); + DeclPtrTy ParseUsingDirective(unsigned Context, SourceLocation UsingLoc); + DeclPtrTy ParseUsingDeclaration(unsigned Context, SourceLocation UsingLoc); + DeclPtrTy ParseStaticAssertDeclaration(); + DeclPtrTy ParseNamespaceAlias(SourceLocation AliasLoc, IdentifierInfo *Alias); //===--------------------------------------------------------------------===// // C++ 9: classes [class] and C structs/unions. @@ -1007,15 +1007,15 @@ private: TemplateParameterLists *TemplateParams = 0, AccessSpecifier AS = AS_none); void ParseCXXMemberSpecification(SourceLocation StartLoc, unsigned TagType, - DeclTy *TagDecl); - DeclTy *ParseCXXClassMemberDeclaration(AccessSpecifier AS); - void ParseConstructorInitializer(DeclTy *ConstructorDecl); - MemInitResult ParseMemInitializer(DeclTy *ConstructorDecl); + DeclPtrTy TagDecl); + DeclPtrTy ParseCXXClassMemberDeclaration(AccessSpecifier AS); + void ParseConstructorInitializer(DeclPtrTy ConstructorDecl); + MemInitResult ParseMemInitializer(DeclPtrTy ConstructorDecl); //===--------------------------------------------------------------------===// // C++ 10: Derived classes [class.derived] - void ParseBaseClause(DeclTy *ClassDecl); - BaseResult ParseBaseSpecifier(DeclTy *ClassDecl); + void ParseBaseClause(DeclPtrTy ClassDecl); + BaseResult ParseBaseSpecifier(DeclPtrTy ClassDecl); AccessSpecifier getAccessSpecifierIfPresent() const; //===--------------------------------------------------------------------===// @@ -1027,10 +1027,10 @@ private: //===--------------------------------------------------------------------===// // C++ 14: Templates [temp] - typedef llvm::SmallVector TemplateParameterList; + typedef llvm::SmallVector TemplateParameterList; // C++ 14.1: Template Parameters [temp.param] - DeclTy *ParseTemplateDeclarationOrSpecialization(unsigned Context, + DeclPtrTy ParseTemplateDeclarationOrSpecialization(unsigned Context, AccessSpecifier AS=AS_none); bool ParseTemplateParameters(unsigned Depth, TemplateParameterList &TemplateParams, @@ -1038,16 +1038,16 @@ private: SourceLocation &RAngleLoc); bool ParseTemplateParameterList(unsigned Depth, TemplateParameterList &TemplateParams); - DeclTy *ParseTemplateParameter(unsigned Depth, unsigned Position); - DeclTy *ParseTypeParameter(unsigned Depth, unsigned Position); - DeclTy *ParseTemplateTemplateParameter(unsigned Depth, unsigned Position); - DeclTy *ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position); + DeclPtrTy ParseTemplateParameter(unsigned Depth, unsigned Position); + DeclPtrTy ParseTypeParameter(unsigned Depth, unsigned Position); + DeclPtrTy ParseTemplateTemplateParameter(unsigned Depth, unsigned Position); + DeclPtrTy ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position); // C++ 14.3: Template arguments [temp.arg] typedef llvm::SmallVector TemplateArgList; typedef llvm::SmallVector TemplateArgIsTypeList; typedef llvm::SmallVector TemplateArgLocationList; - bool ParseTemplateIdAfterTemplateName(DeclTy *Template, + bool ParseTemplateIdAfterTemplateName(DeclPtrTy Template, SourceLocation TemplateNameLoc, const CXXScopeSpec *SS, bool ConsumeLastToken, @@ -1057,7 +1057,7 @@ private: TemplateArgLocationList &TemplateArgLocations, SourceLocation &RAngleLoc); - void AnnotateTemplateIdToken(DeclTy *Template, TemplateNameKind TNK, + void AnnotateTemplateIdToken(DeclPtrTy Template, TemplateNameKind TNK, const CXXScopeSpec *SS, SourceLocation TemplateKWLoc = SourceLocation(), bool AllowTypeAnnotation = true); diff --git a/include/clang/Parse/Scope.h b/include/clang/Parse/Scope.h index 2efb809bbc..84cc5d5c34 100644 --- a/include/clang/Parse/Scope.h +++ b/include/clang/Parse/Scope.h @@ -117,7 +117,7 @@ private: /// popped, these declarations are removed from the IdentifierTable's notion /// of current declaration. It is up to the current Action implementation to /// implement these semantics. - typedef llvm::SmallPtrSet DeclSetTy; + typedef llvm::SmallPtrSet DeclSetTy; DeclSetTy DeclsInScope; /// Entity - The entity with which this scope is associated. For @@ -126,7 +126,7 @@ private: /// maintained by the Action implementation. void *Entity; - typedef llvm::SmallVector UsingDirectivesTy; + typedef llvm::SmallVector UsingDirectivesTy; UsingDirectivesTy UsingDirectives; public: @@ -191,17 +191,17 @@ public: decl_iterator decl_end() const { return DeclsInScope.end(); } bool decl_empty() const { return DeclsInScope.empty(); } - void AddDecl(Action::DeclTy *D) { + void AddDecl(Action::DeclPtrTy D) { DeclsInScope.insert(D); } - void RemoveDecl(Action::DeclTy *D) { + void RemoveDecl(Action::DeclPtrTy D) { DeclsInScope.erase(D); } /// isDeclScope - Return true if this is the scope that the specified decl is /// declared in. - bool isDeclScope(Action::DeclTy *D) { + bool isDeclScope(Action::DeclPtrTy D) { return DeclsInScope.count(D) != 0; } @@ -249,7 +249,7 @@ public: typedef UsingDirectivesTy::iterator udir_iterator; typedef UsingDirectivesTy::const_iterator const_udir_iterator; - void PushUsingDirective(Action::DeclTy *UDir) { + void PushUsingDirective(Action::DeclPtrTy UDir) { UsingDirectives.push_back(UDir); } diff --git a/lib/Parse/DeclSpec.cpp b/lib/Parse/DeclSpec.cpp index 94799c3200..de9f36dd9c 100644 --- a/lib/Parse/DeclSpec.cpp +++ b/lib/Parse/DeclSpec.cpp @@ -225,7 +225,7 @@ bool DeclSpec::SetTypeSpecSign(TSS S, SourceLocation Loc, } bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc, - const char *&PrevSpec, Action::TypeTy *Rep) { + const char *&PrevSpec, void *Rep) { if (TypeSpecType != TST_unspecified) return BadSpecifier((TST)TypeSpecType, PrevSpec); TypeSpecType = T; diff --git a/lib/Parse/MinimalAction.cpp b/lib/Parse/MinimalAction.cpp index 776d701c32..049228f56c 100644 --- a/lib/Parse/MinimalAction.cpp +++ b/lib/Parse/MinimalAction.cpp @@ -26,19 +26,19 @@ ActionBase::~ActionBase() {} Action::~Action() {} // Defined out-of-line here because of dependecy on AttributeList -Action::DeclTy *Action::ActOnUsingDirective(Scope *CurScope, - SourceLocation UsingLoc, - SourceLocation NamespcLoc, - const CXXScopeSpec &SS, - SourceLocation IdentLoc, - IdentifierInfo *NamespcName, - AttributeList *AttrList) { +Action::DeclPtrTy Action::ActOnUsingDirective(Scope *CurScope, + SourceLocation UsingLoc, + SourceLocation NamespcLoc, + const CXXScopeSpec &SS, + SourceLocation IdentLoc, + IdentifierInfo *NamespcName, + AttributeList *AttrList) { // FIXME: Parser seems to assume that Action::ActOn* takes ownership over // passed AttributeList, however other actions don't free it, is it // temporary state or bug? delete AttrList; - return 0; + return DeclPtrTy(); } @@ -135,7 +135,7 @@ bool MinimalAction::isCurrentClassName(const IdentifierInfo &, Scope *, TemplateNameKind MinimalAction::isTemplateName(IdentifierInfo &II, Scope *S, - DeclTy *&TemplateDecl, + DeclPtrTy &TemplateDecl, const CXXScopeSpec *SS) { return TNK_Non_template; } @@ -143,12 +143,12 @@ MinimalAction::isTemplateName(IdentifierInfo &II, Scope *S, /// ActOnDeclarator - If this is a typedef declarator, we modify the /// IdentifierInfo::FETokenInfo field to keep track of this fact, until S is /// popped. -Action::DeclTy * -MinimalAction::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup) { +Action::DeclPtrTy +MinimalAction::ActOnDeclarator(Scope *S, Declarator &D, DeclPtrTy LastInGroup) { IdentifierInfo *II = D.getIdentifier(); // If there is no identifier associated with this declarator, bail out. - if (II == 0) return 0; + if (II == 0) return DeclPtrTy(); TypeNameInfo *weCurrentlyHaveTypeInfo = II->getFETokenInfo(); bool isTypeName = @@ -162,29 +162,29 @@ MinimalAction::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup) { getTable(TypeNameInfoTablePtr)->AddEntry(isTypeName, II); // Remember that this needs to be removed when the scope is popped. - S->AddDecl(II); + S->AddDecl(DeclPtrTy::make(II)); } - return 0; + return DeclPtrTy(); } -Action::DeclTy * +Action::DeclPtrTy MinimalAction::ActOnStartClassInterface(SourceLocation AtInterfaceLoc, IdentifierInfo *ClassName, SourceLocation ClassLoc, IdentifierInfo *SuperName, SourceLocation SuperLoc, - DeclTy * const *ProtoRefs, + const DeclPtrTy *ProtoRefs, unsigned NumProtocols, SourceLocation EndProtoLoc, AttributeList *AttrList) { // Allocate and add the 'TypeNameInfo' "decl". getTable(TypeNameInfoTablePtr)->AddEntry(true, ClassName); - return 0; + return DeclPtrTy(); } /// ActOnForwardClassDeclaration - /// Scope will always be top level file scope. -Action::DeclTy * +Action::DeclPtrTy MinimalAction::ActOnForwardClassDeclaration(SourceLocation AtClassLoc, IdentifierInfo **IdentList, unsigned NumElts) { for (unsigned i = 0; i != NumElts; ++i) { @@ -192,9 +192,9 @@ MinimalAction::ActOnForwardClassDeclaration(SourceLocation AtClassLoc, getTable(TypeNameInfoTablePtr)->AddEntry(true, IdentList[i]); // Remember that this needs to be removed when the scope is popped. - TUScope->AddDecl(IdentList[i]); + TUScope->AddDecl(DeclPtrTy::make(IdentList[i])); } - return 0; + return DeclPtrTy(); } /// ActOnPopScope - When a scope is popped, if any typedefs are now @@ -204,7 +204,7 @@ void MinimalAction::ActOnPopScope(SourceLocation Loc, Scope *S) { for (Scope::decl_iterator I = S->decl_begin(), E = S->decl_end(); I != E; ++I) { - IdentifierInfo &II = *static_cast(*I); + IdentifierInfo &II = *(*I).getAs(); TypeNameInfo *TI = II.getFETokenInfo(); assert(TI && "This decl didn't get pushed??"); diff --git a/lib/Parse/ParseCXXInlineMethods.cpp b/lib/Parse/ParseCXXInlineMethods.cpp index 3ed9802026..e139cf9c3e 100644 --- a/lib/Parse/ParseCXXInlineMethods.cpp +++ b/lib/Parse/ParseCXXInlineMethods.cpp @@ -20,14 +20,15 @@ using namespace clang; /// ParseInlineCXXMethodDef - We parsed and verified that the specified /// Declarator is a well formed C++ inline method definition. Now lex its body /// and store its tokens for parsing after the C++ class is complete. -Parser::DeclTy * +Parser::DeclPtrTy Parser::ParseCXXInlineMethodDef(AccessSpecifier AS, Declarator &D) { assert(D.getTypeObject(0).Kind == DeclaratorChunk::Function && "This isn't a function declarator!"); assert((Tok.is(tok::l_brace) || Tok.is(tok::colon)) && "Current token not a '{' or ':'!"); - DeclTy *FnD = Actions.ActOnCXXMemberDeclarator(CurScope, AS, D, 0, 0, 0); + DeclPtrTy FnD = Actions.ActOnCXXMemberDeclarator(CurScope, AS, D, 0, 0, + DeclPtrTy()); // Consume the tokens and store them for later parsing. diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 0ab7042f5e..5a8b2b8569 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -228,7 +228,7 @@ void Parser::FuzzyParseMicrosoftDeclSpec() { /// [C++0x] static_assert-declaration /// others... [FIXME] /// -Parser::DeclTy *Parser::ParseDeclaration(unsigned Context) { +Parser::DeclPtrTy Parser::ParseDeclaration(unsigned Context) { switch (Tok.getKind()) { case tok::kw_export: case tok::kw_template: @@ -248,7 +248,7 @@ Parser::DeclTy *Parser::ParseDeclaration(unsigned Context) { /// declaration-specifiers init-declarator-list[opt] ';' ///[C90/C++]init-declarator-list ';' [TODO] /// [OMP] threadprivate-directive [TODO] -Parser::DeclTy *Parser::ParseSimpleDeclaration(unsigned Context) { +Parser::DeclPtrTy Parser::ParseSimpleDeclaration(unsigned Context) { // Parse the common declaration-specifiers piece. DeclSpec DS; ParseDeclarationSpecifiers(DS); @@ -291,12 +291,12 @@ Parser::DeclTy *Parser::ParseSimpleDeclaration(unsigned Context) { /// According to the standard grammar, =default and =delete are function /// definitions, but that definitely doesn't fit with the parser here. /// -Parser::DeclTy *Parser:: +Parser::DeclPtrTy Parser:: ParseInitDeclaratorListAfterFirstDeclarator(Declarator &D) { // Declarators may be grouped together ("int X, *Y, Z();"). Provide info so // that they can be chained properly if the actions want this. - Parser::DeclTy *LastDeclInGroup = 0; + Parser::DeclPtrTy LastDeclInGroup; // At this point, we know that it is not a function definition. Parse the // rest of the init-declarator-list. @@ -307,7 +307,7 @@ ParseInitDeclaratorListAfterFirstDeclarator(Declarator &D) { OwningExprResult AsmLabel(ParseSimpleAsm(&Loc)); if (AsmLabel.isInvalid()) { SkipUntil(tok::semi); - return 0; + return DeclPtrTy(); } D.setAsmLabel(AsmLabel.release()); @@ -334,7 +334,7 @@ ParseInitDeclaratorListAfterFirstDeclarator(Declarator &D) { OwningExprResult Init(ParseInitializer()); if (Init.isInvalid()) { SkipUntil(tok::semi); - return 0; + return DeclPtrTy(); } Actions.AddInitializerToDecl(LastDeclInGroup, move(Init)); } @@ -395,7 +395,7 @@ ParseInitDeclaratorListAfterFirstDeclarator(Declarator &D) { // for(is key; in keys) is error. if (D.getContext() == Declarator::ForContext && isTokIdentifier_in()) { Diag(Tok, diag::err_parse_error); - return 0; + return DeclPtrTy(); } return Actions.FinalizeDeclaratorGroup(CurScope, LastDeclInGroup); } @@ -411,7 +411,7 @@ ParseInitDeclaratorListAfterFirstDeclarator(Declarator &D) { SkipUntil(tok::r_brace, true, true); if (Tok.is(tok::semi)) ConsumeToken(); - return 0; + return DeclPtrTy(); } /// ParseSpecifierQualifierList @@ -560,7 +560,7 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS, continue; SourceLocation EndProtoLoc; - llvm::SmallVector ProtocolDecl; + llvm::SmallVector ProtocolDecl; ParseObjCProtocolReferences(ProtocolDecl, false, EndProtoLoc); DS.setProtocolQualifiers(&ProtocolDecl[0], ProtocolDecl.size()); @@ -614,7 +614,7 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS, continue; SourceLocation EndProtoLoc; - llvm::SmallVector ProtocolDecl; + llvm::SmallVector ProtocolDecl; ParseObjCProtocolReferences(ProtocolDecl, false, EndProtoLoc); DS.setProtocolQualifiers(&ProtocolDecl[0], ProtocolDecl.size()); @@ -809,7 +809,7 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS, { SourceLocation EndProtoLoc; - llvm::SmallVector ProtocolDecl; + llvm::SmallVector ProtocolDecl; ParseObjCProtocolReferences(ProtocolDecl, false, EndProtoLoc); DS.setProtocolQualifiers(&ProtocolDecl[0], ProtocolDecl.size()); DS.SetRangeEnd(EndProtoLoc); @@ -917,7 +917,7 @@ bool Parser::ParseOptionalTypeSpecifier(DeclSpec &DS, int& isInvalid, return true; SourceLocation EndProtoLoc; - llvm::SmallVector ProtocolDecl; + llvm::SmallVector ProtocolDecl; ParseObjCProtocolReferences(ProtocolDecl, false, EndProtoLoc); DS.setProtocolQualifiers(&ProtocolDecl[0], ProtocolDecl.size()); @@ -1129,7 +1129,7 @@ ParseStructDeclaration(DeclSpec &DS, /// [OBC] '@' 'defs' '(' class-name ')' /// void Parser::ParseStructUnionBody(SourceLocation RecordLoc, - unsigned TagType, DeclTy *TagDecl) { + unsigned TagType, DeclPtrTy TagDecl) { PrettyStackTraceActionsDecl CrashInfo(TagDecl, RecordLoc, Actions, PP.getSourceManager(), "parsing struct/union body"); @@ -1145,7 +1145,7 @@ void Parser::ParseStructUnionBody(SourceLocation RecordLoc, Diag(Tok, diag::ext_empty_struct_union_enum) << DeclSpec::getSpecifierName((DeclSpec::TST)TagType); - llvm::SmallVector FieldDecls; + llvm::SmallVector FieldDecls; llvm::SmallVector FieldDeclarators; // While we still have something to read, read the declarations in the struct. @@ -1169,9 +1169,9 @@ void Parser::ParseStructUnionBody(SourceLocation RecordLoc, for (unsigned i = 0, e = FieldDeclarators.size(); i != e; ++i) { FieldDeclarator &FD = FieldDeclarators[i]; // Install the declarator into the current TagDecl. - DeclTy *Field = Actions.ActOnField(CurScope, TagDecl, - DS.getSourceRange().getBegin(), - FD.D, FD.BitfieldSize); + DeclPtrTy Field = Actions.ActOnField(CurScope, TagDecl, + DS.getSourceRange().getBegin(), + FD.D, FD.BitfieldSize); FieldDecls.push_back(Field); } } else { // Handle @defs @@ -1188,7 +1188,7 @@ void Parser::ParseStructUnionBody(SourceLocation RecordLoc, SkipUntil(tok::semi, true, true); continue; } - llvm::SmallVector Fields; + llvm::SmallVector Fields; Actions.ActOnDefs(CurScope, TagDecl, Tok.getLocation(), Tok.getIdentifierInfo(), Fields); FieldDecls.insert(FieldDecls.end(), Fields.begin(), Fields.end()); @@ -1292,15 +1292,16 @@ void Parser::ParseEnumSpecifier(DeclSpec &DS, AccessSpecifier AS) { TK = Action::TK_Declaration; else TK = Action::TK_Reference; - DeclTy *TagDecl = Actions.ActOnTag(CurScope, DeclSpec::TST_enum, TK, StartLoc, - SS, Name, NameLoc, Attr, AS); + DeclPtrTy TagDecl = Actions.ActOnTag(CurScope, DeclSpec::TST_enum, TK, + StartLoc, SS, Name, NameLoc, Attr, AS); if (Tok.is(tok::l_brace)) ParseEnumBody(StartLoc, TagDecl); // TODO: semantic analysis on the declspec for enums. const char *PrevSpec = 0; - if (DS.SetTypeSpecType(DeclSpec::TST_enum, StartLoc, PrevSpec, TagDecl)) + if (DS.SetTypeSpecType(DeclSpec::TST_enum, StartLoc, PrevSpec, + TagDecl.getAs())) Diag(StartLoc, diag::err_invalid_decl_spec_combination) << PrevSpec; } @@ -1314,7 +1315,7 @@ void Parser::ParseEnumSpecifier(DeclSpec &DS, AccessSpecifier AS) { /// enumeration-constant: /// identifier /// -void Parser::ParseEnumBody(SourceLocation StartLoc, DeclTy *EnumDecl) { +void Parser::ParseEnumBody(SourceLocation StartLoc, DeclPtrTy EnumDecl) { // Enter the scope of the enum body and start the definition. ParseScope EnumScope(this, Scope::DeclScope); Actions.ActOnTagStartDefinition(CurScope, EnumDecl); @@ -1325,9 +1326,9 @@ void Parser::ParseEnumBody(SourceLocation StartLoc, DeclTy *EnumDecl) { if (Tok.is(tok::r_brace) && !getLang().CPlusPlus) Diag(Tok, diag::ext_empty_struct_union_enum) << "enum"; - llvm::SmallVector EnumConstantDecls; + llvm::SmallVector EnumConstantDecls; - DeclTy *LastEnumConstDecl = 0; + DeclPtrTy LastEnumConstDecl; // Parse the enumerator-list. while (Tok.is(tok::identifier)) { @@ -1344,11 +1345,11 @@ void Parser::ParseEnumBody(SourceLocation StartLoc, DeclTy *EnumDecl) { } // Install the enumerator constant into EnumDecl. - DeclTy *EnumConstDecl = Actions.ActOnEnumConstant(CurScope, EnumDecl, - LastEnumConstDecl, - IdentLoc, Ident, - EqualLoc, - AssignedVal.release()); + DeclPtrTy EnumConstDecl = Actions.ActOnEnumConstant(CurScope, EnumDecl, + LastEnumConstDecl, + IdentLoc, Ident, + EqualLoc, + AssignedVal.release()); EnumConstantDecls.push_back(EnumConstDecl); LastEnumConstDecl = EnumConstDecl; @@ -1366,7 +1367,7 @@ void Parser::ParseEnumBody(SourceLocation StartLoc, DeclTy *EnumDecl) { Actions.ActOnEnumBody(StartLoc, EnumDecl, &EnumConstantDecls[0], EnumConstantDecls.size()); - DeclTy *AttrList = 0; + Action::AttrTy *AttrList = 0; // If attributes exist after the identifier list, parse them. if (Tok.is(tok::kw___attribute)) AttrList = ParseAttributes(); // FIXME: where do they do? @@ -2195,7 +2196,7 @@ void Parser::ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D, // Inform the actions module about the parameter declarator, so it gets // added to the current scope. - DeclTy *Param = Actions.ActOnParamDeclarator(CurScope, ParmDecl); + DeclPtrTy Param = Actions.ActOnParamDeclarator(CurScope, ParmDecl); // Parse the default argument, if any. We parse the default // arguments in all dialects; the semantic analysis in @@ -2300,7 +2301,8 @@ void Parser::ParseFunctionDeclaratorIdentifierList(SourceLocation LParenLoc, // identifier in ParamInfo. ParamsSoFar.insert(Tok.getIdentifierInfo()); ParamInfo.push_back(DeclaratorChunk::ParamInfo(Tok.getIdentifierInfo(), - Tok.getLocation(), 0)); + Tok.getLocation(), + DeclPtrTy())); ConsumeToken(); // eat the first identifier. @@ -2327,7 +2329,8 @@ void Parser::ParseFunctionDeclaratorIdentifierList(SourceLocation LParenLoc, } else { // Remember this identifier in ParamInfo. ParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII, - Tok.getLocation(), 0)); + Tok.getLocation(), + DeclPtrTy())); } // Eat the identifier. diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index 121bf04bc3..37eb34e777 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -42,7 +42,7 @@ using namespace clang; /// namespace-alias-definition: [C++ 7.3.2: namespace.alias] /// 'namespace' identifier '=' qualified-namespace-specifier ';' /// -Parser::DeclTy *Parser::ParseNamespace(unsigned Context) { +Parser::DeclPtrTy Parser::ParseNamespace(unsigned Context) { assert(Tok.is(tok::kw_namespace) && "Not a namespace!"); SourceLocation NamespaceLoc = ConsumeToken(); // eat the 'namespace'. @@ -55,7 +55,7 @@ Parser::DeclTy *Parser::ParseNamespace(unsigned Context) { } // Read label attributes, if present. - DeclTy *AttrList = 0; + Action::AttrTy *AttrList = 0; if (Tok.is(tok::kw___attribute)) // FIXME: save these somewhere. AttrList = ParseAttributes(); @@ -70,7 +70,7 @@ Parser::DeclTy *Parser::ParseNamespace(unsigned Context) { // Enter a scope for the namespace. ParseScope NamespaceScope(this, Scope::DeclScope); - DeclTy *NamespcDecl = + DeclPtrTy NamespcDecl = Actions.ActOnStartNamespaceDef(CurScope, IdentLoc, Ident, LBrace); PrettyStackTraceActionsDecl CrashInfo(NamespcDecl, NamespaceLoc, Actions, @@ -93,14 +93,14 @@ Parser::DeclTy *Parser::ParseNamespace(unsigned Context) { diag::err_expected_ident_lbrace); } - return 0; + return DeclPtrTy(); } /// ParseNamespaceAlias - Parse the part after the '=' in a namespace /// alias definition. /// -Parser::DeclTy *Parser::ParseNamespaceAlias(SourceLocation AliasLoc, - IdentifierInfo *Alias) { +Parser::DeclPtrTy Parser::ParseNamespaceAlias(SourceLocation AliasLoc, + IdentifierInfo *Alias) { assert(Tok.is(tok::equal) && "Not equal token"); ConsumeToken(); // eat the '='. @@ -113,7 +113,7 @@ Parser::DeclTy *Parser::ParseNamespaceAlias(SourceLocation AliasLoc, Diag(Tok, diag::err_expected_namespace_name); // Skip to end of the definition and eat the ';'. SkipUntil(tok::semi); - return 0; + return DeclPtrTy(); } // Parse identifier. @@ -135,7 +135,7 @@ Parser::DeclTy *Parser::ParseNamespaceAlias(SourceLocation AliasLoc, /// 'extern' string-literal '{' declaration-seq[opt] '}' /// 'extern' string-literal declaration /// -Parser::DeclTy *Parser::ParseLinkage(unsigned Context) { +Parser::DeclPtrTy Parser::ParseLinkage(unsigned Context) { assert(Tok.is(tok::string_literal) && "Not a string literal!"); llvm::SmallVector LangBuffer; // LangBuffer is guaranteed to be big enough. @@ -146,7 +146,7 @@ Parser::DeclTy *Parser::ParseLinkage(unsigned Context) { SourceLocation Loc = ConsumeStringToken(); ParseScope LinkageScope(this, Scope::DeclScope); - DeclTy *LinkageSpec + DeclPtrTy LinkageSpec = Actions.ActOnStartLinkageSpecification(CurScope, /*FIXME: */SourceLocation(), Loc, LangBufPtr, StrSize, @@ -170,7 +170,7 @@ Parser::DeclTy *Parser::ParseLinkage(unsigned Context) { /// ParseUsingDirectiveOrDeclaration - Parse C++ using using-declaration or /// using-directive. Assumes that current token is 'using'. -Parser::DeclTy *Parser::ParseUsingDirectiveOrDeclaration(unsigned Context) { +Parser::DeclPtrTy Parser::ParseUsingDirectiveOrDeclaration(unsigned Context) { assert(Tok.is(tok::kw_using) && "Not using token"); // Eat 'using'. @@ -194,8 +194,8 @@ Parser::DeclTy *Parser::ParseUsingDirectiveOrDeclaration(unsigned Context) { /// 'using' 'namespace' ::[opt] nested-name-specifier[opt] /// namespace-name attributes[opt] ; /// -Parser::DeclTy *Parser::ParseUsingDirective(unsigned Context, - SourceLocation UsingLoc) { +Parser::DeclPtrTy Parser::ParseUsingDirective(unsigned Context, + SourceLocation UsingLoc) { assert(Tok.is(tok::kw_namespace) && "Not 'namespace' token"); // Eat 'namespace'. @@ -215,7 +215,7 @@ Parser::DeclTy *Parser::ParseUsingDirective(unsigned Context, // If there was invalid namespace name, skip to end of decl, and eat ';'. SkipUntil(tok::semi); // FIXME: Are there cases, when we would like to call ActOnUsingDirective? - return 0; + return DeclPtrTy(); } // Parse identifier. @@ -242,11 +242,11 @@ Parser::DeclTy *Parser::ParseUsingDirective(unsigned Context, /// unqualified-id [TODO] /// 'using' :: unqualified-id [TODO] /// -Parser::DeclTy *Parser::ParseUsingDeclaration(unsigned Context, - SourceLocation UsingLoc) { +Parser::DeclPtrTy Parser::ParseUsingDeclaration(unsigned Context, + SourceLocation UsingLoc) { assert(false && "Not implemented"); // FIXME: Implement parsing. - return 0; + return DeclPtrTy(); } /// ParseStaticAssertDeclaration - Parse C++0x static_assert-declaratoion. @@ -254,13 +254,13 @@ Parser::DeclTy *Parser::ParseUsingDeclaration(unsigned Context, /// static_assert-declaration: /// static_assert ( constant-expression , string-literal ) ; /// -Parser::DeclTy *Parser::ParseStaticAssertDeclaration() { +Parser::DeclPtrTy Parser::ParseStaticAssertDeclaration() { assert(Tok.is(tok::kw_static_assert) && "Not a static_assert declaration"); SourceLocation StaticAssertLoc = ConsumeToken(); if (Tok.isNot(tok::l_paren)) { Diag(Tok, diag::err_expected_lparen); - return 0; + return DeclPtrTy(); } SourceLocation LParenLoc = ConsumeParen(); @@ -268,21 +268,21 @@ Parser::DeclTy *Parser::ParseStaticAssertDeclaration() { OwningExprResult AssertExpr(ParseConstantExpression()); if (AssertExpr.isInvalid()) { SkipUntil(tok::semi); - return 0; + return DeclPtrTy(); } if (ExpectAndConsume(tok::comma, diag::err_expected_comma, "", tok::semi)) - return 0; + return DeclPtrTy(); if (Tok.isNot(tok::string_literal)) { Diag(Tok, diag::err_expected_string_literal); SkipUntil(tok::semi); - return 0; + return DeclPtrTy(); } OwningExprResult AssertMessage(ParseStringLiteralExpression()); if (AssertMessage.isInvalid()) - return 0; + return DeclPtrTy(); MatchRHSPunctuation(tok::r_paren, LParenLoc); @@ -475,7 +475,7 @@ void Parser::ParseClassSpecifier(DeclSpec &DS, TagOrTempResult = Actions.ActOnClassTemplateSpecialization(CurScope, TagType, TK, StartLoc, SS, - TemplateId->Template, + DeclPtrTy::make(TemplateId->Template), TemplateId->TemplateNameLoc, TemplateId->LAngleLoc, TemplateArgsPtr, @@ -518,7 +518,7 @@ void Parser::ParseClassSpecifier(DeclSpec &DS, if (TagOrTempResult.isInvalid()) DS.SetTypeSpecError(); else if (DS.SetTypeSpecType(TagType, StartLoc, PrevSpec, - TagOrTempResult.get())) + TagOrTempResult.get().getAs())) Diag(StartLoc, diag::err_invalid_decl_spec_combination) << PrevSpec; } @@ -529,8 +529,7 @@ void Parser::ParseClassSpecifier(DeclSpec &DS, /// base-specifier-list: /// base-specifier '...'[opt] /// base-specifier-list ',' base-specifier '...'[opt] -void Parser::ParseBaseClause(DeclTy *ClassDecl) -{ +void Parser::ParseBaseClause(DeclPtrTy ClassDecl) { assert(Tok.is(tok::colon) && "Not a base clause"); ConsumeToken(); @@ -572,8 +571,7 @@ void Parser::ParseBaseClause(DeclTy *ClassDecl) /// class-name /// access-specifier 'virtual'[opt] ::[opt] nested-name-specifier[opt] /// class-name -Parser::BaseResult Parser::ParseBaseSpecifier(DeclTy *ClassDecl) -{ +Parser::BaseResult Parser::ParseBaseSpecifier(DeclPtrTy ClassDecl) { bool IsVirtual = false; SourceLocation StartLoc = Tok.getLocation(); @@ -666,7 +664,7 @@ AccessSpecifier Parser::getAccessSpecifierIfPresent() const /// constant-initializer: /// '=' constant-expression /// -Parser::DeclTy *Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS) { +Parser::DeclPtrTy Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS) { // static_assert-declaration if (Tok.is(tok::kw_static_assert)) return ParseStaticAssertDeclaration(); @@ -702,7 +700,7 @@ Parser::DeclTy *Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS) { return Actions.ParsedFreeStandingDeclSpec(CurScope, DS); default: Diag(DSStart, diag::err_no_declarators); - return 0; + return DeclPtrTy(); } } @@ -717,7 +715,7 @@ Parser::DeclTy *Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS) { SkipUntil(tok::r_brace, true); if (Tok.is(tok::semi)) ConsumeToken(); - return 0; + return DeclPtrTy(); } // function-definition: @@ -727,7 +725,7 @@ Parser::DeclTy *Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS) { Diag(Tok, diag::err_func_def_no_params); ConsumeBrace(); SkipUntil(tok::r_brace, true); - return 0; + return DeclPtrTy(); } if (DS.getStorageClassSpec() == DeclSpec::SCS_typedef) { @@ -737,7 +735,7 @@ Parser::DeclTy *Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS) { // assumes the declarator represents a function, not a typedef. ConsumeBrace(); SkipUntil(tok::r_brace, true); - return 0; + return DeclPtrTy(); } return ParseCXXInlineMethodDef(AS, DeclaratorInfo); @@ -748,7 +746,7 @@ Parser::DeclTy *Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS) { // member-declarator // member-declarator-list ',' member-declarator - DeclTy *LastDeclInGroup = 0; + DeclPtrTy LastDeclInGroup; OwningExprResult BitfieldSize(Actions); OwningExprResult Init(Actions); @@ -865,7 +863,7 @@ Parser::DeclTy *Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS) { SkipUntil(tok::r_brace, true, true); if (Tok.is(tok::semi)) ConsumeToken(); - return 0; + return DeclPtrTy(); } /// ParseCXXMemberSpecification - Parse the class definition. @@ -875,7 +873,7 @@ Parser::DeclTy *Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS) { /// access-specifier ':' member-specification[opt] /// void Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc, - unsigned TagType, DeclTy *TagDecl) { + unsigned TagType, DeclPtrTy TagDecl) { assert((TagType == DeclSpec::TST_struct || TagType == DeclSpec::TST_union || TagType == DeclSpec::TST_class) && "Invalid TagType!"); @@ -997,7 +995,7 @@ void Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc, /// [C++] mem-initializer-list: /// mem-initializer /// mem-initializer , mem-initializer-list -void Parser::ParseConstructorInitializer(DeclTy *ConstructorDecl) { +void Parser::ParseConstructorInitializer(DeclPtrTy ConstructorDecl) { assert(Tok.is(tok::colon) && "Constructor initializer always starts with ':'"); SourceLocation ColonLoc = ConsumeToken(); @@ -1035,7 +1033,7 @@ void Parser::ParseConstructorInitializer(DeclTy *ConstructorDecl) { /// [C++] mem-initializer-id: /// '::'[opt] nested-name-specifier[opt] class-name /// identifier -Parser::MemInitResult Parser::ParseMemInitializer(DeclTy *ConstructorDecl) { +Parser::MemInitResult Parser::ParseMemInitializer(DeclPtrTy ConstructorDecl) { // FIXME: parse '::'[opt] nested-name-specifier[opt] if (Tok.isNot(tok::identifier)) { diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp index b3ec24f864..dc57ac141c 100644 --- a/lib/Parse/ParseExprCXX.cpp +++ b/lib/Parse/ParseExprCXX.cpp @@ -117,7 +117,7 @@ bool Parser::ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS) { // an operator and not as part of a simple-template-id. } - DeclTy *Template = 0; + DeclPtrTy Template; TemplateNameKind TNK = TNK_Non_template; // FIXME: If the nested-name-specifier thus far is dependent, // set TNK = TNK_Dependent_template_name and skip the diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp index ca722fa68d..8ff1944a9d 100644 --- a/lib/Parse/ParseObjc.cpp +++ b/lib/Parse/ParseObjc.cpp @@ -28,7 +28,7 @@ using namespace clang; /// [OBJC] objc-protocol-definition /// [OBJC] objc-method-definition /// [OBJC] '@' 'end' -Parser::DeclTy *Parser::ParseObjCAtDirectives() { +Parser::DeclPtrTy Parser::ParseObjCAtDirectives() { SourceLocation AtLoc = ConsumeToken(); // the "@" switch (Tok.getObjCKeywordID()) { @@ -51,7 +51,7 @@ Parser::DeclTy *Parser::ParseObjCAtDirectives() { default: Diag(AtLoc, diag::err_unexpected_at); SkipUntil(tok::semi); - return 0; + return DeclPtrTy(); } } @@ -59,7 +59,7 @@ Parser::DeclTy *Parser::ParseObjCAtDirectives() { /// objc-class-declaration: /// '@' 'class' identifier-list ';' /// -Parser::DeclTy *Parser::ParseObjCAtClassDeclaration(SourceLocation atLoc) { +Parser::DeclPtrTy Parser::ParseObjCAtClassDeclaration(SourceLocation atLoc) { ConsumeToken(); // the identifier "class" llvm::SmallVector ClassNames; @@ -67,7 +67,7 @@ Parser::DeclTy *Parser::ParseObjCAtClassDeclaration(SourceLocation atLoc) { if (Tok.isNot(tok::identifier)) { Diag(Tok, diag::err_expected_ident); SkipUntil(tok::semi); - return 0; + return DeclPtrTy(); } ClassNames.push_back(Tok.getIdentifierInfo()); ConsumeToken(); @@ -80,7 +80,7 @@ Parser::DeclTy *Parser::ParseObjCAtClassDeclaration(SourceLocation atLoc) { // Consume the ';'. if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@class")) - return 0; + return DeclPtrTy(); return Actions.ActOnForwardClassDeclaration(atLoc, &ClassNames[0], ClassNames.size()); @@ -114,7 +114,7 @@ Parser::DeclTy *Parser::ParseObjCAtClassDeclaration(SourceLocation atLoc) { /// __attribute__((unavailable)) /// __attribute__((objc_exception)) - used by NSException on 64-bit /// -Parser::DeclTy *Parser::ParseObjCAtInterfaceDeclaration( +Parser::DeclPtrTy Parser::ParseObjCAtInterfaceDeclaration( SourceLocation atLoc, AttributeList *attrList) { assert(Tok.isObjCAtKeyword(tok::objc_interface) && "ParseObjCAtInterfaceDeclaration(): Expected @interface"); @@ -122,7 +122,7 @@ Parser::DeclTy *Parser::ParseObjCAtInterfaceDeclaration( if (Tok.isNot(tok::identifier)) { Diag(Tok, diag::err_expected_ident); // missing class or category name. - return 0; + return DeclPtrTy(); } // We have a class or category name - consume it. IdentifierInfo *nameId = Tok.getIdentifierInfo(); @@ -139,26 +139,26 @@ Parser::DeclTy *Parser::ParseObjCAtInterfaceDeclaration( categoryLoc = ConsumeToken(); } else if (!getLang().ObjC2) { Diag(Tok, diag::err_expected_ident); // missing category name. - return 0; + return DeclPtrTy(); } if (Tok.isNot(tok::r_paren)) { Diag(Tok, diag::err_expected_rparen); SkipUntil(tok::r_paren, false); // don't stop at ';' - return 0; + return DeclPtrTy(); } rparenLoc = ConsumeParen(); // Next, we need to check for any protocol references. SourceLocation EndProtoLoc; - llvm::SmallVector ProtocolRefs; + llvm::SmallVector ProtocolRefs; if (Tok.is(tok::less) && ParseObjCProtocolReferences(ProtocolRefs, true, EndProtoLoc)) - return 0; + return DeclPtrTy(); if (attrList) // categories don't support attributes. Diag(Tok, diag::err_objc_no_attributes_on_category); - DeclTy *CategoryType = Actions.ActOnStartCategoryInterface(atLoc, + DeclPtrTy CategoryType = Actions.ActOnStartCategoryInterface(atLoc, nameId, nameLoc, categoryId, categoryLoc, &ProtocolRefs[0], ProtocolRefs.size(), EndProtoLoc); @@ -174,19 +174,19 @@ Parser::DeclTy *Parser::ParseObjCAtInterfaceDeclaration( ConsumeToken(); if (Tok.isNot(tok::identifier)) { Diag(Tok, diag::err_expected_ident); // missing super class name. - return 0; + return DeclPtrTy(); } superClassId = Tok.getIdentifierInfo(); superClassLoc = ConsumeToken(); } // Next, we need to check for any protocol references. - llvm::SmallVector ProtocolRefs; + llvm::SmallVector ProtocolRefs; SourceLocation EndProtoLoc; if (Tok.is(tok::less) && ParseObjCProtocolReferences(ProtocolRefs, true, EndProtoLoc)) - return 0; + return DeclPtrTy(); - DeclTy *ClsType = + DeclPtrTy ClsType = Actions.ActOnStartClassInterface(atLoc, nameId, nameLoc, superClassId, superClassLoc, &ProtocolRefs[0], ProtocolRefs.size(), @@ -211,11 +211,11 @@ Parser::DeclTy *Parser::ParseObjCAtInterfaceDeclaration( /// @required /// @optional /// -void Parser::ParseObjCInterfaceDeclList(DeclTy *interfaceDecl, +void Parser::ParseObjCInterfaceDeclList(DeclPtrTy interfaceDecl, tok::ObjCKeywordKind contextKey) { - llvm::SmallVector allMethods; - llvm::SmallVector allProperties; - llvm::SmallVector allTUVariables; + llvm::SmallVector allMethods; + llvm::SmallVector allProperties; + llvm::SmallVector allTUVariables; tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword; SourceLocation AtEndLoc; @@ -223,7 +223,7 @@ void Parser::ParseObjCInterfaceDeclList(DeclTy *interfaceDecl, while (1) { // If this is a method prototype, parse it. if (Tok.is(tok::minus) || Tok.is(tok::plus)) { - DeclTy *methodPrototype = + DeclPtrTy methodPrototype = ParseObjCMethodPrototype(interfaceDecl, MethodImplKind); allMethods.push_back(methodPrototype); // Consume the ';' here, since ParseObjCMethodPrototype() is re-used for @@ -253,7 +253,7 @@ void Parser::ParseObjCInterfaceDeclList(DeclTy *interfaceDecl, // FIXME: as the name implies, this rule allows function definitions. // We could pass a flag or check for functions during semantic analysis. - DeclTy *VFDecl = ParseDeclarationOrFunctionDefinition(); + DeclPtrTy VFDecl = ParseDeclarationOrFunctionDefinition(); allTUVariables.push_back(VFDecl); continue; } @@ -337,11 +337,11 @@ void Parser::ParseObjCInterfaceDeclList(DeclTy *interfaceDecl, PP.getSelectorTable(), FD.D.getIdentifier()); bool isOverridingProperty = false; - DeclTy *Property = Actions.ActOnProperty(CurScope, AtLoc, FD, OCDS, - GetterSel, SetterSel, - interfaceDecl, - &isOverridingProperty, - MethodImplKind); + DeclPtrTy Property = Actions.ActOnProperty(CurScope, AtLoc, FD, OCDS, + GetterSel, SetterSel, + interfaceDecl, + &isOverridingProperty, + MethodImplKind); if (!isOverridingProperty) allProperties.push_back(Property); } @@ -461,14 +461,14 @@ void Parser::ParseObjCPropertyAttribute(ObjCDeclSpec &DS) { /// objc-method-attributes: [OBJC2] /// __attribute__((deprecated)) /// -Parser::DeclTy *Parser::ParseObjCMethodPrototype(DeclTy *IDecl, - tok::ObjCKeywordKind MethodImplKind) { +Parser::DeclPtrTy Parser::ParseObjCMethodPrototype(DeclPtrTy IDecl, + tok::ObjCKeywordKind MethodImplKind) { assert((Tok.is(tok::minus) || Tok.is(tok::plus)) && "expected +/-"); tok::TokenKind methodType = Tok.getKind(); SourceLocation mLoc = ConsumeToken(); - DeclTy *MDecl = ParseObjCMethodDecl(mLoc, methodType, IDecl, MethodImplKind); + DeclPtrTy MDecl = ParseObjCMethodDecl(mLoc, methodType, IDecl,MethodImplKind); // Since this rule is used for both method declarations and definitions, // the caller is (optionally) responsible for consuming the ';'. return MDecl; @@ -672,11 +672,10 @@ Parser::TypeTy *Parser::ParseObjCTypeName(ObjCDeclSpec &DS) { /// objc-keyword-attributes: [OBJC2] /// __attribute__((unused)) /// -Parser::DeclTy *Parser::ParseObjCMethodDecl(SourceLocation mLoc, - tok::TokenKind mType, - DeclTy *IDecl, - tok::ObjCKeywordKind MethodImplKind) -{ +Parser::DeclPtrTy Parser::ParseObjCMethodDecl(SourceLocation mLoc, + tok::TokenKind mType, + DeclPtrTy IDecl, + tok::ObjCKeywordKind MethodImplKind) { // Parse the return type if present. TypeTy *ReturnType = 0; ObjCDeclSpec DSRet; @@ -692,7 +691,7 @@ Parser::DeclTy *Parser::ParseObjCMethodDecl(SourceLocation mLoc, << SourceRange(mLoc, Tok.getLocation()); // Skip until we get a ; or {}. SkipUntil(tok::r_brace); - return 0; + return DeclPtrTy(); } llvm::SmallVector CargNames; @@ -789,7 +788,7 @@ Parser::DeclTy *Parser::ParseObjCMethodDecl(SourceLocation mLoc, /// '<' identifier-list '>' /// bool Parser:: -ParseObjCProtocolReferences(llvm::SmallVectorImpl &Protocols, +ParseObjCProtocolReferences(llvm::SmallVectorImpl &Protocols, bool WarnOnDeclarations, SourceLocation &EndLoc) { assert(Tok.is(tok::less) && "expected <"); @@ -847,10 +846,10 @@ ParseObjCProtocolReferences(llvm::SmallVectorImpl &Protocols, /// objc-instance-variable-decl: /// struct-declaration /// -void Parser::ParseObjCClassInstanceVariables(DeclTy *interfaceDecl, +void Parser::ParseObjCClassInstanceVariables(DeclPtrTy interfaceDecl, SourceLocation atLoc) { assert(Tok.is(tok::l_brace) && "expected {"); - llvm::SmallVector AllIvarDecls; + llvm::SmallVector AllIvarDecls; llvm::SmallVector FieldDeclarators; ParseScope ClassScope(this, Scope::DeclScope|Scope::ClassScope); @@ -895,9 +894,9 @@ void Parser::ParseObjCClassInstanceVariables(DeclTy *interfaceDecl, for (unsigned i = 0, e = FieldDeclarators.size(); i != e; ++i) { FieldDeclarator &FD = FieldDeclarators[i]; // Install the declarator into interfaceDecl. - DeclTy *Field = Actions.ActOnIvar(CurScope, - DS.getSourceRange().getBegin(), - FD.D, FD.BitfieldSize, visibility); + DeclPtrTy Field = Actions.ActOnIvar(CurScope, + DS.getSourceRange().getBegin(), + FD.D, FD.BitfieldSize, visibility); AllIvarDecls.push_back(Field); } @@ -934,15 +933,15 @@ void Parser::ParseObjCClassInstanceVariables(DeclTy *interfaceDecl, /// "@protocol identifier ;" should be resolved as "@protocol /// identifier-list ;": objc-interface-decl-list may not start with a /// semicolon in the first alternative if objc-protocol-refs are omitted. -Parser::DeclTy *Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc, - AttributeList *attrList) { +Parser::DeclPtrTy Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc, + AttributeList *attrList) { assert(Tok.isObjCAtKeyword(tok::objc_protocol) && "ParseObjCAtProtocolDeclaration(): Expected @protocol"); ConsumeToken(); // the "protocol" identifier if (Tok.isNot(tok::identifier)) { Diag(Tok, diag::err_expected_ident); // missing protocol name. - return 0; + return DeclPtrTy(); } // Save the protocol name, then consume it. IdentifierInfo *protocolName = Tok.getIdentifierInfo(); @@ -965,7 +964,7 @@ Parser::DeclTy *Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc, if (Tok.isNot(tok::identifier)) { Diag(Tok, diag::err_expected_ident); SkipUntil(tok::semi); - return 0; + return DeclPtrTy(); } ProtocolRefs.push_back(IdentifierLocPair(Tok.getIdentifierInfo(), Tok.getLocation())); @@ -976,7 +975,7 @@ Parser::DeclTy *Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc, } // Consume the ';'. if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@protocol")) - return 0; + return DeclPtrTy(); return Actions.ActOnForwardProtocolDeclaration(AtLoc, &ProtocolRefs[0], @@ -987,12 +986,12 @@ Parser::DeclTy *Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc, // Last, and definitely not least, parse a protocol declaration. SourceLocation EndProtoLoc; - llvm::SmallVector ProtocolRefs; + llvm::SmallVector ProtocolRefs; if (Tok.is(tok::less) && ParseObjCProtocolReferences(ProtocolRefs, true, EndProtoLoc)) - return 0; + return DeclPtrTy(); - DeclTy *ProtoType = + DeclPtrTy ProtoType = Actions.ActOnStartProtocolInterface(AtLoc, protocolName, nameLoc, &ProtocolRefs[0], ProtocolRefs.size(), EndProtoLoc, attrList); @@ -1010,8 +1009,7 @@ Parser::DeclTy *Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc, /// /// objc-category-implementation-prologue: /// @implementation identifier ( identifier ) - -Parser::DeclTy *Parser::ParseObjCAtImplementationDeclaration( +Parser::DeclPtrTy Parser::ParseObjCAtImplementationDeclaration( SourceLocation atLoc) { assert(Tok.isObjCAtKeyword(tok::objc_implementation) && "ParseObjCAtImplementationDeclaration(): Expected @implementation"); @@ -1019,7 +1017,7 @@ Parser::DeclTy *Parser::ParseObjCAtImplementationDeclaration( if (Tok.isNot(tok::identifier)) { Diag(Tok, diag::err_expected_ident); // missing class or category name. - return 0; + return DeclPtrTy(); } // We have a class or category name - consume it. IdentifierInfo *nameId = Tok.getIdentifierInfo(); @@ -1036,19 +1034,19 @@ Parser::DeclTy *Parser::ParseObjCAtImplementationDeclaration( categoryLoc = ConsumeToken(); } else { Diag(Tok, diag::err_expected_ident); // missing category name. - return 0; + return DeclPtrTy(); } if (Tok.isNot(tok::r_paren)) { Diag(Tok, diag::err_expected_rparen); SkipUntil(tok::r_paren, false); // don't stop at ';' - return 0; + return DeclPtrTy(); } rparenLoc = ConsumeParen(); - DeclTy *ImplCatType = Actions.ActOnStartCategoryImplementation( + DeclPtrTy ImplCatType = Actions.ActOnStartCategoryImplementation( atLoc, nameId, nameLoc, categoryId, categoryLoc); ObjCImpDecl = ImplCatType; - return 0; + return DeclPtrTy(); } // We have a class implementation SourceLocation superClassLoc; @@ -1058,12 +1056,12 @@ Parser::DeclTy *Parser::ParseObjCAtImplementationDeclaration( ConsumeToken(); if (Tok.isNot(tok::identifier)) { Diag(Tok, diag::err_expected_ident); // missing super class name. - return 0; + return DeclPtrTy(); } superClassId = Tok.getIdentifierInfo(); superClassLoc = ConsumeToken(); // Consume super class name } - DeclTy *ImplClsType = Actions.ActOnStartClassImplementation( + DeclPtrTy ImplClsType = Actions.ActOnStartClassImplementation( atLoc, nameId, nameLoc, superClassId, superClassLoc); @@ -1071,17 +1069,17 @@ Parser::DeclTy *Parser::ParseObjCAtImplementationDeclaration( ParseObjCClassInstanceVariables(ImplClsType/*FIXME*/, atLoc); ObjCImpDecl = ImplClsType; - return 0; + return DeclPtrTy(); } -Parser::DeclTy *Parser::ParseObjCAtEndDeclaration(SourceLocation atLoc) { +Parser::DeclPtrTy Parser::ParseObjCAtEndDeclaration(SourceLocation atLoc) { assert(Tok.isObjCAtKeyword(tok::objc_end) && "ParseObjCAtEndDeclaration(): Expected @end"); - DeclTy *Result = ObjCImpDecl; + DeclPtrTy Result = ObjCImpDecl; ConsumeToken(); // the "end" identifier if (ObjCImpDecl) { Actions.ActOnAtEnd(atLoc, ObjCImpDecl); - ObjCImpDecl = 0; + ObjCImpDecl = DeclPtrTy(); } else Diag(atLoc, diag::warn_expected_implementation); // missing @implementation @@ -1091,30 +1089,28 @@ Parser::DeclTy *Parser::ParseObjCAtEndDeclaration(SourceLocation atLoc) { /// compatibility-alias-decl: /// @compatibility_alias alias-name class-name ';' /// -Parser::DeclTy *Parser::ParseObjCAtAliasDeclaration(SourceLocation atLoc) { +Parser::DeclPtrTy Parser::ParseObjCAtAliasDeclaration(SourceLocation atLoc) { assert(Tok.isObjCAtKeyword(tok::objc_compatibility_alias) && "ParseObjCAtAliasDeclaration(): Expected @compatibility_alias"); ConsumeToken(); // consume compatibility_alias if (Tok.isNot(tok::identifier)) { Diag(Tok, diag::err_expected_ident); - return 0; + return DeclPtrTy(); } IdentifierInfo *aliasId = Tok.getIdentifierInfo(); SourceLocation aliasLoc = ConsumeToken(); // consume alias-name if (Tok.isNot(tok::identifier)) { Diag(Tok, diag::err_expected_ident); - return 0; + return DeclPtrTy(); } IdentifierInfo *classId = Tok.getIdentifierInfo(); SourceLocation classLoc = ConsumeToken(); // consume class-name; if (Tok.isNot(tok::semi)) { Diag(Tok, diag::err_expected_semi_after) << "@compatibility_alias"; - return 0; + return DeclPtrTy(); } - DeclTy *ClsType = Actions.ActOnCompatiblityAlias(atLoc, - aliasId, aliasLoc, - classId, classLoc); - return ClsType; + return Actions.ActOnCompatiblityAlias(atLoc, aliasId, aliasLoc, + classId, classLoc); } /// property-synthesis: @@ -1128,14 +1124,15 @@ Parser::DeclTy *Parser::ParseObjCAtAliasDeclaration(SourceLocation atLoc) { /// identifier /// identifier '=' identifier /// -Parser::DeclTy *Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) { +Parser::DeclPtrTy Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) { assert(Tok.isObjCAtKeyword(tok::objc_synthesize) && "ParseObjCPropertyDynamic(): Expected '@synthesize'"); SourceLocation loc = ConsumeToken(); // consume synthesize if (Tok.isNot(tok::identifier)) { Diag(Tok, diag::err_expected_ident); - return 0; + return DeclPtrTy(); } + while (Tok.is(tok::identifier)) { IdentifierInfo *propertyIvar = 0; IdentifierInfo *propertyId = Tok.getIdentifierInfo(); @@ -1158,7 +1155,7 @@ Parser::DeclTy *Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) { } if (Tok.isNot(tok::semi)) Diag(Tok, diag::err_expected_semi_after) << "@synthesize"; - return 0; + return DeclPtrTy(); } /// property-dynamic: @@ -1168,13 +1165,13 @@ Parser::DeclTy *Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) { /// identifier /// property-list ',' identifier /// -Parser::DeclTy *Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) { +Parser::DeclPtrTy Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) { assert(Tok.isObjCAtKeyword(tok::objc_dynamic) && "ParseObjCPropertyDynamic(): Expected '@dynamic'"); SourceLocation loc = ConsumeToken(); // consume dynamic if (Tok.isNot(tok::identifier)) { Diag(Tok, diag::err_expected_ident); - return 0; + return DeclPtrTy(); } while (Tok.is(tok::identifier)) { IdentifierInfo *propertyId = Tok.getIdentifierInfo(); @@ -1188,7 +1185,7 @@ Parser::DeclTy *Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) { } if (Tok.isNot(tok::semi)) Diag(Tok, diag::err_expected_semi_after) << "@dynamic"; - return 0; + return DeclPtrTy(); } /// objc-throw-statement: @@ -1283,7 +1280,7 @@ Parser::OwningStmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { SourceLocation AtCatchFinallyLoc = ConsumeToken(); if (Tok.isObjCAtKeyword(tok::objc_catch)) { - DeclTy *FirstPart = 0; + DeclPtrTy FirstPart; ConsumeToken(); // consume catch if (Tok.is(tok::l_paren)) { ConsumeParen(); @@ -1348,8 +1345,8 @@ Parser::OwningStmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { /// objc-method-def: objc-method-proto ';'[opt] '{' body '}' /// -Parser::DeclTy *Parser::ParseObjCMethodDefinition() { - DeclTy *MDecl = ParseObjCMethodPrototype(ObjCImpDecl); +Parser::DeclPtrTy Parser::ParseObjCMethodDefinition() { + DeclPtrTy MDecl = ParseObjCMethodPrototype(ObjCImpDecl); PrettyStackTraceActionsDecl CrashInfo(MDecl, Tok.getLocation(), Actions, PP.getSourceManager(), @@ -1368,7 +1365,7 @@ Parser::DeclTy *Parser::ParseObjCMethodDefinition() { // If we didn't find the '{', bail out. if (Tok.isNot(tok::l_brace)) - return 0; + return DeclPtrTy(); } SourceLocation BraceLoc = Tok.getLocation(); diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp index 1d2e82eae3..b996c74fcf 100644 --- a/lib/Parse/ParseStmt.cpp +++ b/lib/Parse/ParseStmt.cpp @@ -101,7 +101,7 @@ Parser::ParseStatementOrDeclaration(bool OnlyStatement) { default: { if ((getLang().CPlusPlus || !OnlyStatement) && isDeclarationStatement()) { SourceLocation DeclStart = Tok.getLocation(); - DeclTy *Decl = ParseDeclaration(Declarator::BlockContext); + DeclPtrTy Decl = ParseDeclaration(Declarator::BlockContext); // FIXME: Pass in the right location for the end of the declstmt. return Actions.ActOnDeclStmt(Decl, DeclStart, DeclStart); } @@ -208,7 +208,7 @@ Parser::OwningStmtResult Parser::ParseLabeledStatement() { SourceLocation ColonLoc = ConsumeToken(); // Read label attributes, if present. - DeclTy *AttrList = 0; + Action::AttrTy *AttrList = 0; if (Tok.is(tok::kw___attribute)) // TODO: save these somewhere. AttrList = ParseAttributes(); @@ -444,7 +444,7 @@ Parser::OwningStmtResult Parser::ParseCompoundStatementBody(bool isStmtExpr) { if (isDeclarationStatement()) { // FIXME: Save the __extension__ on the decl as a node somehow. SourceLocation DeclStart = Tok.getLocation(); - DeclTy *Res = ParseDeclaration(Declarator::BlockContext); + DeclPtrTy Res = ParseDeclaration(Declarator::BlockContext); // FIXME: Pass in the right location for the end of the declstmt. R = Actions.ActOnDeclStmt(Res, DeclStart, DeclStart); } else { @@ -912,7 +912,7 @@ Parser::OwningStmtResult Parser::ParseForStatement() { Diag(Tok, diag::ext_c99_variable_decl_in_for_loop); SourceLocation DeclStart = Tok.getLocation(); - DeclTy *aBlockVarDecl = ParseSimpleDeclaration(Declarator::ForContext); + DeclPtrTy aBlockVarDecl = ParseSimpleDeclaration(Declarator::ForContext); // FIXME: Pass in the right location for the end of the declstmt. FirstPart = Actions.ActOnDeclStmt(aBlockVarDecl, DeclStart, DeclStart); @@ -1287,7 +1287,7 @@ bool Parser::ParseAsmOperandsOpt(llvm::SmallVectorImpl &Names, return true; } -Parser::DeclTy *Parser::ParseFunctionStatementBody(DeclTy *Decl) { +Parser::DeclPtrTy Parser::ParseFunctionStatementBody(DeclPtrTy Decl) { assert(Tok.is(tok::l_brace)); SourceLocation LBraceLoc = Tok.getLocation(); @@ -1369,7 +1369,7 @@ Parser::OwningStmtResult Parser::ParseCXXCatchBlock() { // exception-declaration is equivalent to '...' or a parameter-declaration // without default arguments. - DeclTy *ExceptionDecl = 0; + DeclPtrTy ExceptionDecl; if (Tok.isNot(tok::ellipsis)) { DeclSpec DS; if (ParseCXXTypeSpecifierSeq(DS)) diff --git a/lib/Parse/ParseTemplate.cpp b/lib/Parse/ParseTemplate.cpp index 2c07823aba..29b8a147db 100644 --- a/lib/Parse/ParseTemplate.cpp +++ b/lib/Parse/ParseTemplate.cpp @@ -16,7 +16,6 @@ #include "clang/Parse/DeclSpec.h" #include "clang/Parse/Scope.h" #include "AstGuard.h" - using namespace clang; /// \brief Parse a template declaration or an explicit specialization. @@ -34,7 +33,7 @@ using namespace clang; /// /// explicit-specialization: [ C++ temp.expl.spec] /// 'template' '<' '>' declaration -Parser::DeclTy * +Parser::DeclPtrTy Parser::ParseTemplateDeclarationOrSpecialization(unsigned Context, AccessSpecifier AS) { assert((Tok.is(tok::kw_export) || Tok.is(tok::kw_template)) && @@ -78,7 +77,7 @@ Parser::ParseTemplateDeclarationOrSpecialization(unsigned Context, TemplateLoc = ConsumeToken(); } else { Diag(Tok.getLocation(), diag::err_expected_template); - return 0; + return DeclPtrTy(); } // Parse the '<' template-parameter-list '>' @@ -141,7 +140,7 @@ bool Parser::ParseTemplateParameterList(unsigned Depth, TemplateParameterList &TemplateParams) { while(1) { - if (DeclTy* TmpParam + if (DeclPtrTy TmpParam = ParseTemplateParameter(Depth, TemplateParams.size())) { TemplateParams.push_back(TmpParam); } else { @@ -183,7 +182,7 @@ Parser::ParseTemplateParameterList(unsigned Depth, /// 'typename' identifier[opt] '=' type-id /// 'template' '<' template-parameter-list '>' 'class' identifier[opt] /// 'template' '<' template-parameter-list '>' 'class' identifier[opt] = id-expression -Parser::DeclTy * +Parser::DeclPtrTy Parser::ParseTemplateParameter(unsigned Depth, unsigned Position) { if(Tok.is(tok::kw_class) || (Tok.is(tok::kw_typename) && @@ -210,7 +209,7 @@ Parser::ParseTemplateParameter(unsigned Depth, unsigned Position) { /// 'class' identifier[opt] '=' type-id /// 'typename' identifier[opt] /// 'typename' identifier[opt] '=' type-id -Parser::DeclTy *Parser::ParseTypeParameter(unsigned Depth, unsigned Position) { +Parser::DeclPtrTy Parser::ParseTypeParameter(unsigned Depth, unsigned Position){ assert((Tok.is(tok::kw_class) || Tok.is(tok::kw_typename)) && "A type-parameter starts with 'class' or 'typename'"); @@ -230,12 +229,12 @@ Parser::DeclTy *Parser::ParseTypeParameter(unsigned Depth, unsigned Position) { // don't consume this token. } else { Diag(Tok.getLocation(), diag::err_expected_ident); - return 0; + return DeclPtrTy(); } - DeclTy *TypeParam = Actions.ActOnTypeParameter(CurScope, TypenameKeyword, - KeyLoc, ParamName, NameLoc, - Depth, Position); + DeclPtrTy TypeParam = Actions.ActOnTypeParameter(CurScope, TypenameKeyword, + KeyLoc, ParamName, NameLoc, + Depth, Position); // Grab a default type id (if given). if(Tok.is(tok::equal)) { @@ -256,7 +255,7 @@ Parser::DeclTy *Parser::ParseTypeParameter(unsigned Depth, unsigned Position) { /// type-parameter: [C++ temp.param] /// 'template' '<' template-parameter-list '>' 'class' identifier[opt] /// 'template' '<' template-parameter-list '>' 'class' identifier[opt] = id-expression -Parser::DeclTy * +Parser::DeclPtrTy Parser::ParseTemplateTemplateParameter(unsigned Depth, unsigned Position) { assert(Tok.is(tok::kw_template) && "Expected 'template' keyword"); @@ -268,7 +267,7 @@ Parser::ParseTemplateTemplateParameter(unsigned Depth, unsigned Position) { ParseScope TemplateParmScope(this, Scope::TemplateParamScope); if(!ParseTemplateParameters(Depth + 1, TemplateParams, LAngleLoc, RAngleLoc)) { - return 0; + return DeclPtrTy(); } } @@ -277,7 +276,7 @@ Parser::ParseTemplateTemplateParameter(unsigned Depth, unsigned Position) { if(!Tok.is(tok::kw_class)) { Diag(Tok.getLocation(), diag::err_expected_class_before) << PP.getSpelling(Tok); - return 0; + return DeclPtrTy(); } SourceLocation ClassLoc = ConsumeToken(); @@ -292,7 +291,7 @@ Parser::ParseTemplateTemplateParameter(unsigned Depth, unsigned Position) { // don't consume this token. } else { Diag(Tok.getLocation(), diag::err_expected_ident); - return 0; + return DeclPtrTy(); } TemplateParamsTy *ParamList = @@ -302,7 +301,7 @@ Parser::ParseTemplateTemplateParameter(unsigned Depth, unsigned Position) { TemplateParams.size(), RAngleLoc); - Parser::DeclTy * Param + Parser::DeclPtrTy Param = Actions.ActOnTemplateTemplateParameter(CurScope, TemplateLoc, ParamList, ParamName, NameLoc, Depth, Position); @@ -334,7 +333,7 @@ Parser::ParseTemplateTemplateParameter(unsigned Depth, unsigned Position) { /// parameters. /// FIXME: We need to make a ParseParameterDeclaration that works for /// non-type template parameters and normal function parameters. -Parser::DeclTy * +Parser::DeclPtrTy Parser::ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position) { SourceLocation StartLoc = Tok.getLocation(); @@ -354,12 +353,12 @@ Parser::ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position) { // TODO: This is currently a placeholder for some kind of Sema Error. Diag(Tok.getLocation(), diag::err_parse_error); SkipUntil(tok::comma, tok::greater, true, true); - return 0; + return DeclPtrTy(); } // Create the parameter. - DeclTy *Param = Actions.ActOnNonTypeTemplateParameter(CurScope, ParamDecl, - Depth, Position); + DeclPtrTy Param = Actions.ActOnNonTypeTemplateParameter(CurScope, ParamDecl, + Depth, Position); // If there is a default value, parse it. if (Tok.is(tok::equal)) { @@ -402,7 +401,7 @@ Parser::ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position) { /// last token in the stream (e.g., so that it can be replaced with an /// annotation token). bool -Parser::ParseTemplateIdAfterTemplateName(DeclTy *Template, +Parser::ParseTemplateIdAfterTemplateName(DeclPtrTy Template, SourceLocation TemplateNameLoc, const CXXScopeSpec *SS, bool ConsumeLastToken, @@ -495,7 +494,7 @@ Parser::ParseTemplateIdAfterTemplateName(DeclTy *Template, /// replaced with a type annotation token. Otherwise, the /// simple-template-id is always replaced with a template-id /// annotation token. -void Parser::AnnotateTemplateIdToken(DeclTy *Template, TemplateNameKind TNK, +void Parser::AnnotateTemplateIdToken(DeclPtrTy Template, TemplateNameKind TNK, const CXXScopeSpec *SS, SourceLocation TemplateKWLoc, bool AllowTypeAnnotation) { @@ -552,7 +551,7 @@ void Parser::AnnotateTemplateIdToken(DeclTy *Template, TemplateNameKind TNK, = TemplateIdAnnotation::Allocate(TemplateArgs.size()); TemplateId->TemplateNameLoc = TemplateNameLoc; TemplateId->Name = Name; - TemplateId->Template = Template; + TemplateId->Template = Template.getAs(); TemplateId->Kind = TNK; TemplateId->LAngleLoc = LAngleLoc; TemplateId->RAngleLoc = RAngleLoc; @@ -599,7 +598,7 @@ bool Parser::AnnotateTemplateIdTokenAsType(const CXXScopeSpec *SS) { TemplateId->NumArgs); Action::TypeResult Type - = Actions.ActOnClassTemplateId(TemplateId->Template, + = Actions.ActOnClassTemplateId(DeclPtrTy::make(TemplateId->Template), TemplateId->TemplateNameLoc, TemplateId->LAngleLoc, TemplateArgsPtr, diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp index 7f2c5d307b..00a3349c21 100644 --- a/lib/Parse/Parser.cpp +++ b/lib/Parse/Parser.cpp @@ -27,7 +27,7 @@ Parser::Parser(Preprocessor &pp, Action &actions) CurScope = 0; NumCachedScopes = 0; ParenCount = BracketCount = BraceCount = 0; - ObjCImpDecl = 0; + ObjCImpDecl = DeclPtrTy(); // Add #pragma handlers. These are removed and destroyed in the // destructor. @@ -324,8 +324,8 @@ void Parser::Initialize() { /// ParseTopLevelDecl - Parse one top-level declaration, return whatever the /// action tells us to. This returns true if the EOF was encountered. -bool Parser::ParseTopLevelDecl(DeclTy*& Result) { - Result = 0; +bool Parser::ParseTopLevelDecl(DeclPtrTy &Result) { + Result = DeclPtrTy(); if (Tok.is(tok::eof)) { Actions.ActOnEndOfTranslationUnit(); return true; @@ -342,7 +342,7 @@ bool Parser::ParseTopLevelDecl(DeclTy*& Result) { void Parser::ParseTranslationUnit() { Initialize(); - DeclTy *Res; + DeclPtrTy Res; while (!ParseTopLevelDecl(Res)) /*parse them all*/; @@ -368,20 +368,20 @@ void Parser::ParseTranslationUnit() { /// [GNU] asm-definition: /// simple-asm-expr ';' /// -Parser::DeclTy *Parser::ParseExternalDeclaration() { +Parser::DeclPtrTy Parser::ParseExternalDeclaration() { switch (Tok.getKind()) { case tok::semi: Diag(Tok, diag::ext_top_level_semi); ConsumeToken(); // TODO: Invoke action for top-level semicolon. - return 0; + return DeclPtrTy(); case tok::r_brace: Diag(Tok, diag::err_expected_external_declaration); ConsumeBrace(); - return 0; + return DeclPtrTy(); case tok::eof: Diag(Tok, diag::err_expected_external_declaration); - return 0; + return DeclPtrTy(); case tok::kw___extension__: { // __extension__ silences extension warnings in the subexpression. ExtensionRAIIObject O(Diags); // Use RAII to do this. @@ -396,7 +396,7 @@ Parser::DeclTy *Parser::ParseExternalDeclaration() { if (!Result.isInvalid()) return Actions.ActOnFileScopeAsmDecl(Tok.getLocation(), move(Result)); - return 0; + return DeclPtrTy(); } case tok::at: // @ is not a legal token unless objc is enabled, no need to check. @@ -405,11 +405,9 @@ Parser::DeclTy *Parser::ParseExternalDeclaration() { case tok::plus: if (getLang().ObjC1) return ParseObjCMethodDefinition(); - else { - Diag(Tok, diag::err_expected_external_declaration); - ConsumeToken(); - } - return 0; + Diag(Tok, diag::err_expected_external_declaration); + ConsumeToken(); + return DeclPtrTy(); case tok::kw_using: case tok::kw_namespace: case tok::kw_typedef: @@ -440,7 +438,7 @@ Parser::DeclTy *Parser::ParseExternalDeclaration() { /// [!C99] init-declarator-list ';' [TODO: warn in c99 mode] /// [OMP] threadprivate-directive [TODO] /// -Parser::DeclTy * +Parser::DeclPtrTy Parser::ParseDeclarationOrFunctionDefinition( TemplateParameterLists *TemplateParams, AccessSpecifier AS) { @@ -464,7 +462,7 @@ Parser::ParseDeclarationOrFunctionDefinition( !Tok.isObjCAtKeyword(tok::objc_protocol)) { Diag(Tok, diag::err_objc_unexpected_attr); SkipUntil(tok::semi); // FIXME: better skip? - return 0; + return DeclPtrTy(); } const char *PrevSpec = 0; if (DS.SetTypeSpecType(DeclSpec::TST_unspecified, AtLoc, PrevSpec)) @@ -491,7 +489,7 @@ Parser::ParseDeclarationOrFunctionDefinition( SkipUntil(tok::r_brace, true, true); if (Tok.is(tok::semi)) ConsumeToken(); - return 0; + return DeclPtrTy(); } // If the declarator is the start of a function definition, handle it. @@ -521,7 +519,7 @@ Parser::ParseDeclarationOrFunctionDefinition( } else { SkipUntil(tok::semi); } - return 0; + return DeclPtrTy(); } return ParseFunctionDefinition(DeclaratorInfo); } else { @@ -530,7 +528,7 @@ Parser::ParseDeclarationOrFunctionDefinition( else Diag(Tok, diag::err_invalid_token_after_toplevel_declarator); SkipUntil(tok::semi); - return 0; + return DeclPtrTy(); } // Parse the init-declarator-list for a normal declaration. @@ -550,7 +548,7 @@ Parser::ParseDeclarationOrFunctionDefinition( /// [C++] function-definition: [C++ 8.4] /// decl-specifier-seq[opt] declarator function-try-block [TODO] /// -Parser::DeclTy *Parser::ParseFunctionDefinition(Declarator &D) { +Parser::DeclPtrTy Parser::ParseFunctionDefinition(Declarator &D) { const DeclaratorChunk &FnTypeInfo = D.getTypeObject(0); assert(FnTypeInfo.Kind == DeclaratorChunk::Function && "This isn't a function declarator!"); @@ -584,7 +582,7 @@ Parser::DeclTy *Parser::ParseFunctionDefinition(Declarator &D) { // If we didn't find the '{', bail out. if (Tok.isNot(tok::l_brace)) - return 0; + return DeclPtrTy(); } // Enter a scope for the function body. @@ -592,7 +590,7 @@ Parser::DeclTy *Parser::ParseFunctionDefinition(Declarator &D) { // Tell the actions module that we have entered a function definition with the // specified Declarator for the function. - DeclTy *Res = Actions.ActOnStartOfFunctionDef(CurScope, D); + DeclPtrTy Res = Actions.ActOnStartOfFunctionDef(CurScope, D); // If we have a colon, then we're probably parsing a C++ // ctor-initializer. @@ -652,14 +650,14 @@ void Parser::ParseKNRParamDeclarations(Declarator &D) { // Handle the full declarator list. while (1) { - DeclTy *AttrList; + Action::AttrTy *AttrList; // If attributes are present, parse them. if (Tok.is(tok::kw___attribute)) // FIXME: attach attributes too. AttrList = ParseAttributes(); // Ask the actions module to compute the type for this declarator. - Action::DeclTy *Param = + Action::DeclPtrTy Param = Actions.ActOnParamDeclarator(CurScope, ParmDeclarator); if (Param && @@ -862,7 +860,7 @@ bool Parser::TryAnnotateTypeOrScopeToken() { // If this is a template-id, annotate with a template-id or type token. if (NextToken().is(tok::less)) { - DeclTy *Template; + DeclPtrTy Template; if (TemplateNameKind TNK = Actions.isTemplateName(*Tok.getIdentifierInfo(), CurScope, Template, &SS)) diff --git a/lib/Sema/IdentifierResolver.cpp b/lib/Sema/IdentifierResolver.cpp index 10eec7afb9..c31435b677 100644 --- a/lib/Sema/IdentifierResolver.cpp +++ b/lib/Sema/IdentifierResolver.cpp @@ -112,7 +112,7 @@ bool IdentifierResolver::isDeclInScope(Decl *D, DeclContext *Ctx, ((DeclContext *)S->getEntity())->isTransparentContext()) S = S->getParent(); - if (S->isDeclScope(D)) + if (S->isDeclScope(Action::DeclPtrTy::make(D))) return true; if (LangOpt.CPlusPlus) { // C++ 3.3.2p3: @@ -129,7 +129,7 @@ bool IdentifierResolver::isDeclInScope(Decl *D, DeclContext *Ctx, // assert(S->getParent() && "No TUScope?"); if (S->getParent()->getFlags() & Scope::ControlScope) - return S->getParent()->isDeclScope(D); + return S->getParent()->isDeclScope(Action::DeclPtrTy::make(D)); } return false; } diff --git a/lib/Sema/ParseAST.cpp b/lib/Sema/ParseAST.cpp index fdc57b6e24..59a04dad64 100644 --- a/lib/Sema/ParseAST.cpp +++ b/lib/Sema/ParseAST.cpp @@ -44,14 +44,14 @@ void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer, Consumer->Initialize(Ctx); - Parser::DeclTy *ADecl; + Parser::DeclPtrTy ADecl; while (!P.ParseTopLevelDecl(ADecl)) { // Not end of file. // If we got a null return and something *was* parsed, ignore it. This // is due to a top-level semicolon, an action override, or a parse error // skipping something. if (ADecl) { - Decl* D = static_cast(ADecl); + Decl *D = ADecl.getAs(); Consumer->HandleTopLevelDecl(D); } }; diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index 9662c43bb3..7e72a8453b 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -231,10 +231,10 @@ void Sema::ActOnEndOfTranslationUnit() { // Note: we traverse the scope's list of declarations rather than // the DeclContext's list, because we only want to see the most // recent declaration of each identifier. - for (Scope::decl_iterator I = TUScope->decl_begin(), - IEnd = TUScope->decl_end(); + for (Scope::decl_iterator I = TUScope->decl_begin(), + IEnd = TUScope->decl_end(); I != IEnd; ++I) { - Decl *D = static_cast(*I); + Decl *D = (*I).getAs(); if (D->isInvalidDecl()) continue; diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index ab845595b1..a7c48c838b 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -307,7 +307,7 @@ public: QualType GetTypeForDeclarator(Declarator &D, Scope *S, unsigned Skip = 0); DeclarationName GetNameForDeclarator(Declarator &D); - QualType ObjCGetTypeForMethodDefinition(DeclTy *D); + QualType ObjCGetTypeForMethodDefinition(DeclPtrTy D); bool UnwrapSimilarPointerTypes(QualType& T1, QualType& T2); @@ -326,15 +326,16 @@ public: /// getDeclName - Return a pretty name for the specified decl if possible, or /// an empty string if not. This is used for pretty crash reporting. - virtual std::string getDeclName(DeclTy *D); + virtual std::string getDeclName(DeclPtrTy D); virtual TypeTy *getTypeName(IdentifierInfo &II, SourceLocation NameLoc, Scope *S, const CXXScopeSpec *SS); - virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup){ + virtual DeclPtrTy ActOnDeclarator(Scope *S, Declarator &D, + DeclPtrTy LastInGroup){ return ActOnDeclarator(S, D, LastInGroup, false); } - DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup, - bool IsFunctionDefinition); + DeclPtrTy ActOnDeclarator(Scope *S, Declarator &D, DeclPtrTy LastInGroup, + bool IsFunctionDefinition); void RegisterLocallyScopedExternCDecl(NamedDecl *ND, NamedDecl *PrevDecl, Scope *S); NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC, @@ -355,26 +356,26 @@ public: bool CheckFunctionDeclaration(FunctionDecl *NewFD, NamedDecl *&PrevDecl, bool &Redeclaration, bool &OverloadableAttrRequired); - virtual DeclTy *ActOnParamDeclarator(Scope *S, Declarator &D); - virtual void ActOnParamDefaultArgument(DeclTy *param, + virtual DeclPtrTy ActOnParamDeclarator(Scope *S, Declarator &D); + virtual void ActOnParamDefaultArgument(DeclPtrTy param, SourceLocation EqualLoc, ExprArg defarg); - virtual void ActOnParamUnparsedDefaultArgument(DeclTy *param, + virtual void ActOnParamUnparsedDefaultArgument(DeclPtrTy param, SourceLocation EqualLoc); - virtual void ActOnParamDefaultArgumentError(DeclTy *param); - virtual void AddInitializerToDecl(DeclTy *dcl, ExprArg init); - void AddInitializerToDecl(DeclTy *dcl, ExprArg init, bool DirectInit); - void ActOnUninitializedDecl(DeclTy *dcl); - virtual void SetDeclDeleted(DeclTy *dcl, SourceLocation DelLoc); - virtual DeclTy *FinalizeDeclaratorGroup(Scope *S, DeclTy *Group); + virtual void ActOnParamDefaultArgumentError(DeclPtrTy param); + virtual void AddInitializerToDecl(DeclPtrTy dcl, ExprArg init); + void AddInitializerToDecl(DeclPtrTy dcl, ExprArg init, bool DirectInit); + void ActOnUninitializedDecl(DeclPtrTy dcl); + virtual void SetDeclDeleted(DeclPtrTy dcl, SourceLocation DelLoc); + virtual DeclPtrTy FinalizeDeclaratorGroup(Scope *S, DeclPtrTy Group); virtual void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D); - virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, Declarator &D); - virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, DeclTy *D); - virtual void ActOnStartOfObjCMethodDef(Scope *S, DeclTy *D); + virtual DeclPtrTy ActOnStartOfFunctionDef(Scope *S, Declarator &D); + virtual DeclPtrTy ActOnStartOfFunctionDef(Scope *S, DeclPtrTy D); + virtual void ActOnStartOfObjCMethodDef(Scope *S, DeclPtrTy D); - virtual DeclTy *ActOnFinishFunctionBody(DeclTy *Decl, StmtArg Body); - virtual DeclTy *ActOnFileScopeAsmDecl(SourceLocation Loc, ExprArg expr); + virtual DeclPtrTy ActOnFinishFunctionBody(DeclPtrTy Decl, StmtArg Body); + virtual DeclPtrTy ActOnFileScopeAsmDecl(SourceLocation Loc, ExprArg expr); /// Scope actions. virtual void ActOnPopScope(SourceLocation Loc, Scope *S); @@ -382,23 +383,24 @@ public: /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with /// no declarator (e.g. "struct foo;") is parsed. - virtual DeclTy *ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS); + virtual DeclPtrTy ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS); bool InjectAnonymousStructOrUnionMembers(Scope *S, DeclContext *Owner, RecordDecl *AnonRecord); - virtual DeclTy *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, - RecordDecl *Record); + virtual DeclPtrTy BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, + RecordDecl *Record); - virtual DeclTy *ActOnTag(Scope *S, unsigned TagSpec, TagKind TK, - SourceLocation KWLoc, const CXXScopeSpec &SS, - IdentifierInfo *Name, SourceLocation NameLoc, - AttributeList *Attr, AccessSpecifier AS); + virtual DeclPtrTy ActOnTag(Scope *S, unsigned TagSpec, TagKind TK, + SourceLocation KWLoc, const CXXScopeSpec &SS, + IdentifierInfo *Name, SourceLocation NameLoc, + AttributeList *Attr, AccessSpecifier AS); - virtual void ActOnDefs(Scope *S, DeclTy *TagD, SourceLocation DeclStart, + virtual void ActOnDefs(Scope *S, DeclPtrTy TagD, SourceLocation DeclStart, IdentifierInfo *ClassName, - llvm::SmallVectorImpl &Decls); - virtual DeclTy *ActOnField(Scope *S, DeclTy *TagD, SourceLocation DeclStart, - Declarator &D, ExprTy *BitfieldWidth); + llvm::SmallVectorImpl &Decls); + virtual DeclPtrTy ActOnField(Scope *S, DeclPtrTy TagD, + SourceLocation DeclStart, + Declarator &D, ExprTy *BitfieldWidth); FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart, Declarator &D, Expr *BitfieldWidth, @@ -410,25 +412,25 @@ public: AccessSpecifier AS, NamedDecl *PrevDecl, Declarator *D = 0); - virtual DeclTy *ActOnIvar(Scope *S, SourceLocation DeclStart, - Declarator &D, ExprTy *BitfieldWidth, - tok::ObjCKeywordKind visibility); + virtual DeclPtrTy ActOnIvar(Scope *S, SourceLocation DeclStart, + Declarator &D, ExprTy *BitfieldWidth, + tok::ObjCKeywordKind visibility); // This is used for both record definitions and ObjC interface declarations. virtual void ActOnFields(Scope* S, - SourceLocation RecLoc, DeclTy *TagDecl, - DeclTy **Fields, unsigned NumFields, + SourceLocation RecLoc, DeclPtrTy TagDecl, + DeclPtrTy *Fields, unsigned NumFields, SourceLocation LBrac, SourceLocation RBrac, AttributeList *AttrList); /// ActOnTagStartDefinition - Invoked when we have entered the /// scope of a tag's definition (e.g., for an enumeration, class, /// struct, or union). - virtual void ActOnTagStartDefinition(Scope *S, DeclTy *TagDecl); + virtual void ActOnTagStartDefinition(Scope *S, DeclPtrTy TagDecl); /// ActOnTagFinishDefinition - Invoked once we have finished parsing /// the definition of a tag (enumeration, class, struct, or union). - virtual void ActOnTagFinishDefinition(Scope *S, DeclTy *TagDecl); + virtual void ActOnTagFinishDefinition(Scope *S, DeclPtrTy TagDecl); EnumConstantDecl *CheckEnumConstant(EnumDecl *Enum, EnumConstantDecl *LastEnumConst, @@ -436,12 +438,12 @@ public: IdentifierInfo *Id, ExprArg val); - virtual DeclTy *ActOnEnumConstant(Scope *S, DeclTy *EnumDecl, - DeclTy *LastEnumConstant, - SourceLocation IdLoc, IdentifierInfo *Id, - SourceLocation EqualLoc, ExprTy *Val); - virtual void ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDecl, - DeclTy **Elements, unsigned NumElements); + virtual DeclPtrTy ActOnEnumConstant(Scope *S, DeclPtrTy EnumDecl, + DeclPtrTy LastEnumConstant, + SourceLocation IdLoc, IdentifierInfo *Id, + SourceLocation EqualLoc, ExprTy *Val); + virtual void ActOnEnumBody(SourceLocation EnumLoc, DeclPtrTy EnumDecl, + DeclPtrTy *Elements, unsigned NumElements); DeclContext *getContainingDC(DeclContext *DC); @@ -1082,7 +1084,8 @@ public: virtual OwningStmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, MultiStmtArg Elts, bool isStmtExpr); - virtual OwningStmtResult ActOnDeclStmt(DeclTy *Decl, SourceLocation StartLoc, + virtual OwningStmtResult ActOnDeclStmt(DeclPtrTy Decl, + SourceLocation StartLoc, SourceLocation EndLoc); virtual OwningStmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprArg LHSVal, SourceLocation DotDotDotLoc, ExprArg RHSVal, @@ -1147,7 +1150,7 @@ public: virtual OwningStmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen, - DeclTy *Parm, StmtArg Body, + DeclPtrTy Parm, StmtArg Body, StmtArg CatchList); virtual OwningStmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, @@ -1164,9 +1167,9 @@ public: ExprArg SynchExpr, StmtArg SynchBody); - virtual DeclTy *ActOnExceptionDeclarator(Scope *S, Declarator &D); + virtual DeclPtrTy ActOnExceptionDeclarator(Scope *S, Declarator &D); virtual OwningStmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc, - DeclTy *ExDecl, + DeclPtrTy ExDecl, StmtArg HandlerBlock); virtual OwningStmtResult ActOnCXXTryBlock(SourceLocation TryLoc, StmtArg TryBlock, @@ -1255,7 +1258,7 @@ public: tok::TokenKind OpKind, SourceLocation MemberLoc, IdentifierInfo &Member, - DeclTy *ImplDecl=0); + DeclPtrTy ImplDecl); bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn, FunctionDecl *FDecl, const FunctionProtoType *Proto, @@ -1358,32 +1361,32 @@ public: //===---------------------------- C++ Features --------------------------===// // Act on C++ namespaces - virtual DeclTy *ActOnStartNamespaceDef(Scope *S, SourceLocation IdentLoc, - IdentifierInfo *Ident, - SourceLocation LBrace); - virtual void ActOnFinishNamespaceDef(DeclTy *Dcl, SourceLocation RBrace); - - virtual DeclTy *ActOnUsingDirective(Scope *CurScope, - SourceLocation UsingLoc, - SourceLocation NamespcLoc, - const CXXScopeSpec &SS, - SourceLocation IdentLoc, - IdentifierInfo *NamespcName, - AttributeList *AttrList); + virtual DeclPtrTy ActOnStartNamespaceDef(Scope *S, SourceLocation IdentLoc, + IdentifierInfo *Ident, + SourceLocation LBrace); + virtual void ActOnFinishNamespaceDef(DeclPtrTy Dcl, SourceLocation RBrace); + + virtual DeclPtrTy ActOnUsingDirective(Scope *CurScope, + SourceLocation UsingLoc, + SourceLocation NamespcLoc, + const CXXScopeSpec &SS, + SourceLocation IdentLoc, + IdentifierInfo *NamespcName, + AttributeList *AttrList); void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir); - virtual DeclTy *ActOnNamespaceAliasDef(Scope *CurScope, - SourceLocation AliasLoc, - IdentifierInfo *Alias, - const CXXScopeSpec &SS, - SourceLocation NamespaceLoc, - IdentifierInfo *NamespaceName); + virtual DeclPtrTy ActOnNamespaceAliasDef(Scope *CurScope, + SourceLocation AliasLoc, + IdentifierInfo *Alias, + const CXXScopeSpec &SS, + SourceLocation NamespaceLoc, + IdentifierInfo *NamespaceName); /// AddCXXDirectInitializerToDecl - This action is called immediately after /// ActOnDeclarator, when a C++ direct initializer is present. /// e.g: "int x(1);" - virtual void AddCXXDirectInitializerToDecl(DeclTy *Dcl, + virtual void AddCXXDirectInitializerToDecl(DeclPtrTy Dcl, SourceLocation LParenLoc, MultiExprArg Exprs, SourceLocation *CommaLocs, @@ -1565,15 +1568,15 @@ public: //===--------------------------------------------------------------------===// // C++ Declarations // - virtual DeclTy *ActOnStartLinkageSpecification(Scope *S, - SourceLocation ExternLoc, - SourceLocation LangLoc, - const char *Lang, - unsigned StrSize, - SourceLocation LBraceLoc); - virtual DeclTy *ActOnFinishLinkageSpecification(Scope *S, - DeclTy *LinkageSpec, - SourceLocation RBraceLoc); + virtual DeclPtrTy ActOnStartLinkageSpecification(Scope *S, + SourceLocation ExternLoc, + SourceLocation LangLoc, + const char *Lang, + unsigned StrSize, + SourceLocation LBraceLoc); + virtual DeclPtrTy ActOnFinishLinkageSpecification(Scope *S, + DeclPtrTy LinkageSpec, + SourceLocation RBraceLoc); //===--------------------------------------------------------------------===// @@ -1582,11 +1585,13 @@ public: virtual bool isCurrentClassName(const IdentifierInfo &II, Scope *S, const CXXScopeSpec *SS); - virtual DeclTy *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, - Declarator &D, ExprTy *BitfieldWidth, - ExprTy *Init, DeclTy *LastInGroup); + virtual DeclPtrTy ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, + Declarator &D, + ExprTy *BitfieldWidth, + ExprTy *Init, + DeclPtrTy LastInGroup); - virtual MemInitResult ActOnMemInitializer(DeclTy *ConstructorD, + virtual MemInitResult ActOnMemInitializer(DeclPtrTy ConstructorD, Scope *S, IdentifierInfo *MemberOrBase, SourceLocation IdLoc, @@ -1597,22 +1602,24 @@ public: void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl); - virtual void ActOnMemInitializers(DeclTy *ConstructorDecl, + virtual void ActOnMemInitializers(DeclPtrTy ConstructorDecl, SourceLocation ColonLoc, MemInitTy **MemInits, unsigned NumMemInits); virtual void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc, - DeclTy *TagDecl, + DeclPtrTy TagDecl, SourceLocation LBrac, SourceLocation RBrac); - virtual void ActOnStartDelayedCXXMethodDeclaration(Scope *S, DeclTy *Method); - virtual void ActOnDelayedCXXMethodParameter(Scope *S, DeclTy *Param); - virtual void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, DeclTy *Method); + virtual void ActOnStartDelayedCXXMethodDeclaration(Scope *S, + DeclPtrTy Method); + virtual void ActOnDelayedCXXMethodParameter(Scope *S, DeclPtrTy Param); + virtual void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, + DeclPtrTy Method); - virtual DeclTy *ActOnStaticAssertDeclaration(SourceLocation AssertLoc, - ExprArg AssertExpr, - ExprArg AssertMessageExpr); + virtual DeclPtrTy ActOnStaticAssertDeclaration(SourceLocation AssertLoc, + ExprArg AssertExpr, + ExprArg AssertMessageExpr); bool CheckConstructorDeclarator(Declarator &D, QualType &R, FunctionDecl::StorageClass& SC); @@ -1621,7 +1628,7 @@ public: FunctionDecl::StorageClass& SC); bool CheckConversionDeclarator(Declarator &D, QualType &R, FunctionDecl::StorageClass& SC); - DeclTy *ActOnConversionDeclarator(CXXConversionDecl *Conversion); + DeclPtrTy ActOnConversionDeclarator(CXXConversionDecl *Conversion); //===--------------------------------------------------------------------===// // C++ Derived Classes @@ -1633,7 +1640,7 @@ public: bool Virtual, AccessSpecifier Access, QualType BaseType, SourceLocation BaseLoc); - virtual BaseResult ActOnBaseSpecifier(DeclTy *classdecl, + virtual BaseResult ActOnBaseSpecifier(DeclPtrTy classdecl, SourceRange SpecifierRange, bool Virtual, AccessSpecifier Access, TypeTy *basetype, SourceLocation @@ -1641,7 +1648,7 @@ public: bool AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases, unsigned NumBases); - virtual void ActOnBaseSpecifiers(DeclTy *ClassDecl, BaseTy **Bases, + virtual void ActOnBaseSpecifiers(DeclPtrTy ClassDecl, BaseTy **Bases, unsigned NumBases); bool IsDerivedFrom(QualType Derived, QualType Base); @@ -1686,36 +1693,36 @@ public: // C++ Templates [C++ 14] // virtual TemplateNameKind isTemplateName(IdentifierInfo &II, Scope *S, - DeclTy *&TemplateDecl, + DeclPtrTy &TemplateDecl, const CXXScopeSpec *SS = 0); bool DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl); - TemplateDecl *AdjustDeclIfTemplate(DeclTy *&Decl); - - virtual DeclTy *ActOnTypeParameter(Scope *S, bool Typename, - SourceLocation KeyLoc, - IdentifierInfo *ParamName, - SourceLocation ParamNameLoc, - unsigned Depth, unsigned Position); - virtual void ActOnTypeParameterDefault(DeclTy *TypeParam, + TemplateDecl *AdjustDeclIfTemplate(DeclPtrTy &Decl); + + virtual DeclPtrTy ActOnTypeParameter(Scope *S, bool Typename, + SourceLocation KeyLoc, + IdentifierInfo *ParamName, + SourceLocation ParamNameLoc, + unsigned Depth, unsigned Position); + virtual void ActOnTypeParameterDefault(DeclPtrTy TypeParam, SourceLocation EqualLoc, SourceLocation DefaultLoc, TypeTy *Default); QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc); - virtual DeclTy *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, - unsigned Depth, - unsigned Position); - virtual void ActOnNonTypeTemplateParameterDefault(DeclTy *TemplateParam, + virtual DeclPtrTy ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, + unsigned Depth, + unsigned Position); + virtual void ActOnNonTypeTemplateParameterDefault(DeclPtrTy TemplateParam, SourceLocation EqualLoc, ExprArg Default); - virtual DeclTy *ActOnTemplateTemplateParameter(Scope *S, - SourceLocation TmpLoc, - TemplateParamsTy *Params, - IdentifierInfo *ParamName, - SourceLocation ParamNameLoc, - unsigned Depth, - unsigned Position); - virtual void ActOnTemplateTemplateParameterDefault(DeclTy *TemplateParam, + virtual DeclPtrTy ActOnTemplateTemplateParameter(Scope *S, + SourceLocation TmpLoc, + TemplateParamsTy *Params, + IdentifierInfo *ParamName, + SourceLocation ParamNameLoc, + unsigned Depth, + unsigned Position); + virtual void ActOnTemplateTemplateParameterDefault(DeclPtrTy TemplateParam, SourceLocation EqualLoc, ExprArg Default); @@ -1724,7 +1731,7 @@ public: SourceLocation ExportLoc, SourceLocation TemplateLoc, SourceLocation LAngleLoc, - DeclTy **Params, unsigned NumParams, + DeclPtrTy *Params, unsigned NumParams, SourceLocation RAngleLoc); bool CheckTemplateParameterList(TemplateParameterList *NewParams, TemplateParameterList *OldParams); @@ -1745,7 +1752,7 @@ public: SourceLocation RAngleLoc); virtual TypeResult - ActOnClassTemplateId(DeclTy *Template, SourceLocation TemplateLoc, + ActOnClassTemplateId(DeclPtrTy Template, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ASTTemplateArgsPtr TemplateArgs, SourceLocation *TemplateArgLocs, @@ -1761,7 +1768,7 @@ public: ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagKind TK, SourceLocation KWLoc, const CXXScopeSpec &SS, - DeclTy *Template, + DeclPtrTy Template, SourceLocation TemplateNameLoc, SourceLocation LAngleLoc, ASTTemplateArgsPtr TemplateArgs, @@ -1981,17 +1988,17 @@ public: } // Objective-C declarations. - virtual DeclTy *ActOnStartClassInterface(SourceLocation AtInterfaceLoc, - IdentifierInfo *ClassName, - SourceLocation ClassLoc, - IdentifierInfo *SuperName, - SourceLocation SuperLoc, - DeclTy * const *ProtoRefs, - unsigned NumProtoRefs, - SourceLocation EndProtoLoc, - AttributeList *AttrList); - - virtual DeclTy *ActOnCompatiblityAlias( + virtual DeclPtrTy ActOnStartClassInterface(SourceLocation AtInterfaceLoc, + IdentifierInfo *ClassName, + SourceLocation ClassLoc, + IdentifierInfo *SuperName, + SourceLocation SuperLoc, + const DeclPtrTy *ProtoRefs, + unsigned NumProtoRefs, + SourceLocation EndProtoLoc, + AttributeList *AttrList); + + virtual DeclPtrTy ActOnCompatiblityAlias( SourceLocation AtCompatibilityAliasLoc, IdentifierInfo *AliasName, SourceLocation AliasLocation, IdentifierInfo *ClassName, SourceLocation ClassLocation); @@ -2001,40 +2008,40 @@ public: SourceLocation &PLoc, SourceLocation PrevLoc, const ObjCList &PList); - virtual DeclTy *ActOnStartProtocolInterface( + virtual DeclPtrTy ActOnStartProtocolInterface( SourceLocation AtProtoInterfaceLoc, IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc, - DeclTy * const *ProtoRefNames, unsigned NumProtoRefs, + const DeclPtrTy *ProtoRefNames, unsigned NumProtoRefs, SourceLocation EndProtoLoc, AttributeList *AttrList); - virtual DeclTy *ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc, - IdentifierInfo *ClassName, - SourceLocation ClassLoc, - IdentifierInfo *CategoryName, - SourceLocation CategoryLoc, - DeclTy * const *ProtoRefs, - unsigned NumProtoRefs, - SourceLocation EndProtoLoc); + virtual DeclPtrTy ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc, + IdentifierInfo *ClassName, + SourceLocation ClassLoc, + IdentifierInfo *CategoryName, + SourceLocation CategoryLoc, + const DeclPtrTy *ProtoRefs, + unsigned NumProtoRefs, + SourceLocation EndProtoLoc); - virtual DeclTy *ActOnStartClassImplementation( + virtual DeclPtrTy ActOnStartClassImplementation( SourceLocation AtClassImplLoc, IdentifierInfo *ClassName, SourceLocation ClassLoc, IdentifierInfo *SuperClassname, SourceLocation SuperClassLoc); - virtual DeclTy *ActOnStartCategoryImplementation( + virtual DeclPtrTy ActOnStartCategoryImplementation( SourceLocation AtCatImplLoc, IdentifierInfo *ClassName, SourceLocation ClassLoc, IdentifierInfo *CatName, SourceLocation CatLoc); - virtual DeclTy *ActOnForwardClassDeclaration(SourceLocation Loc, + virtual DeclPtrTy ActOnForwardClassDeclaration(SourceLocation Loc, IdentifierInfo **IdentList, unsigned NumElts); - virtual DeclTy *ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc, + virtual DeclPtrTy ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc, const IdentifierLocPair *IdentList, unsigned NumElts, AttributeList *attrList); @@ -2042,7 +2049,7 @@ public: virtual void FindProtocolDeclaration(bool WarnOnDeclarations, const IdentifierLocPair *ProtocolId, unsigned NumProtocols, - llvm::SmallVectorImpl &Protocols); + llvm::SmallVectorImpl &Protocols); /// Ensure attributes are consistent with type. /// \param [in, out] Attributes The attributes to check; they will @@ -2057,7 +2064,7 @@ public: void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl); void MergeProtocolPropertiesIntoClass(Decl *CDecl, - DeclTy *MergeProtocols); + DeclPtrTy MergeProtocols); void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT, ObjCInterfaceDecl *ID); @@ -2065,28 +2072,29 @@ public: void MergeOneProtocolPropertiesIntoClass(Decl *CDecl, ObjCProtocolDecl *PDecl); - virtual void ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl, - DeclTy **allMethods = 0, unsigned allNum = 0, - DeclTy **allProperties = 0, unsigned pNum = 0, - DeclTy **allTUVars = 0, unsigned tuvNum = 0); - - virtual DeclTy *ActOnProperty(Scope *S, SourceLocation AtLoc, - FieldDeclarator &FD, ObjCDeclSpec &ODS, - Selector GetterSel, Selector SetterSel, - DeclTy *ClassCategory, bool *OverridingProperty, - tok::ObjCKeywordKind MethodImplKind); - - virtual DeclTy *ActOnPropertyImplDecl(SourceLocation AtLoc, - SourceLocation PropertyLoc, - bool ImplKind, DeclTy *ClassImplDecl, - IdentifierInfo *PropertyId, - IdentifierInfo *PropertyIvar); - - virtual DeclTy *ActOnMethodDeclaration( + virtual void ActOnAtEnd(SourceLocation AtEndLoc, DeclPtrTy classDecl, + DeclPtrTy *allMethods = 0, unsigned allNum = 0, + DeclPtrTy *allProperties = 0, unsigned pNum = 0, + DeclPtrTy *allTUVars = 0, unsigned tuvNum = 0); + + virtual DeclPtrTy ActOnProperty(Scope *S, SourceLocation AtLoc, + FieldDeclarator &FD, ObjCDeclSpec &ODS, + Selector GetterSel, Selector SetterSel, + DeclPtrTy ClassCategory, + bool *OverridingProperty, + tok::ObjCKeywordKind MethodImplKind); + + virtual DeclPtrTy ActOnPropertyImplDecl(SourceLocation AtLoc, + SourceLocation PropertyLoc, + bool ImplKind,DeclPtrTy ClassImplDecl, + IdentifierInfo *PropertyId, + IdentifierInfo *PropertyIvar); + + virtual DeclPtrTy ActOnMethodDeclaration( SourceLocation BeginLoc, // location of the + or -. SourceLocation EndLoc, // location of the ; or {. tok::TokenKind MethodType, - DeclTy *ClassDecl, ObjCDeclSpec &ReturnQT, TypeTy *ReturnType, + DeclPtrTy ClassDecl, ObjCDeclSpec &ReturnQT, TypeTy *ReturnType, Selector Sel, // optional arguments. The number of types/arguments is obtained // from the Sel.getNumArgs(). diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index fa386ef68d..f98da95697 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -32,8 +32,8 @@ using namespace clang; /// getDeclName - Return a pretty name for the specified decl if possible, or /// an empty string if not. This is used for pretty crash reporting. -std::string Sema::getDeclName(DeclTy *d) { - Decl *D = static_cast(d); +std::string Sema::getDeclName(DeclPtrTy d) { + Decl *D = d.getAs(); if (NamedDecl *DN = dyn_cast_or_null(D)) return DN->getQualifiedNameAsString(); return ""; @@ -177,7 +177,7 @@ void Sema::PushOnScopeChains(NamedDecl *D, Scope *S) { ((DeclContext *)S->getEntity())->isTransparentContext()) S = S->getParent(); - S->AddDecl(D); + S->AddDecl(DeclPtrTy::make(D)); // Add scoped declarations into their context, so that they can be // found later. Declarations without a context won't be inserted @@ -207,7 +207,7 @@ void Sema::PushOnScopeChains(NamedDecl *D, Scope *S) { // This is a redeclaration. Remove it from the chain and // break out, so that we'll add in the shadowed // declaration. - S->RemoveDecl(*I); + S->RemoveDecl(DeclPtrTy::make(*I)); if (PrevDecl == *I) { IdResolver.RemoveDecl(*I); IdResolver.AddDecl(TD); @@ -238,10 +238,11 @@ void Sema::PushOnScopeChains(NamedDecl *D, Scope *S) { IdResolver.end(), std::bind1st(std::mem_fun(&NamedDecl::declarationReplaces), FD)); - if (Redecl != IdResolver.end() && S->isDeclScope(*Redecl)) { + if (Redecl != IdResolver.end() && + S->isDeclScope(DeclPtrTy::make(*Redecl))) { // There is already a declaration of a function on our // IdResolver chain. Replace it with this declaration. - S->RemoveDecl(*Redecl); + S->RemoveDecl(DeclPtrTy::make(*Redecl)); IdResolver.RemoveDecl(*Redecl); } } @@ -256,7 +257,7 @@ void Sema::ActOnPopScope(SourceLocation Loc, Scope *S) { for (Scope::decl_iterator I = S->decl_begin(), E = S->decl_end(); I != E; ++I) { - Decl *TmpD = static_cast(*I); + Decl *TmpD = (*I).getAs(); assert(TmpD && "This decl didn't get pushed??"); assert(isa(TmpD) && "Decl isn't NamedDecl?"); @@ -903,7 +904,7 @@ bool Sema::CheckParmsForFunctionDef(FunctionDecl *FD) { /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with /// no declarator (e.g. "struct foo;") is parsed. -Sema::DeclTy *Sema::ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS) { +Sema::DeclPtrTy Sema::ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS) { TagDecl *Tag = 0; if (DS.getTypeSpecType() == DeclSpec::TST_class || DS.getTypeSpecType() == DeclSpec::TST_struct || @@ -926,7 +927,7 @@ Sema::DeclTy *Sema::ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS) { // about them. // FIXME: Should we support Microsoft's extensions in this area? if (Record->getDeclName() && getLangOptions().Microsoft) - return Tag; + return DeclPtrTy::make(Tag); } if (!DS.isMissingDeclaratorOk() && @@ -937,15 +938,15 @@ Sema::DeclTy *Sema::ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS) { Tag && isa(Tag)) { Diag(DS.getSourceRange().getBegin(), diag::ext_typedef_without_a_name) << DS.getSourceRange(); - return Tag; + return DeclPtrTy::make(Tag); } Diag(DS.getSourceRange().getBegin(), diag::err_no_declarators) << DS.getSourceRange(); - return 0; + return DeclPtrTy(); } - return Tag; + return DeclPtrTy::make(Tag); } /// InjectAnonymousStructOrUnionMembers - Inject the members of the @@ -992,7 +993,7 @@ bool Sema::InjectAnonymousStructOrUnionMembers(Scope *S, DeclContext *Owner, // considered to have been defined in the scope in which the // anonymous union is declared. Owner->makeDeclVisibleInContext(*F); - S->AddDecl(*F); + S->AddDecl(DeclPtrTy::make(*F)); IdResolver.AddDecl(*F); } } else if (const RecordType *InnerRecordType @@ -1011,8 +1012,8 @@ bool Sema::InjectAnonymousStructOrUnionMembers(Scope *S, DeclContext *Owner, /// anonymous structure or union. Anonymous unions are a C++ feature /// (C++ [class.union]) and a GNU C extension; anonymous structures /// are a GNU C and GNU C++ extension. -Sema::DeclTy *Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, - RecordDecl *Record) { +Sema::DeclPtrTy Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, + RecordDecl *Record) { DeclContext *Owner = Record->getDeclContext(); // Diagnose whether this anonymous struct/union is an extension. @@ -1165,7 +1166,7 @@ Sema::DeclTy *Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, if (Invalid) Anon->setInvalidDecl(); - return Anon; + return DeclPtrTy::make(Anon); } @@ -1233,10 +1234,11 @@ static bool isNearlyMatchingFunction(ASTContext &Context, return true; } -Sema::DeclTy * -Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl, +Sema::DeclPtrTy +Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclPtrTy lastDecl, bool IsFunctionDefinition) { - NamedDecl *LastDeclarator = dyn_cast_or_null((Decl *)lastDecl); + NamedDecl *LastDeclarator = + dyn_cast_or_null(lastDecl.getAs()); DeclarationName Name = GetNameForDeclarator(D); // All of these full declarators require an identifier. If it doesn't have @@ -1246,7 +1248,7 @@ Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl, Diag(D.getDeclSpec().getSourceRange().getBegin(), diag::err_declarator_need_ident) << D.getDeclSpec().getSourceRange() << D.getSourceRange(); - return 0; + return DeclPtrTy(); } // The scope passed in may not be a decl scope. Zip up the scope tree until @@ -1366,7 +1368,7 @@ Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl, } if (New == 0) - return 0; + return DeclPtrTy(); // If this has an identifier and is not an invalid redeclaration, // add it to the scope stack. @@ -1376,7 +1378,7 @@ Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl, if (D.getInvalidType() || InvalidDecl) New->setInvalidDecl(); - return New; + return DeclPtrTy::make(New); } /// TryToFixInvalidVariablyModifiedType - Helper method to turn variable array @@ -1442,11 +1444,11 @@ Sema::RegisterLocallyScopedExternCDecl(NamedDecl *ND, NamedDecl *PrevDecl, if (S && IdResolver.ReplaceDecl(PrevDecl, ND)) { // The previous declaration was found on the identifer resolver // chain, so remove it from its scope. - while (S && !S->isDeclScope(PrevDecl)) + while (S && !S->isDeclScope(DeclPtrTy::make(PrevDecl))) S = S->getParent(); if (S) - S->RemoveDecl(PrevDecl); + S->RemoveDecl(DeclPtrTy::make(PrevDecl)); } } @@ -2009,9 +2011,9 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, // already checks for that case. if (FTI.NumArgs == 1 && !FTI.isVariadic && FTI.ArgInfo[0].Ident == 0 && FTI.ArgInfo[0].Param && - ((ParmVarDecl*)FTI.ArgInfo[0].Param)->getType()->isVoidType()) { + FTI.ArgInfo[0].Param.getAs()->getType()->isVoidType()) { // empty arg list, don't push any params. - ParmVarDecl *Param = (ParmVarDecl*)FTI.ArgInfo[0].Param; + ParmVarDecl *Param = FTI.ArgInfo[0].Param.getAs(); // In C++, the empty parameter-type-list must be spelled "void"; a // typedef of void is not permitted. @@ -2020,10 +2022,8 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, Diag(Param->getLocation(), diag::ext_param_typedef_of_void); } } else if (FTI.NumArgs > 0 && FTI.ArgInfo[0].Param != 0) { - for (unsigned i = 0, e = FTI.NumArgs; i != e; ++i) { - ParmVarDecl *PVD = (ParmVarDecl *)FTI.ArgInfo[i].Param; - Params.push_back(PVD); - } + for (unsigned i = 0, e = FTI.NumArgs; i != e; ++i) + Params.push_back(FTI.ArgInfo[i].Param.getAs()); } NewFD->setParams(Context, &Params[0], Params.size()); @@ -2267,15 +2267,15 @@ bool Sema::CheckForConstantInitializer(Expr *Init, QualType DclT) { return true; } -void Sema::AddInitializerToDecl(DeclTy *dcl, ExprArg init) { +void Sema::AddInitializerToDecl(DeclPtrTy dcl, ExprArg init) { AddInitializerToDecl(dcl, move(init), /*DirectInit=*/false); } /// AddInitializerToDecl - Adds the initializer Init to the /// declaration dcl. If DirectInit is true, this is C++ direct /// initialization rather than copy initialization. -void Sema::AddInitializerToDecl(DeclTy *dcl, ExprArg init, bool DirectInit) { - Decl *RealDecl = static_cast(dcl); +void Sema::AddInitializerToDecl(DeclPtrTy dcl, ExprArg init, bool DirectInit) { + Decl *RealDecl = dcl.getAs(); // If there is no declaration, there was an error parsing it. Just ignore // the initializer. if (RealDecl == 0) @@ -2430,8 +2430,8 @@ void Sema::AddInitializerToDecl(DeclTy *dcl, ExprArg init, bool DirectInit) { return; } -void Sema::ActOnUninitializedDecl(DeclTy *dcl) { - Decl *RealDecl = static_cast(dcl); +void Sema::ActOnUninitializedDecl(DeclPtrTy dcl) { + Decl *RealDecl = dcl.getAs(); // If there is no declaration, there was an error parsing it. Just ignore it. if (RealDecl == 0) @@ -2518,11 +2518,11 @@ void Sema::ActOnUninitializedDecl(DeclTy *dcl) { } /// The declarators are chained together backwards, reverse the list. -Sema::DeclTy *Sema::FinalizeDeclaratorGroup(Scope *S, DeclTy *group) { +Sema::DeclPtrTy Sema::FinalizeDeclaratorGroup(Scope *S, DeclPtrTy group) { // Often we have single declarators, handle them quickly. - Decl *Group = static_cast(group); + Decl *Group = group.getAs(); if (Group == 0) - return 0; + return DeclPtrTy(); Decl *NewGroup = 0; if (Group->getNextDeclarator() == 0) @@ -2578,12 +2578,12 @@ Sema::DeclTy *Sema::FinalizeDeclaratorGroup(Scope *S, DeclTy *group) { } } } - return NewGroup; + return DeclPtrTy::make(NewGroup); } /// ActOnParamDeclarator - Called from Parser::ParseFunctionDeclarator() /// to introduce parameters into function prototype scope. -Sema::DeclTy * +Sema::DeclPtrTy Sema::ActOnParamDeclarator(Scope *S, Declarator &D) { const DeclSpec &DS = D.getDeclSpec(); @@ -2625,7 +2625,7 @@ Sema::ActOnParamDeclarator(Scope *S, Declarator &D) { DiagnoseTemplateParameterShadow(D.getIdentifierLoc(), PrevDecl); // Just pretend that we didn't see the previous declaration. PrevDecl = 0; - } else if (S->isDeclScope(PrevDecl)) { + } else if (S->isDeclScope(DeclPtrTy::make(PrevDecl))) { Diag(D.getIdentifierLoc(), diag::err_param_redefinition) << II; // Recover by removing the name @@ -2675,13 +2675,12 @@ Sema::ActOnParamDeclarator(Scope *S, Declarator &D) { } // Add the parameter declaration into this scope. - S->AddDecl(New); + S->AddDecl(DeclPtrTy::make(New)); if (II) IdResolver.AddDecl(New); ProcessDeclAttributes(New, D); - return New; - + return DeclPtrTy::make(New); } void Sema::ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D) { @@ -2710,7 +2709,8 @@ void Sema::ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D) { } } -Sema::DeclTy *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Declarator &D) { +Sema::DeclPtrTy Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, + Declarator &D) { assert(getCurFunctionDecl() == 0 && "Function parsing confused"); assert(D.getTypeObject(0).Kind == DeclaratorChunk::Function && "Not a function declarator!"); @@ -2723,13 +2723,12 @@ Sema::DeclTy *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Declarator &D) { Scope *ParentScope = FnBodyScope->getParent(); return ActOnStartOfFunctionDef(FnBodyScope, - ActOnDeclarator(ParentScope, D, 0, - /*IsFunctionDefinition=*/true)); + ActOnDeclarator(ParentScope, D, DeclPtrTy(), + /*IsFunctionDefinition=*/true)); } -Sema::DeclTy *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, DeclTy *D) { - Decl *decl = static_cast(D); - FunctionDecl *FD = cast(decl); +Sema::DeclPtrTy Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, DeclPtrTy D) { + FunctionDecl *FD = cast(D.getAs()); // See if this is a redefinition. const FunctionDecl *Definition; @@ -2778,7 +2777,7 @@ Sema::DeclTy *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, DeclTy *D) { diag::err_attribute_can_be_applied_only_to_symbol_declaration) << "dllimport"; FD->setInvalidDecl(); - return FD; + return DeclPtrTy::make(FD); } else { // If a symbol previously declared dllimport is later defined, the // attribute is ignored in subsequent references, and a warning is @@ -2788,7 +2787,7 @@ Sema::DeclTy *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, DeclTy *D) { << FD->getNameAsCString() << "dllimport"; } } - return FD; + return DeclPtrTy::make(FD); } static bool StatementCreatesScope(Stmt* S) { @@ -2868,8 +2867,8 @@ void Sema::RecursiveCalcJumpScopes(llvm::DenseMap& LabelScopeMap, } } -Sema::DeclTy *Sema::ActOnFinishFunctionBody(DeclTy *D, StmtArg BodyArg) { - Decl *dcl = static_cast(D); +Sema::DeclPtrTy Sema::ActOnFinishFunctionBody(DeclPtrTy D, StmtArg BodyArg) { + Decl *dcl = D.getAs(); Stmt *Body = static_cast(BodyArg.release()); if (FunctionDecl *FD = dyn_cast_or_null(dcl)) { FD->setBody(cast(Body)); @@ -2879,7 +2878,7 @@ Sema::DeclTy *Sema::ActOnFinishFunctionBody(DeclTy *D, StmtArg BodyArg) { MD->setBody(cast(Body)); } else { Body->Destroy(Context); - return 0; + return DeclPtrTy(); } PopDeclContext(); // Verify and clean out per-function state. @@ -2974,7 +2973,7 @@ NamedDecl *Sema::ImplicitlyDefineFunction(SourceLocation Loc, CurContext = Context.getTranslationUnitDecl(); FunctionDecl *FD = - dyn_cast(static_cast(ActOnDeclarator(TUScope, D, 0))); + dyn_cast(ActOnDeclarator(TUScope, D, DeclPtrTy()).getAs()); FD->setImplicit(); CurContext = PrevDC; @@ -3087,10 +3086,10 @@ TypedefDecl *Sema::ParseTypedefDecl(Scope *S, Declarator &D, QualType T, /// former case, Name will be non-null. In the later case, Name will be null. /// TagSpec indicates what kind of tag this is. TK indicates whether this is a /// reference/declaration/definition of a tag. -Sema::DeclTy *Sema::ActOnTag(Scope *S, unsigned TagSpec, TagKind TK, - SourceLocation KWLoc, const CXXScopeSpec &SS, - IdentifierInfo *Name, SourceLocation NameLoc, - AttributeList *Attr, AccessSpecifier AS) { +Sema::DeclPtrTy Sema::ActOnTag(Scope *S, unsigned TagSpec, TagKind TK, + SourceLocation KWLoc, const CXXScopeSpec &SS, + IdentifierInfo *Name, SourceLocation NameLoc, + AttributeList *Attr, AccessSpecifier AS) { // If this is not a definition, it must have a name. assert((Name != 0 || TK == TK_Definition) && "Nameless record must be a definition!"); @@ -3197,7 +3196,7 @@ Sema::DeclTy *Sema::ActOnTag(Scope *S, unsigned TagSpec, TagKind TK, // For our current ASTs this shouldn't be a problem, but will // need to be changed with DeclGroups. if (TK == TK_Reference) - return PrevDecl; + return DeclPtrTy::make(PrevDecl); // Diagnose attempts to redefine a tag. if (TK == TK_Definition) { @@ -3398,12 +3397,12 @@ CreateNewDecl: CurContext->addDecl(New); } - return New; + return DeclPtrTy::make(New); } -void Sema::ActOnTagStartDefinition(Scope *S, DeclTy *TagD) { +void Sema::ActOnTagStartDefinition(Scope *S, DeclPtrTy TagD) { AdjustDeclIfTemplate(TagD); - TagDecl *Tag = cast((Decl *)TagD); + TagDecl *Tag = cast(TagD.getAs()); // Enter the tag context. PushDeclContext(S, Tag); @@ -3432,9 +3431,9 @@ void Sema::ActOnTagStartDefinition(Scope *S, DeclTy *TagD) { } } -void Sema::ActOnTagFinishDefinition(Scope *S, DeclTy *TagD) { +void Sema::ActOnTagFinishDefinition(Scope *S, DeclPtrTy TagD) { AdjustDeclIfTemplate(TagD); - TagDecl *Tag = cast((Decl *)TagD); + TagDecl *Tag = cast(TagD.getAs()); if (isa(Tag)) FieldCollector->FinishClass(); @@ -3488,13 +3487,13 @@ bool Sema::VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName, /// ActOnField - Each field of a struct/union/class is passed into this in order /// to create a FieldDecl object for it. -Sema::DeclTy *Sema::ActOnField(Scope *S, DeclTy *TagD, - SourceLocation DeclStart, - Declarator &D, ExprTy *BitfieldWidth) { - - return HandleField(S, static_cast(TagD), DeclStart, D, - static_cast(BitfieldWidth), - AS_public); +Sema::DeclPtrTy Sema::ActOnField(Scope *S, DeclPtrTy TagD, + SourceLocation DeclStart, + Declarator &D, ExprTy *BitfieldWidth) { + FieldDecl *Res = HandleField(S, cast_or_null(TagD.getAs()), + DeclStart, D, static_cast(BitfieldWidth), + AS_public); + return DeclPtrTy::make(Res); } /// HandleField - Analyze a field of a C struct or a C++ data member. @@ -3647,10 +3646,10 @@ TranslateIvarVisibility(tok::ObjCKeywordKind ivarVisibility) { /// ActOnIvar - Each ivar field of an objective-c class is passed into this /// in order to create an IvarDecl object for it. -Sema::DeclTy *Sema::ActOnIvar(Scope *S, - SourceLocation DeclStart, - Declarator &D, ExprTy *BitfieldWidth, - tok::ObjCKeywordKind Visibility) { +Sema::DeclPtrTy Sema::ActOnIvar(Scope *S, + SourceLocation DeclStart, + Declarator &D, ExprTy *BitfieldWidth, + tok::ObjCKeywordKind Visibility) { IdentifierInfo *II = D.getIdentifier(); Expr *BitWidth = (Expr*)BitfieldWidth; @@ -3713,19 +3712,19 @@ Sema::DeclTy *Sema::ActOnIvar(Scope *S, if (II) { // FIXME: When interfaces are DeclContexts, we'll need to add // these to the interface. - S->AddDecl(NewID); + S->AddDecl(DeclPtrTy::make(NewID)); IdResolver.AddDecl(NewID); } - return NewID; + return DeclPtrTy::make(NewID); } void Sema::ActOnFields(Scope* S, - SourceLocation RecLoc, DeclTy *RecDecl, - DeclTy **Fields, unsigned NumFields, + SourceLocation RecLoc, DeclPtrTy RecDecl, + DeclPtrTy *Fields, unsigned NumFields, SourceLocation LBrac, SourceLocation RBrac, AttributeList *Attr) { - Decl *EnclosingDecl = static_cast(RecDecl); + Decl *EnclosingDecl = RecDecl.getAs(); assert(EnclosingDecl && "missing record or interface decl"); // If the decl this is being inserted into is invalid, then it may be a @@ -3742,8 +3741,7 @@ void Sema::ActOnFields(Scope* S, RecordDecl *Record = dyn_cast(EnclosingDecl); for (unsigned i = 0; i != NumFields; ++i) { - FieldDecl *FD = cast_or_null(static_cast(Fields[i])); - assert(FD && "missing field decl"); + FieldDecl *FD = cast(Fields[i].getAs()); // Get the type for the field. Type *FDTy = FD->getType().getTypePtr(); @@ -3916,13 +3914,14 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl *Enum, } -Sema::DeclTy *Sema::ActOnEnumConstant(Scope *S, DeclTy *theEnumDecl, - DeclTy *lastEnumConst, - SourceLocation IdLoc, IdentifierInfo *Id, - SourceLocation EqualLoc, ExprTy *val) { - EnumDecl *TheEnumDecl = cast(static_cast(theEnumDecl)); +Sema::DeclPtrTy Sema::ActOnEnumConstant(Scope *S, DeclPtrTy theEnumDecl, + DeclPtrTy lastEnumConst, + SourceLocation IdLoc, + IdentifierInfo *Id, + SourceLocation EqualLoc, ExprTy *val) { + EnumDecl *TheEnumDecl = cast(theEnumDecl.getAs()); EnumConstantDecl *LastEnumConst = - cast_or_null(static_cast(lastEnumConst)); + cast_or_null(lastEnumConst.getAs()); Expr *Val = static_cast(val); // The scope passed in may not be a decl scope. Zip up the scope tree until @@ -3951,7 +3950,7 @@ Sema::DeclTy *Sema::ActOnEnumConstant(Scope *S, DeclTy *theEnumDecl, Diag(IdLoc, diag::err_redefinition) << Id; Diag(PrevDecl->getLocation(), diag::note_previous_definition); if (Val) Val->Destroy(Context); - return 0; + return DeclPtrTy(); } } @@ -3962,14 +3961,14 @@ Sema::DeclTy *Sema::ActOnEnumConstant(Scope *S, DeclTy *theEnumDecl, if (New) PushOnScopeChains(New, S); - return New; + return DeclPtrTy::make(New); } // FIXME: For consistency with ActOnFields(), we should have the parser // pass in the source location for the left/right braces. -void Sema::ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDeclX, - DeclTy **Elements, unsigned NumElements) { - EnumDecl *Enum = cast(static_cast(EnumDeclX)); +void Sema::ActOnEnumBody(SourceLocation EnumLoc, DeclPtrTy EnumDeclX, + DeclPtrTy *Elements, unsigned NumElements) { + EnumDecl *Enum = cast(EnumDeclX.getAs()); QualType EnumType = Context.getTypeDeclType(Enum); // TODO: If the result value doesn't fit in an int, it must be a long or long @@ -3987,7 +3986,7 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDeclX, for (unsigned i = 0; i != NumElements; ++i) { EnumConstantDecl *ECD = - cast_or_null(static_cast(Elements[i])); + cast_or_null(Elements[i].getAs()); if (!ECD) continue; // Already issued a diagnostic. // If the enum value doesn't fit in an int, emit an extension warning. @@ -4061,7 +4060,7 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDeclX, // the type of the enum if needed. for (unsigned i = 0; i != NumElements; ++i) { EnumConstantDecl *ECD = - cast_or_null(static_cast(Elements[i])); + cast_or_null(Elements[i].getAs()); if (!ECD) continue; // Already issued a diagnostic. // Standard C says the enumerators have int type, but we allow, as an @@ -4135,10 +4134,11 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDeclX, Enum->completeDefinition(Context, BestType); } -Sema::DeclTy *Sema::ActOnFileScopeAsmDecl(SourceLocation Loc, - ExprArg expr) { +Sema::DeclPtrTy Sema::ActOnFileScopeAsmDecl(SourceLocation Loc, + ExprArg expr) { StringLiteral *AsmString = cast((Expr*)expr.release()); - return FileScopeAsmDecl::Create(Context, CurContext, Loc, AsmString); + return DeclPtrTy::make(FileScopeAsmDecl::Create(Context, CurContext, + Loc, AsmString)); } diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 67c8777e34..27d42dd88a 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -105,9 +105,9 @@ namespace { /// provided for a function parameter is well-formed. If so, attach it /// to the parameter declaration. void -Sema::ActOnParamDefaultArgument(DeclTy *param, SourceLocation EqualLoc, +Sema::ActOnParamDefaultArgument(DeclPtrTy param, SourceLocation EqualLoc, ExprArg defarg) { - ParmVarDecl *Param = (ParmVarDecl *)param; + ParmVarDecl *Param = cast(param.getAs()); ExprOwningPtr DefaultArg(this, (Expr *)defarg.release()); QualType ParamType = Param->getType(); @@ -153,17 +153,17 @@ Sema::ActOnParamDefaultArgument(DeclTy *param, SourceLocation EqualLoc, /// argument for a function parameter, but we can't parse it yet /// because we're inside a class definition. Note that this default /// argument will be parsed later. -void Sema::ActOnParamUnparsedDefaultArgument(DeclTy *param, +void Sema::ActOnParamUnparsedDefaultArgument(DeclPtrTy param, SourceLocation EqualLoc) { - ParmVarDecl *Param = (ParmVarDecl*)param; + ParmVarDecl *Param = cast(param.getAs()); if (Param) Param->setUnparsedDefaultArg(); } /// ActOnParamDefaultArgumentError - Parsing or semantic analysis of /// the default argument for the parameter param failed. -void Sema::ActOnParamDefaultArgumentError(DeclTy *param) { - ((ParmVarDecl*)param)->setInvalidDecl(); +void Sema::ActOnParamDefaultArgumentError(DeclPtrTy param) { + cast(param.getAs())->setInvalidDecl(); } /// CheckExtraCXXDefaultArguments - Check for any extra default @@ -179,11 +179,12 @@ void Sema::CheckExtraCXXDefaultArguments(Declarator &D) { // parameter pack. If it is specified in a // parameter-declaration-clause, it shall not occur within a // declarator or abstract-declarator of a parameter-declaration. - for (unsigned i = 0; i < D.getNumTypeObjects(); ++i) { + for (unsigned i = 0, e = D.getNumTypeObjects(); i != e; ++i) { DeclaratorChunk &chunk = D.getTypeObject(i); if (chunk.Kind == DeclaratorChunk::Function) { - for (unsigned argIdx = 0; argIdx < chunk.Fun.NumArgs; ++argIdx) { - ParmVarDecl *Param = (ParmVarDecl *)chunk.Fun.ArgInfo[argIdx].Param; + for (unsigned argIdx = 0, e = chunk.Fun.NumArgs; argIdx != e; ++argIdx) { + ParmVarDecl *Param = + cast(chunk.Fun.ArgInfo[argIdx].Param.getAs()); if (Param->hasUnparsedDefaultArg()) { CachedTokens *Toks = chunk.Fun.ArgInfo[argIdx].DefaultArgTokens; Diag(Param->getLocation(), diag::err_param_default_argument_nonfunc) @@ -381,11 +382,11 @@ Sema::CheckBaseSpecifier(CXXRecordDecl *Class, /// class foo : public bar, virtual private baz { /// 'public bar' and 'virtual private baz' are each base-specifiers. Sema::BaseResult -Sema::ActOnBaseSpecifier(DeclTy *classdecl, SourceRange SpecifierRange, +Sema::ActOnBaseSpecifier(DeclPtrTy classdecl, SourceRange SpecifierRange, bool Virtual, AccessSpecifier Access, TypeTy *basetype, SourceLocation BaseLoc) { AdjustDeclIfTemplate(classdecl); - CXXRecordDecl *Class = cast((Decl*)classdecl); + CXXRecordDecl *Class = cast(classdecl.getAs()); QualType BaseType = QualType::getFromOpaquePtr(basetype); if (CXXBaseSpecifier *BaseSpec = CheckBaseSpecifier(Class, SpecifierRange, Virtual, Access, @@ -451,13 +452,13 @@ bool Sema::AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases, /// ActOnBaseSpecifiers - Attach the given base specifiers to the /// class, after checking whether there are any duplicate base /// classes. -void Sema::ActOnBaseSpecifiers(DeclTy *ClassDecl, BaseTy **Bases, +void Sema::ActOnBaseSpecifiers(DeclPtrTy ClassDecl, BaseTy **Bases, unsigned NumBases) { if (!ClassDecl || !Bases || !NumBases) return; AdjustDeclIfTemplate(ClassDecl); - AttachBaseSpecifiers(cast((Decl*)ClassDecl), + AttachBaseSpecifiers(cast(ClassDecl.getAs()), (CXXBaseSpecifier**)(Bases), NumBases); } @@ -470,10 +471,10 @@ void Sema::ActOnBaseSpecifiers(DeclTy *ClassDecl, BaseTy **Bases, /// bitfield width if there is one and 'InitExpr' specifies the initializer if /// any. 'LastInGroup' is non-null for cases where one declspec has multiple /// declarators on it. -Sema::DeclTy * +Sema::DeclPtrTy Sema::ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, Declarator &D, ExprTy *BW, ExprTy *InitExpr, - DeclTy *LastInGroup) { + DeclPtrTy LastInGroup) { const DeclSpec &DS = D.getDeclSpec(); DeclarationName Name = GetNameForDeclarator(D); Expr *BitWidth = static_cast(BW); @@ -552,7 +553,7 @@ Sema::ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, Declarator &D, AS); assert(Member && "HandleField never returns null"); } else { - Member = static_cast(ActOnDeclarator(S, D, LastInGroup)); + Member = ActOnDeclarator(S, D, LastInGroup).getAs(); if (!Member) { if (BitWidth) DeleteExpr(BitWidth); return LastInGroup; @@ -590,18 +591,18 @@ Sema::ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, Declarator &D, assert((Name || isInstField) && "No identifier for non-field ?"); if (Init) - AddInitializerToDecl(Member, ExprArg(*this, Init), false); + AddInitializerToDecl(DeclPtrTy::make(Member), ExprArg(*this, Init), false); if (isInstField) { FieldCollector->Add(cast(Member)); return LastInGroup; } - return Member; + return DeclPtrTy::make(Member); } /// ActOnMemInitializer - Handle a C++ member initializer. Sema::MemInitResult -Sema::ActOnMemInitializer(DeclTy *ConstructorD, +Sema::ActOnMemInitializer(DeclPtrTy ConstructorD, Scope *S, IdentifierInfo *MemberOrBase, SourceLocation IdLoc, @@ -610,7 +611,7 @@ Sema::ActOnMemInitializer(DeclTy *ConstructorD, SourceLocation *CommaLocs, SourceLocation RParenLoc) { CXXConstructorDecl *Constructor - = dyn_cast((Decl*)ConstructorD); + = dyn_cast(ConstructorD.getAs()); if (!Constructor) { // The user wrote a constructor initializer on a function that is // not a C++ constructor. Ignore the error for now, because we may @@ -706,11 +707,11 @@ Sema::ActOnMemInitializer(DeclTy *ConstructorD, return new CXXBaseOrMemberInitializer(BaseType, (Expr **)Args, NumArgs); } -void Sema::ActOnMemInitializers(DeclTy *ConstructorDecl, +void Sema::ActOnMemInitializers(DeclPtrTy ConstructorDecl, SourceLocation ColonLoc, MemInitTy **MemInits, unsigned NumMemInits) { CXXConstructorDecl *Constructor = - dyn_cast((Decl *)ConstructorDecl); + dyn_cast(ConstructorDecl.getAs()); if (!Constructor) { Diag(ColonLoc, diag::err_only_constructors_take_base_inits); @@ -917,15 +918,15 @@ namespace { } void Sema::ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc, - DeclTy *TagDecl, + DeclPtrTy TagDecl, SourceLocation LBrac, SourceLocation RBrac) { TemplateDecl *Template = AdjustDeclIfTemplate(TagDecl); ActOnFields(S, RLoc, TagDecl, - (DeclTy**)FieldCollector->getCurFields(), + (DeclPtrTy*)FieldCollector->getCurFields(), FieldCollector->getCurNumFields(), LBrac, RBrac, 0); - CXXRecordDecl *RD = cast((Decl*)TagDecl); + CXXRecordDecl *RD = cast(TagDecl.getAs()); if (!RD->isAbstract()) { // Collect all the pure virtual methods and see if this is an abstract // class after all. @@ -1159,9 +1160,9 @@ void Sema::AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl) { /// Method declaration as if we had just parsed the qualified method /// name. However, it should not bring the parameters into scope; /// that will be performed by ActOnDelayedCXXMethodParameter. -void Sema::ActOnStartDelayedCXXMethodDeclaration(Scope *S, DeclTy *MethodD) { +void Sema::ActOnStartDelayedCXXMethodDeclaration(Scope *S, DeclPtrTy MethodD) { CXXScopeSpec SS; - FunctionDecl *Method = (FunctionDecl*)MethodD; + FunctionDecl *Method = cast(MethodD.getAs()); QualType ClassTy = Context.getTypeDeclType(cast(Method->getDeclContext())); SS.setScopeRep( @@ -1174,15 +1175,15 @@ void Sema::ActOnStartDelayedCXXMethodDeclaration(Scope *S, DeclTy *MethodD) { /// function parameter into scope for use in parsing later parts of /// the method declaration. For example, we could see an /// ActOnParamDefaultArgument event for this parameter. -void Sema::ActOnDelayedCXXMethodParameter(Scope *S, DeclTy *ParamD) { - ParmVarDecl *Param = (ParmVarDecl*)ParamD; +void Sema::ActOnDelayedCXXMethodParameter(Scope *S, DeclPtrTy ParamD) { + ParmVarDecl *Param = cast(ParamD.getAs()); // If this parameter has an unparsed default argument, clear it out // to make way for the parsed default argument. if (Param->hasUnparsedDefaultArg()) Param->setDefaultArg(0); - S->AddDecl(Param); + S->AddDecl(DeclPtrTy::make(Param)); if (Param->getDeclName()) IdResolver.AddDecl(Param); } @@ -1193,8 +1194,8 @@ void Sema::ActOnDelayedCXXMethodParameter(Scope *S, DeclTy *ParamD) { /// ActOnStartOfFunctionDef action later (not necessarily /// immediately!) for this method, if it was also defined inside the /// class body. -void Sema::ActOnFinishDelayedCXXMethodDeclaration(Scope *S, DeclTy *MethodD) { - FunctionDecl *Method = (FunctionDecl*)MethodD; +void Sema::ActOnFinishDelayedCXXMethodDeclaration(Scope *S, DeclPtrTy MethodD) { + FunctionDecl *Method = cast(MethodD.getAs()); CXXScopeSpec SS; QualType ClassTy = Context.getTypeDeclType(cast(Method->getDeclContext())); @@ -1483,7 +1484,7 @@ bool Sema::CheckConversionDeclarator(Declarator &D, QualType &R, /// the declaration of the given C++ conversion function. This routine /// is responsible for recording the conversion function in the C++ /// class, if possible. -Sema::DeclTy *Sema::ActOnConversionDeclarator(CXXConversionDecl *Conversion) { +Sema::DeclPtrTy Sema::ActOnConversionDeclarator(CXXConversionDecl *Conversion) { assert(Conversion && "Expected to receive a conversion function declaration"); // Set the lexical context of this conversion function @@ -1528,14 +1529,14 @@ Sema::DeclTy *Sema::ActOnConversionDeclarator(CXXConversionDecl *Conversion) { Conv != ConvEnd; ++Conv) { if (*Conv == Conversion->getPreviousDeclaration()) { *Conv = Conversion; - return (DeclTy *)Conversion; + return DeclPtrTy::make(Conversion); } } assert(Conversion->isInvalidDecl() && "Conversion should not get here."); } else ClassDecl->addConversionFunction(Context, Conversion); - return (DeclTy *)Conversion; + return DeclPtrTy::make(Conversion); } //===----------------------------------------------------------------------===// @@ -1544,10 +1545,10 @@ Sema::DeclTy *Sema::ActOnConversionDeclarator(CXXConversionDecl *Conversion) { /// ActOnStartNamespaceDef - This is called at the start of a namespace /// definition. -Sema::DeclTy *Sema::ActOnStartNamespaceDef(Scope *NamespcScope, - SourceLocation IdentLoc, - IdentifierInfo *II, - SourceLocation LBrace) { +Sema::DeclPtrTy Sema::ActOnStartNamespaceDef(Scope *NamespcScope, + SourceLocation IdentLoc, + IdentifierInfo *II, + SourceLocation LBrace) { NamespaceDecl *Namespc = NamespaceDecl::Create(Context, CurContext, IdentLoc, II); Namespc->setLBracLoc(LBrace); @@ -1573,9 +1574,9 @@ Sema::DeclTy *Sema::ActOnStartNamespaceDef(Scope *NamespcScope, Namespc->setOriginalNamespace(OrigNS->getOriginalNamespace()); // Remove the previous declaration from the scope. - if (DeclRegionScope->isDeclScope(OrigNS)) { + if (DeclRegionScope->isDeclScope(DeclPtrTy::make(OrigNS))) { IdResolver.RemoveDecl(OrigNS); - DeclRegionScope->RemoveDecl(OrigNS); + DeclRegionScope->RemoveDecl(DeclPtrTy::make(OrigNS)); } } else if (PrevDecl) { // This is an invalid name redefinition. @@ -1597,26 +1598,26 @@ Sema::DeclTy *Sema::ActOnStartNamespaceDef(Scope *NamespcScope, // each DeclContext for the namespace has the declarations // that showed up in that particular namespace definition. PushDeclContext(NamespcScope, Namespc); - return Namespc; + return DeclPtrTy::make(Namespc); } /// ActOnFinishNamespaceDef - This callback is called after a namespace is /// exited. Decl is the DeclTy returned by ActOnStartNamespaceDef. -void Sema::ActOnFinishNamespaceDef(DeclTy *D, SourceLocation RBrace) { - Decl *Dcl = static_cast(D); +void Sema::ActOnFinishNamespaceDef(DeclPtrTy D, SourceLocation RBrace) { + Decl *Dcl = D.getAs(); NamespaceDecl *Namespc = dyn_cast_or_null(Dcl); assert(Namespc && "Invalid parameter, expected NamespaceDecl"); Namespc->setRBracLoc(RBrace); PopDeclContext(); } -Sema::DeclTy *Sema::ActOnUsingDirective(Scope *S, - SourceLocation UsingLoc, - SourceLocation NamespcLoc, - const CXXScopeSpec &SS, - SourceLocation IdentLoc, - IdentifierInfo *NamespcName, - AttributeList *AttrList) { +Sema::DeclPtrTy Sema::ActOnUsingDirective(Scope *S, + SourceLocation UsingLoc, + SourceLocation NamespcLoc, + const CXXScopeSpec &SS, + SourceLocation IdentLoc, + IdentifierInfo *NamespcName, + AttributeList *AttrList) { assert(!SS.isInvalid() && "Invalid CXXScopeSpec."); assert(NamespcName && "Invalid NamespcName."); assert(IdentLoc.isValid() && "Invalid NamespceName location."); @@ -1629,7 +1630,7 @@ Sema::DeclTy *Sema::ActOnUsingDirective(Scope *S, LookupNamespaceName, false); if (R.isAmbiguous()) { DiagnoseAmbiguousLookup(R, NamespcName, IdentLoc); - return 0; + return DeclPtrTy(); } if (NamedDecl *NS = R) { assert(isa(NS) && "expected namespace decl"); @@ -1660,7 +1661,7 @@ Sema::DeclTy *Sema::ActOnUsingDirective(Scope *S, // FIXME: We ignore attributes for now. delete AttrList; - return UDir; + return DeclPtrTy::make(UDir); } void Sema::PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir) { @@ -1672,15 +1673,15 @@ void Sema::PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir) { else // Otherwise it is block-sope. using-directives will affect lookup // only to the end of scope. - S->PushUsingDirective(UDir); + S->PushUsingDirective(DeclPtrTy::make(UDir)); } -Sema::DeclTy *Sema::ActOnNamespaceAliasDef(Scope *S, - SourceLocation AliasLoc, - IdentifierInfo *Alias, - const CXXScopeSpec &SS, - SourceLocation NamespaceLoc, - IdentifierInfo *NamespaceName) { +Sema::DeclPtrTy Sema::ActOnNamespaceAliasDef(Scope *S, + SourceLocation AliasLoc, + IdentifierInfo *Alias, + const CXXScopeSpec &SS, + SourceLocation NamespaceLoc, + IdentifierInfo *NamespaceName) { // Check if we have a previous declaration with the same name. if (NamedDecl *PrevDecl = LookupName(S, Alias, LookupOrdinaryName)) { @@ -1690,7 +1691,7 @@ Sema::DeclTy *Sema::ActOnNamespaceAliasDef(Scope *S, diag::err_redefinition_different_kind; Diag(AliasLoc, DiagID) << Alias; Diag(PrevDecl->getLocation(), diag::note_previous_definition); - return 0; + return DeclPtrTy(); } // Lookup the namespace name. @@ -1698,33 +1699,33 @@ Sema::DeclTy *Sema::ActOnNamespaceAliasDef(Scope *S, LookupNamespaceName, false); if (R.isAmbiguous()) { DiagnoseAmbiguousLookup(R, NamespaceName, NamespaceLoc); - return 0; + return DeclPtrTy(); } if (!R) { Diag(NamespaceLoc, diag::err_expected_namespace_name) << SS.getRange(); - return 0; + return DeclPtrTy(); } - return 0; + return DeclPtrTy(); } /// AddCXXDirectInitializerToDecl - This action is called immediately after /// ActOnDeclarator, when a C++ direct initializer is present. /// e.g: "int x(1);" -void Sema::AddCXXDirectInitializerToDecl(DeclTy *Dcl, SourceLocation LParenLoc, +void Sema::AddCXXDirectInitializerToDecl(DeclPtrTy Dcl, + SourceLocation LParenLoc, MultiExprArg Exprs, SourceLocation *CommaLocs, SourceLocation RParenLoc) { unsigned NumExprs = Exprs.size(); assert(NumExprs != 0 && Exprs.get() && "missing expressions"); - Decl *RealDecl = static_cast(Dcl); + Decl *RealDecl = Dcl.getAs(); // If there is no declaration, there was an error parsing it. Just ignore // the initializer. - if (RealDecl == 0) { + if (RealDecl == 0) return; - } VarDecl *VDecl = dyn_cast(RealDecl); if (!VDecl) { @@ -2411,12 +2412,12 @@ bool Sema::CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl) { /// by Lang/StrSize. LBraceLoc, if valid, provides the location of /// the '{' brace. Otherwise, this linkage specification does not /// have any braces. -Sema::DeclTy *Sema::ActOnStartLinkageSpecification(Scope *S, - SourceLocation ExternLoc, - SourceLocation LangLoc, - const char *Lang, - unsigned StrSize, - SourceLocation LBraceLoc) { +Sema::DeclPtrTy Sema::ActOnStartLinkageSpecification(Scope *S, + SourceLocation ExternLoc, + SourceLocation LangLoc, + const char *Lang, + unsigned StrSize, + SourceLocation LBraceLoc) { LinkageSpecDecl::LanguageIDs Language; if (strncmp(Lang, "\"C\"", StrSize) == 0) Language = LinkageSpecDecl::lang_c; @@ -2424,7 +2425,7 @@ Sema::DeclTy *Sema::ActOnStartLinkageSpecification(Scope *S, Language = LinkageSpecDecl::lang_cxx; else { Diag(LangLoc, diag::err_bad_language); - return 0; + return DeclPtrTy(); } // FIXME: Add all the various semantics of linkage specifications @@ -2434,16 +2435,16 @@ Sema::DeclTy *Sema::ActOnStartLinkageSpecification(Scope *S, LBraceLoc.isValid()); CurContext->addDecl(D); PushDeclContext(S, D); - return D; + return DeclPtrTy::make(D); } /// ActOnFinishLinkageSpecification - Completely the definition of /// the C++ linkage specification LinkageSpec. If RBraceLoc is /// valid, it's the position of the closing '}' brace in a linkage /// specification that uses braces. -Sema::DeclTy *Sema::ActOnFinishLinkageSpecification(Scope *S, - DeclTy *LinkageSpec, - SourceLocation RBraceLoc) { +Sema::DeclPtrTy Sema::ActOnFinishLinkageSpecification(Scope *S, + DeclPtrTy LinkageSpec, + SourceLocation RBraceLoc) { if (LinkageSpec) PopDeclContext(); return LinkageSpec; @@ -2451,8 +2452,7 @@ Sema::DeclTy *Sema::ActOnFinishLinkageSpecification(Scope *S, /// ActOnExceptionDeclarator - Parsed the exception-declarator in a C++ catch /// handler. -Sema::DeclTy *Sema::ActOnExceptionDeclarator(Scope *S, Declarator &D) -{ +Sema::DeclPtrTy Sema::ActOnExceptionDeclarator(Scope *S, Declarator &D) { QualType ExDeclType = GetTypeForDeclarator(D, S); SourceLocation Begin = D.getDeclSpec().getSourceRange().getBegin(); @@ -2497,11 +2497,10 @@ Sema::DeclTy *Sema::ActOnExceptionDeclarator(Scope *S, Declarator &D) if (NamedDecl *PrevDecl = LookupName(S, II, LookupOrdinaryName)) { // The scope should be freshly made just for us. There is just no way // it contains any previous declaration. - assert(!S->isDeclScope(PrevDecl)); + assert(!S->isDeclScope(DeclPtrTy::make(PrevDecl))); if (PrevDecl->isTemplateParameter()) { // Maybe we will complain about the shadowed template parameter. DiagnoseTemplateParameterShadow(D.getIdentifierLoc(), PrevDecl); - } } @@ -2517,17 +2516,17 @@ Sema::DeclTy *Sema::ActOnExceptionDeclarator(Scope *S, Declarator &D) } // Add the exception declaration into this scope. - S->AddDecl(ExDecl); + S->AddDecl(DeclPtrTy::make(ExDecl)); if (II) IdResolver.AddDecl(ExDecl); ProcessDeclAttributes(ExDecl, D); - return ExDecl; + return DeclPtrTy::make(ExDecl); } -Sema::DeclTy *Sema::ActOnStaticAssertDeclaration(SourceLocation AssertLoc, - ExprArg assertexpr, - ExprArg assertmessageexpr) { +Sema::DeclPtrTy Sema::ActOnStaticAssertDeclaration(SourceLocation AssertLoc, + ExprArg assertexpr, + ExprArg assertmessageexpr) { Expr *AssertExpr = (Expr *)assertexpr.get(); StringLiteral *AssertMessage = cast((Expr *)assertmessageexpr.get()); @@ -2537,7 +2536,7 @@ Sema::DeclTy *Sema::ActOnStaticAssertDeclaration(SourceLocation AssertLoc, if (!AssertExpr->isIntegerConstantExpr(Value, Context)) { Diag(AssertLoc, diag::err_static_assert_expression_is_not_constant) << AssertExpr->getSourceRange(); - return 0; + return DeclPtrTy(); } if (Value == 0) { @@ -2554,11 +2553,11 @@ Sema::DeclTy *Sema::ActOnStaticAssertDeclaration(SourceLocation AssertLoc, AssertExpr, AssertMessage); CurContext->addDecl(Decl); - return Decl; + return DeclPtrTy::make(Decl); } -void Sema::SetDeclDeleted(DeclTy *dcl, SourceLocation DelLoc) { - Decl *Dcl = static_cast(dcl); +void Sema::SetDeclDeleted(DeclPtrTy dcl, SourceLocation DelLoc) { + Decl *Dcl = dcl.getAs(); FunctionDecl *Fn = dyn_cast(Dcl); if (!Fn) { Diag(DelLoc, diag::err_deleted_non_function); diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index ba35333fe5..8809eb9442 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -20,9 +20,9 @@ using namespace clang; /// ActOnStartOfObjCMethodDef - This routine sets up parameters; invisible /// and user declared, in the method definition's AST. -void Sema::ActOnStartOfObjCMethodDef(Scope *FnBodyScope, DeclTy *D) { +void Sema::ActOnStartOfObjCMethodDef(Scope *FnBodyScope, DeclPtrTy D) { assert(getCurMethodDecl() == 0 && "Method parsing confused"); - ObjCMethodDecl *MDecl = dyn_cast_or_null((Decl *)D); + ObjCMethodDecl *MDecl = dyn_cast_or_null(D.getAs()); // If we don't have a valid method decl, simply return. if (!MDecl) @@ -53,11 +53,11 @@ void Sema::ActOnStartOfObjCMethodDef(Scope *FnBodyScope, DeclTy *D) { PushOnScopeChains(*PI, FnBodyScope); } -Sema::DeclTy *Sema:: +Sema::DeclPtrTy Sema:: ActOnStartClassInterface(SourceLocation AtInterfaceLoc, IdentifierInfo *ClassName, SourceLocation ClassLoc, IdentifierInfo *SuperName, SourceLocation SuperLoc, - DeclTy * const *ProtoRefs, unsigned NumProtoRefs, + const DeclPtrTy *ProtoRefs, unsigned NumProtoRefs, SourceLocation EndProtoLoc, AttributeList *AttrList) { assert(ClassName && "Missing class identifier"); @@ -85,7 +85,7 @@ ActOnStartClassInterface(SourceLocation AtInterfaceLoc, // Return the previous class interface. // FIXME: don't leak the objects passed in! - return IDecl; + return DeclPtrTy::make(IDecl); } else { IDecl->setLocation(AtInterfaceLoc); IDecl->setForwardDecl(false); @@ -100,7 +100,7 @@ ActOnStartClassInterface(SourceLocation AtInterfaceLoc, // FIXME: PushOnScopeChains CurContext->addDecl(IDecl); // Remember that this needs to be removed when the scope is popped. - TUScope->AddDecl(IDecl); + TUScope->AddDecl(DeclPtrTy::make(IDecl)); } if (SuperName) { @@ -160,16 +160,16 @@ ActOnStartClassInterface(SourceLocation AtInterfaceLoc, } CheckObjCDeclScope(IDecl); - return IDecl; + return DeclPtrTy::make(IDecl); } /// ActOnCompatiblityAlias - this action is called after complete parsing of /// @compatibility_alias declaration. It sets up the alias relationships. -Sema::DeclTy *Sema::ActOnCompatiblityAlias(SourceLocation AtLoc, - IdentifierInfo *AliasName, - SourceLocation AliasLocation, - IdentifierInfo *ClassName, - SourceLocation ClassLocation) { +Sema::DeclPtrTy Sema::ActOnCompatiblityAlias(SourceLocation AtLoc, + IdentifierInfo *AliasName, + SourceLocation AliasLocation, + IdentifierInfo *ClassName, + SourceLocation ClassLocation) { // Look for previous declaration of alias name NamedDecl *ADecl = LookupName(TUScope, AliasName, LookupOrdinaryName); if (ADecl) { @@ -178,7 +178,7 @@ Sema::DeclTy *Sema::ActOnCompatiblityAlias(SourceLocation AtLoc, else Diag(AliasLocation, diag::err_conflicting_aliasing_type) << AliasName; Diag(ADecl->getLocation(), diag::note_previous_declaration); - return 0; + return DeclPtrTy(); } // Check for class declaration NamedDecl *CDeclU = LookupName(TUScope, ClassName, LookupOrdinaryName); @@ -196,7 +196,7 @@ Sema::DeclTy *Sema::ActOnCompatiblityAlias(SourceLocation AtLoc, Diag(ClassLocation, diag::warn_undef_interface) << ClassName; if (CDeclU) Diag(CDeclU->getLocation(), diag::note_previous_declaration); - return 0; + return DeclPtrTy(); } // Everything checked out, instantiate a new alias declaration AST. @@ -208,9 +208,9 @@ Sema::DeclTy *Sema::ActOnCompatiblityAlias(SourceLocation AtLoc, // FIXME: PushOnScopeChains? CurContext->addDecl(AliasDecl); if (!CheckObjCDeclScope(AliasDecl)) - TUScope->AddDecl(AliasDecl); + TUScope->AddDecl(DeclPtrTy::make(AliasDecl)); - return AliasDecl; + return DeclPtrTy::make(AliasDecl); } void Sema::CheckForwardProtocolDeclarationForCircularDependency( @@ -232,11 +232,11 @@ void Sema::CheckForwardProtocolDeclarationForCircularDependency( } } -Sema::DeclTy * +Sema::DeclPtrTy Sema::ActOnStartProtocolInterface(SourceLocation AtProtoInterfaceLoc, IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc, - DeclTy * const *ProtoRefs, + const DeclPtrTy *ProtoRefs, unsigned NumProtoRefs, SourceLocation EndProtoLoc, AttributeList *AttrList) { @@ -251,7 +251,7 @@ Sema::ActOnStartProtocolInterface(SourceLocation AtProtoInterfaceLoc, Diag(PDecl->getLocation(), diag::note_previous_definition); // Just return the protocol we already had. // FIXME: don't leak the objects passed in! - return PDecl; + return DeclPtrTy::make(PDecl); } ObjCList PList; PList.set((ObjCProtocolDecl *const*)ProtoRefs, NumProtoRefs, Context); @@ -279,7 +279,7 @@ Sema::ActOnStartProtocolInterface(SourceLocation AtProtoInterfaceLoc, } CheckObjCDeclScope(PDecl); - return PDecl; + return DeclPtrTy::make(PDecl); } /// FindProtocolDeclaration - This routine looks up protocols and @@ -289,7 +289,7 @@ void Sema::FindProtocolDeclaration(bool WarnOnDeclarations, const IdentifierLocPair *ProtocolId, unsigned NumProtocols, - llvm::SmallVectorImpl &Protocols) { + llvm::SmallVectorImpl &Protocols) { for (unsigned i = 0; i != NumProtocols; ++i) { ObjCProtocolDecl *PDecl = ObjCProtocols[ProtocolId[i].first]; if (!PDecl) { @@ -305,7 +305,7 @@ Sema::FindProtocolDeclaration(bool WarnOnDeclarations, if (WarnOnDeclarations && PDecl->isForwardDecl()) Diag(ProtocolId[i].second, diag::warn_undef_protocolref) << ProtocolId[i].first; - Protocols.push_back(PDecl); + Protocols.push_back(DeclPtrTy::make(PDecl)); } } @@ -428,8 +428,8 @@ Sema::MergeOneProtocolPropertiesIntoClass(Decl *CDecl, /// inherited protocol into the list of properties for class/category 'CDecl' /// void Sema::MergeProtocolPropertiesIntoClass(Decl *CDecl, - DeclTy *MergeItsProtocols) { - Decl *ClassDecl = static_cast(MergeItsProtocols); + DeclPtrTy MergeItsProtocols) { + Decl *ClassDecl = MergeItsProtocols.getAs(); ObjCInterfaceDecl *IDecl = dyn_cast_or_null(CDecl); if (!IDecl) { @@ -446,12 +446,12 @@ void Sema::MergeProtocolPropertiesIntoClass(Decl *CDecl, // their properties into this class as well. for (ObjCCategoryDecl::protocol_iterator P = CatDecl->protocol_begin(), E = CatDecl->protocol_end(); P != E; ++P) - MergeProtocolPropertiesIntoClass(CatDecl, *P); + MergeProtocolPropertiesIntoClass(CatDecl, DeclPtrTy::make(*P)); } else { ObjCProtocolDecl *MD = cast(ClassDecl); for (ObjCProtocolDecl::protocol_iterator P = MD->protocol_begin(), E = MD->protocol_end(); P != E; ++P) - MergeOneProtocolPropertiesIntoClass(CatDecl, (*P)); + MergeOneProtocolPropertiesIntoClass(CatDecl, *P); } return; } @@ -466,12 +466,12 @@ void Sema::MergeProtocolPropertiesIntoClass(Decl *CDecl, // their properties into this class as well. for (ObjCInterfaceDecl::protocol_iterator P = IDecl->protocol_begin(), E = IDecl->protocol_end(); P != E; ++P) - MergeProtocolPropertiesIntoClass(IDecl, *P); + MergeProtocolPropertiesIntoClass(IDecl, DeclPtrTy::make(*P)); } else { ObjCProtocolDecl *MD = cast(ClassDecl); for (ObjCProtocolDecl::protocol_iterator P = MD->protocol_begin(), E = MD->protocol_end(); P != E; ++P) - MergeOneProtocolPropertiesIntoClass(IDecl, (*P)); + MergeOneProtocolPropertiesIntoClass(IDecl, *P); } } @@ -505,7 +505,7 @@ void Sema::DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT, } /// ActOnForwardProtocolDeclaration - -Action::DeclTy * +Action::DeclPtrTy Sema::ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc, const IdentifierLocPair *IdentList, unsigned NumElts, @@ -531,15 +531,15 @@ Sema::ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc, &Protocols[0], Protocols.size()); CurContext->addDecl(PDecl); CheckObjCDeclScope(PDecl); - return PDecl; + return DeclPtrTy::make(PDecl); } -Sema::DeclTy *Sema:: +Sema::DeclPtrTy Sema:: ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc, IdentifierInfo *ClassName, SourceLocation ClassLoc, IdentifierInfo *CategoryName, SourceLocation CategoryLoc, - DeclTy * const *ProtoRefs, + const DeclPtrTy *ProtoRefs, unsigned NumProtoRefs, SourceLocation EndProtoLoc) { ObjCCategoryDecl *CDecl = @@ -552,7 +552,7 @@ ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc, if (!IDecl || IDecl->isForwardDecl()) { CDecl->setInvalidDecl(); Diag(ClassLoc, diag::err_undef_interface) << ClassName; - return CDecl; + return DeclPtrTy::make(CDecl); } CDecl->setClassInterface(IDecl); @@ -580,13 +580,13 @@ ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc, } CheckObjCDeclScope(CDecl); - return CDecl; + return DeclPtrTy::make(CDecl); } /// ActOnStartCategoryImplementation - Perform semantic checks on the /// category implementation declaration and build an ObjCCategoryImplDecl /// object. -Sema::DeclTy *Sema::ActOnStartCategoryImplementation( +Sema::DeclPtrTy Sema::ActOnStartCategoryImplementation( SourceLocation AtCatImplLoc, IdentifierInfo *ClassName, SourceLocation ClassLoc, IdentifierInfo *CatName, SourceLocation CatLoc) { @@ -606,10 +606,10 @@ Sema::DeclTy *Sema::ActOnStartCategoryImplementation( ObjCCategoryImpls.push_back(CDecl); CheckObjCDeclScope(CDecl); - return CDecl; + return DeclPtrTy::make(CDecl); } -Sema::DeclTy *Sema::ActOnStartClassImplementation( +Sema::DeclPtrTy Sema::ActOnStartClassImplementation( SourceLocation AtClassImplLoc, IdentifierInfo *ClassName, SourceLocation ClassLoc, IdentifierInfo *SuperClassname, @@ -666,7 +666,7 @@ Sema::DeclTy *Sema::ActOnStartClassImplementation( // FIXME: PushOnScopeChains? CurContext->addDecl(IDecl); // Remember that this needs to be removed when the scope is popped. - TUScope->AddDecl(IDecl); + TUScope->AddDecl(DeclPtrTy::make(IDecl)); } ObjCImplementationDecl* IMPDecl = @@ -677,7 +677,7 @@ Sema::DeclTy *Sema::ActOnStartClassImplementation( CurContext->addDecl(IMPDecl); if (CheckObjCDeclScope(IMPDecl)) - return IMPDecl; + return DeclPtrTy::make(IMPDecl); // Check that there is no duplicate implementation of this class. if (ObjCImplementations[ClassName]) @@ -685,7 +685,7 @@ Sema::DeclTy *Sema::ActOnStartClassImplementation( Diag(ClassLoc, diag::err_dup_implementation_class) << ClassName; else // add it to the list. ObjCImplementations[ClassName] = IMPDecl; - return IMPDecl; + return DeclPtrTy::make(IMPDecl); } void Sema::CheckImplementationIvars(ObjCImplementationDecl *ImpDecl, @@ -957,7 +957,7 @@ void Sema::ImplMethodsVsClassMethods(ObjCImplDecl* IMPDecl, } /// ActOnForwardClassDeclaration - -Action::DeclTy * +Action::DeclPtrTy Sema::ActOnForwardClassDeclaration(SourceLocation AtClassLoc, IdentifierInfo **IdentList, unsigned NumElts) { @@ -995,7 +995,7 @@ Sema::ActOnForwardClassDeclaration(SourceLocation AtClassLoc, // FIXME: PushOnScopeChains? CurContext->addDecl(IDecl); // Remember that this needs to be removed when the scope is popped. - TUScope->AddDecl(IDecl); + TUScope->AddDecl(DeclPtrTy::make(IDecl)); } Interfaces.push_back(IDecl); @@ -1006,7 +1006,7 @@ Sema::ActOnForwardClassDeclaration(SourceLocation AtClassLoc, Interfaces.size()); CurContext->addDecl(CDecl); CheckObjCDeclScope(CDecl); - return CDecl; + return DeclPtrTy::make(CDecl); } @@ -1231,12 +1231,12 @@ void Sema::ProcessPropertyDecl(ObjCPropertyDecl *property, // Note: For class/category implemenations, allMethods/allProperties is // always null. -void Sema::ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl, - DeclTy **allMethods, unsigned allNum, - DeclTy **allProperties, unsigned pNum, - DeclTy **allTUVars, +void Sema::ActOnAtEnd(SourceLocation AtEndLoc, DeclPtrTy classDecl, + DeclPtrTy *allMethods, unsigned allNum, + DeclPtrTy *allProperties, unsigned pNum, + DeclPtrTy *allTUVars, unsigned tuvNum) { - Decl *ClassDecl = static_cast(classDecl); + Decl *ClassDecl = classDecl.getAs(); // FIXME: If we don't have a ClassDecl, we have an error. We should consider // always passing in a decl. If the decl has an error, isInvalidDecl() @@ -1257,7 +1257,7 @@ void Sema::ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl, for (unsigned i = 0; i < allNum; i++ ) { ObjCMethodDecl *Method = - cast_or_null(static_cast(allMethods[i])); + cast_or_null(allMethods[i].getAs()); if (!Method) continue; // Already issued a diagnostic. if (Method->isInstanceMethod()) { @@ -1299,14 +1299,14 @@ void Sema::ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl, // Compares properties declared in this class to those of its // super class. ComparePropertiesInBaseAndSuper(I); - MergeProtocolPropertiesIntoClass(I, I); + MergeProtocolPropertiesIntoClass(I, DeclPtrTy::make(I)); } else if (ObjCCategoryDecl *C = dyn_cast(ClassDecl)) { // Categories are used to extend the class by declaring new methods. // By the same token, they are also used to add new properties. No // need to compare the added property to those in the class. // Merge protocol properties into category - MergeProtocolPropertiesIntoClass(C, C); + MergeProtocolPropertiesIntoClass(C, DeclPtrTy::make(C)); if (C->getIdentifier() == 0) DiagnoseClassExtensionDupMethods(C, C->getClassInterface()); } @@ -1341,7 +1341,7 @@ void Sema::ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl, } if (isInterfaceDeclKind) for (unsigned i = 0; i < tuvNum; i++) { - if (VarDecl *VDecl = dyn_cast((Decl*)allTUVars[i])) { + if (VarDecl *VDecl = dyn_cast(allTUVars[i].getAs())) { if (VDecl->getStorageClass() != VarDecl::Extern && VDecl->getStorageClass() != VarDecl::PrivateExtern) { NamedDecl *ClassNameDecl = dyn_cast(ClassDecl); @@ -1374,9 +1374,9 @@ CvtQTToAstBitMask(ObjCDeclSpec::ObjCDeclQualifier PQTVal) { return ret; } -Sema::DeclTy *Sema::ActOnMethodDeclaration( +Sema::DeclPtrTy Sema::ActOnMethodDeclaration( SourceLocation MethodLoc, SourceLocation EndLoc, - tok::TokenKind MethodType, DeclTy *classDecl, + tok::TokenKind MethodType, DeclPtrTy classDecl, ObjCDeclSpec &ReturnQT, TypeTy *ReturnType, Selector Sel, // optional arguments. The number of types/arguments is obtained @@ -1385,12 +1385,12 @@ Sema::DeclTy *Sema::ActOnMethodDeclaration( llvm::SmallVectorImpl &Cdecls, AttributeList *AttrList, tok::ObjCKeywordKind MethodDeclKind, bool isVariadic) { - Decl *ClassDecl = static_cast(classDecl); + Decl *ClassDecl = classDecl.getAs(); // Make sure we can establish a context for the method. if (!ClassDecl) { Diag(MethodLoc, diag::error_missing_method_context); - return 0; + return DeclPtrTy(); } QualType resultDeclType; @@ -1402,7 +1402,7 @@ Sema::DeclTy *Sema::ActOnMethodDeclaration( if (resultDeclType->isObjCInterfaceType()) { Diag(MethodLoc, diag::err_object_cannot_be_by_value) << "returned"; - return 0; + return DeclPtrTy(); } } else // get the type for "id". resultDeclType = Context.getObjCIdType(); @@ -1436,7 +1436,7 @@ Sema::DeclTy *Sema::ActOnMethodDeclaration( Diag(MethodLoc, diag::err_object_cannot_be_by_value) << "passed"; ObjCMethod->setInvalidDecl(); - return 0; + return DeclPtrTy(); } } else argType = Context.getObjCIdType(); @@ -1495,7 +1495,7 @@ Sema::DeclTy *Sema::ActOnMethodDeclaration( << ObjCMethod->getDeclName(); Diag(PrevMethod->getLocation(), diag::note_previous_declaration); } - return ObjCMethod; + return DeclPtrTy::make(ObjCMethod); } void Sema::CheckObjCPropertyAttributes(QualType PropertyTy, @@ -1571,14 +1571,14 @@ void Sema::CheckObjCPropertyAttributes(QualType PropertyTy, } } -Sema::DeclTy *Sema::ActOnProperty(Scope *S, SourceLocation AtLoc, - FieldDeclarator &FD, - ObjCDeclSpec &ODS, - Selector GetterSel, - Selector SetterSel, - DeclTy *ClassCategory, - bool *isOverridingProperty, - tok::ObjCKeywordKind MethodImplKind) { +Sema::DeclPtrTy Sema::ActOnProperty(Scope *S, SourceLocation AtLoc, + FieldDeclarator &FD, + ObjCDeclSpec &ODS, + Selector GetterSel, + Selector SetterSel, + DeclPtrTy ClassCategory, + bool *isOverridingProperty, + tok::ObjCKeywordKind MethodImplKind) { unsigned Attributes = ODS.getPropertyAttributes(); bool isReadWrite = ((Attributes & ObjCDeclSpec::DQ_PR_readwrite) || // default is readwrite! @@ -1590,7 +1590,7 @@ Sema::DeclTy *Sema::ActOnProperty(Scope *S, SourceLocation AtLoc, !(Attributes & ObjCDeclSpec::DQ_PR_retain) && !(Attributes & ObjCDeclSpec::DQ_PR_copy))); QualType T = GetTypeForDeclarator(FD.D, S); - Decl *ClassDecl = static_cast(ClassCategory); + Decl *ClassDecl = ClassCategory.getAs(); // May modify Attributes. CheckObjCPropertyAttributes(T, AtLoc, Attributes); @@ -1632,7 +1632,7 @@ Sema::DeclTy *Sema::ActOnProperty(Scope *S, SourceLocation AtLoc, else Diag(AtLoc, diag::err_use_continuation_class) << ICDecl->getDeclName(); *isOverridingProperty = true; - return 0; + return DeclPtrTy(); } // No matching property found in the main class. Just fall thru // and add property to the anonymous category. It looks like @@ -1641,7 +1641,7 @@ Sema::DeclTy *Sema::ActOnProperty(Scope *S, SourceLocation AtLoc, } else { Diag(CDecl->getLocation(), diag::err_continuation_class); *isOverridingProperty = true; - return 0; + return DeclPtrTy(); } } @@ -1691,24 +1691,24 @@ Sema::DeclTy *Sema::ActOnProperty(Scope *S, SourceLocation AtLoc, else if (MethodImplKind == tok::objc_optional) PDecl->setPropertyImplementation(ObjCPropertyDecl::Optional); - return PDecl; + return DeclPtrTy::make(PDecl); } /// ActOnPropertyImplDecl - This routine performs semantic checks and /// builds the AST node for a property implementation declaration; declared /// as @synthesize or @dynamic. /// -Sema::DeclTy *Sema::ActOnPropertyImplDecl(SourceLocation AtLoc, - SourceLocation PropertyLoc, - bool Synthesize, - DeclTy *ClassCatImpDecl, - IdentifierInfo *PropertyId, - IdentifierInfo *PropertyIvar) { - Decl *ClassImpDecl = static_cast(ClassCatImpDecl); +Sema::DeclPtrTy Sema::ActOnPropertyImplDecl(SourceLocation AtLoc, + SourceLocation PropertyLoc, + bool Synthesize, + DeclPtrTy ClassCatImpDecl, + IdentifierInfo *PropertyId, + IdentifierInfo *PropertyIvar) { + Decl *ClassImpDecl = ClassCatImpDecl.getAs(); // Make sure we have a context for the property implementation declaration. if (!ClassImpDecl) { Diag(AtLoc, diag::error_missing_property_context); - return 0; + return DeclPtrTy(); } ObjCPropertyDecl *property = 0; ObjCInterfaceDecl* IDecl = 0; @@ -1727,18 +1727,18 @@ Sema::DeclTy *Sema::ActOnPropertyImplDecl(SourceLocation AtLoc, property = IDecl->FindPropertyDeclaration(PropertyId); if (!property) { Diag(PropertyLoc, diag::error_bad_property_decl) << IDecl->getDeclName(); - return 0; + return DeclPtrTy(); } } else if ((CatImplClass = dyn_cast(ClassImpDecl))) { if (Synthesize) { Diag(AtLoc, diag::error_synthesize_category_decl); - return 0; + return DeclPtrTy(); } IDecl = CatImplClass->getClassInterface(); if (!IDecl) { Diag(AtLoc, diag::error_missing_property_interface); - return 0; + return DeclPtrTy(); } ObjCCategoryDecl *Category = IDecl->FindCategoryDeclaration(CatImplClass->getIdentifier()); @@ -1746,18 +1746,17 @@ Sema::DeclTy *Sema::ActOnPropertyImplDecl(SourceLocation AtLoc, // If category for this implementation not found, it is an error which // has already been reported eralier. if (!Category) - return 0; + return DeclPtrTy(); // Look for this property declaration in @implementation's category property = Category->FindPropertyDeclaration(PropertyId); if (!property) { Diag(PropertyLoc, diag::error_bad_category_property_decl) << Category->getDeclName(); - return 0; + return DeclPtrTy(); } - } - else { + } else { Diag(AtLoc, diag::error_bad_property_context); - return 0; + return DeclPtrTy(); } ObjCIvarDecl *Ivar = 0; // Check that we have a valid, previously declared ivar for @synthesize @@ -1773,7 +1772,7 @@ Sema::DeclTy *Sema::ActOnPropertyImplDecl(SourceLocation AtLoc, << PropertyId; else Diag(PropertyLoc, diag::error_missing_property_ivar_decl) << PropertyId; - return 0; + return DeclPtrTy(); } QualType PropType = Context.getCanonicalType(property->getType()); QualType IvarType = Context.getCanonicalType(Ivar->getType()); @@ -1783,40 +1782,37 @@ Sema::DeclTy *Sema::ActOnPropertyImplDecl(SourceLocation AtLoc, if (CheckAssignmentConstraints(PropType, IvarType) != Compatible) { Diag(PropertyLoc, diag::error_property_ivar_type) << property->getDeclName() << Ivar->getDeclName(); - return 0; + return DeclPtrTy(); } - else { - // FIXME! Rules for properties are somewhat different that those - // for assignments. Use a new routine to consolidate all cases; - // specifically for property redeclarations as well as for ivars. - QualType lhsType = - Context.getCanonicalType(PropType).getUnqualifiedType(); - QualType rhsType = - Context.getCanonicalType(IvarType).getUnqualifiedType(); - if (lhsType != rhsType && - lhsType->isArithmeticType()) { - Diag(PropertyLoc, diag::error_property_ivar_type) - << property->getDeclName() << Ivar->getDeclName(); - return 0; - } - // __weak is explicit. So it works on Canonical type. - if (PropType.isObjCGCWeak() && !IvarType.isObjCGCWeak()) { - Diag(PropertyLoc, diag::error_weak_property) - << property->getDeclName() << Ivar->getDeclName(); - return 0; - } - if ((Context.isObjCObjectPointerType(property->getType()) || - PropType.isObjCGCStrong()) && IvarType.isObjCGCWeak()) { - Diag(PropertyLoc, diag::error_strong_property) - << property->getDeclName() << Ivar->getDeclName(); - return 0; - } + + // FIXME! Rules for properties are somewhat different that those + // for assignments. Use a new routine to consolidate all cases; + // specifically for property redeclarations as well as for ivars. + QualType lhsType =Context.getCanonicalType(PropType).getUnqualifiedType(); + QualType rhsType =Context.getCanonicalType(IvarType).getUnqualifiedType(); + if (lhsType != rhsType && + lhsType->isArithmeticType()) { + Diag(PropertyLoc, diag::error_property_ivar_type) + << property->getDeclName() << Ivar->getDeclName(); + return DeclPtrTy(); + } + // __weak is explicit. So it works on Canonical type. + if (PropType.isObjCGCWeak() && !IvarType.isObjCGCWeak()) { + Diag(PropertyLoc, diag::error_weak_property) + << property->getDeclName() << Ivar->getDeclName(); + return DeclPtrTy(); + } + if ((Context.isObjCObjectPointerType(property->getType()) || + PropType.isObjCGCStrong()) && IvarType.isObjCGCWeak()) { + Diag(PropertyLoc, diag::error_strong_property) + << property->getDeclName() << Ivar->getDeclName(); + return DeclPtrTy(); } } } else if (PropertyIvar) { // @dynamic Diag(PropertyLoc, diag::error_dynamic_property_ivar_decl); - return 0; + return DeclPtrTy(); } assert (property && "ActOnPropertyImplDecl - property declaration missing"); ObjCPropertyImplDecl *PIDecl = @@ -1840,7 +1836,7 @@ Sema::DeclTy *Sema::ActOnPropertyImplDecl(SourceLocation AtLoc, if (ObjCPropertyImplDecl *PPIDecl = IC->FindPropertyImplDecl(PropertyId)) { Diag(PropertyLoc, diag::error_property_implemented) << PropertyId; Diag(PPIDecl->getLocation(), diag::note_previous_declaration); - return 0; + return DeclPtrTy(); } IC->addPropertyImplementation(PIDecl); } @@ -1858,12 +1854,12 @@ Sema::DeclTy *Sema::ActOnPropertyImplDecl(SourceLocation AtLoc, CatImplClass->FindPropertyImplDecl(PropertyId)) { Diag(PropertyLoc, diag::error_property_implemented) << PropertyId; Diag(PPIDecl->getLocation(), diag::note_previous_declaration); - return 0; + return DeclPtrTy(); } CatImplClass->addPropertyImplementation(PIDecl); } - return PIDecl; + return DeclPtrTy::make(PIDecl); } bool Sema::CheckObjCDeclScope(Decl *D) { @@ -1882,28 +1878,26 @@ bool Sema::CheckObjCDeclScope(Decl *D) { /// part of the AST generation logic of @defs. static void CollectIvars(ObjCInterfaceDecl *Class, RecordDecl *Record, ASTContext& Ctx, - llvm::SmallVectorImpl &ivars) { + llvm::SmallVectorImpl &ivars) { if (Class->getSuperClass()) CollectIvars(Class->getSuperClass(), Record, Ctx, ivars); // For each ivar, create a fresh ObjCAtDefsFieldDecl. - for (ObjCInterfaceDecl::ivar_iterator - I=Class->ivar_begin(), E=Class->ivar_end(); I!=E; ++I) { - + for (ObjCInterfaceDecl::ivar_iterator I = Class->ivar_begin(), + E = Class->ivar_end(); I != E; ++I) { ObjCIvarDecl* ID = *I; - ivars.push_back(ObjCAtDefsFieldDecl::Create(Ctx, Record, - ID->getLocation(), - ID->getIdentifier(), - ID->getType(), - ID->getBitWidth())); + Decl *FD = ObjCAtDefsFieldDecl::Create(Ctx, Record, ID->getLocation(), + ID->getIdentifier(), ID->getType(), + ID->getBitWidth()); + ivars.push_back(Sema::DeclPtrTy::make(FD)); } } /// Called whenever @defs(ClassName) is encountered in the source. Inserts the /// instance variables of ClassName into Decls. -void Sema::ActOnDefs(Scope *S, DeclTy *TagD, SourceLocation DeclStart, +void Sema::ActOnDefs(Scope *S, DeclPtrTy TagD, SourceLocation DeclStart, IdentifierInfo *ClassName, - llvm::SmallVectorImpl &Decls) { + llvm::SmallVectorImpl &Decls) { // Check that ClassName is a valid class ObjCInterfaceDecl *Class = getObjCInterfaceDecl(ClassName); if (!Class) { @@ -1911,15 +1905,15 @@ void Sema::ActOnDefs(Scope *S, DeclTy *TagD, SourceLocation DeclStart, return; } // Collect the instance variables - CollectIvars(Class, dyn_cast((Decl*)TagD), Context, Decls); + CollectIvars(Class, dyn_cast(TagD.getAs()), Context, Decls); // Introduce all of these fields into the appropriate scope. - for (llvm::SmallVectorImpl::iterator D = Decls.begin(); + for (llvm::SmallVectorImpl::iterator D = Decls.begin(); D != Decls.end(); ++D) { - FieldDecl *FD = cast((Decl*)*D); + FieldDecl *FD = cast(D->getAs()); if (getLangOptions().CPlusPlus) PushOnScopeChains(cast(FD), S); - else if (RecordDecl *Record = dyn_cast((Decl*)TagD)) + else if (RecordDecl *Record = dyn_cast(TagD.getAs())) Record->addDecl(FD); } } diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 0a77c21875..39d2a50f6d 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -876,7 +876,7 @@ Sema::ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc, Scope *CheckS = S; while (CheckS) { if (CheckS->isWithinElse() && - CheckS->getControlParent()->isDeclScope(Var)) { + CheckS->getControlParent()->isDeclScope(DeclPtrTy::make(Var))) { if (Var->getType()->isBooleanType()) ExprError(Diag(Loc, diag::warn_value_always_false) << Var->getDeclName()); @@ -1743,7 +1743,7 @@ Action::OwningExprResult Sema::ActOnMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc, tok::TokenKind OpKind, SourceLocation MemberLoc, IdentifierInfo &Member, - DeclTy *ObjCImpDecl) { + DeclPtrTy ObjCImpDecl) { Expr *BaseExpr = static_cast(Base.release()); assert(BaseExpr && "no record expression"); @@ -1879,7 +1879,7 @@ Sema::ActOnMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc, // the context as argument to this routine. Ideally, this context need // be passed down in the AST node and somehow calculated from the AST // for a function decl. - Decl *ImplDecl = static_cast(ObjCImpDecl); + Decl *ImplDecl = ObjCImpDecl.getAs(); if (ObjCImplementationDecl *IMPD = dyn_cast(ImplDecl)) ClassOfMethodDecl = IMPD->getClassInterface(); @@ -4590,13 +4590,13 @@ void Sema::ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope) { // no arguments, not a function that takes a single void argument. if (FTI.hasPrototype && FTI.NumArgs == 1 && !FTI.isVariadic && FTI.ArgInfo[0].Ident == 0 && - (!((ParmVarDecl *)FTI.ArgInfo[0].Param)->getType().getCVRQualifiers() && - ((ParmVarDecl *)FTI.ArgInfo[0].Param)->getType()->isVoidType())) { + (!FTI.ArgInfo[0].Param.getAs()->getType().getCVRQualifiers()&& + FTI.ArgInfo[0].Param.getAs()->getType()->isVoidType())) { // empty arg list, don't push any params. CurBlock->isVariadic = false; } else if (FTI.hasPrototype) { for (unsigned i = 0, e = FTI.NumArgs; i != e; ++i) - CurBlock->Params.push_back((ParmVarDecl *)FTI.ArgInfo[i].Param); + CurBlock->Params.push_back(FTI.ArgInfo[i].Param.getAs()); CurBlock->isVariadic = FTI.isVariadic; QualType T = GetTypeForDeclarator (ParamInfo, CurScope); diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index a6cb24ceec..361434a0dd 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -664,26 +664,28 @@ Sema::ActOnCXXConditionDeclarationExpr(Scope *S, SourceLocation StartLoc, } else if (const RecordType *RT = Ty->getAsRecordType()) { RecordDecl *RD = RT->getDecl(); // The type-specifier-seq shall not declare a new class... - if (RD->isDefinition() && (RD->getIdentifier() == 0 || S->isDeclScope(RD))) + if (RD->isDefinition() && + (RD->getIdentifier() == 0 || S->isDeclScope(DeclPtrTy::make(RD)))) Diag(RD->getLocation(), diag::err_type_defined_in_condition); } else if (const EnumType *ET = Ty->getAsEnumType()) { EnumDecl *ED = ET->getDecl(); // ...or enumeration. - if (ED->isDefinition() && (ED->getIdentifier() == 0 || S->isDeclScope(ED))) + if (ED->isDefinition() && + (ED->getIdentifier() == 0 || S->isDeclScope(DeclPtrTy::make(ED)))) Diag(ED->getLocation(), diag::err_type_defined_in_condition); } - DeclTy *Dcl = ActOnDeclarator(S, D, 0); + DeclPtrTy Dcl = ActOnDeclarator(S, D, DeclPtrTy()); if (!Dcl) return ExprError(); AddInitializerToDecl(Dcl, move(AssignExprVal)); // Mark this variable as one that is declared within a conditional. - if (VarDecl *VD = dyn_cast((Decl *)Dcl)) - VD->setDeclaredInCondition(true); - - return Owned(new (Context) CXXConditionDeclExpr(StartLoc, EqualLoc, - cast(static_cast(Dcl)))); + // We know that the decl had to be a VarDecl because that is the only type of + // decl that can be assigned and the grammar requires an '='. + VarDecl *VD = cast(Dcl.getAs()); + VD->setDeclaredInCondition(true); + return Owned(new (Context) CXXConditionDeclExpr(StartLoc, EqualLoc, VD)); } /// CheckCXXBooleanCondition - Returns true if a conversion to bool is invalid. diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index 770f9301e6..69bd5602d3 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -84,12 +84,11 @@ static void AddScopeUsingDirectives(Scope *S, UsingDirectivesTy &UDirs) { AddNamespaceUsingDirectives(Ctx, UDirs, /*ref*/ VisitedNS); } else { - Scope::udir_iterator - I = S->using_directives_begin(), - End = S->using_directives_end(); + Scope::udir_iterator I = S->using_directives_begin(), + End = S->using_directives_end(); for (; I != End; ++I) { - UsingDirectiveDecl * UD = static_cast(*I); + UsingDirectiveDecl *UD = I->getAs(); UDirs.push_back(UD); std::push_heap(UDirs.begin(), UDirs.end(), UsingDirAncestorCompare()); @@ -575,7 +574,7 @@ Sema::CppLookupName(Scope *S, DeclarationName Name, // for (; S && !isNamespaceOrTranslationUnitScope(S); S = S->getParent()) { // Check whether the IdResolver has anything in this scope. - for (; I != IEnd && S->isDeclScope(*I); ++I) { + for (; I != IEnd && S->isDeclScope(DeclPtrTy::make(*I)); ++I) { if (isAcceptableLookupResult(*I, NameKind, IDNS)) { // We found something. Look for anything else in our scope // with this same name and in an acceptable identifier @@ -583,7 +582,7 @@ Sema::CppLookupName(Scope *S, DeclarationName Name, // need to. IdentifierResolver::iterator LastI = I; for (++LastI; LastI != IEnd; ++LastI) { - if (!S->isDeclScope(*LastI)) + if (!S->isDeclScope(DeclPtrTy::make(*LastI))) break; } LookupResult Result = @@ -666,7 +665,7 @@ Sema::CppLookupName(Scope *S, DeclarationName Name, "We should have been looking only at file context here already."); // Check whether the IdResolver has anything in this scope. - for (; I != IEnd && S->isDeclScope(*I); ++I) { + for (; I != IEnd && S->isDeclScope(DeclPtrTy::make(*I)); ++I) { if (isAcceptableLookupResult(*I, NameKind, IDNS)) { // We found something. Look for anything else in our scope // with this same name and in an acceptable identifier @@ -674,7 +673,7 @@ Sema::CppLookupName(Scope *S, DeclarationName Name, // need to. IdentifierResolver::iterator LastI = I; for (++LastI; LastI != IEnd; ++LastI) { - if (!S->isDeclScope(*LastI)) + if (!S->isDeclScope(DeclPtrTy::make(*LastI))) break; } @@ -790,7 +789,7 @@ Sema::LookupName(Scope *S, DeclarationName Name, LookupNameKind NameKind, if (NameKind == LookupRedeclarationWithLinkage) { // Determine whether this (or a previous) declaration is // out-of-scope. - if (!LeftStartingScope && !S->isDeclScope(*I)) + if (!LeftStartingScope && !S->isDeclScope(DeclPtrTy::make(*I))) LeftStartingScope = true; // If we found something outside of our starting scope that @@ -804,14 +803,15 @@ Sema::LookupName(Scope *S, DeclarationName Name, LookupNameKind NameKind, // might have a set of overloaded functions. // Figure out what scope the identifier is in. - while (!(S->getFlags() & Scope::DeclScope) || !S->isDeclScope(*I)) + while (!(S->getFlags() & Scope::DeclScope) || + !S->isDeclScope(DeclPtrTy::make(*I))) S = S->getParent(); // Find the last declaration in this scope (with the same // name, naturally). IdentifierResolver::iterator LastI = I; for (++LastI; LastI != IEnd; ++LastI) { - if (!S->isDeclScope(*LastI)) + if (!S->isDeclScope(DeclPtrTy::make(*LastI))) break; } diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index 025a245c6c..ca6d7fe98e 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -4323,7 +4323,7 @@ Sema::BuildOverloadedArrowExpr(Scope *S, Expr *Base, SourceLocation OpLoc, Method->getResultType().getNonReferenceType(), OpLoc); return ActOnMemberReferenceExpr(S, ExprArg(*this, Base), OpLoc, tok::arrow, - MemberLoc, Member).release(); + MemberLoc, Member, DeclPtrTy()).release(); } /// FixOverloadedFunctionReference - E is an expression that refers to diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 4082d485b8..b331911099 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -37,14 +37,13 @@ Sema::OwningStmtResult Sema::ActOnNullStmt(SourceLocation SemiLoc) { return Owned(new (Context) NullStmt(SemiLoc)); } -Sema::OwningStmtResult Sema::ActOnDeclStmt(DeclTy *decl, +Sema::OwningStmtResult Sema::ActOnDeclStmt(DeclPtrTy decl, SourceLocation StartLoc, SourceLocation EndLoc) { - if (decl == 0) + Decl *D = decl.getAs(); + if (D == 0) return StmtError(); - Decl *D = static_cast(decl); - // This is a temporary hack until we are always passing around // DeclGroupRefs. llvm::SmallVector decls; @@ -1001,10 +1000,10 @@ Sema::OwningStmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, Action::OwningStmtResult Sema::ActOnObjCAtCatchStmt(SourceLocation AtLoc, - SourceLocation RParen, DeclTy *Parm, + SourceLocation RParen, DeclPtrTy Parm, StmtArg Body, StmtArg catchList) { Stmt *CatchList = static_cast(catchList.release()); - ParmVarDecl *PVD = static_cast(Parm); + ParmVarDecl *PVD = cast_or_null(Parm.getAs()); // PVD == 0 implies @catch(...). if (PVD) { @@ -1071,11 +1070,11 @@ Sema::ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, ExprArg SynchExpr, /// ActOnCXXCatchBlock - Takes an exception declaration and a handler block /// and creates a proper catch handler from them. Action::OwningStmtResult -Sema::ActOnCXXCatchBlock(SourceLocation CatchLoc, DeclTy *ExDecl, +Sema::ActOnCXXCatchBlock(SourceLocation CatchLoc, DeclPtrTy ExDecl, StmtArg HandlerBlock) { // There's nothing to test that ActOnExceptionDecl didn't already test. return Owned(new (Context) CXXCatchStmt(CatchLoc, - static_cast(ExDecl), + cast_or_null(ExDecl.getAs()), static_cast(HandlerBlock.release()))); } diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 69946975cd..773a2b1b92 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -27,21 +27,19 @@ using namespace clang; /// passed to indicate the C++ scope in which the identifier will be /// found. TemplateNameKind Sema::isTemplateName(IdentifierInfo &II, Scope *S, - DeclTy *&Template, + DeclPtrTy &Template, const CXXScopeSpec *SS) { NamedDecl *IIDecl = LookupParsedName(S, SS, &II, LookupOrdinaryName); if (IIDecl) { if (isa(IIDecl)) { - Template = IIDecl; + Template = DeclPtrTy::make(IIDecl); if (isa(IIDecl)) return TNK_Function_template; - else if (isa(IIDecl)) + if (isa(IIDecl)) return TNK_Class_template; - else if (isa(IIDecl)) - return TNK_Template_template_parm; - else - assert(false && "Unknown TemplateDecl"); + assert(isa(IIDecl) && "Unknown TemplateDecl"); + return TNK_Template_template_parm; } else if (CXXRecordDecl *Record = dyn_cast(IIDecl)) { // C++ [temp.local]p1: // Like normal (non-template) classes, class templates have an @@ -56,11 +54,11 @@ TemplateNameKind Sema::isTemplateName(IdentifierInfo &II, Scope *S, // specialization. if (Record->isInjectedClassName()) { Record = cast(Context.getCanonicalDecl(Record)); - if ((Template = Record->getDescribedClassTemplate())) + if ((Template = DeclPtrTy::make(Record->getDescribedClassTemplate()))) return TNK_Class_template; - else if (ClassTemplateSpecializationDecl *Spec + if (ClassTemplateSpecializationDecl *Spec = dyn_cast(Record)) { - Template = Spec->getSpecializedTemplate(); + Template = DeclPtrTy::make(Spec->getSpecializedTemplate()); return TNK_Class_template; } } @@ -69,7 +67,7 @@ TemplateNameKind Sema::isTemplateName(IdentifierInfo &II, Scope *S, // FIXME: What follows is a gross hack. if (FunctionDecl *FD = dyn_cast(IIDecl)) { if (FD->getType()->isDependentType()) { - Template = FD; + Template = DeclPtrTy::make(FD); return TNK_Function_template; } } else if (OverloadedFunctionDecl *Ovl @@ -78,7 +76,7 @@ TemplateNameKind Sema::isTemplateName(IdentifierInfo &II, Scope *S, FEnd = Ovl->function_end(); F != FEnd; ++F) { if ((*F)->getType()->isDependentType()) { - Template = Ovl; + Template = DeclPtrTy::make(Ovl); return TNK_Function_template; } } @@ -110,10 +108,9 @@ bool Sema::DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl) { /// AdjustDeclIfTemplate - If the given decl happens to be a template, reset /// the parameter D to reference the templated declaration and return a pointer /// to the template declaration. Otherwise, do nothing to D and return null. -TemplateDecl *Sema::AdjustDeclIfTemplate(DeclTy *&D) -{ - if(TemplateDecl *Temp = dyn_cast(static_cast(D))) { - D = Temp->getTemplatedDecl(); +TemplateDecl *Sema::AdjustDeclIfTemplate(DeclPtrTy &D) { + if (TemplateDecl *Temp = dyn_cast(D.getAs())) { + D = DeclPtrTy::make(Temp->getTemplatedDecl()); return Temp; } return 0; @@ -128,11 +125,11 @@ TemplateDecl *Sema::AdjustDeclIfTemplate(DeclTy *&D) /// ParamName is the location of the parameter name (if any). /// If the type parameter has a default argument, it will be added /// later via ActOnTypeParameterDefault. -Sema::DeclTy *Sema::ActOnTypeParameter(Scope *S, bool Typename, - SourceLocation KeyLoc, - IdentifierInfo *ParamName, - SourceLocation ParamNameLoc, - unsigned Depth, unsigned Position) { +Sema::DeclPtrTy Sema::ActOnTypeParameter(Scope *S, bool Typename, + SourceLocation KeyLoc, + IdentifierInfo *ParamName, + SourceLocation ParamNameLoc, + unsigned Depth, unsigned Position) { assert(S->isTemplateParamScope() && "Template type parameter not in template parameter scope!"); bool Invalid = false; @@ -156,21 +153,21 @@ Sema::DeclTy *Sema::ActOnTypeParameter(Scope *S, bool Typename, if (ParamName) { // Add the template parameter into the current scope. - S->AddDecl(Param); + S->AddDecl(DeclPtrTy::make(Param)); IdResolver.AddDecl(Param); } - return Param; + return DeclPtrTy::make(Param); } /// ActOnTypeParameterDefault - Adds a default argument (the type /// Default) to the given template type parameter (TypeParam). -void Sema::ActOnTypeParameterDefault(DeclTy *TypeParam, +void Sema::ActOnTypeParameterDefault(DeclPtrTy TypeParam, SourceLocation EqualLoc, SourceLocation DefaultLoc, TypeTy *DefaultT) { TemplateTypeParmDecl *Parm - = cast(static_cast(TypeParam)); + = cast(TypeParam.getAs()); QualType Default = QualType::getFromOpaquePtr(DefaultT); // C++ [temp.param]p14: @@ -234,9 +231,9 @@ Sema::CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc) { /// template parameter (e.g., "int Size" in "template /// class Array") has been parsed. S is the current scope and D is /// the parsed declarator. -Sema::DeclTy *Sema::ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, - unsigned Depth, - unsigned Position) { +Sema::DeclPtrTy Sema::ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, + unsigned Depth, + unsigned Position) { QualType T = GetTypeForDeclarator(D, S); assert(S->isTemplateParamScope() && @@ -265,19 +262,19 @@ Sema::DeclTy *Sema::ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, if (D.getIdentifier()) { // Add the template parameter into the current scope. - S->AddDecl(Param); + S->AddDecl(DeclPtrTy::make(Param)); IdResolver.AddDecl(Param); } - return Param; + return DeclPtrTy::make(Param); } /// \brief Adds a default argument to the given non-type template /// parameter. -void Sema::ActOnNonTypeTemplateParameterDefault(DeclTy *TemplateParamD, +void Sema::ActOnNonTypeTemplateParameterDefault(DeclPtrTy TemplateParamD, SourceLocation EqualLoc, ExprArg DefaultE) { NonTypeTemplateParmDecl *TemplateParm - = cast(static_cast(TemplateParamD)); + = cast(TemplateParamD.getAs()); Expr *Default = static_cast(DefaultE.get()); // C++ [temp.param]p14: @@ -297,13 +294,13 @@ void Sema::ActOnNonTypeTemplateParameterDefault(DeclTy *TemplateParamD, /// ActOnTemplateTemplateParameter - Called when a C++ template template /// parameter (e.g. T in template