2006-10-30 06:09:44 +08:00
|
|
|
//===--- IdentifierTable.cpp - Hash table for identifier lookup -----------===//
|
2006-06-18 13:43:12 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 03:59:25 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-06-18 13:43:12 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2006-07-05 01:53:21 +08:00
|
|
|
// This file implements the IdentifierInfo, IdentifierVisitor, and
|
2006-07-03 12:28:52 +08:00
|
|
|
// IdentifierTable interfaces.
|
2006-06-18 13:43:12 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2007-10-07 16:58:51 +08:00
|
|
|
#include "clang/Basic/IdentifierTable.h"
|
2006-10-18 14:07:05 +08:00
|
|
|
#include "clang/Basic/LangOptions.h"
|
2007-10-06 02:42:47 +08:00
|
|
|
#include "llvm/ADT/FoldingSet.h"
|
2007-10-06 04:15:24 +08:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2009-10-18 02:13:02 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2009-03-03 06:20:04 +08:00
|
|
|
#include <cstdio>
|
2007-10-24 06:18:37 +08:00
|
|
|
|
2006-06-18 13:43:12 +08:00
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2006-07-05 01:53:21 +08:00
|
|
|
// IdentifierInfo Implementation
|
2006-06-18 13:43:12 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-01-21 07:28:34 +08:00
|
|
|
IdentifierInfo::IdentifierInfo() {
|
2006-10-29 07:46:24 +08:00
|
|
|
TokenID = tok::identifier;
|
2008-11-07 00:32:23 +08:00
|
|
|
ObjCOrBuiltinID = 0;
|
2007-10-07 15:09:52 +08:00
|
|
|
HasMacro = false;
|
2006-10-29 07:46:24 +08:00
|
|
|
IsExtension = false;
|
|
|
|
IsPoisoned = false;
|
2006-11-22 01:23:33 +08:00
|
|
|
IsCPPOperatorKeyword = false;
|
2009-01-21 15:43:11 +08:00
|
|
|
NeedsHandleIdentifier = false;
|
2006-10-29 07:46:24 +08:00
|
|
|
FETokenInfo = 0;
|
2009-01-21 07:28:34 +08:00
|
|
|
Entry = 0;
|
2006-10-29 07:46:24 +08:00
|
|
|
}
|
|
|
|
|
2006-06-18 13:43:12 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// IdentifierTable Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-01-16 02:47:46 +08:00
|
|
|
IdentifierInfoLookup::~IdentifierInfoLookup() {}
|
|
|
|
|
2009-04-26 07:30:02 +08:00
|
|
|
ExternalIdentifierLookup::~ExternalIdentifierLookup() {}
|
|
|
|
|
2009-01-16 02:47:46 +08:00
|
|
|
IdentifierTable::IdentifierTable(const LangOptions &LangOpts,
|
|
|
|
IdentifierInfoLookup* externalLookup)
|
|
|
|
: HashTable(8192), // Start with space for 8K identifiers.
|
|
|
|
ExternalLookup(externalLookup) {
|
2006-10-30 07:49:15 +08:00
|
|
|
|
2006-10-27 11:59:10 +08:00
|
|
|
// Populate the identifier table with info about keywords for the current
|
|
|
|
// language.
|
2006-10-18 14:07:05 +08:00
|
|
|
AddKeywords(LangOpts);
|
2006-07-03 12:28:52 +08:00
|
|
|
}
|
2006-06-18 13:43:12 +08:00
|
|
|
|
2006-10-18 14:07:05 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Language Keyword Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-04-28 11:13:54 +08:00
|
|
|
// Constants for TokenKinds.def
|
|
|
|
namespace {
|
|
|
|
enum {
|
|
|
|
KEYALL = 1,
|
|
|
|
KEYC99 = 2,
|
|
|
|
KEYCXX = 4,
|
|
|
|
KEYCXX0X = 8,
|
|
|
|
KEYGNU = 16,
|
2009-06-26 07:25:15 +08:00
|
|
|
KEYMS = 32,
|
|
|
|
BOOLSUPPORT = 64
|
2009-04-28 11:13:54 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2006-10-18 14:07:05 +08:00
|
|
|
/// AddKeyword - This method is used to associate a token ID with specific
|
|
|
|
/// identifiers because they are language keywords. This causes the lexer to
|
|
|
|
/// automatically map matching identifiers to specialized token codes.
|
|
|
|
///
|
2007-07-16 12:18:29 +08:00
|
|
|
/// The C90/C99/CPP/CPP0x flags are set to 0 if the token should be
|
|
|
|
/// enabled in the specified langauge, set to 1 if it is an extension
|
|
|
|
/// in the specified language, and set to 2 if disabled in the
|
|
|
|
/// specified language.
|
2006-10-30 07:43:13 +08:00
|
|
|
static void AddKeyword(const char *Keyword, unsigned KWLen,
|
2009-04-28 11:13:54 +08:00
|
|
|
tok::TokenKind TokenCode, unsigned Flags,
|
2006-10-18 14:07:05 +08:00
|
|
|
const LangOptions &LangOpts, IdentifierTable &Table) {
|
2009-04-28 11:13:54 +08:00
|
|
|
unsigned AddResult = 0;
|
|
|
|
if (Flags & KEYALL) AddResult = 2;
|
|
|
|
else if (LangOpts.CPlusPlus && (Flags & KEYCXX)) AddResult = 2;
|
|
|
|
else if (LangOpts.CPlusPlus0x && (Flags & KEYCXX0X)) AddResult = 2;
|
|
|
|
else if (LangOpts.C99 && (Flags & KEYC99)) AddResult = 2;
|
|
|
|
else if (LangOpts.GNUMode && (Flags & KEYGNU)) AddResult = 1;
|
|
|
|
else if (LangOpts.Microsoft && (Flags & KEYMS)) AddResult = 1;
|
2009-06-30 09:26:17 +08:00
|
|
|
else if (LangOpts.Bool && (Flags & BOOLSUPPORT)) AddResult = 2;
|
2009-04-28 11:13:54 +08:00
|
|
|
|
|
|
|
// Don't add this keyword if disabled in this language.
|
|
|
|
if (AddResult == 0) return;
|
|
|
|
|
2006-10-30 07:43:13 +08:00
|
|
|
IdentifierInfo &Info = Table.get(Keyword, Keyword+KWLen);
|
2006-10-18 14:07:05 +08:00
|
|
|
Info.setTokenID(TokenCode);
|
2009-04-28 11:13:54 +08:00
|
|
|
Info.setIsExtensionToken(AddResult == 1);
|
2006-10-18 14:07:05 +08:00
|
|
|
}
|
|
|
|
|
2006-11-22 01:23:33 +08:00
|
|
|
/// AddCXXOperatorKeyword - Register a C++ operator keyword alternative
|
|
|
|
/// representations.
|
|
|
|
static void AddCXXOperatorKeyword(const char *Keyword, unsigned KWLen,
|
|
|
|
tok::TokenKind TokenCode,
|
|
|
|
IdentifierTable &Table) {
|
|
|
|
IdentifierInfo &Info = Table.get(Keyword, Keyword + KWLen);
|
|
|
|
Info.setTokenID(TokenCode);
|
2007-10-24 06:18:37 +08:00
|
|
|
Info.setIsCPlusPlusOperatorKeyword();
|
2006-11-22 01:23:33 +08:00
|
|
|
}
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
/// AddObjCKeyword - Register an Objective-C @keyword like "class" "selector" or
|
2006-10-18 14:07:05 +08:00
|
|
|
/// "property".
|
2009-09-09 23:08:12 +08:00
|
|
|
static void AddObjCKeyword(tok::ObjCKeywordKind ObjCID,
|
2006-10-18 14:07:05 +08:00
|
|
|
const char *Name, unsigned NameLen,
|
|
|
|
IdentifierTable &Table) {
|
|
|
|
Table.get(Name, Name+NameLen).setObjCKeywordID(ObjCID);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// AddKeywords - Add all keywords to the symbol table.
|
|
|
|
///
|
|
|
|
void IdentifierTable::AddKeywords(const LangOptions &LangOpts) {
|
|
|
|
// Add keywords and tokens for the current language.
|
|
|
|
#define KEYWORD(NAME, FLAGS) \
|
2006-10-30 07:43:13 +08:00
|
|
|
AddKeyword(#NAME, strlen(#NAME), tok::kw_ ## NAME, \
|
2009-04-28 11:13:54 +08:00
|
|
|
FLAGS, LangOpts, *this);
|
|
|
|
#define ALIAS(NAME, TOK, FLAGS) \
|
|
|
|
AddKeyword(NAME, strlen(NAME), tok::kw_ ## TOK, \
|
|
|
|
FLAGS, LangOpts, *this);
|
2006-11-22 01:23:33 +08:00
|
|
|
#define CXX_KEYWORD_OPERATOR(NAME, ALIAS) \
|
2006-12-04 15:48:37 +08:00
|
|
|
if (LangOpts.CXXOperatorNames) \
|
2006-11-22 01:23:33 +08:00
|
|
|
AddCXXOperatorKeyword(#NAME, strlen(#NAME), tok::ALIAS, *this);
|
2006-10-18 14:07:05 +08:00
|
|
|
#define OBJC1_AT_KEYWORD(NAME) \
|
|
|
|
if (LangOpts.ObjC1) \
|
|
|
|
AddObjCKeyword(tok::objc_##NAME, #NAME, strlen(#NAME), *this);
|
|
|
|
#define OBJC2_AT_KEYWORD(NAME) \
|
|
|
|
if (LangOpts.ObjC2) \
|
|
|
|
AddObjCKeyword(tok::objc_##NAME, #NAME, strlen(#NAME), *this);
|
|
|
|
#include "clang/Basic/TokenKinds.def"
|
|
|
|
}
|
|
|
|
|
2007-10-07 15:52:34 +08:00
|
|
|
tok::PPKeywordKind IdentifierInfo::getPPKeywordID() const {
|
|
|
|
// We use a perfect hash function here involving the length of the keyword,
|
|
|
|
// the first and third character. For preprocessor ID's there are no
|
|
|
|
// collisions (if there were, the switch below would complain about duplicate
|
|
|
|
// case values). Note that this depends on 'if' being null terminated.
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-10-07 15:52:34 +08:00
|
|
|
#define HASH(LEN, FIRST, THIRD) \
|
|
|
|
(LEN << 5) + (((FIRST-'a') + (THIRD-'a')) & 31)
|
|
|
|
#define CASE(LEN, FIRST, THIRD, NAME) \
|
|
|
|
case HASH(LEN, FIRST, THIRD): \
|
|
|
|
return memcmp(Name, #NAME, LEN) ? tok::pp_not_keyword : tok::pp_ ## NAME
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-10-07 15:52:34 +08:00
|
|
|
unsigned Len = getLength();
|
2007-10-11 04:59:57 +08:00
|
|
|
if (Len < 2) return tok::pp_not_keyword;
|
2009-10-18 02:13:02 +08:00
|
|
|
const char *Name = getNameStart();
|
2007-10-07 15:52:34 +08:00
|
|
|
switch (HASH(Len, Name[0], Name[2])) {
|
|
|
|
default: return tok::pp_not_keyword;
|
|
|
|
CASE( 2, 'i', '\0', if);
|
|
|
|
CASE( 4, 'e', 'i', elif);
|
|
|
|
CASE( 4, 'e', 's', else);
|
|
|
|
CASE( 4, 'l', 'n', line);
|
|
|
|
CASE( 4, 's', 'c', sccs);
|
|
|
|
CASE( 5, 'e', 'd', endif);
|
|
|
|
CASE( 5, 'e', 'r', error);
|
|
|
|
CASE( 5, 'i', 'e', ident);
|
|
|
|
CASE( 5, 'i', 'd', ifdef);
|
|
|
|
CASE( 5, 'u', 'd', undef);
|
|
|
|
|
|
|
|
CASE( 6, 'a', 's', assert);
|
|
|
|
CASE( 6, 'd', 'f', define);
|
|
|
|
CASE( 6, 'i', 'n', ifndef);
|
|
|
|
CASE( 6, 'i', 'p', import);
|
|
|
|
CASE( 6, 'p', 'a', pragma);
|
|
|
|
|
|
|
|
CASE( 7, 'd', 'f', defined);
|
|
|
|
CASE( 7, 'i', 'c', include);
|
|
|
|
CASE( 7, 'w', 'r', warning);
|
|
|
|
|
|
|
|
CASE( 8, 'u', 'a', unassert);
|
|
|
|
CASE(12, 'i', 'c', include_next);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-09 02:24:34 +08:00
|
|
|
CASE(16, '_', 'i', __include_macros);
|
2007-10-07 15:52:34 +08:00
|
|
|
#undef CASE
|
|
|
|
#undef HASH
|
|
|
|
}
|
|
|
|
}
|
2006-10-18 14:07:05 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Stats Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2006-06-18 13:43:12 +08:00
|
|
|
/// PrintStats - Print statistics about how well the identifier table is doing
|
|
|
|
/// at hashing identifiers.
|
|
|
|
void IdentifierTable::PrintStats() const {
|
2006-10-30 07:43:13 +08:00
|
|
|
unsigned NumBuckets = HashTable.getNumBuckets();
|
|
|
|
unsigned NumIdentifiers = HashTable.getNumItems();
|
|
|
|
unsigned NumEmptyBuckets = NumBuckets-NumIdentifiers;
|
2006-06-18 13:43:12 +08:00
|
|
|
unsigned AverageIdentifierSize = 0;
|
|
|
|
unsigned MaxIdentifierLength = 0;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2006-10-30 07:43:13 +08:00
|
|
|
// TODO: Figure out maximum times an identifier had to probe for -stats.
|
2009-01-21 07:28:34 +08:00
|
|
|
for (llvm::StringMap<IdentifierInfo*, llvm::BumpPtrAllocator>::const_iterator
|
2007-02-11 16:19:57 +08:00
|
|
|
I = HashTable.begin(), E = HashTable.end(); I != E; ++I) {
|
|
|
|
unsigned IdLen = I->getKeyLength();
|
|
|
|
AverageIdentifierSize += IdLen;
|
|
|
|
if (MaxIdentifierLength < IdLen)
|
|
|
|
MaxIdentifierLength = IdLen;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-06-16 07:05:46 +08:00
|
|
|
fprintf(stderr, "\n*** Identifier Table Stats:\n");
|
|
|
|
fprintf(stderr, "# Identifiers: %d\n", NumIdentifiers);
|
|
|
|
fprintf(stderr, "# Empty Buckets: %d\n", NumEmptyBuckets);
|
|
|
|
fprintf(stderr, "Hash density (#identifiers per bucket): %f\n",
|
|
|
|
NumIdentifiers/(double)NumBuckets);
|
|
|
|
fprintf(stderr, "Ave identifier length: %f\n",
|
|
|
|
(AverageIdentifierSize/(double)NumIdentifiers));
|
|
|
|
fprintf(stderr, "Max identifier length: %d\n", MaxIdentifierLength);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2006-06-18 13:43:12 +08:00
|
|
|
// Compute statistics about the memory allocated for identifiers.
|
2006-10-30 07:43:13 +08:00
|
|
|
HashTable.getAllocator().PrintStats();
|
2006-06-18 13:43:12 +08:00
|
|
|
}
|
Add SelectorInfo (similar in spirit to IdentifierInfo). The key difference is SelectorInfo is not string-oriented, it is a unique aggregate of IdentifierInfo's (using a folding set). SelectorInfo also has a richer API that simplifies the parser/action interface. 3 noteworthy benefits:
#1: It is cleaner. I never "liked" storing keyword selectors (i.e. foo:bar:baz) in the IdentifierTable.
#2: It is more space efficient. Since Cocoa keyword selectors can be quite long, this technique is space saving. For Cocoa.h, pulling the keyword selectors out saves ~180k. The cost of the SelectorInfo data is ~100k. Saves ~80k, or 43%.
#3: It results in many API simplifications. Here are some highlights:
- Removed 3 actions (ActOnKeywordMessage, ActOnUnaryMessage, & one flavor of ObjcBuildMethodDeclaration that was specific to unary messages).
- Removed 3 funky structs from DeclSpec.h (ObjcKeywordMessage, ObjcKeywordDecl, and ObjcKeywordInfo).
- Removed 2 ivars and 2 constructors from ObjCMessageExpr (fyi, this space savings has not been measured).
I am happy with the way it turned out (though it took a bit more hacking than I expected). Given the central role of selectors in ObjC, making sure this is "right" will pay dividends later.
Thanks to Chris for talking this through with me and suggesting this approach.
llvm-svn: 42395
2007-09-27 22:38:14 +08:00
|
|
|
|
2007-10-06 02:42:47 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// SelectorTable Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2007-10-06 04:15:24 +08:00
|
|
|
unsigned llvm::DenseMapInfo<clang::Selector>::getHashValue(clang::Selector S) {
|
|
|
|
return DenseMapInfo<void*>::getHashValue(S.getAsOpaquePtr());
|
|
|
|
}
|
|
|
|
|
2008-11-17 22:58:09 +08:00
|
|
|
namespace clang {
|
2007-10-06 02:42:47 +08:00
|
|
|
/// MultiKeywordSelector - One of these variable length records is kept for each
|
|
|
|
/// selector containing more than one keyword. We use a folding set
|
2009-09-09 23:08:12 +08:00
|
|
|
/// to unique aggregate names (keyword selectors in ObjC parlance). Access to
|
2007-10-06 02:42:47 +08:00
|
|
|
/// this class is provided strictly through Selector.
|
2009-09-09 23:08:12 +08:00
|
|
|
class MultiKeywordSelector
|
2008-11-17 22:58:09 +08:00
|
|
|
: public DeclarationNameExtra, public llvm::FoldingSetNode {
|
|
|
|
MultiKeywordSelector(unsigned nKeys) {
|
|
|
|
ExtraKindOrNumArgs = NUM_EXTRA_KINDS + nKeys;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
public:
|
2007-10-06 02:42:47 +08:00
|
|
|
// Constructor for keyword selectors.
|
|
|
|
MultiKeywordSelector(unsigned nKeys, IdentifierInfo **IIV) {
|
|
|
|
assert((nKeys > 1) && "not a multi-keyword selector");
|
2008-11-17 22:58:09 +08:00
|
|
|
ExtraKindOrNumArgs = NUM_EXTRA_KINDS + nKeys;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-10-06 02:42:47 +08:00
|
|
|
// Fill in the trailing keyword array.
|
|
|
|
IdentifierInfo **KeyInfo = reinterpret_cast<IdentifierInfo **>(this+1);
|
|
|
|
for (unsigned i = 0; i != nKeys; ++i)
|
|
|
|
KeyInfo[i] = IIV[i];
|
2009-09-09 23:08:12 +08:00
|
|
|
}
|
|
|
|
|
2007-10-07 09:33:16 +08:00
|
|
|
// getName - Derive the full selector name and return it.
|
|
|
|
std::string getName() const;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-11-17 22:58:09 +08:00
|
|
|
unsigned getNumArgs() const { return ExtraKindOrNumArgs - NUM_EXTRA_KINDS; }
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-10-06 02:42:47 +08:00
|
|
|
typedef IdentifierInfo *const *keyword_iterator;
|
|
|
|
keyword_iterator keyword_begin() const {
|
|
|
|
return reinterpret_cast<keyword_iterator>(this+1);
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
keyword_iterator keyword_end() const {
|
|
|
|
return keyword_begin()+getNumArgs();
|
2007-10-06 02:42:47 +08:00
|
|
|
}
|
2007-10-07 09:33:16 +08:00
|
|
|
IdentifierInfo *getIdentifierInfoForSlot(unsigned i) const {
|
2008-11-17 22:58:09 +08:00
|
|
|
assert(i < getNumArgs() && "getIdentifierInfoForSlot(): illegal index");
|
2007-10-06 02:42:47 +08:00
|
|
|
return keyword_begin()[i];
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
static void Profile(llvm::FoldingSetNodeID &ID,
|
2007-10-06 02:42:47 +08:00
|
|
|
keyword_iterator ArgTys, unsigned NumArgs) {
|
|
|
|
ID.AddInteger(NumArgs);
|
2007-10-07 09:33:16 +08:00
|
|
|
for (unsigned i = 0; i != NumArgs; ++i)
|
|
|
|
ID.AddPointer(ArgTys[i]);
|
2007-10-06 02:42:47 +08:00
|
|
|
}
|
|
|
|
void Profile(llvm::FoldingSetNodeID &ID) {
|
2008-11-17 22:58:09 +08:00
|
|
|
Profile(ID, keyword_begin(), getNumArgs());
|
2007-10-06 02:42:47 +08:00
|
|
|
}
|
|
|
|
};
|
2007-10-06 04:15:24 +08:00
|
|
|
} // end namespace clang.
|
2007-10-06 02:42:47 +08:00
|
|
|
|
|
|
|
unsigned Selector::getNumArgs() const {
|
|
|
|
unsigned IIF = getIdentifierInfoFlag();
|
|
|
|
if (IIF == ZeroArg)
|
|
|
|
return 0;
|
|
|
|
if (IIF == OneArg)
|
|
|
|
return 1;
|
|
|
|
// We point to a MultiKeywordSelector (pointer doesn't contain any flags).
|
|
|
|
MultiKeywordSelector *SI = reinterpret_cast<MultiKeywordSelector *>(InfoPtr);
|
2009-09-09 23:08:12 +08:00
|
|
|
return SI->getNumArgs();
|
2007-10-06 02:42:47 +08:00
|
|
|
}
|
|
|
|
|
2007-10-07 09:33:16 +08:00
|
|
|
IdentifierInfo *Selector::getIdentifierInfoForSlot(unsigned argIndex) const {
|
2009-04-27 06:20:50 +08:00
|
|
|
if (getIdentifierInfoFlag()) {
|
2007-10-07 09:33:16 +08:00
|
|
|
assert(argIndex == 0 && "illegal keyword index");
|
2009-04-27 06:20:50 +08:00
|
|
|
return getAsIdentifierInfo();
|
2007-10-06 02:42:47 +08:00
|
|
|
}
|
|
|
|
// We point to a MultiKeywordSelector (pointer doesn't contain any flags).
|
|
|
|
MultiKeywordSelector *SI = reinterpret_cast<MultiKeywordSelector *>(InfoPtr);
|
|
|
|
return SI->getIdentifierInfoForSlot(argIndex);
|
|
|
|
}
|
|
|
|
|
2007-10-07 09:33:16 +08:00
|
|
|
std::string MultiKeywordSelector::getName() const {
|
2009-10-18 02:13:02 +08:00
|
|
|
llvm::SmallString<256> Str;
|
|
|
|
llvm::raw_svector_ostream OS(Str);
|
2007-10-07 09:33:16 +08:00
|
|
|
for (keyword_iterator I = keyword_begin(), E = keyword_end(); I != E; ++I) {
|
|
|
|
if (*I)
|
2009-10-19 05:17:35 +08:00
|
|
|
OS << (*I)->getName();
|
2009-10-18 02:13:02 +08:00
|
|
|
OS << ':';
|
2007-10-07 09:33:16 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-10-18 02:13:02 +08:00
|
|
|
return OS.str();
|
2007-10-06 02:42:47 +08:00
|
|
|
}
|
|
|
|
|
2008-11-24 11:33:13 +08:00
|
|
|
std::string Selector::getAsString() const {
|
2009-04-27 06:20:50 +08:00
|
|
|
if (InfoPtr == 0)
|
|
|
|
return "<null selector>";
|
|
|
|
|
2009-03-07 07:36:28 +08:00
|
|
|
if (InfoPtr & ArgFlags) {
|
|
|
|
IdentifierInfo *II = getAsIdentifierInfo();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-07 09:22:02 +08:00
|
|
|
// If the number of arguments is 0 then II is guaranteed to not be null.
|
2009-03-07 07:36:28 +08:00
|
|
|
if (getNumArgs() == 0)
|
2009-10-19 05:17:35 +08:00
|
|
|
return II->getName();
|
2009-10-18 02:13:02 +08:00
|
|
|
|
|
|
|
if (!II)
|
|
|
|
return ":";
|
2009-03-07 07:36:28 +08:00
|
|
|
|
2009-10-19 05:17:35 +08:00
|
|
|
return II->getName().str() + ":";
|
2007-10-06 02:42:47 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-10-07 09:33:16 +08:00
|
|
|
// We have a multiple keyword selector (no embedded flags).
|
|
|
|
return reinterpret_cast<MultiKeywordSelector *>(InfoPtr)->getName();
|
2007-10-06 02:42:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-04 13:35:38 +08:00
|
|
|
namespace {
|
|
|
|
struct SelectorTableImpl {
|
|
|
|
llvm::FoldingSet<MultiKeywordSelector> Table;
|
|
|
|
llvm::BumpPtrAllocator Allocator;
|
|
|
|
};
|
|
|
|
} // end anonymous namespace.
|
|
|
|
|
|
|
|
static SelectorTableImpl &getSelectorTableImpl(void *P) {
|
|
|
|
return *static_cast<SelectorTableImpl*>(P);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 10:00:24 +08:00
|
|
|
Selector SelectorTable::getSelector(unsigned nKeys, IdentifierInfo **IIV) {
|
|
|
|
if (nKeys < 2)
|
|
|
|
return Selector(IIV[0], nKeys);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-04 13:35:38 +08:00
|
|
|
SelectorTableImpl &SelTabImpl = getSelectorTableImpl(Impl);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-10-06 02:42:47 +08:00
|
|
|
// Unique selector, to guarantee there is one per name.
|
|
|
|
llvm::FoldingSetNodeID ID;
|
|
|
|
MultiKeywordSelector::Profile(ID, IIV, nKeys);
|
|
|
|
|
|
|
|
void *InsertPos = 0;
|
2009-03-04 13:35:38 +08:00
|
|
|
if (MultiKeywordSelector *SI =
|
|
|
|
SelTabImpl.Table.FindNodeOrInsertPos(ID, InsertPos))
|
2007-10-06 02:42:47 +08:00
|
|
|
return Selector(SI);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-10-06 02:42:47 +08:00
|
|
|
// MultiKeywordSelector objects are not allocated with new because they have a
|
|
|
|
// variable size array (for parameter types) at the end of them.
|
2009-03-04 13:35:38 +08:00
|
|
|
unsigned Size = sizeof(MultiKeywordSelector) + nKeys*sizeof(IdentifierInfo *);
|
|
|
|
MultiKeywordSelector *SI =
|
2009-09-09 23:08:12 +08:00
|
|
|
(MultiKeywordSelector*)SelTabImpl.Allocator.Allocate(Size,
|
2009-03-04 13:35:38 +08:00
|
|
|
llvm::alignof<MultiKeywordSelector>());
|
2007-10-06 02:42:47 +08:00
|
|
|
new (SI) MultiKeywordSelector(nKeys, IIV);
|
2009-03-04 13:35:38 +08:00
|
|
|
SelTabImpl.Table.InsertNode(SI, InsertPos);
|
2007-10-06 02:42:47 +08:00
|
|
|
return Selector(SI);
|
|
|
|
}
|
|
|
|
|
|
|
|
SelectorTable::SelectorTable() {
|
2009-03-04 13:35:38 +08:00
|
|
|
Impl = new SelectorTableImpl();
|
2007-10-06 02:42:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SelectorTable::~SelectorTable() {
|
2009-03-04 13:35:38 +08:00
|
|
|
delete &getSelectorTableImpl(Impl);
|
2007-10-06 02:42:47 +08:00
|
|
|
}
|
|
|
|
|
2009-11-04 08:56:37 +08:00
|
|
|
const char *clang::getOperatorSpelling(OverloadedOperatorKind Operator) {
|
|
|
|
switch (Operator) {
|
|
|
|
case OO_None:
|
|
|
|
case NUM_OVERLOADED_OPERATORS:
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
|
|
|
|
case OO_##Name: return Spelling;
|
|
|
|
#include "clang/Basic/OperatorKinds.def"
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|