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

1

2

3

4

5

6

7

8

13

15

17

18

19

20

21

22

23

24

25

27 const ASTContext &Ctx,

28 const NamespaceDecl *Namesp,

29 bool WithGlobalNsPrefix);

30

31

32

33

34

35

36

37

38

39

40

42 const ASTContext &Ctx, const TypeDecl *TD,

43 bool FullyQualify, bool WithGlobalNsPrefix);

44

46 const ASTContext &Ctx, const Decl *decl,

47 bool FullyQualified, bool WithGlobalNsPrefix);

48

50 const ASTContext &Ctx, NestedNameSpecifier *scope, bool WithGlobalNsPrefix);

51

54 bool WithGlobalNsPrefix) {

55 bool Changed = false;

57

59

60

61 assert(ArgTDecl != nullptr);

63

64 if (QTName &&

68 Ctx, NNS, WithGlobalNsPrefix);

69 if (QNNS != NNS) {

70 Changed = true;

71 NNS = QNNS;

72 } else {

73 NNS = nullptr;

74 }

75 } else {

77 Ctx, ArgTDecl, true, WithGlobalNsPrefix);

78 }

79 if (NNS) {

83 TName =

85 false, UnderlyingTN);

86 Changed = true;

87 }

88 return Changed;

89}

90

93 bool WithGlobalNsPrefix) {

94 bool Changed = false;

95

96

97

98

102 if (Changed) {

104 }

107

109 if (QTFQ != SubTy) {

111 Changed = true;

112 }

113 }

114 return Changed;

115}

116

118 const Type *TypePtr,

119 bool WithGlobalNsPrefix) {

120

121

122

123 assert(!isa(TypePtr));

124

125

126 if (const auto *TST = dyn_cast(TypePtr)) {

127 bool MightHaveChanged = false;

129

130

133 Ctx, Arg, WithGlobalNsPrefix);

134 FQArgs.push_back(Arg);

135 }

136

137

138

139 if (MightHaveChanged) {

141 TST->getTemplateName(), FQArgs,

142 TST->getCanonicalTypeInternal());

143

144

145

147 }

148 } else if (const auto *TSTRecord = dyn_cast(TypePtr)) {

149

150

151

152

153 if (const auto *TSTDecl =

154 dyn_cast(TSTRecord->getDecl())) {

156

157 bool MightHaveChanged = false;

159 for (unsigned int I = 0, E = TemplateArgs.size(); I != E; ++I) {

160

161

164 Ctx, Arg, WithGlobalNsPrefix);

165 FQArgs.push_back(Arg);

166 }

167

168

169

170 if (MightHaveChanged) {

171 TemplateName TN(TSTDecl->getSpecializedTemplate());

173 TN, FQArgs,

174 TSTRecord->getCanonicalTypeInternal());

175

176

177

179 }

180 }

181 }

182 return TypePtr;

183}

184

186 bool FullyQualify,

187 bool WithGlobalNsPrefix) {

189 if (const auto *NS = dyn_cast(DC)) {

190 while (NS && NS->isInline()) {

191

192 NS = dyn_cast(NS->getDeclContext());

193 }

194 if (NS && NS->getDeclName()) {

196 }

197 return nullptr;

198 } else if (const auto *TD = dyn_cast(DC)) {

200 } else if (const auto *TDD = dyn_cast(DC)) {

202 Ctx, TDD, FullyQualify, WithGlobalNsPrefix);

205 }

206 return nullptr;

207}

208

209

212 bool WithGlobalNsPrefix) {

213 switch (Scope->getKind()) {

215

219 Ctx, Scope->getAsNamespace(), WithGlobalNsPrefix);

221

222

223

224

226 Ctx,

227 Scope->getAsNamespaceAlias()->getNamespace()->getCanonicalDecl(),

228 WithGlobalNsPrefix);

230

231

232

234 Ctx, Scope->getPrefix(), WithGlobalNsPrefix);

239

240 const TagDecl *TD = nullptr;

242 TD = TagDeclType->getDecl();

243 } else {

245 }

246 if (TD) {

248 true ,

249 WithGlobalNsPrefix);

250 } else if (const auto *TDD = dyn_cast(Type)) {

252 true ,

253 WithGlobalNsPrefix);

254 }

256 }

257 }

258 llvm_unreachable("bad NNS kind");

259}

260

261

262

