[cfe-commits] r38852 - in /cfe/cfe/trunk: Parse/ParseStmt.cpp include/clang/Basic/DiagnosticKinds.def include/clang/Parse/Parser.h test/Parser/statements.c
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:25:11 PDT 2007
Author: sabre
Date: Wed Jul 11 11:25:11 2007
New Revision: 38852
URL: http://llvm.org/viewvc/llvm-project?rev=38852&view=rev
Log:
Add support for parsing declarations in blocks. This implements
Parser/statements.c:test4
Modified:
cfe/cfe/trunk/Parse/ParseStmt.cpp
cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def
cfe/cfe/trunk/include/clang/Parse/Parser.h
cfe/cfe/trunk/test/Parser/statements.c
Modified: cfe/cfe/trunk/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseStmt.cpp?rev=38852&r1=38851&r2=38852&view=diff
==============================================================================
--- cfe/cfe/trunk/Parse/ParseStmt.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseStmt.cpp Wed Jul 11 11:25:11 2007
@@ -76,10 +76,23 @@
// the token to end in a semicolon (in which case SemiError should be set),
// or they directly 'return;' if not.
switch (Tok.getKind()) {
+ case tok::identifier: // C99 6.8.1: labeled-statement
+ // identifier ':' statement
+ // declaration (if !OnlyStatement)
+ // expression[opt] ';'
+ return ParseIdentifierStatement(OnlyStatement);
+
default:
- Diag(Tok, OnlyStatement ? diag::err_expected_statement :
- diag::err_expected_statement_declaration);
- SkipUntil(tok::semi);
+ if (!OnlyStatement && isDeclarationSpecifier()) {
+ // TODO: warn/disable if declaration is in the middle of a block and !C99.
+ ParseDeclaration(Declarator::BlockContext);
+ return;
+ } else if (Tok.getKind() == tok::r_brace) {
+ Diag(Tok, diag::err_expected_statement);
+ } else {
+ // expression[opt] ';'
+ ParseExpression();
+ }
return;
case tok::kw_case: // C99 6.8.1: labeled-statement
@@ -140,8 +153,6 @@
ParseReturnStatement();
SemiError = "return statement";
break;
-
- // TODO: Handle OnlyStatement..
}
// If we reached this code, the statement must end in a semicolon.
@@ -153,6 +164,17 @@
}
}
+/// ParseIdentifierStatement - Because we don't have two-token lookahead, we
+/// have a bit of a quandry here. Reading the identifier is necessary to see if
+/// there is a ':' after it. If there is, this is a label, regardless of what
+/// else the identifier can mean. If not, this is either part of a declaration
+/// (if the identifier is a type-name) or part of an expression.
+void Parser::ParseIdentifierStatement(bool OnlyStatement) {
+
+ assert(0);
+
+}
+
/// ParseCaseStatement
/// labeled-statement:
/// 'case' constant-expression ':' statement
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=38852&r1=38851&r2=38852&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def Wed Jul 11 11:25:11 2007
@@ -278,8 +278,6 @@
"expected '=', ',', ';', 'asm', or '__attribute__' after declarator")
DIAG(err_expected_statement, ERROR,
"expected statement")
-DIAG(err_expected_statement_declaration, ERROR,
- "expected statement or declaration")
DIAG(err_expected_lparen_after, ERROR,
"expected '(' after '%s'")
DIAG(err_expected_while, ERROR,
Modified: cfe/cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Parse/Parser.h?rev=38852&r1=38851&r2=38852&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/Parser.h Wed Jul 11 11:25:11 2007
@@ -160,6 +160,7 @@
// C99 6.8: Statements and Blocks.
void ParseStatement() { ParseStatementOrDeclaration(true); }
void ParseStatementOrDeclaration(bool OnlyStatement = false);
+ void ParseIdentifierStatement(bool OnlyStatement);
void ParseCaseStatement();
void ParseDefaultStatement();
void ParseCompoundStatement();
Modified: cfe/cfe/trunk/test/Parser/statements.c
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/test/Parser/statements.c?rev=38852&r1=38851&r2=38852&view=diff
==============================================================================
--- cfe/cfe/trunk/test/Parser/statements.c (original)
+++ cfe/cfe/trunk/test/Parser/statements.c Wed Jul 11 11:25:11 2007
@@ -29,3 +29,11 @@
;
}
}
+
+int test4() {
+ if (0);
+
+ int X; // declaration in a block.
+
+ if (0);
+}
More information about the cfe-commits
mailing list