[cfe-commits] r68009 - in /cfe/trunk: include/clang/Basic/DiagnosticParseKinds.td lib/Parse/ParseDecl.cpp lib/Parse/Parser.cpp test/Parser/typeof.c test/Sema/init.c
Chris Lattner
sabre at nondot.org
Sun Mar 29 10:18:04 PDT 2009
Author: lattner
Date: Sun Mar 29 12:18:04 2009
New Revision: 68009
URL: http://llvm.org/viewvc/llvm-project?rev=68009&view=rev
Log:
hoist checks for ; and in out of ParseInitDeclaratorListAfterFirstDeclarator
into ParseSimpleDeclaration, and improve a diagnostic.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/Parser.cpp
cfe/trunk/test/Parser/typeof.c
cfe/trunk/test/Sema/init.c
Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=68009&r1=68008&r2=68009&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Sun Mar 29 12:18:04 2009
@@ -78,6 +78,8 @@
def err_expected_rsquare : Error<"expected ']'">;
def err_expected_rbrace : Error<"expected '}'">;
def err_expected_greater : Error<"expected '>'">;
+def err_expected_semi_declation : Error<
+ "expected ';' at end of declaration">;
def err_expected_semi_decl_list : Error<
"expected ';' at end of declaration list">;
def ext_expected_semi_decl_list : Extension<
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=68009&r1=68008&r2=68009&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Sun Mar 29 12:18:04 2009
@@ -273,7 +273,30 @@
Declarator DeclaratorInfo(DS, (Declarator::TheContext)Context);
ParseDeclarator(DeclaratorInfo);
- return ParseInitDeclaratorListAfterFirstDeclarator(DeclaratorInfo);
+ DeclGroupPtrTy DG =
+ ParseInitDeclaratorListAfterFirstDeclarator(DeclaratorInfo);
+
+ if (Tok.is(tok::semi)) {
+ ConsumeToken();
+ // for(is key; in keys) is error.
+ if (Context == Declarator::ForContext && isTokIdentifier_in())
+ Diag(Tok, diag::err_parse_error);
+
+ return DG;
+ }
+
+ // If this is an ObjC2 for-each loop, this is a successful declarator
+ // parse. The syntax for these looks like:
+ // 'for' '(' declaration 'in' expr ')' statement
+ if (Context == Declarator::ForContext && isTokIdentifier_in())
+ return DG;
+
+ Diag(Tok, diag::err_expected_semi_declation);
+ // Skip to end of block or statement
+ SkipUntil(tok::r_brace, true, true);
+ if (Tok.is(tok::semi))
+ ConsumeToken();
+ return DG;
}
@@ -315,7 +338,7 @@
SourceLocation Loc;
OwningExprResult AsmLabel(ParseSimpleAsm(&Loc));
if (AsmLabel.isInvalid()) {
- SkipUntil(tok::semi);
+ SkipUntil(tok::semi, true, true);
return DeclGroupPtrTy();
}
@@ -343,7 +366,7 @@
} else {
OwningExprResult Init(ParseInitializer());
if (Init.isInvalid()) {
- SkipUntil(tok::semi);
+ SkipUntil(tok::semi, true, true);
return DeclGroupPtrTy();
}
Actions.AddInitializerToDecl(ThisDecl, move(Init));
@@ -400,31 +423,8 @@
ParseDeclarator(D);
}
- if (Tok.is(tok::semi)) {
- ConsumeToken();
- // for(is key; in keys) is error.
- if (D.getContext() == Declarator::ForContext && isTokIdentifier_in()) {
- Diag(Tok, diag::err_parse_error);
- return DeclGroupPtrTy();
- }
-
- return Actions.FinalizeDeclaratorGroup(CurScope, &DeclsInGroup[0],
- DeclsInGroup.size());
- }
-
- // If this is an ObjC2 for-each loop, this is a successful declarator
- // parse. The syntax for these looks like:
- // 'for' '(' declaration 'in' expr ')' statement
- if (D.getContext() == Declarator::ForContext && isTokIdentifier_in())
- return Actions.FinalizeDeclaratorGroup(CurScope, &DeclsInGroup[0],
- DeclsInGroup.size());
-
- Diag(Tok, diag::err_parse_error);
- // Skip to end of block or statement
- SkipUntil(tok::r_brace, true, true);
- if (Tok.is(tok::semi))
- ConsumeToken();
- return DeclGroupPtrTy();
+ return Actions.FinalizeDeclaratorGroup(CurScope, &DeclsInGroup[0],
+ DeclsInGroup.size());
}
/// ParseSpecifierQualifierList
Modified: cfe/trunk/lib/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=68009&r1=68008&r2=68009&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/Parser.cpp (original)
+++ cfe/trunk/lib/Parse/Parser.cpp Sun Mar 29 12:18:04 2009
@@ -517,9 +517,13 @@
Tok.is(tok::kw_asm) || // int X() __asm__ -> not a function def
Tok.is(tok::kw___attribute) || // int X() __attr__ -> not a function def
(getLang().CPlusPlus &&
- Tok.is(tok::l_paren)) ) { // int X(0) -> not a function def [C++]
+ Tok.is(tok::l_paren))) { // int X(0) -> not a function def [C++]
// Parse the init-declarator-list for a normal declaration.
- return ParseInitDeclaratorListAfterFirstDeclarator(DeclaratorInfo);
+ DeclGroupPtrTy DG =
+ ParseInitDeclaratorListAfterFirstDeclarator(DeclaratorInfo);
+ // Eat the semi colon after the declaration.
+ ExpectAndConsume(tok::semi, diag::err_expected_semi_declation);
+ return DG;
}
@@ -564,7 +568,8 @@
/// [C90] function-definition: [C99 6.7.1] - implicit int result
/// [C90] decl-specs[opt] declarator declaration-list[opt] compound-statement
/// [C++] function-definition: [C++ 8.4]
-/// decl-specifier-seq[opt] declarator ctor-initializer[opt] function-body
+/// decl-specifier-seq[opt] declarator ctor-initializer[opt]
+/// function-body
/// [C++] function-definition: [C++ 8.4]
/// decl-specifier-seq[opt] declarator function-try-block [TODO]
///
Modified: cfe/trunk/test/Parser/typeof.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/typeof.c?rev=68009&r1=68008&r2=68009&view=diff
==============================================================================
--- cfe/trunk/test/Parser/typeof.c (original)
+++ cfe/trunk/test/Parser/typeof.c Sun Mar 29 12:18:04 2009
@@ -9,8 +9,8 @@
short typeof (int) aShortInt; // expected-error{{'short typeof' is invalid}}
int int ttt; // expected-error{{cannot combine with previous 'int' declaration specifier}}
typeof(TInt) anInt;
- short TInt eee; // expected-error{{parse error}}
- void ary[7] fff; // expected-error{{array has incomplete element type 'void'}} expected-error{{parse error}}
+ short TInt eee; // expected-error{{expected ';' at end of declaration}}
+ void ary[7] fff; // expected-error{{array has incomplete element type 'void'}} expected-error{{expected ';' at end of declaration}}
typeof(void ary[7]) anIntError; // expected-error{{expected ')'}} expected-note {{to match this '('}} expected-warning {{type specifier missing, defaults to 'int'}}
typeof(const int) aci;
const typeof (*pi) aConstInt;
Modified: cfe/trunk/test/Sema/init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/init.c?rev=68009&r1=68008&r2=68009&view=diff
==============================================================================
--- cfe/trunk/test/Sema/init.c (original)
+++ cfe/trunk/test/Sema/init.c Sun Mar 29 12:18:04 2009
@@ -20,7 +20,7 @@
int test() {
int a[10];
int b[10] = a; // expected-error {{initialization with '{...}' expected}}
-int +; // expected-error {{expected identifier or '('}} expected-error {{parse error}}
+int +; // expected-error {{expected identifier or '('}} expected-error {{expected ';' at end of declaration}}
}
More information about the cfe-commits
mailing list