clang: include/clang/Sema/Lookup.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14#ifndef LLVM_CLANG_SEMA_LOOKUP_H

15#define LLVM_CLANG_SEMA_LOOKUP_H

16

28#include "llvm/ADT/MapVector.h"

29#include "llvm/ADT/STLExtras.h"

30#include "llvm/Support/Casting.h"

31#include

32#include

33#include

34

36

37class CXXBasePaths;

38

39

40

41

42

43

44

45

47public:

49

51

52

53

54

56

57

58

60

61

62

64

65

66

67

69

70

71

72

75

77

78

79

80

81

82

83

84

85

86

87

88

90

91

92

93

94

95

96

97

98

99

100

101

102

104

105

106

107

108

109

110

111

112

113

114

115

116

117

119

120

121

122

123

124

125

126

127

128

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

148

149

153

155

159 RedeclarationKind Redecl = RedeclarationKind::NotForRedeclaration)

160 : SemaPtr(&SemaRef), NameInfo(NameInfo), LookupKind(LookupKind),

165 configure();

166 }

167

168

169

170

174 RedeclarationKind Redecl = RedeclarationKind::NotForRedeclaration)

175 : SemaPtr(&SemaRef), NameInfo(Name, NameLoc), LookupKind(LookupKind),

180 configure();

181 }

182

183

184

185

187 : SemaPtr(Other.SemaPtr), NameInfo(Other.NameInfo),

188 LookupKind(Other.LookupKind), IDNS(Other.IDNS), Redecl(Other.Redecl),

189 ExternalRedecl(Other.ExternalRedecl), HideTags(Other.HideTags),

190 AllowHidden(Other.AllowHidden),

191 TemplateNameLookup(Other.TemplateNameLookup) {}

192

193

194

197

199 : ResultKind(std::move(Other.ResultKind)),

200 Ambiguity(std::move(Other.Ambiguity)), Decls(std::move(Other.Decls)),

201 Paths(std::move(Other.Paths)),

202 NamingClass(std::move(Other.NamingClass)),

203 BaseObjectType(std::move(Other.BaseObjectType)),

204 SemaPtr(std::move(Other.SemaPtr)), NameInfo(std::move(Other.NameInfo)),

205 NameContextRange(std::move(Other.NameContextRange)),

206 LookupKind(std::move(Other.LookupKind)), IDNS(std::move(Other.IDNS)),

207 Redecl(std::move(Other.Redecl)),

208 ExternalRedecl(std::move(Other.ExternalRedecl)),

209 HideTags(std::move(Other.HideTags)),

210 DiagnoseAccess(std::move(Other.DiagnoseAccess)),

211 DiagnoseAmbiguous(std::move(Other.DiagnoseAmbiguous)),

212 AllowHidden(std::move(Other.AllowHidden)),

213 Shadowed(std::move(Other.Shadowed)),

214 TemplateNameLookup(std::move(Other.TemplateNameLookup)) {

215 Other.Paths = nullptr;

216 Other.DiagnoseAccess = false;

217 Other.DiagnoseAmbiguous = false;

218 }

219

221 ResultKind = std::move(Other.ResultKind);

222 Ambiguity = std::move(Other.Ambiguity);

223 Decls = std::move(Other.Decls);

224 Paths = std::move(Other.Paths);

225 NamingClass = std::move(Other.NamingClass);

226 BaseObjectType = std::move(Other.BaseObjectType);

227 SemaPtr = std::move(Other.SemaPtr);

228 NameInfo = std::move(Other.NameInfo);

229 NameContextRange = std::move(Other.NameContextRange);

230 LookupKind = std::move(Other.LookupKind);

231 IDNS = std::move(Other.IDNS);

232 Redecl = std::move(Other.Redecl);

233 ExternalRedecl = std::move(Other.ExternalRedecl);

234 HideTags = std::move(Other.HideTags);

235 DiagnoseAccess = std::move(Other.DiagnoseAccess);

236 DiagnoseAmbiguous = std::move(Other.DiagnoseAmbiguous);

237 AllowHidden = std::move(Other.AllowHidden);

238 Shadowed = std::move(Other.Shadowed);

239 TemplateNameLookup = std::move(Other.TemplateNameLookup);

240 Other.Paths = nullptr;

241 Other.DiagnoseAccess = false;

242 Other.DiagnoseAmbiguous = false;

243 return *this;

244 }

245

247 if (DiagnoseAccess)

248 diagnoseAccess();

249 if (DiagnoseAmbiguous)

250 diagnoseAmbiguous();