265 bool FullyQualified, bool WithGlobalNsPrefix) {

266 assert(Decl);

267

269 const auto *Outer = dyn_cast(DC);

270 const auto *OuterNS = dyn_cast(DC);

271 if (Outer && !(OuterNS && OuterNS->isAnonymousNamespace())) {

272 if (const auto *CxxDecl = dyn_cast(DC)) {

274 CxxDecl->getDescribedClassTemplate()) {

275

276

277

278

279

280

281

282

283

284

285 if (ClassTempl->spec_begin() != ClassTempl->spec_end()) {

286 Decl = *(ClassTempl->spec_begin());

287 Outer = dyn_cast(Decl);

288 OuterNS = dyn_cast(Decl);

289 }

290 }

291 }

292

293 if (OuterNS) {

295 } else if (const auto *TD = dyn_cast(Outer)) {

297 Ctx, TD, FullyQualified, WithGlobalNsPrefix);

298 } else if (isa(Outer)) {

299

300 return nullptr;

301 } else {

302

303

304

305 return nullptr;

306 }

309 }

310 return nullptr;

311}

312

313

314

317 bool FullyQualified, bool WithGlobalNsPrefix) {

318 if (!TypePtr) return nullptr;

319

321

322 if (const auto *TDT = dyn_cast(TypePtr)) {

323 Decl = TDT->getDecl();

324 } else if (const auto *TagDeclType = dyn_cast(TypePtr)) {

325 Decl = TagDeclType->getDecl();

326 } else if (const auto *TST = dyn_cast(TypePtr)) {

327 Decl = TST->getTemplateName().getAsTemplateDecl();

328 } else {

330 }

331

332 if (Decl) return nullptr;

333

335 Ctx, Decl, FullyQualified, WithGlobalNsPrefix);

336}

337

340 bool WithGlobalNsPrefix) {

341 while (Namespace && Namespace->isInline()) {

342

343 Namespace = dyn_cast(Namespace->getDeclContext());

344 }

345 if (!Namespace) return nullptr;

346

347 bool FullyQualified = true;

349 Ctx,

350 createOuterNNS(Ctx, Namespace, FullyQualified, WithGlobalNsPrefix),

351 Namespace);

352}

353

356 bool FullyQualify,

357 bool WithGlobalNsPrefix) {

359 if (isa(TypePtr) ||

360 isa(TypePtr)) {

361

362

363

364

366 }

367

369 Ctx, createOuterNNS(Ctx, TD, FullyQualify, WithGlobalNsPrefix),

370 false , TypePtr);

371}

372

373

374

376 bool WithGlobalNsPrefix) {

377

378

379 if (isa(QT.getTypePtr())) {

380

384

386 return QT;

387 }

388

389 if (auto *MPT = dyn_cast(QT.getTypePtr())) {

390

392

395 WithGlobalNsPrefix);

397

399 return QT;

400 }

401

402

403

404 if (isa(QT.getTypePtr())) {

405

406 bool IsLValueRefTy = isa(QT.getTypePtr());

409

410

411 if (IsLValueRefTy)

413 else

415

417 return QT;

418 }

419

420

421

422

423

424 while (isa(QT.getTypePtr())) {

425

427

428 QT = cast(QT.getTypePtr())->desugar();

429

430

432 }

433

435

436

437

441 if (const auto *ETypeInput = dyn_cast(QT.getTypePtr())) {

442 QT = ETypeInput->getNamedType();

444 Keyword = ETypeInput->getKeyword();

445 }

446

447

448

450 QT = Ctx.getQualifiedType(UT->getUnderlyingType(), PrefixQualifiers);

452 }

453

454

456 true ,

457 WithGlobalNsPrefix);

458

459

460

461 if (isa(QT.getTypePtr()) ||

462 isa(QT.getTypePtr())) {

463

464

465

466

468 Ctx, QT.getTypePtr(), WithGlobalNsPrefix);

470 }

473 }

475 return QT;

476}

477

481 bool WithGlobalNsPrefix) {

484}

485

486}

487}

Defines the C++ template declaration subclasses.

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

QualType getRValueReferenceType(QualType T) const

Return the uniqued reference to the type for an rvalue reference to the specified type.

QualType getMemberPointerType(QualType T, const Type *Cls) const

Return the uniqued reference to the type for a member pointer to the specified type in the specified ...

QualType getTemplateSpecializationType(TemplateName T, ArrayRef< TemplateArgument > Args, QualType Canon=QualType()) const

TemplateName getQualifiedTemplateName(NestedNameSpecifier *NNS, bool TemplateKeyword, TemplateName Template) const

Retrieve the template name that represents a qualified template name such as std::vector.

QualType getPointerType(QualType T) const

Return the uniqued reference to the type for a pointer to the specified type.

QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const

Return the uniqued reference to the type for an lvalue reference to the specified type.

QualType getQualifiedType(SplitQualType split) const

Un-split a SplitQualType.

QualType getElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, QualType NamedType, TagDecl *OwnedTagDecl=nullptr) const

Declaration of a class template.

DeclContext - This is used only as base class of specific decl types that can act as declaration cont...

bool isTranslationUnit() const

DeclContext * getRedeclContext()

getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...

