aboutsummaryrefslogtreecommitdiff
path: root/include/clang/Basic/IdentifierTable.h
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2008-11-06 22:13:31 +0000
committerDouglas Gregor <dgregor@apple.com>2008-11-06 22:13:31 +0000
commit1cd1b1e987f5e2f060d7972b13d83239b36d77d6 (patch)
tree2776b50f5ad1ceafd1aae9a31001b6b1a3f9dd5d /include/clang/Basic/IdentifierTable.h
parent5142af38ed0dd2f592cbfa00fa6e2e14dd6cc516 (diff)
Parsing, ASTs, and semantic analysis for the declaration of overloaded
operators in C++. Overloaded operators can be called directly via their operator-function-ids, e.g., "operator+(foo, bar)", but we don't yet implement the semantics of operator overloading to handle, e.g., "foo + bar". git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58817 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Basic/IdentifierTable.h')
-rw-r--r--include/clang/Basic/IdentifierTable.h27
1 files changed, 25 insertions, 2 deletions
diff --git a/include/clang/Basic/IdentifierTable.h b/include/clang/Basic/IdentifierTable.h
index acdf3dae8f..d84ce07d41 100644
--- a/include/clang/Basic/IdentifierTable.h
+++ b/include/clang/Basic/IdentifierTable.h
@@ -15,6 +15,7 @@
#ifndef LLVM_CLANG_BASIC_IDENTIFIERTABLE_H
#define LLVM_CLANG_BASIC_IDENTIFIERTABLE_H
+#include "clang/Basic/OperatorKinds.h"
#include "clang/Basic/TokenKinds.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/SmallString.h"
@@ -49,11 +50,12 @@ class IdentifierInfo {
// First NUM_OBJC_KEYWORDS values are for Objective-C, the remaining values
// are for builtins.
unsigned ObjCOrBuiltinID :10;
+ unsigned OperatorID : 6; // C++ overloaded operator.
bool HasMacro : 1; // True if there is a #define for this.
bool IsExtension : 1; // True if identifier is a lang extension.
bool IsPoisoned : 1; // True if identifier is poisoned.
bool IsCPPOperatorKeyword : 1; // True if ident is a C++ operator keyword.
- // 10 bits left in 32-bit word.
+ // 4 bits left in 32-bit word.
void *FETokenInfo; // Managed by the language front-end.
IdentifierInfo(const IdentifierInfo&); // NONCOPYABLE.
void operator=(const IdentifierInfo&); // NONASSIGNABLE.
@@ -120,6 +122,16 @@ public:
&& "ID too large for field!");
}
+ /// getOverloadedOperatorID - Get the C++ overloaded operator that
+ /// corresponds to this identifier.
+ OverloadedOperatorKind getOverloadedOperatorID() const {
+ return OverloadedOperatorKind(OperatorID);
+ }
+ void setOverloadedOperatorID(OverloadedOperatorKind ID) {
+ OperatorID = ID;
+ assert(OperatorID == (unsigned)ID && "ID too large for field!");
+ }
+
/// get/setExtension - Initialize information about whether or not this
/// language token is an extension. This controls extension warnings, and is
/// only valid if a custom token ID is set.
@@ -161,6 +173,11 @@ class IdentifierTable {
// BumpPtrAllocator!
typedef llvm::StringMap<IdentifierInfo, llvm::BumpPtrAllocator> HashTableTy;
HashTableTy HashTable;
+
+ /// OverloadedOperators - Identifiers corresponding to each of the
+ /// overloadable operators in C++.
+ IdentifierInfo *OverloadedOperators[NUM_OVERLOADED_OPERATORS];
+
public:
/// IdentifierTable ctor - Create the identifier table, populating it with
/// info about the language keywords for the language specified by LangOpts.
@@ -180,7 +197,12 @@ public:
const char *NameBytes = &Name[0];
return get(NameBytes, NameBytes+Name.size());
}
-
+
+ /// getOverloadedOperator - Retrieve the identifier
+ IdentifierInfo &getOverloadedOperator(OverloadedOperatorKind Op) {
+ return *OverloadedOperators[Op];
+ }
+
typedef HashTableTy::const_iterator iterator;
typedef HashTableTy::const_iterator const_iterator;
@@ -194,6 +216,7 @@ public:
void PrintStats() const;
void AddKeywords(const LangOptions &LangOpts);
+ void AddOverloadedOperators();
/// Emit - Serialize this IdentifierTable to a bitstream. This should
/// be called AFTER objects that externally reference the identifiers in the