251 if (Paths) deletePaths(Paths);

252 }

253

254

256 return NameInfo;

257 }

258

259

261 this->NameInfo = NameInfo;

262 }

263

264

266 return NameInfo.getName();

267 }

268

269

272 }

273

274

276 return LookupKind;

277 }

278

279

281 return Redecl;

282 }

283

284

285

287 return ExternalRedecl;

288 }

289

291 return ExternalRedecl ? RedeclarationKind::ForExternalRedeclaration

292 : Redecl ? RedeclarationKind::ForVisibleRedeclaration

293 : RedeclarationKind::NotForRedeclaration;

294 }

295

296

297

299 AllowHidden = AH;

300 }

301

302

303

305 return AllowHidden ||

307 }

308

309

310

312 HideTags = Hide;

313 }

314

315

316

317

320 }

321

323

326 }

327

328

329

330

333 }

334

335

338 }

339

342 }

343

345 assert(checkDebugAssumptions());

346 return ResultKind;

347 }

348

351 return Ambiguity;

352 }

353

355 return Decls;

356 }

357

360

361

363

364

365

367 return Paths;

368 }

369

370

371

373

375

380 }

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

405

406

407

409 if (D->isInIdentifierNamespace(IDNS))

410 return nullptr;

411

413 return D;

414

415 return getAcceptableDeclSlow(D);

416 }

417

418private:

419 static bool isAcceptableSlow(Sema &SemaRef, NamedDecl *D,

421 static bool isReachableSlow(Sema &SemaRef, NamedDecl *D);

423

424public:

425

427 return IDNS;

428 }

429

430

431

433 return NamingClass != nullptr;

434 }

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

453 return NamingClass;

454 }

455

456

458 NamingClass = Record;

459 }

460

461

462

463

465 return BaseObjectType;

466 }

467

468

470 BaseObjectType = T;

471 }

472

473

474

477 }

478

479

480

483 ResultKind = Found;

484 }

485

486

487

490 ResultKind = Found;

491 }

492

493

494

497 }

498

499

500

502 assert((ResultKind == NotFound ||

506 }

507

508

509

511

512

513

515

516

517

518

519

520

522

523

524

526 if (Decls.empty()) {

529

530 if (Paths) {

531 deletePaths(Paths);

532 Paths = nullptr;

533 }

534 } else {

535 std::optional SavedAK;

536 bool WasAmbiguous = false;

538 SavedAK = Ambiguity;

539 WasAmbiguous = true;

540 }

541 ResultKind = Found;

543

544

545

547 (void)WasAmbiguous;

548 assert(WasAmbiguous);

549 Ambiguity = *SavedAK;

550 } else if (Paths) {

551 deletePaths(Paths);

552 Paths = nullptr;

553 }

554 }

555 }

556

557 template

561 }

562

563

564

565

566

567

570 && "getFoundDecl called on non-unique result");

571 return (*begin())->getUnderlyingDecl();

572 }

573

574

576 assert(!Decls.empty() && "cannot get representative of empty set");

578 }

579

580

583 }

584

585

586

587

588

590

591

592

593

594

596

597

598

599

602 }

603

604

605 LLVM_ATTRIBUTE_REINITIALIZES void clear() {

608 if (Paths) deletePaths(Paths);

609 Paths = nullptr;

610 NamingClass = nullptr;

611 Shadowed = false;

612 }

613

614

615

618 LookupKind = Kind;

619 configure();

620 }

621

622

624 Redecl = (RK != RedeclarationKind::NotForRedeclaration);

625 ExternalRedecl = (RK == RedeclarationKind::ForExternalRedeclaration);

626 configure();

627 }

628

630 void print(raw_ostream &);

631

632

633

635 DiagnoseAccess = false;

636 DiagnoseAmbiguous = false;

637 }

638

639

640

642

643

645

646

647

649

650

652 NameContextRange = SR;

653 }

654

655

656

657

659 return NameContextRange;

660 }

661

662

663

665 return NameInfo.getLoc();

666 }

667

668

669

671

672

673

674

677

680 bool Changed = false;

681 bool CalledDone = false;

682

684

685 public:

687 : Results(F.Results), I(F.I), Changed(F.Changed),

688 CalledDone(F.CalledDone) {

689 F.CalledDone = true;

690 }

691

692

693

695

696

697

700

702 assert(CalledDone &&

703 "LookupResult::Filter destroyed without done() call");

704 }

705

707 return I != Results.end();

708 }

709

711 assert(I != Results.end() && "next() called on empty filter");

712 return *I++;

713 }

714

