[cfe-commits] r39453 - in /cfe/cfe/trunk: AST/Expr.cpp AST/SemaExpr.cpp AST/SemaExprCXX.cpp Sema/SemaExpr.cpp Sema/SemaExprCXX.cpp include/clang/AST/Expr.h include/clang/AST/ExprCXX.h include/clang/Basic/SourceLocation.h
Steve Naroff
snaroff at apple.com
Wed Jul 11 09:44:36 PDT 2007
Author: snaroff
Date: Wed Jul 11 11:44:36 2007
New Revision: 39453
URL: http://llvm.org/viewvc/llvm-project?rev=39453&view=rev
Log:
Bug #:
Submitted by:
Reviewed by:
Refinements to the SourceRange/SourceLocation work.
- Renamed Expr::getSourceLocation() helper function to getLocStart(). Added
Expr::getLocEnd(). Converted all the getSourceRange() methods to use the new helpers.
- Removed many getSourceLocation() accessors. The Expr::getLocStart() helper
is the "right" way to get a source location. If we want to add class specific
getters (for location), then the names should be reflective of the specific class.
For examaple, UnaryOperator::getOpLocation(). For now, I see no reason to have these.
- Fixed StringLiteral.
- Start actually instantiating ParenExpr()!
Modified:
cfe/cfe/trunk/AST/Expr.cpp
cfe/cfe/trunk/AST/SemaExpr.cpp
cfe/cfe/trunk/AST/SemaExprCXX.cpp
cfe/cfe/trunk/Sema/SemaExpr.cpp
cfe/cfe/trunk/Sema/SemaExprCXX.cpp
cfe/cfe/trunk/include/clang/AST/Expr.h
cfe/cfe/trunk/include/clang/AST/ExprCXX.h
cfe/cfe/trunk/include/clang/Basic/SourceLocation.h
Modified: cfe/cfe/trunk/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Expr.cpp?rev=39453&r1=39452&r2=39453&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/Expr.cpp (original)
+++ cfe/cfe/trunk/AST/Expr.cpp Wed Jul 11 11:44:36 2007
@@ -22,7 +22,8 @@
//===----------------------------------------------------------------------===//
StringLiteral::StringLiteral(const char *strData, unsigned byteLength,
- bool Wide, QualType t, SourceLocation l) :
+ bool Wide, QualType t, SourceLocation firstLoc,
+ SourceLocation lastLoc) :
Expr(StringLiteralClass, t) {
// OPTIMIZE: could allocate this appended to the StringLiteral.
char *AStrData = new char[byteLength];
@@ -30,7 +31,8 @@
StrData = AStrData;
ByteLength = byteLength;
IsWide = Wide;
- Loc = l;
+ firstTokLoc = firstLoc;
+ lastTokLoc = lastLoc;
}
StringLiteral::~StringLiteral() {
Modified: cfe/cfe/trunk/AST/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/SemaExpr.cpp?rev=39453&r1=39452&r2=39453&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/SemaExpr.cpp (original)
+++ cfe/cfe/trunk/AST/SemaExpr.cpp Wed Jul 11 11:44:36 2007
@@ -56,7 +56,8 @@
// FIXME: use factory.
// Pass &StringTokLocs[0], StringTokLocs.size() to factory!
return new StringLiteral(Literal.GetString(), Literal.GetStringLength(),
- Literal.AnyWide, t, SourceLocation()/*FIXME*/);
+ Literal.AnyWide, t, StringToks[0].getLocation(),
+ StringToks[NumStringToks-1].getLocation());
}
@@ -169,7 +170,7 @@
ExprTy *Val) {
Expr *e = (Expr *)Val;
assert((e != 0) && "ParseParenExpr() missing expr");
- return e;
+ return new ParenExpr(L, R, e);
}
/// The UsualUnaryConversion() function is *not* called by this routine.
@@ -405,7 +406,7 @@
// first, check the condition.
if (!cond->isScalarType()) { // C99 6.5.15p2
- Diag(Cond->getSourceLocation(), diag::err_typecheck_cond_expect_scalar,
+ Diag(Cond->getLocStart(), diag::err_typecheck_cond_expect_scalar,
cond.getAsString());
return QualType();
}
Modified: cfe/cfe/trunk/AST/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/SemaExprCXX.cpp?rev=39453&r1=39452&r2=39453&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/SemaExprCXX.cpp (original)
+++ cfe/cfe/trunk/AST/SemaExprCXX.cpp Wed Jul 11 11:44:36 2007
@@ -38,8 +38,8 @@
/// ParseCXXBoolLiteral - Parse {true,false} literals.
Action::ExprResult
-Sema::ParseCXXBoolLiteral(SourceLocation, tok::TokenKind Kind) {
+Sema::ParseCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind) {
assert((Kind != tok::kw_true || Kind != tok::kw_false) &&
"Unknown C++ Boolean value!");
- return new CXXBoolLiteralExpr(Kind == tok::kw_true);
+ return new CXXBoolLiteralExpr(Kind == tok::kw_true, OpLoc);
}
Modified: cfe/cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/SemaExpr.cpp?rev=39453&r1=39452&r2=39453&view=diff
==============================================================================
--- cfe/cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaExpr.cpp Wed Jul 11 11:44:36 2007
@@ -56,7 +56,8 @@
// FIXME: use factory.
// Pass &StringTokLocs[0], StringTokLocs.size() to factory!
return new StringLiteral(Literal.GetString(), Literal.GetStringLength(),
- Literal.AnyWide, t, SourceLocation()/*FIXME*/);
+ Literal.AnyWide, t, StringToks[0].getLocation(),
+ StringToks[NumStringToks-1].getLocation());
}
@@ -169,7 +170,7 @@
ExprTy *Val) {
Expr *e = (Expr *)Val;
assert((e != 0) && "ParseParenExpr() missing expr");
- return e;
+ return new ParenExpr(L, R, e);
}
/// The UsualUnaryConversion() function is *not* called by this routine.
@@ -405,7 +406,7 @@
// first, check the condition.
if (!cond->isScalarType()) { // C99 6.5.15p2
- Diag(Cond->getSourceLocation(), diag::err_typecheck_cond_expect_scalar,
+ Diag(Cond->getLocStart(), diag::err_typecheck_cond_expect_scalar,
cond.getAsString());
return QualType();
}
Modified: cfe/cfe/trunk/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/SemaExprCXX.cpp?rev=39453&r1=39452&r2=39453&view=diff
==============================================================================
--- cfe/cfe/trunk/Sema/SemaExprCXX.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaExprCXX.cpp Wed Jul 11 11:44:36 2007
@@ -38,8 +38,8 @@
/// ParseCXXBoolLiteral - Parse {true,false} literals.
Action::ExprResult
-Sema::ParseCXXBoolLiteral(SourceLocation, tok::TokenKind Kind) {
+Sema::ParseCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind) {
assert((Kind != tok::kw_true || Kind != tok::kw_false) &&
"Unknown C++ Boolean value!");
- return new CXXBoolLiteralExpr(Kind == tok::kw_true);
+ return new CXXBoolLiteralExpr(Kind == tok::kw_true, OpLoc);
}
Modified: cfe/cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/Expr.h?rev=39453&r1=39452&r2=39453&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Expr.h Wed Jul 11 11:44:36 2007
@@ -39,7 +39,8 @@
/// value objects created/interpreted by SourceManager. We assume AST
/// clients will have a pointer to the respective SourceManager.
virtual SourceRange getSourceRange() const = 0;
- SourceLocation getSourceLocation() const { return getSourceRange().Begin(); }
+ SourceLocation getLocStart() const { return getSourceRange().Begin(); }
+ SourceLocation getLocEnd() const { return getSourceRange().End(); }
/// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or
/// incomplete type other than void. Nonarray expressions that can be lvalues:
@@ -89,8 +90,7 @@
Expr(DeclRefExprClass, t), D(d), Loc(l) {}
Decl *getDecl() const { return D; }
- SourceLocation getSourceLocation() const { return Loc; }
- virtual SourceRange getSourceRange() const { return SourceRange(Loc,Loc); }
+ virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
@@ -110,8 +110,7 @@
assert(type->isIntegerType() && "Illegal type in IntegerLiteral");
}
intmax_t getValue() const { return Value; }
- SourceLocation getSourceLocation() const { return Loc; }
- virtual SourceRange getSourceRange() const { return SourceRange(Loc,Loc); }
+ virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
@@ -128,8 +127,7 @@
CharacterLiteral(unsigned value, QualType type, SourceLocation l)
: Expr(CharacterLiteralClass, type), Value(value), Loc(l) {
}
- SourceLocation getSourceLocation() const { return Loc; }
- virtual SourceRange getSourceRange() const { return SourceRange(Loc,Loc); }
+ virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
@@ -145,8 +143,7 @@
FloatingLiteral(float value, QualType type, SourceLocation l)
: Expr(FloatingLiteralClass, type), Value(value), Loc(l) {}
- SourceLocation getSourceLocation() const { return Loc; }
- virtual SourceRange getSourceRange() const { return SourceRange(Loc,Loc); }
+ virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
@@ -159,19 +156,22 @@
const char *StrData;
unsigned ByteLength;
bool IsWide;
- SourceLocation Loc;
+ // if the StringLiteral was composed using token pasting, both locations
+ // are needed. If not (the common case), firstTokLoc == lastTokLoc.
+ // FIXME: if space becomes an issue, we should create a sub-class.
+ SourceLocation firstTokLoc, lastTokLoc;
public:
StringLiteral(const char *strData, unsigned byteLength, bool Wide,
- QualType t, SourceLocation l);
+ QualType t, SourceLocation b, SourceLocation e);
virtual ~StringLiteral();
const char *getStrData() const { return StrData; }
unsigned getByteLength() const { return ByteLength; }
bool isWide() const { return IsWide; }
- SourceLocation getSourceLocation() const { return Loc; }
- virtual SourceRange getSourceRange() const { return SourceRange(Loc,Loc); }
-
+ virtual SourceRange getSourceRange() const {
+ return SourceRange(firstTokLoc,lastTokLoc);
+ }
virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == StringLiteralClass;
@@ -186,7 +186,7 @@
Expr *Val;
public:
ParenExpr(SourceLocation l, SourceLocation r, Expr *val)
- : Expr(ParenExprClass, QualType()), L(l), R(r), Val(val) {}
+ : Expr(ParenExprClass, val->getType()), L(l), R(r), Val(val) {}
Expr *getSubExpr() const { return Val; }
SourceRange getSourceRange() const { return SourceRange(L, R); }
@@ -230,12 +230,11 @@
Opcode getOpcode() const { return Opc; }
Expr *getSubExpr() const { return Val; }
- SourceLocation getSourceLocation() const { return Loc; }
virtual SourceRange getSourceRange() const {
if (isPostfix())
- return SourceRange(getSubExpr()->getSourceRange().Begin(), Loc);
+ return SourceRange(getSubExpr()->getLocStart(), Loc);
else
- return SourceRange(Loc, getSubExpr()->getSourceRange().End());
+ return SourceRange(Loc, getSubExpr()->getLocEnd());
}
bool isPostfix() const { return isPostfix(Opc); }
bool isIncrementDecrementOp() const { return Opc>=PostInc && Opc<=PreDec; }
@@ -297,7 +296,7 @@
Expr *getBase() const { return Base; }
Expr *getIdx() { return Idx; }
SourceRange getSourceRange() const {
- return SourceRange(Base->getSourceRange().Begin(), Loc);
+ return SourceRange(Base->getLocStart(), Loc);
}
virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
@@ -323,7 +322,7 @@
Expr *getCallee() const { return Fn; }
SourceRange getSourceRange() const {
- return SourceRange(Fn->getSourceRange().Begin(), Loc);
+ return SourceRange(Fn->getLocStart(), Loc);
}
/// getNumArgs - Return the number of actual arguments to this call.
@@ -362,7 +361,7 @@
FieldDecl *getMemberDecl() const { return MemberDecl; }
bool isArrow() const { return IsArrow; }
virtual SourceRange getSourceRange() const {
- return SourceRange(getBase()->getSourceRange().Begin(),
+ return SourceRange(getBase()->getLocStart(),
getMemberDecl()->getLocation());
}
virtual void visit(StmtVisitor &Visitor);
@@ -386,7 +385,6 @@
QualType getDestType() const { return Ty; }
Expr *getSubExpr() const { return Op; }
- SourceLocation getSourceLocation() const { return Loc; }
virtual SourceRange getSourceRange() const {
return SourceRange(Loc, getSubExpr()->getSourceRange().End());
}
@@ -442,8 +440,7 @@
Expr *getLHS() const { return LHS; }
Expr *getRHS() const { return RHS; }
virtual SourceRange getSourceRange() const {
- return SourceRange(getLHS()->getSourceRange().Begin(),
- getRHS()->getSourceRange().End());
+ return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd());
}
virtual void visit(StmtVisitor &Visitor);
@@ -470,8 +467,7 @@
Expr *getRHS() const { return RHS; }
virtual SourceRange getSourceRange() const {
- return SourceRange(getCond()->getSourceRange().Begin(),
- getRHS()->getSourceRange().End());
+ return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd());
}
virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
Modified: cfe/cfe/trunk/include/clang/AST/ExprCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/ExprCXX.h?rev=39453&r1=39452&r2=39453&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/cfe/trunk/include/clang/AST/ExprCXX.h Wed Jul 11 11:44:36 2007
@@ -47,12 +47,12 @@
///
class CXXBoolLiteralExpr : public Expr {
bool Value;
+ SourceLocation Loc;
public:
- CXXBoolLiteralExpr(bool val) :
- Expr(CXXBoolLiteralExprClass, QualType()), Value(val) {}
+ CXXBoolLiteralExpr(bool val, SourceLocation l) :
+ Expr(CXXBoolLiteralExprClass, QualType()), Value(val), Loc(l) {}
- virtual SourceRange getSourceRange() const { // FIXME
- return SourceRange(SourceLocation(),SourceLocation()); }
+ virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
virtual void visit(StmtVisitor &Visitor);
};
Modified: cfe/cfe/trunk/include/clang/Basic/SourceLocation.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Basic/SourceLocation.h?rev=39453&r1=39452&r2=39453&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/SourceLocation.h (original)
+++ cfe/cfe/trunk/include/clang/Basic/SourceLocation.h Wed Jul 11 11:44:36 2007
@@ -94,6 +94,7 @@
SourceLocation B;
SourceLocation E;
public:
+ SourceRange(SourceLocation loc) : B(loc), E(loc) {}
SourceRange(SourceLocation begin, SourceLocation end) : B(begin), E(end) {}
SourceLocation Begin() const { return B; }
More information about the cfe-commits
mailing list