Deleted Added
full compact
Expr.cpp (200583) Expr.cpp (201361)
1//===--- Expr.cpp - Expression AST Node Implementation --------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//

--- 160 unchanged lines hidden (view full) ---

169 return FD->getNameAsString();
170
171 llvm::SmallString<256> Name;
172 llvm::raw_svector_ostream Out(Name);
173
174 if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
175 if (MD->isVirtual())
176 Out << "virtual ";
1//===--- Expr.cpp - Expression AST Node Implementation --------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//

--- 160 unchanged lines hidden (view full) ---

169 return FD->getNameAsString();
170
171 llvm::SmallString<256> Name;
172 llvm::raw_svector_ostream Out(Name);
173
174 if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
175 if (MD->isVirtual())
176 Out << "virtual ";
177 if (MD->isStatic())
178 Out << "static ";
177 }
178
179 PrintingPolicy Policy(Context.getLangOptions());
180 Policy.SuppressTagKind = true;
181
182 std::string Proto = FD->getQualifiedNameAsString(Policy);
183
184 const FunctionType *AFT = FD->getType()->getAs<FunctionType>();

--- 13 unchanged lines hidden (view full) ---

198
199 if (FT->isVariadic()) {
200 if (FD->getNumParams()) POut << ", ";
201 POut << "...";
202 }
203 }
204 Proto += ")";
205
179 }
180
181 PrintingPolicy Policy(Context.getLangOptions());
182 Policy.SuppressTagKind = true;
183
184 std::string Proto = FD->getQualifiedNameAsString(Policy);
185
186 const FunctionType *AFT = FD->getType()->getAs<FunctionType>();

--- 13 unchanged lines hidden (view full) ---

200
201 if (FT->isVariadic()) {
202 if (FD->getNumParams()) POut << ", ";
203 POut << "...";
204 }
205 }
206 Proto += ")";
207
208 if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
209 Qualifiers ThisQuals = Qualifiers::fromCVRMask(MD->getTypeQualifiers());
210 if (ThisQuals.hasConst())
211 Proto += " const";
212 if (ThisQuals.hasVolatile())
213 Proto += " volatile";
214 }
215
206 if (!isa<CXXConstructorDecl>(FD) && !isa<CXXDestructorDecl>(FD))
207 AFT->getResultType().getAsStringInternal(Proto, Policy);
208
209 Out << Proto;
210
211 Out.flush();
212 return Name.str().str();
213 }

--- 179 unchanged lines hidden (view full) ---

393
394void CallExpr::DoDestroy(ASTContext& C) {
395 DestroyChildren(C);
396 if (SubExprs) C.Deallocate(SubExprs);
397 this->~CallExpr();
398 C.Deallocate(this);
399}
400
216 if (!isa<CXXConstructorDecl>(FD) && !isa<CXXDestructorDecl>(FD))
217 AFT->getResultType().getAsStringInternal(Proto, Policy);
218
219 Out << Proto;
220
221 Out.flush();
222 return Name.str().str();
223 }

--- 179 unchanged lines hidden (view full) ---