715

717 I = Results.begin();

718 }

719

720

722 Results.Decls.erase(--I);

723 Changed = true;

724 }

725

726

727

729 Results.Decls.replace(I-1, D);

730 Changed = true;

731 }

732

733

735 Results.Decls.replace(I-1, D, AS);

736 Changed = true;

737 }

738

740 assert(!CalledDone && "done() called twice");

741 CalledDone = true;

742

743 if (Changed)

744 Results.resolveKindAfterFilter();

745 }

746 };

747

748

750 return Filter(*this);

751 }

752

754 if (FindLocalExtern)

756 else

757 IDNS &= ~Decl::IDNS_LocalExtern;

758 }

759

760private:

761 void diagnoseAccess() {

763 getSema().getLangOpts().AccessControl)

765 }

766

767 void diagnoseAmbiguous() {

770 }

771

774 Ambiguity = AK;

775 }

776

777 void addDeclsFromBasePaths(const CXXBasePaths &P);

778 void configure();

779

780 bool checkDebugAssumptions() const;

781

782 bool checkUnresolved() const {

784 if (isa((*I)->getUnderlyingDecl()))

785 return true;

786 return false;

787 }

788

789 static void deletePaths(CXXBasePaths *);

790

791

793

794

796 UnresolvedSet<8> Decls;

797 CXXBasePaths *Paths = nullptr;

798 CXXRecordDecl *NamingClass = nullptr;

799 QualType BaseObjectType;

800

801

802 Sema *SemaPtr;

803 DeclarationNameInfo NameInfo;

804 SourceRange NameContextRange;

806 unsigned IDNS = 0;

807

808 bool Redecl;

809 bool ExternalRedecl;

810

811

812

813 bool HideTags = true;

814

815 bool DiagnoseAccess = false;

816 bool DiagnoseAmbiguous = false;

817

818

819 bool AllowHidden = false;

820

821

822

823

824 bool Shadowed = false;

825

826

827 bool TemplateNameLookup = false;

828};

829

830

831

832

833

834

835

837public:

838

840

841

842

843

845

846

847

848

849

850

851

852

853

854

855

856

857

859 bool InBaseClass) = 0;

860

861

862

863

864

866};

867

868

870private:

871

872 llvm::MapVector<NamedDecl*, NamedDecl*> Decls;

873

874 struct select_second {

875 NamedDecl *operator()(std::pair<NamedDecl*, NamedDecl*> P) const {

876 return P.second;

877 }

878 };

879

880public:

881

883

884

886 Decls.erase(cast(D->getCanonicalDecl()));

887 }

888

890 llvm::mapped_iterator<decltype(Decls)::iterator, select_second>;

891

894};

895

896}

897

898#endif

enum clang::sema::@1727::IndirectLocalPathEntry::EntryKind Kind

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

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

Defines the clang::LangOptions interface.

llvm::MachO::Record Record

RedeclarationKind

