clang: lib/AST/DeclarationName.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

30#include "llvm/ADT/FoldingSet.h"

31#include "llvm/Support/Compiler.h"

32#include "llvm/Support/ErrorHandling.h"

33#include "llvm/Support/raw_ostream.h"

34#include

35#include

36#include

37

38using namespace clang;

39

40static int compareInt(unsigned A, unsigned B) {

41 return (A < B ? -1 : (A > B ? 1 : 0));

42}

43

47

52 if (!LII)

53 return RII ? -1 : 0;

54 if (!RII)

55 return 1;

56

58 }

59

65

68 return LHSSelector.getAsIdentifierInfo()->getName().compare(

69 RHSSelector.getAsIdentifierInfo()->getName());

70 }

72 for (unsigned I = 0, N = std::min(LN, RN); I != N; ++I) {

73 if (int Compare = LHSSelector.getNameForSlot(I).compare(

75 return Compare;

76 }

77

79 }

80

85 return -1;

87 return 1;

88 return 0;

89

91

92

95

99

103

105 return 0;

106 }

107

108 llvm_unreachable("Invalid DeclarationName Kind!");

109}

110

112 raw_ostream &OS,

114

116

118 ClassRec->getDecl()->printName(OS, Policy);

119 return;

120 }

123 InjTy->getDecl()->printName(OS, Policy);

124 return;

125 }

126 }

127 ClassType.print(OS, Policy);

128}

129

135 StringRef Name = II->getName();

136

137

138 if (II->isMangledOpenMPVariantName()) {

139 std::pair<StringRef, StringRef> NameContextPair =

141 OS << NameContextPair.first << "["

142 << OMPTraitInfo(NameContextPair.second) << "]";

143 } else {

144 OS << Name;

145 }

146 }

147 return;

148

153 return;

154

157

159 OS << '~';

161

163 OS << "<deduction guide for ";

165 OS << '>';

166 return;

167

170 assert(OpName && "not an overloaded operator");

171

172 OS << "operator";

173 if (OpName[0] >= 'a' && OpName[0] <= 'z')

174 OS << ' ';

175 OS << OpName;

176 return;

177 }

178

181 return;

182

184 OS << "operator ";

187 OS << *Rec->getDecl();

188 return;

189 }

190

193 Type.print(OS, CXXPolicy);

194 return;

195 }

197 OS << "";

198 return;

199 }

200

201 llvm_unreachable("Unexpected declaration name kind");

202}

203

205

209 return OS;

210}

211

212}

213

217 return true;

218

219

221 if (TD && TD->getDeclContext()->isDependentContext())

222 return true;

223

224 return false;

225}

226

229 llvm::raw_string_ostream OS(Result);

230 OS << *this;

232}

233

234void *DeclarationName::getFETokenInfoSlow() const {

237 llvm_unreachable("case Identifier already handled by getFETokenInfo!");

241 return castAsCXXSpecialNameExtra()->FETokenInfo;

243 return castAsCXXOperatorIdName()->FETokenInfo;

245 return castAsCXXDeductionGuideNameExtra()->FETokenInfo;

247 return castAsCXXLiteralOperatorIdName()->FETokenInfo;

248 default:

249 llvm_unreachable("DeclarationName has no FETokenInfo!");

250 }

251}

252

253void DeclarationName::setFETokenInfoSlow(void *T) {

256 llvm_unreachable("case Identifier already handled by setFETokenInfo!");

260 castAsCXXSpecialNameExtra()->FETokenInfo = T;

261 break;

263 castAsCXXOperatorIdName()->FETokenInfo = T;

264 break;

266 castAsCXXDeductionGuideNameExtra()->FETokenInfo = T;

267 break;

269 castAsCXXLiteralOperatorIdName()->FETokenInfo = T;

270 break;

271 default:

272 llvm_unreachable("DeclarationName has no FETokenInfo!");

273 }

274}

275

277 llvm::errs() << *this << '\n';

278}

279

281

284}

285

289

290 llvm::FoldingSetNodeID ID;

291 ID.AddPointer(Template);

292

293 void *InsertPos = nullptr;