403
404void CallExpr::DoDestroy(ASTContext& C) {
405 DestroyChildren(C);
406 if (SubExprs) C.Deallocate(SubExprs);
407 this->~CallExpr();
408 C.Deallocate(this);
409}
410
401FunctionDecl *CallExpr::getDirectCallee() {
411Decl *CallExpr::getCalleeDecl() {
402 Expr *CEE = getCallee()->IgnoreParenCasts();
403 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CEE))
412 Expr *CEE = getCallee()->IgnoreParenCasts();
413 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CEE))
404 return dyn_cast<FunctionDecl>(DRE->getDecl());
414 return DRE->getDecl();
415 if (MemberExpr *ME = dyn_cast<MemberExpr>(CEE))
416 return ME->getMemberDecl();
405
406 return 0;
407}
408
417
418 return 0;
419}
420
421FunctionDecl *CallExpr::getDirectCallee() {
422 return dyn_cast_or_null<FunctionDecl>(getCalleeDecl());
423}
424
409/// setNumArgs - This changes the number of arguments present in this call.
410/// Any orphaned expressions are deleted by this, and any new operands are set
411/// to null.
412void CallExpr::setNumArgs(ASTContext& C, unsigned NumArgs) {
413 // No change, just return.
414 if (NumArgs == getNumArgs()) return;
415
416 // If shrinking # arguments, just delete the extras and forgot them.

--- 436 unchanged lines hidden (view full) ---

853 R2 = cast<ArraySubscriptExpr>(this)->getRHS()->getSourceRange();
854 return true;
855
856 case CallExprClass:
857 case CXXOperatorCallExprClass:
858 case CXXMemberCallExprClass: {
859 // If this is a direct call, get the callee.
860 const CallExpr *CE = cast<CallExpr>(this);
425/// setNumArgs - This changes the number of arguments present in this call.
426/// Any orphaned expressions are deleted by this, and any new operands are set
427/// to null.
428void CallExpr::setNumArgs(ASTContext& C, unsigned NumArgs) {
429 // No change, just return.
430 if (NumArgs == getNumArgs()) return;
431
432 // If shrinking # arguments, just delete the extras and forgot them.

--- 436 unchanged lines hidden (view full) ---

869 R2 = cast<ArraySubscriptExpr>(this)->getRHS()->getSourceRange();
870 return true;
871
872 case CallExprClass:
873 case CXXOperatorCallExprClass:
874 case CXXMemberCallExprClass: {
875 // If this is a direct call, get the callee.
876 const CallExpr *CE = cast<CallExpr>(this);
861 if (const FunctionDecl *FD = CE->getDirectCallee()) {
877 if (const Decl *FD = CE->getCalleeDecl()) {
862 // If the callee has attribute pure, const, or warn_unused_result, warn
863 // about it. void foo() { strlen("bar"); } should warn.
864 //
865 // Note: If new cases are added here, DiagnoseUnusedExprResult should be
866 // updated to match for QoI.
867 if (FD->getAttr<WarnUnusedResultAttr>() ||
868 FD->getAttr<PureAttr>() || FD->getAttr<ConstAttr>()) {
869 Loc = CE->getCallee()->getLocStart();

--- 172 unchanged lines hidden (view full) ---

1042 return LV_Valid;
1043
1044 // -- If E2 is a static data member [...] then E1.E2 is an lvalue.
1045 if (isa<VarDecl>(Member) && Member->getDeclContext()->isRecord())
1046 return LV_Valid;
1047
1048 // -- If E2 is a non-static data member [...]. If E1 is an
1049 // lvalue, then E1.E2 is an lvalue.
878 // If the callee has attribute pure, const, or warn_unused_result, warn
879 // about it. void foo() { strlen("bar"); } should warn.
880 //
881 // Note: If new cases are added here, DiagnoseUnusedExprResult should be
882 // updated to match for QoI.
883 if (FD->getAttr<WarnUnusedResultAttr>() ||
884 FD->getAttr<PureAttr>() || FD->getAttr<ConstAttr>()) {
885 Loc = CE->getCallee()->getLocStart();

--- 172 unchanged lines hidden (view full) ---

1058 return LV_Valid;
1059
1060 // -- If E2 is a static data member [...] then E1.E2 is an lvalue.
1061 if (isa<VarDecl>(Member) && Member->getDeclContext()->isRecord())
1062 return LV_Valid;
1063
1064 // -- If E2 is a non-static data member [...]. If E1 is an
1065 // lvalue, then E1.E2 is an lvalue.
1050 if (isa(Member))
1051 return m->isArrow() ? LV_Valid : m->getBase()->isLvalue(Ctx);
1066 if (isa<FieldDecl>(Member)) {
1067 if (m->isArrow())
1068 return LV_Valid;
1069 Expr *BaseExp = m->getBase();
1070 return (BaseExp->getStmtClass() == ObjCPropertyRefExprClass) ?
1071 LV_SubObjCPropertySetting : BaseExp->isLvalue(Ctx);
1072 }
1052
1053 // -- If it refers to a static member function [...], then
1054 // E1.E2 is an lvalue.
1055 // -- Otherwise, if E1.E2 refers to a non-static member
1056 // function [...], then E1.E2 is not an lvalue.
1057 if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(Member))
1058 return Method->isStatic()? LV_Valid : LV_MemberFunction;
1059
1060 // -- If E2 is a member enumerator [...], the expression E1.E2
1061 // is not an lvalue.
1062 if (isa<EnumConstantDecl>(Member))
1063 return LV_InvalidExpression;
1064
1065 // Not an lvalue.
1066 return LV_InvalidExpression;
1067 }
1073
1074 // -- If it refers to a static member function [...], then
1075 // E1.E2 is an lvalue.
1076 // -- Otherwise, if E1.E2 refers to a non-static member
1077 // function [...], then E1.E2 is not an lvalue.
1078 if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(Member))
1079 return Method->isStatic()? LV_Valid : LV_MemberFunction;
1080
1081 // -- If E2 is a member enumerator [...], the expression E1.E2
1082 // is not an lvalue.
1083 if (isa<EnumConstantDecl>(Member))
1084 return LV_InvalidExpression;
1085
1086 // Not an lvalue.
1087 return LV_InvalidExpression;
1088 }
1068
1089
1069 // C99 6.5.2.3p4
1090 // C99 6.5.2.3p4
1070 return m->isArrow() ? LV_Valid : m->getBase()->isLvalue(Ctx);
1091 if (m->isArrow())
1092 return LV_Valid;
1093 Expr *BaseExp = m->getBase();
1094 return (BaseExp->getStmtClass() == ObjCPropertyRefExprClass) ?
1095 LV_SubObjCPropertySetting : BaseExp->isLvalue(Ctx);
1071 }
1072 case UnaryOperatorClass:
1073 if (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Deref)
1074 return LV_Valid; // C99 6.5.3p4
1075
1076 if (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Real ||
1077 cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Imag ||
1078 cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Extension)

--- 120 unchanged lines hidden (view full) ---

1199 // Both sides must be lvalues for the result to be an lvalue.
1200 if (True->isLvalue(Ctx) != LV_Valid || False->isLvalue(Ctx) != LV_Valid)
1201 return LV_InvalidExpression;
1202
1203 // That's it.
1204 return LV_Valid;
1205 }
1206
1096 }
1097 case UnaryOperatorClass:
1098 if (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Deref)
1099 return LV_Valid; // C99 6.5.3p4
1100
1101 if (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Real ||
1102 cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Imag ||
1103 cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Extension)

--- 120 unchanged lines hidden (view full) ---

1224 // Both sides must be lvalues for the result to be an lvalue.
1225 if (True->isLvalue(Ctx) != LV_Valid || False->isLvalue(Ctx) != LV_Valid)
1226 return LV_InvalidExpression;
1227
1228 // That's it.
1229 return LV_Valid;
1230 }
1231
1232 case Expr::CXXExprWithTemporariesClass:
1233 return cast<CXXExprWithTemporaries>(this)->getSubExpr()->isLvalue(Ctx);
1234
1235 case Expr::ObjCMessageExprClass:
1236 if (const ObjCMethodDecl *Method
1237 = cast<ObjCMessageExpr>(this)->getMethodDecl())
1238 if (Method->getResultType()->isLValueReferenceType())
1239 return LV_Valid;
1240 break;
1241
1207 default:
1208 break;
1209 }
1210 return LV_InvalidExpression;
1211}
1212
1213/// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type,
1214/// does not have an incomplete type, does not have a const-qualified type, and

