[cfe-commits] r39274 - in /cfe/cfe/trunk: AST/Sema.h AST/SemaDecl.cpp Parse/ParseDecl.cpp Sema/Sema.h Sema/SemaDecl.cpp include/clang/Parse/Action.h
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:42:19 PDT 2007
Author: sabre
Date: Wed Jul 11 11:42:18 2007
New Revision: 39274
URL: http://llvm.org/viewvc/llvm-project?rev=39274&view=rev
Log:
When parsing a struct/union tag, we need to know whether the tag is a use
or a definition/declaration of a tag. This is required to handle
C99 6.7.2.3p11 properly.
Modified:
cfe/cfe/trunk/AST/Sema.h
cfe/cfe/trunk/AST/SemaDecl.cpp
cfe/cfe/trunk/Parse/ParseDecl.cpp
cfe/cfe/trunk/Sema/Sema.h
cfe/cfe/trunk/Sema/SemaDecl.cpp
cfe/cfe/trunk/include/clang/Parse/Action.h
Modified: cfe/cfe/trunk/AST/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Sema.h?rev=39274&r1=39273&r2=39274&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/Sema.h (original)
+++ cfe/cfe/trunk/AST/Sema.h Wed Jul 11 11:42:18 2007
@@ -83,7 +83,7 @@
Decl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
Scope *S);
- virtual DeclTy *ParseStructUnionTag(Scope *S, bool isUnion,
+ virtual DeclTy *ParseStructUnionTag(Scope *S, bool isUnion, bool isUse,
SourceLocation KWLoc,IdentifierInfo *Name,
SourceLocation NameLoc);
Modified: cfe/cfe/trunk/AST/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/SemaDecl.cpp?rev=39274&r1=39273&r2=39274&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/SemaDecl.cpp (original)
+++ cfe/cfe/trunk/AST/SemaDecl.cpp Wed Jul 11 11:42:18 2007
@@ -141,7 +141,6 @@
const DeclaratorChunk::ParamInfo &PI = FTI.Fun.ArgInfo[ArgNo];
IdentifierInfo *II = PI.Ident;
-
if (Decl *PrevDecl = LookupScopedDecl(II, Decl::IDNS_Ordinary)) {
// TODO: CHECK FOR CONFLICTS, multiple decls with same name in one scope.
@@ -265,14 +264,31 @@
/// ParseStructUnionTag - This is invoked when we see 'struct foo' or
/// 'struct {'. In the former case, Name will be non-null. In the later case,
/// Name will be null. isUnion indicates whether this is a union or struct tag.
-Sema::DeclTy *Sema::ParseStructUnionTag(Scope *S, bool isUnion,
+/// isUse indicates whether this is a use of a preexisting struct tag, or if it
+/// is a definition or declaration of a new one.
+Sema::DeclTy *Sema::ParseStructUnionTag(Scope *S, bool isUnion, bool isUse,
SourceLocation KWLoc,
IdentifierInfo *Name,
SourceLocation NameLoc) {
+ // If this is a use of an existing tag, it must have a name.
+ assert((isUse || Name != 0) && "Nameless record must have a name!");
+
// If this is a named struct, check to see if there was a previous forward
// declaration or definition.
if (Decl *PrevDecl = LookupScopedDecl(Name, Decl::IDNS_Tag)) {
+
+ // If this is a use of a previous tag, or if the tag is already declared in
+ // the same scope (so that the definition/declaration completes or
+ // rementions the tag), reuse the decl.
+ if (isUse || S->isDeclScope(PrevDecl)) {
+
+
+ }
+
// TODO: verify it's struct/union, etc.
+
+
+
}
// If there is an identifier, use the location of the identifier as the
Modified: cfe/cfe/trunk/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseDecl.cpp?rev=39274&r1=39273&r2=39274&view=diff
==============================================================================
--- cfe/cfe/trunk/Parse/ParseDecl.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseDecl.cpp Wed Jul 11 11:42:18 2007
@@ -454,9 +454,17 @@
// There are three options here. If we have 'struct foo;', then this is a
// forward declaration. If we have 'struct foo {...' then this is a
- // definition. Otherwise we have something like 'struct foo xyz', a use.
- DeclTy *TagDecl = Actions.ParseStructUnionTag(CurScope, isUnion, StartLoc,
- Name, NameLoc);
+ // definition. Otherwise we have something like 'struct foo xyz', a use. Tell
+ // the actions module whether this is a definition (forward or not) of the
+ // type insted of a use.
+ //
+ // This is needed to handle stuff like this right (C99 6.7.2.3p11):
+ // struct foo {..}; void bar() { struct foo; } <- new foo in bar.
+ // struct foo {..}; void bar() { struct foo x; } <- use of old foo.
+ //
+ bool isUse = Tok.getKind() != tok::l_brace && Tok.getKind() != tok::semi;
+ DeclTy *TagDecl = Actions.ParseStructUnionTag(CurScope, isUnion, isUse,
+ StartLoc, Name, NameLoc);
// TODO: more with the tag decl.
if (Tok.getKind() == tok::l_brace) {
SourceLocation LBraceLoc = ConsumeBrace();
Modified: cfe/cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/Sema.h?rev=39274&r1=39273&r2=39274&view=diff
==============================================================================
--- cfe/cfe/trunk/Sema/Sema.h (original)
+++ cfe/cfe/trunk/Sema/Sema.h Wed Jul 11 11:42:18 2007
@@ -83,7 +83,7 @@
Decl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
Scope *S);
- virtual DeclTy *ParseStructUnionTag(Scope *S, bool isUnion,
+ virtual DeclTy *ParseStructUnionTag(Scope *S, bool isUnion, bool isUse,
SourceLocation KWLoc,IdentifierInfo *Name,
SourceLocation NameLoc);
Modified: cfe/cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/SemaDecl.cpp?rev=39274&r1=39273&r2=39274&view=diff
==============================================================================
--- cfe/cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaDecl.cpp Wed Jul 11 11:42:18 2007
@@ -141,7 +141,6 @@
const DeclaratorChunk::ParamInfo &PI = FTI.Fun.ArgInfo[ArgNo];
IdentifierInfo *II = PI.Ident;
-
if (Decl *PrevDecl = LookupScopedDecl(II, Decl::IDNS_Ordinary)) {
// TODO: CHECK FOR CONFLICTS, multiple decls with same name in one scope.
@@ -265,14 +264,31 @@
/// ParseStructUnionTag - This is invoked when we see 'struct foo' or
/// 'struct {'. In the former case, Name will be non-null. In the later case,
/// Name will be null. isUnion indicates whether this is a union or struct tag.
-Sema::DeclTy *Sema::ParseStructUnionTag(Scope *S, bool isUnion,
+/// isUse indicates whether this is a use of a preexisting struct tag, or if it
+/// is a definition or declaration of a new one.
+Sema::DeclTy *Sema::ParseStructUnionTag(Scope *S, bool isUnion, bool isUse,
SourceLocation KWLoc,
IdentifierInfo *Name,
SourceLocation NameLoc) {
+ // If this is a use of an existing tag, it must have a name.
+ assert((isUse || Name != 0) && "Nameless record must have a name!");
+
// If this is a named struct, check to see if there was a previous forward
// declaration or definition.
if (Decl *PrevDecl = LookupScopedDecl(Name, Decl::IDNS_Tag)) {
+
+ // If this is a use of a previous tag, or if the tag is already declared in
+ // the same scope (so that the definition/declaration completes or
+ // rementions the tag), reuse the decl.
+ if (isUse || S->isDeclScope(PrevDecl)) {
+
+
+ }
+
// TODO: verify it's struct/union, etc.
+
+
+
}
// If there is an identifier, use the location of the identifier as the
Modified: cfe/cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Parse/Action.h?rev=39274&r1=39273&r2=39274&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/Action.h Wed Jul 11 11:42:18 2007
@@ -140,7 +140,7 @@
return 0;
}
- virtual DeclTy *ParseStructUnionTag(Scope *S, bool isUnion,
+ virtual DeclTy *ParseStructUnionTag(Scope *S, bool isUnion, bool isUse,
SourceLocation KWLoc,IdentifierInfo *Name,
SourceLocation NameLoc) {
return 0;
More information about the cfe-commits
mailing list