[cfe-commits] r41473 - in /cfe/trunk: Parse/ParseStmt.cpp Sema/SemaStmt.cpp test/Parser/extension.c
Chris Lattner
sabre at nondot.org
Sun Aug 26 18:01:57 PDT 2007
Author: lattner
Date: Sun Aug 26 20:01:57 2007
New Revision: 41473
URL: http://llvm.org/viewvc/llvm-project?rev=41473&view=rev
Log:
implement a fixme: __extension__ marker on decls in compound stmts.
Modified:
cfe/trunk/Parse/ParseStmt.cpp
cfe/trunk/Sema/SemaStmt.cpp
cfe/trunk/test/Parser/extension.c
Modified: cfe/trunk/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseStmt.cpp?rev=41473&r1=41472&r2=41473&view=diff
==============================================================================
--- cfe/trunk/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/Parse/ParseStmt.cpp Sun Aug 26 20:01:57 2007
@@ -354,7 +354,7 @@
///
/// block-item:
/// declaration
-/// [GNU] '__extension__' declaration [TODO]
+/// [GNU] '__extension__' declaration
/// statement
/// [OMP] openmp-directive [TODO]
///
@@ -392,11 +392,47 @@
SourceLocation LBraceLoc = ConsumeBrace(); // eat the '{'.
// TODO: "__label__ X, Y, Z;" is the GNU "Local Label" extension. These are
- // only allowed at the start of a compound stmt.
+ // only allowed at the start of a compound stmt regardless of the language.
llvm::SmallVector<StmtTy*, 32> Stmts;
while (Tok.getKind() != tok::r_brace && Tok.getKind() != tok::eof) {
- StmtResult R = ParseStatementOrDeclaration(false);
+ StmtResult R;
+ if (Tok.getKind() != tok::kw___extension__) {
+ R = ParseStatementOrDeclaration(false);
+ } else {
+ // __extension__ can start declarations and it can also be a unary
+ // operator for expressions. Consume multiple __extension__ markers here
+ // until we can determine which is which.
+ SourceLocation ExtLoc = ConsumeToken();
+ while (Tok.getKind() == tok::kw___extension__)
+ ConsumeToken();
+
+ // If this is the start of a declaration, parse it as such.
+ if (isDeclarationSpecifier()) {
+ // FIXME: Save the __extension__ on the decl as a node somehow.
+ // FIXME: disable extwarns.
+ R = Actions.ParseDeclStmt(ParseDeclaration(Declarator::BlockContext));
+ } else {
+ // Otherwise this was a unary __extension__ marker. Parse the
+ // subexpression and add the __extension__ unary op.
+ // FIXME: disable extwarns.
+ ExprResult Res = ParseCastExpression(false);
+ if (Res.isInvalid) {
+ SkipUntil(tok::semi);
+ continue;
+ }
+
+ // Add the __extension__ node to the AST.
+ Res = Actions.ParseUnaryOp(ExtLoc, tok::kw___extension__, Res.Val);
+ if (Res.isInvalid)
+ continue;
+
+ // Eat the semicolon at the end of stmt and convert the expr into a stmt.
+ ExpectAndConsume(tok::semi, diag::err_expected_semi_after_expr);
+ R = Actions.ParseExprStmt(Res.Val);
+ }
+ }
+
if (!R.isInvalid && R.Val)
Stmts.push_back(R.Val);
}
Modified: cfe/trunk/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaStmt.cpp?rev=41473&r1=41472&r2=41473&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/Sema/SemaStmt.cpp Sun Aug 26 20:01:57 2007
@@ -48,6 +48,10 @@
Action::StmtResult
Sema::ParseCompoundStmt(SourceLocation L, SourceLocation R,
StmtTy **Elts, unsigned NumElts) {
+ // FIXME: ISO C90 forbids mixed declarations and code
+ // Note that __extension__ can be around a decl.
+
+
return new CompoundStmt((Stmt**)Elts, NumElts);
}
Modified: cfe/trunk/test/Parser/extension.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/extension.c?rev=41473&r1=41472&r2=41473&view=diff
==============================================================================
--- cfe/trunk/test/Parser/extension.c (original)
+++ cfe/trunk/test/Parser/extension.c Sun Aug 26 20:01:57 2007
@@ -7,3 +7,11 @@
long long int quot;
long long int rem;
}lldiv_t;
+
+
+// Compound expr __extension__ marker.
+void bar() {
+ __extension__ int i;
+ int j;
+}
+
More information about the cfe-commits
mailing list