--- 24 unchanged lines hidden (view full) ---

1239 if (CE->getSubExpr()->isLvalue(Ctx) == LV_Valid) {
1240 if (Loc)
1241 *Loc = CE->getLParenLoc();
1242 return MLV_LValueCast;
1243 }
1244 }
1245 return MLV_InvalidExpression;
1246 case LV_MemberFunction: return MLV_MemberFunction;
1242 default:
1243 break;
1244 }
1245 return LV_InvalidExpression;
1246}
1247
1248/// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type,
1249/// does not have an incomplete type, does not have a const-qualified type, and

--- 24 unchanged lines hidden (view full) ---

1274 if (CE->getSubExpr()->isLvalue(Ctx) == LV_Valid) {
1275 if (Loc)
1276 *Loc = CE->getLParenLoc();
1277 return MLV_LValueCast;
1278 }
1279 }
1280 return MLV_InvalidExpression;
1281 case LV_MemberFunction: return MLV_MemberFunction;
1282 case LV_SubObjCPropertySetting: return MLV_SubObjCPropertySetting;
1247 }
1248
1249 // The following is illegal:
1250 // void takeclosure(void (^C)(void));
1251 // void func() { int x = 1; takeclosure(^{ x = 7; }); }
1252 //
1253 if (const BlockDeclRefExpr *BDR = dyn_cast<BlockDeclRefExpr>(this)) {
1254 if (!BDR->isByRef() && isa<VarDecl>(BDR->getDecl()))

--- 736 unchanged lines hidden (view full) ---

1991 }
1992}
1993
1994// constructor for instance messages.
1995ObjCMessageExpr::ObjCMessageExpr(Expr *receiver, Selector selInfo,
1996 QualType retType, ObjCMethodDecl *mproto,
1997 SourceLocation LBrac, SourceLocation RBrac,
1998 Expr **ArgExprs, unsigned nargs)
1283 }
1284
1285 // The following is illegal:
1286 // void takeclosure(void (^C)(void));
1287 // void func() { int x = 1; takeclosure(^{ x = 7; }); }
1288 //
1289 if (const BlockDeclRefExpr *BDR = dyn_cast<BlockDeclRefExpr>(this)) {
1290 if (!BDR->isByRef() && isa<VarDecl>(BDR->getDecl()))

--- 736 unchanged lines hidden (view full) ---

2027 }
2028}
2029
2030// constructor for instance messages.
2031ObjCMessageExpr::ObjCMessageExpr(Expr *receiver, Selector selInfo,
2032 QualType retType, ObjCMethodDecl *mproto,
2033 SourceLocation LBrac, SourceLocation RBrac,
2034 Expr **ArgExprs, unsigned nargs)
1999 : Expr(ObjCMessageExprClass, retType), SelName(selInfo),
2035 : Expr(ObjCMessageExprClass, retType, false, false), SelName(selInfo),
2000 MethodProto(mproto) {
2001 NumArgs = nargs;
2002 SubExprs = new Stmt*[NumArgs+1];
2003 SubExprs[RECEIVER] = receiver;
2004 if (NumArgs) {
2005 for (unsigned i = 0; i != NumArgs; ++i)
2006 SubExprs[i+ARGS_START] = static_cast<Expr *>(ArgExprs[i]);
2007 }
2008 LBracloc = LBrac;
2009 RBracloc = RBrac;
2010}
2011
2012// constructor for class messages.
2013// FIXME: clsName should be typed to ObjCInterfaceType
2014ObjCMessageExpr::ObjCMessageExpr(IdentifierInfo *clsName, Selector selInfo,
2015 QualType retType, ObjCMethodDecl *mproto,
2016 SourceLocation LBrac, SourceLocation RBrac,
2017 Expr **ArgExprs, unsigned nargs)
2036 MethodProto(mproto) {
2037 NumArgs = nargs;
2038 SubExprs = new Stmt*[NumArgs+1];
2039 SubExprs[RECEIVER] = receiver;
2040 if (NumArgs) {
2041 for (unsigned i = 0; i != NumArgs; ++i)
2042 SubExprs[i+ARGS_START] = static_cast<Expr *>(ArgExprs[i]);
2043 }
2044 LBracloc = LBrac;
2045 RBracloc = RBrac;
2046}
2047
2048// constructor for class messages.
2049// FIXME: clsName should be typed to ObjCInterfaceType
2050ObjCMessageExpr::ObjCMessageExpr(IdentifierInfo *clsName, Selector selInfo,
2051 QualType retType, ObjCMethodDecl *mproto,
2052 SourceLocation LBrac, SourceLocation RBrac,
2053 Expr **ArgExprs, unsigned nargs)
2018 : Expr(ObjCMessageExprClass, retType), SelName(selInfo),
2054 : Expr(ObjCMessageExprClass, retType, false, false), SelName(selInfo),
2019 MethodProto(mproto) {
2020 NumArgs = nargs;
2021 SubExprs = new Stmt*[NumArgs+1];
2022 SubExprs[RECEIVER] = (Expr*) ((uintptr_t) clsName | IsClsMethDeclUnknown);
2023 if (NumArgs) {
2024 for (unsigned i = 0; i != NumArgs; ++i)
2025 SubExprs[i+ARGS_START] = static_cast<Expr *>(ArgExprs[i]);
2026 }
2027 LBracloc = LBrac;
2028 RBracloc = RBrac;
2029}
2030
2031// constructor for class messages.
2032ObjCMessageExpr::ObjCMessageExpr(ObjCInterfaceDecl *cls, Selector selInfo,
2033 QualType retType, ObjCMethodDecl *mproto,
2034 SourceLocation LBrac, SourceLocation RBrac,
2035 Expr **ArgExprs, unsigned nargs)
2055 MethodProto(mproto) {
2056 NumArgs = nargs;
2057 SubExprs = new Stmt*[NumArgs+1];
2058 SubExprs[RECEIVER] = (Expr*) ((uintptr_t) clsName | IsClsMethDeclUnknown);
2059 if (NumArgs) {
2060 for (unsigned i = 0; i != NumArgs; ++i)
2061 SubExprs[i+ARGS_START] = static_cast<Expr *>(ArgExprs[i]);
2062 }
2063 LBracloc = LBrac;
2064 RBracloc = RBrac;
2065}
2066
2067// constructor for class messages.
2068ObjCMessageExpr::ObjCMessageExpr(ObjCInterfaceDecl *cls, Selector selInfo,
2069 QualType retType, ObjCMethodDecl *mproto,
2070 SourceLocation LBrac, SourceLocation RBrac,
2071 Expr **ArgExprs, unsigned nargs)
2036: Expr(ObjCMessageExprClass, retType), SelName(selInfo),
2072: Expr(ObjCMessageExprClass, retType, false, false), SelName(selInfo),
2037MethodProto(mproto) {
2038 NumArgs = nargs;
2039 SubExprs = new Stmt*[NumArgs+1];
2040 SubExprs[RECEIVER] = (Expr*) ((uintptr_t) cls | IsClsMethDeclKnown);
2041 if (NumArgs) {
2042 for (unsigned i = 0; i != NumArgs; ++i)
2043 SubExprs[i+ARGS_START] = static_cast<Expr *>(ArgExprs[i]);
2044 }

--- 507 unchanged lines hidden ---
2073MethodProto(mproto) {
2074 NumArgs = nargs;
2075 SubExprs = new Stmt*[NumArgs+1];
2076 SubExprs[RECEIVER] = (Expr*) ((uintptr_t) cls | IsClsMethDeclKnown);
2077 if (NumArgs) {
2078 for (unsigned i = 0; i != NumArgs; ++i)
2079 SubExprs[i+ARGS_START] = static_cast<Expr *>(ArgExprs[i]);
2080 }

--- 507 unchanged lines hidden ---