diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-05-28 23:31:59 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-05-28 23:31:59 +0000 |
commit | 402abb55fc2e0cdda5fb1ac90009b1f5f6774906 (patch) | |
tree | 3c379d93e527baaa9a8cc7184a92f80b8f9762da /lib/Parse | |
parent | 2dce5f8a99b5c48f1287ff3941288ca6f7fde2de (diff) |
When we parse a tag specifier, keep track of whether that tag
specifier resulted in the creation of a new TagDecl node, which
happens either when the tag specifier was a definition or when the tag
specifier was the first declaration of that tag type. This information
has several uses, the first of which is implemented in this commit:
1) In C++, one is not allowed to define tag types within a type
specifier (e.g., static_cast<struct S { int x; } *>(0) is
ill-formed) or within the result or parameter types of a
function. We now diagnose this.
2) We can extend DeclGroups to contain information about any tags
that are declared/defined within the declaration specifiers of a
variable, e.g.,
struct Point { int x, y, z; } p;
This will help improve AST printing and template instantiation,
among other things.
3) For C99, we can keep track of whether a tag type is defined
within the type of a parameter, to properly cope with cases like,
e.g.,
int bar(struct T2 { int x; } y) {
struct T2 z;
}
We can also do similar things wherever there is a type specifier,
e.g., to keep track of where the definition of S occurs in this
legal C99 code:
(struct S { int x, y; } *)0
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72555 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse')
-rw-r--r-- | lib/Parse/DeclSpec.cpp | 4 | ||||
-rw-r--r-- | lib/Parse/ParseDecl.cpp | 6 | ||||
-rw-r--r-- | lib/Parse/ParseDeclCXX.cpp | 5 |
3 files changed, 10 insertions, 5 deletions
diff --git a/lib/Parse/DeclSpec.cpp b/lib/Parse/DeclSpec.cpp index e592deecd0..2a765d2124 100644 --- a/lib/Parse/DeclSpec.cpp +++ b/lib/Parse/DeclSpec.cpp @@ -241,12 +241,14 @@ bool DeclSpec::SetTypeSpecSign(TSS S, SourceLocation Loc, } bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc, - const char *&PrevSpec, void *Rep) { + const char *&PrevSpec, void *Rep, + bool Owned) { if (TypeSpecType != TST_unspecified) return BadSpecifier((TST)TypeSpecType, PrevSpec); TypeSpecType = T; TypeRep = Rep; TSTLoc = Loc; + TypeSpecOwned = Owned; return false; } diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 59e9555a88..54e70be16e 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -1460,8 +1460,10 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS, TK = Action::TK_Declaration; else TK = Action::TK_Reference; + bool Owned = false; DeclPtrTy TagDecl = Actions.ActOnTag(CurScope, DeclSpec::TST_enum, TK, - StartLoc, SS, Name, NameLoc, Attr, AS); + StartLoc, SS, Name, NameLoc, Attr, AS, + Owned); if (Tok.is(tok::l_brace)) ParseEnumBody(StartLoc, TagDecl); @@ -1469,7 +1471,7 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS, // TODO: semantic analysis on the declspec for enums. const char *PrevSpec = 0; if (DS.SetTypeSpecType(DeclSpec::TST_enum, StartLoc, PrevSpec, - TagDecl.getAs<void>())) + TagDecl.getAs<void>(), Owned)) Diag(StartLoc, diag::err_invalid_decl_spec_combination) << PrevSpec; } diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index a7d3b52bd2..cfbd9097f7 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -479,6 +479,7 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind, // FIXME: When TK == TK_Reference and we have a template-id, we need // to turn that template-id into a type. + bool Owned = false; if (TemplateId && TK != Action::TK_Reference) { // Explicit specialization, class template partial specialization, // or explicit instantiation. @@ -582,7 +583,7 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind, // Declaration or definition of a class type TagOrTempResult = Actions.ActOnTag(CurScope, TagType, TK, StartLoc, SS, - Name, NameLoc, Attr, AS); + Name, NameLoc, Attr, AS, Owned); } // Parse the optional base clause (C++ only). @@ -608,7 +609,7 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind, } if (DS.SetTypeSpecType(TagType, StartLoc, PrevSpec, - TagOrTempResult.get().getAs<void>())) + TagOrTempResult.get().getAs<void>(), Owned)) Diag(StartLoc, diag::err_invalid_decl_spec_combination) << PrevSpec; if (DS.isFriendSpecified()) |