Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- IdentifierTable.cpp - Hash table for identifier lookup -----------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the IdentifierInfo, IdentifierVisitor, and |
| 11 | // IdentifierTable interfaces. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Chris Lattner | c7229c3 | 2007-10-07 08:58:51 +0000 | [diff] [blame] | 15 | #include "clang/Basic/IdentifierTable.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 16 | #include "clang/Basic/LangOptions.h" |
Chris Lattner | 8599426 | 2007-10-05 20:15:24 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/DenseMap.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/FoldingSet.h" |
Benjamin Kramer | 8fe83e1 | 2012-02-04 13:45:25 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/SmallString.h" |
David Blaikie | 7530c03 | 2012-01-17 06:56:22 +0000 | [diff] [blame] | 20 | #include "llvm/Support/ErrorHandling.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 21 | #include "llvm/Support/raw_ostream.h" |
Joerg Sonnenberger | 7094dee | 2012-08-10 10:58:18 +0000 | [diff] [blame] | 22 | #include <cctype> |
Chris Lattner | 3daed52 | 2009-03-02 22:20:04 +0000 | [diff] [blame] | 23 | #include <cstdio> |
Ted Kremenek | c637e6b | 2007-10-23 22:18:37 +0000 | [diff] [blame] | 24 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 25 | using namespace clang; |
| 26 | |
| 27 | //===----------------------------------------------------------------------===// |
| 28 | // IdentifierInfo Implementation |
| 29 | //===----------------------------------------------------------------------===// |
| 30 | |
Ted Kremenek | ea9c26b | 2009-01-20 23:28:34 +0000 | [diff] [blame] | 31 | IdentifierInfo::IdentifierInfo() { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 32 | TokenID = tok::identifier; |
Douglas Gregor | 5142af3 | 2008-11-06 16:32:23 +0000 | [diff] [blame] | 33 | ObjCOrBuiltinID = 0; |
Chris Lattner | 4365a7e | 2007-10-07 07:09:52 +0000 | [diff] [blame] | 34 | HasMacro = false; |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 35 | HadMacro = false; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 36 | IsExtension = false; |
Richard Smith | 98d86b9 | 2011-10-11 19:57:52 +0000 | [diff] [blame] | 37 | IsCXX11CompatKeyword = false; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 38 | IsPoisoned = false; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 39 | IsCPPOperatorKeyword = false; |
Chris Lattner | 6a170eb | 2009-01-21 07:43:11 +0000 | [diff] [blame] | 40 | NeedsHandleIdentifier = false; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 41 | IsFromAST = false; |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 42 | ChangedAfterLoad = false; |
Argyrios Kyrtzidis | 646395b | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 43 | RevertedTokenID = false; |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 44 | OutOfDate = false; |
Ted Kremenek | 32ad2ee | 2012-03-01 22:07:04 +0000 | [diff] [blame] | 45 | IsModulesImport = false; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 46 | FETokenInfo = 0; |
Ted Kremenek | ea9c26b | 2009-01-20 23:28:34 +0000 | [diff] [blame] | 47 | Entry = 0; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 50 | //===----------------------------------------------------------------------===// |
| 51 | // IdentifierTable Implementation |
| 52 | //===----------------------------------------------------------------------===// |
| 53 | |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 54 | IdentifierIterator::~IdentifierIterator() { } |
| 55 | |
Ted Kremenek | 72b1b15 | 2009-01-15 18:47:46 +0000 | [diff] [blame] | 56 | IdentifierInfoLookup::~IdentifierInfoLookup() {} |
| 57 | |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 58 | namespace { |
| 59 | /// \brief A simple identifier lookup iterator that represents an |
| 60 | /// empty sequence of identifiers. |
| 61 | class EmptyLookupIterator : public IdentifierIterator |
| 62 | { |
| 63 | public: |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 64 | virtual StringRef Next() { return StringRef(); } |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 65 | }; |
| 66 | } |
| 67 | |
| 68 | IdentifierIterator *IdentifierInfoLookup::getIdentifiers() const { |
| 69 | return new EmptyLookupIterator(); |
| 70 | } |
| 71 | |
Douglas Gregor | 8c5a760 | 2009-04-25 23:30:02 +0000 | [diff] [blame] | 72 | ExternalIdentifierLookup::~ExternalIdentifierLookup() {} |
| 73 | |
Ted Kremenek | 72b1b15 | 2009-01-15 18:47:46 +0000 | [diff] [blame] | 74 | IdentifierTable::IdentifierTable(const LangOptions &LangOpts, |
| 75 | IdentifierInfoLookup* externalLookup) |
| 76 | : HashTable(8192), // Start with space for 8K identifiers. |
| 77 | ExternalLookup(externalLookup) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 78 | |
| 79 | // Populate the identifier table with info about keywords for the current |
| 80 | // language. |
| 81 | AddKeywords(LangOpts); |
Ted Kremenek | f15e114 | 2012-03-01 22:53:32 +0000 | [diff] [blame] | 82 | |
| 83 | |
| 84 | // Add the '_experimental_modules_import' contextual keyword. |
Douglas Gregor | 1b257af | 2012-12-11 22:11:52 +0000 | [diff] [blame] | 85 | get("import").setModulesImport(true); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | //===----------------------------------------------------------------------===// |
| 89 | // Language Keyword Implementation |
| 90 | //===----------------------------------------------------------------------===// |
| 91 | |
Eli Friedman | eb32fde | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 92 | // Constants for TokenKinds.def |
| 93 | namespace { |
| 94 | enum { |
Dylan Noblesmith | 6792292 | 2011-04-09 13:34:05 +0000 | [diff] [blame] | 95 | KEYC99 = 0x1, |
| 96 | KEYCXX = 0x2, |
Richard Smith | 4e24f0f | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 97 | KEYCXX11 = 0x4, |
Dylan Noblesmith | 6792292 | 2011-04-09 13:34:05 +0000 | [diff] [blame] | 98 | KEYGNU = 0x8, |
| 99 | KEYMS = 0x10, |
| 100 | BOOLSUPPORT = 0x20, |
| 101 | KEYALTIVEC = 0x40, |
| 102 | KEYNOCXX = 0x80, |
| 103 | KEYBORLAND = 0x100, |
| 104 | KEYOPENCL = 0x200, |
Benjamin Kramer | ffbe9b9 | 2011-12-23 17:00:35 +0000 | [diff] [blame] | 105 | KEYC11 = 0x400, |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 106 | KEYARC = 0x800, |
Francois Pichet | a5a4cba | 2012-07-24 06:17:24 +0000 | [diff] [blame] | 107 | KEYNOMS = 0x01000, |
Abramo Bagnara | 5b86ffd | 2012-09-05 17:30:57 +0000 | [diff] [blame] | 108 | WCHARSUPPORT = 0x02000, |
Francois Pichet | a5a4cba | 2012-07-24 06:17:24 +0000 | [diff] [blame] | 109 | KEYALL = (0xffff & ~KEYNOMS) // Because KEYNOMS is used to exclude. |
Eli Friedman | eb32fde | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 110 | }; |
| 111 | } |
| 112 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 113 | /// AddKeyword - This method is used to associate a token ID with specific |
| 114 | /// identifiers because they are language keywords. This causes the lexer to |
| 115 | /// automatically map matching identifiers to specialized token codes. |
| 116 | /// |
Richard Smith | 98d86b9 | 2011-10-11 19:57:52 +0000 | [diff] [blame] | 117 | /// The C90/C99/CPP/CPP0x flags are set to 3 if the token is a keyword in a |
| 118 | /// future language standard, set to 2 if the token should be enabled in the |
Nick Lewycky | 0be8fb5 | 2012-03-11 23:14:21 +0000 | [diff] [blame] | 119 | /// specified language, set to 1 if it is an extension in the specified |
Richard Smith | 98d86b9 | 2011-10-11 19:57:52 +0000 | [diff] [blame] | 120 | /// language, and set to 0 if disabled in the specified language. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 121 | static void AddKeyword(StringRef Keyword, |
Eli Friedman | eb32fde | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 122 | tok::TokenKind TokenCode, unsigned Flags, |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 123 | const LangOptions &LangOpts, IdentifierTable &Table) { |
Eli Friedman | eb32fde | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 124 | unsigned AddResult = 0; |
Dylan Noblesmith | 6792292 | 2011-04-09 13:34:05 +0000 | [diff] [blame] | 125 | if (Flags == KEYALL) AddResult = 2; |
Eli Friedman | eb32fde | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 126 | else if (LangOpts.CPlusPlus && (Flags & KEYCXX)) AddResult = 2; |
Richard Smith | 4e24f0f | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 127 | else if (LangOpts.CPlusPlus11 && (Flags & KEYCXX11)) AddResult = 2; |
Eli Friedman | eb32fde | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 128 | else if (LangOpts.C99 && (Flags & KEYC99)) AddResult = 2; |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 129 | else if (LangOpts.GNUKeywords && (Flags & KEYGNU)) AddResult = 1; |
Francois Pichet | 62ec1f2 | 2011-09-17 17:15:52 +0000 | [diff] [blame] | 130 | else if (LangOpts.MicrosoftExt && (Flags & KEYMS)) AddResult = 1; |
Dawn Perchik | 52fc314 | 2010-09-03 01:29:35 +0000 | [diff] [blame] | 131 | else if (LangOpts.Borland && (Flags & KEYBORLAND)) AddResult = 1; |
Chris Lattner | e4f2142 | 2009-06-30 01:26:17 +0000 | [diff] [blame] | 132 | else if (LangOpts.Bool && (Flags & BOOLSUPPORT)) AddResult = 2; |
Abramo Bagnara | 5b86ffd | 2012-09-05 17:30:57 +0000 | [diff] [blame] | 133 | else if (LangOpts.WChar && (Flags & WCHARSUPPORT)) AddResult = 2; |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 134 | else if (LangOpts.AltiVec && (Flags & KEYALTIVEC)) AddResult = 2; |
Peter Collingbourne | f315fa8 | 2011-02-14 01:42:53 +0000 | [diff] [blame] | 135 | else if (LangOpts.OpenCL && (Flags & KEYOPENCL)) AddResult = 2; |
Douglas Gregor | 3a43d8d | 2010-10-13 20:00:38 +0000 | [diff] [blame] | 136 | else if (!LangOpts.CPlusPlus && (Flags & KEYNOCXX)) AddResult = 2; |
Benjamin Kramer | ffbe9b9 | 2011-12-23 17:00:35 +0000 | [diff] [blame] | 137 | else if (LangOpts.C11 && (Flags & KEYC11)) AddResult = 2; |
Fariborz Jahanian | 00852e4 | 2011-12-19 21:06:15 +0000 | [diff] [blame] | 138 | // We treat bridge casts as objective-C keywords so we can warn on them |
| 139 | // in non-arc mode. |
| 140 | else if (LangOpts.ObjC2 && (Flags & KEYARC)) AddResult = 2; |
Richard Smith | 4e24f0f | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 141 | else if (LangOpts.CPlusPlus && (Flags & KEYCXX11)) AddResult = 3; |
Richard Smith | 98d86b9 | 2011-10-11 19:57:52 +0000 | [diff] [blame] | 142 | |
Francois Pichet | dfd110c | 2012-07-22 11:32:41 +0000 | [diff] [blame] | 143 | // Don't add this keyword under MicrosoftMode. |
| 144 | if (LangOpts.MicrosoftMode && (Flags & KEYNOMS)) |
| 145 | return; |
Eli Friedman | eb32fde | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 146 | // Don't add this keyword if disabled in this language. |
| 147 | if (AddResult == 0) return; |
| 148 | |
Richard Smith | 98d86b9 | 2011-10-11 19:57:52 +0000 | [diff] [blame] | 149 | IdentifierInfo &Info = |
| 150 | Table.get(Keyword, AddResult == 3 ? tok::identifier : TokenCode); |
Eli Friedman | eb32fde | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 151 | Info.setIsExtensionToken(AddResult == 1); |
Richard Smith | 98d86b9 | 2011-10-11 19:57:52 +0000 | [diff] [blame] | 152 | Info.setIsCXX11CompatKeyword(AddResult == 3); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 153 | } |
| 154 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 155 | /// AddCXXOperatorKeyword - Register a C++ operator keyword alternative |
| 156 | /// representations. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 157 | static void AddCXXOperatorKeyword(StringRef Keyword, |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 158 | tok::TokenKind TokenCode, |
| 159 | IdentifierTable &Table) { |
Argyrios Kyrtzidis | 646395b | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 160 | IdentifierInfo &Info = Table.get(Keyword, TokenCode); |
Ted Kremenek | c637e6b | 2007-10-23 22:18:37 +0000 | [diff] [blame] | 161 | Info.setIsCPlusPlusOperatorKeyword(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 162 | } |
| 163 | |
James Dennett | 6557d13 | 2012-06-15 21:27:44 +0000 | [diff] [blame] | 164 | /// AddObjCKeyword - Register an Objective-C \@keyword like "class" "selector" |
| 165 | /// or "property". |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 166 | static void AddObjCKeyword(StringRef Name, |
Kovarththanan Rajaratnam | 50acf24 | 2010-03-12 11:27:37 +0000 | [diff] [blame] | 167 | tok::ObjCKeywordKind ObjCID, |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 168 | IdentifierTable &Table) { |
Kovarththanan Rajaratnam | 50acf24 | 2010-03-12 11:27:37 +0000 | [diff] [blame] | 169 | Table.get(Name).setObjCKeywordID(ObjCID); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | /// AddKeywords - Add all keywords to the symbol table. |
| 173 | /// |
| 174 | void IdentifierTable::AddKeywords(const LangOptions &LangOpts) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 175 | // Add keywords and tokens for the current language. |
| 176 | #define KEYWORD(NAME, FLAGS) \ |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 177 | AddKeyword(StringRef(#NAME), tok::kw_ ## NAME, \ |
Eli Friedman | eb32fde | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 178 | FLAGS, LangOpts, *this); |
| 179 | #define ALIAS(NAME, TOK, FLAGS) \ |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 180 | AddKeyword(StringRef(NAME), tok::kw_ ## TOK, \ |
Eli Friedman | eb32fde | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 181 | FLAGS, LangOpts, *this); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 182 | #define CXX_KEYWORD_OPERATOR(NAME, ALIAS) \ |
| 183 | if (LangOpts.CXXOperatorNames) \ |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 184 | AddCXXOperatorKeyword(StringRef(#NAME), tok::ALIAS, *this); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 185 | #define OBJC1_AT_KEYWORD(NAME) \ |
| 186 | if (LangOpts.ObjC1) \ |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 187 | AddObjCKeyword(StringRef(#NAME), tok::objc_##NAME, *this); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 188 | #define OBJC2_AT_KEYWORD(NAME) \ |
| 189 | if (LangOpts.ObjC2) \ |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 190 | AddObjCKeyword(StringRef(#NAME), tok::objc_##NAME, *this); |
John McCall | a5fc472 | 2011-04-09 22:50:59 +0000 | [diff] [blame] | 191 | #define TESTING_KEYWORD(NAME, FLAGS) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 192 | #include "clang/Basic/TokenKinds.def" |
John McCall | a5fc472 | 2011-04-09 22:50:59 +0000 | [diff] [blame] | 193 | |
| 194 | if (LangOpts.ParseUnknownAnytype) |
| 195 | AddKeyword("__unknown_anytype", tok::kw___unknown_anytype, KEYALL, |
| 196 | LangOpts, *this); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 197 | } |
| 198 | |
Chris Lattner | 387b98d | 2007-10-07 07:52:34 +0000 | [diff] [blame] | 199 | tok::PPKeywordKind IdentifierInfo::getPPKeywordID() const { |
| 200 | // We use a perfect hash function here involving the length of the keyword, |
| 201 | // the first and third character. For preprocessor ID's there are no |
| 202 | // collisions (if there were, the switch below would complain about duplicate |
| 203 | // case values). Note that this depends on 'if' being null terminated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 204 | |
Chris Lattner | 387b98d | 2007-10-07 07:52:34 +0000 | [diff] [blame] | 205 | #define HASH(LEN, FIRST, THIRD) \ |
| 206 | (LEN << 5) + (((FIRST-'a') + (THIRD-'a')) & 31) |
| 207 | #define CASE(LEN, FIRST, THIRD, NAME) \ |
| 208 | case HASH(LEN, FIRST, THIRD): \ |
| 209 | return memcmp(Name, #NAME, LEN) ? tok::pp_not_keyword : tok::pp_ ## NAME |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 210 | |
Chris Lattner | 387b98d | 2007-10-07 07:52:34 +0000 | [diff] [blame] | 211 | unsigned Len = getLength(); |
Chris Lattner | a31f030 | 2007-10-10 20:59:57 +0000 | [diff] [blame] | 212 | if (Len < 2) return tok::pp_not_keyword; |
Daniel Dunbar | 76b61cc | 2009-10-17 18:13:02 +0000 | [diff] [blame] | 213 | const char *Name = getNameStart(); |
Chris Lattner | 387b98d | 2007-10-07 07:52:34 +0000 | [diff] [blame] | 214 | switch (HASH(Len, Name[0], Name[2])) { |
| 215 | default: return tok::pp_not_keyword; |
| 216 | CASE( 2, 'i', '\0', if); |
| 217 | CASE( 4, 'e', 'i', elif); |
| 218 | CASE( 4, 'e', 's', else); |
| 219 | CASE( 4, 'l', 'n', line); |
| 220 | CASE( 4, 's', 'c', sccs); |
| 221 | CASE( 5, 'e', 'd', endif); |
| 222 | CASE( 5, 'e', 'r', error); |
| 223 | CASE( 5, 'i', 'e', ident); |
| 224 | CASE( 5, 'i', 'd', ifdef); |
| 225 | CASE( 5, 'u', 'd', undef); |
| 226 | |
| 227 | CASE( 6, 'a', 's', assert); |
| 228 | CASE( 6, 'd', 'f', define); |
| 229 | CASE( 6, 'i', 'n', ifndef); |
| 230 | CASE( 6, 'i', 'p', import); |
| 231 | CASE( 6, 'p', 'a', pragma); |
Douglas Gregor | 94ad28b | 2012-01-03 18:24:14 +0000 | [diff] [blame] | 232 | |
Chris Lattner | 387b98d | 2007-10-07 07:52:34 +0000 | [diff] [blame] | 233 | CASE( 7, 'd', 'f', defined); |
| 234 | CASE( 7, 'i', 'c', include); |
| 235 | CASE( 7, 'w', 'r', warning); |
| 236 | |
| 237 | CASE( 8, 'u', 'a', unassert); |
| 238 | CASE(12, 'i', 'c', include_next); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 239 | |
Douglas Gregor | 1ac13c3 | 2012-01-03 19:48:16 +0000 | [diff] [blame] | 240 | CASE(14, '_', 'p', __public_macro); |
| 241 | |
| 242 | CASE(15, '_', 'p', __private_macro); |
| 243 | |
Chris Lattner | b8e240e | 2009-04-08 18:24:34 +0000 | [diff] [blame] | 244 | CASE(16, '_', 'i', __include_macros); |
Chris Lattner | 387b98d | 2007-10-07 07:52:34 +0000 | [diff] [blame] | 245 | #undef CASE |
| 246 | #undef HASH |
| 247 | } |
| 248 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 249 | |
| 250 | //===----------------------------------------------------------------------===// |
| 251 | // Stats Implementation |
| 252 | //===----------------------------------------------------------------------===// |
| 253 | |
| 254 | /// PrintStats - Print statistics about how well the identifier table is doing |
| 255 | /// at hashing identifiers. |
| 256 | void IdentifierTable::PrintStats() const { |
| 257 | unsigned NumBuckets = HashTable.getNumBuckets(); |
| 258 | unsigned NumIdentifiers = HashTable.getNumItems(); |
| 259 | unsigned NumEmptyBuckets = NumBuckets-NumIdentifiers; |
| 260 | unsigned AverageIdentifierSize = 0; |
| 261 | unsigned MaxIdentifierLength = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 262 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 263 | // TODO: Figure out maximum times an identifier had to probe for -stats. |
Ted Kremenek | ea9c26b | 2009-01-20 23:28:34 +0000 | [diff] [blame] | 264 | for (llvm::StringMap<IdentifierInfo*, llvm::BumpPtrAllocator>::const_iterator |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 265 | I = HashTable.begin(), E = HashTable.end(); I != E; ++I) { |
| 266 | unsigned IdLen = I->getKeyLength(); |
| 267 | AverageIdentifierSize += IdLen; |
| 268 | if (MaxIdentifierLength < IdLen) |
| 269 | MaxIdentifierLength = IdLen; |
| 270 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 271 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 272 | fprintf(stderr, "\n*** Identifier Table Stats:\n"); |
| 273 | fprintf(stderr, "# Identifiers: %d\n", NumIdentifiers); |
| 274 | fprintf(stderr, "# Empty Buckets: %d\n", NumEmptyBuckets); |
| 275 | fprintf(stderr, "Hash density (#identifiers per bucket): %f\n", |
| 276 | NumIdentifiers/(double)NumBuckets); |
| 277 | fprintf(stderr, "Ave identifier length: %f\n", |
| 278 | (AverageIdentifierSize/(double)NumIdentifiers)); |
| 279 | fprintf(stderr, "Max identifier length: %d\n", MaxIdentifierLength); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 280 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 281 | // Compute statistics about the memory allocated for identifiers. |
| 282 | HashTable.getAllocator().PrintStats(); |
| 283 | } |
Steve Naroff | 68d331a | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 284 | |
Steve Naroff | 29238a0 | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 285 | //===----------------------------------------------------------------------===// |
| 286 | // SelectorTable Implementation |
| 287 | //===----------------------------------------------------------------------===// |
| 288 | |
Chris Lattner | 8599426 | 2007-10-05 20:15:24 +0000 | [diff] [blame] | 289 | unsigned llvm::DenseMapInfo<clang::Selector>::getHashValue(clang::Selector S) { |
| 290 | return DenseMapInfo<void*>::getHashValue(S.getAsOpaquePtr()); |
| 291 | } |
| 292 | |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 293 | namespace clang { |
Steve Naroff | 29238a0 | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 294 | /// MultiKeywordSelector - One of these variable length records is kept for each |
| 295 | /// selector containing more than one keyword. We use a folding set |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 296 | /// to unique aggregate names (keyword selectors in ObjC parlance). Access to |
Steve Naroff | 29238a0 | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 297 | /// this class is provided strictly through Selector. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 298 | class MultiKeywordSelector |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 299 | : public DeclarationNameExtra, public llvm::FoldingSetNode { |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 300 | MultiKeywordSelector(unsigned nKeys) { |
| 301 | ExtraKindOrNumArgs = NUM_EXTRA_KINDS + nKeys; |
| 302 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 303 | public: |
Steve Naroff | 29238a0 | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 304 | // Constructor for keyword selectors. |
| 305 | MultiKeywordSelector(unsigned nKeys, IdentifierInfo **IIV) { |
| 306 | assert((nKeys > 1) && "not a multi-keyword selector"); |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 307 | ExtraKindOrNumArgs = NUM_EXTRA_KINDS + nKeys; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 308 | |
Steve Naroff | 29238a0 | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 309 | // Fill in the trailing keyword array. |
| 310 | IdentifierInfo **KeyInfo = reinterpret_cast<IdentifierInfo **>(this+1); |
| 311 | for (unsigned i = 0; i != nKeys; ++i) |
| 312 | KeyInfo[i] = IIV[i]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 313 | } |
| 314 | |
Chris Lattner | f836e3f | 2007-10-07 01:33:16 +0000 | [diff] [blame] | 315 | // getName - Derive the full selector name and return it. |
| 316 | std::string getName() const; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 317 | |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 318 | unsigned getNumArgs() const { return ExtraKindOrNumArgs - NUM_EXTRA_KINDS; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 319 | |
Steve Naroff | 29238a0 | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 320 | typedef IdentifierInfo *const *keyword_iterator; |
| 321 | keyword_iterator keyword_begin() const { |
| 322 | return reinterpret_cast<keyword_iterator>(this+1); |
| 323 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 324 | keyword_iterator keyword_end() const { |
| 325 | return keyword_begin()+getNumArgs(); |
Steve Naroff | 29238a0 | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 326 | } |
Chris Lattner | f836e3f | 2007-10-07 01:33:16 +0000 | [diff] [blame] | 327 | IdentifierInfo *getIdentifierInfoForSlot(unsigned i) const { |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 328 | assert(i < getNumArgs() && "getIdentifierInfoForSlot(): illegal index"); |
Steve Naroff | 29238a0 | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 329 | return keyword_begin()[i]; |
| 330 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 331 | static void Profile(llvm::FoldingSetNodeID &ID, |
Steve Naroff | 29238a0 | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 332 | keyword_iterator ArgTys, unsigned NumArgs) { |
| 333 | ID.AddInteger(NumArgs); |
Chris Lattner | f836e3f | 2007-10-07 01:33:16 +0000 | [diff] [blame] | 334 | for (unsigned i = 0; i != NumArgs; ++i) |
| 335 | ID.AddPointer(ArgTys[i]); |
Steve Naroff | 29238a0 | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 336 | } |
| 337 | void Profile(llvm::FoldingSetNodeID &ID) { |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 338 | Profile(ID, keyword_begin(), getNumArgs()); |
Steve Naroff | 29238a0 | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 339 | } |
| 340 | }; |
Chris Lattner | 8599426 | 2007-10-05 20:15:24 +0000 | [diff] [blame] | 341 | } // end namespace clang. |
Steve Naroff | 29238a0 | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 342 | |
| 343 | unsigned Selector::getNumArgs() const { |
| 344 | unsigned IIF = getIdentifierInfoFlag(); |
Douglas Gregor | 51603be | 2012-05-04 18:24:37 +0000 | [diff] [blame] | 345 | if (IIF <= ZeroArg) |
Steve Naroff | 29238a0 | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 346 | return 0; |
| 347 | if (IIF == OneArg) |
| 348 | return 1; |
Douglas Gregor | 51603be | 2012-05-04 18:24:37 +0000 | [diff] [blame] | 349 | // We point to a MultiKeywordSelector. |
| 350 | MultiKeywordSelector *SI = getMultiKeywordSelector(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 351 | return SI->getNumArgs(); |
Steve Naroff | 29238a0 | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 352 | } |
| 353 | |
Chris Lattner | f836e3f | 2007-10-07 01:33:16 +0000 | [diff] [blame] | 354 | IdentifierInfo *Selector::getIdentifierInfoForSlot(unsigned argIndex) const { |
Douglas Gregor | 51603be | 2012-05-04 18:24:37 +0000 | [diff] [blame] | 355 | if (getIdentifierInfoFlag() < MultiArg) { |
Chris Lattner | f836e3f | 2007-10-07 01:33:16 +0000 | [diff] [blame] | 356 | assert(argIndex == 0 && "illegal keyword index"); |
Douglas Gregor | 405bad0 | 2009-04-26 22:20:50 +0000 | [diff] [blame] | 357 | return getAsIdentifierInfo(); |
Steve Naroff | 29238a0 | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 358 | } |
Douglas Gregor | 51603be | 2012-05-04 18:24:37 +0000 | [diff] [blame] | 359 | // We point to a MultiKeywordSelector. |
| 360 | MultiKeywordSelector *SI = getMultiKeywordSelector(); |
Steve Naroff | 29238a0 | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 361 | return SI->getIdentifierInfoForSlot(argIndex); |
| 362 | } |
| 363 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 364 | StringRef Selector::getNameForSlot(unsigned int argIndex) const { |
Douglas Gregor | 813d834 | 2011-02-18 22:29:55 +0000 | [diff] [blame] | 365 | IdentifierInfo *II = getIdentifierInfoForSlot(argIndex); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 366 | return II? II->getName() : StringRef(); |
Douglas Gregor | 813d834 | 2011-02-18 22:29:55 +0000 | [diff] [blame] | 367 | } |
| 368 | |
Chris Lattner | f836e3f | 2007-10-07 01:33:16 +0000 | [diff] [blame] | 369 | std::string MultiKeywordSelector::getName() const { |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 370 | SmallString<256> Str; |
Daniel Dunbar | 76b61cc | 2009-10-17 18:13:02 +0000 | [diff] [blame] | 371 | llvm::raw_svector_ostream OS(Str); |
Chris Lattner | f836e3f | 2007-10-07 01:33:16 +0000 | [diff] [blame] | 372 | for (keyword_iterator I = keyword_begin(), E = keyword_end(); I != E; ++I) { |
| 373 | if (*I) |
Daniel Dunbar | 01eb9b9 | 2009-10-18 21:17:35 +0000 | [diff] [blame] | 374 | OS << (*I)->getName(); |
Daniel Dunbar | 76b61cc | 2009-10-17 18:13:02 +0000 | [diff] [blame] | 375 | OS << ':'; |
Steve Naroff | 29238a0 | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 376 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 377 | |
Daniel Dunbar | 76b61cc | 2009-10-17 18:13:02 +0000 | [diff] [blame] | 378 | return OS.str(); |
Steve Naroff | 29238a0 | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 379 | } |
| 380 | |
Chris Lattner | 077bf5e | 2008-11-24 03:33:13 +0000 | [diff] [blame] | 381 | std::string Selector::getAsString() const { |
Douglas Gregor | 405bad0 | 2009-04-26 22:20:50 +0000 | [diff] [blame] | 382 | if (InfoPtr == 0) |
| 383 | return "<null selector>"; |
| 384 | |
Douglas Gregor | 51603be | 2012-05-04 18:24:37 +0000 | [diff] [blame] | 385 | if (getIdentifierInfoFlag() < MultiArg) { |
Ted Kremenek | f5ed396 | 2009-03-06 23:36:28 +0000 | [diff] [blame] | 386 | IdentifierInfo *II = getAsIdentifierInfo(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 387 | |
Ted Kremenek | 150ec29 | 2009-03-07 01:22:02 +0000 | [diff] [blame] | 388 | // If the number of arguments is 0 then II is guaranteed to not be null. |
Ted Kremenek | f5ed396 | 2009-03-06 23:36:28 +0000 | [diff] [blame] | 389 | if (getNumArgs() == 0) |
Daniel Dunbar | 01eb9b9 | 2009-10-18 21:17:35 +0000 | [diff] [blame] | 390 | return II->getName(); |
Ted Kremenek | f5ed396 | 2009-03-06 23:36:28 +0000 | [diff] [blame] | 391 | |
Daniel Dunbar | 76b61cc | 2009-10-17 18:13:02 +0000 | [diff] [blame] | 392 | if (!II) |
| 393 | return ":"; |
| 394 | |
Daniel Dunbar | 01eb9b9 | 2009-10-18 21:17:35 +0000 | [diff] [blame] | 395 | return II->getName().str() + ":"; |
Steve Naroff | 29238a0 | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 396 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 397 | |
Douglas Gregor | 51603be | 2012-05-04 18:24:37 +0000 | [diff] [blame] | 398 | // We have a multiple keyword selector. |
| 399 | return getMultiKeywordSelector()->getName(); |
Steve Naroff | 29238a0 | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 400 | } |
| 401 | |
John McCall | 85f3d76 | 2011-03-02 01:50:55 +0000 | [diff] [blame] | 402 | /// Interpreting the given string using the normal CamelCase |
| 403 | /// conventions, determine whether the given string starts with the |
| 404 | /// given "word", which is assumed to end in a lowercase letter. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 405 | static bool startsWithWord(StringRef name, StringRef word) { |
John McCall | 85f3d76 | 2011-03-02 01:50:55 +0000 | [diff] [blame] | 406 | if (name.size() < word.size()) return false; |
| 407 | return ((name.size() == word.size() || |
| 408 | !islower(name[word.size()])) |
| 409 | && name.startswith(word)); |
| 410 | } |
| 411 | |
| 412 | ObjCMethodFamily Selector::getMethodFamilyImpl(Selector sel) { |
| 413 | IdentifierInfo *first = sel.getIdentifierInfoForSlot(0); |
| 414 | if (!first) return OMF_None; |
| 415 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 416 | StringRef name = first->getName(); |
John McCall | 85f3d76 | 2011-03-02 01:50:55 +0000 | [diff] [blame] | 417 | if (sel.isUnarySelector()) { |
| 418 | if (name == "autorelease") return OMF_autorelease; |
| 419 | if (name == "dealloc") return OMF_dealloc; |
Nico Weber | 80cb6e6 | 2011-08-28 22:35:17 +0000 | [diff] [blame] | 420 | if (name == "finalize") return OMF_finalize; |
John McCall | 85f3d76 | 2011-03-02 01:50:55 +0000 | [diff] [blame] | 421 | if (name == "release") return OMF_release; |
| 422 | if (name == "retain") return OMF_retain; |
| 423 | if (name == "retainCount") return OMF_retainCount; |
Douglas Gregor | 926df6c | 2011-06-11 01:09:30 +0000 | [diff] [blame] | 424 | if (name == "self") return OMF_self; |
John McCall | 85f3d76 | 2011-03-02 01:50:55 +0000 | [diff] [blame] | 425 | } |
Fariborz Jahanian | 9670e17 | 2011-07-05 22:38:59 +0000 | [diff] [blame] | 426 | |
| 427 | if (name == "performSelector") return OMF_performSelector; |
John McCall | 85f3d76 | 2011-03-02 01:50:55 +0000 | [diff] [blame] | 428 | |
| 429 | // The other method families may begin with a prefix of underscores. |
| 430 | while (!name.empty() && name.front() == '_') |
| 431 | name = name.substr(1); |
| 432 | |
| 433 | if (name.empty()) return OMF_None; |
| 434 | switch (name.front()) { |
| 435 | case 'a': |
| 436 | if (startsWithWord(name, "alloc")) return OMF_alloc; |
| 437 | break; |
| 438 | case 'c': |
| 439 | if (startsWithWord(name, "copy")) return OMF_copy; |
| 440 | break; |
| 441 | case 'i': |
| 442 | if (startsWithWord(name, "init")) return OMF_init; |
| 443 | break; |
| 444 | case 'm': |
| 445 | if (startsWithWord(name, "mutableCopy")) return OMF_mutableCopy; |
| 446 | break; |
| 447 | case 'n': |
| 448 | if (startsWithWord(name, "new")) return OMF_new; |
| 449 | break; |
| 450 | default: |
| 451 | break; |
| 452 | } |
| 453 | |
| 454 | return OMF_None; |
| 455 | } |
Steve Naroff | 29238a0 | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 456 | |
Chris Lattner | 5f7d228 | 2009-03-04 05:35:38 +0000 | [diff] [blame] | 457 | namespace { |
| 458 | struct SelectorTableImpl { |
| 459 | llvm::FoldingSet<MultiKeywordSelector> Table; |
| 460 | llvm::BumpPtrAllocator Allocator; |
| 461 | }; |
| 462 | } // end anonymous namespace. |
| 463 | |
| 464 | static SelectorTableImpl &getSelectorTableImpl(void *P) { |
| 465 | return *static_cast<SelectorTableImpl*>(P); |
| 466 | } |
| 467 | |
Benjamin Kramer | 8fe83e1 | 2012-02-04 13:45:25 +0000 | [diff] [blame] | 468 | /*static*/ Selector |
| 469 | SelectorTable::constructSetterName(IdentifierTable &Idents, |
| 470 | SelectorTable &SelTable, |
| 471 | const IdentifierInfo *Name) { |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 472 | SmallString<100> SelectorName; |
Benjamin Kramer | 8fe83e1 | 2012-02-04 13:45:25 +0000 | [diff] [blame] | 473 | SelectorName = "set"; |
| 474 | SelectorName += Name->getName(); |
| 475 | SelectorName[3] = toupper(SelectorName[3]); |
| 476 | IdentifierInfo *SetterName = &Idents.get(SelectorName); |
| 477 | return SelTable.getUnarySelector(SetterName); |
| 478 | } |
| 479 | |
Ted Kremenek | 97f55d6 | 2011-04-18 22:47:04 +0000 | [diff] [blame] | 480 | size_t SelectorTable::getTotalMemory() const { |
| 481 | SelectorTableImpl &SelTabImpl = getSelectorTableImpl(Impl); |
| 482 | return SelTabImpl.Allocator.getTotalMemory(); |
| 483 | } |
Chris Lattner | 5f7d228 | 2009-03-04 05:35:38 +0000 | [diff] [blame] | 484 | |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 485 | Selector SelectorTable::getSelector(unsigned nKeys, IdentifierInfo **IIV) { |
| 486 | if (nKeys < 2) |
| 487 | return Selector(IIV[0], nKeys); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 488 | |
Chris Lattner | 5f7d228 | 2009-03-04 05:35:38 +0000 | [diff] [blame] | 489 | SelectorTableImpl &SelTabImpl = getSelectorTableImpl(Impl); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 490 | |
Steve Naroff | 29238a0 | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 491 | // Unique selector, to guarantee there is one per name. |
| 492 | llvm::FoldingSetNodeID ID; |
| 493 | MultiKeywordSelector::Profile(ID, IIV, nKeys); |
| 494 | |
| 495 | void *InsertPos = 0; |
Chris Lattner | 5f7d228 | 2009-03-04 05:35:38 +0000 | [diff] [blame] | 496 | if (MultiKeywordSelector *SI = |
| 497 | SelTabImpl.Table.FindNodeOrInsertPos(ID, InsertPos)) |
Steve Naroff | 29238a0 | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 498 | return Selector(SI); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 499 | |
Steve Naroff | 29238a0 | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 500 | // MultiKeywordSelector objects are not allocated with new because they have a |
| 501 | // variable size array (for parameter types) at the end of them. |
Chris Lattner | 5f7d228 | 2009-03-04 05:35:38 +0000 | [diff] [blame] | 502 | unsigned Size = sizeof(MultiKeywordSelector) + nKeys*sizeof(IdentifierInfo *); |
| 503 | MultiKeywordSelector *SI = |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 504 | (MultiKeywordSelector*)SelTabImpl.Allocator.Allocate(Size, |
Chris Lattner | 3248854 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 505 | llvm::alignOf<MultiKeywordSelector>()); |
Steve Naroff | 29238a0 | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 506 | new (SI) MultiKeywordSelector(nKeys, IIV); |
Chris Lattner | 5f7d228 | 2009-03-04 05:35:38 +0000 | [diff] [blame] | 507 | SelTabImpl.Table.InsertNode(SI, InsertPos); |
Steve Naroff | 29238a0 | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 508 | return Selector(SI); |
| 509 | } |
| 510 | |
Steve Naroff | 29238a0 | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 511 | SelectorTable::SelectorTable() { |
Chris Lattner | 5f7d228 | 2009-03-04 05:35:38 +0000 | [diff] [blame] | 512 | Impl = new SelectorTableImpl(); |
Steve Naroff | 29238a0 | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | SelectorTable::~SelectorTable() { |
Chris Lattner | 5f7d228 | 2009-03-04 05:35:38 +0000 | [diff] [blame] | 516 | delete &getSelectorTableImpl(Impl); |
Steve Naroff | 29238a0 | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 517 | } |
| 518 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 519 | const char *clang::getOperatorSpelling(OverloadedOperatorKind Operator) { |
| 520 | switch (Operator) { |
| 521 | case OO_None: |
| 522 | case NUM_OVERLOADED_OPERATORS: |
| 523 | return 0; |
Kovarththanan Rajaratnam | 50acf24 | 2010-03-12 11:27:37 +0000 | [diff] [blame] | 524 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 525 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 526 | case OO_##Name: return Spelling; |
| 527 | #include "clang/Basic/OperatorKinds.def" |
| 528 | } |
Kovarththanan Rajaratnam | 50acf24 | 2010-03-12 11:27:37 +0000 | [diff] [blame] | 529 | |
David Blaikie | 7530c03 | 2012-01-17 06:56:22 +0000 | [diff] [blame] | 530 | llvm_unreachable("Invalid OverloadedOperatorKind!"); |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 531 | } |