aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Naroff <snaroff@apple.com>2007-08-31 23:49:30 +0000
committerSteve Naroff <snaroff@apple.com>2007-08-31 23:49:30 +0000
commit507f2d5811bd7da1a4d9d2f4960f32177dfab9de (patch)
treeb623fba3c79afbadcd80d760dd706e42bbbc9d3a
parentb5a69586f1b8855ee4c1f0bb7a8f0ff4fe32ce09 (diff)
Convert more statments over to SourceRanges...
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41666 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--AST/Stmt.cpp8
-rw-r--r--Sema/SemaStmt.cpp12
-rw-r--r--include/clang/AST/Stmt.h30
3 files changed, 33 insertions, 17 deletions
diff --git a/AST/Stmt.cpp b/AST/Stmt.cpp
index 17f59a48d0..9b405f1e23 100644
--- a/AST/Stmt.cpp
+++ b/AST/Stmt.cpp
@@ -81,6 +81,14 @@ const char *LabelStmt::getName() const {
return getID()->getName();
}
+// This is defined here to avoid polluting Stmt.h with importing Expr.h
+SourceRange ReturnStmt::getSourceRange() const {
+ if (RetExpr)
+ return SourceRange(RetLoc, RetExpr->getLocEnd());
+ else
+ return SourceRange(RetLoc);
+}
+
//===----------------------------------------------------------------------===//
// Child Iterators for iterating over subexpressions/substatements
//===----------------------------------------------------------------------===//
diff --git a/Sema/SemaStmt.cpp b/Sema/SemaStmt.cpp
index 1c26202c76..87d5e26298 100644
--- a/Sema/SemaStmt.cpp
+++ b/Sema/SemaStmt.cpp
@@ -506,7 +506,7 @@ Sema::ParseGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
if (LabelDecl == 0)
LabelDecl = new LabelStmt(LabelLoc, LabelII, 0);
- return new GotoStmt(LabelDecl);
+ return new GotoStmt(LabelDecl, GotoLoc);
}
Action::StmtResult
@@ -526,7 +526,7 @@ Sema::ParseContinueStmt(SourceLocation ContinueLoc, Scope *CurScope) {
return true;
}
- return new ContinueStmt();
+ return new ContinueStmt(ContinueLoc);
}
Action::StmtResult
@@ -538,7 +538,7 @@ Sema::ParseBreakStmt(SourceLocation BreakLoc, Scope *CurScope) {
return true;
}
- return new BreakStmt();
+ return new BreakStmt(BreakLoc);
}
@@ -552,7 +552,7 @@ Sema::ParseReturnStmt(SourceLocation ReturnLoc, ExprTy *rex) {
Diag(ReturnLoc, diag::ext_return_has_expr,
CurFunctionDecl->getIdentifier()->getName(),
RetValExp->getSourceRange());
- return new ReturnStmt(RetValExp);
+ return new ReturnStmt(ReturnLoc, RetValExp);
} else {
if (!RetValExp) {
const char *funcName = CurFunctionDecl->getIdentifier()->getName();
@@ -560,7 +560,7 @@ Sema::ParseReturnStmt(SourceLocation ReturnLoc, ExprTy *rex) {
Diag(ReturnLoc, diag::ext_return_missing_expr, funcName);
else // C90 6.6.6.4p4
Diag(ReturnLoc, diag::warn_return_missing_expr, funcName);
- return new ReturnStmt((Expr*)0);
+ return new ReturnStmt(ReturnLoc, (Expr*)0);
}
}
// we have a non-void function with an expression, continue checking
@@ -608,6 +608,6 @@ Sema::ParseReturnStmt(SourceLocation ReturnLoc, ExprTy *rex) {
if (RetValExp) CheckReturnStackAddr(RetValExp, lhsType, ReturnLoc);
- return new ReturnStmt((Expr*)RetValExp);
+ return new ReturnStmt(ReturnLoc, (Expr*)RetValExp);
}
diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h
index 35f4bf57e6..aae088a512 100644
--- a/include/clang/AST/Stmt.h
+++ b/include/clang/AST/Stmt.h
@@ -153,7 +153,7 @@ public:
SourceLocation getSemiLoc() const { return SemiLoc; }
- virtual SourceRange getSourceRange() const { return SourceRange(); }
+ virtual SourceRange getSourceRange() const { return SourceRange(SemiLoc); }
static bool classof(const Stmt *T) {
return T->getStmtClass() == NullStmtClass;
@@ -520,13 +520,16 @@ public:
///
class GotoStmt : public Stmt {
LabelStmt *Label;
+ SourceLocation GotoLoc;
public:
- GotoStmt(LabelStmt *label) : Stmt(GotoStmtClass), Label(label) {}
+ GotoStmt(LabelStmt *label, SourceLocation GL) : Stmt(GotoStmtClass),
+ Label(label), GotoLoc(GL) {}
LabelStmt *getLabel() const { return Label; }
- virtual SourceRange getSourceRange() const { return SourceRange(); }
-
+ virtual SourceRange getSourceRange() const {
+ return SourceRange(GotoLoc, Label->getLocEnd());
+ }
static bool classof(const Stmt *T) {
return T->getStmtClass() == GotoStmtClass;
}
@@ -563,11 +566,13 @@ public:
/// ContinueStmt - This represents a continue.
///
class ContinueStmt : public Stmt {
+ SourceLocation ContinueLoc;
public:
- ContinueStmt() : Stmt(ContinueStmtClass) {}
+ ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass), ContinueLoc(CL) {}
- virtual SourceRange getSourceRange() const { return SourceRange(); }
-
+ virtual SourceRange getSourceRange() const {
+ return SourceRange(ContinueLoc);
+ }
static bool classof(const Stmt *T) {
return T->getStmtClass() == ContinueStmtClass;
}
@@ -581,10 +586,11 @@ public:
/// BreakStmt - This represents a break.
///
class BreakStmt : public Stmt {
+ SourceLocation BreakLoc;
public:
- BreakStmt() : Stmt(BreakStmtClass) {}
+ BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass), BreakLoc(BL) {}
- virtual SourceRange getSourceRange() const { return SourceRange(); }
+ virtual SourceRange getSourceRange() const { return SourceRange(BreakLoc); }
static bool classof(const Stmt *T) {
return T->getStmtClass() == BreakStmtClass;
@@ -601,13 +607,15 @@ public:
///
class ReturnStmt : public Stmt {
Expr *RetExpr;
+ SourceLocation RetLoc;
public:
- ReturnStmt(Expr *E = 0) : Stmt(ReturnStmtClass), RetExpr(E) {}
+ ReturnStmt(SourceLocation RL, Expr *E = 0) : Stmt(ReturnStmtClass),
+ RetExpr(E), RetLoc(RL) {}
const Expr *getRetValue() const { return RetExpr; }
Expr *getRetValue() { return RetExpr; }
- virtual SourceRange getSourceRange() const { return SourceRange(); }
+ virtual SourceRange getSourceRange() const;
static bool classof(const Stmt *T) {
return T->getStmtClass() == ReturnStmtClass;