move semantic analysis of break/continue out of the parser into the sema class.

llvm-svn: 39157
This commit is contained in:
Chris Lattner 2006-11-10 05:17:58 +00:00
parent af8d581230
commit eaafe122b6
8 changed files with 78 additions and 32 deletions

View File

@ -22,6 +22,15 @@
using namespace llvm;
using namespace clang;
//===----------------------------------------------------------------------===//
// Helper functions.
//===----------------------------------------------------------------------===//
void Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg) {
PP.Diag(Loc, DiagID, Msg);
}
//===----------------------------------------------------------------------===//
// Symbol table tracking callbacks.
//===----------------------------------------------------------------------===//

View File

@ -17,6 +17,7 @@
#include "clang/Parse/Action.h"
#include <vector>
#include <string>
namespace llvm {
namespace clang {
@ -36,6 +37,9 @@ public:
Sema(Preprocessor &pp, std::vector<Decl*> &prevInGroup)
: PP(pp), LastInGroupList(prevInGroup) {}
void Diag(SourceLocation Loc, unsigned DiagID,
const std::string &Msg = std::string());
//===--------------------------------------------------------------------===//
// Symbol table tracking callbacks.
//
@ -81,8 +85,9 @@ public:
virtual StmtResult ParseIndirectGotoStmt(SourceLocation GotoLoc,
SourceLocation StarLoc,
ExprTy *DestExp);
virtual StmtResult ParseContinueStmt(SourceLocation ContinueLoc);
virtual StmtResult ParseBreakStmt(SourceLocation GotoLoc);
virtual StmtResult ParseContinueStmt(SourceLocation ContinueLoc,
Scope *CurScope);
virtual StmtResult ParseBreakStmt(SourceLocation GotoLoc, Scope *CurScope);
virtual StmtResult ParseReturnStmt(SourceLocation ReturnLoc,
ExprTy *RetValExp);

View File

@ -13,6 +13,8 @@
#include "Sema.h"
#include "clang/AST/Stmt.h"
#include "clang/Parse/Scope.h"
#include "clang/Basic/Diagnostic.h"
using namespace llvm;
using namespace clang;
@ -89,12 +91,28 @@ Sema::ParseIndirectGotoStmt(SourceLocation GotoLoc,SourceLocation StarLoc,
}
Action::StmtResult
Sema::ParseContinueStmt(SourceLocation ContinueLoc) {
Sema::ParseContinueStmt(SourceLocation ContinueLoc, Scope *CurScope) {
Scope *S = CurScope->getContinueParent();
if (!S) {
// C99 6.8.6.2p1: A break shall appear only in or as a loop body.
Diag(ContinueLoc, diag::err_continue_not_in_loop);
return true;
}
// FIXME: Remember that this continue goes with this loop.
return new ContinueStmt();
}
Action::StmtResult
Sema::ParseBreakStmt(SourceLocation GotoLoc) {
Sema::ParseBreakStmt(SourceLocation BreakLoc, Scope *CurScope) {
Scope *S = CurScope->getBreakParent();
if (!S) {
// C99 6.8.6.3p1: A break shall appear only in or as a switch/loop body.
Diag(BreakLoc, diag::err_break_not_in_loop_or_switch);
return true;
}
// FIXME: Remember that this break goes with this loop/switch.
return new BreakStmt();
}

View File

@ -660,17 +660,7 @@ Parser::StmtResult Parser::ParseGotoStatement() {
///
Parser::StmtResult Parser::ParseContinueStatement() {
SourceLocation ContinueLoc = ConsumeToken(); // eat the 'continue'.
Scope *S = CurScope->getContinueParent();
if (!S) {
// C99 6.8.6.2p1: A break shall appear only in or as a loop body.
Diag(ContinueLoc, diag::err_continue_not_in_loop);
return true;
}
// FIXME: Remember that this continue goes with this loop.
return Actions.ParseContinueStmt(ContinueLoc);
return Actions.ParseContinueStmt(ContinueLoc, CurScope);
}
/// ParseBreakStatement
@ -681,16 +671,7 @@ Parser::StmtResult Parser::ParseContinueStatement() {
///
Parser::StmtResult Parser::ParseBreakStatement() {
SourceLocation BreakLoc = ConsumeToken(); // eat the 'break'.
Scope *S = CurScope->getBreakParent();
if (!S) {
// C99 6.8.6.3p1: A break shall appear only in or as a switch/loop body.
Diag(BreakLoc, diag::err_break_not_in_loop_or_switch);
return true;
}
// FIXME: Remember that this break goes with this loop/switch.
return Actions.ParseBreakStmt(BreakLoc);
return Actions.ParseBreakStmt(BreakLoc, CurScope);
}
/// ParseReturnStatement

View File

@ -22,6 +22,15 @@
using namespace llvm;
using namespace clang;
//===----------------------------------------------------------------------===//
// Helper functions.
//===----------------------------------------------------------------------===//
void Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg) {
PP.Diag(Loc, DiagID, Msg);
}
//===----------------------------------------------------------------------===//
// Symbol table tracking callbacks.
//===----------------------------------------------------------------------===//

View File

@ -17,6 +17,7 @@
#include "clang/Parse/Action.h"
#include <vector>
#include <string>
namespace llvm {
namespace clang {
@ -36,6 +37,9 @@ public:
Sema(Preprocessor &pp, std::vector<Decl*> &prevInGroup)
: PP(pp), LastInGroupList(prevInGroup) {}
void Diag(SourceLocation Loc, unsigned DiagID,
const std::string &Msg = std::string());
//===--------------------------------------------------------------------===//
// Symbol table tracking callbacks.
//
@ -81,8 +85,9 @@ public:
virtual StmtResult ParseIndirectGotoStmt(SourceLocation GotoLoc,
SourceLocation StarLoc,
ExprTy *DestExp);
virtual StmtResult ParseContinueStmt(SourceLocation ContinueLoc);
virtual StmtResult ParseBreakStmt(SourceLocation GotoLoc);
virtual StmtResult ParseContinueStmt(SourceLocation ContinueLoc,
Scope *CurScope);
virtual StmtResult ParseBreakStmt(SourceLocation GotoLoc, Scope *CurScope);
virtual StmtResult ParseReturnStmt(SourceLocation ReturnLoc,
ExprTy *RetValExp);

View File

@ -13,6 +13,8 @@
#include "Sema.h"
#include "clang/AST/Stmt.h"
#include "clang/Parse/Scope.h"
#include "clang/Basic/Diagnostic.h"
using namespace llvm;
using namespace clang;
@ -89,12 +91,28 @@ Sema::ParseIndirectGotoStmt(SourceLocation GotoLoc,SourceLocation StarLoc,
}
Action::StmtResult
Sema::ParseContinueStmt(SourceLocation ContinueLoc) {
Sema::ParseContinueStmt(SourceLocation ContinueLoc, Scope *CurScope) {
Scope *S = CurScope->getContinueParent();
if (!S) {
// C99 6.8.6.2p1: A break shall appear only in or as a loop body.
Diag(ContinueLoc, diag::err_continue_not_in_loop);
return true;
}
// FIXME: Remember that this continue goes with this loop.
return new ContinueStmt();
}
Action::StmtResult
Sema::ParseBreakStmt(SourceLocation GotoLoc) {
Sema::ParseBreakStmt(SourceLocation BreakLoc, Scope *CurScope) {
Scope *S = CurScope->getBreakParent();
if (!S) {
// C99 6.8.6.3p1: A break shall appear only in or as a switch/loop body.
Diag(BreakLoc, diag::err_break_not_in_loop_or_switch);
return true;
}
// FIXME: Remember that this break goes with this loop/switch.
return new BreakStmt();
}

View File

@ -181,14 +181,15 @@ public:
ExprTy *DestExp) {
return 0;
}
virtual StmtResult ParseContinueStmt(SourceLocation ContinueLoc) {
virtual StmtResult ParseContinueStmt(SourceLocation ContinueLoc,
Scope *CurScope) {
return 0;
}
virtual StmtResult ParseBreakStmt(SourceLocation GotoLoc) {
virtual StmtResult ParseBreakStmt(SourceLocation GotoLoc, Scope *CurScope) {
return 0;
}
virtual StmtResult ParseReturnStmt(SourceLocation ReturnLoc,
ExprTy *RetValExp) {
ExprTy *RetValExp) {
return 0;
}