aboutsummaryrefslogtreecommitdiff
path: root/lib/Basic
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
commitb4609806e9232593ece09ce08b630836e825865c (patch)
tree7b70b5d015a0fd6fbf2907a5a0a12596f2760823 /lib/Basic
parent0aab796da21bfc45381d3ce76c795710cb97acfc (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59306 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Basic')
-rw-r--r--lib/Basic/IdentifierTable.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/Basic/IdentifierTable.cpp b/lib/Basic/IdentifierTable.cpp
index b8684753b2..4d737c50bc 100644
--- a/lib/Basic/IdentifierTable.cpp
+++ b/lib/Basic/IdentifierTable.cpp
@@ -189,11 +189,22 @@ void IdentifierTable::AddKeywords(const LangOptions &LangOpts) {
#include "clang/Basic/TokenKinds.def"
}
+/// addOperatorPrefix - Add the prefix "operator" (possible with a
+/// space after it) to the given operator symbol, and return the
+/// result.
+static std::string addOperatorPrefix(const char* Symbol) {
+ std::string result = "operator";
+ if (Symbol[0] >= 'a' && Symbol[0] <= 'z')
+ result += ' ';
+ result += Symbol;
+ return result;
+}
+
/// AddOverloadedOperators - Register the name of all C++ overloadable
/// operators ("operator+", "operator[]", etc.)
void IdentifierTable::AddOverloadedOperators() {
#define OVERLOADED_OPERATOR(Name,Spelling,Token, Unary, Binary, MemberOnly) \
- OverloadedOperators[OO_##Name] = &get(Spelling); \
+ OverloadedOperators[OO_##Name] = &get(addOperatorPrefix(Spelling)); \
OverloadedOperators[OO_##Name]->setOverloadedOperatorID(OO_##Name);
#include "clang/Basic/OperatorKinds.def"
}