[cfe-commits] r38842 - in /cfe/cfe/trunk: Parse/ParseDecl.cpp Parse/ParseStmt.cpp Parse/Parser.cpp clang.xcodeproj/project.pbxproj include/clang/Basic/DiagnosticKinds.def include/clang/Parse/Parser.h
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:25:06 PDT 2007
Author: sabre
Date: Wed Jul 11 11:25:06 2007
New Revision: 38842
URL: http://llvm.org/viewvc/llvm-project?rev=38842&view=rev
Log:
Start parsing statements and function bodies. This implements
Parser/statements.c:test1.
Added:
cfe/cfe/trunk/Parse/ParseStmt.cpp (with props)
Modified:
cfe/cfe/trunk/Parse/ParseDecl.cpp
cfe/cfe/trunk/Parse/Parser.cpp
cfe/cfe/trunk/clang.xcodeproj/project.pbxproj
cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def
cfe/cfe/trunk/include/clang/Parse/Parser.h
Modified: cfe/cfe/trunk/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseDecl.cpp?rev=38842&r1=38841&r2=38842&view=diff
==============================================================================
--- cfe/cfe/trunk/Parse/ParseDecl.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseDecl.cpp Wed Jul 11 11:25:06 2007
@@ -464,7 +464,7 @@
HasPrototype = false;
IsEmpty = true;
} else if (Tok.getKind() == tok::identifier &&
- 0/*TODO: !isatypedefname(Tok.getIdentifierInfo())*/) {
+ 1/*TODO: !isatypedefname(Tok.getIdentifierInfo())*/) {
// Identifier list. Note that '(' identifier-list ')' is only allowed for
// normal declarators, not for abstract-declarators.
assert(D.isPastIdentifier() && "Identifier (if present) must be passed!");
Added: cfe/cfe/trunk/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseStmt.cpp?rev=38842&view=auto
==============================================================================
--- cfe/cfe/trunk/Parse/ParseStmt.cpp (added)
+++ cfe/cfe/trunk/Parse/ParseStmt.cpp Wed Jul 11 11:25:06 2007
@@ -0,0 +1,124 @@
+//===--- Statement.cpp - Statement and Block Parser -----------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by Chris Lattner and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements the Statement and Block portions of the Parser
+// interface.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Parse/Parser.h"
+#include "clang/Basic/Diagnostic.h"
+using namespace llvm;
+using namespace clang;
+
+//===----------------------------------------------------------------------===//
+// C99 6.8: Statements and Blocks.
+//===----------------------------------------------------------------------===//
+
+/// ParseStatementOrDeclaration - Read 'statement' or 'declaration'.
+/// StatementOrDeclaration:
+/// statement
+/// declaration
+///
+/// statement:
+/// labeled-statement
+/// compound-statement
+/// expression-statement
+/// selection-statement
+/// iteration-statement
+/// jump-statement
+/// [OBC] objc-throw-statement [TODO]
+/// [OBC] objc-try-catch-statement [TODO]
+/// [OBC] objc-synchronized-statement [TODO]
+/// [GNU] asm-statement [TODO]
+/// [OMP] openmp-construct [TODO]
+///
+/// labeled-statement:
+/// identifier ':' statement
+/// 'case' constant-expression ':' statement
+/// 'default' ':' statement
+///
+/// expression-statement:
+/// expression[opt] ';'
+///
+/// selection-statement:
+/// if-statement
+/// switch-statement
+///
+/// iteration-statement:
+/// while-statement
+/// do-statement
+/// for-statement
+///
+/// jump-statement:
+/// 'goto' identifier ';'
+/// 'continue' ';'
+/// 'break' ';'
+/// 'return' expression[opt] ';'
+/// [GNU] 'goto' '*' expression ';' [TODO]
+///
+/// [OBC] objc-throw-statement: [TODO]
+/// [OBC] '@' 'throw' expression ';' [TODO]
+/// [OBC] '@' 'throw' ';' [TODO]
+///
+void Parser::ParseStatementOrDeclaration() {
+ switch (Tok.getKind()) {
+ default:
+ Diag(Tok, diag::err_expected_statement_declaration);
+ SkipUntil(tok::semi);
+ break;
+
+ case tok::semi: // expression[opt] ';' -> expression isn't present.
+ ConsumeToken();
+ break;
+ case tok::l_brace: // compound-statement -> '{}' block
+ ParseCompoundStatement();
+ break;
+ }
+}
+
+/// ParseCompoundStatement - Parse a "{}" block.
+///
+/// compound-statement: [C99 6.8.2]
+/// { block-item-list[opt] }
+/// [GNU] { label-declarations block-item-list } [TODO]
+///
+/// block-item-list:
+/// block-item
+/// block-item-list block-item
+///
+/// block-item:
+/// declaration
+/// [GNU] '__extension__' declaration [TODO]
+/// statement
+/// [OMP] openmp-directive [TODO]
+///
+/// [GNU] label-declarations:
+/// [GNU] label-declaration
+/// [GNU] label-declarations label-declaration
+///
+/// [GNU] label-declaration:
+/// [GNU] '__label__' identifier-list ';'
+///
+/// [OMP] openmp-directive: [TODO]
+/// [OMP] barrier-directive
+/// [OMP] flush-directive
+void Parser::ParseCompoundStatement() {
+ assert(Tok.getKind() == tok::l_brace && "Not a compount stmt!");
+ ConsumeBrace(); // eat the '{'.
+
+ while (Tok.getKind() != tok::r_brace && Tok.getKind() != tok::eof)
+ ParseStatementOrDeclaration();
+
+ // We broke out of the while loop because we found a '}' or EOF.
+ if (Tok.getKind() == tok::r_brace)
+ ConsumeBrace();
+ else
+ Diag(Tok, diag::err_expected_rbrace);
+}
Propchange: cfe/cfe/trunk/Parse/ParseStmt.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/cfe/trunk/Parse/ParseStmt.cpp
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: cfe/cfe/trunk/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/Parser.cpp?rev=38842&r1=38841&r2=38842&view=diff
==============================================================================
--- cfe/cfe/trunk/Parse/Parser.cpp (original)
+++ cfe/cfe/trunk/Parse/Parser.cpp Wed Jul 11 11:25:06 2007
@@ -318,7 +318,18 @@
// FIXME: Install the arguments into the current scope.
}
+ // We should have an opening brace now.
+ if (Tok.getKind() != tok::l_brace) {
+ Diag(Tok, diag::err_expected_fn_body);
+
+ // Skip over garbage, until we get to '{'. Don't eat the '{'.
+ SkipUntil(tok::l_brace, true, true);
+
+ // If we didn't find the '{', bail out.
+ if (Tok.getKind() != tok::l_brace)
+ return;
+ }
-
+ ParseCompoundStatement();
}
Modified: cfe/cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=38842&r1=38841&r2=38842&view=diff
==============================================================================
--- cfe/cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/cfe/trunk/clang.xcodeproj/project.pbxproj Wed Jul 11 11:25:06 2007
@@ -11,6 +11,7 @@
DE06BEC90A854E390050E87E /* Scope.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE06BEC80A854E390050E87E /* Scope.cpp */; };
DE06BECB0A854E4B0050E87E /* Scope.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE06BECA0A854E4B0050E87E /* Scope.h */; };
DE06BEF40A8558200050E87E /* Decl.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE06BEF30A8558200050E87E /* Decl.h */; };
+ DE06CC180A899E110050E87E /* Statement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE06CC170A899E110050E87E /* Statement.cpp */; };
DE1F22030A7D852A00FBF588 /* Parser.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE1F22020A7D852A00FBF588 /* Parser.h */; };
DE1F22200A7D879000FBF588 /* ParserActions.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE1F221F0A7D879000FBF588 /* ParserActions.h */; };
DE1F24700A7DC99000FBF588 /* Actions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE1F246D0A7DC99000FBF588 /* Actions.cpp */; };
@@ -114,6 +115,7 @@
DE06BEC80A854E390050E87E /* Scope.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = Scope.cpp; path = Parse/Scope.cpp; sourceTree = "<group>"; };
DE06BECA0A854E4B0050E87E /* Scope.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = Scope.h; path = clang/Parse/Scope.h; sourceTree = "<group>"; };
DE06BEF30A8558200050E87E /* Decl.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = Decl.h; path = clang/Parse/Decl.h; sourceTree = "<group>"; };
+ DE06CC170A899E110050E87E /* Statement.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = Statement.cpp; path = Parse/Statement.cpp; sourceTree = "<group>"; };
DE1F22020A7D852A00FBF588 /* Parser.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = Parser.h; path = clang/Parse/Parser.h; sourceTree = "<group>"; };
DE1F221F0A7D879000FBF588 /* ParserActions.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ParserActions.h; path = clang/Parse/ParserActions.h; sourceTree = "<group>"; };
DE1F246D0A7DC99000FBF588 /* Actions.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = Actions.cpp; path = Parse/Actions.cpp; sourceTree = "<group>"; };
@@ -228,6 +230,7 @@
DE1F246E0A7DC99000FBF588 /* Parse.cpp */,
DE1F246F0A7DC99000FBF588 /* ParseDeclarations.cpp */,
DE06BEC80A854E390050E87E /* Scope.cpp */,
+ DE06CC170A899E110050E87E /* Statement.cpp */,
);
name = Parse;
sourceTree = "<group>";
@@ -382,6 +385,7 @@
DE1F24720A7DC99000FBF588 /* ParseDeclarations.cpp in Sources */,
DE1F257B0A7DD86800FBF588 /* Declarations.cpp in Sources */,
DE06BEC90A854E390050E87E /* Scope.cpp in Sources */,
+ DE06CC180A899E110050E87E /* Statement.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
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=38842&r1=38841&r2=38842&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def Wed Jul 11 11:25:06 2007
@@ -264,12 +264,16 @@
"expected identifier or '('")
DIAG(err_expected_rparen, ERROR,
"expected ')'")
+DIAG(err_expected_rbrace, ERROR,
+ "expected '}' to end compound statement ('{}' block)")
DIAG(err_expected_semi_knr_fn_body, ERROR,
"expected ';' at end of K&R-style function argument declaration list")
DIAG(err_expected_fn_body, ERROR,
"expected function body after function declarator")
DIAG(err_expected_after_declarator, ERROR,
"expected '=', ',', ';', 'asm', or '__attribute__' after declarator")
+DIAG(err_expected_statement_declaration, ERROR,
+ "expected statement or declaration")
/// err_matching - this is used as a continuation of a previous error, e.g. to
/// specify the '(' when we expected a ')'. This should probably be some
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=38842&r1=38841&r2=38842&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/Parser.h Wed Jul 11 11:25:06 2007
@@ -155,7 +155,12 @@
void ParseExternalDeclaration();
void ParseDeclarationOrFunctionDefinition();
void ParseFunctionDefinition(Declarator &D);
-
+
+ //===--------------------------------------------------------------------===//
+ // C99 6.8: Statements and Blocks.
+ void ParseStatementOrDeclaration();
+ void ParseCompoundStatement();
+
//===--------------------------------------------------------------------===//
// C99 6.7: Declarations.
void ParseDeclarationSpecifiers(DeclSpec &DS);
More information about the cfe-commits
mailing list