clang  9.0.0svn
NestedNameSpecifier.cpp
Go to the documentation of this file.
1 //===- NestedNameSpecifier.cpp - C++ nested name specifiers ---------------===//
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 defines the NestedNameSpecifier class, which represents
11 // a C++ nested-name-specifier.
12 //
13 //===----------------------------------------------------------------------===//
14 
16 #include "clang/AST/ASTContext.h"
17 #include "clang/AST/Decl.h"
18 #include "clang/AST/DeclCXX.h"
19 #include "clang/AST/DeclTemplate.h"
21 #include "clang/AST/TemplateName.h"
22 #include "clang/AST/Type.h"
23 #include "clang/AST/TypeLoc.h"
24 #include "clang/Basic/LLVM.h"
27 #include "llvm/ADT/FoldingSet.h"
28 #include "llvm/ADT/SmallVector.h"
29 #include "llvm/Support/Casting.h"
30 #include "llvm/Support/Compiler.h"
31 #include "llvm/Support/ErrorHandling.h"
32 #include "llvm/Support/raw_ostream.h"
33 #include <algorithm>
34 #include <cassert>
35 #include <cstdlib>
36 #include <cstring>
37 
38 using namespace clang;
39 
41 NestedNameSpecifier::FindOrInsert(const ASTContext &Context,
42  const NestedNameSpecifier &Mockup) {
43  llvm::FoldingSetNodeID ID;
44  Mockup.Profile(ID);
45 
46  void *InsertPos = nullptr;
48  = Context.NestedNameSpecifiers.FindNodeOrInsertPos(ID, InsertPos);
49  if (!NNS) {
50  NNS =
51  new (Context, alignof(NestedNameSpecifier)) NestedNameSpecifier(Mockup);
52  Context.NestedNameSpecifiers.InsertNode(NNS, InsertPos);
53  }
54 
55  return NNS;
56 }
57 
60  NestedNameSpecifier *Prefix, IdentifierInfo *II) {
61  assert(II && "Identifier cannot be NULL");
62  assert((!Prefix || Prefix->isDependent()) && "Prefix must be dependent");
63 
64  NestedNameSpecifier Mockup;
65  Mockup.Prefix.setPointer(Prefix);
66  Mockup.Prefix.setInt(StoredIdentifier);
67  Mockup.Specifier = II;
68  return FindOrInsert(Context, Mockup);
69 }
70 
73  NestedNameSpecifier *Prefix,
74  const NamespaceDecl *NS) {
75  assert(NS && "Namespace cannot be NULL");
76  assert((!Prefix ||
77  (Prefix->getAsType() == nullptr &&
78  Prefix->getAsIdentifier() == nullptr)) &&
79  "Broken nested name specifier");
80  NestedNameSpecifier Mockup;
81  Mockup.Prefix.setPointer(Prefix);
82  Mockup.Prefix.setInt(StoredDecl);
83  Mockup.Specifier = const_cast<NamespaceDecl *>(NS);
84  return FindOrInsert(Context, Mockup);
85 }
86 
89  NestedNameSpecifier *Prefix,
90  NamespaceAliasDecl *Alias) {
91  assert(Alias && "Namespace alias cannot be NULL");
92  assert((!Prefix ||
93  (Prefix->getAsType() == nullptr &&
94  Prefix->getAsIdentifier() == nullptr)) &&
95  "Broken nested name specifier");
96  NestedNameSpecifier Mockup;
97  Mockup.Prefix.setPointer(Prefix);
98  Mockup.Prefix.setInt(StoredDecl);
99  Mockup.Specifier = Alias;
100  return FindOrInsert(Context, Mockup);
101 }
102 
105  NestedNameSpecifier *Prefix,
106  bool Template, const Type *T) {
107  assert(T && "Type cannot be NULL");
108  NestedNameSpecifier Mockup;
109  Mockup.Prefix.setPointer(Prefix);
110  Mockup.Prefix.setInt(Template? StoredTypeSpecWithTemplate : StoredTypeSpec);
111  Mockup.Specifier = const_cast<Type*>(T);
112  return FindOrInsert(Context, Mockup);
113 }
114 
117  assert(II && "Identifier cannot be NULL");
118  NestedNameSpecifier Mockup;
119  Mockup.Prefix.setPointer(nullptr);
120  Mockup.Prefix.setInt(StoredIdentifier);
121  Mockup.Specifier = II;
122  return FindOrInsert(Context, Mockup);
123 }
124 
127  if (!Context.GlobalNestedNameSpecifier)
128  Context.GlobalNestedNameSpecifier =
129  new (Context, alignof(NestedNameSpecifier)) NestedNameSpecifier();
130  return Context.GlobalNestedNameSpecifier;
131 }
132 
135  CXXRecordDecl *RD) {
136  NestedNameSpecifier Mockup;
137  Mockup.Prefix.setPointer(nullptr);
138  Mockup.Prefix.setInt(StoredDecl);
139  Mockup.Specifier = RD;
140  return FindOrInsert(Context, Mockup);
141 }
142 
144  if (!Specifier)
145  return Global;
146 
147  switch (Prefix.getInt()) {
148  case StoredIdentifier:
149  return Identifier;
150 
151  case StoredDecl: {
152  NamedDecl *ND = static_cast<NamedDecl *>(Specifier);
153  if (isa<CXXRecordDecl>(ND))
154  return Super;
155  return isa<NamespaceDecl>(ND) ? Namespace : NamespaceAlias;
156  }
157 
158  case StoredTypeSpec:
159  return TypeSpec;
160 
161  case StoredTypeSpecWithTemplate:
162  return TypeSpecWithTemplate;
163  }
164 
165  llvm_unreachable("Invalid NNS Kind!");
166 }
167 
168 /// Retrieve the namespace stored in this nested name specifier.
170  if (Prefix.getInt() == StoredDecl)
171  return dyn_cast<NamespaceDecl>(static_cast<NamedDecl *>(Specifier));
172 
173  return nullptr;
174 }
175 
176 /// Retrieve the namespace alias stored in this nested name specifier.
178  if (Prefix.getInt() == StoredDecl)
179  return dyn_cast<NamespaceAliasDecl>(static_cast<NamedDecl *>(Specifier));
180 
181  return nullptr;
182 }
183 
184 /// Retrieve the record declaration stored in this nested name specifier.
186  switch (Prefix.getInt()) {
187  case StoredIdentifier:
188  return nullptr;
189 
190  case StoredDecl:
191  return dyn_cast<CXXRecordDecl>(static_cast<NamedDecl *>(Specifier));
192 
193  case StoredTypeSpec:
194  case StoredTypeSpecWithTemplate:
195  return getAsType()->getAsCXXRecordDecl();
196  }
197 
198  llvm_unreachable("Invalid NNS Kind!");
199 }
200 
201 /// Whether this nested name specifier refers to a dependent
202 /// type or not.
204  switch (getKind()) {
205  case Identifier:
206  // Identifier specifiers always represent dependent types
207  return true;
208 
209  case Namespace:
210  case NamespaceAlias:
211  case Global:
212  return false;
213 
214  case Super: {
215  CXXRecordDecl *RD = static_cast<CXXRecordDecl *>(Specifier);
216  for (const auto &Base : RD->bases())
217  if (Base.getType()->isDependentType())
218  return true;
219 
220  return false;
221  }
222 
223  case TypeSpec:
225  return getAsType()->isDependentType();
226  }
227 
228  llvm_unreachable("Invalid NNS Kind!");
229 }
230 
231 /// Whether this nested name specifier refers to a dependent
232 /// type or not.
234  switch (getKind()) {
235  case Identifier:
236  // Identifier specifiers always represent dependent types
237  return true;
238 
239  case Namespace:
240  case NamespaceAlias:
241  case Global:
242  case Super:
243  return false;
244 
245  case TypeSpec:
248  }
249 
250  llvm_unreachable("Invalid NNS Kind!");
251 }
252 
254  switch (getKind()) {
255  case Identifier:
257 
258  case Namespace:
259  case NamespaceAlias:
260  case Global:
261  case Super:
262  return false;
263 
264  case TypeSpec:
267  }
268 
269  llvm_unreachable("Invalid NNS Kind!");
270 }
271 
272 /// Print this nested name specifier to the given output
273 /// stream.
274 void NestedNameSpecifier::print(raw_ostream &OS, const PrintingPolicy &Policy,
275  bool ResolveTemplateArguments) const {
276  if (getPrefix())
277  getPrefix()->print(OS, Policy);
278 
279  switch (getKind()) {
280  case Identifier:
281  OS << getAsIdentifier()->getName();
282  break;
283 
284  case Namespace:
285  if (getAsNamespace()->isAnonymousNamespace())
286  return;
287 
288  OS << getAsNamespace()->getName();
289  break;
290 
291  case NamespaceAlias:
292  OS << getAsNamespaceAlias()->getName();
293  break;
294 
295  case Global:
296  break;
297 
298  case Super:
299  OS << "__super";
300  break;
301 
303  OS << "template ";
304  // Fall through to print the type.
305  LLVM_FALLTHROUGH;
306 
307  case TypeSpec: {
308  const auto *Record =
309  dyn_cast_or_null<ClassTemplateSpecializationDecl>(getAsRecordDecl());
310  if (ResolveTemplateArguments && Record) {
311  // Print the type trait with resolved template parameters.
312  Record->printName(OS);
313  printTemplateArgumentList(OS, Record->getTemplateArgs().asArray(),
314  Policy);
315  break;
316  }
317  const Type *T = getAsType();
318 
319  PrintingPolicy InnerPolicy(Policy);
320  InnerPolicy.SuppressScope = true;
321 
322  // Nested-name-specifiers are intended to contain minimally-qualified
323  // types. An actual ElaboratedType will not occur, since we'll store
324  // just the type that is referred to in the nested-name-specifier (e.g.,
325  // a TypedefType, TagType, etc.). However, when we are dealing with
326  // dependent template-id types (e.g., Outer<T>::template Inner<U>),
327  // the type requires its own nested-name-specifier for uniqueness, so we
328  // suppress that nested-name-specifier during printing.
329  assert(!isa<ElaboratedType>(T) &&
330  "Elaborated type in nested-name-specifier");
331  if (const TemplateSpecializationType *SpecType
332  = dyn_cast<TemplateSpecializationType>(T)) {
333  // Print the template name without its corresponding
334  // nested-name-specifier.
335  SpecType->getTemplateName().print(OS, InnerPolicy, true);
336 
337  // Print the template argument list.
338  printTemplateArgumentList(OS, SpecType->template_arguments(),
339  InnerPolicy);
340  } else {
341  // Print the type normally
342  QualType(T, 0).print(OS, InnerPolicy);
343  }
344  break;
345  }
346  }
347 
348  OS << "::";
349 }
350 
351 LLVM_DUMP_METHOD void NestedNameSpecifier::dump(const LangOptions &LO) const {
352  dump(llvm::errs(), LO);
353 }
354 
355 LLVM_DUMP_METHOD void NestedNameSpecifier::dump() const { dump(llvm::errs()); }
356 
357 LLVM_DUMP_METHOD void NestedNameSpecifier::dump(llvm::raw_ostream &OS) const {
358  LangOptions LO;
359  dump(OS, LO);
360 }
361 
362 LLVM_DUMP_METHOD void NestedNameSpecifier::dump(llvm::raw_ostream &OS,
363  const LangOptions &LO) const {
364  print(OS, PrintingPolicy(LO));
365 }
366 
367 unsigned
368 NestedNameSpecifierLoc::getLocalDataLength(NestedNameSpecifier *Qualifier) {
369  assert(Qualifier && "Expected a non-NULL qualifier");
370 
371  // Location of the trailing '::'.
372  unsigned Length = sizeof(unsigned);
373 
374  switch (Qualifier->getKind()) {
376  // Nothing more to add.
377  break;
378 
383  // The location of the identifier or namespace name.
384  Length += sizeof(unsigned);
385  break;
386 
389  // The "void*" that points at the TypeLoc data.
390  // Note: the 'template' keyword is part of the TypeLoc.
391  Length += sizeof(void *);
392  break;
393  }
394 
395  return Length;
396 }
397 
398 unsigned
400  unsigned Length = 0;
401  for (; Qualifier; Qualifier = Qualifier->getPrefix())
402  Length += getLocalDataLength(Qualifier);
403  return Length;
404 }
405 
406 /// Load a (possibly unaligned) source location from a given address
407 /// and offset.
408 static SourceLocation LoadSourceLocation(void *Data, unsigned Offset) {
409  unsigned Raw;
410  memcpy(&Raw, static_cast<char *>(Data) + Offset, sizeof(unsigned));
412 }
413 
414 /// Load a (possibly unaligned) pointer from a given address and
415 /// offset.
416 static void *LoadPointer(void *Data, unsigned Offset) {
417  void *Result;
418  memcpy(&Result, static_cast<char *>(Data) + Offset, sizeof(void*));
419  return Result;
420 }
421 
423  if (!Qualifier)
424  return SourceRange();
425 
427  while (NestedNameSpecifierLoc Prefix = First.getPrefix())
428  First = Prefix;
429 
430  return SourceRange(First.getLocalSourceRange().getBegin(),
431  getLocalSourceRange().getEnd());
432 }
433 
435  if (!Qualifier)
436  return SourceRange();
437 
438  unsigned Offset = getDataLength(Qualifier->getPrefix());
439  switch (Qualifier->getKind()) {
441  return LoadSourceLocation(Data, Offset);
442 
447  return SourceRange(LoadSourceLocation(Data, Offset),
448  LoadSourceLocation(Data, Offset + sizeof(unsigned)));
449 
452  // The "void*" that points at the TypeLoc data.
453  // Note: the 'template' keyword is part of the TypeLoc.
454  void *TypeData = LoadPointer(Data, Offset);
455  TypeLoc TL(Qualifier->getAsType(), TypeData);
456  return SourceRange(TL.getBeginLoc(),
457  LoadSourceLocation(Data, Offset + sizeof(void*)));
458  }
459  }
460 
461  llvm_unreachable("Invalid NNS Kind!");
462 }
463 
465  if (Qualifier->getKind() != NestedNameSpecifier::TypeSpec &&
467  return TypeLoc();
468 
469  // The "void*" that points at the TypeLoc data.
470  unsigned Offset = getDataLength(Qualifier->getPrefix());
471  void *TypeData = LoadPointer(Data, Offset);
472  return TypeLoc(Qualifier->getAsType(), TypeData);
473 }
474 
475 static void Append(char *Start, char *End, char *&Buffer, unsigned &BufferSize,
476  unsigned &BufferCapacity) {
477  if (Start == End)
478  return;
479 
480  if (BufferSize + (End - Start) > BufferCapacity) {
481  // Reallocate the buffer.
482  unsigned NewCapacity = std::max(
483  (unsigned)(BufferCapacity ? BufferCapacity * 2 : sizeof(void *) * 2),
484  (unsigned)(BufferSize + (End - Start)));
485  char *NewBuffer = static_cast<char *>(llvm::safe_malloc(NewCapacity));
486  if (BufferCapacity) {
487  memcpy(NewBuffer, Buffer, BufferSize);
488  free(Buffer);
489  }
490  Buffer = NewBuffer;
491  BufferCapacity = NewCapacity;
492  }
493 
494  memcpy(Buffer + BufferSize, Start, End - Start);
495  BufferSize += End-Start;
496 }
497 
498 /// Save a source location to the given buffer.
499 static void SaveSourceLocation(SourceLocation Loc, char *&Buffer,
500  unsigned &BufferSize, unsigned &BufferCapacity) {
501  unsigned Raw = Loc.getRawEncoding();
502  Append(reinterpret_cast<char *>(&Raw),
503  reinterpret_cast<char *>(&Raw) + sizeof(unsigned),
504  Buffer, BufferSize, BufferCapacity);
505 }
506 
507 /// Save a pointer to the given buffer.
508 static void SavePointer(void *Ptr, char *&Buffer, unsigned &BufferSize,
509  unsigned &BufferCapacity) {
510  Append(reinterpret_cast<char *>(&Ptr),
511  reinterpret_cast<char *>(&Ptr) + sizeof(void *),
512  Buffer, BufferSize, BufferCapacity);
513 }
514 
517  : Representation(Other.Representation) {
518  if (!Other.Buffer)
519  return;
520 
521  if (Other.BufferCapacity == 0) {
522  // Shallow copy is okay.
523  Buffer = Other.Buffer;
524  BufferSize = Other.BufferSize;
525  return;
526  }
527 
528  // Deep copy
529  Append(Other.Buffer, Other.Buffer + Other.BufferSize, Buffer, BufferSize,
530  BufferCapacity);
531 }
532 
536  Representation = Other.Representation;
537 
538  if (Buffer && Other.Buffer && BufferCapacity >= Other.BufferSize) {
539  // Re-use our storage.
540  BufferSize = Other.BufferSize;
541  memcpy(Buffer, Other.Buffer, BufferSize);
542  return *this;
543  }
544 
545  // Free our storage, if we have any.
546  if (BufferCapacity) {
547  free(Buffer);
548  BufferCapacity = 0;
549  }
550 
551  if (!Other.Buffer) {
552  // Empty.
553  Buffer = nullptr;
554  BufferSize = 0;
555  return *this;
556  }
557 
558  if (Other.BufferCapacity == 0) {
559  // Shallow copy is okay.
560  Buffer = Other.Buffer;
561  BufferSize = Other.BufferSize;
562  return *this;
563  }
564 
565  // Deep copy.
566  BufferSize = 0;
567  Append(Other.Buffer, Other.Buffer + Other.BufferSize, Buffer, BufferSize,
568  BufferCapacity);
569  return *this;
570 }
571 
573  SourceLocation TemplateKWLoc,
574  TypeLoc TL,
575  SourceLocation ColonColonLoc) {
576  Representation = NestedNameSpecifier::Create(Context, Representation,
577  TemplateKWLoc.isValid(),
578  TL.getTypePtr());
579 
580  // Push source-location info into the buffer.
581  SavePointer(TL.getOpaqueData(), Buffer, BufferSize, BufferCapacity);
582  SaveSourceLocation(ColonColonLoc, Buffer, BufferSize, BufferCapacity);
583 }
584 
588  SourceLocation ColonColonLoc) {
589  Representation = NestedNameSpecifier::Create(Context, Representation,
590  Identifier);
591 
592  // Push source-location info into the buffer.
593  SaveSourceLocation(IdentifierLoc, Buffer, BufferSize, BufferCapacity);
594  SaveSourceLocation(ColonColonLoc, Buffer, BufferSize, BufferCapacity);
595 }
596 
598  NamespaceDecl *Namespace,
599  SourceLocation NamespaceLoc,
600  SourceLocation ColonColonLoc) {
601  Representation = NestedNameSpecifier::Create(Context, Representation,
602  Namespace);
603 
604  // Push source-location info into the buffer.
605  SaveSourceLocation(NamespaceLoc, Buffer, BufferSize, BufferCapacity);
606  SaveSourceLocation(ColonColonLoc, Buffer, BufferSize, BufferCapacity);
607 }
608 
610  NamespaceAliasDecl *Alias,
611  SourceLocation AliasLoc,
612  SourceLocation ColonColonLoc) {
613  Representation = NestedNameSpecifier::Create(Context, Representation, Alias);
614 
615  // Push source-location info into the buffer.
616  SaveSourceLocation(AliasLoc, Buffer, BufferSize, BufferCapacity);
617  SaveSourceLocation(ColonColonLoc, Buffer, BufferSize, BufferCapacity);
618 }
619 
621  SourceLocation ColonColonLoc) {
622  assert(!Representation && "Already have a nested-name-specifier!?");
623  Representation = NestedNameSpecifier::GlobalSpecifier(Context);
624 
625  // Push source-location info into the buffer.
626  SaveSourceLocation(ColonColonLoc, Buffer, BufferSize, BufferCapacity);
627 }
628 
630  CXXRecordDecl *RD,
631  SourceLocation SuperLoc,
632  SourceLocation ColonColonLoc) {
633  Representation = NestedNameSpecifier::SuperSpecifier(Context, RD);
634 
635  // Push source-location info into the buffer.
636  SaveSourceLocation(SuperLoc, Buffer, BufferSize, BufferCapacity);
637  SaveSourceLocation(ColonColonLoc, Buffer, BufferSize, BufferCapacity);
638 }
639 
641  NestedNameSpecifier *Qualifier,
642  SourceRange R) {
643  Representation = Qualifier;
644 
645  // Construct bogus (but well-formed) source information for the
646  // nested-name-specifier.
647  BufferSize = 0;
649  for (NestedNameSpecifier *NNS = Qualifier; NNS; NNS = NNS->getPrefix())
650  Stack.push_back(NNS);
651  while (!Stack.empty()) {
652  NestedNameSpecifier *NNS = Stack.pop_back_val();
653  switch (NNS->getKind()) {
657  SaveSourceLocation(R.getBegin(), Buffer, BufferSize, BufferCapacity);
658  break;
659 
662  TypeSourceInfo *TSInfo
663  = Context.getTrivialTypeSourceInfo(QualType(NNS->getAsType(), 0),
664  R.getBegin());
665  SavePointer(TSInfo->getTypeLoc().getOpaqueData(), Buffer, BufferSize,
666  BufferCapacity);
667  break;
668  }
669 
672  break;
673  }
674 
675  // Save the location of the '::'.
676  SaveSourceLocation(Stack.empty()? R.getEnd() : R.getBegin(),
677  Buffer, BufferSize, BufferCapacity);
678  }
679 }
680 
682  if (BufferCapacity)
683  free(Buffer);
684 
685  if (!Other) {
686  Representation = nullptr;
687  BufferSize = 0;
688  return;
689  }
690 
691  // Rather than copying the data (which is wasteful), "adopt" the
692  // pointer (which points into the ASTContext) but set the capacity to zero to
693  // indicate that we don't own it.
694  Representation = Other.getNestedNameSpecifier();
695  Buffer = static_cast<char *>(Other.getOpaqueData());
696  BufferSize = Other.getDataLength();
697  BufferCapacity = 0;
698 }
699 
702  if (!Representation)
703  return NestedNameSpecifierLoc();
704 
705  // If we adopted our data pointer from elsewhere in the AST context, there's
706  // no need to copy the memory.
707  if (BufferCapacity == 0)
708  return NestedNameSpecifierLoc(Representation, Buffer);
709 
710  // FIXME: After copying the source-location information, should we free
711  // our (temporary) buffer and adopt the ASTContext-allocated memory?
712  // Doing so would optimize repeated calls to getWithLocInContext().
713  void *Mem = Context.Allocate(BufferSize, alignof(void *));
714  memcpy(Mem, Buffer, BufferSize);
715  return NestedNameSpecifierLoc(Representation, Mem);
716 }
Defines the clang::ASTContext interface.
StringRef Identifier
Definition: Format.cpp:1636
unsigned getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it...
A (possibly-)qualified type.
Definition: Type.h:638
base_class_range bases()
Definition: DeclCXX.h:823
void MakeTrivial(ASTContext &Context, NestedNameSpecifier *Qualifier, SourceRange R)
Make a new nested-name-specifier from incomplete source-location information.
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range covering the entirety of this nested-name-specifier.
C Language Family Type Representation.
Microsoft&#39;s &#39;__super&#39; specifier, stored as a CXXRecordDecl* of the class it appeared in...
NestedNameSpecifier * getPrefix() const
Return the prefix of this nested name specifier.
Defines the C++ template declaration subclasses.
The base class of the type hierarchy.
Definition: Type.h:1407
Represent a C++ namespace.
Definition: Decl.h:515
A container of type source information.
Definition: Decl.h:87
void Profile(llvm::FoldingSetNodeID &ID) const
An identifier, stored as an IdentifierInfo*.
static NestedNameSpecifier * Create(const ASTContext &Context, NestedNameSpecifier *Prefix, IdentifierInfo *II)
Builds a specifier combining a prefix and an identifier.
NestedNameSpecifierLocBuilder & operator=(const NestedNameSpecifierLocBuilder &Other)
A namespace, stored as a NamespaceDecl*.
Describes how types, statements, expressions, and declarations should be printed. ...
Definition: PrettyPrinter.h:38
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
void Adopt(NestedNameSpecifierLoc Other)
Adopt an existing nested-name-specifier (with source-range information).
const Type * getTypePtr() const
Definition: TypeLoc.h:135
static void Append(char *Start, char *End, char *&Buffer, unsigned &BufferSize, unsigned &BufferCapacity)
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:57
One of these records is kept for each identifier that is lexed.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:155
A C++ nested-name-specifier augmented with source location information.
static SourceLocation getFromRawEncoding(unsigned Encoding)
Turn a raw encoding of a SourceLocation object into a real SourceLocation.
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:50
CXXRecordDecl * getAsRecordDecl() const
Retrieve the record declaration stored in this nested name specifier.
IdentifierInfo * getAsIdentifier() const
Retrieve the identifier stored in this nested name specifier.
static void SaveSourceLocation(SourceLocation Loc, char *&Buffer, unsigned &BufferSize, unsigned &BufferCapacity)
Save a source location to the given buffer.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
SourceRange getLocalSourceRange() const
Retrieve the source range covering just the last part of this nested-name-specifier, not including the prefix.
NamespaceAliasDecl * getAsNamespaceAlias() const
Retrieve the namespace alias stored in this nested name specifier.
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
Definition: Type.h:1831
static SourceLocation LoadSourceLocation(void *Data, unsigned Offset)
Load a (possibly unaligned) source location from a given address and offset.
void print(raw_ostream &OS, const PrintingPolicy &Policy, bool ResolveTemplateArguments=false) const
Print this nested name specifier to the given output stream.
Class that aids in the construction of nested-name-specifiers along with source-location information ...
void * getOpaqueData() const
Get the pointer where source information is stored.
Definition: TypeLoc.h:140
bool isInstantiationDependent() const
Whether this nested name specifier involves a template parameter.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1613
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location, which defaults to the empty location.
unsigned Offset
Definition: Format.cpp:1631
static NestedNameSpecifier * SuperSpecifier(const ASTContext &Context, CXXRecordDecl *RD)
Returns the nested name specifier representing the __super scope for the given CXXRecordDecl.
NamespaceDecl * getAsNamespace() const
Retrieve the namespace stored in this nested name specifier.
Defines the clang::LangOptions interface.
SourceLocation End
NestedNameSpecifierLoc getPrefix() const
Return the prefix of this nested-name-specifier.
void printTemplateArgumentList(raw_ostream &OS, ArrayRef< TemplateArgument > Args, const PrintingPolicy &Policy)
Print a template argument list, including the &#39;<&#39; and &#39;>&#39; enclosing the template arguments.
Defines the clang::TypeLoc interface and its subclasses.
A namespace alias, stored as a NamespaceAliasDecl*.
SourceLocation getEnd() const
Wraps an identifier and optional source location for the identifier.
Definition: ParsedAttr.h:95
The result type of a method or function.
SpecifierKind
The kind of specifier that completes this nested name specifier.
bool containsUnexpandedParameterPack() const
Whether this nested-name-specifier contains an unexpanded parameter pack (for C++11 variadic template...
void MakeSuper(ASTContext &Context, CXXRecordDecl *RD, SourceLocation SuperLoc, SourceLocation ColonColonLoc)
Turns this (empty) nested-name-specifier into &#39;__super&#39; nested-name-specifier.
Encodes a location in the source.
unsigned SuppressScope
Suppresses printing of scope specifiers.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
void MakeGlobal(ASTContext &Context, SourceLocation ColonColonLoc)
Turn this (empty) nested-name-specifier into the global nested-name-specifier &#39;::&#39;.
static void SavePointer(void *Ptr, char *&Buffer, unsigned &BufferSize, unsigned &BufferCapacity)
Save a pointer to the given buffer.
static void * LoadPointer(void *Data, unsigned Offset)
Load a (possibly unaligned) pointer from a given address and offset.
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
Definition: Type.h:2085
void * Allocate(size_t Size, unsigned Align=8) const
Definition: ASTContext.h:669
StringRef getName() const
Return the actual identifier string.
Dataflow Directional Tag Classes.
NestedNameSpecifier * getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
bool isValid() const
Return true if this is a valid SourceLocation object.
unsigned getDataLength() const
Determines the data length for the entire nested-name-specifier.
bool isDependent() const
Whether this nested name specifier refers to a dependent type or not.
A type that was preceded by the &#39;template&#39; keyword, stored as a Type*.
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:238
void * getOpaqueData() const
Retrieve the opaque pointer that refers to source-location data.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
Defines the clang::SourceLocation class and associated facilities.
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context...
Represents a C++ struct/union/class.
Definition: DeclCXX.h:300
TypeLoc getTypeLoc() const
For a nested-name-specifier that refers to a type, retrieve the type with source-location information...
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:276
__DEVICE__ int max(int __a, int __b)
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2079
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:4844
void Extend(ASTContext &Context, SourceLocation TemplateKWLoc, TypeLoc TL, SourceLocation ColonColonLoc)
Extend the current nested-name-specifier by another nested-name-specifier component of the form &#39;type...
A trivial tuple used to represent a source range.
This represents a decl that may have a name.
Definition: Decl.h:249
Represents a C++ namespace alias.
Definition: DeclCXX.h:3020
The global specifier &#39;::&#39;. There is no stored value.
SourceLocation getBegin() const
static NestedNameSpecifier * GlobalSpecifier(const ASTContext &Context)
Returns the nested name specifier representing the global scope.