Eugene Zelenko | 21fadad | 2017-11-21 23:26:08 +0000 | [diff] [blame] | 1 | //===- DeclarationName.cpp - Declaration names implementation -------------===// |
Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the DeclarationName and DeclarationNameTable |
| 11 | // classes. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
Eugene Zelenko | 21fadad | 2017-11-21 23:26:08 +0000 | [diff] [blame] | 14 | |
Mehdi Amini | 9670f84 | 2016-07-18 19:02:11 +0000 | [diff] [blame] | 15 | #include "clang/AST/DeclarationName.h" |
Ted Kremenek | 6aead3a | 2010-05-10 20:40:08 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTContext.h" |
Eugene Zelenko | 21fadad | 2017-11-21 23:26:08 +0000 | [diff] [blame] | 17 | #include "clang/AST/Decl.h" |
| 18 | #include "clang/AST/DeclBase.h" |
Argyrios Kyrtzidis | d571908 | 2016-02-15 01:32:36 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclCXX.h" |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclTemplate.h" |
Eugene Zelenko | 21fadad | 2017-11-21 23:26:08 +0000 | [diff] [blame] | 21 | #include "clang/AST/PrettyPrinter.h" |
Douglas Gregor | 92751d4 | 2008-11-17 22:58:34 +0000 | [diff] [blame] | 22 | #include "clang/AST/Type.h" |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 23 | #include "clang/AST/TypeLoc.h" |
Douglas Gregor | b082bab | 2009-11-04 22:24:30 +0000 | [diff] [blame] | 24 | #include "clang/AST/TypeOrdering.h" |
Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 25 | #include "clang/Basic/IdentifierTable.h" |
Eugene Zelenko | 21fadad | 2017-11-21 23:26:08 +0000 | [diff] [blame] | 26 | #include "clang/Basic/LLVM.h" |
| 27 | #include "clang/Basic/LangOptions.h" |
| 28 | #include "clang/Basic/OperatorKinds.h" |
| 29 | #include "clang/Basic/SourceLocation.h" |
Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 30 | #include "llvm/ADT/FoldingSet.h" |
Eugene Zelenko | 21fadad | 2017-11-21 23:26:08 +0000 | [diff] [blame] | 31 | #include "llvm/Support/Casting.h" |
| 32 | #include "llvm/Support/Compiler.h" |
Chandler Carruth | 2b59fbe | 2010-12-15 07:29:18 +0000 | [diff] [blame] | 33 | #include "llvm/Support/ErrorHandling.h" |
Benjamin Kramer | 95c7c42 | 2010-04-17 09:56:45 +0000 | [diff] [blame] | 34 | #include "llvm/Support/raw_ostream.h" |
Eugene Zelenko | 21fadad | 2017-11-21 23:26:08 +0000 | [diff] [blame] | 35 | #include <algorithm> |
| 36 | #include <cassert> |
| 37 | #include <cstdint> |
| 38 | #include <string> |
| 39 | |
Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 40 | using namespace clang; |
| 41 | |
John McCall | ef3057c | 2010-02-13 01:04:05 +0000 | [diff] [blame] | 42 | static int compareInt(unsigned A, unsigned B) { |
| 43 | return (A < B ? -1 : (A > B ? 1 : 0)); |
| 44 | } |
| 45 | |
| 46 | int DeclarationName::compare(DeclarationName LHS, DeclarationName RHS) { |
Douglas Gregor | b082bab | 2009-11-04 22:24:30 +0000 | [diff] [blame] | 47 | if (LHS.getNameKind() != RHS.getNameKind()) |
John McCall | ef3057c | 2010-02-13 01:04:05 +0000 | [diff] [blame] | 48 | return (LHS.getNameKind() < RHS.getNameKind() ? -1 : 1); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 49 | |
Douglas Gregor | b082bab | 2009-11-04 22:24:30 +0000 | [diff] [blame] | 50 | switch (LHS.getNameKind()) { |
John McCall | ef3057c | 2010-02-13 01:04:05 +0000 | [diff] [blame] | 51 | case DeclarationName::Identifier: { |
| 52 | IdentifierInfo *LII = LHS.getAsIdentifierInfo(); |
| 53 | IdentifierInfo *RII = RHS.getAsIdentifierInfo(); |
| 54 | if (!LII) return RII ? -1 : 0; |
| 55 | if (!RII) return 1; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 56 | |
John McCall | ef3057c | 2010-02-13 01:04:05 +0000 | [diff] [blame] | 57 | return LII->getName().compare(RII->getName()); |
| 58 | } |
Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 59 | |
Douglas Gregor | b082bab | 2009-11-04 22:24:30 +0000 | [diff] [blame] | 60 | case DeclarationName::ObjCZeroArgSelector: |
| 61 | case DeclarationName::ObjCOneArgSelector: |
| 62 | case DeclarationName::ObjCMultiArgSelector: { |
| 63 | Selector LHSSelector = LHS.getObjCSelector(); |
| 64 | Selector RHSSelector = RHS.getObjCSelector(); |
Manman Ren | b666573 | 2016-11-17 18:41:18 +0000 | [diff] [blame] | 65 | // getNumArgs for ZeroArgSelector returns 0, but we still need to compare. |
| 66 | if (LHS.getNameKind() == DeclarationName::ObjCZeroArgSelector && |
| 67 | RHS.getNameKind() == DeclarationName::ObjCZeroArgSelector) { |
| 68 | return LHSSelector.getAsIdentifierInfo()->getName().compare( |
| 69 | RHSSelector.getAsIdentifierInfo()->getName()); |
| 70 | } |
John McCall | ef3057c | 2010-02-13 01:04:05 +0000 | [diff] [blame] | 71 | unsigned LN = LHSSelector.getNumArgs(), RN = RHSSelector.getNumArgs(); |
| 72 | for (unsigned I = 0, N = std::min(LN, RN); I != N; ++I) { |
Douglas Gregor | af2a6ae | 2011-02-18 22:29:55 +0000 | [diff] [blame] | 73 | switch (LHSSelector.getNameForSlot(I).compare( |
| 74 | RHSSelector.getNameForSlot(I))) { |
Manman Ren | b666573 | 2016-11-17 18:41:18 +0000 | [diff] [blame] | 75 | case -1: return -1; |
| 76 | case 1: return 1; |
Douglas Gregor | b082bab | 2009-11-04 22:24:30 +0000 | [diff] [blame] | 77 | default: break; |
| 78 | } |
| 79 | } |
John McCall | ef3057c | 2010-02-13 01:04:05 +0000 | [diff] [blame] | 80 | |
| 81 | return compareInt(LN, RN); |
Douglas Gregor | b082bab | 2009-11-04 22:24:30 +0000 | [diff] [blame] | 82 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 83 | |
Douglas Gregor | b082bab | 2009-11-04 22:24:30 +0000 | [diff] [blame] | 84 | case DeclarationName::CXXConstructorName: |
| 85 | case DeclarationName::CXXDestructorName: |
| 86 | case DeclarationName::CXXConversionFunctionName: |
John McCall | ef3057c | 2010-02-13 01:04:05 +0000 | [diff] [blame] | 87 | if (QualTypeOrdering()(LHS.getCXXNameType(), RHS.getCXXNameType())) |
| 88 | return -1; |
| 89 | if (QualTypeOrdering()(RHS.getCXXNameType(), LHS.getCXXNameType())) |
| 90 | return 1; |
| 91 | return 0; |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 92 | |
| 93 | case DeclarationName::CXXDeductionGuideName: |
| 94 | // We never want to compare deduction guide names for templates from |
| 95 | // different scopes, so just compare the template-name. |
| 96 | return compare(LHS.getCXXDeductionGuideTemplate()->getDeclName(), |
| 97 | RHS.getCXXDeductionGuideTemplate()->getDeclName()); |
| 98 | |
Douglas Gregor | b082bab | 2009-11-04 22:24:30 +0000 | [diff] [blame] | 99 | case DeclarationName::CXXOperatorName: |
John McCall | ef3057c | 2010-02-13 01:04:05 +0000 | [diff] [blame] | 100 | return compareInt(LHS.getCXXOverloadedOperator(), |
| 101 | RHS.getCXXOverloadedOperator()); |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 102 | |
| 103 | case DeclarationName::CXXLiteralOperatorName: |
John McCall | ef3057c | 2010-02-13 01:04:05 +0000 | [diff] [blame] | 104 | return LHS.getCXXLiteralIdentifier()->getName().compare( |
| 105 | RHS.getCXXLiteralIdentifier()->getName()); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 106 | |
Douglas Gregor | b082bab | 2009-11-04 22:24:30 +0000 | [diff] [blame] | 107 | case DeclarationName::CXXUsingDirective: |
John McCall | ef3057c | 2010-02-13 01:04:05 +0000 | [diff] [blame] | 108 | return 0; |
Douglas Gregor | b082bab | 2009-11-04 22:24:30 +0000 | [diff] [blame] | 109 | } |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 110 | |
| 111 | llvm_unreachable("Invalid DeclarationName Kind!"); |
Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 112 | } |
| 113 | |
Argyrios Kyrtzidis | e91793c | 2016-02-13 21:46:50 +0000 | [diff] [blame] | 114 | static void printCXXConstructorDestructorName(QualType ClassType, |
| 115 | raw_ostream &OS, |
Richard Smith | 301bc21 | 2016-05-19 01:39:10 +0000 | [diff] [blame] | 116 | PrintingPolicy Policy) { |
| 117 | // We know we're printing C++ here. Ensure we print types properly. |
| 118 | Policy.adjustForCPlusPlus(); |
| 119 | |
Argyrios Kyrtzidis | e91793c | 2016-02-13 21:46:50 +0000 | [diff] [blame] | 120 | if (const RecordType *ClassRec = ClassType->getAs<RecordType>()) { |
| 121 | OS << *ClassRec->getDecl(); |
| 122 | return; |
| 123 | } |
Argyrios Kyrtzidis | d571908 | 2016-02-15 01:32:36 +0000 | [diff] [blame] | 124 | if (Policy.SuppressTemplateArgsInCXXConstructors) { |
| 125 | if (auto *InjTy = ClassType->getAs<InjectedClassNameType>()) { |
| 126 | OS << *InjTy->getDecl(); |
| 127 | return; |
| 128 | } |
| 129 | } |
Richard Smith | 301bc21 | 2016-05-19 01:39:10 +0000 | [diff] [blame] | 130 | ClassType.print(OS, Policy); |
Argyrios Kyrtzidis | e91793c | 2016-02-13 21:46:50 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | void DeclarationName::print(raw_ostream &OS, const PrintingPolicy &Policy) { |
| 134 | DeclarationName &N = *this; |
David Blaikie | d4da872 | 2013-05-14 21:04:00 +0000 | [diff] [blame] | 135 | switch (N.getNameKind()) { |
| 136 | case DeclarationName::Identifier: |
| 137 | if (const IdentifierInfo *II = N.getAsIdentifierInfo()) |
| 138 | OS << II->getName(); |
Argyrios Kyrtzidis | e91793c | 2016-02-13 21:46:50 +0000 | [diff] [blame] | 139 | return; |
David Blaikie | d4da872 | 2013-05-14 21:04:00 +0000 | [diff] [blame] | 140 | |
| 141 | case DeclarationName::ObjCZeroArgSelector: |
| 142 | case DeclarationName::ObjCOneArgSelector: |
| 143 | case DeclarationName::ObjCMultiArgSelector: |
Aaron Ballman | b190f97 | 2014-01-03 17:59:55 +0000 | [diff] [blame] | 144 | N.getObjCSelector().print(OS); |
Argyrios Kyrtzidis | e91793c | 2016-02-13 21:46:50 +0000 | [diff] [blame] | 145 | return; |
David Blaikie | d4da872 | 2013-05-14 21:04:00 +0000 | [diff] [blame] | 146 | |
Argyrios Kyrtzidis | e91793c | 2016-02-13 21:46:50 +0000 | [diff] [blame] | 147 | case DeclarationName::CXXConstructorName: |
| 148 | return printCXXConstructorDestructorName(N.getCXXNameType(), OS, Policy); |
David Blaikie | d4da872 | 2013-05-14 21:04:00 +0000 | [diff] [blame] | 149 | |
Eugene Zelenko | 21fadad | 2017-11-21 23:26:08 +0000 | [diff] [blame] | 150 | case DeclarationName::CXXDestructorName: |
David Blaikie | d4da872 | 2013-05-14 21:04:00 +0000 | [diff] [blame] | 151 | OS << '~'; |
Argyrios Kyrtzidis | e91793c | 2016-02-13 21:46:50 +0000 | [diff] [blame] | 152 | return printCXXConstructorDestructorName(N.getCXXNameType(), OS, Policy); |
David Blaikie | d4da872 | 2013-05-14 21:04:00 +0000 | [diff] [blame] | 153 | |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 154 | case DeclarationName::CXXDeductionGuideName: |
Richard Smith | f283fdc | 2017-02-08 00:35:25 +0000 | [diff] [blame] | 155 | OS << "<deduction guide for "; |
| 156 | getCXXDeductionGuideTemplate()->getDeclName().print(OS, Policy); |
| 157 | OS << '>'; |
| 158 | return; |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 159 | |
David Blaikie | d4da872 | 2013-05-14 21:04:00 +0000 | [diff] [blame] | 160 | case DeclarationName::CXXOperatorName: { |
| 161 | static const char* const OperatorNames[NUM_OVERLOADED_OPERATORS] = { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 162 | nullptr, |
David Blaikie | d4da872 | 2013-05-14 21:04:00 +0000 | [diff] [blame] | 163 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 164 | Spelling, |
| 165 | #include "clang/Basic/OperatorKinds.def" |
| 166 | }; |
| 167 | const char *OpName = OperatorNames[N.getCXXOverloadedOperator()]; |
| 168 | assert(OpName && "not an overloaded operator"); |
| 169 | |
| 170 | OS << "operator"; |
| 171 | if (OpName[0] >= 'a' && OpName[0] <= 'z') |
| 172 | OS << ' '; |
Argyrios Kyrtzidis | e91793c | 2016-02-13 21:46:50 +0000 | [diff] [blame] | 173 | OS << OpName; |
| 174 | return; |
David Blaikie | d4da872 | 2013-05-14 21:04:00 +0000 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | case DeclarationName::CXXLiteralOperatorName: |
Argyrios Kyrtzidis | e91793c | 2016-02-13 21:46:50 +0000 | [diff] [blame] | 178 | OS << "operator\"\"" << N.getCXXLiteralIdentifier()->getName(); |
| 179 | return; |
David Blaikie | d4da872 | 2013-05-14 21:04:00 +0000 | [diff] [blame] | 180 | |
| 181 | case DeclarationName::CXXConversionFunctionName: { |
| 182 | OS << "operator "; |
| 183 | QualType Type = N.getCXXNameType(); |
Argyrios Kyrtzidis | e91793c | 2016-02-13 21:46:50 +0000 | [diff] [blame] | 184 | if (const RecordType *Rec = Type->getAs<RecordType>()) { |
| 185 | OS << *Rec->getDecl(); |
| 186 | return; |
| 187 | } |
Richard Smith | 301bc21 | 2016-05-19 01:39:10 +0000 | [diff] [blame] | 188 | // We know we're printing C++ here, ensure we print 'bool' properly. |
| 189 | PrintingPolicy CXXPolicy = Policy; |
| 190 | CXXPolicy.adjustForCPlusPlus(); |
| 191 | Type.print(OS, CXXPolicy); |
Argyrios Kyrtzidis | e91793c | 2016-02-13 21:46:50 +0000 | [diff] [blame] | 192 | return; |
David Blaikie | d4da872 | 2013-05-14 21:04:00 +0000 | [diff] [blame] | 193 | } |
| 194 | case DeclarationName::CXXUsingDirective: |
Argyrios Kyrtzidis | e91793c | 2016-02-13 21:46:50 +0000 | [diff] [blame] | 195 | OS << "<using-directive>"; |
| 196 | return; |
David Blaikie | d4da872 | 2013-05-14 21:04:00 +0000 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | llvm_unreachable("Unexpected declaration name kind"); |
| 200 | } |
| 201 | |
Eugene Zelenko | 21fadad | 2017-11-21 23:26:08 +0000 | [diff] [blame] | 202 | namespace clang { |
| 203 | |
Argyrios Kyrtzidis | e91793c | 2016-02-13 21:46:50 +0000 | [diff] [blame] | 204 | raw_ostream &operator<<(raw_ostream &OS, DeclarationName N) { |
| 205 | LangOptions LO; |
| 206 | N.print(OS, PrintingPolicy(LO)); |
| 207 | return OS; |
| 208 | } |
| 209 | |
Eugene Zelenko | 21fadad | 2017-11-21 23:26:08 +0000 | [diff] [blame] | 210 | } // namespace clang |
Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 211 | |
Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 212 | DeclarationName::NameKind DeclarationName::getNameKind() const { |
| 213 | switch (getStoredNameKind()) { |
| 214 | case StoredIdentifier: return Identifier; |
| 215 | case StoredObjCZeroArgSelector: return ObjCZeroArgSelector; |
| 216 | case StoredObjCOneArgSelector: return ObjCOneArgSelector; |
| 217 | |
Douglas Gregor | 163c585 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 218 | case StoredDeclarationNameExtra: |
Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 219 | switch (getExtra()->ExtraKindOrNumArgs) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 220 | case DeclarationNameExtra::CXXConstructor: |
Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 221 | return CXXConstructorName; |
| 222 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 223 | case DeclarationNameExtra::CXXDestructor: |
Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 224 | return CXXDestructorName; |
| 225 | |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 226 | case DeclarationNameExtra::CXXDeductionGuide: |
| 227 | return CXXDeductionGuideName; |
| 228 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 229 | case DeclarationNameExtra::CXXConversionFunction: |
Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 230 | return CXXConversionFunctionName; |
| 231 | |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 232 | case DeclarationNameExtra::CXXLiteralOperator: |
| 233 | return CXXLiteralOperatorName; |
| 234 | |
Douglas Gregor | 889ceb7 | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 235 | case DeclarationNameExtra::CXXUsingDirective: |
| 236 | return CXXUsingDirective; |
| 237 | |
Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 238 | default: |
Douglas Gregor | 163c585 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 239 | // Check if we have one of the CXXOperator* enumeration values. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 240 | if (getExtra()->ExtraKindOrNumArgs < |
Douglas Gregor | 889ceb7 | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 241 | DeclarationNameExtra::CXXUsingDirective) |
Douglas Gregor | 163c585 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 242 | return CXXOperatorName; |
| 243 | |
Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 244 | return ObjCMultiArgSelector; |
| 245 | } |
Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | // Can't actually get here. |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 249 | llvm_unreachable("This should be unreachable!"); |
Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 250 | } |
| 251 | |
Douglas Gregor | ea0a0a9 | 2010-01-11 18:40:55 +0000 | [diff] [blame] | 252 | bool DeclarationName::isDependentName() const { |
| 253 | QualType T = getCXXNameType(); |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 254 | if (!T.isNull() && T->isDependentType()) |
| 255 | return true; |
| 256 | |
| 257 | // A class-scope deduction guide in a dependent context has a dependent name. |
| 258 | auto *TD = getCXXDeductionGuideTemplate(); |
| 259 | if (TD && TD->getDeclContext()->isDependentContext()) |
| 260 | return true; |
| 261 | |
| 262 | return false; |
Douglas Gregor | ea0a0a9 | 2010-01-11 18:40:55 +0000 | [diff] [blame] | 263 | } |
| 264 | |
Douglas Gregor | 92751d4 | 2008-11-17 22:58:34 +0000 | [diff] [blame] | 265 | std::string DeclarationName::getAsString() const { |
Benjamin Kramer | 95c7c42 | 2010-04-17 09:56:45 +0000 | [diff] [blame] | 266 | std::string Result; |
| 267 | llvm::raw_string_ostream OS(Result); |
David Blaikie | d4da872 | 2013-05-14 21:04:00 +0000 | [diff] [blame] | 268 | OS << *this; |
Benjamin Kramer | 95c7c42 | 2010-04-17 09:56:45 +0000 | [diff] [blame] | 269 | return OS.str(); |
| 270 | } |
| 271 | |
Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 272 | QualType DeclarationName::getCXXNameType() const { |
| 273 | if (CXXSpecialName *CXXName = getAsCXXSpecialName()) |
| 274 | return CXXName->Type; |
| 275 | else |
| 276 | return QualType(); |
| 277 | } |
| 278 | |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 279 | TemplateDecl *DeclarationName::getCXXDeductionGuideTemplate() const { |
| 280 | if (auto *Guide = getAsCXXDeductionGuideNameExtra()) |
| 281 | return Guide->Template; |
| 282 | return nullptr; |
| 283 | } |
| 284 | |
Douglas Gregor | 163c585 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 285 | OverloadedOperatorKind DeclarationName::getCXXOverloadedOperator() const { |
| 286 | if (CXXOperatorIdName *CXXOp = getAsCXXOperatorIdName()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 287 | unsigned value |
Douglas Gregor | 163c585 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 288 | = CXXOp->ExtraKindOrNumArgs - DeclarationNameExtra::CXXConversionFunction; |
| 289 | return static_cast<OverloadedOperatorKind>(value); |
| 290 | } else { |
| 291 | return OO_None; |
| 292 | } |
| 293 | } |
| 294 | |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 295 | IdentifierInfo *DeclarationName::getCXXLiteralIdentifier() const { |
| 296 | if (CXXLiteralOperatorIdName *CXXLit = getAsCXXLiteralOperatorIdName()) |
| 297 | return CXXLit->ID; |
| 298 | else |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 299 | return nullptr; |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 300 | } |
| 301 | |
Douglas Gregor | 0da5305 | 2012-05-03 23:18:44 +0000 | [diff] [blame] | 302 | void *DeclarationName::getFETokenInfoAsVoidSlow() const { |
Douglas Gregor | ae2fbad | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 303 | switch (getNameKind()) { |
| 304 | case Identifier: |
Benjamin Kramer | 1458c1c | 2012-05-19 16:03:58 +0000 | [diff] [blame] | 305 | llvm_unreachable("Handled by getFETokenInfo()"); |
Douglas Gregor | ae2fbad | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 306 | |
| 307 | case CXXConstructorName: |
| 308 | case CXXDestructorName: |
| 309 | case CXXConversionFunctionName: |
| 310 | return getAsCXXSpecialName()->FETokenInfo; |
| 311 | |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 312 | case CXXDeductionGuideName: |
| 313 | return getAsCXXDeductionGuideNameExtra()->FETokenInfo; |
| 314 | |
Douglas Gregor | 163c585 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 315 | case CXXOperatorName: |
| 316 | return getAsCXXOperatorIdName()->FETokenInfo; |
| 317 | |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 318 | case CXXLiteralOperatorName: |
Richard Smith | c1b0565 | 2012-03-09 08:37:16 +0000 | [diff] [blame] | 319 | return getAsCXXLiteralOperatorIdName()->FETokenInfo; |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 320 | |
Douglas Gregor | ae2fbad | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 321 | default: |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 322 | llvm_unreachable("Declaration name has no FETokenInfo"); |
Douglas Gregor | ae2fbad | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 323 | } |
Douglas Gregor | ae2fbad | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | void DeclarationName::setFETokenInfo(void *T) { |
| 327 | switch (getNameKind()) { |
| 328 | case Identifier: |
| 329 | getAsIdentifierInfo()->setFETokenInfo(T); |
| 330 | break; |
| 331 | |
| 332 | case CXXConstructorName: |
| 333 | case CXXDestructorName: |
| 334 | case CXXConversionFunctionName: |
| 335 | getAsCXXSpecialName()->FETokenInfo = T; |
| 336 | break; |
| 337 | |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 338 | case CXXDeductionGuideName: |
| 339 | getAsCXXDeductionGuideNameExtra()->FETokenInfo = T; |
| 340 | break; |
| 341 | |
Douglas Gregor | 163c585 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 342 | case CXXOperatorName: |
| 343 | getAsCXXOperatorIdName()->FETokenInfo = T; |
| 344 | break; |
| 345 | |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 346 | case CXXLiteralOperatorName: |
Richard Smith | c1b0565 | 2012-03-09 08:37:16 +0000 | [diff] [blame] | 347 | getAsCXXLiteralOperatorIdName()->FETokenInfo = T; |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 348 | break; |
| 349 | |
Douglas Gregor | ae2fbad | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 350 | default: |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 351 | llvm_unreachable("Declaration name has no FETokenInfo"); |
Douglas Gregor | ae2fbad | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 352 | } |
| 353 | } |
| 354 | |
Douglas Gregor | 889ceb7 | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 355 | DeclarationName DeclarationName::getUsingDirectiveName() { |
| 356 | // Single instance of DeclarationNameExtra for using-directive |
Nuno Lopes | 221c1fd | 2009-12-10 00:07:02 +0000 | [diff] [blame] | 357 | static const DeclarationNameExtra UDirExtra = |
Douglas Gregor | 889ceb7 | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 358 | { DeclarationNameExtra::CXXUsingDirective }; |
| 359 | |
| 360 | uintptr_t Ptr = reinterpret_cast<uintptr_t>(&UDirExtra); |
| 361 | Ptr |= StoredDeclarationNameExtra; |
| 362 | |
| 363 | return DeclarationName(Ptr); |
| 364 | } |
| 365 | |
Yaron Keren | cdae941 | 2016-01-29 19:38:18 +0000 | [diff] [blame] | 366 | LLVM_DUMP_METHOD void DeclarationName::dump() const { |
David Blaikie | d4da872 | 2013-05-14 21:04:00 +0000 | [diff] [blame] | 367 | llvm::errs() << *this << '\n'; |
Anders Carlsson | 1b69be2 | 2009-11-15 22:30:43 +0000 | [diff] [blame] | 368 | } |
| 369 | |
Jay Foad | 39c7980 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 370 | DeclarationNameTable::DeclarationNameTable(const ASTContext &C) : Ctx(C) { |
Douglas Gregor | 163c585 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 371 | // Initialize the overloaded operator names. |
Ted Kremenek | 7e550ca | 2010-05-10 20:56:10 +0000 | [diff] [blame] | 372 | CXXOperatorNames = new (Ctx) CXXOperatorIdName[NUM_OVERLOADED_OPERATORS]; |
Douglas Gregor | 163c585 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 373 | for (unsigned Op = 0; Op < NUM_OVERLOADED_OPERATORS; ++Op) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 374 | CXXOperatorNames[Op].ExtraKindOrNumArgs |
Douglas Gregor | 163c585 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 375 | = Op + DeclarationNameExtra::CXXConversionFunction; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 376 | CXXOperatorNames[Op].FETokenInfo = nullptr; |
Douglas Gregor | 163c585 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 377 | } |
Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 378 | } |
| 379 | |
Benjamin Kramer | d7d2b1f | 2012-12-01 16:35:25 +0000 | [diff] [blame] | 380 | DeclarationName DeclarationNameTable::getCXXConstructorName(CanQualType Ty) { |
| 381 | return getCXXSpecialName(DeclarationName::CXXConstructorName, |
| 382 | Ty.getUnqualifiedType()); |
| 383 | } |
| 384 | |
| 385 | DeclarationName DeclarationNameTable::getCXXDestructorName(CanQualType Ty) { |
| 386 | return getCXXSpecialName(DeclarationName::CXXDestructorName, |
| 387 | Ty.getUnqualifiedType()); |
| 388 | } |
| 389 | |
| 390 | DeclarationName |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 391 | DeclarationNameTable::getCXXDeductionGuideName(TemplateDecl *Template) { |
| 392 | Template = cast<TemplateDecl>(Template->getCanonicalDecl()); |
| 393 | |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 394 | llvm::FoldingSetNodeID ID; |
| 395 | ID.AddPointer(Template); |
| 396 | |
| 397 | void *InsertPos = nullptr; |
Bruno Ricci | b619883 | 2018-08-06 16:47:31 +0000 | [diff] [blame^] | 398 | if (auto *Name = CXXDeductionGuideNames.FindNodeOrInsertPos(ID, InsertPos)) |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 399 | return DeclarationName(Name); |
| 400 | |
| 401 | auto *Name = new (Ctx) CXXDeductionGuideNameExtra; |
| 402 | Name->ExtraKindOrNumArgs = DeclarationNameExtra::CXXDeductionGuide; |
| 403 | Name->Template = Template; |
| 404 | Name->FETokenInfo = nullptr; |
| 405 | |
Bruno Ricci | b619883 | 2018-08-06 16:47:31 +0000 | [diff] [blame^] | 406 | CXXDeductionGuideNames.InsertNode(Name, InsertPos); |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 407 | return DeclarationName(Name); |
| 408 | } |
| 409 | |
| 410 | DeclarationName |
Benjamin Kramer | d7d2b1f | 2012-12-01 16:35:25 +0000 | [diff] [blame] | 411 | DeclarationNameTable::getCXXConversionFunctionName(CanQualType Ty) { |
| 412 | return getCXXSpecialName(DeclarationName::CXXConversionFunctionName, Ty); |
| 413 | } |
| 414 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 415 | DeclarationName |
| 416 | DeclarationNameTable::getCXXSpecialName(DeclarationName::NameKind Kind, |
Douglas Gregor | 2211d34 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 417 | CanQualType Ty) { |
Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 418 | assert(Kind >= DeclarationName::CXXConstructorName && |
| 419 | Kind <= DeclarationName::CXXConversionFunctionName && |
| 420 | "Kind must be a C++ special name kind"); |
Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 421 | |
| 422 | DeclarationNameExtra::ExtraKind EKind; |
| 423 | switch (Kind) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 424 | case DeclarationName::CXXConstructorName: |
Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 425 | EKind = DeclarationNameExtra::CXXConstructor; |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 426 | assert(!Ty.hasQualifiers() &&"Constructor type must be unqualified"); |
Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 427 | break; |
| 428 | case DeclarationName::CXXDestructorName: |
| 429 | EKind = DeclarationNameExtra::CXXDestructor; |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 430 | assert(!Ty.hasQualifiers() && "Destructor type must be unqualified"); |
Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 431 | break; |
| 432 | case DeclarationName::CXXConversionFunctionName: |
| 433 | EKind = DeclarationNameExtra::CXXConversionFunction; |
| 434 | break; |
| 435 | default: |
| 436 | return DeclarationName(); |
| 437 | } |
| 438 | |
| 439 | // Unique selector, to guarantee there is one per name. |
| 440 | llvm::FoldingSetNodeID ID; |
| 441 | ID.AddInteger(EKind); |
| 442 | ID.AddPointer(Ty.getAsOpaquePtr()); |
| 443 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 444 | void *InsertPos = nullptr; |
Bruno Ricci | b619883 | 2018-08-06 16:47:31 +0000 | [diff] [blame^] | 445 | if (CXXSpecialName *Name = CXXSpecialNames.FindNodeOrInsertPos(ID, InsertPos)) |
Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 446 | return DeclarationName(Name); |
| 447 | |
Ted Kremenek | 7e550ca | 2010-05-10 20:56:10 +0000 | [diff] [blame] | 448 | CXXSpecialName *SpecialName = new (Ctx) CXXSpecialName; |
Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 449 | SpecialName->ExtraKindOrNumArgs = EKind; |
| 450 | SpecialName->Type = Ty; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 451 | SpecialName->FETokenInfo = nullptr; |
Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 452 | |
Bruno Ricci | b619883 | 2018-08-06 16:47:31 +0000 | [diff] [blame^] | 453 | CXXSpecialNames.InsertNode(SpecialName, InsertPos); |
Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 454 | return DeclarationName(SpecialName); |
| 455 | } |
| 456 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 457 | DeclarationName |
Douglas Gregor | 163c585 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 458 | DeclarationNameTable::getCXXOperatorName(OverloadedOperatorKind Op) { |
| 459 | return DeclarationName(&CXXOperatorNames[(unsigned)Op]); |
| 460 | } |
| 461 | |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 462 | DeclarationName |
| 463 | DeclarationNameTable::getCXXLiteralOperatorName(IdentifierInfo *II) { |
Alexis Hunt | c88db06 | 2010-01-13 09:01:02 +0000 | [diff] [blame] | 464 | llvm::FoldingSetNodeID ID; |
| 465 | ID.AddPointer(II); |
| 466 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 467 | void *InsertPos = nullptr; |
Alexis Hunt | c88db06 | 2010-01-13 09:01:02 +0000 | [diff] [blame] | 468 | if (CXXLiteralOperatorIdName *Name = |
Bruno Ricci | b619883 | 2018-08-06 16:47:31 +0000 | [diff] [blame^] | 469 | CXXLiteralOperatorNames.FindNodeOrInsertPos(ID, InsertPos)) |
Alexis Hunt | c88db06 | 2010-01-13 09:01:02 +0000 | [diff] [blame] | 470 | return DeclarationName (Name); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 471 | |
Ted Kremenek | 7e550ca | 2010-05-10 20:56:10 +0000 | [diff] [blame] | 472 | CXXLiteralOperatorIdName *LiteralName = new (Ctx) CXXLiteralOperatorIdName; |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 473 | LiteralName->ExtraKindOrNumArgs = DeclarationNameExtra::CXXLiteralOperator; |
| 474 | LiteralName->ID = II; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 475 | LiteralName->FETokenInfo = nullptr; |
Alexis Hunt | c88db06 | 2010-01-13 09:01:02 +0000 | [diff] [blame] | 476 | |
Bruno Ricci | b619883 | 2018-08-06 16:47:31 +0000 | [diff] [blame^] | 477 | CXXLiteralOperatorNames.InsertNode(LiteralName, InsertPos); |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 478 | return DeclarationName(LiteralName); |
| 479 | } |
| 480 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 481 | DeclarationNameLoc::DeclarationNameLoc(DeclarationName Name) { |
| 482 | switch (Name.getNameKind()) { |
| 483 | case DeclarationName::Identifier: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 484 | case DeclarationName::CXXDeductionGuideName: |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 485 | break; |
| 486 | case DeclarationName::CXXConstructorName: |
| 487 | case DeclarationName::CXXDestructorName: |
| 488 | case DeclarationName::CXXConversionFunctionName: |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 489 | NamedType.TInfo = nullptr; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 490 | break; |
| 491 | case DeclarationName::CXXOperatorName: |
| 492 | CXXOperatorName.BeginOpNameLoc = SourceLocation().getRawEncoding(); |
| 493 | CXXOperatorName.EndOpNameLoc = SourceLocation().getRawEncoding(); |
| 494 | break; |
| 495 | case DeclarationName::CXXLiteralOperatorName: |
| 496 | CXXLiteralOperatorName.OpNameLoc = SourceLocation().getRawEncoding(); |
| 497 | break; |
| 498 | case DeclarationName::ObjCZeroArgSelector: |
| 499 | case DeclarationName::ObjCOneArgSelector: |
| 500 | case DeclarationName::ObjCMultiArgSelector: |
| 501 | // FIXME: ? |
| 502 | break; |
| 503 | case DeclarationName::CXXUsingDirective: |
| 504 | break; |
| 505 | } |
| 506 | } |
| 507 | |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 508 | bool DeclarationNameInfo::containsUnexpandedParameterPack() const { |
| 509 | switch (Name.getNameKind()) { |
| 510 | case DeclarationName::Identifier: |
| 511 | case DeclarationName::ObjCZeroArgSelector: |
| 512 | case DeclarationName::ObjCOneArgSelector: |
| 513 | case DeclarationName::ObjCMultiArgSelector: |
| 514 | case DeclarationName::CXXOperatorName: |
| 515 | case DeclarationName::CXXLiteralOperatorName: |
| 516 | case DeclarationName::CXXUsingDirective: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 517 | case DeclarationName::CXXDeductionGuideName: |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 518 | return false; |
| 519 | |
| 520 | case DeclarationName::CXXConstructorName: |
| 521 | case DeclarationName::CXXDestructorName: |
| 522 | case DeclarationName::CXXConversionFunctionName: |
| 523 | if (TypeSourceInfo *TInfo = LocInfo.NamedType.TInfo) |
| 524 | return TInfo->getType()->containsUnexpandedParameterPack(); |
| 525 | |
| 526 | return Name.getCXXNameType()->containsUnexpandedParameterPack(); |
| 527 | } |
Chandler Carruth | 2b59fbe | 2010-12-15 07:29:18 +0000 | [diff] [blame] | 528 | llvm_unreachable("All name kinds handled."); |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 529 | } |
| 530 | |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 531 | bool DeclarationNameInfo::isInstantiationDependent() const { |
| 532 | switch (Name.getNameKind()) { |
| 533 | case DeclarationName::Identifier: |
| 534 | case DeclarationName::ObjCZeroArgSelector: |
| 535 | case DeclarationName::ObjCOneArgSelector: |
| 536 | case DeclarationName::ObjCMultiArgSelector: |
| 537 | case DeclarationName::CXXOperatorName: |
| 538 | case DeclarationName::CXXLiteralOperatorName: |
| 539 | case DeclarationName::CXXUsingDirective: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 540 | case DeclarationName::CXXDeductionGuideName: |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 541 | return false; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 542 | |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 543 | case DeclarationName::CXXConstructorName: |
| 544 | case DeclarationName::CXXDestructorName: |
| 545 | case DeclarationName::CXXConversionFunctionName: |
| 546 | if (TypeSourceInfo *TInfo = LocInfo.NamedType.TInfo) |
| 547 | return TInfo->getType()->isInstantiationDependentType(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 548 | |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 549 | return Name.getCXXNameType()->isInstantiationDependentType(); |
| 550 | } |
| 551 | llvm_unreachable("All name kinds handled."); |
| 552 | } |
| 553 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 554 | std::string DeclarationNameInfo::getAsString() const { |
| 555 | std::string Result; |
| 556 | llvm::raw_string_ostream OS(Result); |
| 557 | printName(OS); |
| 558 | return OS.str(); |
| 559 | } |
| 560 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 561 | void DeclarationNameInfo::printName(raw_ostream &OS) const { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 562 | switch (Name.getNameKind()) { |
| 563 | case DeclarationName::Identifier: |
| 564 | case DeclarationName::ObjCZeroArgSelector: |
| 565 | case DeclarationName::ObjCOneArgSelector: |
| 566 | case DeclarationName::ObjCMultiArgSelector: |
| 567 | case DeclarationName::CXXOperatorName: |
| 568 | case DeclarationName::CXXLiteralOperatorName: |
| 569 | case DeclarationName::CXXUsingDirective: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 570 | case DeclarationName::CXXDeductionGuideName: |
David Blaikie | d4da872 | 2013-05-14 21:04:00 +0000 | [diff] [blame] | 571 | OS << Name; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 572 | return; |
| 573 | |
| 574 | case DeclarationName::CXXConstructorName: |
| 575 | case DeclarationName::CXXDestructorName: |
| 576 | case DeclarationName::CXXConversionFunctionName: |
| 577 | if (TypeSourceInfo *TInfo = LocInfo.NamedType.TInfo) { |
| 578 | if (Name.getNameKind() == DeclarationName::CXXDestructorName) |
| 579 | OS << '~'; |
| 580 | else if (Name.getNameKind() == DeclarationName::CXXConversionFunctionName) |
| 581 | OS << "operator "; |
Richard Smith | e81daee | 2014-01-22 00:27:42 +0000 | [diff] [blame] | 582 | LangOptions LO; |
| 583 | LO.CPlusPlus = true; |
Benjamin Kramer | 00e8a19 | 2014-02-25 18:03:55 +0000 | [diff] [blame] | 584 | LO.Bool = true; |
Alex Lorenz | a981c7d | 2017-04-11 16:46:03 +0000 | [diff] [blame] | 585 | PrintingPolicy PP(LO); |
| 586 | PP.SuppressScope = true; |
| 587 | OS << TInfo->getType().getAsString(PP); |
David Blaikie | d4da872 | 2013-05-14 21:04:00 +0000 | [diff] [blame] | 588 | } else |
| 589 | OS << Name; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 590 | return; |
| 591 | } |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 592 | llvm_unreachable("Unexpected declaration name kind"); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 593 | } |
| 594 | |
Stephen Kelly | f50288c | 2018-07-30 20:39:14 +0000 | [diff] [blame] | 595 | SourceLocation DeclarationNameInfo::getEndLocPrivate() const { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 596 | switch (Name.getNameKind()) { |
| 597 | case DeclarationName::Identifier: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 598 | case DeclarationName::CXXDeductionGuideName: |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 599 | return NameLoc; |
| 600 | |
| 601 | case DeclarationName::CXXOperatorName: { |
| 602 | unsigned raw = LocInfo.CXXOperatorName.EndOpNameLoc; |
| 603 | return SourceLocation::getFromRawEncoding(raw); |
| 604 | } |
| 605 | |
| 606 | case DeclarationName::CXXLiteralOperatorName: { |
| 607 | unsigned raw = LocInfo.CXXLiteralOperatorName.OpNameLoc; |
| 608 | return SourceLocation::getFromRawEncoding(raw); |
| 609 | } |
| 610 | |
| 611 | case DeclarationName::CXXConstructorName: |
| 612 | case DeclarationName::CXXDestructorName: |
| 613 | case DeclarationName::CXXConversionFunctionName: |
| 614 | if (TypeSourceInfo *TInfo = LocInfo.NamedType.TInfo) |
| 615 | return TInfo->getTypeLoc().getEndLoc(); |
| 616 | else |
| 617 | return NameLoc; |
| 618 | |
| 619 | // DNInfo work in progress: FIXME. |
| 620 | case DeclarationName::ObjCZeroArgSelector: |
| 621 | case DeclarationName::ObjCOneArgSelector: |
| 622 | case DeclarationName::ObjCMultiArgSelector: |
| 623 | case DeclarationName::CXXUsingDirective: |
| 624 | return NameLoc; |
| 625 | } |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 626 | llvm_unreachable("Unexpected declaration name kind"); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 627 | } |