Decl - This represents one declaration (or definition), e.g.

DeclContext * getDeclContext()

Represent a C++ namespace.

Represents a C++ nested name specifier, such as "\::std::vector::".

static NestedNameSpecifier * Create(const ASTContext &Context, NestedNameSpecifier *Prefix, const IdentifierInfo *II)

Builds a specifier combining a prefix and an identifier.

static NestedNameSpecifier * GlobalSpecifier(const ASTContext &Context)

Returns the nested name specifier representing the global scope.

@ NamespaceAlias

A namespace alias, stored as a NamespaceAliasDecl*.

@ TypeSpec

A type, stored as a Type*.

@ TypeSpecWithTemplate

A type that was preceded by the 'template' keyword, stored as a Type*.

@ Super

Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.

@ Identifier

An identifier, stored as an IdentifierInfo*.

@ Global

The global specifier '::'. There is no stored value.

@ Namespace

A namespace, stored as a NamespaceDecl*.

A (possibly-)qualified type.

bool hasLocalQualifiers() const

Determine whether this particular QualType instance has any qualifiers, without looking through any t...

const Type * getTypePtr() const

Retrieves a pointer to the underlying (unqualified) type.

Qualifiers getQualifiers() const

Retrieve the set of qualifiers applied to this type.

static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)

Qualifiers getLocalQualifiers() const

Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...

Represents a template name as written in source code.

NestedNameSpecifier * getQualifier() const

Return the nested name specifier that qualifies this name.

bool hasTemplateKeyword() const

Whether the template name was prefixed by the "template" keyword.

The collection of all-type qualifiers we support.

Scope - A scope is a transient data structure that is used while parsing the program.

Represents the declaration of a struct/union/class/enum.

A template argument list.

unsigned size() const

Retrieve the number of template arguments in this template argument list.

Represents a template argument.

QualType getAsType() const

Retrieve the type for a type template argument.

TemplateName getAsTemplate() const

Retrieve the template name for a template name argument.

@ Template

The template argument is a template name that was provided for a template template parameter.

@ Type

The template argument is a type.

ArgKind getKind() const

Return the kind of stored template argument.

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

Represents a C++ template name within the type system.

TemplateDecl * getAsTemplateDecl(bool IgnoreDeduced=false) const

Retrieve the underlying template declaration that this template name refers to, if known.

QualifiedTemplateName * getAsQualifiedTemplateName() const

Retrieve the underlying qualified template name structure, if any.

UsingShadowDecl * getAsUsingShadowDecl() const

Retrieve the using shadow declaration through which the underlying template declaration is introduced...

Represents a declaration of a type.

const Type * getTypeForDecl() const

The base class of the type hierarchy.

CXXRecordDecl * getAsCXXRecordDecl() const

Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...

QualType getPointeeType() const

If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.

const T * getAs() const

Member-template getAs'.

Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...

static NestedNameSpecifier * createOuterNNS(const ASTContext &Ctx, const Decl *D, bool FullyQualify, bool WithGlobalNsPrefix)

static bool getFullyQualifiedTemplateName(const ASTContext &Ctx, TemplateName &TName, bool WithGlobalNsPrefix)

static const Type * getFullyQualifiedTemplateType(const ASTContext &Ctx, const Type *TypePtr, bool WithGlobalNsPrefix)

static NestedNameSpecifier * getFullyQualifiedNestedNameSpecifier(const ASTContext &Ctx, NestedNameSpecifier *scope, bool WithGlobalNsPrefix)

Return a fully qualified version of this name specifier.

static bool getFullyQualifiedTemplateArgument(const ASTContext &Ctx, TemplateArgument &Arg, bool WithGlobalNsPrefix)

static NestedNameSpecifier * createNestedNameSpecifierForScopeOf(const ASTContext &Ctx, const Decl *decl, bool FullyQualified, bool WithGlobalNsPrefix)

Create a nested name specifier for the declaring context of the type.

std::string getFullyQualifiedName(QualType QT, const ASTContext &Ctx, const PrintingPolicy &Policy, bool WithGlobalNsPrefix=false)

Get the fully qualified name for a type.

static NestedNameSpecifier * createNestedNameSpecifier(const ASTContext &Ctx, const NamespaceDecl *Namesp, bool WithGlobalNsPrefix)

Create a NestedNameSpecifier for Namesp and its enclosing scopes.

QualType getFullyQualifiedType(QualType QT, const ASTContext &Ctx, bool WithGlobalNsPrefix=false)

Generates a QualType that can be used to name the same type if used at the end of the current transla...

const internal::VariadicAllOfMatcher< Decl > decl

Matches declarations.

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

ElaboratedTypeKeyword

The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...

@ None

No keyword precedes the qualified type name.

@ Class

The "class" keyword introduces the elaborated-type-specifier.

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