mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-25 18:36:05 +00:00
Start parsing statements and function bodies. This implements
Parser/statements.c:test1. llvm-svn: 38842
This commit is contained in:
parent
fff824fe14
commit
0ccd51ebe2
@ -464,7 +464,7 @@ void Parser::ParseParenDeclarator(Declarator &D) {
|
||||
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!");
|
||||
|
124
clang/Parse/ParseStmt.cpp
Normal file
124
clang/Parse/ParseStmt.cpp
Normal file
@ -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);
|
||||
}
|
@ -318,7 +318,18 @@ void Parser::ParseFunctionDefinition(Declarator &D) {
|
||||
// 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();
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -264,12 +264,16 @@ DIAG(err_expected_ident_lparen, ERROR,
|
||||
"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
|
||||
|
@ -155,7 +155,12 @@ private:
|
||||
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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user