summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2008-11-14 16:09:21 +0000
committerDouglas Gregor <dgregor@apple.com>2008-11-14 16:09:21 +0000
commit993603d80db194627969b3be96ef64e9635d4ab7 (patch)
treec938a0b3f2aff91cce84b89ffee09da4984d1ef5 /clang/lib/Sema
parent5fe593390948b8a133bbabb6237e28f5eec55512 (diff)
downloadbcm5719-llvm-993603d80db194627969b3be96ef64e9635d4ab7.tar.gz
bcm5719-llvm-993603d80db194627969b3be96ef64e9635d4ab7.zip
Add a new expression node, CXXOperatorCallExpr, which expresses a
function call created in response to the use of operator syntax that resolves to an overloaded operator in C++, e.g., "str1 + str2" that resolves to std::operator+(str1, str2)". We now build a CXXOperatorCallExpr in C++ when we pick an overloaded operator. (But only for binary operators, where we actually implement overloading) I decided *not* to refactor the current CallExpr to make it abstract (with FunctionCallExpr and CXXOperatorCallExpr as derived classes). Doing so would allow us to make CXXOperatorCallExpr a little bit smaller, at the cost of making the argument and callee accessors virtual. We won't know if this is going to be a win until we can parse lots of C++ code to determine how much memory we'll save by making this change vs. the performance penalty due to the extra virtual calls. llvm-svn: 59306
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r--clang/lib/Sema/SemaDecl.cpp4
-rw-r--r--clang/lib/Sema/SemaExpr.cpp12
2 files changed, 9 insertions, 7 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 6dd9fa7c4bc..76835bc3abc 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -1237,6 +1237,7 @@ bool Sema::CheckAddressConstantExpression(const Expr* Init) {
case Expr::ObjCStringLiteralClass:
return false;
case Expr::CallExprClass:
+ case Expr::CXXOperatorCallExprClass:
// __builtin___CFStringMakeConstantString is a valid constant l-value.
if (cast<CallExpr>(Init)->isBuiltinCall() ==
Builtin::BI__builtin___CFStringMakeConstantString)
@@ -1432,7 +1433,8 @@ bool Sema::CheckArithmeticConstantExpression(const Expr* Init) {
case Expr::TypesCompatibleExprClass:
case Expr::CXXBoolLiteralExprClass:
return false;
- case Expr::CallExprClass: {
+ case Expr::CallExprClass:
+ case Expr::CXXOperatorCallExprClass: {
const CallExpr *CE = cast<CallExpr>(Init);
// Allow any constant foldable calls to builtins.
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index c9f311a204a..686a8f40083 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -2851,12 +2851,12 @@ Action::ExprResult Sema::ActOnBinOp(Scope *S, SourceLocation TokLoc,
ResultTy = ResultTy.getNonReferenceType();
// Build the actual expression node.
- // FIXME: We lose the fact that we have a function here!
- if (Opc > BinaryOperator::Assign && Opc <= BinaryOperator::OrAssign)
- return new CompoundAssignOperator(lhs, rhs, Opc, ResultTy, ResultTy,
- TokLoc);
- else
- return new BinaryOperator(lhs, rhs, Opc, ResultTy, TokLoc);
+ Expr *FnExpr = new DeclRefExpr(FnDecl, FnDecl->getType(),
+ SourceLocation());
+ UsualUnaryConversions(FnExpr);
+
+ Expr *Args[2] = { lhs, rhs };
+ return new CXXOperatorCallExpr(FnExpr, Args, 2, ResultTy, TokLoc);
} else {
// We matched a built-in operator. Convert the arguments, then
// break out so that we will build the appropriate built-in
OpenPOWER on IntegriCloud