[cfe-commits] r56081 - in /cfe/trunk: include/clang/Parse/Parser.h lib/Parse/ParseDecl.cpp
Argiris Kirtzidis
akyrtzi at gmail.com
Wed Sep 10 17:21:42 PDT 2008
Author: akirtzidis
Date: Wed Sep 10 19:21:41 2008
New Revision: 56081
URL: http://llvm.org/viewvc/llvm-project?rev=56081&view=rev
Log:
Fold Parser::ParseTag into Parser::ParseEnumSpecifier, as suggested in this post:
http://lists.cs.uiuc.edu/pipermail/cfe-dev/2008-September/002721.html
Modified:
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Parse/ParseDecl.cpp
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=56081&r1=56080&r2=56081&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Wed Sep 10 19:21:41 2008
@@ -519,7 +519,6 @@
void ParseObjCTypeQualifierList(ObjCDeclSpec &DS);
- bool ParseTag(DeclTy *&Decl, unsigned TagType, SourceLocation StartLoc);
void ParseEnumSpecifier(DeclSpec &DS);
void ParseEnumBody(SourceLocation StartLoc, DeclTy *TagDecl);
void ParseStructUnionBody(SourceLocation StartLoc, unsigned TagType,
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=56081&r1=56080&r2=56081&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Wed Sep 10 19:21:41 2008
@@ -603,52 +603,6 @@
}
}
-/// ParseTag - Parse "struct-or-union-or-class-or-enum identifier[opt]", where
-/// the first token has already been read and has been turned into an instance
-/// of DeclSpec::TST (TagType). This returns true if there is an error parsing,
-/// otherwise it returns false and fills in Decl.
-bool Parser::ParseTag(DeclTy *&Decl, unsigned TagType, SourceLocation StartLoc){
- AttributeList *Attr = 0;
- // If attributes exist after tag, parse them.
- if (Tok.is(tok::kw___attribute))
- Attr = ParseAttributes();
-
- // Must have either 'struct name' or 'struct {...}'.
- if (Tok.isNot(tok::identifier) && Tok.isNot(tok::l_brace)) {
- Diag(Tok, diag::err_expected_ident_lbrace);
-
- // Skip the rest of this declarator, up until the comma or semicolon.
- SkipUntil(tok::comma, true);
- return true;
- }
-
- // If an identifier is present, consume and remember it.
- IdentifierInfo *Name = 0;
- SourceLocation NameLoc;
- if (Tok.is(tok::identifier)) {
- Name = Tok.getIdentifierInfo();
- NameLoc = ConsumeToken();
- }
-
- // 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 reference.
- //
- // 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.
- //
- Action::TagKind TK;
- if (Tok.is(tok::l_brace))
- TK = Action::TK_Definition;
- else if (Tok.is(tok::semi))
- TK = Action::TK_Declaration;
- else
- TK = Action::TK_Reference;
- Decl = Actions.ActOnTag(CurScope, TagType, TK, StartLoc, Name, NameLoc, Attr);
- return false;
-}
-
/// ParseStructDeclaration - Parse a struct declaration without the terminating
/// semicolon.
///
@@ -834,9 +788,46 @@
SourceLocation StartLoc = ConsumeToken();
// Parse the tag portion of this.
- DeclTy *TagDecl;
- if (ParseTag(TagDecl, DeclSpec::TST_enum, StartLoc))
+
+ AttributeList *Attr = 0;
+ // If attributes exist after tag, parse them.
+ if (Tok.is(tok::kw___attribute))
+ Attr = ParseAttributes();
+
+ // Must have either 'enum name' or 'enum {...}'.
+ if (Tok.isNot(tok::identifier) && Tok.isNot(tok::l_brace)) {
+ Diag(Tok, diag::err_expected_ident_lbrace);
+
+ // Skip the rest of this declarator, up until the comma or semicolon.
+ SkipUntil(tok::comma, true);
return;
+ }
+
+ // If an identifier is present, consume and remember it.
+ IdentifierInfo *Name = 0;
+ SourceLocation NameLoc;
+ if (Tok.is(tok::identifier)) {
+ Name = Tok.getIdentifierInfo();
+ NameLoc = ConsumeToken();
+ }
+
+ // There are three options here. If we have 'enum foo;', then this is a
+ // forward declaration. If we have 'enum foo {...' then this is a
+ // definition. Otherwise we have something like 'enum foo xyz', a reference.
+ //
+ // This is needed to handle stuff like this right (C99 6.7.2.3p11):
+ // enum foo {..}; void bar() { enum foo; } <- new foo in bar.
+ // enum foo {..}; void bar() { enum foo x; } <- use of old foo.
+ //
+ Action::TagKind TK;
+ if (Tok.is(tok::l_brace))
+ TK = Action::TK_Definition;
+ else if (Tok.is(tok::semi))
+ TK = Action::TK_Declaration;
+ else
+ TK = Action::TK_Reference;
+ DeclTy *TagDecl = Actions.ActOnTag(CurScope, DeclSpec::TST_enum, TK, StartLoc,
+ Name, NameLoc, Attr);
if (Tok.is(tok::l_brace))
ParseEnumBody(StartLoc, TagDecl);
More information about the cfe-commits
mailing list