Specifies whether (or how) name lookup is being performed for a redeclaration (vs.

@ NotForRedeclaration

The lookup is a reference to this name that is not for the purpose of redeclaring the name.

@ ForExternalRedeclaration

The lookup results will be used for redeclaration of a name with external linkage; non-visible lookup...

Defines the clang::SourceLocation class and associated facilities.

Defines various enumerations that describe declaration and type specifiers.

C Language Family Type Representation.

A class for storing results from argument-dependent lookup.

void insert(NamedDecl *D)

Adds a new ADL candidate to this map.

void erase(NamedDecl *D)

Removes any data associated with a given decl.

llvm::mapped_iterator< decltype(Decls)::iterator, select_second > iterator

BasePaths - Represents the set of paths from a derived class to one of its (direct or indirect) bases...

Represents a C++ struct/union/class.

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

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

@ IDNS_LocalExtern

This declaration is a function-local extern declaration of a variable or function.

The name of a declaration.

A class for iterating through a result set and possibly filtering out results.

void replace(NamedDecl *D)

Replaces the current entry with the given one, preserving the access bits.

void restart()

Restart the iteration.

Filter & operator=(const Filter &)=delete

Filter & operator=(Filter &&)=delete

void erase()

Erase the last element returned from this iterator.

void replace(NamedDecl *D, AccessSpecifier AS)

Replaces the current entry with the given one.

Filter(const Filter &)=delete

Represents the results of name lookup.

void setLookupNameInfo(const DeclarationNameInfo &NameInfo)

Sets the name info to look up.

void resolveKindAfterFilter()

Re-resolves the result kind of the lookup after a set of removals has been performed.

void addAllDecls(const LookupResult &Other)

Add all the declarations from another set of lookup results.

RedeclarationKind redeclarationKind() const

@ FoundOverloaded

Name lookup found a set of overloaded functions that met the criteria.

@ FoundUnresolvedValue

Name lookup found an unresolvable value declaration and cannot yet complete.

@ Ambiguous

Name lookup results in an ambiguity; use getAmbiguityKind to figure out what kind of ambiguity we hav...

@ NotFound

No entity found met the criteria.

@ NotFoundInCurrentInstantiation

No entity found met the criteria within the current instantiation,, but there were dependent base cla...

@ Found

Name lookup found a single declaration that met the criteria.

bool wasNotFoundInCurrentInstantiation() const

Determine whether no result was found because we could not search into dependent base classes of the ...

void setShadowed()

Note that we found and ignored a declaration while performing lookup.

static bool isAvailableForLookup(Sema &SemaRef, NamedDecl *ND)

Determine whether this lookup is permitted to see the declaration.

bool isSuppressingAccessDiagnostics() const

Determines whether this lookup is suppressing access control diagnostics.

LLVM_ATTRIBUTE_REINITIALIZES void clear()

Clears out any current state.

LookupResult(TemporaryToken _, const LookupResult &Other)

Creates a temporary lookup result, initializing its core data using the information from another resu...

SourceRange getContextRange() const

Gets the source range of the context of this name; for C++ qualified lookups, this is the source rang...

void setTemplateNameLookup(bool TemplateName)

Sets whether this is a template-name lookup.

void setFindLocalExtern(bool FindLocalExtern)

bool isUnresolvableResult() const

void setBaseObjectType(QualType T)

Sets the base object type for this lookup.

void setAllowHidden(bool AH)

Specify whether hidden declarations are visible, e.g., for recovery reasons.

DeclClass * getAsSingle() const

void addDecl(NamedDecl *D, AccessSpecifier AS)

Add a declaration to these results with the given access.

void setContextRange(SourceRange SR)

Sets a 'context' source range.

static bool isAcceptable(Sema &SemaRef, NamedDecl *D, Sema::AcceptableKind Kind)

void setAmbiguousQualifiedTagHiding()

Make these results show that the name was found in different contexts and a tag decl was hidden by an...

bool isForExternalRedeclaration() const

True if this lookup is just looking for an existing declaration to link against a declaration with ex...

void addDecl(NamedDecl *D)

Add a declaration to these results with its natural access.

bool isTemplateNameLookup() const

void setAmbiguousBaseSubobjects(CXXBasePaths &P)

Make these results show that the name was found in distinct base classes of the same type.

bool isSingleTagDecl() const

Asks if the result is a single tag decl.

void setLookupName(DeclarationName Name)

Sets the name to look up.

bool empty() const

Return true if no decls were found.

void resolveKind()

Resolves the result kind of the lookup, possibly hiding decls.

void setRedeclarationKind(RedeclarationKind RK)

Change this lookup's redeclaration kind.

AmbiguityKind getAmbiguityKind() const

bool isOverloadedResult() const

Determines if the results are overloaded.

SourceLocation getNameLoc() const

Gets the location of the identifier.

void setAmbiguousBaseSubobjectTypes(CXXBasePaths &P)

Make these results show that the name was found in base classes of different types.

CXXBasePaths * getBasePaths() const

Return the base paths structure that's associated with these results, or null if none is.

Filter makeFilter()

Create a filter for this result set.

NamedDecl * getFoundDecl() const

Fetch the unique decl found by this lookup.

void setHideTags(bool Hide)

Sets whether tag declarations should be hidden by non-tag declarations during resolution.

LookupResult & operator=(LookupResult &&Other)

NamedDecl * getAcceptableDecl(NamedDecl *D) const

Retrieve the accepted (re)declaration of the given declaration, if there is one.

bool isSingleResult() const

Determines if this names a single result which is not an unresolved value using decl.

unsigned getIdentifierNamespace() const

Returns the identifier namespace mask for this lookup.

CXXRecordDecl * getNamingClass() const

Returns the 'naming class' for this lookup, i.e.

Sema::LookupNameKind getLookupKind() const

Gets the kind of lookup to perform.

Sema & getSema() const

Get the Sema object that this lookup result is searching with.

QualType getBaseObjectType() const

Returns the base object type associated with this lookup; important for [class.protected].

LookupResult(const LookupResult &)=delete

void suppressAccessDiagnostics()

Suppress the diagnostics that would normally fire because of this lookup due to access control violat...

LookupResult(Sema &SemaRef, DeclarationName Name, SourceLocation NameLoc, Sema::LookupNameKind LookupKind, RedeclarationKind Redecl=RedeclarationKind::NotForRedeclaration)

LookupResult & operator=(const LookupResult &)=delete

const UnresolvedSetImpl & asUnresolvedSet() const

UnresolvedSetImpl::iterator iterator

void clear(Sema::LookupNameKind Kind)

Clears out any current state and re-initializes for a different kind of lookup.

LookupResult(LookupResult &&Other)

bool isClassLookup() const

Returns whether these results arose from performing a lookup into a class.

bool isSuppressingAmbiguousDiagnostics() const

Determines whether this lookup is suppressing ambiguous lookup diagnostics.

void setNamingClass(CXXRecordDecl *Record)

Sets the 'naming class' for this lookup.

LookupResult(Sema &SemaRef, const DeclarationNameInfo &NameInfo, Sema::LookupNameKind LookupKind, RedeclarationKind Redecl=RedeclarationKind::NotForRedeclaration)

NamedDecl * getRepresentativeDecl() const

Fetches a representative decl. Useful for lazy diagnostics.

LookupResultKind getResultKind() const

void print(raw_ostream &)

static bool isReachable(Sema &SemaRef, NamedDecl *D)

TemporaryToken

A little identifier for flagging temporary lookup results.

void suppressDiagnostics()

Suppress the diagnostics that would normally fire because of this lookup.

bool isForRedeclaration() const

True if this lookup is just looking for an existing declaration.

DeclarationName getLookupName() const

Gets the name to look up.

bool isHiddenDeclarationVisible(NamedDecl *ND) const

Determine whether this lookup is permitted to see hidden declarations, such as those in modules that ...

@ AmbiguousTagHiding

Name lookup results in an ambiguity because an entity with a tag name was hidden by an entity with an...

@ AmbiguousBaseSubobjectTypes

Name lookup results in an ambiguity because multiple entities that meet the lookup criteria were foun...

@ AmbiguousReferenceToPlaceholderVariable

Name lookup results in an ambiguity because multiple placeholder variables were found in the same sco...

@ AmbiguousReference

Name lookup results in an ambiguity because multiple definitions of entity that meet the lookup crite...

@ AmbiguousBaseSubobjects

Name lookup results in an ambiguity because multiple nonstatic entities that meet the lookup criteria...

void setNotFoundInCurrentInstantiation()

Note that while no result was found in the current instantiation, there were dependent base classes t...

static bool isVisible(Sema &SemaRef, NamedDecl *D)

Determine whether the given declaration is visible to the program.

const DeclarationNameInfo & getLookupNameInfo() const

Gets the name info to look up.

bool isShadowed() const

Determine whether the lookup result was shadowed by some other declaration that lookup ignored.

This represents a decl that may have a name.

bool isExternallyDeclarable() const

Determine whether this declaration can be redeclared in a different translation unit.

A (possibly-)qualified type.

Sema - This implements semantic analysis and AST building for C.

LookupNameKind

Describes the kind of name lookup to perform.

void CheckLookupAccess(const LookupResult &R)

Checks access to all the declarations in the given result set.

void DiagnoseAmbiguousLookup(LookupResult &Result)

Produce a diagnostic describing the ambiguity that resulted from name lookup.

Encodes a location in the source.

A trivial tuple used to represent a source range.

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

A set of unresolved declarations.

UnresolvedSetIterator iterator

void append(iterator I, iterator E)

void addDecl(NamedDecl *D)

The iterator over UnresolvedSets.

Consumes visible declarations found when searching for all visible names within a given scope or cont...

virtual bool includeHiddenDecls() const

Determine whether hidden declarations (from unimported modules) should be given to this consumer.

virtual void EnteredContext(DeclContext *Ctx)

Callback to inform the client that Sema entered into a new context to find a visible declaration.

virtual void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, DeclContext *Ctx, bool InBaseClass)=0

Invoked each time Sema::LookupVisibleDecls() finds a declaration visible from the current scope or co...

virtual ~VisibleDeclConsumer()

Destroys the visible declaration consumer.

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

const FunctionProtoType * T

@ Other

Other implicit parameter.

AccessSpecifier

A C++ access specifier (public, private, protected), plus the special value "none" which means differ...

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

SourceLocation getLoc() const

getLoc - Returns the main location of the declaration name.

DeclarationName getName() const

getName - Returns the embedded declaration name.

void setName(DeclarationName N)

setName - Sets the embedded declaration name.