]> granicus.if.org Git - clang/commitdiff
Make sure to explicitly pass type/value dependence to Expr constructor. This
authorEli Friedman <eli.friedman@gmail.com>
Wed, 30 Dec 2009 00:13:48 +0000 (00:13 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Wed, 30 Dec 2009 00:13:48 +0000 (00:13 +0000)
caught several cases where we were not doing the right thing. I'm
not completely sure all cases are being handled correctly, but this should
be an improvement.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92281 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Expr.h
include/clang/AST/ExprCXX.h
include/clang/AST/ExprObjC.h
lib/AST/Expr.cpp

index 1a615c1e3f8fe8e2d2574f3db85d33d8e3b0f377..0cb22df92ff75d1f74a5cc0cd901cfe03eaea65c 100644 (file)
@@ -53,14 +53,6 @@ protected:
   /// (C++ [temp.dep.constexpr]).
   bool ValueDependent : 1;
 
-  // FIXME: Eventually, this constructor should go away and we should
-  // require every subclass to provide type/value-dependence
-  // information.
-  Expr(StmtClass SC, QualType T)
-    : Stmt(SC), TypeDependent(false), ValueDependent(false) {
-    setType(T);
-  }
-
   Expr(StmtClass SC, QualType T, bool TD, bool VD)
     : Stmt(SC), TypeDependent(TD), ValueDependent(VD) {
     setType(T);
@@ -609,7 +601,7 @@ public:
   // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy,
   // or UnsignedLongLongTy
   IntegerLiteral(const llvm::APInt &V, QualType type, SourceLocation l)
-    : Expr(IntegerLiteralClass, type), Value(V), Loc(l) {
+    : Expr(IntegerLiteralClass, type, false, false), Value(V), Loc(l) {
     assert(type->isIntegerType() && "Illegal type in IntegerLiteral");
   }
 
@@ -643,7 +635,8 @@ class CharacterLiteral : public Expr {
 public:
   // type should be IntTy
   CharacterLiteral(unsigned value, bool iswide, QualType type, SourceLocation l)
-    : Expr(CharacterLiteralClass, type), Value(value), Loc(l), IsWide(iswide) {
+    : Expr(CharacterLiteralClass, type, false, false), Value(value), Loc(l),
+      IsWide(iswide) {
   }
 
   /// \brief Construct an empty character literal.
@@ -677,7 +670,8 @@ class FloatingLiteral : public Expr {
 public:
   FloatingLiteral(const llvm::APFloat &V, bool isexact,
                   QualType Type, SourceLocation L)
-    : Expr(FloatingLiteralClass, Type), Value(V), IsExact(isexact), Loc(L) {}
+    : Expr(FloatingLiteralClass, Type, false, false), Value(V),
+      IsExact(isexact), Loc(L) {}
 
   /// \brief Construct an empty floating-point literal.
   explicit FloatingLiteral(EmptyShell Empty)
@@ -718,7 +712,7 @@ class ImaginaryLiteral : public Expr {
   Stmt *Val;
 public:
   ImaginaryLiteral(Expr *val, QualType Ty)
-    : Expr(ImaginaryLiteralClass, Ty), Val(val) {}
+    : Expr(ImaginaryLiteralClass, Ty, false, false), Val(val) {}
 
   /// \brief Build an empty imaginary literal.
   explicit ImaginaryLiteral(EmptyShell Empty)
@@ -762,7 +756,7 @@ class StringLiteral : public Expr {
   unsigned NumConcatenated;
   SourceLocation TokLocs[1];
 
-  StringLiteral(QualType Ty) : Expr(StringLiteralClass, Ty) {}
+  StringLiteral(QualType Ty) : Expr(StringLiteralClass, Ty, false, false) {}
 
 protected:
   virtual void DoDestroy(ASTContext &C);
@@ -1466,10 +1460,11 @@ class CompoundLiteralExpr : public Expr {
   Stmt *Init;
   bool FileScope;
 public:
+  // FIXME: Can compound literals be value-dependent?
   CompoundLiteralExpr(SourceLocation lparenloc, QualType ty, Expr *init,
                       bool fileScope)
-    : Expr(CompoundLiteralExprClass, ty), LParenLoc(lparenloc), Init(init),
-      FileScope(fileScope) {}
+    : Expr(CompoundLiteralExprClass, ty, ty->isDependentType(), false),
+      LParenLoc(lparenloc), Init(init), FileScope(fileScope) {}
 
   /// \brief Construct an empty compound literal.
   explicit CompoundLiteralExpr(EmptyShell Empty)
@@ -1903,8 +1898,11 @@ public:
 
 protected:
   BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
-                 SourceLocation oploc, bool dead)
-    : Expr(CompoundAssignOperatorClass, ResTy), Opc(opc), OpLoc(oploc) {
+                 SourceLocation opLoc, bool dead)
+    : Expr(CompoundAssignOperatorClass, ResTy,
+           lhs->isTypeDependent() || rhs->isTypeDependent(),
+           lhs->isValueDependent() || rhs->isValueDependent()),
+      Opc(opc), OpLoc(opLoc) {
     SubExprs[LHS] = lhs;
     SubExprs[RHS] = rhs;
   }
@@ -2033,7 +2031,8 @@ class AddrLabelExpr : public Expr {
 public:
   AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelStmt *L,
                 QualType t)
-    : Expr(AddrLabelExprClass, t), AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {}
+    : Expr(AddrLabelExprClass, t, false, false),
+      AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {}
 
   /// \brief Build an empty address of a label expression.
   explicit AddrLabelExpr(EmptyShell Empty)
@@ -2068,9 +2067,11 @@ class StmtExpr : public Expr {
   Stmt *SubStmt;
   SourceLocation LParenLoc, RParenLoc;
 public:
+  // FIXME: Does type-dependence need to be computed differently?
   StmtExpr(CompoundStmt *substmt, QualType T,
            SourceLocation lp, SourceLocation rp) :
-    Expr(StmtExprClass, T), SubStmt(substmt),  LParenLoc(lp), RParenLoc(rp) { }
+    Expr(StmtExprClass, T, T->isDependentType(), false),
+    SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { }
 
   /// \brief Build an empty statement expression.
   explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { }
@@ -2109,8 +2110,8 @@ class TypesCompatibleExpr : public Expr {
 public:
   TypesCompatibleExpr(QualType ReturnType, SourceLocation BLoc,
                       QualType t1, QualType t2, SourceLocation RP) :
-    Expr(TypesCompatibleExprClass, ReturnType), Type1(t1), Type2(t2),
-    BuiltinLoc(BLoc), RParenLoc(RP) {}
+    Expr(TypesCompatibleExprClass, ReturnType, false, false),
+    Type1(t1), Type2(t2), BuiltinLoc(BLoc), RParenLoc(RP) {}
 
   /// \brief Build an empty __builtin_type_compatible_p expression.
   explicit TypesCompatibleExpr(EmptyShell Empty)
@@ -2160,11 +2161,13 @@ protected:
   virtual void DoDestroy(ASTContext &C);
 
 public:
+  // FIXME: Can a shufflevector be value-dependent?  Does type-dependence need
+  // to be computed differently?
   ShuffleVectorExpr(ASTContext &C, Expr **args, unsigned nexpr,
                     QualType Type, SourceLocation BLoc,
                     SourceLocation RP) :
-    Expr(ShuffleVectorExprClass, Type), BuiltinLoc(BLoc),
-    RParenLoc(RP), NumExprs(nexpr) {
+    Expr(ShuffleVectorExprClass, Type, Type->isDependentType(), false),
+    BuiltinLoc(BLoc), RParenLoc(RP), NumExprs(nexpr) {
 
     SubExprs = new (C) Stmt*[nexpr];
     for (unsigned i = 0; i < nexpr; i++)
@@ -2292,7 +2295,7 @@ class GNUNullExpr : public Expr {
 
 public:
   GNUNullExpr(QualType Ty, SourceLocation Loc)
-    : Expr(GNUNullExprClass, Ty), TokenLoc(Loc) { }
+    : Expr(GNUNullExprClass, Ty, false, false), TokenLoc(Loc) { }
 
   /// \brief Build an empty GNU __null expression.
   explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { }
@@ -2320,7 +2323,7 @@ class VAArgExpr : public Expr {
   SourceLocation BuiltinLoc, RParenLoc;
 public:
   VAArgExpr(SourceLocation BLoc, Expr* e, QualType t, SourceLocation RPLoc)
-    : Expr(VAArgExprClass, t),
+    : Expr(VAArgExprClass, t, t->isDependentType(), false),
       Val(e),
       BuiltinLoc(BLoc),
       RParenLoc(RPLoc) { }
@@ -2802,7 +2805,7 @@ public:
 class ImplicitValueInitExpr : public Expr {
 public:
   explicit ImplicitValueInitExpr(QualType ty)
-    : Expr(ImplicitValueInitExprClass, ty) { }
+    : Expr(ImplicitValueInitExprClass, ty, false, false) { }
 
   /// \brief Construct an empty implicit value initialization.
   explicit ImplicitValueInitExpr(EmptyShell Empty)
@@ -2890,7 +2893,8 @@ class ExtVectorElementExpr : public Expr {
 public:
   ExtVectorElementExpr(QualType ty, Expr *base, IdentifierInfo &accessor,
                        SourceLocation loc)
-    : Expr(ExtVectorElementExprClass, ty),
+    : Expr(ExtVectorElementExprClass, ty, base->isTypeDependent(),
+           base->isValueDependent()),
       Base(base), Accessor(&accessor), AccessorLoc(loc) {}
 
   /// \brief Build an empty vector element expression.
@@ -2945,7 +2949,7 @@ protected:
   bool HasBlockDeclRefExprs;
 public:
   BlockExpr(BlockDecl *BD, QualType ty, bool hasBlockDeclRefExprs)
-    : Expr(BlockExprClass, ty),
+    : Expr(BlockExprClass, ty, ty->isDependentType(), false),
       TheBlock(BD), HasBlockDeclRefExprs(hasBlockDeclRefExprs) {}
 
   /// \brief Build an empty block expression.
@@ -2990,10 +2994,11 @@ class BlockDeclRefExpr : public Expr {
   bool IsByRef : 1;
   bool ConstQualAdded : 1;
 public:
+  // FIXME: Fix type/value dependence!
   BlockDeclRefExpr(ValueDecl *d, QualType t, SourceLocation l, bool ByRef,
-                   bool constAdded = false) :
-       Expr(BlockDeclRefExprClass, t), D(d), Loc(l), IsByRef(ByRef),
-                                       ConstQualAdded(constAdded) {}
+                   bool constAdded = false)
+  : Expr(BlockDeclRefExprClass, t, false, false), D(d), Loc(l), IsByRef(ByRef),
+    ConstQualAdded(constAdded) {}
 
   // \brief Build an empty reference to a declared variable in a
   // block.
index 662dbb697242a6fb70728e1d58318218f93fba94..d0e21f576d75e98bee4003fd9b62f7632f7e4809 100644 (file)
@@ -224,7 +224,7 @@ class CXXBoolLiteralExpr : public Expr {
   SourceLocation Loc;
 public:
   CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) :
-    Expr(CXXBoolLiteralExprClass, Ty), Value(val), Loc(l) {}
+    Expr(CXXBoolLiteralExprClass, Ty, false, false), Value(val), Loc(l) {}
 
   bool getValue() const { return Value; }
 
@@ -245,7 +245,7 @@ class CXXNullPtrLiteralExpr : public Expr {
   SourceLocation Loc;
 public:
   CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) :
-    Expr(CXXNullPtrLiteralExprClass, Ty), Loc(l) {}
+    Expr(CXXNullPtrLiteralExprClass, Ty, false, false), Loc(l) {}
 
   virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
 
@@ -401,12 +401,13 @@ protected:
     : Expr(SC, 
            param->hasUnparsedDefaultArg()
              ? param->getType().getNonReferenceType()
-             : param->getDefaultArg()->getType()),
+             : param->getDefaultArg()->getType(),
+           false, false),
       Param(param, false), Loc(Loc) { }
 
   CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param, 
                     Expr *SubExpr)
-    : Expr(SC, SubExpr->getType()), Param(param, true), Loc(Loc)
+    : Expr(SC, SubExpr->getType(), false, false), Param(param, true), Loc(Loc)
   {
     *reinterpret_cast<Expr **>(this + 1) = SubExpr;
   }
@@ -491,8 +492,8 @@ class CXXBindTemporaryExpr : public Expr {
   Stmt *SubExpr;
 
   CXXBindTemporaryExpr(CXXTemporary *temp, Expr* subexpr)
-   : Expr(CXXBindTemporaryExprClass,
-          subexpr->getType()), Temp(temp), SubExpr(subexpr) { }
+   : Expr(CXXBindTemporaryExprClass, subexpr->getType(), false, false),
+     Temp(temp), SubExpr(subexpr) { }
   ~CXXBindTemporaryExpr() { }
 
 protected:
index 0613f4c095f8e4e8fd5fc010b76518cf94a7e963..0b0cd64ad7215add0831539f3c19fb4387b04c38 100644 (file)
@@ -30,7 +30,7 @@ class ObjCStringLiteral : public Expr {
   SourceLocation AtLoc;
 public:
   ObjCStringLiteral(StringLiteral *SL, QualType T, SourceLocation L)
-    : Expr(ObjCStringLiteralClass, T), String(SL), AtLoc(L) {}
+    : Expr(ObjCStringLiteralClass, T, false, false), String(SL), AtLoc(L) {}
   explicit ObjCStringLiteral(EmptyShell Empty)
     : Expr(ObjCStringLiteralClass, Empty) {}
 
@@ -100,7 +100,8 @@ class ObjCSelectorExpr : public Expr {
 public:
   ObjCSelectorExpr(QualType T, Selector selInfo,
                    SourceLocation at, SourceLocation rp)
-  : Expr(ObjCSelectorExprClass, T), SelName(selInfo), AtLoc(at), RParenLoc(rp){}
+  : Expr(ObjCSelectorExprClass, T, false, false), SelName(selInfo), AtLoc(at),
+    RParenLoc(rp){}
   explicit ObjCSelectorExpr(EmptyShell Empty)
    : Expr(ObjCSelectorExprClass, Empty) {}
 
@@ -139,7 +140,7 @@ class ObjCProtocolExpr : public Expr {
 public:
   ObjCProtocolExpr(QualType T, ObjCProtocolDecl *protocol,
                    SourceLocation at, SourceLocation rp)
-  : Expr(ObjCProtocolExprClass, T), TheProtocol(protocol),
+  : Expr(ObjCProtocolExprClass, T, false, false), TheProtocol(protocol),
     AtLoc(at), RParenLoc(rp) {}
   explicit ObjCProtocolExpr(EmptyShell Empty)
     : Expr(ObjCProtocolExprClass, Empty) {}
@@ -178,7 +179,7 @@ public:
   ObjCIvarRefExpr(ObjCIvarDecl *d,
                   QualType t, SourceLocation l, Expr *base=0,
                   bool arrow = false, bool freeIvar = false) :
-    Expr(ObjCIvarRefExprClass, t), D(d),
+    Expr(ObjCIvarRefExprClass, t, false, false), D(d),
     Loc(l), Base(base), IsArrow(arrow),
     IsFreeIvar(freeIvar) {}
 
@@ -227,7 +228,8 @@ private:
 public:
   ObjCPropertyRefExpr(ObjCPropertyDecl *PD, QualType t,
                       SourceLocation l, Expr *base)
-    : Expr(ObjCPropertyRefExprClass, t), AsProperty(PD), IdLoc(l), Base(base) {
+    : Expr(ObjCPropertyRefExprClass, t, false, false), AsProperty(PD),
+      IdLoc(l), Base(base) {
   }
 
   explicit ObjCPropertyRefExpr(EmptyShell Empty)
@@ -291,16 +293,17 @@ public:
                  QualType t,
                  ObjCMethodDecl *setter,
                  SourceLocation l, Expr *base)
-    : Expr(ObjCImplicitSetterGetterRefExprClass, t), Setter(setter),
-      Getter(getter), MemberLoc(l), Base(base), InterfaceDecl(0),
-      ClassLoc(SourceLocation()) {
+    : Expr(ObjCImplicitSetterGetterRefExprClass, t, false, false),
+      Setter(setter), Getter(getter), MemberLoc(l), Base(base),
+      InterfaceDecl(0), ClassLoc(SourceLocation()) {
     }
   ObjCImplicitSetterGetterRefExpr(ObjCMethodDecl *getter,
                  QualType t,
                  ObjCMethodDecl *setter,
                  SourceLocation l, ObjCInterfaceDecl *C, SourceLocation CL)
-    : Expr(ObjCImplicitSetterGetterRefExprClass, t), Setter(setter),
-      Getter(getter), MemberLoc(l), Base(0), InterfaceDecl(C), ClassLoc(CL) {
+    : Expr(ObjCImplicitSetterGetterRefExprClass, t, false, false),
+      Setter(setter), Getter(getter), MemberLoc(l), Base(0), InterfaceDecl(C),
+      ClassLoc(CL) {
     }
   explicit ObjCImplicitSetterGetterRefExpr(EmptyShell Empty)
            : Expr(ObjCImplicitSetterGetterRefExprClass, Empty){}
@@ -488,7 +491,7 @@ class ObjCSuperExpr : public Expr {
   SourceLocation Loc;
 public:
   ObjCSuperExpr(SourceLocation L, QualType Type)
-    : Expr(ObjCSuperExprClass, Type), Loc(L) { }
+    : Expr(ObjCSuperExprClass, Type, false, false), Loc(L) { }
   explicit ObjCSuperExpr(EmptyShell Empty) : Expr(ObjCSuperExprClass, Empty) {}
 
   SourceLocation getLoc() const { return Loc; }
@@ -519,7 +522,7 @@ class ObjCIsaExpr : public Expr {
   bool IsArrow;
 public:
   ObjCIsaExpr(Expr *base, bool isarrow, SourceLocation l, QualType ty)
-    : Expr(ObjCIsaExprClass, ty),
+    : Expr(ObjCIsaExprClass, ty, false, false),
       Base(base), IsaMemberLoc(l), IsArrow(isarrow) {}
 
   /// \brief Build an empty expression.
index a31a7f51f828e77ba23bca16612bf462cc51e864..04a6abca87c966a334031f8a5a646bad682b76e1 100644 (file)
@@ -2032,7 +2032,7 @@ ObjCMessageExpr::ObjCMessageExpr(Expr *receiver, Selector selInfo,
                 QualType retType, ObjCMethodDecl *mproto,
                 SourceLocation LBrac, SourceLocation RBrac,
                 Expr **ArgExprs, unsigned nargs)
-  : Expr(ObjCMessageExprClass, retType), SelName(selInfo),
+  : Expr(ObjCMessageExprClass, retType, false, false), SelName(selInfo),
     MethodProto(mproto) {
   NumArgs = nargs;
   SubExprs = new Stmt*[NumArgs+1];
@@ -2051,7 +2051,7 @@ ObjCMessageExpr::ObjCMessageExpr(IdentifierInfo *clsName, Selector selInfo,
                 QualType retType, ObjCMethodDecl *mproto,
                 SourceLocation LBrac, SourceLocation RBrac,
                 Expr **ArgExprs, unsigned nargs)
-  : Expr(ObjCMessageExprClass, retType), SelName(selInfo),
+  : Expr(ObjCMessageExprClass, retType, false, false), SelName(selInfo),
     MethodProto(mproto) {
   NumArgs = nargs;
   SubExprs = new Stmt*[NumArgs+1];
@@ -2069,7 +2069,7 @@ ObjCMessageExpr::ObjCMessageExpr(ObjCInterfaceDecl *cls, Selector selInfo,
                                  QualType retType, ObjCMethodDecl *mproto,
                                  SourceLocation LBrac, SourceLocation RBrac,
                                  Expr **ArgExprs, unsigned nargs)
-: Expr(ObjCMessageExprClass, retType), SelName(selInfo),
+: Expr(ObjCMessageExprClass, retType, false, false), SelName(selInfo),
 MethodProto(mproto) {
   NumArgs = nargs;
   SubExprs = new Stmt*[NumArgs+1];