294 if (auto *Name = CXXDeductionGuideNames.FindNodeOrInsertPos(ID, InsertPos))

296

298 CXXDeductionGuideNames.InsertNode(Name, InsertPos);

300}

301

303

305

306 llvm::FoldingSetNodeID ID;

308 void *InsertPos = nullptr;

309 if (auto *Name = CXXConstructorNames.FindNodeOrInsertPos(ID, InsertPos))

310 return {Name, DeclarationName::StoredCXXConstructorName};

311

312

314 CXXConstructorNames.InsertNode(SpecialName, InsertPos);

315 return {SpecialName, DeclarationName::StoredCXXConstructorName};

316}

317

319

321

322 llvm::FoldingSetNodeID ID;

324 void *InsertPos = nullptr;

325 if (auto *Name = CXXDestructorNames.FindNodeOrInsertPos(ID, InsertPos))

326 return {Name, DeclarationName::StoredCXXDestructorName};

327

328

330 CXXDestructorNames.InsertNode(SpecialName, InsertPos);

331 return {SpecialName, DeclarationName::StoredCXXDestructorName};

332}

333

336

337 llvm::FoldingSetNodeID ID;

339 void *InsertPos = nullptr;

340 if (auto *Name =

341 CXXConversionFunctionNames.FindNodeOrInsertPos(ID, InsertPos))

342 return {Name, DeclarationName::StoredCXXConversionFunctionName};

343

344

346 CXXConversionFunctionNames.InsertNode(SpecialName, InsertPos);

347 return {SpecialName, DeclarationName::StoredCXXConversionFunctionName};

348}

349

353 switch (Kind) {

360 default:

361 llvm_unreachable("Invalid kind in getCXXSpecialName!");

362 }

363}

364

367 llvm::FoldingSetNodeID ID;

368 ID.AddPointer(II);

369

370 void *InsertPos = nullptr;

371 if (auto *Name = CXXLiteralOperatorNames.FindNodeOrInsertPos(ID, InsertPos))

373

375 CXXLiteralOperatorNames.InsertNode(LiteralName, InsertPos);

377}

378

380 switch (Name.getNameKind()) {

383 break;

387 setNamedTypeLoc(nullptr);

388 break;

391 break;

394 break;

398

399 break;

401 break;

402 }

403}

404

415 return false;

416

421 return TInfo->getType()->containsUnexpandedParameterPack();

422

424 }

425 llvm_unreachable("All name kinds handled.");

426}

427

438 return false;

439

444 return TInfo->getType()->isInstantiationDependentType();

445

447 }

448 llvm_unreachable("All name kinds handled.");

449}

450

453 llvm::raw_string_ostream OS(Result);

454 OS << *this;

456}

457

461 return OS;

462}

463

474 Name.print(OS, Policy);

475 return;

476

482 OS << '~';

484 OS << "operator ";

488 OS << TInfo->getType().getAsString(Policy);

489 } else

490 Name.print(OS, Policy);

491 return;

492 }

493 llvm_unreachable("Unexpected declaration name kind");

494}

495

496SourceLocation DeclarationNameInfo::getEndLocPrivate() const {

500 return NameLoc;

501

504

507

512 return TInfo->getTypeLoc().getEndLoc();

513 else

514 return NameLoc;

515

516

521 return NameLoc;

522 }

523 llvm_unreachable("Unexpected declaration name kind");

524}

Defines the clang::ASTContext interface.

Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....

Defines the C++ template declaration subclasses.

static void printCXXConstructorDestructorName(QualType ClassType, raw_ostream &OS, PrintingPolicy Policy)

static int compareInt(unsigned A, unsigned B)

Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.

Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.

Defines the clang::LangOptions interface.

This file defines OpenMP AST classes for clauses.

Defines an enumeration for C++ overloaded operators.

Defines the clang::SourceLocation class and associated facilities.

Defines the clang::TypeLoc interface and its subclasses.

Allows QualTypes to be sorted and hence used in maps and sets.

C Language Family Type Representation.

Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...

void * getAsOpaquePtr() const

Retrieve the internal representation of this canonical type.

CanQual< T > getUnqualifiedType() const

Retrieve the unqualified form of this type.

