[cfe-commits] r39277 - in /cfe/cfe/trunk: AST/Sema.h AST/SemaDecl.cpp Parse/ParseDecl.cpp Sema/Sema.h Sema/SemaDecl.cpp include/clang/Basic/DiagnosticKinds.def include/clang/Parse/Action.h
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:42:22 PDT 2007
Author: sabre
Date: Wed Jul 11 11:42:22 2007
New Revision: 39277
URL: http://llvm.org/viewvc/llvm-project?rev=39277&view=rev
Log:
Finish tag processing. Since it can be shared with C++ Classes and enums,
rename it to ParseTag.
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/Basic/DiagnosticKinds.def
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=39277&r1=39276&r2=39277&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/Sema.h (original)
+++ cfe/cfe/trunk/AST/Sema.h Wed Jul 11 11:42:22 2007
@@ -83,10 +83,10 @@
Decl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
Scope *S);
- virtual DeclTy *ParseStructUnionTag(Scope *S, bool isUnion, bool isUse,
- SourceLocation KWLoc,IdentifierInfo *Name,
- SourceLocation NameLoc);
-
+ virtual DeclTy *ParseTag(Scope *S, TagType Ty, bool isUse,
+ SourceLocation KWLoc, IdentifierInfo *Name,
+ SourceLocation NameLoc);
+
//===--------------------------------------------------------------------===//
// Statement Parsing Callbacks: SemaStmt.cpp.
Modified: cfe/cfe/trunk/AST/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/SemaDecl.cpp?rev=39277&r1=39276&r2=39277&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/SemaDecl.cpp (original)
+++ cfe/cfe/trunk/AST/SemaDecl.cpp Wed Jul 11 11:42:22 2007
@@ -266,14 +266,20 @@
/// Name will be null. isUnion indicates whether this is a union or struct tag.
/// 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) {
+Sema::DeclTy *Sema::ParseTag(Scope *S, TagType Ty, 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!");
- Decl::Kind Kind = isUnion ? Decl::Union : Decl::Struct;
+ Decl::Kind Kind;
+ switch (Ty) {
+ default: assert(0 && "Unknown tag type!");
+ case TAG_STRUCT: Kind = Decl::Struct; break;
+ case TAG_UNION: Kind = Decl::Union; break;
+ case TAG_CLASS: Kind = Decl::Class; break;
+ case TAG_ENUM: Kind = Decl::Enum; break;
+ }
// If there is an identifier, use the location of the identifier as the
// location of the decl, otherwise use the location of the struct/union
@@ -292,20 +298,24 @@
// Make sure that this wasn't declared as an enum and now used as a struct
// or something similar.
if (PrevDecl->getKind() != Kind) {
- Diag(KWLoc, diag::err_redefinition_with_wrong_tag, Name->getName());
+ Diag(KWLoc, diag::err_use_with_wrong_tag, Name->getName());
Diag(PrevDecl->getLocation(), diag::err_previous_use);
}
-
+
+ // Okay, this is a reference to the old decl, return it.
+ return PrevDecl;
}
-
- // TODO: verify it's struct/union, etc.
-
-
-
+ // If we get here, this is a definition of a new struct type in a nested
+ // scope, e.g. "struct foo; void bar() { struct foo; }", just create a new
+ // type.
}
// Otherwise, if this is the first time we've seen this tag, create the decl.
- Decl *New = new RecordDecl(Kind, Loc, Name);
+ Decl *New;
+ if (Kind != Decl::Enum)
+ New = new RecordDecl(Kind, Loc, Name);
+ else
+ assert(0 && "Enum tags not implemented yet!");
// If this has an identifier, add it to the scope stack.
if (Name) {
Modified: cfe/cfe/trunk/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseDecl.cpp?rev=39277&r1=39276&r2=39277&view=diff
==============================================================================
--- cfe/cfe/trunk/Parse/ParseDecl.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseDecl.cpp Wed Jul 11 11:42:22 2007
@@ -463,8 +463,10 @@
// 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);
+ DeclTy *TagDecl = Actions.ParseTag(CurScope,
+ isUnion ? Action::TAG_UNION :
+ Action::TAG_STRUCT, 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=39277&r1=39276&r2=39277&view=diff
==============================================================================
--- cfe/cfe/trunk/Sema/Sema.h (original)
+++ cfe/cfe/trunk/Sema/Sema.h Wed Jul 11 11:42:22 2007
@@ -83,10 +83,10 @@
Decl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
Scope *S);
- virtual DeclTy *ParseStructUnionTag(Scope *S, bool isUnion, bool isUse,
- SourceLocation KWLoc,IdentifierInfo *Name,
- SourceLocation NameLoc);
-
+ virtual DeclTy *ParseTag(Scope *S, TagType Ty, bool isUse,
+ SourceLocation KWLoc, IdentifierInfo *Name,
+ SourceLocation NameLoc);
+
//===--------------------------------------------------------------------===//
// Statement Parsing Callbacks: SemaStmt.cpp.
Modified: cfe/cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/SemaDecl.cpp?rev=39277&r1=39276&r2=39277&view=diff
==============================================================================
--- cfe/cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaDecl.cpp Wed Jul 11 11:42:22 2007
@@ -266,14 +266,20 @@
/// Name will be null. isUnion indicates whether this is a union or struct tag.
/// 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) {
+Sema::DeclTy *Sema::ParseTag(Scope *S, TagType Ty, 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!");
- Decl::Kind Kind = isUnion ? Decl::Union : Decl::Struct;
+ Decl::Kind Kind;
+ switch (Ty) {
+ default: assert(0 && "Unknown tag type!");
+ case TAG_STRUCT: Kind = Decl::Struct; break;
+ case TAG_UNION: Kind = Decl::Union; break;
+ case TAG_CLASS: Kind = Decl::Class; break;
+ case TAG_ENUM: Kind = Decl::Enum; break;
+ }
// If there is an identifier, use the location of the identifier as the
// location of the decl, otherwise use the location of the struct/union
@@ -292,20 +298,24 @@
// Make sure that this wasn't declared as an enum and now used as a struct
// or something similar.
if (PrevDecl->getKind() != Kind) {
- Diag(KWLoc, diag::err_redefinition_with_wrong_tag, Name->getName());
+ Diag(KWLoc, diag::err_use_with_wrong_tag, Name->getName());
Diag(PrevDecl->getLocation(), diag::err_previous_use);
}
-
+
+ // Okay, this is a reference to the old decl, return it.
+ return PrevDecl;
}
-
- // TODO: verify it's struct/union, etc.
-
-
-
+ // If we get here, this is a definition of a new struct type in a nested
+ // scope, e.g. "struct foo; void bar() { struct foo; }", just create a new
+ // type.
}
// Otherwise, if this is the first time we've seen this tag, create the decl.
- Decl *New = new RecordDecl(Kind, Loc, Name);
+ Decl *New;
+ if (Kind != Decl::Enum)
+ New = new RecordDecl(Kind, Loc, Name);
+ else
+ assert(0 && "Enum tags not implemented yet!");
// If this has an identifier, add it to the scope stack.
if (Name) {
Modified: cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=39277&r1=39276&r2=39277&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def Wed Jul 11 11:42:22 2007
@@ -426,8 +426,8 @@
"use of undeclared identifier '%s'")
DIAG(err_redefinition, ERROR,
"redefinition of '%s'")
-DIAG(err_redefinition_with_wrong_tag, ERROR,
- "redefinition of '%s' with tag that does not match previous use")
+DIAG(err_use_with_wrong_tag, ERROR,
+ "use of '%s' with tag type that does not match previous declaration")
DIAG(warn_implicit_function_decl, WARNING,
"implicit declaration of function '%s'")
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=39277&r1=39276&r2=39277&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/Action.h Wed Jul 11 11:42:22 2007
@@ -140,9 +140,10 @@
return 0;
}
- virtual DeclTy *ParseStructUnionTag(Scope *S, bool isUnion, bool isUse,
- SourceLocation KWLoc,IdentifierInfo *Name,
- SourceLocation NameLoc) {
+ enum TagType { TAG_STRUCT, TAG_UNION, TAG_ENUM, TAG_CLASS };
+ virtual DeclTy *ParseTag(Scope *S, TagType Ty, bool isUse,
+ SourceLocation KWLoc, IdentifierInfo *Name,
+ SourceLocation NameLoc) {
return 0;
}
More information about the cfe-commits
mailing list