clang: lib/Serialization/ASTCommon.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
19#include "llvm/Support/DJB.h"
20#include "llvm/Support/FileSystem.h"
21#include "llvm/Support/raw_ostream.h"
22
23using namespace clang;
24
25
27
30 unsigned ID = 0;
32 case BuiltinType::Void:
34 break;
35 case BuiltinType::Bool:
37 break;
38 case BuiltinType::Char_U:
40 break;
41 case BuiltinType::UChar:
43 break;
44 case BuiltinType::UShort:
46 break;
47 case BuiltinType::UInt:
49 break;
50 case BuiltinType::ULong:
52 break;
53 case BuiltinType::ULongLong:
55 break;
56 case BuiltinType::UInt128:
58 break;
59 case BuiltinType::Char_S:
61 break;
62 case BuiltinType::SChar:
64 break;
65 case BuiltinType::WChar_S:
66 case BuiltinType::WChar_U:
68 break;
69 case BuiltinType::Short:
71 break;
72 case BuiltinType::Int:
74 break;
75 case BuiltinType::Long:
77 break;
78 case BuiltinType::LongLong:
80 break;
81 case BuiltinType::Int128:
83 break;
84 case BuiltinType::Half:
86 break;
87 case BuiltinType::Float:
89 break;
90 case BuiltinType::Double:
92 break;
93 case BuiltinType::LongDouble:
95 break;
96 case BuiltinType::ShortAccum:
98 break;
99 case BuiltinType::Accum:
101 break;
102 case BuiltinType::LongAccum:
104 break;
105 case BuiltinType::UShortAccum:
107 break;
108 case BuiltinType::UAccum:
110 break;
111 case BuiltinType::ULongAccum:
113 break;
114 case BuiltinType::ShortFract:
116 break;
117 case BuiltinType::Fract:
119 break;
120 case BuiltinType::LongFract:
122 break;
123 case BuiltinType::UShortFract:
125 break;
126 case BuiltinType::UFract:
128 break;
129 case BuiltinType::ULongFract:
131 break;
132 case BuiltinType::SatShortAccum:
134 break;
135 case BuiltinType::SatAccum:
137 break;
138 case BuiltinType::SatLongAccum:
140 break;
141 case BuiltinType::SatUShortAccum:
143 break;
144 case BuiltinType::SatUAccum:
146 break;
147 case BuiltinType::SatULongAccum:
149 break;
150 case BuiltinType::SatShortFract:
152 break;
153 case BuiltinType::SatFract:
155 break;
156 case BuiltinType::SatLongFract:
158 break;
159 case BuiltinType::SatUShortFract:
161 break;
162 case BuiltinType::SatUFract:
164 break;
165 case BuiltinType::SatULongFract:
167 break;
168 case BuiltinType::Float16:
170 break;
171 case BuiltinType::Float128:
173 break;
174 case BuiltinType::Ibm128:
176 break;
177 case BuiltinType::NullPtr:
179 break;
180 case BuiltinType::Char8:
182 break;
183 case BuiltinType::Char16:
185 break;
186 case BuiltinType::Char32:
188 break;
189 case BuiltinType::Overload:
191 break;
192 case BuiltinType::UnresolvedTemplate:
194 break;
195 case BuiltinType::BoundMember:
197 break;
198 case BuiltinType::PseudoObject:
200 break;
201 case BuiltinType::Dependent:
203 break;
204 case BuiltinType::UnknownAny:
206 break;
207 case BuiltinType::ARCUnbridgedCast:
209 break;
210 case BuiltinType::ObjCId:
212 break;
213 case BuiltinType::ObjCClass:
215 break;
216 case BuiltinType::ObjCSel:
218 break;
219#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
220 case BuiltinType::Id: \
221 ID = PREDEF_TYPE_##Id##_ID; \
222 break;
223#include "clang/Basic/OpenCLImageTypes.def"
224#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
225 case BuiltinType::Id: \
226 ID = PREDEF_TYPE_##Id##_ID; \
227 break;
228#include "clang/Basic/OpenCLExtensionTypes.def"
229 case BuiltinType::OCLSampler:
231 break;
232 case BuiltinType::OCLEvent:
234 break;
235 case BuiltinType::OCLClkEvent:
237 break;
238 case BuiltinType::OCLQueue:
240 break;
241 case BuiltinType::OCLReserveID:
243 break;
244#define SVE_TYPE(Name, Id, SingletonId) \
245 case BuiltinType::Id: \
246 ID = PREDEF_TYPE_##Id##_ID; \
247 break;
248#include "clang/Basic/AArch64SVEACLETypes.def"
249#define PPC_VECTOR_TYPE(Name, Id, Size) \
250 case BuiltinType::Id: \
251 ID = PREDEF_TYPE_##Id##_ID; \
252 break;
253#include "clang/Basic/PPCTypes.def"
254#define RVV_TYPE(Name, Id, SingletonId) \
255 case BuiltinType::Id: \
256 ID = PREDEF_TYPE_##Id##_ID; \
257 break;
258#include "clang/Basic/RISCVVTypes.def"
259#define WASM_TYPE(Name, Id, SingletonId) \
260 case BuiltinType::Id: \
261 ID = PREDEF_TYPE_##Id##_ID; \
262 break;
263#include "clang/Basic/WebAssemblyReferenceTypes.def"
264#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
265 case BuiltinType::Id: \
266 ID = PREDEF_TYPE_##Id##_ID; \
267 break;
268#include "clang/Basic/AMDGPUTypes.def"
269#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
270 case BuiltinType::Id: \
271 ID = PREDEF_TYPE_##Id##_ID; \
272 break;
273#include "clang/Basic/HLSLIntangibleTypes.def"
274 case BuiltinType::BuiltinFn:
276 break;
277 case BuiltinType::IncompleteMatrixIdx:
279 break;
280 case BuiltinType::ArraySection:
282 break;
283 case BuiltinType::OMPArrayShaping:
285 break;
286 case BuiltinType::OMPIterator:
288 break;
289 case BuiltinType::BFloat16:
291 break;
292 }
293
295}
296
299 if (N == 0)
300 ++N;
301 unsigned R = 5381;
302 for (unsigned I = 0; I != N; ++I)
304 R = llvm::djbHash(II->getName(), R);
305 return R;
306}
307
311
312 case Decl::TranslationUnit:
313 case Decl::ExternCContext:
314 case Decl::Namespace:
315 case Decl::LinkageSpec:
316 case Decl::Export:
317 return nullptr;
318
319
320 case Decl::Enum:
321 case Decl::Record:
323 return Def;
324 return nullptr;
325
326
327
328 case Decl::CXXRecord:
329 case Decl::ClassTemplateSpecialization:
330 case Decl::ClassTemplatePartialSpecialization:
331 return nullptr;
332
333
334 case Decl::Function:
335 case Decl::CXXMethod:
336 case Decl::CXXConstructor:
337 case Decl::CXXDestructor:
338 case Decl::CXXConversion:
339 case Decl::ObjCMethod:
340 case Decl::Block:
341 case Decl::OutlinedFunction:
342 case Decl::Captured:
343
344
345 case Decl::ObjCCategory:
346 case Decl::ObjCCategoryImpl:
347 case Decl::ObjCImplementation:
348 return DC;
349
350 case Decl::ObjCProtocol:
353 return Def;
354 return nullptr;
355
356
357
358
359 case Decl::ObjCInterface:
360 return nullptr;
361
362 default:
363 llvm_unreachable("Unhandled DeclContext in AST reader");
364 }
365
366 llvm_unreachable("Unhandled decl kind");
367}
368
370 switch (static_cast<Decl::Kind>(Kind)) {
371 case Decl::TranslationUnit:
372 case Decl::ExternCContext:
373
374 return true;
375
376 case Decl::Namespace:
377 case Decl::NamespaceAlias:
378 case Decl::Typedef:
379 case Decl::TypeAlias:
380 case Decl::Enum:
381 case Decl::Record:
382 case Decl::CXXRecord:
383 case Decl::ClassTemplateSpecialization:
384 case Decl::ClassTemplatePartialSpecialization:
385 case Decl::VarTemplateSpecialization:
386 case Decl::VarTemplatePartialSpecialization:
387 case Decl::Function:
388 case Decl::CXXDeductionGuide:
389 case Decl::CXXMethod:
390 case Decl::CXXConstructor:
391 case Decl::CXXDestructor:
392 case Decl::CXXConversion:
393 case Decl::UsingShadow:
394 case Decl::ConstructorUsingShadow:
395 case Decl::Var:
396 case Decl::FunctionTemplate:
397 case Decl::ClassTemplate:
398 case Decl::VarTemplate:
399 case Decl::TypeAliasTemplate:
400 case Decl::ObjCProtocol:
401 case Decl::ObjCInterface:
402 case Decl::Empty:
403 return true;
404
405
406 case Decl::UsingDirective:
407 case Decl::Label:
408 case Decl::UnresolvedUsingTypename:
409 case Decl::TemplateTypeParm:
410 case Decl::EnumConstant:
411 case Decl::UnresolvedUsingValue:
412 case Decl::IndirectField:
413 case Decl::Field:
414 case Decl::MSProperty:
415 case Decl::MSGuid:
416 case Decl::UnnamedGlobalConstant:
417 case Decl::TemplateParamObject:
418 case Decl::ObjCIvar:
419 case Decl::ObjCAtDefsField:
420 case Decl::NonTypeTemplateParm:
421 case Decl::TemplateTemplateParm:
422 case Decl::Using:
423 case Decl::UsingEnum:
424 case Decl::UsingPack:
425 case Decl::ObjCMethod:
426 case Decl::ObjCCategory:
427 case Decl::ObjCCategoryImpl:
428 case Decl::ObjCImplementation:
429 case Decl::ObjCProperty:
430 case Decl::ObjCCompatibleAlias:
431 case Decl::LinkageSpec:
432 case Decl::Export:
433 case Decl::ObjCPropertyImpl:
434 case Decl::PragmaComment:
435 case Decl::PragmaDetectMismatch:
436 case Decl::FileScopeAsm:
437 case Decl::TopLevelStmt:
438 case Decl::AccessSpec:
439 case Decl::Friend:
440 case Decl::FriendTemplate:
441 case Decl::StaticAssert:
442 case Decl::Block:
443 case Decl::OutlinedFunction:
444 case Decl::Captured:
445 case Decl::Import:
446 case Decl::OMPThreadPrivate:
447 case Decl::OMPAllocate:
448 case Decl::OMPRequires:
449 case Decl::OMPCapturedExpr:
450 case Decl::OMPDeclareReduction:
451 case Decl::OMPDeclareMapper:
452 case Decl::BuiltinTemplate:
453 case Decl::Decomposition:
454 case Decl::Binding:
455 case Decl::Concept:
456 case Decl::ImplicitConceptSpecialization:
457 case Decl::LifetimeExtendedTemporary:
458 case Decl::RequiresExprBody:
459 case Decl::UnresolvedUsingIfExists:
460 case Decl::HLSLBuffer:
461 return false;
462
463
464
465 case Decl::ImplicitParam:
466 case Decl::ParmVar:
467 case Decl::ObjCTypeParam:
468 return false;
469 }
470
471 llvm_unreachable("Unhandled declaration kind");
472}
473
475
476
477
478
479
480
483
484
485 if (auto *FD = dyn_cast(D))
486 return !FD->getDescribedFunctionTemplate();
487 if (auto *RD = dyn_cast(D))
488 return !RD->getDescribedClassTemplate();
489 return true;
490 }
491
492
493
494
495
497 if (auto *VD = dyn_cast(D))
498 return VD->isStaticLocal();
499
500 return isa<TagDecl, BlockDecl>(D);
501 }
502
503
504
505 if (D->getDeclName())
506 return false;
508 return false;
509 return isa<TagDecl, FieldDecl>(D);
510}
511
513
514 std::error_code EC;
515 llvm::raw_fd_ostream OS(ModuleFile::getTimestampFilename(ModuleFilename), EC,
516 llvm::sys::fs::OF_TextWithCRLF);
517 if (EC)
518 return;
519 OS << "Timestamp file\n";
520 OS.close();
521 OS.clear_error();
522}
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
static const NamedDecl * getDefinition(const Decl *D)
virtual ~ASTDeserializationListener()
This class is used for builtin types like 'int'.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
bool isFunctionOrMethod() const
Decl::Kind getDeclKind() const
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so,...
Kind
Lists the kind of concrete classes of Decl.
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
One of these records is kept for each identifier that is lexed.
This represents a decl that may have a name.
Represents an Objective-C protocol declaration.
Smart pointer class that efficiently represents Objective-C method names.
const IdentifierInfo * getIdentifierInfoForSlot(unsigned argIndex) const
Retrieve the identifier at a given position in the selector.
unsigned getNumArgs() const
Represents the declaration of a struct/union/class/enum.
A type index; the type ID with the qualifier bits removed.
@ PREDEF_TYPE_LONG_ACCUM_ID
The 'long _Accum' type.
@ PREDEF_TYPE_SAMPLER_ID
OpenCL sampler type.
@ PREDEF_TYPE_INT128_ID
The '__int128_t' type.
@ PREDEF_TYPE_CHAR32_ID
The C++ 'char32_t' type.
@ PREDEF_TYPE_SAT_SHORT_ACCUM_ID
The '_Sat short _Accum' type.
@ PREDEF_TYPE_IBM128_ID
The '__ibm128' type.
@ PREDEF_TYPE_SHORT_FRACT_ID
The 'short _Fract' type.
@ PREDEF_TYPE_BOUND_MEMBER
The placeholder type for bound member functions.
@ PREDEF_TYPE_LONGLONG_ID
The (signed) 'long long' type.
@ PREDEF_TYPE_FRACT_ID
The '_Fract' type.
@ PREDEF_TYPE_ARC_UNBRIDGED_CAST
ARC's unbridged-cast placeholder type.
@ PREDEF_TYPE_USHORT_FRACT_ID
The 'unsigned short _Fract' type.
@ PREDEF_TYPE_SAT_ULONG_FRACT_ID
The '_Sat unsigned long _Fract' type.
@ PREDEF_TYPE_BOOL_ID
The 'bool' or '_Bool' type.
@ PREDEF_TYPE_SAT_LONG_ACCUM_ID
The '_Sat long _Accum' type.
@ PREDEF_TYPE_SAT_LONG_FRACT_ID
The '_Sat long _Fract' type.
@ PREDEF_TYPE_SAT_SHORT_FRACT_ID
The '_Sat short _Fract' type.
@ PREDEF_TYPE_CHAR_U_ID
The 'char' type, when it is unsigned.
@ PREDEF_TYPE_RESERVE_ID_ID
OpenCL reserve_id type.
@ PREDEF_TYPE_SAT_ACCUM_ID
The '_Sat _Accum' type.
@ PREDEF_TYPE_BUILTIN_FN
The placeholder type for builtin functions.
@ PREDEF_TYPE_SHORT_ACCUM_ID
The 'short _Accum' type.
@ PREDEF_TYPE_FLOAT_ID
The 'float' type.
@ PREDEF_TYPE_QUEUE_ID
OpenCL queue type.
@ PREDEF_TYPE_INT_ID
The (signed) 'int' type.
@ PREDEF_TYPE_OBJC_SEL
The ObjC 'SEL' type.
@ PREDEF_TYPE_BFLOAT16_ID
The '__bf16' type.
@ PREDEF_TYPE_WCHAR_ID
The C++ 'wchar_t' type.
@ PREDEF_TYPE_UCHAR_ID
The 'unsigned char' type.
@ PREDEF_TYPE_UACCUM_ID
The 'unsigned _Accum' type.
@ PREDEF_TYPE_SCHAR_ID
The 'signed char' type.
@ PREDEF_TYPE_CHAR_S_ID
The 'char' type, when it is signed.
@ PREDEF_TYPE_NULLPTR_ID
The type of 'nullptr'.
@ PREDEF_TYPE_ULONG_FRACT_ID
The 'unsigned long _Fract' type.
@ PREDEF_TYPE_FLOAT16_ID
The '_Float16' type.
@ PREDEF_TYPE_UINT_ID
The 'unsigned int' type.
@ PREDEF_TYPE_FLOAT128_ID
The '__float128' type.
@ PREDEF_TYPE_OBJC_ID
The ObjC 'id' type.
@ PREDEF_TYPE_CHAR16_ID
The C++ 'char16_t' type.
@ PREDEF_TYPE_ARRAY_SECTION
The placeholder type for an array section.
@ PREDEF_TYPE_ULONGLONG_ID
The 'unsigned long long' type.
@ PREDEF_TYPE_SAT_UFRACT_ID
The '_Sat unsigned _Fract' type.
@ PREDEF_TYPE_USHORT_ID
The 'unsigned short' type.
@ PREDEF_TYPE_SHORT_ID
The (signed) 'short' type.
@ PREDEF_TYPE_OMP_ARRAY_SHAPING
The placeholder type for OpenMP array shaping operation.
@ PREDEF_TYPE_DEPENDENT_ID
The placeholder type for dependent types.
@ PREDEF_TYPE_LONGDOUBLE_ID
The 'long double' type.
@ PREDEF_TYPE_DOUBLE_ID
The 'double' type.
@ PREDEF_TYPE_UINT128_ID
The '__uint128_t' type.
@ PREDEF_TYPE_HALF_ID
The OpenCL 'half' / ARM NEON __fp16 type.
@ PREDEF_TYPE_VOID_ID
The void type.
@ PREDEF_TYPE_SAT_USHORT_FRACT_ID
The '_Sat unsigned short _Fract' type.
@ PREDEF_TYPE_ACCUM_ID
The '_Accum' type.
@ PREDEF_TYPE_SAT_FRACT_ID
The '_Sat _Fract' type.
@ PREDEF_TYPE_USHORT_ACCUM_ID
The 'unsigned short _Accum' type.
@ PREDEF_TYPE_CHAR8_ID
The C++ 'char8_t' type.
@ PREDEF_TYPE_UFRACT_ID
The 'unsigned _Fract' type.
@ PREDEF_TYPE_OVERLOAD_ID
The placeholder type for overloaded function sets.
@ PREDEF_TYPE_INCOMPLETE_MATRIX_IDX
A placeholder type for incomplete matrix index operations.
@ PREDEF_TYPE_UNRESOLVED_TEMPLATE
The placeholder type for unresolved templates.
@ PREDEF_TYPE_SAT_USHORT_ACCUM_ID
The '_Sat unsigned short _Accum' type.
@ PREDEF_TYPE_LONG_ID
The (signed) 'long' type.
@ PREDEF_TYPE_SAT_ULONG_ACCUM_ID
The '_Sat unsigned long _Accum' type.
@ PREDEF_TYPE_LONG_FRACT_ID
The 'long _Fract' type.
@ PREDEF_TYPE_UNKNOWN_ANY
The 'unknown any' placeholder type.
@ PREDEF_TYPE_OMP_ITERATOR
The placeholder type for OpenMP iterator expression.
@ PREDEF_TYPE_PSEUDO_OBJECT
The pseudo-object placeholder type.
@ PREDEF_TYPE_OBJC_CLASS
The ObjC 'Class' type.
@ PREDEF_TYPE_ULONG_ID
The 'unsigned long' type.
@ PREDEF_TYPE_SAT_UACCUM_ID
The '_Sat unsigned _Accum' type.
@ PREDEF_TYPE_CLK_EVENT_ID
OpenCL clk event type.
@ PREDEF_TYPE_EVENT_ID
OpenCL event type.
@ PREDEF_TYPE_ULONG_ACCUM_ID
The 'unsigned long _Accum' type.
bool isRedeclarableDeclKind(unsigned Kind)
Determine whether the given declaration kind is redeclarable.
TypeIdx TypeIdxFromBuiltin(const BuiltinType *BT)
bool needsAnonymousDeclarationNumber(const NamedDecl *D)
Determine whether the given declaration needs an anonymous declaration number.
const DeclContext * getDefinitiveDeclContext(const DeclContext *DC)
Retrieve the "definitive" declaration that provides all of the visible entries for the given declarat...
void updateModuleTimestamp(StringRef ModuleFilename)
unsigned ComputeHash(Selector Sel)
The JSON file list parser is used to communicate input to InstallAPI.