[cfe-commits] r39552 - in /cfe/cfe/trunk: AST/Expr.cpp AST/Type.cpp Sema/SemaDecl.cpp Sema/SemaStmt.cpp include/clang/AST/Expr.h include/clang/AST/Type.h
clattner at cs.uiuc.edu
clattner at cs.uiuc.edu
Wed Jul 11 09:45:31 PDT 2007
Author: clattner
Date: Wed Jul 11 11:45:31 2007
New Revision: 39552
URL: http://llvm.org/viewvc/llvm-project?rev=39552&view=rev
Log:
Modify Expr::isConstantExpr and friends take a pointer to a SourceLoc instead
of one by reference, making it optional.
Modified:
cfe/cfe/trunk/AST/Expr.cpp
cfe/cfe/trunk/AST/Type.cpp
cfe/cfe/trunk/Sema/SemaDecl.cpp
cfe/cfe/trunk/Sema/SemaStmt.cpp
cfe/cfe/trunk/include/clang/AST/Expr.h
cfe/cfe/trunk/include/clang/AST/Type.h
Modified: cfe/cfe/trunk/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Expr.cpp?rev=39552&r1=39551&r2=39552&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/Expr.cpp (original)
+++ cfe/cfe/trunk/AST/Expr.cpp Wed Jul 11 11:45:31 2007
@@ -204,7 +204,7 @@
/// violation. FIXME: This routine currently implements C90 semantics.
/// To properly implement C99 semantics this routine will need to evaluate
/// expressions involving operators previously mentioned.
-bool Expr::isConstantExpr(bool isIntConst, SourceLocation &loc) const {
+bool Expr::isConstantExpr(bool isIntConst, SourceLocation *Loc) const {
switch (getStmtClass()) {
case IntegerLiteralClass:
case CharacterLiteralClass:
@@ -213,67 +213,67 @@
case StringLiteralClass:
if (!isIntConst)
return true;
- loc = getLocStart();
+ if (Loc) *Loc = getLocStart();
return false;
case DeclRefExprClass:
if (isa<EnumConstantDecl>(cast<DeclRefExpr>(this)->getDecl()))
return true;
- loc = getLocStart();
+ if (Loc) *Loc = getLocStart();
return false;
case UnaryOperatorClass:
const UnaryOperator *uop = cast<UnaryOperator>(this);
if (uop->isIncrementDecrementOp()) { // C99 6.6p3
- loc = getLocStart();
+ if (Loc) *Loc = getLocStart();
return false;
}
// C99 6.5.3.4p2: otherwise, the operand is *not* evaluated and the result
// is an integer constant. This effective ignores any subexpression that
// isn't actually a constant expression (what an odd language:-)
if (uop->isSizeOfAlignOfOp())
- return uop->getSubExpr()->getType()->isConstantSizeType(loc);
- return uop->getSubExpr()->isConstantExpr(isIntConst, loc);
+ return uop->getSubExpr()->getType()->isConstantSizeType(Loc);
+ return uop->getSubExpr()->isConstantExpr(isIntConst, Loc);
case BinaryOperatorClass:
const BinaryOperator *bop = cast<BinaryOperator>(this);
// C99 6.6p3: shall not contain assignment, increment/decrement,
// function call, or comma operators, *except* when they are contained
// within a subexpression that is not evaluated.
if (bop->isAssignmentOp() || bop->getOpcode() == BinaryOperator::Comma) {
- loc = getLocStart();
+ if (Loc) *Loc = getLocStart();
return false;
}
- return bop->getLHS()->isConstantExpr(isIntConst, loc) &&
- bop->getRHS()->isConstantExpr(isIntConst, loc);
+ return bop->getLHS()->isConstantExpr(isIntConst, Loc) &&
+ bop->getRHS()->isConstantExpr(isIntConst, Loc);
case ParenExprClass:
- return cast<ParenExpr>(this)->getSubExpr()->isConstantExpr(isIntConst, loc);
+ return cast<ParenExpr>(this)->getSubExpr()->isConstantExpr(isIntConst, Loc);
case CastExprClass:
const CastExpr *castExpr = cast<CastExpr>(this);
// C99 6.6p6: shall only convert arithmetic types to integer types.
if (!castExpr->getSubExpr()->getType()->isArithmeticType()) {
- loc = castExpr->getSubExpr()->getLocStart();
+ if (Loc) *Loc = castExpr->getSubExpr()->getLocStart();
return false;
}
if (!castExpr->getDestType()->isIntegerType()) {
- loc = getLocStart();
+ if (Loc) *Loc = getLocStart();
return false;
}
// allow floating constants that are the immediate operands of casts.
- if (castExpr->getSubExpr()->isConstantExpr(isIntConst, loc) ||
+ if (castExpr->getSubExpr()->isConstantExpr(isIntConst, Loc) ||
isa<FloatingLiteral>(castExpr->getSubExpr()))
return true;
- loc = getLocStart();
+ if (Loc) *Loc = getLocStart();
return false;
case SizeOfAlignOfTypeExprClass:
const SizeOfAlignOfTypeExpr *sizeExpr = cast<SizeOfAlignOfTypeExpr>(this);
if (sizeExpr->isSizeOf())
- return sizeExpr->getArgumentType()->isConstantSizeType(loc);
+ return sizeExpr->getArgumentType()->isConstantSizeType(Loc);
return true; // alignof will always evaluate to a constant
case ConditionalOperatorClass:
const ConditionalOperator *condExpr = cast<ConditionalOperator>(this);
- return condExpr->getCond()->isConstantExpr(isIntConst, loc) &&
- condExpr->getLHS()->isConstantExpr(isIntConst, loc) &&
- condExpr->getRHS()->isConstantExpr(isIntConst, loc);
+ return condExpr->getCond()->isConstantExpr(isIntConst, Loc) &&
+ condExpr->getLHS()->isConstantExpr(isIntConst, Loc) &&
+ condExpr->getRHS()->isConstantExpr(isIntConst, Loc);
default:
- loc = getLocStart();
+ if (Loc) *Loc = getLocStart();
return false;
}
}
Modified: cfe/cfe/trunk/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Type.cpp?rev=39552&r1=39551&r2=39552&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/Type.cpp (original)
+++ cfe/cfe/trunk/AST/Type.cpp Wed Jul 11 11:45:31 2007
@@ -294,7 +294,7 @@
// The only variable size types are auto arrays within a function. Structures
// cannot contain a VLA member. They can have a flexible array member, however
// the structure is still constant size (C99 6.7.2.1p16).
-bool Type::isConstantSizeType(SourceLocation &loc) const {
+bool Type::isConstantSizeType(SourceLocation *loc) const {
if (const ArrayType *ary = dyn_cast<ArrayType>(CanonicalType)) {
if (Expr *size = ary->getSize()) {
if (!size->isConstantExpr(loc))
Modified: cfe/cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/SemaDecl.cpp?rev=39552&r1=39551&r2=39552&view=diff
==============================================================================
--- cfe/cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaDecl.cpp Wed Jul 11 11:45:31 2007
@@ -33,7 +33,7 @@
bool Sema::isConstantArrayType(ArrayType *ary, SourceLocation loc) {
if (Expr *size = ary->getSize()) {
SourceLocation expLoc;
- if (!size->isConstantExpr(expLoc)) {
+ if (!size->isConstantExpr(&expLoc)) {
Diag(expLoc, diag::err_typecheck_illegal_vla);
return false;
}
@@ -806,7 +806,7 @@
}
SourceLocation expLoc;
// C99 6.7.2.2p2: Make sure we have an integer constant expression.
- if (Val && !((Expr *)Val)->isIntegerConstantExpr(expLoc)) {
+ if (Val && !((Expr *)Val)->isIntegerConstantExpr(&expLoc)) {
Diag(expLoc, diag::err_enum_value_not_integer_constant_expr, Id->getName());
return 0;
}
Modified: cfe/cfe/trunk/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/SemaStmt.cpp?rev=39552&r1=39551&r2=39552&view=diff
==============================================================================
--- cfe/cfe/trunk/Sema/SemaStmt.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaStmt.cpp Wed Jul 11 11:45:31 2007
@@ -46,7 +46,8 @@
SourceLocation expLoc;
// C99 6.8.4.2p3: The expression shall be an integer constant.
- if (!((Expr *)LHSVal)->isIntegerConstantExpr(expLoc))
+ if (!((Expr *)LHSVal)->isIntegerConstantExpr(&expLoc))
+ // FIXME: Should pass in case expr as range.
return Diag(CaseLoc, diag::err_case_label_not_integer_constant_expr);
return new CaseStmt((Expr*)LHSVal, (Expr*)RHSVal, (Stmt*)SubStmt);
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=39552&r1=39551&r2=39552&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Expr.h Wed Jul 11 11:45:31 2007
@@ -79,10 +79,12 @@
bool isNullPointerConstant() const;
- bool isConstantExpr(SourceLocation &loc) const
- { return isConstantExpr(false, loc); }
- bool isIntegerConstantExpr(SourceLocation &loc) const
- { return isConstantExpr(true, loc); }
+ bool isConstantExpr(SourceLocation *Loc = 0) const {
+ return isConstantExpr(false, Loc);
+ }
+ bool isIntegerConstantExpr(SourceLocation *Loc = 0) const {
+ return isConstantExpr(true, Loc);
+ }
virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
@@ -91,7 +93,7 @@
}
static bool classof(const Expr *) { return true; }
private:
- bool isConstantExpr(bool isIntegerConstant, SourceLocation &loc) const;
+ bool isConstantExpr(bool isIntegerConstant, SourceLocation *loc) const;
};
//===----------------------------------------------------------------------===//
Modified: cfe/cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/Type.h?rev=39552&r1=39551&r2=39552&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Type.h Wed Jul 11 11:45:31 2007
@@ -236,7 +236,10 @@
bool isSignedIntegerType() const; // C99 6.2.5p4
bool isUnsignedIntegerType() const; // C99 6.2.5p6
- bool isConstantSizeType(SourceLocation &) const; // C99 6.7.5p3: VLA if false
+ /// isConstantSizeType - Return true if this is not a variable sized type,
+ /// according to the rules of C99 6.7.5p3. If Loc is non-null, it is set to
+ /// the location of the subexpression that makes it a vla type.
+ bool isConstantSizeType(SourceLocation *Loc = 0) const;
/// Compatibility predicates used to check assignment expressions.
static bool typesAreCompatible(QualType, QualType); // C99 6.2.7p1
More information about the cfe-commits
mailing list