virtual Decl * getCanonicalDecl()

Retrieves the "canonical" declaration of the given declaration.

SourceLocation getCXXLiteralOperatorNameLoc() const

Return the location of the literal operator name (without the operator keyword).

TypeSourceInfo * getNamedTypeInfo() const

Returns the source type info.

SourceLocation getCXXOperatorNameEndLoc() const

Return the end location of the getCXXOperatorNameRange() range.

The name of a declaration.

static int compare(DeclarationName LHS, DeclarationName RHS)

IdentifierInfo * getAsIdentifierInfo() const

Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn't...

bool isDependentName() const

Determines whether the name itself is dependent, e.g., because it involves a C++ type that is itself ...

TemplateDecl * getCXXDeductionGuideTemplate() const

If this name is the name of a C++ deduction guide, return the template associated with that name.

void print(raw_ostream &OS, const PrintingPolicy &Policy) const

std::string getAsString() const

Retrieve the human-readable string for this name.

const IdentifierInfo * getCXXLiteralIdentifier() const

If this name is the name of a literal operator, retrieve the identifier associated with it.

OverloadedOperatorKind getCXXOverloadedOperator() const

If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...

NameKind

The kind of the name stored in this DeclarationName.

@ CXXConversionFunctionName

QualType getCXXNameType() const

If this name is one of the C++ names (of a constructor, destructor, or conversion function),...

Selector getObjCSelector() const

Get the Objective-C selector stored in this declaration name.

NameKind getNameKind() const

Determine what kind of name this is.

One of these records is kept for each identifier that is lexed.

StringRef getName() const

Return the actual identifier string.

The injected class name of a C++ class template or class template partial specialization.

Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...

DeclarationName getDeclName() const

Get the actual, stored name of the declaration, which may be a special name.

Helper data structure representing the traits in a match clause of an declare variant or metadirectiv...

A (possibly-)qualified type.

void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const

A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...

Smart pointer class that efficiently represents Objective-C method names.

StringRef getNameForSlot(unsigned argIndex) const

Retrieve the name at a given position in the selector.

void print(llvm::raw_ostream &OS) const

Prints the full selector name (e.g. "foo:bar:").

unsigned getNumArgs() const

Encodes a location in the source.

A trivial tuple used to represent a source range.

The base class of all kinds of template declarations (e.g., class, function, etc.).

A container of type source information.

The base class of the type hierarchy.

bool isInstantiationDependentType() const

Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...

bool isDependentType() const

Whether this type is a dependent type, meaning that its definition somehow depends on a template para...

bool containsUnexpandedParameterPack() const

Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...

const T * getAs() const

Member-template getAs'.

Contains the actual identifier that makes up the name of a C++ literal operator.

The JSON file list parser is used to communicate input to InstallAPI.

OverloadedOperatorKind

Enumeration specifying the different kinds of C++ overloaded operators.

@ NUM_OVERLOADED_OPERATORS

static constexpr StringRef getOpenMPVariantManglingSeparatorStr()

OpenMP variants are mangled early based on their OpenMP context selector.

const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ASTContext::SectionInfo &Section)

Insertion operator for diagnostics.

@ Result

The result type of a method or function.

const FunctionProtoType * T

const char * getOperatorSpelling(OverloadedOperatorKind Operator)

Retrieve the spelling of the given overloaded operator, without the preceding "operator" keyword.

DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...

bool isInstantiationDependent() const

Determine whether this name involves a template parameter.

void printName(raw_ostream &OS, PrintingPolicy Policy) const

printName - Print the human-readable name to a stream.

std::string getAsString() const

getAsString - Retrieve the human-readable string for this name.

bool containsUnexpandedParameterPack() const

Determine whether this name contains an unexpanded parameter pack.

Describes how types, statements, expressions, and declarations should be printed.

void adjustForCPlusPlus()

Adjust this printing policy for cases where it's known that we're printing C++ code (for instance,...

unsigned SuppressScope

Suppresses printing of scope specifiers.

unsigned SuppressTemplateArgsInCXXConstructors

When true, suppresses printing template arguments in names of C++ constructors.

Function object that provides a total ordering on QualType values.