diff options
author | Chris Lattner <sabre@nondot.org> | 2009-03-28 19:18:32 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-03-28 19:18:32 +0000 |
commit | b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2 (patch) | |
tree | de590dbcd3bf708b1f203f27df4eccef59f0235a /lib/Parse | |
parent | 8054e25b5116e331a2ee4203f5fae2bee1c3cc46 (diff) |
Introduce a new OpaquePtr<N> 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<DeclPtrTy> 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
Diffstat (limited to 'lib/Parse')
-rw-r--r-- | lib/Parse/DeclSpec.cpp | 2 | ||||
-rw-r--r-- | lib/Parse/MinimalAction.cpp | 42 | ||||
-rw-r--r-- | lib/Parse/ParseCXXInlineMethods.cpp | 5 | ||||
-rw-r--r-- | lib/Parse/ParseDecl.cpp | 69 | ||||
-rw-r--r-- | lib/Parse/ParseDeclCXX.cpp | 74 | ||||
-rw-r--r-- | lib/Parse/ParseExprCXX.cpp | 2 | ||||
-rw-r--r-- | lib/Parse/ParseObjc.cpp | 159 | ||||
-rw-r--r-- | lib/Parse/ParseStmt.cpp | 12 | ||||
-rw-r--r-- | lib/Parse/ParseTemplate.cpp | 45 | ||||
-rw-r--r-- | lib/Parse/Parser.cpp | 48 |
10 files changed, 227 insertions, 231 deletions
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<TypeNameInfo>(); 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<IdentifierInfo*>(*I); + IdentifierInfo &II = *(*I).getAs<IdentifierInfo>(); TypeNameInfo *TI = II.getFETokenInfo<TypeNameInfo>(); 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<DeclTy *, 8> ProtocolDecl; + llvm::SmallVector<DeclPtrTy, 8> 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<DeclTy *, 8> ProtocolDecl; + llvm::SmallVector<DeclPtrTy, 8> ProtocolDecl; ParseObjCProtocolReferences(ProtocolDecl, false, EndProtoLoc); DS.setProtocolQualifiers(&ProtocolDecl[0], ProtocolDecl.size()); @@ -809,7 +809,7 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS, { SourceLocation EndProtoLoc; - llvm::SmallVector<DeclTy *, 8> ProtocolDecl; + llvm::SmallVector<DeclPtrTy, 8> 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<DeclTy *, 8> ProtocolDecl; + llvm::SmallVector<DeclPtrTy, 8> 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<DeclTy*, 32> FieldDecls; + llvm::SmallVector<DeclPtrTy, 32> FieldDecls; llvm::SmallVector<FieldDeclarator, 8> 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<DeclTy*, 16> Fields; + llvm::SmallVector<DeclPtrTy, 16> 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<void>())) 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<DeclTy*, 32> EnumConstantDecls; + llvm::SmallVector<DeclPtrTy, 32> 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<char, 8> 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<void>())) 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<IdentifierInfo *, 8> 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<DeclTy *, 8> ProtocolRefs; + llvm::SmallVector<DeclPtrTy, 8> 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, |