From 736104a7619c53ef92553780273d7357a3cdde81 Mon Sep 17 00:00:00 2001 From: Guy Benyei Date: Tue, 18 Dec 2012 12:30:03 +0000 Subject: [PATCH] Add OpenCL images as clang builtin types. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@170428 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/ASTContext.h | 3 + include/clang/AST/BuiltinTypes.def | 460 +- include/clang/AST/Type.h | 45 + include/clang/Basic/Specifiers.h | 394 +- include/clang/Basic/TokenKinds.def | 6 + include/clang/Sema/DeclSpec.h | 8 +- include/clang/Serialization/ASTBitCodes.h | 2722 ++-- lib/AST/ASTContext.cpp | 19 + lib/AST/ItaniumMangle.cpp | 7154 +++++----- lib/AST/MicrosoftMangle.cpp | 3443 ++--- lib/AST/NSAPI.cpp | 834 +- lib/AST/Type.cpp | 6 + lib/AST/TypeLoc.cpp | 728 +- lib/CodeGen/CGDebugInfo.cpp | 5636 ++++---- lib/CodeGen/CGDebugInfo.h | 655 +- lib/CodeGen/CGOpenCLRuntime.cpp | 87 +- lib/CodeGen/CGOpenCLRuntime.h | 98 +- lib/CodeGen/CGRTTI.cpp | 2028 +-- lib/CodeGen/CodeGenTypes.cpp | 10 + lib/Parse/ParseDecl.cpp | 48 + lib/Parse/ParseExpr.cpp | 8 +- lib/Parse/ParseTentative.cpp | 3154 ++--- lib/Sema/DeclSpec.cpp | 12 + lib/Sema/SemaTemplateVariadic.cpp | 6 + lib/Sema/SemaType.cpp | 24 + lib/Serialization/ASTCommon.cpp | 166 +- lib/Serialization/ASTReader.cpp | 13990 ++++++++++---------- test/CodeGenOpenCL/opencl_types.cl | 22 + test/PCH/ocl_types.cl | 18 + test/PCH/ocl_types.h | 19 + test/Parser/opencl-image-access.cl | 30 +- tools/libclang/CIndex.cpp | 12344 ++++++++--------- tools/libclang/CIndexUSRs.cpp | 1818 +-- 33 files changed, 28202 insertions(+), 27793 deletions(-) create mode 100644 test/CodeGenOpenCL/opencl_types.cl create mode 100644 test/PCH/ocl_types.cl create mode 100644 test/PCH/ocl_types.h diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index 86b2c42f85..d750ba948d 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -716,6 +716,9 @@ public: CanQualType PseudoObjectTy, ARCUnbridgedCastTy; CanQualType ObjCBuiltinIdTy, ObjCBuiltinClassTy, ObjCBuiltinSelTy; CanQualType ObjCBuiltinBoolTy; + CanQualType OCLImage1dTy, OCLImage1dArrayTy, OCLImage1dBufferTy; + CanQualType OCLImage2dTy, OCLImage2dArrayTy; + CanQualType OCLImage3dTy; // Types for deductions in C++0x [stmt.ranged]'s desugaring. Built on demand. mutable QualType AutoDeductTy; // Deduction against 'auto'. diff --git a/include/clang/AST/BuiltinTypes.def b/include/clang/AST/BuiltinTypes.def index ba322fb326..75ebb2c5a5 100644 --- a/include/clang/AST/BuiltinTypes.def +++ b/include/clang/AST/BuiltinTypes.def @@ -1,226 +1,234 @@ -//===-- BuiltinTypeNodes.def - Metadata about BuiltinTypes ------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file defines the database about various builtin singleton types. -// -// BuiltinType::Id is the enumerator defining the type. -// -// Context.SingletonId is the global singleton of this type. Some global -// singletons are shared by multiple types. -// -// BUILTIN_TYPE(Id, SingletonId) - A builtin type that has not been -// covered by any other #define. Defining this macro covers all -// the builtins. -// -// SIGNED_TYPE(Id, SingletonId) - A signed integral type. -// -// UNSIGNED_TYPE(Id, SingletonId) - An unsigned integral type. -// -// FLOATING_TYPE(Id, SingletonId) - A floating-point type. -// -// PLACEHOLDER_TYPE(Id, SingletonId) - A placeholder type. Placeholder -// types are used to perform context-sensitive checking of specific -// forms of expression. -// -// SHARED_SINGLETON_TYPE(Expansion) - The given expansion corresponds -// to a builtin which uses a shared singleton type. -// -//===----------------------------------------------------------------------===// - -#ifndef SIGNED_TYPE -#define SIGNED_TYPE(Id, SingletonId) BUILTIN_TYPE(Id, SingletonId) -#endif - -#ifndef UNSIGNED_TYPE -#define UNSIGNED_TYPE(Id, SingletonId) BUILTIN_TYPE(Id, SingletonId) -#endif - -#ifndef FLOATING_TYPE -#define FLOATING_TYPE(Id, SingletonId) BUILTIN_TYPE(Id, SingletonId) -#endif - -#ifndef PLACEHOLDER_TYPE -#define PLACEHOLDER_TYPE(Id, SingletonId) BUILTIN_TYPE(Id, SingletonId) -#endif - -#ifndef SHARED_SINGLETON_TYPE -#define SHARED_SINGLETON_TYPE(Expansion) Expansion -#endif - -//===- Builtin Types ------------------------------------------------------===// - -// void -BUILTIN_TYPE(Void, VoidTy) - -//===- Unsigned Types -----------------------------------------------------===// - -// 'bool' in C++, '_Bool' in C99 -UNSIGNED_TYPE(Bool, BoolTy) - -// 'char' for targets where it's unsigned -SHARED_SINGLETON_TYPE(UNSIGNED_TYPE(Char_U, CharTy)) - -// 'unsigned char', explicitly qualified -UNSIGNED_TYPE(UChar, UnsignedCharTy) - -// 'wchar_t' for targets where it's unsigned -SHARED_SINGLETON_TYPE(UNSIGNED_TYPE(WChar_U, WCharTy)) - -// 'char16_t' in C++ -UNSIGNED_TYPE(Char16, Char16Ty) - -// 'char32_t' in C++ -UNSIGNED_TYPE(Char32, Char32Ty) - -// 'unsigned short' -UNSIGNED_TYPE(UShort, UnsignedShortTy) - -// 'unsigned int' -UNSIGNED_TYPE(UInt, UnsignedIntTy) - -// 'unsigned long' -UNSIGNED_TYPE(ULong, UnsignedLongTy) - -// 'unsigned long long' -UNSIGNED_TYPE(ULongLong, UnsignedLongLongTy) - -// '__uint128_t' -UNSIGNED_TYPE(UInt128, UnsignedInt128Ty) - -//===- Signed Types -------------------------------------------------------===// - -// 'char' for targets where it's signed -SHARED_SINGLETON_TYPE(SIGNED_TYPE(Char_S, CharTy)) - -// 'signed char', explicitly qualified -SIGNED_TYPE(SChar, SignedCharTy) - -// 'wchar_t' for targets where it's signed -SHARED_SINGLETON_TYPE(SIGNED_TYPE(WChar_S, WCharTy)) - -// 'short' or 'signed short' -SIGNED_TYPE(Short, ShortTy) - -// 'int' or 'signed int' -SIGNED_TYPE(Int, IntTy) - -// 'long' or 'signed long' -SIGNED_TYPE(Long, LongTy) - -// 'long long' or 'signed long long' -SIGNED_TYPE(LongLong, LongLongTy) - -// '__int128_t' -SIGNED_TYPE(Int128, Int128Ty) - -//===- Floating point types -----------------------------------------------===// - -// 'half' in OpenCL, '__fp16' in ARM NEON. -FLOATING_TYPE(Half, HalfTy) - -// 'float' -FLOATING_TYPE(Float, FloatTy) - -// 'double' -FLOATING_TYPE(Double, DoubleTy) - -// 'long double' -FLOATING_TYPE(LongDouble, LongDoubleTy) - -//===- Language-specific types --------------------------------------------===// - -// This is the type of C++0x 'nullptr'. -BUILTIN_TYPE(NullPtr, NullPtrTy) - -// The primitive Objective C 'id' type. The user-visible 'id' -// type is a typedef of an ObjCObjectPointerType to an -// ObjCObjectType with this as its base. In fact, this only ever -// shows up in an AST as the base type of an ObjCObjectType. -BUILTIN_TYPE(ObjCId, ObjCBuiltinIdTy) - -// The primitive Objective C 'Class' type. The user-visible -// 'Class' type is a typedef of an ObjCObjectPointerType to an -// ObjCObjectType with this as its base. In fact, this only ever -// shows up in an AST as the base type of an ObjCObjectType. -BUILTIN_TYPE(ObjCClass, ObjCBuiltinClassTy) - -// The primitive Objective C 'SEL' type. The user-visible 'SEL' -// type is a typedef of a PointerType to this. -BUILTIN_TYPE(ObjCSel, ObjCBuiltinSelTy) - -// This represents the type of an expression whose type is -// totally unknown, e.g. 'T::foo'. It is permitted for this to -// appear in situations where the structure of the type is -// theoretically deducible. -BUILTIN_TYPE(Dependent, DependentTy) - -// The type of an unresolved overload set. A placeholder type. -// Expressions with this type have one of the following basic -// forms, with parentheses generally permitted: -// foo # possibly qualified, not if an implicit access -// foo # possibly qualified, not if an implicit access -// &foo # possibly qualified, not if an implicit access -// x->foo # only if might be a static member function -// &x->foo # only if might be a static member function -// &Class::foo # when a pointer-to-member; sub-expr also has this type -// OverloadExpr::find can be used to analyze the expression. -// -// Overload should be the first placeholder type, or else change -// BuiltinType::isNonOverloadPlaceholderType() -PLACEHOLDER_TYPE(Overload, OverloadTy) - -// The type of a bound C++ non-static member function. -// A placeholder type. Expressions with this type have one of the -// following basic forms: -// foo # if an implicit access -// x->foo # if only contains non-static members -PLACEHOLDER_TYPE(BoundMember, BoundMemberTy) - -// The type of an expression which refers to a pseudo-object, -// such as those introduced by Objective C's @property or -// VS.NET's __property declarations. A placeholder type. The -// pseudo-object is actually accessed by emitting a call to -// some sort of function or method; typically there is a pair -// of a setter and a getter, with the setter used if the -// pseudo-object reference is used syntactically as the -// left-hand-side of an assignment operator. -// -// A pseudo-object reference naming an Objective-C @property is -// always a dot access with a base of object-pointer type, -// e.g. 'x.foo'. -// -// In VS.NET, a __property declaration creates an implicit -// member with an associated name, which can then be named -// in any of the normal ways an ordinary member could be. -PLACEHOLDER_TYPE(PseudoObject, PseudoObjectTy) - -// __builtin_any_type. A placeholder type. Useful for clients -// like debuggers that don't know what type to give something. -// Only a small number of operations are valid on expressions of -// unknown type, most notably explicit casts. -PLACEHOLDER_TYPE(UnknownAny, UnknownAnyTy) - -PLACEHOLDER_TYPE(BuiltinFn, BuiltinFnTy) - -// The type of a cast which, in ARC, would normally require a -// __bridge, but which might be okay depending on the immediate -// context. -PLACEHOLDER_TYPE(ARCUnbridgedCast, ARCUnbridgedCastTy) - -#ifdef LAST_BUILTIN_TYPE -LAST_BUILTIN_TYPE(ARCUnbridgedCast) -#undef LAST_BUILTIN_TYPE -#endif - -#undef SHARED_SINGLETON_TYPE -#undef PLACEHOLDER_TYPE -#undef FLOATING_TYPE -#undef SIGNED_TYPE -#undef UNSIGNED_TYPE -#undef BUILTIN_TYPE +//===-- BuiltinTypeNodes.def - Metadata about BuiltinTypes ------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines the database about various builtin singleton types. +// +// BuiltinType::Id is the enumerator defining the type. +// +// Context.SingletonId is the global singleton of this type. Some global +// singletons are shared by multiple types. +// +// BUILTIN_TYPE(Id, SingletonId) - A builtin type that has not been +// covered by any other #define. Defining this macro covers all +// the builtins. +// +// SIGNED_TYPE(Id, SingletonId) - A signed integral type. +// +// UNSIGNED_TYPE(Id, SingletonId) - An unsigned integral type. +// +// FLOATING_TYPE(Id, SingletonId) - A floating-point type. +// +// PLACEHOLDER_TYPE(Id, SingletonId) - A placeholder type. Placeholder +// types are used to perform context-sensitive checking of specific +// forms of expression. +// +// SHARED_SINGLETON_TYPE(Expansion) - The given expansion corresponds +// to a builtin which uses a shared singleton type. +// +//===----------------------------------------------------------------------===// + +#ifndef SIGNED_TYPE +#define SIGNED_TYPE(Id, SingletonId) BUILTIN_TYPE(Id, SingletonId) +#endif + +#ifndef UNSIGNED_TYPE +#define UNSIGNED_TYPE(Id, SingletonId) BUILTIN_TYPE(Id, SingletonId) +#endif + +#ifndef FLOATING_TYPE +#define FLOATING_TYPE(Id, SingletonId) BUILTIN_TYPE(Id, SingletonId) +#endif + +#ifndef PLACEHOLDER_TYPE +#define PLACEHOLDER_TYPE(Id, SingletonId) BUILTIN_TYPE(Id, SingletonId) +#endif + +#ifndef SHARED_SINGLETON_TYPE +#define SHARED_SINGLETON_TYPE(Expansion) Expansion +#endif + +//===- Builtin Types ------------------------------------------------------===// + +// void +BUILTIN_TYPE(Void, VoidTy) + +//===- Unsigned Types -----------------------------------------------------===// + +// 'bool' in C++, '_Bool' in C99 +UNSIGNED_TYPE(Bool, BoolTy) + +// 'char' for targets where it's unsigned +SHARED_SINGLETON_TYPE(UNSIGNED_TYPE(Char_U, CharTy)) + +// 'unsigned char', explicitly qualified +UNSIGNED_TYPE(UChar, UnsignedCharTy) + +// 'wchar_t' for targets where it's unsigned +SHARED_SINGLETON_TYPE(UNSIGNED_TYPE(WChar_U, WCharTy)) + +// 'char16_t' in C++ +UNSIGNED_TYPE(Char16, Char16Ty) + +// 'char32_t' in C++ +UNSIGNED_TYPE(Char32, Char32Ty) + +// 'unsigned short' +UNSIGNED_TYPE(UShort, UnsignedShortTy) + +// 'unsigned int' +UNSIGNED_TYPE(UInt, UnsignedIntTy) + +// 'unsigned long' +UNSIGNED_TYPE(ULong, UnsignedLongTy) + +// 'unsigned long long' +UNSIGNED_TYPE(ULongLong, UnsignedLongLongTy) + +// '__uint128_t' +UNSIGNED_TYPE(UInt128, UnsignedInt128Ty) + +//===- Signed Types -------------------------------------------------------===// + +// 'char' for targets where it's signed +SHARED_SINGLETON_TYPE(SIGNED_TYPE(Char_S, CharTy)) + +// 'signed char', explicitly qualified +SIGNED_TYPE(SChar, SignedCharTy) + +// 'wchar_t' for targets where it's signed +SHARED_SINGLETON_TYPE(SIGNED_TYPE(WChar_S, WCharTy)) + +// 'short' or 'signed short' +SIGNED_TYPE(Short, ShortTy) + +// 'int' or 'signed int' +SIGNED_TYPE(Int, IntTy) + +// 'long' or 'signed long' +SIGNED_TYPE(Long, LongTy) + +// 'long long' or 'signed long long' +SIGNED_TYPE(LongLong, LongLongTy) + +// '__int128_t' +SIGNED_TYPE(Int128, Int128Ty) + +//===- Floating point types -----------------------------------------------===// + +// 'half' in OpenCL, '__fp16' in ARM NEON. +FLOATING_TYPE(Half, HalfTy) + +// 'float' +FLOATING_TYPE(Float, FloatTy) + +// 'double' +FLOATING_TYPE(Double, DoubleTy) + +// 'long double' +FLOATING_TYPE(LongDouble, LongDoubleTy) + +//===- Language-specific types --------------------------------------------===// + +// This is the type of C++0x 'nullptr'. +BUILTIN_TYPE(NullPtr, NullPtrTy) + +// The primitive Objective C 'id' type. The user-visible 'id' +// type is a typedef of an ObjCObjectPointerType to an +// ObjCObjectType with this as its base. In fact, this only ever +// shows up in an AST as the base type of an ObjCObjectType. +BUILTIN_TYPE(ObjCId, ObjCBuiltinIdTy) + +// The primitive Objective C 'Class' type. The user-visible +// 'Class' type is a typedef of an ObjCObjectPointerType to an +// ObjCObjectType with this as its base. In fact, this only ever +// shows up in an AST as the base type of an ObjCObjectType. +BUILTIN_TYPE(ObjCClass, ObjCBuiltinClassTy) + +// The primitive Objective C 'SEL' type. The user-visible 'SEL' +// type is a typedef of a PointerType to this. +BUILTIN_TYPE(ObjCSel, ObjCBuiltinSelTy) + +// OpenCL image types. +BUILTIN_TYPE(OCLImage1d, OCLImage1dTy) +BUILTIN_TYPE(OCLImage1dArray, OCLImage1dArrayTy) +BUILTIN_TYPE(OCLImage1dBuffer, OCLImage1dBufferTy) +BUILTIN_TYPE(OCLImage2d, OCLImage2dTy) +BUILTIN_TYPE(OCLImage2dArray, OCLImage2dArrayTy) +BUILTIN_TYPE(OCLImage3d, OCLImage3dTy) + +// This represents the type of an expression whose type is +// totally unknown, e.g. 'T::foo'. It is permitted for this to +// appear in situations where the structure of the type is +// theoretically deducible. +BUILTIN_TYPE(Dependent, DependentTy) + +// The type of an unresolved overload set. A placeholder type. +// Expressions with this type have one of the following basic +// forms, with parentheses generally permitted: +// foo # possibly qualified, not if an implicit access +// foo # possibly qualified, not if an implicit access +// &foo # possibly qualified, not if an implicit access +// x->foo # only if might be a static member function +// &x->foo # only if might be a static member function +// &Class::foo # when a pointer-to-member; sub-expr also has this type +// OverloadExpr::find can be used to analyze the expression. +// +// Overload should be the first placeholder type, or else change +// BuiltinType::isNonOverloadPlaceholderType() +PLACEHOLDER_TYPE(Overload, OverloadTy) + +// The type of a bound C++ non-static member function. +// A placeholder type. Expressions with this type have one of the +// following basic forms: +// foo # if an implicit access +// x->foo # if only contains non-static members +PLACEHOLDER_TYPE(BoundMember, BoundMemberTy) + +// The type of an expression which refers to a pseudo-object, +// such as those introduced by Objective C's @property or +// VS.NET's __property declarations. A placeholder type. The +// pseudo-object is actually accessed by emitting a call to +// some sort of function or method; typically there is a pair +// of a setter and a getter, with the setter used if the +// pseudo-object reference is used syntactically as the +// left-hand-side of an assignment operator. +// +// A pseudo-object reference naming an Objective-C @property is +// always a dot access with a base of object-pointer type, +// e.g. 'x.foo'. +// +// In VS.NET, a __property declaration creates an implicit +// member with an associated name, which can then be named +// in any of the normal ways an ordinary member could be. +PLACEHOLDER_TYPE(PseudoObject, PseudoObjectTy) + +// __builtin_any_type. A placeholder type. Useful for clients +// like debuggers that don't know what type to give something. +// Only a small number of operations are valid on expressions of +// unknown type, most notably explicit casts. +PLACEHOLDER_TYPE(UnknownAny, UnknownAnyTy) + +PLACEHOLDER_TYPE(BuiltinFn, BuiltinFnTy) + +// The type of a cast which, in ARC, would normally require a +// __bridge, but which might be okay depending on the immediate +// context. +PLACEHOLDER_TYPE(ARCUnbridgedCast, ARCUnbridgedCastTy) + +#ifdef LAST_BUILTIN_TYPE +LAST_BUILTIN_TYPE(ARCUnbridgedCast) +#undef LAST_BUILTIN_TYPE +#endif + +#undef SHARED_SINGLETON_TYPE +#undef PLACEHOLDER_TYPE +#undef FLOATING_TYPE +#undef SIGNED_TYPE +#undef UNSIGNED_TYPE +#undef BUILTIN_TYPE diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h index 368be8d6b0..cf3b565fc3 100644 --- a/include/clang/AST/Type.h +++ b/include/clang/AST/Type.h @@ -1580,6 +1580,17 @@ public: bool isNullPtrType() const; // C++0x nullptr_t bool isAtomicType() const; // C11 _Atomic() + bool isImage1dT() const; // OpenCL image1d_t + bool isImage1dArrayT() const; // OpenCL image1d_array_t + bool isImage1dBufferT() const; // OpenCL image1d_buffer_t + bool isImage2dT() const; // OpenCL image2d_t + bool isImage2dArrayT() const; // OpenCL image2d_array_t + bool isImage3dT() const; // OpenCL image3d_t + + bool isImageType() const; // Any OpenCL image type + + bool isOpenCLSpecificType() const; // Any OpenCL specific type + /// Determines if this type, which must satisfy /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather /// than implicitly __strong. @@ -4883,6 +4894,40 @@ inline bool Type::isObjCSelType() const { inline bool Type::isObjCBuiltinType() const { return isObjCIdType() || isObjCClassType() || isObjCSelType(); } + +inline bool Type::isImage1dT() const { + return isSpecificBuiltinType(BuiltinType::OCLImage1d); +} + +inline bool Type::isImage1dArrayT() const { + return isSpecificBuiltinType(BuiltinType::OCLImage1dArray); +} + +inline bool Type::isImage1dBufferT() const { + return isSpecificBuiltinType(BuiltinType::OCLImage1dBuffer); +} + +inline bool Type::isImage2dT() const { + return isSpecificBuiltinType(BuiltinType::OCLImage2d); +} + +inline bool Type::isImage2dArrayT() const { + return isSpecificBuiltinType(BuiltinType::OCLImage2dArray); +} + +inline bool Type::isImage3dT() const { + return isSpecificBuiltinType(BuiltinType::OCLImage3d); +} +inline bool Type::isImageType() const { + return isImage3dT() || + isImage2dT() || isImage2dArrayT() || + isImage1dT() || isImage1dArrayT() || isImage1dBufferT(); +} + +inline bool Type::isOpenCLSpecificType() const { + return isImageType(); +} + inline bool Type::isTemplateTypeParmType() const { return isa(CanonicalType); } diff --git a/include/clang/Basic/Specifiers.h b/include/clang/Basic/Specifiers.h index c82b8cb918..8a6c62933c 100644 --- a/include/clang/Basic/Specifiers.h +++ b/include/clang/Basic/Specifiers.h @@ -1,194 +1,200 @@ -//===--- Specifiers.h - Declaration and Type Specifiers ---------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -/// -/// \file -/// \brief Defines various enumerations that describe declaration and -/// type specifiers. -/// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_BASIC_SPECIFIERS_H -#define LLVM_CLANG_BASIC_SPECIFIERS_H - -namespace clang { - /// \brief Specifies the width of a type, e.g., short, long, or long long. - enum TypeSpecifierWidth { - TSW_unspecified, - TSW_short, - TSW_long, - TSW_longlong - }; - - /// \brief Specifies the signedness of a type, e.g., signed or unsigned. - enum TypeSpecifierSign { - TSS_unspecified, - TSS_signed, - TSS_unsigned - }; - - /// \brief Specifies the kind of type. - enum TypeSpecifierType { - TST_unspecified, - TST_void, - TST_char, - TST_wchar, // C++ wchar_t - TST_char16, // C++0x char16_t - TST_char32, // C++0x char32_t - TST_int, - TST_int128, - TST_half, // OpenCL half, ARM NEON __fp16 - TST_float, - TST_double, - TST_bool, // _Bool - TST_decimal32, // _Decimal32 - TST_decimal64, // _Decimal64 - TST_decimal128, // _Decimal128 - TST_enum, - TST_union, - TST_struct, - TST_class, // C++ class type - TST_interface, // C++ (Microsoft-specific) __interface type - TST_typename, // Typedef, C++ class-name or enum name, etc. - TST_typeofType, - TST_typeofExpr, - TST_decltype, // C++0x decltype - TST_underlyingType, // __underlying_type for C++0x - TST_auto, // C++0x auto - TST_unknown_anytype, // __unknown_anytype extension - TST_atomic, // C11 _Atomic - TST_error // erroneous type - }; - - /// \brief Structure that packs information about the type specifiers that - /// were written in a particular type specifier sequence. - struct WrittenBuiltinSpecs { - /*DeclSpec::TST*/ unsigned Type : 5; - /*DeclSpec::TSS*/ unsigned Sign : 2; - /*DeclSpec::TSW*/ unsigned Width : 2; - bool ModeAttr : 1; - }; - - /// \brief A C++ access specifier (public, private, protected), plus the - /// special value "none" which means different things in different contexts. - enum AccessSpecifier { - AS_public, - AS_protected, - AS_private, - AS_none - }; - - /// \brief The categorization of expression values, currently following the - /// C++11 scheme. - enum ExprValueKind { - /// \brief An r-value expression (a pr-value in the C++11 taxonomy) - /// produces a temporary value. - VK_RValue, - - /// \brief An l-value expression is a reference to an object with - /// independent storage. - VK_LValue, - - /// \brief An x-value expression is a reference to an object with - /// independent storage but which can be "moved", i.e. - /// efficiently cannibalized for its resources. - VK_XValue - }; - - /// \brief A further classification of the kind of object referenced by an - /// l-value or x-value. - enum ExprObjectKind { - /// An ordinary object is located at an address in memory. - OK_Ordinary, - - /// A bitfield object is a bitfield on a C or C++ record. - OK_BitField, - - /// A vector component is an element or range of elements on a vector. - OK_VectorComponent, - - /// An Objective-C property is a logical field of an Objective-C - /// object which is read and written via Objective-C method calls. - OK_ObjCProperty, - - /// An Objective-C array/dictionary subscripting which reads an - /// object or writes at the subscripted array/dictionary element via - /// Objective-C method calls. - OK_ObjCSubscript - }; - - // \brief Describes the kind of template specialization that a - // particular template specialization declaration represents. - enum TemplateSpecializationKind { - /// This template specialization was formed from a template-id but - /// has not yet been declared, defined, or instantiated. - TSK_Undeclared = 0, - /// This template specialization was implicitly instantiated from a - /// template. (C++ [temp.inst]). - TSK_ImplicitInstantiation, - /// This template specialization was declared or defined by an - /// explicit specialization (C++ [temp.expl.spec]) or partial - /// specialization (C++ [temp.class.spec]). - TSK_ExplicitSpecialization, - /// This template specialization was instantiated from a template - /// due to an explicit instantiation declaration request - /// (C++0x [temp.explicit]). - TSK_ExplicitInstantiationDeclaration, - /// This template specialization was instantiated from a template - /// due to an explicit instantiation definition request - /// (C++ [temp.explicit]). - TSK_ExplicitInstantiationDefinition - }; - - /// \brief Storage classes. - enum StorageClass { - // These are legal on both functions and variables. - SC_None, - SC_Extern, - SC_Static, - SC_PrivateExtern, - - // These are only legal on variables. - SC_OpenCLWorkGroupLocal, - SC_Auto, - SC_Register - }; - - /// \brief Checks whether the given storage class is legal for functions. - inline bool isLegalForFunction(StorageClass SC) { - return SC <= SC_PrivateExtern; - } - - /// \brief Checks whether the given storage class is legal for variables. - inline bool isLegalForVariable(StorageClass SC) { - return true; - } - - /// \brief In-class initialization styles for non-static data members. - enum InClassInitStyle { - ICIS_NoInit, ///< No in-class initializer. - ICIS_CopyInit, ///< Copy initialization. - ICIS_ListInit ///< Direct list-initialization. - }; - - /// \brief CallingConv - Specifies the calling convention that a function uses. - enum CallingConv { - CC_Default, - CC_C, // __attribute__((cdecl)) - CC_X86StdCall, // __attribute__((stdcall)) - CC_X86FastCall, // __attribute__((fastcall)) - CC_X86ThisCall, // __attribute__((thiscall)) - CC_X86Pascal, // __attribute__((pascal)) - CC_AAPCS, // __attribute__((pcs("aapcs"))) - CC_AAPCS_VFP, // __attribute__((pcs("aapcs-vfp"))) - CC_PnaclCall // __attribute__((pnaclcall)) - }; - -} // end namespace clang - -#endif // LLVM_CLANG_BASIC_SPECIFIERS_H +//===--- Specifiers.h - Declaration and Type Specifiers ---------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// \brief Defines various enumerations that describe declaration and +/// type specifiers. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_BASIC_SPECIFIERS_H +#define LLVM_CLANG_BASIC_SPECIFIERS_H + +namespace clang { + /// \brief Specifies the width of a type, e.g., short, long, or long long. + enum TypeSpecifierWidth { + TSW_unspecified, + TSW_short, + TSW_long, + TSW_longlong + }; + + /// \brief Specifies the signedness of a type, e.g., signed or unsigned. + enum TypeSpecifierSign { + TSS_unspecified, + TSS_signed, + TSS_unsigned + }; + + /// \brief Specifies the kind of type. + enum TypeSpecifierType { + TST_unspecified, + TST_void, + TST_char, + TST_wchar, // C++ wchar_t + TST_char16, // C++0x char16_t + TST_char32, // C++0x char32_t + TST_int, + TST_int128, + TST_half, // OpenCL half, ARM NEON __fp16 + TST_float, + TST_double, + TST_bool, // _Bool + TST_decimal32, // _Decimal32 + TST_decimal64, // _Decimal64 + TST_decimal128, // _Decimal128 + TST_enum, + TST_union, + TST_struct, + TST_class, // C++ class type + TST_interface, // C++ (Microsoft-specific) __interface type + TST_typename, // Typedef, C++ class-name or enum name, etc. + TST_typeofType, + TST_typeofExpr, + TST_decltype, // C++0x decltype + TST_underlyingType, // __underlying_type for C++0x + TST_auto, // C++0x auto + TST_unknown_anytype, // __unknown_anytype extension + TST_atomic, // C11 _Atomic + TST_image1d_t, // OpenCL image1d_t + TST_image1d_array_t, // OpenCL image1d_array_t + TST_image1d_buffer_t, // OpenCL image1d_buffer_t + TST_image2d_t, // OpenCL image2d_t + TST_image2d_array_t, // OpenCL image2d_array_t + TST_image3d_t, // OpenCL image3d_t + TST_error // erroneous type + }; + + /// \brief Structure that packs information about the type specifiers that + /// were written in a particular type specifier sequence. + struct WrittenBuiltinSpecs { + /*DeclSpec::TST*/ unsigned Type : 6; + /*DeclSpec::TSS*/ unsigned Sign : 2; + /*DeclSpec::TSW*/ unsigned Width : 2; + bool ModeAttr : 1; + }; + + /// \brief A C++ access specifier (public, private, protected), plus the + /// special value "none" which means different things in different contexts. + enum AccessSpecifier { + AS_public, + AS_protected, + AS_private, + AS_none + }; + + /// \brief The categorization of expression values, currently following the + /// C++11 scheme. + enum ExprValueKind { + /// \brief An r-value expression (a pr-value in the C++11 taxonomy) + /// produces a temporary value. + VK_RValue, + + /// \brief An l-value expression is a reference to an object with + /// independent storage. + VK_LValue, + + /// \brief An x-value expression is a reference to an object with + /// independent storage but which can be "moved", i.e. + /// efficiently cannibalized for its resources. + VK_XValue + }; + + /// \brief A further classification of the kind of object referenced by an + /// l-value or x-value. + enum ExprObjectKind { + /// An ordinary object is located at an address in memory. + OK_Ordinary, + + /// A bitfield object is a bitfield on a C or C++ record. + OK_BitField, + + /// A vector component is an element or range of elements on a vector. + OK_VectorComponent, + + /// An Objective-C property is a logical field of an Objective-C + /// object which is read and written via Objective-C method calls. + OK_ObjCProperty, + + /// An Objective-C array/dictionary subscripting which reads an + /// object or writes at the subscripted array/dictionary element via + /// Objective-C method calls. + OK_ObjCSubscript + }; + + // \brief Describes the kind of template specialization that a + // particular template specialization declaration represents. + enum TemplateSpecializationKind { + /// This template specialization was formed from a template-id but + /// has not yet been declared, defined, or instantiated. + TSK_Undeclared = 0, + /// This template specialization was implicitly instantiated from a + /// template. (C++ [temp.inst]). + TSK_ImplicitInstantiation, + /// This template specialization was declared or defined by an + /// explicit specialization (C++ [temp.expl.spec]) or partial + /// specialization (C++ [temp.class.spec]). + TSK_ExplicitSpecialization, + /// This template specialization was instantiated from a template + /// due to an explicit instantiation declaration request + /// (C++0x [temp.explicit]). + TSK_ExplicitInstantiationDeclaration, + /// This template specialization was instantiated from a template + /// due to an explicit instantiation definition request + /// (C++ [temp.explicit]). + TSK_ExplicitInstantiationDefinition + }; + + /// \brief Storage classes. + enum StorageClass { + // These are legal on both functions and variables. + SC_None, + SC_Extern, + SC_Static, + SC_PrivateExtern, + + // These are only legal on variables. + SC_OpenCLWorkGroupLocal, + SC_Auto, + SC_Register + }; + + /// \brief Checks whether the given storage class is legal for functions. + inline bool isLegalForFunction(StorageClass SC) { + return SC <= SC_PrivateExtern; + } + + /// \brief Checks whether the given storage class is legal for variables. + inline bool isLegalForVariable(StorageClass SC) { + return true; + } + + /// \brief In-class initialization styles for non-static data members. + enum InClassInitStyle { + ICIS_NoInit, ///< No in-class initializer. + ICIS_CopyInit, ///< Copy initialization. + ICIS_ListInit ///< Direct list-initialization. + }; + + /// \brief CallingConv - Specifies the calling convention that a function uses. + enum CallingConv { + CC_Default, + CC_C, // __attribute__((cdecl)) + CC_X86StdCall, // __attribute__((stdcall)) + CC_X86FastCall, // __attribute__((fastcall)) + CC_X86ThisCall, // __attribute__((thiscall)) + CC_X86Pascal, // __attribute__((pascal)) + CC_AAPCS, // __attribute__((pcs("aapcs"))) + CC_AAPCS_VFP, // __attribute__((pcs("aapcs-vfp"))) + CC_PnaclCall // __attribute__((pnaclcall)) + }; + +} // end namespace clang + +#endif // LLVM_CLANG_BASIC_SPECIFIERS_H diff --git a/include/clang/Basic/TokenKinds.def b/include/clang/Basic/TokenKinds.def index f02ba6438b..7bc489b25c 100644 --- a/include/clang/Basic/TokenKinds.def +++ b/include/clang/Basic/TokenKinds.def @@ -448,6 +448,12 @@ ALIAS("read_only", __read_only , KEYOPENCL) ALIAS("write_only", __write_only , KEYOPENCL) ALIAS("read_write", __read_write , KEYOPENCL) KEYWORD(__builtin_astype , KEYOPENCL) +KEYWORD(image1d_t , KEYOPENCL) +KEYWORD(image1d_array_t , KEYOPENCL) +KEYWORD(image1d_buffer_t , KEYOPENCL) +KEYWORD(image2d_t , KEYOPENCL) +KEYWORD(image2d_array_t , KEYOPENCL) +KEYWORD(image3d_t , KEYOPENCL) // Borland Extensions. KEYWORD(__pascal , KEYALL) diff --git a/include/clang/Sema/DeclSpec.h b/include/clang/Sema/DeclSpec.h index d261810574..bc8fc64699 100644 --- a/include/clang/Sema/DeclSpec.h +++ b/include/clang/Sema/DeclSpec.h @@ -276,6 +276,12 @@ public: static const TST TST_auto = clang::TST_auto; static const TST TST_unknown_anytype = clang::TST_unknown_anytype; static const TST TST_atomic = clang::TST_atomic; + static const TST TST_image1d_t = clang::TST_image1d_t; + static const TST TST_image1d_array_t = clang::TST_image1d_array_t; + static const TST TST_image1d_buffer_t = clang::TST_image1d_buffer_t; + static const TST TST_image2d_t = clang::TST_image2d_t; + static const TST TST_image2d_array_t = clang::TST_image2d_array_t; + static const TST TST_image3d_t = clang::TST_image3d_t; static const TST TST_error = clang::TST_error; // type-qualifiers @@ -306,7 +312,7 @@ private: /*TSW*/unsigned TypeSpecWidth : 2; /*TSC*/unsigned TypeSpecComplex : 2; /*TSS*/unsigned TypeSpecSign : 2; - /*TST*/unsigned TypeSpecType : 5; + /*TST*/unsigned TypeSpecType : 6; unsigned TypeAltiVecVector : 1; unsigned TypeAltiVecPixel : 1; unsigned TypeAltiVecBool : 1; diff --git a/include/clang/Serialization/ASTBitCodes.h b/include/clang/Serialization/ASTBitCodes.h index 4273e14787..868a1758b6 100644 --- a/include/clang/Serialization/ASTBitCodes.h +++ b/include/clang/Serialization/ASTBitCodes.h @@ -1,1355 +1,1367 @@ -//===- ASTBitCodes.h - Enum values for the PCH bitcode format ---*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This header defines Bitcode enum values for Clang serialized AST files. -// -// The enum values defined in this file should be considered permanent. If -// new features are added, they should have values added at the end of the -// respective lists. -// -//===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_FRONTEND_PCHBITCODES_H -#define LLVM_CLANG_FRONTEND_PCHBITCODES_H - -#include "clang/AST/Type.h" -#include "llvm/ADT/DenseMap.h" -#include "llvm/Bitcode/BitCodes.h" -#include "llvm/Support/DataTypes.h" - -namespace clang { - namespace serialization { - /// \brief AST file major version number supported by this version of - /// Clang. - /// - /// Whenever the AST file format changes in a way that makes it - /// incompatible with previous versions (such that a reader - /// designed for the previous version could not support reading - /// the new version), this number should be increased. - /// - /// Version 4 of AST files also requires that the version control branch and - /// revision match exactly, since there is no backward compatibility of - /// AST files at this time. - const unsigned VERSION_MAJOR = 5; - - /// \brief AST file minor version number supported by this version of - /// Clang. - /// - /// Whenever the AST format changes in a way that is still - /// compatible with previous versions (such that a reader designed - /// for the previous version could still support reading the new - /// version by ignoring new kinds of subblocks), this number - /// should be increased. - const unsigned VERSION_MINOR = 0; - - /// \brief An ID number that refers to an identifier in an AST file. - /// - /// The ID numbers of identifiers are consecutive (in order of discovery) - /// and start at 1. 0 is reserved for NULL. - typedef uint32_t IdentifierID; - - /// \brief An ID number that refers to a declaration in an AST file. - /// - /// The ID numbers of declarations are consecutive (in order of - /// discovery), with values below NUM_PREDEF_DECL_IDS being reserved. - /// At the start of a chain of precompiled headers, declaration ID 1 is - /// used for the translation unit declaration. - typedef uint32_t DeclID; - - /// \brief a Decl::Kind/DeclID pair. - typedef std::pair KindDeclIDPair; - - // FIXME: Turn these into classes so we can have some type safety when - // we go from local ID to global and vice-versa. - typedef DeclID LocalDeclID; - typedef DeclID GlobalDeclID; - - /// \brief An ID number that refers to a type in an AST file. - /// - /// The ID of a type is partitioned into two parts: the lower - /// three bits are used to store the const/volatile/restrict - /// qualifiers (as with QualType) and the upper bits provide a - /// type index. The type index values are partitioned into two - /// sets. The values below NUM_PREDEF_TYPE_IDs are predefined type - /// IDs (based on the PREDEF_TYPE_*_ID constants), with 0 as a - /// placeholder for "no type". Values from NUM_PREDEF_TYPE_IDs are - /// other types that have serialized representations. - typedef uint32_t TypeID; - - /// \brief A type index; the type ID with the qualifier bits removed. - class TypeIdx { - uint32_t Idx; - public: - TypeIdx() : Idx(0) { } - explicit TypeIdx(uint32_t index) : Idx(index) { } - - uint32_t getIndex() const { return Idx; } - TypeID asTypeID(unsigned FastQuals) const { - if (Idx == uint32_t(-1)) - return TypeID(-1); - - return (Idx << Qualifiers::FastWidth) | FastQuals; - } - static TypeIdx fromTypeID(TypeID ID) { - if (ID == TypeID(-1)) - return TypeIdx(-1); - - return TypeIdx(ID >> Qualifiers::FastWidth); - } - }; - - /// A structure for putting "fast"-unqualified QualTypes into a - /// DenseMap. This uses the standard pointer hash function. - struct UnsafeQualTypeDenseMapInfo { - static inline bool isEqual(QualType A, QualType B) { return A == B; } - static inline QualType getEmptyKey() { - return QualType::getFromOpaquePtr((void*) 1); - } - static inline QualType getTombstoneKey() { - return QualType::getFromOpaquePtr((void*) 2); - } - static inline unsigned getHashValue(QualType T) { - assert(!T.getLocalFastQualifiers() && - "hash invalid for types with fast quals"); - uintptr_t v = reinterpret_cast(T.getAsOpaquePtr()); - return (unsigned(v) >> 4) ^ (unsigned(v) >> 9); - } - }; - - /// \brief An ID number that refers to an identifier in an AST file. - typedef uint32_t IdentID; - - /// \brief The number of predefined identifier IDs. - const unsigned int NUM_PREDEF_IDENT_IDS = 1; - - /// \brief An ID number that refers to a macro in an AST file. - typedef uint32_t MacroID; - - /// \brief The number of predefined macro IDs. - const unsigned int NUM_PREDEF_MACRO_IDS = 1; - - /// \brief An ID number that refers to an ObjC selector in an AST file. - typedef uint32_t SelectorID; - - /// \brief The number of predefined selector IDs. - const unsigned int NUM_PREDEF_SELECTOR_IDS = 1; - - /// \brief An ID number that refers to a set of CXXBaseSpecifiers in an - /// AST file. - typedef uint32_t CXXBaseSpecifiersID; - - /// \brief An ID number that refers to an entity in the detailed - /// preprocessing record. - typedef uint32_t PreprocessedEntityID; - - /// \brief An ID number that refers to a submodule in a module file. - typedef uint32_t SubmoduleID; - - /// \brief The number of predefined submodule IDs. - const unsigned int NUM_PREDEF_SUBMODULE_IDS = 1; - - /// \brief Source range/offset of a preprocessed entity. - struct PPEntityOffset { - /// \brief Raw source location of beginning of range. - unsigned Begin; - /// \brief Raw source location of end of range. - unsigned End; - /// \brief Offset in the AST file. - uint32_t BitOffset; - - PPEntityOffset(SourceRange R, uint32_t BitOffset) - : Begin(R.getBegin().getRawEncoding()), - End(R.getEnd().getRawEncoding()), - BitOffset(BitOffset) { } - }; - - /// \brief Source range/offset of a preprocessed entity. - struct DeclOffset { - /// \brief Raw source location. - unsigned Loc; - /// \brief Offset in the AST file. - uint32_t BitOffset; - - DeclOffset() : Loc(0), BitOffset(0) { } - DeclOffset(SourceLocation Loc, uint32_t BitOffset) - : Loc(Loc.getRawEncoding()), - BitOffset(BitOffset) { } - void setLocation(SourceLocation L) { - Loc = L.getRawEncoding(); - } - }; - - /// \brief The number of predefined preprocessed entity IDs. - const unsigned int NUM_PREDEF_PP_ENTITY_IDS = 1; - - /// \brief Describes the various kinds of blocks that occur within - /// an AST file. - enum BlockIDs { - /// \brief The AST block, which acts as a container around the - /// full AST block. - AST_BLOCK_ID = llvm::bitc::FIRST_APPLICATION_BLOCKID, - - /// \brief The block containing information about the source - /// manager. - SOURCE_MANAGER_BLOCK_ID, - - /// \brief The block containing information about the - /// preprocessor. - PREPROCESSOR_BLOCK_ID, - - /// \brief The block containing the definitions of all of the - /// types and decls used within the AST file. - DECLTYPES_BLOCK_ID, - - /// \brief The block containing DECL_UPDATES records. - DECL_UPDATES_BLOCK_ID, - - /// \brief The block containing the detailed preprocessing record. - PREPROCESSOR_DETAIL_BLOCK_ID, - - /// \brief The block containing the submodule structure. - SUBMODULE_BLOCK_ID, - - /// \brief The block containing comments. - COMMENTS_BLOCK_ID, - - /// \brief The control block, which contains all of the - /// information that needs to be validated prior to committing - /// to loading the AST file. - CONTROL_BLOCK_ID, - - /// \brief The block of input files, which were used as inputs - /// to create this AST file. - /// - /// This block is part of the control block. - INPUT_FILES_BLOCK_ID - }; - - /// \brief Record types that occur within the control block. - enum ControlRecordTypes { - /// \brief AST file metadata, including the AST file version number - /// and information about the compiler used to build this AST file. - METADATA = 1, - - /// \brief Record code for the list of other AST files imported by - /// this AST file. - IMPORTS = 2, - - /// \brief Record code for the language options table. - /// - /// The record with this code contains the contents of the - /// LangOptions structure. We serialize the entire contents of - /// the structure, and let the reader decide which options are - /// actually important to check. - LANGUAGE_OPTIONS = 3, - - /// \brief Record code for the target options table. - TARGET_OPTIONS = 4, - - /// \brief Record code for the original file that was used to - /// generate the AST file, including both its file ID and its - /// name. - ORIGINAL_FILE = 5, - - /// \brief The directory that the PCH was originally created in. - ORIGINAL_PCH_DIR = 6, - - /// \brief Record code for file ID of the file or buffer that was used to - /// generate the AST file. - ORIGINAL_FILE_ID = 7, - - /// \brief Offsets into the input-files block where input files - /// reside. - INPUT_FILE_OFFSETS = 8, - - /// \brief Record code for the diagnostic options table. - DIAGNOSTIC_OPTIONS = 9, - - /// \brief Record code for the filesystem options table. - FILE_SYSTEM_OPTIONS = 10, - - /// \brief Record code for the headers search options table. - HEADER_SEARCH_OPTIONS = 11, - - /// \brief Record code for the preprocessor options table. - PREPROCESSOR_OPTIONS = 12 - }; - - /// \brief Record types that occur within the input-files block - /// inside the control block. - enum InputFileRecordTypes { - /// \brief An input file. - INPUT_FILE = 1 - }; - - /// \brief Record types that occur within the AST block itself. - enum ASTRecordTypes { - /// \brief Record code for the offsets of each type. - /// - /// The TYPE_OFFSET constant describes the record that occurs - /// within the AST block. The record itself is an array of offsets that - /// point into the declarations and types block (identified by - /// DECLTYPES_BLOCK_ID). The index into the array is based on the ID - /// of a type. For a given type ID @c T, the lower three bits of - /// @c T are its qualifiers (const, volatile, restrict), as in - /// the QualType class. The upper bits, after being shifted and - /// subtracting NUM_PREDEF_TYPE_IDS, are used to index into the - /// TYPE_OFFSET block to determine the offset of that type's - /// corresponding record within the DECLTYPES_BLOCK_ID block. - TYPE_OFFSET = 1, - - /// \brief Record code for the offsets of each decl. - /// - /// The DECL_OFFSET constant describes the record that occurs - /// within the block identified by DECL_OFFSETS_BLOCK_ID within - /// the AST block. The record itself is an array of offsets that - /// point into the declarations and types block (identified by - /// DECLTYPES_BLOCK_ID). The declaration ID is an index into this - /// record, after subtracting one to account for the use of - /// declaration ID 0 for a NULL declaration pointer. Index 0 is - /// reserved for the translation unit declaration. - DECL_OFFSET = 2, - - /// \brief Record code for the table of offsets of each - /// identifier ID. - /// - /// The offset table contains offsets into the blob stored in - /// the IDENTIFIER_TABLE record. Each offset points to the - /// NULL-terminated string that corresponds to that identifier. - IDENTIFIER_OFFSET = 3, - - /// \brief This is so that older clang versions, before the introduction - /// of the control block, can read and reject the newer PCH format. - /// *DON"T CHANGE THIS NUMBER*. - METADATA_OLD_FORMAT = 4, - - /// \brief Record code for the identifier table. - /// - /// The identifier table is a simple blob that contains - /// NULL-terminated strings for all of the identifiers - /// referenced by the AST file. The IDENTIFIER_OFFSET table - /// contains the mapping from identifier IDs to the characters - /// in this blob. Note that the starting offsets of all of the - /// identifiers are odd, so that, when the identifier offset - /// table is loaded in, we can use the low bit to distinguish - /// between offsets (for unresolved identifier IDs) and - /// IdentifierInfo pointers (for already-resolved identifier - /// IDs). - IDENTIFIER_TABLE = 5, - - /// \brief Record code for the array of external definitions. - /// - /// The AST file contains a list of all of the unnamed external - /// definitions present within the parsed headers, stored as an - /// array of declaration IDs. These external definitions will be - /// reported to the AST consumer after the AST file has been - /// read, since their presence can affect the semantics of the - /// program (e.g., for code generation). - EXTERNAL_DEFINITIONS = 6, - - /// \brief Record code for the set of non-builtin, special - /// types. - /// - /// This record contains the type IDs for the various type nodes - /// that are constructed during semantic analysis (e.g., - /// __builtin_va_list). The SPECIAL_TYPE_* constants provide - /// offsets into this record. - SPECIAL_TYPES = 7, - - /// \brief Record code for the extra statistics we gather while - /// generating an AST file. - STATISTICS = 8, - - /// \brief Record code for the array of tentative definitions. - TENTATIVE_DEFINITIONS = 9, - - /// \brief Record code for the array of locally-scoped external - /// declarations. - LOCALLY_SCOPED_EXTERNAL_DECLS = 10, - - /// \brief Record code for the table of offsets into the - /// Objective-C method pool. - SELECTOR_OFFSETS = 11, - - /// \brief Record code for the Objective-C method pool, - METHOD_POOL = 12, - - /// \brief The value of the next __COUNTER__ to dispense. - /// [PP_COUNTER_VALUE, Val] - PP_COUNTER_VALUE = 13, - - /// \brief Record code for the table of offsets into the block - /// of source-location information. - SOURCE_LOCATION_OFFSETS = 14, - - /// \brief Record code for the set of source location entries - /// that need to be preloaded by the AST reader. - /// - /// This set contains the source location entry for the - /// predefines buffer and for any file entries that need to be - /// preloaded. - SOURCE_LOCATION_PRELOADS = 15, - - /// \brief Record code for the set of ext_vector type names. - EXT_VECTOR_DECLS = 16, - - /// \brief Record code for the array of unused file scoped decls. - UNUSED_FILESCOPED_DECLS = 17, - - /// \brief Record code for the table of offsets to entries in the - /// preprocessing record. - PPD_ENTITIES_OFFSETS = 18, - - /// \brief Record code for the array of VTable uses. - VTABLE_USES = 19, - - /// \brief Record code for the array of dynamic classes. - DYNAMIC_CLASSES = 20, - - /// \brief Record code for referenced selector pool. - REFERENCED_SELECTOR_POOL = 21, - - /// \brief Record code for an update to the TU's lexically contained - /// declarations. - TU_UPDATE_LEXICAL = 22, - - /// \brief Record code for the array describing the locations (in the - /// LOCAL_REDECLARATIONS record) of the redeclaration chains, indexed by - /// the first known ID. - LOCAL_REDECLARATIONS_MAP = 23, - - /// \brief Record code for declarations that Sema keeps references of. - SEMA_DECL_REFS = 24, - - /// \brief Record code for weak undeclared identifiers. - WEAK_UNDECLARED_IDENTIFIERS = 25, - - /// \brief Record code for pending implicit instantiations. - PENDING_IMPLICIT_INSTANTIATIONS = 26, - - /// \brief Record code for a decl replacement block. - /// - /// If a declaration is modified after having been deserialized, and then - /// written to a dependent AST file, its ID and offset must be added to - /// the replacement block. - DECL_REPLACEMENTS = 27, - - /// \brief Record code for an update to a decl context's lookup table. - /// - /// In practice, this should only be used for the TU and namespaces. - UPDATE_VISIBLE = 28, - - /// \brief Record for offsets of DECL_UPDATES records for declarations - /// that were modified after being deserialized and need updates. - DECL_UPDATE_OFFSETS = 29, - - /// \brief Record of updates for a declaration that was modified after - /// being deserialized. - DECL_UPDATES = 30, - - /// \brief Record code for the table of offsets to CXXBaseSpecifier - /// sets. - CXX_BASE_SPECIFIER_OFFSETS = 31, - - /// \brief Record code for \#pragma diagnostic mappings. - DIAG_PRAGMA_MAPPINGS = 32, - - /// \brief Record code for special CUDA declarations. - CUDA_SPECIAL_DECL_REFS = 33, - - /// \brief Record code for header search information. - HEADER_SEARCH_TABLE = 34, - - /// \brief Record code for floating point \#pragma options. - FP_PRAGMA_OPTIONS = 35, - - /// \brief Record code for enabled OpenCL extensions. - OPENCL_EXTENSIONS = 36, - - /// \brief The list of delegating constructor declarations. - DELEGATING_CTORS = 37, - - /// \brief Record code for the set of known namespaces, which are used - /// for typo correction. - KNOWN_NAMESPACES = 38, - - /// \brief Record code for the remapping information used to relate - /// loaded modules to the various offsets and IDs(e.g., source location - /// offests, declaration and type IDs) that are used in that module to - /// refer to other modules. - MODULE_OFFSET_MAP = 39, - - /// \brief Record code for the source manager line table information, - /// which stores information about \#line directives. - SOURCE_MANAGER_LINE_TABLE = 40, - - /// \brief Record code for map of Objective-C class definition IDs to the - /// ObjC categories in a module that are attached to that class. - OBJC_CATEGORIES_MAP = 41, - - /// \brief Record code for a file sorted array of DeclIDs in a module. - FILE_SORTED_DECLS = 42, - - /// \brief Record code for an array of all of the (sub)modules that were - /// imported by the AST file. - IMPORTED_MODULES = 43, - - /// \brief Record code for the set of merged declarations in an AST file. - MERGED_DECLARATIONS = 44, - - /// \brief Record code for the array of redeclaration chains. - /// - /// This array can only be interpreted properly using the local - /// redeclarations map. - LOCAL_REDECLARATIONS = 45, - - /// \brief Record code for the array of Objective-C categories (including - /// extensions). - /// - /// This array can only be interpreted properly using the Objective-C - /// categories map. - OBJC_CATEGORIES = 46, - - /// \brief Record code for the table of offsets of each macro ID. - /// - /// The offset table contains offsets into the blob stored in - /// the preprocessor block. Each offset points to the corresponding - /// macro definition. - MACRO_OFFSET = 47, - - /// \brief Record of updates for a macro that was modified after - /// being deserialized. - MACRO_UPDATES = 48 - }; - - /// \brief Record types used within a source manager block. - enum SourceManagerRecordTypes { - /// \brief Describes a source location entry (SLocEntry) for a - /// file. - SM_SLOC_FILE_ENTRY = 1, - /// \brief Describes a source location entry (SLocEntry) for a - /// buffer. - SM_SLOC_BUFFER_ENTRY = 2, - /// \brief Describes a blob that contains the data for a buffer - /// entry. This kind of record always directly follows a - /// SM_SLOC_BUFFER_ENTRY record or a SM_SLOC_FILE_ENTRY with an - /// overridden buffer. - SM_SLOC_BUFFER_BLOB = 3, - /// \brief Describes a source location entry (SLocEntry) for a - /// macro expansion. - SM_SLOC_EXPANSION_ENTRY = 4 - }; - - /// \brief Record types used within a preprocessor block. - enum PreprocessorRecordTypes { - // The macros in the PP section are a PP_MACRO_* instance followed by a - // list of PP_TOKEN instances for each token in the definition. - - /// \brief An object-like macro definition. - /// [PP_MACRO_OBJECT_LIKE, IdentInfoID, SLoc, IsUsed] - PP_MACRO_OBJECT_LIKE = 1, - - /// \brief A function-like macro definition. - /// [PP_MACRO_FUNCTION_LIKE, \, IsC99Varargs, - /// IsGNUVarars, NumArgs, ArgIdentInfoID* ] - PP_MACRO_FUNCTION_LIKE = 2, - - /// \brief Describes one token. - /// [PP_TOKEN, SLoc, Length, IdentInfoID, Kind, Flags] - PP_TOKEN = 3 - }; - - /// \brief Record types used within a preprocessor detail block. - enum PreprocessorDetailRecordTypes { - /// \brief Describes a macro expansion within the preprocessing record. - PPD_MACRO_EXPANSION = 0, - - /// \brief Describes a macro definition within the preprocessing record. - PPD_MACRO_DEFINITION = 1, - - /// \brief Describes an inclusion directive within the preprocessing - /// record. - PPD_INCLUSION_DIRECTIVE = 2 - }; - - /// \brief Record types used within a submodule description block. - enum SubmoduleRecordTypes { - /// \brief Metadata for submodules as a whole. - SUBMODULE_METADATA = 0, - /// \brief Defines the major attributes of a submodule, including its - /// name and parent. - SUBMODULE_DEFINITION = 1, - /// \brief Specifies the umbrella header used to create this module, - /// if any. - SUBMODULE_UMBRELLA_HEADER = 2, - /// \brief Specifies a header that falls into this (sub)module. - SUBMODULE_HEADER = 3, - /// \brief Specifies a top-level header that falls into this (sub)module. - SUBMODULE_TOPHEADER = 4, - /// \brief Specifies an umbrella directory. - SUBMODULE_UMBRELLA_DIR = 5, - /// \brief Specifies the submodules that are imported by this - /// submodule. - SUBMODULE_IMPORTS = 6, - /// \brief Specifies the submodules that are re-exported from this - /// submodule. - SUBMODULE_EXPORTS = 7, - /// \brief Specifies a required feature. - SUBMODULE_REQUIRES = 8, - /// \brief Specifies a header that has been explicitly excluded - /// from this submodule. - SUBMODULE_EXCLUDED_HEADER = 9 - }; - - /// \brief Record types used within a comments block. - enum CommentRecordTypes { - COMMENTS_RAW_COMMENT = 0 - }; - - /// \defgroup ASTAST AST file AST constants - /// - /// The constants in this group describe various components of the - /// abstract syntax tree within an AST file. - /// - /// @{ - - /// \brief Predefined type IDs. - /// - /// These type IDs correspond to predefined types in the AST - /// context, such as built-in types (int) and special place-holder - /// types (the \ and \ type markers). Such - /// types are never actually serialized, since they will be built - /// by the AST context when it is created. - enum PredefinedTypeIDs { - /// \brief The NULL type. - PREDEF_TYPE_NULL_ID = 0, - /// \brief The void type. - PREDEF_TYPE_VOID_ID = 1, - /// \brief The 'bool' or '_Bool' type. - PREDEF_TYPE_BOOL_ID = 2, - /// \brief The 'char' type, when it is unsigned. - PREDEF_TYPE_CHAR_U_ID = 3, - /// \brief The 'unsigned char' type. - PREDEF_TYPE_UCHAR_ID = 4, - /// \brief The 'unsigned short' type. - PREDEF_TYPE_USHORT_ID = 5, - /// \brief The 'unsigned int' type. - PREDEF_TYPE_UINT_ID = 6, - /// \brief The 'unsigned long' type. - PREDEF_TYPE_ULONG_ID = 7, - /// \brief The 'unsigned long long' type. - PREDEF_TYPE_ULONGLONG_ID = 8, - /// \brief The 'char' type, when it is signed. - PREDEF_TYPE_CHAR_S_ID = 9, - /// \brief The 'signed char' type. - PREDEF_TYPE_SCHAR_ID = 10, - /// \brief The C++ 'wchar_t' type. - PREDEF_TYPE_WCHAR_ID = 11, - /// \brief The (signed) 'short' type. - PREDEF_TYPE_SHORT_ID = 12, - /// \brief The (signed) 'int' type. - PREDEF_TYPE_INT_ID = 13, - /// \brief The (signed) 'long' type. - PREDEF_TYPE_LONG_ID = 14, - /// \brief The (signed) 'long long' type. - PREDEF_TYPE_LONGLONG_ID = 15, - /// \brief The 'float' type. - PREDEF_TYPE_FLOAT_ID = 16, - /// \brief The 'double' type. - PREDEF_TYPE_DOUBLE_ID = 17, - /// \brief The 'long double' type. - PREDEF_TYPE_LONGDOUBLE_ID = 18, - /// \brief The placeholder type for overloaded function sets. - PREDEF_TYPE_OVERLOAD_ID = 19, - /// \brief The placeholder type for dependent types. - PREDEF_TYPE_DEPENDENT_ID = 20, - /// \brief The '__uint128_t' type. - PREDEF_TYPE_UINT128_ID = 21, - /// \brief The '__int128_t' type. - PREDEF_TYPE_INT128_ID = 22, - /// \brief The type of 'nullptr'. - PREDEF_TYPE_NULLPTR_ID = 23, - /// \brief The C++ 'char16_t' type. - PREDEF_TYPE_CHAR16_ID = 24, - /// \brief The C++ 'char32_t' type. - PREDEF_TYPE_CHAR32_ID = 25, - /// \brief The ObjC 'id' type. - PREDEF_TYPE_OBJC_ID = 26, - /// \brief The ObjC 'Class' type. - PREDEF_TYPE_OBJC_CLASS = 27, - /// \brief The ObjC 'SEL' type. - PREDEF_TYPE_OBJC_SEL = 28, - /// \brief The 'unknown any' placeholder type. - PREDEF_TYPE_UNKNOWN_ANY = 29, - /// \brief The placeholder type for bound member functions. - PREDEF_TYPE_BOUND_MEMBER = 30, - /// \brief The "auto" deduction type. - PREDEF_TYPE_AUTO_DEDUCT = 31, - /// \brief The "auto &&" deduction type. - PREDEF_TYPE_AUTO_RREF_DEDUCT = 32, - /// \brief The OpenCL 'half' / ARM NEON __fp16 type. - PREDEF_TYPE_HALF_ID = 33, - /// \brief ARC's unbridged-cast placeholder type. - PREDEF_TYPE_ARC_UNBRIDGED_CAST = 34, - /// \brief The pseudo-object placeholder type. - PREDEF_TYPE_PSEUDO_OBJECT = 35, - /// \brief The __va_list_tag placeholder type. - PREDEF_TYPE_VA_LIST_TAG = 36, - /// \brief The placeholder type for builtin functions. - PREDEF_TYPE_BUILTIN_FN = 37 - }; - - /// \brief The number of predefined type IDs that are reserved for - /// the PREDEF_TYPE_* constants. - /// - /// Type IDs for non-predefined types will start at - /// NUM_PREDEF_TYPE_IDs. - const unsigned NUM_PREDEF_TYPE_IDS = 100; - - /// \brief The number of allowed abbreviations in bits - const unsigned NUM_ALLOWED_ABBREVS_SIZE = 4; - - /// \brief Record codes for each kind of type. - /// - /// These constants describe the type records that can occur within a - /// block identified by DECLTYPES_BLOCK_ID in the AST file. Each - /// constant describes a record for a specific type class in the - /// AST. - enum TypeCode { - /// \brief An ExtQualType record. - TYPE_EXT_QUAL = 1, - /// \brief A ComplexType record. - TYPE_COMPLEX = 3, - /// \brief A PointerType record. - TYPE_POINTER = 4, - /// \brief A BlockPointerType record. - TYPE_BLOCK_POINTER = 5, - /// \brief An LValueReferenceType record. - TYPE_LVALUE_REFERENCE = 6, - /// \brief An RValueReferenceType record. - TYPE_RVALUE_REFERENCE = 7, - /// \brief A MemberPointerType record. - TYPE_MEMBER_POINTER = 8, - /// \brief A ConstantArrayType record. - TYPE_CONSTANT_ARRAY = 9, - /// \brief An IncompleteArrayType record. - TYPE_INCOMPLETE_ARRAY = 10, - /// \brief A VariableArrayType record. - TYPE_VARIABLE_ARRAY = 11, - /// \brief A VectorType record. - TYPE_VECTOR = 12, - /// \brief An ExtVectorType record. - TYPE_EXT_VECTOR = 13, - /// \brief A FunctionNoProtoType record. - TYPE_FUNCTION_NO_PROTO = 14, - /// \brief A FunctionProtoType record. - TYPE_FUNCTION_PROTO = 15, - /// \brief A TypedefType record. - TYPE_TYPEDEF = 16, - /// \brief A TypeOfExprType record. - TYPE_TYPEOF_EXPR = 17, - /// \brief A TypeOfType record. - TYPE_TYPEOF = 18, - /// \brief A RecordType record. - TYPE_RECORD = 19, - /// \brief An EnumType record. - TYPE_ENUM = 20, - /// \brief An ObjCInterfaceType record. - TYPE_OBJC_INTERFACE = 21, - /// \brief An ObjCObjectPointerType record. - TYPE_OBJC_OBJECT_POINTER = 22, - /// \brief a DecltypeType record. - TYPE_DECLTYPE = 23, - /// \brief An ElaboratedType record. - TYPE_ELABORATED = 24, - /// \brief A SubstTemplateTypeParmType record. - TYPE_SUBST_TEMPLATE_TYPE_PARM = 25, - /// \brief An UnresolvedUsingType record. - TYPE_UNRESOLVED_USING = 26, - /// \brief An InjectedClassNameType record. - TYPE_INJECTED_CLASS_NAME = 27, - /// \brief An ObjCObjectType record. - TYPE_OBJC_OBJECT = 28, - /// \brief An TemplateTypeParmType record. - TYPE_TEMPLATE_TYPE_PARM = 29, - /// \brief An TemplateSpecializationType record. - TYPE_TEMPLATE_SPECIALIZATION = 30, - /// \brief A DependentNameType record. - TYPE_DEPENDENT_NAME = 31, - /// \brief A DependentTemplateSpecializationType record. - TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION = 32, - /// \brief A DependentSizedArrayType record. - TYPE_DEPENDENT_SIZED_ARRAY = 33, - /// \brief A ParenType record. - TYPE_PAREN = 34, - /// \brief A PackExpansionType record. - TYPE_PACK_EXPANSION = 35, - /// \brief An AttributedType record. - TYPE_ATTRIBUTED = 36, - /// \brief A SubstTemplateTypeParmPackType record. - TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK = 37, - /// \brief A AutoType record. - TYPE_AUTO = 38, - /// \brief A UnaryTransformType record. - TYPE_UNARY_TRANSFORM = 39, - /// \brief An AtomicType record. - TYPE_ATOMIC = 40 - }; - - /// \brief The type IDs for special types constructed by semantic - /// analysis. - /// - /// The constants in this enumeration are indices into the - /// SPECIAL_TYPES record. - enum SpecialTypeIDs { - /// \brief CFConstantString type - SPECIAL_TYPE_CF_CONSTANT_STRING = 0, - /// \brief C FILE typedef type - SPECIAL_TYPE_FILE = 1, - /// \brief C jmp_buf typedef type - SPECIAL_TYPE_JMP_BUF = 2, - /// \brief C sigjmp_buf typedef type - SPECIAL_TYPE_SIGJMP_BUF = 3, - /// \brief Objective-C "id" redefinition type - SPECIAL_TYPE_OBJC_ID_REDEFINITION = 4, - /// \brief Objective-C "Class" redefinition type - SPECIAL_TYPE_OBJC_CLASS_REDEFINITION = 5, - /// \brief Objective-C "SEL" redefinition type - SPECIAL_TYPE_OBJC_SEL_REDEFINITION = 6, - /// \brief C ucontext_t typedef type - SPECIAL_TYPE_UCONTEXT_T = 7 - }; - - /// \brief The number of special type IDs. - const unsigned NumSpecialTypeIDs = 8; - - /// \brief Predefined declaration IDs. - /// - /// These declaration IDs correspond to predefined declarations in the AST - /// context, such as the NULL declaration ID. Such declarations are never - /// actually serialized, since they will be built by the AST context when - /// it is created. - enum PredefinedDeclIDs { - /// \brief The NULL declaration. - PREDEF_DECL_NULL_ID = 0, - - /// \brief The translation unit. - PREDEF_DECL_TRANSLATION_UNIT_ID = 1, - - /// \brief The Objective-C 'id' type. - PREDEF_DECL_OBJC_ID_ID = 2, - - /// \brief The Objective-C 'SEL' type. - PREDEF_DECL_OBJC_SEL_ID = 3, - - /// \brief The Objective-C 'Class' type. - PREDEF_DECL_OBJC_CLASS_ID = 4, - - /// \brief The Objective-C 'Protocol' type. - PREDEF_DECL_OBJC_PROTOCOL_ID = 5, - - /// \brief The signed 128-bit integer type. - PREDEF_DECL_INT_128_ID = 6, - - /// \brief The unsigned 128-bit integer type. - PREDEF_DECL_UNSIGNED_INT_128_ID = 7, - - /// \brief The internal 'instancetype' typedef. - PREDEF_DECL_OBJC_INSTANCETYPE_ID = 8, - - /// \brief The internal '__builtin_va_list' typedef. - PREDEF_DECL_BUILTIN_VA_LIST_ID = 9 - }; - - /// \brief The number of declaration IDs that are predefined. - /// - /// For more information about predefined declarations, see the - /// \c PredefinedDeclIDs type and the PREDEF_DECL_*_ID constants. - const unsigned int NUM_PREDEF_DECL_IDS = 10; - - /// \brief Record codes for each kind of declaration. - /// - /// These constants describe the declaration records that can occur within - /// a declarations block (identified by DECLS_BLOCK_ID). Each - /// constant describes a record for a specific declaration class - /// in the AST. - enum DeclCode { - /// \brief A TypedefDecl record. - DECL_TYPEDEF = 51, - /// \brief A TypeAliasDecl record. - DECL_TYPEALIAS, - /// \brief An EnumDecl record. - DECL_ENUM, - /// \brief A RecordDecl record. - DECL_RECORD, - /// \brief An EnumConstantDecl record. - DECL_ENUM_CONSTANT, - /// \brief A FunctionDecl record. - DECL_FUNCTION, - /// \brief A ObjCMethodDecl record. - DECL_OBJC_METHOD, - /// \brief A ObjCInterfaceDecl record. - DECL_OBJC_INTERFACE, - /// \brief A ObjCProtocolDecl record. - DECL_OBJC_PROTOCOL, - /// \brief A ObjCIvarDecl record. - DECL_OBJC_IVAR, - /// \brief A ObjCAtDefsFieldDecl record. - DECL_OBJC_AT_DEFS_FIELD, - /// \brief A ObjCCategoryDecl record. - DECL_OBJC_CATEGORY, - /// \brief A ObjCCategoryImplDecl record. - DECL_OBJC_CATEGORY_IMPL, - /// \brief A ObjCImplementationDecl record. - DECL_OBJC_IMPLEMENTATION, - /// \brief A ObjCCompatibleAliasDecl record. - DECL_OBJC_COMPATIBLE_ALIAS, - /// \brief A ObjCPropertyDecl record. - DECL_OBJC_PROPERTY, - /// \brief A ObjCPropertyImplDecl record. - DECL_OBJC_PROPERTY_IMPL, - /// \brief A FieldDecl record. - DECL_FIELD, - /// \brief A VarDecl record. - DECL_VAR, - /// \brief An ImplicitParamDecl record. - DECL_IMPLICIT_PARAM, - /// \brief A ParmVarDecl record. - DECL_PARM_VAR, - /// \brief A FileScopeAsmDecl record. - DECL_FILE_SCOPE_ASM, - /// \brief A BlockDecl record. - DECL_BLOCK, - /// \brief A record that stores the set of declarations that are - /// lexically stored within a given DeclContext. - /// - /// The record itself is a blob that is an array of declaration IDs, - /// in the order in which those declarations were added to the - /// declaration context. This data is used when iterating over - /// the contents of a DeclContext, e.g., via - /// DeclContext::decls_begin() and DeclContext::decls_end(). - DECL_CONTEXT_LEXICAL, - /// \brief A record that stores the set of declarations that are - /// visible from a given DeclContext. - /// - /// The record itself stores a set of mappings, each of which - /// associates a declaration name with one or more declaration - /// IDs. This data is used when performing qualified name lookup - /// into a DeclContext via DeclContext::lookup. - DECL_CONTEXT_VISIBLE, - /// \brief A LabelDecl record. - DECL_LABEL, - /// \brief A NamespaceDecl record. - DECL_NAMESPACE, - /// \brief A NamespaceAliasDecl record. - DECL_NAMESPACE_ALIAS, - /// \brief A UsingDecl record. - DECL_USING, - /// \brief A UsingShadowDecl record. - DECL_USING_SHADOW, - /// \brief A UsingDirecitveDecl record. - DECL_USING_DIRECTIVE, - /// \brief An UnresolvedUsingValueDecl record. - DECL_UNRESOLVED_USING_VALUE, - /// \brief An UnresolvedUsingTypenameDecl record. - DECL_UNRESOLVED_USING_TYPENAME, - /// \brief A LinkageSpecDecl record. - DECL_LINKAGE_SPEC, - /// \brief A CXXRecordDecl record. - DECL_CXX_RECORD, - /// \brief A CXXMethodDecl record. - DECL_CXX_METHOD, - /// \brief A CXXConstructorDecl record. - DECL_CXX_CONSTRUCTOR, - /// \brief A CXXDestructorDecl record. - DECL_CXX_DESTRUCTOR, - /// \brief A CXXConversionDecl record. - DECL_CXX_CONVERSION, - /// \brief An AccessSpecDecl record. - DECL_ACCESS_SPEC, - - /// \brief A FriendDecl record. - DECL_FRIEND, - /// \brief A FriendTemplateDecl record. - DECL_FRIEND_TEMPLATE, - /// \brief A ClassTemplateDecl record. - DECL_CLASS_TEMPLATE, - /// \brief A ClassTemplateSpecializationDecl record. - DECL_CLASS_TEMPLATE_SPECIALIZATION, - /// \brief A ClassTemplatePartialSpecializationDecl record. - DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION, - /// \brief A FunctionTemplateDecl record. - DECL_FUNCTION_TEMPLATE, - /// \brief A TemplateTypeParmDecl record. - DECL_TEMPLATE_TYPE_PARM, - /// \brief A NonTypeTemplateParmDecl record. - DECL_NON_TYPE_TEMPLATE_PARM, - /// \brief A TemplateTemplateParmDecl record. - DECL_TEMPLATE_TEMPLATE_PARM, - /// \brief A TypeAliasTemplateDecl record. - DECL_TYPE_ALIAS_TEMPLATE, - /// \brief A StaticAssertDecl record. - DECL_STATIC_ASSERT, - /// \brief A record containing CXXBaseSpecifiers. - DECL_CXX_BASE_SPECIFIERS, - /// \brief A IndirectFieldDecl record. - DECL_INDIRECTFIELD, - /// \brief A NonTypeTemplateParmDecl record that stores an expanded - /// non-type template parameter pack. - DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK, - /// \brief A TemplateTemplateParmDecl record that stores an expanded - /// template template parameter pack. - DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK, - /// \brief A ClassScopeFunctionSpecializationDecl record a class scope - /// function specialization. (Microsoft extension). - DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION, - /// \brief An ImportDecl recording a module import. - DECL_IMPORT - }; - - /// \brief Record codes for each kind of statement or expression. - /// - /// These constants describe the records that describe statements - /// or expressions. These records occur within type and declarations - /// block, so they begin with record values of 100. Each constant - /// describes a record for a specific statement or expression class in the - /// AST. - enum StmtCode { - /// \brief A marker record that indicates that we are at the end - /// of an expression. - STMT_STOP = 100, - /// \brief A NULL expression. - STMT_NULL_PTR, - /// \brief A reference to a previously [de]serialized Stmt record. - STMT_REF_PTR, - /// \brief A NullStmt record. - STMT_NULL, - /// \brief A CompoundStmt record. - STMT_COMPOUND, - /// \brief A CaseStmt record. - STMT_CASE, - /// \brief A DefaultStmt record. - STMT_DEFAULT, - /// \brief A LabelStmt record. - STMT_LABEL, - /// \brief An AttributedStmt record. - STMT_ATTRIBUTED, - /// \brief An IfStmt record. - STMT_IF, - /// \brief A SwitchStmt record. - STMT_SWITCH, - /// \brief A WhileStmt record. - STMT_WHILE, - /// \brief A DoStmt record. - STMT_DO, - /// \brief A ForStmt record. - STMT_FOR, - /// \brief A GotoStmt record. - STMT_GOTO, - /// \brief An IndirectGotoStmt record. - STMT_INDIRECT_GOTO, - /// \brief A ContinueStmt record. - STMT_CONTINUE, - /// \brief A BreakStmt record. - STMT_BREAK, - /// \brief A ReturnStmt record. - STMT_RETURN, - /// \brief A DeclStmt record. - STMT_DECL, - /// \brief A GCC-style AsmStmt record. - STMT_GCCASM, - /// \brief A MS-style AsmStmt record. - STMT_MSASM, - /// \brief A PredefinedExpr record. - EXPR_PREDEFINED, - /// \brief A DeclRefExpr record. - EXPR_DECL_REF, - /// \brief An IntegerLiteral record. - EXPR_INTEGER_LITERAL, - /// \brief A FloatingLiteral record. - EXPR_FLOATING_LITERAL, - /// \brief An ImaginaryLiteral record. - EXPR_IMAGINARY_LITERAL, - /// \brief A StringLiteral record. - EXPR_STRING_LITERAL, - /// \brief A CharacterLiteral record. - EXPR_CHARACTER_LITERAL, - /// \brief A ParenExpr record. - EXPR_PAREN, - /// \brief A ParenListExpr record. - EXPR_PAREN_LIST, - /// \brief A UnaryOperator record. - EXPR_UNARY_OPERATOR, - /// \brief An OffsetOfExpr record. - EXPR_OFFSETOF, - /// \brief A SizefAlignOfExpr record. - EXPR_SIZEOF_ALIGN_OF, - /// \brief An ArraySubscriptExpr record. - EXPR_ARRAY_SUBSCRIPT, - /// \brief A CallExpr record. - EXPR_CALL, - /// \brief A MemberExpr record. - EXPR_MEMBER, - /// \brief A BinaryOperator record. - EXPR_BINARY_OPERATOR, - /// \brief A CompoundAssignOperator record. - EXPR_COMPOUND_ASSIGN_OPERATOR, - /// \brief A ConditionOperator record. - EXPR_CONDITIONAL_OPERATOR, - /// \brief An ImplicitCastExpr record. - EXPR_IMPLICIT_CAST, - /// \brief A CStyleCastExpr record. - EXPR_CSTYLE_CAST, - /// \brief A CompoundLiteralExpr record. - EXPR_COMPOUND_LITERAL, - /// \brief An ExtVectorElementExpr record. - EXPR_EXT_VECTOR_ELEMENT, - /// \brief An InitListExpr record. - EXPR_INIT_LIST, - /// \brief A DesignatedInitExpr record. - EXPR_DESIGNATED_INIT, - /// \brief An ImplicitValueInitExpr record. - EXPR_IMPLICIT_VALUE_INIT, - /// \brief A VAArgExpr record. - EXPR_VA_ARG, - /// \brief An AddrLabelExpr record. - EXPR_ADDR_LABEL, - /// \brief A StmtExpr record. - EXPR_STMT, - /// \brief A ChooseExpr record. - EXPR_CHOOSE, - /// \brief A GNUNullExpr record. - EXPR_GNU_NULL, - /// \brief A ShuffleVectorExpr record. - EXPR_SHUFFLE_VECTOR, - /// \brief BlockExpr - EXPR_BLOCK, - /// \brief A GenericSelectionExpr record. - EXPR_GENERIC_SELECTION, - /// \brief A PseudoObjectExpr record. - EXPR_PSEUDO_OBJECT, - /// \brief An AtomicExpr record. - EXPR_ATOMIC, - - // Objective-C - - /// \brief An ObjCStringLiteral record. - EXPR_OBJC_STRING_LITERAL, - - EXPR_OBJC_BOXED_EXPRESSION, - EXPR_OBJC_ARRAY_LITERAL, - EXPR_OBJC_DICTIONARY_LITERAL, - - - /// \brief An ObjCEncodeExpr record. - EXPR_OBJC_ENCODE, - /// \brief An ObjCSelectorExpr record. - EXPR_OBJC_SELECTOR_EXPR, - /// \brief An ObjCProtocolExpr record. - EXPR_OBJC_PROTOCOL_EXPR, - /// \brief An ObjCIvarRefExpr record. - EXPR_OBJC_IVAR_REF_EXPR, - /// \brief An ObjCPropertyRefExpr record. - EXPR_OBJC_PROPERTY_REF_EXPR, - /// \brief An ObjCSubscriptRefExpr record. - EXPR_OBJC_SUBSCRIPT_REF_EXPR, - /// \brief UNUSED - EXPR_OBJC_KVC_REF_EXPR, - /// \brief An ObjCMessageExpr record. - EXPR_OBJC_MESSAGE_EXPR, - /// \brief An ObjCIsa Expr record. - EXPR_OBJC_ISA, - /// \brief An ObjCIndirectCopyRestoreExpr record. - EXPR_OBJC_INDIRECT_COPY_RESTORE, - - /// \brief An ObjCForCollectionStmt record. - STMT_OBJC_FOR_COLLECTION, - /// \brief An ObjCAtCatchStmt record. - STMT_OBJC_CATCH, - /// \brief An ObjCAtFinallyStmt record. - STMT_OBJC_FINALLY, - /// \brief An ObjCAtTryStmt record. - STMT_OBJC_AT_TRY, - /// \brief An ObjCAtSynchronizedStmt record. - STMT_OBJC_AT_SYNCHRONIZED, - /// \brief An ObjCAtThrowStmt record. - STMT_OBJC_AT_THROW, - /// \brief An ObjCAutoreleasePoolStmt record. - STMT_OBJC_AUTORELEASE_POOL, - /// \brief A ObjCBoolLiteralExpr record. - EXPR_OBJC_BOOL_LITERAL, - - // C++ - - /// \brief A CXXCatchStmt record. - STMT_CXX_CATCH, - /// \brief A CXXTryStmt record. - STMT_CXX_TRY, - /// \brief A CXXForRangeStmt record. - STMT_CXX_FOR_RANGE, - - /// \brief A CXXOperatorCallExpr record. - EXPR_CXX_OPERATOR_CALL, - /// \brief A CXXMemberCallExpr record. - EXPR_CXX_MEMBER_CALL, - /// \brief A CXXConstructExpr record. - EXPR_CXX_CONSTRUCT, - /// \brief A CXXTemporaryObjectExpr record. - EXPR_CXX_TEMPORARY_OBJECT, - /// \brief A CXXStaticCastExpr record. - EXPR_CXX_STATIC_CAST, - /// \brief A CXXDynamicCastExpr record. - EXPR_CXX_DYNAMIC_CAST, - /// \brief A CXXReinterpretCastExpr record. - EXPR_CXX_REINTERPRET_CAST, - /// \brief A CXXConstCastExpr record. - EXPR_CXX_CONST_CAST, - /// \brief A CXXFunctionalCastExpr record. - EXPR_CXX_FUNCTIONAL_CAST, - /// \brief A UserDefinedLiteral record. - EXPR_USER_DEFINED_LITERAL, - /// \brief A CXXBoolLiteralExpr record. - EXPR_CXX_BOOL_LITERAL, - EXPR_CXX_NULL_PTR_LITERAL, // CXXNullPtrLiteralExpr - EXPR_CXX_TYPEID_EXPR, // CXXTypeidExpr (of expr). - EXPR_CXX_TYPEID_TYPE, // CXXTypeidExpr (of type). - EXPR_CXX_THIS, // CXXThisExpr - EXPR_CXX_THROW, // CXXThrowExpr - EXPR_CXX_DEFAULT_ARG, // CXXDefaultArgExpr - EXPR_CXX_BIND_TEMPORARY, // CXXBindTemporaryExpr - - EXPR_CXX_SCALAR_VALUE_INIT, // CXXScalarValueInitExpr - EXPR_CXX_NEW, // CXXNewExpr - EXPR_CXX_DELETE, // CXXDeleteExpr - EXPR_CXX_PSEUDO_DESTRUCTOR, // CXXPseudoDestructorExpr - - EXPR_EXPR_WITH_CLEANUPS, // ExprWithCleanups - - EXPR_CXX_DEPENDENT_SCOPE_MEMBER, // CXXDependentScopeMemberExpr - EXPR_CXX_DEPENDENT_SCOPE_DECL_REF, // DependentScopeDeclRefExpr - EXPR_CXX_UNRESOLVED_CONSTRUCT, // CXXUnresolvedConstructExpr - EXPR_CXX_UNRESOLVED_MEMBER, // UnresolvedMemberExpr - EXPR_CXX_UNRESOLVED_LOOKUP, // UnresolvedLookupExpr - - EXPR_CXX_UNARY_TYPE_TRAIT, // UnaryTypeTraitExpr - EXPR_CXX_EXPRESSION_TRAIT, // ExpressionTraitExpr - EXPR_CXX_NOEXCEPT, // CXXNoexceptExpr - - EXPR_OPAQUE_VALUE, // OpaqueValueExpr - EXPR_BINARY_CONDITIONAL_OPERATOR, // BinaryConditionalOperator - EXPR_BINARY_TYPE_TRAIT, // BinaryTypeTraitExpr - EXPR_TYPE_TRAIT, // TypeTraitExpr - EXPR_ARRAY_TYPE_TRAIT, // ArrayTypeTraitIntExpr - - EXPR_PACK_EXPANSION, // PackExpansionExpr - EXPR_SIZEOF_PACK, // SizeOfPackExpr - EXPR_SUBST_NON_TYPE_TEMPLATE_PARM, // SubstNonTypeTemplateParmExpr - EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK,// SubstNonTypeTemplateParmPackExpr - EXPR_FUNCTION_PARM_PACK, // FunctionParmPackExpr - EXPR_MATERIALIZE_TEMPORARY, // MaterializeTemporaryExpr - - // CUDA - EXPR_CUDA_KERNEL_CALL, // CUDAKernelCallExpr - - // OpenCL - EXPR_ASTYPE, // AsTypeExpr - - // Microsoft - EXPR_CXX_UUIDOF_EXPR, // CXXUuidofExpr (of expr). - EXPR_CXX_UUIDOF_TYPE, // CXXUuidofExpr (of type). - STMT_SEH_EXCEPT, // SEHExceptStmt - STMT_SEH_FINALLY, // SEHFinallyStmt - STMT_SEH_TRY, // SEHTryStmt - - // ARC - EXPR_OBJC_BRIDGED_CAST, // ObjCBridgedCastExpr - - STMT_MS_DEPENDENT_EXISTS, // MSDependentExistsStmt - EXPR_LAMBDA // LambdaExpr - }; - - /// \brief The kinds of designators that can occur in a - /// DesignatedInitExpr. - enum DesignatorTypes { - /// \brief Field designator where only the field name is known. - DESIG_FIELD_NAME = 0, - /// \brief Field designator where the field has been resolved to - /// a declaration. - DESIG_FIELD_DECL = 1, - /// \brief Array designator. - DESIG_ARRAY = 2, - /// \brief GNU array range designator. - DESIG_ARRAY_RANGE = 3 - }; - - /// \brief The different kinds of data that can occur in a - /// CtorInitializer. - enum CtorInitializerType { - CTOR_INITIALIZER_BASE, - CTOR_INITIALIZER_DELEGATING, - CTOR_INITIALIZER_MEMBER, - CTOR_INITIALIZER_INDIRECT_MEMBER - }; - - /// \brief Describes the redeclarations of a declaration. - struct LocalRedeclarationsInfo { - DeclID FirstID; // The ID of the first declaration - unsigned Offset; // Offset into the array of redeclaration chains. - - friend bool operator<(const LocalRedeclarationsInfo &X, - const LocalRedeclarationsInfo &Y) { - return X.FirstID < Y.FirstID; - } - - friend bool operator>(const LocalRedeclarationsInfo &X, - const LocalRedeclarationsInfo &Y) { - return X.FirstID > Y.FirstID; - } - - friend bool operator<=(const LocalRedeclarationsInfo &X, - const LocalRedeclarationsInfo &Y) { - return X.FirstID <= Y.FirstID; - } - - friend bool operator>=(const LocalRedeclarationsInfo &X, - const LocalRedeclarationsInfo &Y) { - return X.FirstID >= Y.FirstID; - } - }; - - /// \brief Describes the categories of an Objective-C class. - struct ObjCCategoriesInfo { - DeclID DefinitionID; // The ID of the definition - unsigned Offset; // Offset into the array of category lists. - - friend bool operator<(const ObjCCategoriesInfo &X, - const ObjCCategoriesInfo &Y) { - return X.DefinitionID < Y.DefinitionID; - } - - friend bool operator>(const ObjCCategoriesInfo &X, - const ObjCCategoriesInfo &Y) { - return X.DefinitionID > Y.DefinitionID; - } - - friend bool operator<=(const ObjCCategoriesInfo &X, - const ObjCCategoriesInfo &Y) { - return X.DefinitionID <= Y.DefinitionID; - } - - friend bool operator>=(const ObjCCategoriesInfo &X, - const ObjCCategoriesInfo &Y) { - return X.DefinitionID >= Y.DefinitionID; - } - }; - - /// @} - } -} // end namespace clang - -#endif +//===- ASTBitCodes.h - Enum values for the PCH bitcode format ---*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This header defines Bitcode enum values for Clang serialized AST files. +// +// The enum values defined in this file should be considered permanent. If +// new features are added, they should have values added at the end of the +// respective lists. +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_CLANG_FRONTEND_PCHBITCODES_H +#define LLVM_CLANG_FRONTEND_PCHBITCODES_H + +#include "clang/AST/Type.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/Bitcode/BitCodes.h" +#include "llvm/Support/DataTypes.h" + +namespace clang { + namespace serialization { + /// \brief AST file major version number supported by this version of + /// Clang. + /// + /// Whenever the AST file format changes in a way that makes it + /// incompatible with previous versions (such that a reader + /// designed for the previous version could not support reading + /// the new version), this number should be increased. + /// + /// Version 4 of AST files also requires that the version control branch and + /// revision match exactly, since there is no backward compatibility of + /// AST files at this time. + const unsigned VERSION_MAJOR = 5; + + /// \brief AST file minor version number supported by this version of + /// Clang. + /// + /// Whenever the AST format changes in a way that is still + /// compatible with previous versions (such that a reader designed + /// for the previous version could still support reading the new + /// version by ignoring new kinds of subblocks), this number + /// should be increased. + const unsigned VERSION_MINOR = 0; + + /// \brief An ID number that refers to an identifier in an AST file. + /// + /// The ID numbers of identifiers are consecutive (in order of discovery) + /// and start at 1. 0 is reserved for NULL. + typedef uint32_t IdentifierID; + + /// \brief An ID number that refers to a declaration in an AST file. + /// + /// The ID numbers of declarations are consecutive (in order of + /// discovery), with values below NUM_PREDEF_DECL_IDS being reserved. + /// At the start of a chain of precompiled headers, declaration ID 1 is + /// used for the translation unit declaration. + typedef uint32_t DeclID; + + /// \brief a Decl::Kind/DeclID pair. + typedef std::pair KindDeclIDPair; + + // FIXME: Turn these into classes so we can have some type safety when + // we go from local ID to global and vice-versa. + typedef DeclID LocalDeclID; + typedef DeclID GlobalDeclID; + + /// \brief An ID number that refers to a type in an AST file. + /// + /// The ID of a type is partitioned into two parts: the lower + /// three bits are used to store the const/volatile/restrict + /// qualifiers (as with QualType) and the upper bits provide a + /// type index. The type index values are partitioned into two + /// sets. The values below NUM_PREDEF_TYPE_IDs are predefined type + /// IDs (based on the PREDEF_TYPE_*_ID constants), with 0 as a + /// placeholder for "no type". Values from NUM_PREDEF_TYPE_IDs are + /// other types that have serialized representations. + typedef uint32_t TypeID; + + /// \brief A type index; the type ID with the qualifier bits removed. + class TypeIdx { + uint32_t Idx; + public: + TypeIdx() : Idx(0) { } + explicit TypeIdx(uint32_t index) : Idx(index) { } + + uint32_t getIndex() const { return Idx; } + TypeID asTypeID(unsigned FastQuals) const { + if (Idx == uint32_t(-1)) + return TypeID(-1); + + return (Idx << Qualifiers::FastWidth) | FastQuals; + } + static TypeIdx fromTypeID(TypeID ID) { + if (ID == TypeID(-1)) + return TypeIdx(-1); + + return TypeIdx(ID >> Qualifiers::FastWidth); + } + }; + + /// A structure for putting "fast"-unqualified QualTypes into a + /// DenseMap. This uses the standard pointer hash function. + struct UnsafeQualTypeDenseMapInfo { + static inline bool isEqual(QualType A, QualType B) { return A == B; } + static inline QualType getEmptyKey() { + return QualType::getFromOpaquePtr((void*) 1); + } + static inline QualType getTombstoneKey() { + return QualType::getFromOpaquePtr((void*) 2); + } + static inline unsigned getHashValue(QualType T) { + assert(!T.getLocalFastQualifiers() && + "hash invalid for types with fast quals"); + uintptr_t v = reinterpret_cast(T.getAsOpaquePtr()); + return (unsigned(v) >> 4) ^ (unsigned(v) >> 9); + } + }; + + /// \brief An ID number that refers to an identifier in an AST file. + typedef uint32_t IdentID; + + /// \brief The number of predefined identifier IDs. + const unsigned int NUM_PREDEF_IDENT_IDS = 1; + + /// \brief An ID number that refers to a macro in an AST file. + typedef uint32_t MacroID; + + /// \brief The number of predefined macro IDs. + const unsigned int NUM_PREDEF_MACRO_IDS = 1; + + /// \brief An ID number that refers to an ObjC selector in an AST file. + typedef uint32_t SelectorID; + + /// \brief The number of predefined selector IDs. + const unsigned int NUM_PREDEF_SELECTOR_IDS = 1; + + /// \brief An ID number that refers to a set of CXXBaseSpecifiers in an + /// AST file. + typedef uint32_t CXXBaseSpecifiersID; + + /// \brief An ID number that refers to an entity in the detailed + /// preprocessing record. + typedef uint32_t PreprocessedEntityID; + + /// \brief An ID number that refers to a submodule in a module file. + typedef uint32_t SubmoduleID; + + /// \brief The number of predefined submodule IDs. + const unsigned int NUM_PREDEF_SUBMODULE_IDS = 1; + + /// \brief Source range/offset of a preprocessed entity. + struct PPEntityOffset { + /// \brief Raw source location of beginning of range. + unsigned Begin; + /// \brief Raw source location of end of range. + unsigned End; + /// \brief Offset in the AST file. + uint32_t BitOffset; + + PPEntityOffset(SourceRange R, uint32_t BitOffset) + : Begin(R.getBegin().getRawEncoding()), + End(R.getEnd().getRawEncoding()), + BitOffset(BitOffset) { } + }; + + /// \brief Source range/offset of a preprocessed entity. + struct DeclOffset { + /// \brief Raw source location. + unsigned Loc; + /// \brief Offset in the AST file. + uint32_t BitOffset; + + DeclOffset() : Loc(0), BitOffset(0) { } + DeclOffset(SourceLocation Loc, uint32_t BitOffset) + : Loc(Loc.getRawEncoding()), + BitOffset(BitOffset) { } + void setLocation(SourceLocation L) { + Loc = L.getRawEncoding(); + } + }; + + /// \brief The number of predefined preprocessed entity IDs. + const unsigned int NUM_PREDEF_PP_ENTITY_IDS = 1; + + /// \brief Describes the various kinds of blocks that occur within + /// an AST file. + enum BlockIDs { + /// \brief The AST block, which acts as a container around the + /// full AST block. + AST_BLOCK_ID = llvm::bitc::FIRST_APPLICATION_BLOCKID, + + /// \brief The block containing information about the source + /// manager. + SOURCE_MANAGER_BLOCK_ID, + + /// \brief The block containing information about the + /// preprocessor. + PREPROCESSOR_BLOCK_ID, + + /// \brief The block containing the definitions of all of the + /// types and decls used within the AST file. + DECLTYPES_BLOCK_ID, + + /// \brief The block containing DECL_UPDATES records. + DECL_UPDATES_BLOCK_ID, + + /// \brief The block containing the detailed preprocessing record. + PREPROCESSOR_DETAIL_BLOCK_ID, + + /// \brief The block containing the submodule structure. + SUBMODULE_BLOCK_ID, + + /// \brief The block containing comments. + COMMENTS_BLOCK_ID, + + /// \brief The control block, which contains all of the + /// information that needs to be validated prior to committing + /// to loading the AST file. + CONTROL_BLOCK_ID, + + /// \brief The block of input files, which were used as inputs + /// to create this AST file. + /// + /// This block is part of the control block. + INPUT_FILES_BLOCK_ID + }; + + /// \brief Record types that occur within the control block. + enum ControlRecordTypes { + /// \brief AST file metadata, including the AST file version number + /// and information about the compiler used to build this AST file. + METADATA = 1, + + /// \brief Record code for the list of other AST files imported by + /// this AST file. + IMPORTS = 2, + + /// \brief Record code for the language options table. + /// + /// The record with this code contains the contents of the + /// LangOptions structure. We serialize the entire contents of + /// the structure, and let the reader decide which options are + /// actually important to check. + LANGUAGE_OPTIONS = 3, + + /// \brief Record code for the target options table. + TARGET_OPTIONS = 4, + + /// \brief Record code for the original file that was used to + /// generate the AST file, including both its file ID and its + /// name. + ORIGINAL_FILE = 5, + + /// \brief The directory that the PCH was originally created in. + ORIGINAL_PCH_DIR = 6, + + /// \brief Record code for file ID of the file or buffer that was used to + /// generate the AST file. + ORIGINAL_FILE_ID = 7, + + /// \brief Offsets into the input-files block where input files + /// reside. + INPUT_FILE_OFFSETS = 8, + + /// \brief Record code for the diagnostic options table. + DIAGNOSTIC_OPTIONS = 9, + + /// \brief Record code for the filesystem options table. + FILE_SYSTEM_OPTIONS = 10, + + /// \brief Record code for the headers search options table. + HEADER_SEARCH_OPTIONS = 11, + + /// \brief Record code for the preprocessor options table. + PREPROCESSOR_OPTIONS = 12 + }; + + /// \brief Record types that occur within the input-files block + /// inside the control block. + enum InputFileRecordTypes { + /// \brief An input file. + INPUT_FILE = 1 + }; + + /// \brief Record types that occur within the AST block itself. + enum ASTRecordTypes { + /// \brief Record code for the offsets of each type. + /// + /// The TYPE_OFFSET constant describes the record that occurs + /// within the AST block. The record itself is an array of offsets that + /// point into the declarations and types block (identified by + /// DECLTYPES_BLOCK_ID). The index into the array is based on the ID + /// of a type. For a given type ID @c T, the lower three bits of + /// @c T are its qualifiers (const, volatile, restrict), as in + /// the QualType class. The upper bits, after being shifted and + /// subtracting NUM_PREDEF_TYPE_IDS, are used to index into the + /// TYPE_OFFSET block to determine the offset of that type's + /// corresponding record within the DECLTYPES_BLOCK_ID block. + TYPE_OFFSET = 1, + + /// \brief Record code for the offsets of each decl. + /// + /// The DECL_OFFSET constant describes the record that occurs + /// within the block identified by DECL_OFFSETS_BLOCK_ID within + /// the AST block. The record itself is an array of offsets that + /// point into the declarations and types block (identified by + /// DECLTYPES_BLOCK_ID). The declaration ID is an index into this + /// record, after subtracting one to account for the use of + /// declaration ID 0 for a NULL declaration pointer. Index 0 is + /// reserved for the translation unit declaration. + DECL_OFFSET = 2, + + /// \brief Record code for the table of offsets of each + /// identifier ID. + /// + /// The offset table contains offsets into the blob stored in + /// the IDENTIFIER_TABLE record. Each offset points to the + /// NULL-terminated string that corresponds to that identifier. + IDENTIFIER_OFFSET = 3, + + /// \brief This is so that older clang versions, before the introduction + /// of the control block, can read and reject the newer PCH format. + /// *DON"T CHANGE THIS NUMBER*. + METADATA_OLD_FORMAT = 4, + + /// \brief Record code for the identifier table. + /// + /// The identifier table is a simple blob that contains + /// NULL-terminated strings for all of the identifiers + /// referenced by the AST file. The IDENTIFIER_OFFSET table + /// contains the mapping from identifier IDs to the characters + /// in this blob. Note that the starting offsets of all of the + /// identifiers are odd, so that, when the identifier offset + /// table is loaded in, we can use the low bit to distinguish + /// between offsets (for unresolved identifier IDs) and + /// IdentifierInfo pointers (for already-resolved identifier + /// IDs). + IDENTIFIER_TABLE = 5, + + /// \brief Record code for the array of external definitions. + /// + /// The AST file contains a list of all of the unnamed external + /// definitions present within the parsed headers, stored as an + /// array of declaration IDs. These external definitions will be + /// reported to the AST consumer after the AST file has been + /// read, since their presence can affect the semantics of the + /// program (e.g., for code generation). + EXTERNAL_DEFINITIONS = 6, + + /// \brief Record code for the set of non-builtin, special + /// types. + /// + /// This record contains the type IDs for the various type nodes + /// that are constructed during semantic analysis (e.g., + /// __builtin_va_list). The SPECIAL_TYPE_* constants provide + /// offsets into this record. + SPECIAL_TYPES = 7, + + /// \brief Record code for the extra statistics we gather while + /// generating an AST file. + STATISTICS = 8, + + /// \brief Record code for the array of tentative definitions. + TENTATIVE_DEFINITIONS = 9, + + /// \brief Record code for the array of locally-scoped external + /// declarations. + LOCALLY_SCOPED_EXTERNAL_DECLS = 10, + + /// \brief Record code for the table of offsets into the + /// Objective-C method pool. + SELECTOR_OFFSETS = 11, + + /// \brief Record code for the Objective-C method pool, + METHOD_POOL = 12, + + /// \brief The value of the next __COUNTER__ to dispense. + /// [PP_COUNTER_VALUE, Val] + PP_COUNTER_VALUE = 13, + + /// \brief Record code for the table of offsets into the block + /// of source-location information. + SOURCE_LOCATION_OFFSETS = 14, + + /// \brief Record code for the set of source location entries + /// that need to be preloaded by the AST reader. + /// + /// This set contains the source location entry for the + /// predefines buffer and for any file entries that need to be + /// preloaded. + SOURCE_LOCATION_PRELOADS = 15, + + /// \brief Record code for the set of ext_vector type names. + EXT_VECTOR_DECLS = 16, + + /// \brief Record code for the array of unused file scoped decls. + UNUSED_FILESCOPED_DECLS = 17, + + /// \brief Record code for the table of offsets to entries in the + /// preprocessing record. + PPD_ENTITIES_OFFSETS = 18, + + /// \brief Record code for the array of VTable uses. + VTABLE_USES = 19, + + /// \brief Record code for the array of dynamic classes. + DYNAMIC_CLASSES = 20, + + /// \brief Record code for referenced selector pool. + REFERENCED_SELECTOR_POOL = 21, + + /// \brief Record code for an update to the TU's lexically contained + /// declarations. + TU_UPDATE_LEXICAL = 22, + + /// \brief Record code for the array describing the locations (in the + /// LOCAL_REDECLARATIONS record) of the redeclaration chains, indexed by + /// the first known ID. + LOCAL_REDECLARATIONS_MAP = 23, + + /// \brief Record code for declarations that Sema keeps references of. + SEMA_DECL_REFS = 24, + + /// \brief Record code for weak undeclared identifiers. + WEAK_UNDECLARED_IDENTIFIERS = 25, + + /// \brief Record code for pending implicit instantiations. + PENDING_IMPLICIT_INSTANTIATIONS = 26, + + /// \brief Record code for a decl replacement block. + /// + /// If a declaration is modified after having been deserialized, and then + /// written to a dependent AST file, its ID and offset must be added to + /// the replacement block. + DECL_REPLACEMENTS = 27, + + /// \brief Record code for an update to a decl context's lookup table. + /// + /// In practice, this should only be used for the TU and namespaces. + UPDATE_VISIBLE = 28, + + /// \brief Record for offsets of DECL_UPDATES records for declarations + /// that were modified after being deserialized and need updates. + DECL_UPDATE_OFFSETS = 29, + + /// \brief Record of updates for a declaration that was modified after + /// being deserialized. + DECL_UPDATES = 30, + + /// \brief Record code for the table of offsets to CXXBaseSpecifier + /// sets. + CXX_BASE_SPECIFIER_OFFSETS = 31, + + /// \brief Record code for \#pragma diagnostic mappings. + DIAG_PRAGMA_MAPPINGS = 32, + + /// \brief Record code for special CUDA declarations. + CUDA_SPECIAL_DECL_REFS = 33, + + /// \brief Record code for header search information. + HEADER_SEARCH_TABLE = 34, + + /// \brief Record code for floating point \#pragma options. + FP_PRAGMA_OPTIONS = 35, + + /// \brief Record code for enabled OpenCL extensions. + OPENCL_EXTENSIONS = 36, + + /// \brief The list of delegating constructor declarations. + DELEGATING_CTORS = 37, + + /// \brief Record code for the set of known namespaces, which are used + /// for typo correction. + KNOWN_NAMESPACES = 38, + + /// \brief Record code for the remapping information used to relate + /// loaded modules to the various offsets and IDs(e.g., source location + /// offests, declaration and type IDs) that are used in that module to + /// refer to other modules. + MODULE_OFFSET_MAP = 39, + + /// \brief Record code for the source manager line table information, + /// which stores information about \#line directives. + SOURCE_MANAGER_LINE_TABLE = 40, + + /// \brief Record code for map of Objective-C class definition IDs to the + /// ObjC categories in a module that are attached to that class. + OBJC_CATEGORIES_MAP = 41, + + /// \brief Record code for a file sorted array of DeclIDs in a module. + FILE_SORTED_DECLS = 42, + + /// \brief Record code for an array of all of the (sub)modules that were + /// imported by the AST file. + IMPORTED_MODULES = 43, + + /// \brief Record code for the set of merged declarations in an AST file. + MERGED_DECLARATIONS = 44, + + /// \brief Record code for the array of redeclaration chains. + /// + /// This array can only be interpreted properly using the local + /// redeclarations map. + LOCAL_REDECLARATIONS = 45, + + /// \brief Record code for the array of Objective-C categories (including + /// extensions). + /// + /// This array can only be interpreted properly using the Objective-C + /// categories map. + OBJC_CATEGORIES = 46, + + /// \brief Record code for the table of offsets of each macro ID. + /// + /// The offset table contains offsets into the blob stored in + /// the preprocessor block. Each offset points to the corresponding + /// macro definition. + MACRO_OFFSET = 47, + + /// \brief Record of updates for a macro that was modified after + /// being deserialized. + MACRO_UPDATES = 48 + }; + + /// \brief Record types used within a source manager block. + enum SourceManagerRecordTypes { + /// \brief Describes a source location entry (SLocEntry) for a + /// file. + SM_SLOC_FILE_ENTRY = 1, + /// \brief Describes a source location entry (SLocEntry) for a + /// buffer. + SM_SLOC_BUFFER_ENTRY = 2, + /// \brief Describes a blob that contains the data for a buffer + /// entry. This kind of record always directly follows a + /// SM_SLOC_BUFFER_ENTRY record or a SM_SLOC_FILE_ENTRY with an + /// overridden buffer. + SM_SLOC_BUFFER_BLOB = 3, + /// \brief Describes a source location entry (SLocEntry) for a + /// macro expansion. + SM_SLOC_EXPANSION_ENTRY = 4 + }; + + /// \brief Record types used within a preprocessor block. + enum PreprocessorRecordTypes { + // The macros in the PP section are a PP_MACRO_* instance followed by a + // list of PP_TOKEN instances for each token in the definition. + + /// \brief An object-like macro definition. + /// [PP_MACRO_OBJECT_LIKE, IdentInfoID, SLoc, IsUsed] + PP_MACRO_OBJECT_LIKE = 1, + + /// \brief A function-like macro definition. + /// [PP_MACRO_FUNCTION_LIKE, \, IsC99Varargs, + /// IsGNUVarars, NumArgs, ArgIdentInfoID* ] + PP_MACRO_FUNCTION_LIKE = 2, + + /// \brief Describes one token. + /// [PP_TOKEN, SLoc, Length, IdentInfoID, Kind, Flags] + PP_TOKEN = 3 + }; + + /// \brief Record types used within a preprocessor detail block. + enum PreprocessorDetailRecordTypes { + /// \brief Describes a macro expansion within the preprocessing record. + PPD_MACRO_EXPANSION = 0, + + /// \brief Describes a macro definition within the preprocessing record. + PPD_MACRO_DEFINITION = 1, + + /// \brief Describes an inclusion directive within the preprocessing + /// record. + PPD_INCLUSION_DIRECTIVE = 2 + }; + + /// \brief Record types used within a submodule description block. + enum SubmoduleRecordTypes { + /// \brief Metadata for submodules as a whole. + SUBMODULE_METADATA = 0, + /// \brief Defines the major attributes of a submodule, including its + /// name and parent. + SUBMODULE_DEFINITION = 1, + /// \brief Specifies the umbrella header used to create this module, + /// if any. + SUBMODULE_UMBRELLA_HEADER = 2, + /// \brief Specifies a header that falls into this (sub)module. + SUBMODULE_HEADER = 3, + /// \brief Specifies a top-level header that falls into this (sub)module. + SUBMODULE_TOPHEADER = 4, + /// \brief Specifies an umbrella directory. + SUBMODULE_UMBRELLA_DIR = 5, + /// \brief Specifies the submodules that are imported by this + /// submodule. + SUBMODULE_IMPORTS = 6, + /// \brief Specifies the submodules that are re-exported from this + /// submodule. + SUBMODULE_EXPORTS = 7, + /// \brief Specifies a required feature. + SUBMODULE_REQUIRES = 8, + /// \brief Specifies a header that has been explicitly excluded + /// from this submodule. + SUBMODULE_EXCLUDED_HEADER = 9 + }; + + /// \brief Record types used within a comments block. + enum CommentRecordTypes { + COMMENTS_RAW_COMMENT = 0 + }; + + /// \defgroup ASTAST AST file AST constants + /// + /// The constants in this group describe various components of the + /// abstract syntax tree within an AST file. + /// + /// @{ + + /// \brief Predefined type IDs. + /// + /// These type IDs correspond to predefined types in the AST + /// context, such as built-in types (int) and special place-holder + /// types (the \ and \ type markers). Such + /// types are never actually serialized, since they will be built + /// by the AST context when it is created. + enum PredefinedTypeIDs { + /// \brief The NULL type. + PREDEF_TYPE_NULL_ID = 0, + /// \brief The void type. + PREDEF_TYPE_VOID_ID = 1, + /// \brief The 'bool' or '_Bool' type. + PREDEF_TYPE_BOOL_ID = 2, + /// \brief The 'char' type, when it is unsigned. + PREDEF_TYPE_CHAR_U_ID = 3, + /// \brief The 'unsigned char' type. + PREDEF_TYPE_UCHAR_ID = 4, + /// \brief The 'unsigned short' type. + PREDEF_TYPE_USHORT_ID = 5, + /// \brief The 'unsigned int' type. + PREDEF_TYPE_UINT_ID = 6, + /// \brief The 'unsigned long' type. + PREDEF_TYPE_ULONG_ID = 7, + /// \brief The 'unsigned long long' type. + PREDEF_TYPE_ULONGLONG_ID = 8, + /// \brief The 'char' type, when it is signed. + PREDEF_TYPE_CHAR_S_ID = 9, + /// \brief The 'signed char' type. + PREDEF_TYPE_SCHAR_ID = 10, + /// \brief The C++ 'wchar_t' type. + PREDEF_TYPE_WCHAR_ID = 11, + /// \brief The (signed) 'short' type. + PREDEF_TYPE_SHORT_ID = 12, + /// \brief The (signed) 'int' type. + PREDEF_TYPE_INT_ID = 13, + /// \brief The (signed) 'long' type. + PREDEF_TYPE_LONG_ID = 14, + /// \brief The (signed) 'long long' type. + PREDEF_TYPE_LONGLONG_ID = 15, + /// \brief The 'float' type. + PREDEF_TYPE_FLOAT_ID = 16, + /// \brief The 'double' type. + PREDEF_TYPE_DOUBLE_ID = 17, + /// \brief The 'long double' type. + PREDEF_TYPE_LONGDOUBLE_ID = 18, + /// \brief The placeholder type for overloaded function sets. + PREDEF_TYPE_OVERLOAD_ID = 19, + /// \brief The placeholder type for dependent types. + PREDEF_TYPE_DEPENDENT_ID = 20, + /// \brief The '__uint128_t' type. + PREDEF_TYPE_UINT128_ID = 21, + /// \brief The '__int128_t' type. + PREDEF_TYPE_INT128_ID = 22, + /// \brief The type of 'nullptr'. + PREDEF_TYPE_NULLPTR_ID = 23, + /// \brief The C++ 'char16_t' type. + PREDEF_TYPE_CHAR16_ID = 24, + /// \brief The C++ 'char32_t' type. + PREDEF_TYPE_CHAR32_ID = 25, + /// \brief The ObjC 'id' type. + PREDEF_TYPE_OBJC_ID = 26, + /// \brief The ObjC 'Class' type. + PREDEF_TYPE_OBJC_CLASS = 27, + /// \brief The ObjC 'SEL' type. + PREDEF_TYPE_OBJC_SEL = 28, + /// \brief The 'unknown any' placeholder type. + PREDEF_TYPE_UNKNOWN_ANY = 29, + /// \brief The placeholder type for bound member functions. + PREDEF_TYPE_BOUND_MEMBER = 30, + /// \brief The "auto" deduction type. + PREDEF_TYPE_AUTO_DEDUCT = 31, + /// \brief The "auto &&" deduction type. + PREDEF_TYPE_AUTO_RREF_DEDUCT = 32, + /// \brief The OpenCL 'half' / ARM NEON __fp16 type. + PREDEF_TYPE_HALF_ID = 33, + /// \brief ARC's unbridged-cast placeholder type. + PREDEF_TYPE_ARC_UNBRIDGED_CAST = 34, + /// \brief The pseudo-object placeholder type. + PREDEF_TYPE_PSEUDO_OBJECT = 35, + /// \brief The __va_list_tag placeholder type. + PREDEF_TYPE_VA_LIST_TAG = 36, + /// \brief The placeholder type for builtin functions. + PREDEF_TYPE_BUILTIN_FN = 37, + /// \brief OpenCL 1d image type. + PREDEF_TYPE_IMAGE1D_ID = 38, + /// \brief OpenCL 1d image array type. + PREDEF_TYPE_IMAGE1D_ARR_ID = 39, + /// \brief OpenCL 1d image buffer type. + PREDEF_TYPE_IMAGE1D_BUFF_ID = 40, + /// \brief OpenCL 2d image type. + PREDEF_TYPE_IMAGE2D_ID = 41, + /// \brief OpenCL 2d image array type. + PREDEF_TYPE_IMAGE2D_ARR_ID = 42, + /// \brief OpenCL 3d image type. + PREDEF_TYPE_IMAGE3D_ID = 43 + }; + + /// \brief The number of predefined type IDs that are reserved for + /// the PREDEF_TYPE_* constants. + /// + /// Type IDs for non-predefined types will start at + /// NUM_PREDEF_TYPE_IDs. + const unsigned NUM_PREDEF_TYPE_IDS = 100; + + /// \brief The number of allowed abbreviations in bits + const unsigned NUM_ALLOWED_ABBREVS_SIZE = 4; + + /// \brief Record codes for each kind of type. + /// + /// These constants describe the type records that can occur within a + /// block identified by DECLTYPES_BLOCK_ID in the AST file. Each + /// constant describes a record for a specific type class in the + /// AST. + enum TypeCode { + /// \brief An ExtQualType record. + TYPE_EXT_QUAL = 1, + /// \brief A ComplexType record. + TYPE_COMPLEX = 3, + /// \brief A PointerType record. + TYPE_POINTER = 4, + /// \brief A BlockPointerType record. + TYPE_BLOCK_POINTER = 5, + /// \brief An LValueReferenceType record. + TYPE_LVALUE_REFERENCE = 6, + /// \brief An RValueReferenceType record. + TYPE_RVALUE_REFERENCE = 7, + /// \brief A MemberPointerType record. + TYPE_MEMBER_POINTER = 8, + /// \brief A ConstantArrayType record. + TYPE_CONSTANT_ARRAY = 9, + /// \brief An IncompleteArrayType record. + TYPE_INCOMPLETE_ARRAY = 10, + /// \brief A VariableArrayType record. + TYPE_VARIABLE_ARRAY = 11, + /// \brief A VectorType record. + TYPE_VECTOR = 12, + /// \brief An ExtVectorType record. + TYPE_EXT_VECTOR = 13, + /// \brief A FunctionNoProtoType record. + TYPE_FUNCTION_NO_PROTO = 14, + /// \brief A FunctionProtoType record. + TYPE_FUNCTION_PROTO = 15, + /// \brief A TypedefType record. + TYPE_TYPEDEF = 16, + /// \brief A TypeOfExprType record. + TYPE_TYPEOF_EXPR = 17, + /// \brief A TypeOfType record. + TYPE_TYPEOF = 18, + /// \brief A RecordType record. + TYPE_RECORD = 19, + /// \brief An EnumType record. + TYPE_ENUM = 20, + /// \brief An ObjCInterfaceType record. + TYPE_OBJC_INTERFACE = 21, + /// \brief An ObjCObjectPointerType record. + TYPE_OBJC_OBJECT_POINTER = 22, + /// \brief a DecltypeType record. + TYPE_DECLTYPE = 23, + /// \brief An ElaboratedType record. + TYPE_ELABORATED = 24, + /// \brief A SubstTemplateTypeParmType record. + TYPE_SUBST_TEMPLATE_TYPE_PARM = 25, + /// \brief An UnresolvedUsingType record. + TYPE_UNRESOLVED_USING = 26, + /// \brief An InjectedClassNameType record. + TYPE_INJECTED_CLASS_NAME = 27, + /// \brief An ObjCObjectType record. + TYPE_OBJC_OBJECT = 28, + /// \brief An TemplateTypeParmType record. + TYPE_TEMPLATE_TYPE_PARM = 29, + /// \brief An TemplateSpecializationType record. + TYPE_TEMPLATE_SPECIALIZATION = 30, + /// \brief A DependentNameType record. + TYPE_DEPENDENT_NAME = 31, + /// \brief A DependentTemplateSpecializationType record. + TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION = 32, + /// \brief A DependentSizedArrayType record. + TYPE_DEPENDENT_SIZED_ARRAY = 33, + /// \brief A ParenType record. + TYPE_PAREN = 34, + /// \brief A PackExpansionType record. + TYPE_PACK_EXPANSION = 35, + /// \brief An AttributedType record. + TYPE_ATTRIBUTED = 36, + /// \brief A SubstTemplateTypeParmPackType record. + TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK = 37, + /// \brief A AutoType record. + TYPE_AUTO = 38, + /// \brief A UnaryTransformType record. + TYPE_UNARY_TRANSFORM = 39, + /// \brief An AtomicType record. + TYPE_ATOMIC = 40 + }; + + /// \brief The type IDs for special types constructed by semantic + /// analysis. + /// + /// The constants in this enumeration are indices into the + /// SPECIAL_TYPES record. + enum SpecialTypeIDs { + /// \brief CFConstantString type + SPECIAL_TYPE_CF_CONSTANT_STRING = 0, + /// \brief C FILE typedef type + SPECIAL_TYPE_FILE = 1, + /// \brief C jmp_buf typedef type + SPECIAL_TYPE_JMP_BUF = 2, + /// \brief C sigjmp_buf typedef type + SPECIAL_TYPE_SIGJMP_BUF = 3, + /// \brief Objective-C "id" redefinition type + SPECIAL_TYPE_OBJC_ID_REDEFINITION = 4, + /// \brief Objective-C "Class" redefinition type + SPECIAL_TYPE_OBJC_CLASS_REDEFINITION = 5, + /// \brief Objective-C "SEL" redefinition type + SPECIAL_TYPE_OBJC_SEL_REDEFINITION = 6, + /// \brief C ucontext_t typedef type + SPECIAL_TYPE_UCONTEXT_T = 7 + }; + + /// \brief The number of special type IDs. + const unsigned NumSpecialTypeIDs = 8; + + /// \brief Predefined declaration IDs. + /// + /// These declaration IDs correspond to predefined declarations in the AST + /// context, such as the NULL declaration ID. Such declarations are never + /// actually serialized, since they will be built by the AST context when + /// it is created. + enum PredefinedDeclIDs { + /// \brief The NULL declaration. + PREDEF_DECL_NULL_ID = 0, + + /// \brief The translation unit. + PREDEF_DECL_TRANSLATION_UNIT_ID = 1, + + /// \brief The Objective-C 'id' type. + PREDEF_DECL_OBJC_ID_ID = 2, + + /// \brief The Objective-C 'SEL' type. + PREDEF_DECL_OBJC_SEL_ID = 3, + + /// \brief The Objective-C 'Class' type. + PREDEF_DECL_OBJC_CLASS_ID = 4, + + /// \brief The Objective-C 'Protocol' type. + PREDEF_DECL_OBJC_PROTOCOL_ID = 5, + + /// \brief The signed 128-bit integer type. + PREDEF_DECL_INT_128_ID = 6, + + /// \brief The unsigned 128-bit integer type. + PREDEF_DECL_UNSIGNED_INT_128_ID = 7, + + /// \brief The internal 'instancetype' typedef. + PREDEF_DECL_OBJC_INSTANCETYPE_ID = 8, + + /// \brief The internal '__builtin_va_list' typedef. + PREDEF_DECL_BUILTIN_VA_LIST_ID = 9 + }; + + /// \brief The number of declaration IDs that are predefined. + /// + /// For more information about predefined declarations, see the + /// \c PredefinedDeclIDs type and the PREDEF_DECL_*_ID constants. + const unsigned int NUM_PREDEF_DECL_IDS = 10; + + /// \brief Record codes for each kind of declaration. + /// + /// These constants describe the declaration records that can occur within + /// a declarations block (identified by DECLS_BLOCK_ID). Each + /// constant describes a record for a specific declaration class + /// in the AST. + enum DeclCode { + /// \brief A TypedefDecl record. + DECL_TYPEDEF = 51, + /// \brief A TypeAliasDecl record. + DECL_TYPEALIAS, + /// \brief An EnumDecl record. + DECL_ENUM, + /// \brief A RecordDecl record. + DECL_RECORD, + /// \brief An EnumConstantDecl record. + DECL_ENUM_CONSTANT, + /// \brief A FunctionDecl record. + DECL_FUNCTION, + /// \brief A ObjCMethodDecl record. + DECL_OBJC_METHOD, + /// \brief A ObjCInterfaceDecl record. + DECL_OBJC_INTERFACE, + /// \brief A ObjCProtocolDecl record. + DECL_OBJC_PROTOCOL, + /// \brief A ObjCIvarDecl record. + DECL_OBJC_IVAR, + /// \brief A ObjCAtDefsFieldDecl record. + DECL_OBJC_AT_DEFS_FIELD, + /// \brief A ObjCCategoryDecl record. + DECL_OBJC_CATEGORY, + /// \brief A ObjCCategoryImplDecl record. + DECL_OBJC_CATEGORY_IMPL, + /// \brief A ObjCImplementationDecl record. + DECL_OBJC_IMPLEMENTATION, + /// \brief A ObjCCompatibleAliasDecl record. + DECL_OBJC_COMPATIBLE_ALIAS, + /// \brief A ObjCPropertyDecl record. + DECL_OBJC_PROPERTY, + /// \brief A ObjCPropertyImplDecl record. + DECL_OBJC_PROPERTY_IMPL, + /// \brief A FieldDecl record. + DECL_FIELD, + /// \brief A VarDecl record. + DECL_VAR, + /// \brief An ImplicitParamDecl record. + DECL_IMPLICIT_PARAM, + /// \brief A ParmVarDecl record. + DECL_PARM_VAR, + /// \brief A FileScopeAsmDecl record. + DECL_FILE_SCOPE_ASM, + /// \brief A BlockDecl record. + DECL_BLOCK, + /// \brief A record that stores the set of declarations that are + /// lexically stored within a given DeclContext. + /// + /// The record itself is a blob that is an array of declaration IDs, + /// in the order in which those declarations were added to the + /// declaration context. This data is used when iterating over + /// the contents of a DeclContext, e.g., via + /// DeclContext::decls_begin() and DeclContext::decls_end(). + DECL_CONTEXT_LEXICAL, + /// \brief A record that stores the set of declarations that are + /// visible from a given DeclContext. + /// + /// The record itself stores a set of mappings, each of which + /// associates a declaration name with one or more declaration + /// IDs. This data is used when performing qualified name lookup + /// into a DeclContext via DeclContext::lookup. + DECL_CONTEXT_VISIBLE, + /// \brief A LabelDecl record. + DECL_LABEL, + /// \brief A NamespaceDecl record. + DECL_NAMESPACE, + /// \brief A NamespaceAliasDecl record. + DECL_NAMESPACE_ALIAS, + /// \brief A UsingDecl record. + DECL_USING, + /// \brief A UsingShadowDecl record. + DECL_USING_SHADOW, + /// \brief A UsingDirecitveDecl record. + DECL_USING_DIRECTIVE, + /// \brief An UnresolvedUsingValueDecl record. + DECL_UNRESOLVED_USING_VALUE, + /// \brief An UnresolvedUsingTypenameDecl record. + DECL_UNRESOLVED_USING_TYPENAME, + /// \brief A LinkageSpecDecl record. + DECL_LINKAGE_SPEC, + /// \brief A CXXRecordDecl record. + DECL_CXX_RECORD, + /// \brief A CXXMethodDecl record. + DECL_CXX_METHOD, + /// \brief A CXXConstructorDecl record. + DECL_CXX_CONSTRUCTOR, + /// \brief A CXXDestructorDecl record. + DECL_CXX_DESTRUCTOR, + /// \brief A CXXConversionDecl record. + DECL_CXX_CONVERSION, + /// \brief An AccessSpecDecl record. + DECL_ACCESS_SPEC, + + /// \brief A FriendDecl record. + DECL_FRIEND, + /// \brief A FriendTemplateDecl record. + DECL_FRIEND_TEMPLATE, + /// \brief A ClassTemplateDecl record. + DECL_CLASS_TEMPLATE, + /// \brief A ClassTemplateSpecializationDecl record. + DECL_CLASS_TEMPLATE_SPECIALIZATION, + /// \brief A ClassTemplatePartialSpecializationDecl record. + DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION, + /// \brief A FunctionTemplateDecl record. + DECL_FUNCTION_TEMPLATE, + /// \brief A TemplateTypeParmDecl record. + DECL_TEMPLATE_TYPE_PARM, + /// \brief A NonTypeTemplateParmDecl record. + DECL_NON_TYPE_TEMPLATE_PARM, + /// \brief A TemplateTemplateParmDecl record. + DECL_TEMPLATE_TEMPLATE_PARM, + /// \brief A TypeAliasTemplateDecl record. + DECL_TYPE_ALIAS_TEMPLATE, + /// \brief A StaticAssertDecl record. + DECL_STATIC_ASSERT, + /// \brief A record containing CXXBaseSpecifiers. + DECL_CXX_BASE_SPECIFIERS, + /// \brief A IndirectFieldDecl record. + DECL_INDIRECTFIELD, + /// \brief A NonTypeTemplateParmDecl record that stores an expanded + /// non-type template parameter pack. + DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK, + /// \brief A TemplateTemplateParmDecl record that stores an expanded + /// template template parameter pack. + DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK, + /// \brief A ClassScopeFunctionSpecializationDecl record a class scope + /// function specialization. (Microsoft extension). + DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION, + /// \brief An ImportDecl recording a module import. + DECL_IMPORT + }; + + /// \brief Record codes for each kind of statement or expression. + /// + /// These constants describe the records that describe statements + /// or expressions. These records occur within type and declarations + /// block, so they begin with record values of 100. Each constant + /// describes a record for a specific statement or expression class in the + /// AST. + enum StmtCode { + /// \brief A marker record that indicates that we are at the end + /// of an expression. + STMT_STOP = 100, + /// \brief A NULL expression. + STMT_NULL_PTR, + /// \brief A reference to a previously [de]serialized Stmt record. + STMT_REF_PTR, + /// \brief A NullStmt record. + STMT_NULL, + /// \brief A CompoundStmt record. + STMT_COMPOUND, + /// \brief A CaseStmt record. + STMT_CASE, + /// \brief A DefaultStmt record. + STMT_DEFAULT, + /// \brief A LabelStmt record. + STMT_LABEL, + /// \brief An AttributedStmt record. + STMT_ATTRIBUTED, + /// \brief An IfStmt record. + STMT_IF, + /// \brief A SwitchStmt record. + STMT_SWITCH, + /// \brief A WhileStmt record. + STMT_WHILE, + /// \brief A DoStmt record. + STMT_DO, + /// \brief A ForStmt record. + STMT_FOR, + /// \brief A GotoStmt record. + STMT_GOTO, + /// \brief An IndirectGotoStmt record. + STMT_INDIRECT_GOTO, + /// \brief A ContinueStmt record. + STMT_CONTINUE, + /// \brief A BreakStmt record. + STMT_BREAK, + /// \brief A ReturnStmt record. + STMT_RETURN, + /// \brief A DeclStmt record. + STMT_DECL, + /// \brief A GCC-style AsmStmt record. + STMT_GCCASM, + /// \brief A MS-style AsmStmt record. + STMT_MSASM, + /// \brief A PredefinedExpr record. + EXPR_PREDEFINED, + /// \brief A DeclRefExpr record. + EXPR_DECL_REF, + /// \brief An IntegerLiteral record. + EXPR_INTEGER_LITERAL, + /// \brief A FloatingLiteral record. + EXPR_FLOATING_LITERAL, + /// \brief An ImaginaryLiteral record. + EXPR_IMAGINARY_LITERAL, + /// \brief A StringLiteral record. + EXPR_STRING_LITERAL, + /// \brief A CharacterLiteral record. + EXPR_CHARACTER_LITERAL, + /// \brief A ParenExpr record. + EXPR_PAREN, + /// \brief A ParenListExpr record. + EXPR_PAREN_LIST, + /// \brief A UnaryOperator record. + EXPR_UNARY_OPERATOR, + /// \brief An OffsetOfExpr record. + EXPR_OFFSETOF, + /// \brief A SizefAlignOfExpr record. + EXPR_SIZEOF_ALIGN_OF, + /// \brief An ArraySubscriptExpr record. + EXPR_ARRAY_SUBSCRIPT, + /// \brief A CallExpr record. + EXPR_CALL, + /// \brief A MemberExpr record. + EXPR_MEMBER, + /// \brief A BinaryOperator record. + EXPR_BINARY_OPERATOR, + /// \brief A CompoundAssignOperator record. + EXPR_COMPOUND_ASSIGN_OPERATOR, + /// \brief A ConditionOperator record. + EXPR_CONDITIONAL_OPERATOR, + /// \brief An ImplicitCastExpr record. + EXPR_IMPLICIT_CAST, + /// \brief A CStyleCastExpr record. + EXPR_CSTYLE_CAST, + /// \brief A CompoundLiteralExpr record. + EXPR_COMPOUND_LITERAL, + /// \brief An ExtVectorElementExpr record. + EXPR_EXT_VECTOR_ELEMENT, + /// \brief An InitListExpr record. + EXPR_INIT_LIST, + /// \brief A DesignatedInitExpr record. + EXPR_DESIGNATED_INIT, + /// \brief An ImplicitValueInitExpr record. + EXPR_IMPLICIT_VALUE_INIT, + /// \brief A VAArgExpr record. + EXPR_VA_ARG, + /// \brief An AddrLabelExpr record. + EXPR_ADDR_LABEL, + /// \brief A StmtExpr record. + EXPR_STMT, + /// \brief A ChooseExpr record. + EXPR_CHOOSE, + /// \brief A GNUNullExpr record. + EXPR_GNU_NULL, + /// \brief A ShuffleVectorExpr record. + EXPR_SHUFFLE_VECTOR, + /// \brief BlockExpr + EXPR_BLOCK, + /// \brief A GenericSelectionExpr record. + EXPR_GENERIC_SELECTION, + /// \brief A PseudoObjectExpr record. + EXPR_PSEUDO_OBJECT, + /// \brief An AtomicExpr record. + EXPR_ATOMIC, + + // Objective-C + + /// \brief An ObjCStringLiteral record. + EXPR_OBJC_STRING_LITERAL, + + EXPR_OBJC_BOXED_EXPRESSION, + EXPR_OBJC_ARRAY_LITERAL, + EXPR_OBJC_DICTIONARY_LITERAL, + + + /// \brief An ObjCEncodeExpr record. + EXPR_OBJC_ENCODE, + /// \brief An ObjCSelectorExpr record. + EXPR_OBJC_SELECTOR_EXPR, + /// \brief An ObjCProtocolExpr record. + EXPR_OBJC_PROTOCOL_EXPR, + /// \brief An ObjCIvarRefExpr record. + EXPR_OBJC_IVAR_REF_EXPR, + /// \brief An ObjCPropertyRefExpr record. + EXPR_OBJC_PROPERTY_REF_EXPR, + /// \brief An ObjCSubscriptRefExpr record. + EXPR_OBJC_SUBSCRIPT_REF_EXPR, + /// \brief UNUSED + EXPR_OBJC_KVC_REF_EXPR, + /// \brief An ObjCMessageExpr record. + EXPR_OBJC_MESSAGE_EXPR, + /// \brief An ObjCIsa Expr record. + EXPR_OBJC_ISA, + /// \brief An ObjCIndirectCopyRestoreExpr record. + EXPR_OBJC_INDIRECT_COPY_RESTORE, + + /// \brief An ObjCForCollectionStmt record. + STMT_OBJC_FOR_COLLECTION, + /// \brief An ObjCAtCatchStmt record. + STMT_OBJC_CATCH, + /// \brief An ObjCAtFinallyStmt record. + STMT_OBJC_FINALLY, + /// \brief An ObjCAtTryStmt record. + STMT_OBJC_AT_TRY, + /// \brief An ObjCAtSynchronizedStmt record. + STMT_OBJC_AT_SYNCHRONIZED, + /// \brief An ObjCAtThrowStmt record. + STMT_OBJC_AT_THROW, + /// \brief An ObjCAutoreleasePoolStmt record. + STMT_OBJC_AUTORELEASE_POOL, + /// \brief A ObjCBoolLiteralExpr record. + EXPR_OBJC_BOOL_LITERAL, + + // C++ + + /// \brief A CXXCatchStmt record. + STMT_CXX_CATCH, + /// \brief A CXXTryStmt record. + STMT_CXX_TRY, + /// \brief A CXXForRangeStmt record. + STMT_CXX_FOR_RANGE, + + /// \brief A CXXOperatorCallExpr record. + EXPR_CXX_OPERATOR_CALL, + /// \brief A CXXMemberCallExpr record. + EXPR_CXX_MEMBER_CALL, + /// \brief A CXXConstructExpr record. + EXPR_CXX_CONSTRUCT, + /// \brief A CXXTemporaryObjectExpr record. + EXPR_CXX_TEMPORARY_OBJECT, + /// \brief A CXXStaticCastExpr record. + EXPR_CXX_STATIC_CAST, + /// \brief A CXXDynamicCastExpr record. + EXPR_CXX_DYNAMIC_CAST, + /// \brief A CXXReinterpretCastExpr record. + EXPR_CXX_REINTERPRET_CAST, + /// \brief A CXXConstCastExpr record. + EXPR_CXX_CONST_CAST, + /// \brief A CXXFunctionalCastExpr record. + EXPR_CXX_FUNCTIONAL_CAST, + /// \brief A UserDefinedLiteral record. + EXPR_USER_DEFINED_LITERAL, + /// \brief A CXXBoolLiteralExpr record. + EXPR_CXX_BOOL_LITERAL, + EXPR_CXX_NULL_PTR_LITERAL, // CXXNullPtrLiteralExpr + EXPR_CXX_TYPEID_EXPR, // CXXTypeidExpr (of expr). + EXPR_CXX_TYPEID_TYPE, // CXXTypeidExpr (of type). + EXPR_CXX_THIS, // CXXThisExpr + EXPR_CXX_THROW, // CXXThrowExpr + EXPR_CXX_DEFAULT_ARG, // CXXDefaultArgExpr + EXPR_CXX_BIND_TEMPORARY, // CXXBindTemporaryExpr + + EXPR_CXX_SCALAR_VALUE_INIT, // CXXScalarValueInitExpr + EXPR_CXX_NEW, // CXXNewExpr + EXPR_CXX_DELETE, // CXXDeleteExpr + EXPR_CXX_PSEUDO_DESTRUCTOR, // CXXPseudoDestructorExpr + + EXPR_EXPR_WITH_CLEANUPS, // ExprWithCleanups + + EXPR_CXX_DEPENDENT_SCOPE_MEMBER, // CXXDependentScopeMemberExpr + EXPR_CXX_DEPENDENT_SCOPE_DECL_REF, // DependentScopeDeclRefExpr + EXPR_CXX_UNRESOLVED_CONSTRUCT, // CXXUnresolvedConstructExpr + EXPR_CXX_UNRESOLVED_MEMBER, // UnresolvedMemberExpr + EXPR_CXX_UNRESOLVED_LOOKUP, // UnresolvedLookupExpr + + EXPR_CXX_UNARY_TYPE_TRAIT, // UnaryTypeTraitExpr + EXPR_CXX_EXPRESSION_TRAIT, // ExpressionTraitExpr + EXPR_CXX_NOEXCEPT, // CXXNoexceptExpr + + EXPR_OPAQUE_VALUE, // OpaqueValueExpr + EXPR_BINARY_CONDITIONAL_OPERATOR, // BinaryConditionalOperator + EXPR_BINARY_TYPE_TRAIT, // BinaryTypeTraitExpr + EXPR_TYPE_TRAIT, // TypeTraitExpr + EXPR_ARRAY_TYPE_TRAIT, // ArrayTypeTraitIntExpr + + EXPR_PACK_EXPANSION, // PackExpansionExpr + EXPR_SIZEOF_PACK, // SizeOfPackExpr + EXPR_SUBST_NON_TYPE_TEMPLATE_PARM, // SubstNonTypeTemplateParmExpr + EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK,// SubstNonTypeTemplateParmPackExpr + EXPR_FUNCTION_PARM_PACK, // FunctionParmPackExpr + EXPR_MATERIALIZE_TEMPORARY, // MaterializeTemporaryExpr + + // CUDA + EXPR_CUDA_KERNEL_CALL, // CUDAKernelCallExpr + + // OpenCL + EXPR_ASTYPE, // AsTypeExpr + + // Microsoft + EXPR_CXX_UUIDOF_EXPR, // CXXUuidofExpr (of expr). + EXPR_CXX_UUIDOF_TYPE, // CXXUuidofExpr (of type). + STMT_SEH_EXCEPT, // SEHExceptStmt + STMT_SEH_FINALLY, // SEHFinallyStmt + STMT_SEH_TRY, // SEHTryStmt + + // ARC + EXPR_OBJC_BRIDGED_CAST, // ObjCBridgedCastExpr + + STMT_MS_DEPENDENT_EXISTS, // MSDependentExistsStmt + EXPR_LAMBDA // LambdaExpr + }; + + /// \brief The kinds of designators that can occur in a + /// DesignatedInitExpr. + enum DesignatorTypes { + /// \brief Field designator where only the field name is known. + DESIG_FIELD_NAME = 0, + /// \brief Field designator where the field has been resolved to + /// a declaration. + DESIG_FIELD_DECL = 1, + /// \brief Array designator. + DESIG_ARRAY = 2, + /// \brief GNU array range designator. + DESIG_ARRAY_RANGE = 3 + }; + + /// \brief The different kinds of data that can occur in a + /// CtorInitializer. + enum CtorInitializerType { + CTOR_INITIALIZER_BASE, + CTOR_INITIALIZER_DELEGATING, + CTOR_INITIALIZER_MEMBER, + CTOR_INITIALIZER_INDIRECT_MEMBER + }; + + /// \brief Describes the redeclarations of a declaration. + struct LocalRedeclarationsInfo { + DeclID FirstID; // The ID of the first declaration + unsigned Offset; // Offset into the array of redeclaration chains. + + friend bool operator<(const LocalRedeclarationsInfo &X, + const LocalRedeclarationsInfo &Y) { + return X.FirstID < Y.FirstID; + } + + friend bool operator>(const LocalRedeclarationsInfo &X, + const LocalRedeclarationsInfo &Y) { + return X.FirstID > Y.FirstID; + } + + friend bool operator<=(const LocalRedeclarationsInfo &X, + const LocalRedeclarationsInfo &Y) { + return X.FirstID <= Y.FirstID; + } + + friend bool operator>=(const LocalRedeclarationsInfo &X, + const LocalRedeclarationsInfo &Y) { + return X.FirstID >= Y.FirstID; + } + }; + + /// \brief Describes the categories of an Objective-C class. + struct ObjCCategoriesInfo { + DeclID DefinitionID; // The ID of the definition + unsigned Offset; // Offset into the array of category lists. + + friend bool operator<(const ObjCCategoriesInfo &X, + const ObjCCategoriesInfo &Y) { + return X.DefinitionID < Y.DefinitionID; + } + + friend bool operator>(const ObjCCategoriesInfo &X, + const ObjCCategoriesInfo &Y) { + return X.DefinitionID > Y.DefinitionID; + } + + friend bool operator<=(const ObjCCategoriesInfo &X, + const ObjCCategoriesInfo &Y) { + return X.DefinitionID <= Y.DefinitionID; + } + + friend bool operator>=(const ObjCCategoriesInfo &X, + const ObjCCategoriesInfo &Y) { + return X.DefinitionID >= Y.DefinitionID; + } + }; + + /// @} + } +} // end namespace clang + +#endif diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index f3fa13584d..b04b830c85 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -874,6 +874,15 @@ void ASTContext::InitBuiltinTypes(const TargetInfo &Target) { InitBuiltinType(ObjCBuiltinIdTy, BuiltinType::ObjCId); InitBuiltinType(ObjCBuiltinClassTy, BuiltinType::ObjCClass); InitBuiltinType(ObjCBuiltinSelTy, BuiltinType::ObjCSel); + + if (LangOpts.OpenCL) { + InitBuiltinType(OCLImage1dTy, BuiltinType::OCLImage1d); + InitBuiltinType(OCLImage1dArrayTy, BuiltinType::OCLImage1dArray); + InitBuiltinType(OCLImage1dBufferTy, BuiltinType::OCLImage1dBuffer); + InitBuiltinType(OCLImage2dTy, BuiltinType::OCLImage2d); + InitBuiltinType(OCLImage2dArrayTy, BuiltinType::OCLImage2dArray); + InitBuiltinType(OCLImage3dTy, BuiltinType::OCLImage3d); + } // Builtin type for __objc_yes and __objc_no ObjCBuiltinBoolTy = (Target.useSignedCharForObjCBool() ? @@ -1412,6 +1421,16 @@ ASTContext::getTypeInfoImpl(const Type *T) const { Width = Target->getPointerWidth(0); Align = Target->getPointerAlign(0); break; + case BuiltinType::OCLImage1d: + case BuiltinType::OCLImage1dArray: + case BuiltinType::OCLImage1dBuffer: + case BuiltinType::OCLImage2d: + case BuiltinType::OCLImage2dArray: + case BuiltinType::OCLImage3d: + // Currently these types are pointers to opaque types. + Width = Target->getPointerWidth(0); + Align = Target->getPointerAlign(0); + break; } break; case Type::ObjCObjectPointer: diff --git a/lib/AST/ItaniumMangle.cpp b/lib/AST/ItaniumMangle.cpp index 566a3894cb..65907f909b 100644 --- a/lib/AST/ItaniumMangle.cpp +++ b/lib/AST/ItaniumMangle.cpp @@ -1,3574 +1,3580 @@ -//===--- ItaniumMangle.cpp - Itanium C++ Name Mangling ----------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// Implements C++ name mangling according to the Itanium C++ ABI, -// which is used in GCC 3.2 and newer (and many compilers that are -// ABI-compatible with GCC): -// -// http://www.codesourcery.com/public/cxx-abi/abi.html -// -//===----------------------------------------------------------------------===// -#include "clang/AST/Mangle.h" -#include "clang/AST/ASTContext.h" -#include "clang/AST/Attr.h" -#include "clang/AST/Decl.h" -#include "clang/AST/DeclCXX.h" -#include "clang/AST/DeclObjC.h" -#include "clang/AST/DeclTemplate.h" -#include "clang/AST/ExprCXX.h" -#include "clang/AST/ExprObjC.h" -#include "clang/AST/TypeLoc.h" -#include "clang/Basic/ABI.h" -#include "clang/Basic/SourceManager.h" -#include "clang/Basic/TargetInfo.h" -#include "llvm/ADT/StringExtras.h" -#include "llvm/Support/ErrorHandling.h" -#include "llvm/Support/raw_ostream.h" - -#define MANGLE_CHECKER 0 - -#if MANGLE_CHECKER -#include -#endif - -using namespace clang; - -namespace { - -/// \brief Retrieve the declaration context that should be used when mangling -/// the given declaration. -static const DeclContext *getEffectiveDeclContext(const Decl *D) { - // The ABI assumes that lambda closure types that occur within - // default arguments live in the context of the function. However, due to - // the way in which Clang parses and creates function declarations, this is - // not the case: the lambda closure type ends up living in the context - // where the function itself resides, because the function declaration itself - // had not yet been created. Fix the context here. - if (const CXXRecordDecl *RD = dyn_cast(D)) { - if (RD->isLambda()) - if (ParmVarDecl *ContextParam - = dyn_cast_or_null(RD->getLambdaContextDecl())) - return ContextParam->getDeclContext(); - } - - return D->getDeclContext(); -} - -static const DeclContext *getEffectiveParentContext(const DeclContext *DC) { - return getEffectiveDeclContext(cast(DC)); -} - -static const CXXRecordDecl *GetLocalClassDecl(const NamedDecl *ND) { - const DeclContext *DC = dyn_cast(ND); - if (!DC) - DC = getEffectiveDeclContext(ND); - while (!DC->isNamespace() && !DC->isTranslationUnit()) { - const DeclContext *Parent = getEffectiveDeclContext(cast(DC)); - if (isa(Parent)) - return dyn_cast(DC); - DC = Parent; - } - return 0; -} - -static const FunctionDecl *getStructor(const FunctionDecl *fn) { - if (const FunctionTemplateDecl *ftd = fn->getPrimaryTemplate()) - return ftd->getTemplatedDecl(); - - return fn; -} - -static const NamedDecl *getStructor(const NamedDecl *decl) { - const FunctionDecl *fn = dyn_cast_or_null(decl); - return (fn ? getStructor(fn) : decl); -} - -static const unsigned UnknownArity = ~0U; - -class ItaniumMangleContext : public MangleContext { - llvm::DenseMap AnonStructIds; - unsigned Discriminator; - llvm::DenseMap Uniquifier; - -public: - explicit ItaniumMangleContext(ASTContext &Context, - DiagnosticsEngine &Diags) - : MangleContext(Context, Diags) { } - - uint64_t getAnonymousStructId(const TagDecl *TD) { - std::pair::iterator, bool> Result = - AnonStructIds.insert(std::make_pair(TD, AnonStructIds.size())); - return Result.first->second; - } - - void startNewFunction() { - MangleContext::startNewFunction(); - mangleInitDiscriminator(); - } - - /// @name Mangler Entry Points - /// @{ - - bool shouldMangleDeclName(const NamedDecl *D); - void mangleName(const NamedDecl *D, raw_ostream &); - void mangleThunk(const CXXMethodDecl *MD, - const ThunkInfo &Thunk, - raw_ostream &); - void mangleCXXDtorThunk(const CXXDestructorDecl *DD, CXXDtorType Type, - const ThisAdjustment &ThisAdjustment, - raw_ostream &); - void mangleReferenceTemporary(const VarDecl *D, - raw_ostream &); - void mangleCXXVTable(const CXXRecordDecl *RD, - raw_ostream &); - void mangleCXXVTT(const CXXRecordDecl *RD, - raw_ostream &); - void mangleCXXCtorVTable(const CXXRecordDecl *RD, int64_t Offset, - const CXXRecordDecl *Type, - raw_ostream &); - void mangleCXXRTTI(QualType T, raw_ostream &); - void mangleCXXRTTIName(QualType T, raw_ostream &); - void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type, - raw_ostream &); - void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type, - raw_ostream &); - - void mangleItaniumGuardVariable(const VarDecl *D, raw_ostream &); - - void mangleInitDiscriminator() { - Discriminator = 0; - } - - bool getNextDiscriminator(const NamedDecl *ND, unsigned &disc) { - // Lambda closure types with external linkage (indicated by a - // non-zero lambda mangling number) have their own numbering scheme, so - // they do not need a discriminator. - if (const CXXRecordDecl *RD = dyn_cast(ND)) - if (RD->isLambda() && RD->getLambdaManglingNumber() > 0) - return false; - - unsigned &discriminator = Uniquifier[ND]; - if (!discriminator) - discriminator = ++Discriminator; - if (discriminator == 1) - return false; - disc = discriminator-2; - return true; - } - /// @} -}; - -/// CXXNameMangler - Manage the mangling of a single name. -class CXXNameMangler { - ItaniumMangleContext &Context; - raw_ostream &Out; - - /// The "structor" is the top-level declaration being mangled, if - /// that's not a template specialization; otherwise it's the pattern - /// for that specialization. - const NamedDecl *Structor; - unsigned StructorType; - - /// SeqID - The next subsitution sequence number. - unsigned SeqID; - - class FunctionTypeDepthState { - unsigned Bits; - - enum { InResultTypeMask = 1 }; - - public: - FunctionTypeDepthState() : Bits(0) {} - - /// The number of function types we're inside. - unsigned getDepth() const { - return Bits >> 1; - } - - /// True if we're in the return type of the innermost function type. - bool isInResultType() const { - return Bits & InResultTypeMask; - } - - FunctionTypeDepthState push() { - FunctionTypeDepthState tmp = *this; - Bits = (Bits & ~InResultTypeMask) + 2; - return tmp; - } - - void enterResultType() { - Bits |= InResultTypeMask; - } - - void leaveResultType() { - Bits &= ~InResultTypeMask; - } - - void pop(FunctionTypeDepthState saved) { - assert(getDepth() == saved.getDepth() + 1); - Bits = saved.Bits; - } - - } FunctionTypeDepth; - - llvm::DenseMap Substitutions; - - ASTContext &getASTContext() const { return Context.getASTContext(); } - -public: - CXXNameMangler(ItaniumMangleContext &C, raw_ostream &Out_, - const NamedDecl *D = 0) - : Context(C), Out(Out_), Structor(getStructor(D)), StructorType(0), - SeqID(0) { - // These can't be mangled without a ctor type or dtor type. - assert(!D || (!isa(D) && - !isa(D))); - } - CXXNameMangler(ItaniumMangleContext &C, raw_ostream &Out_, - const CXXConstructorDecl *D, CXXCtorType Type) - : Context(C), Out(Out_), Structor(getStructor(D)), StructorType(Type), - SeqID(0) { } - CXXNameMangler(ItaniumMangleContext &C, raw_ostream &Out_, - const CXXDestructorDecl *D, CXXDtorType Type) - : Context(C), Out(Out_), Structor(getStructor(D)), StructorType(Type), - SeqID(0) { } - -#if MANGLE_CHECKER - ~CXXNameMangler() { - if (Out.str()[0] == '\01') - return; - - int status = 0; - char *result = abi::__cxa_demangle(Out.str().str().c_str(), 0, 0, &status); - assert(status == 0 && "Could not demangle mangled name!"); - free(result); - } -#endif - raw_ostream &getStream() { return Out; } - - void mangle(const NamedDecl *D, StringRef Prefix = "_Z"); - void mangleCallOffset(int64_t NonVirtual, int64_t Virtual); - void mangleNumber(const llvm::APSInt &I); - void mangleNumber(int64_t Number); - void mangleFloat(const llvm::APFloat &F); - void mangleFunctionEncoding(const FunctionDecl *FD); - void mangleName(const NamedDecl *ND); - void mangleType(QualType T); - void mangleNameOrStandardSubstitution(const NamedDecl *ND); - -private: - bool mangleSubstitution(const NamedDecl *ND); - bool mangleSubstitution(QualType T); - bool mangleSubstitution(TemplateName Template); - bool mangleSubstitution(uintptr_t Ptr); - - void mangleExistingSubstitution(QualType type); - void mangleExistingSubstitution(TemplateName name); - - bool mangleStandardSubstitution(const NamedDecl *ND); - - void addSubstitution(const NamedDecl *ND) { - ND = cast(ND->getCanonicalDecl()); - - addSubstitution(reinterpret_cast(ND)); - } - void addSubstitution(QualType T); - void addSubstitution(TemplateName Template); - void addSubstitution(uintptr_t Ptr); - - void mangleUnresolvedPrefix(NestedNameSpecifier *qualifier, - NamedDecl *firstQualifierLookup, - bool recursive = false); - void mangleUnresolvedName(NestedNameSpecifier *qualifier, - NamedDecl *firstQualifierLookup, - DeclarationName name, - unsigned KnownArity = UnknownArity); - - void mangleName(const TemplateDecl *TD, - const TemplateArgument *TemplateArgs, - unsigned NumTemplateArgs); - void mangleUnqualifiedName(const NamedDecl *ND) { - mangleUnqualifiedName(ND, ND->getDeclName(), UnknownArity); - } - void mangleUnqualifiedName(const NamedDecl *ND, DeclarationName Name, - unsigned KnownArity); - void mangleUnscopedName(const NamedDecl *ND); - void mangleUnscopedTemplateName(const TemplateDecl *ND); - void mangleUnscopedTemplateName(TemplateName); - void mangleSourceName(const IdentifierInfo *II); - void mangleLocalName(const NamedDecl *ND); - void mangleLambda(const CXXRecordDecl *Lambda); - void mangleNestedName(const NamedDecl *ND, const DeclContext *DC, - bool NoFunction=false); - void mangleNestedName(const TemplateDecl *TD, - const TemplateArgument *TemplateArgs, - unsigned NumTemplateArgs); - void manglePrefix(NestedNameSpecifier *qualifier); - void manglePrefix(const DeclContext *DC, bool NoFunction=false); - void manglePrefix(QualType type); - void mangleTemplatePrefix(const TemplateDecl *ND); - void mangleTemplatePrefix(TemplateName Template); - void mangleOperatorName(OverloadedOperatorKind OO, unsigned Arity); - void mangleQualifiers(Qualifiers Quals); - void mangleRefQualifier(RefQualifierKind RefQualifier); - - void mangleObjCMethodName(const ObjCMethodDecl *MD); - - // Declare manglers for every type class. -#define ABSTRACT_TYPE(CLASS, PARENT) -#define NON_CANONICAL_TYPE(CLASS, PARENT) -#define TYPE(CLASS, PARENT) void mangleType(const CLASS##Type *T); -#include "clang/AST/TypeNodes.def" - - void mangleType(const TagType*); - void mangleType(TemplateName); - void mangleBareFunctionType(const FunctionType *T, - bool MangleReturnType); - void mangleNeonVectorType(const VectorType *T); - - void mangleIntegerLiteral(QualType T, const llvm::APSInt &Value); - void mangleMemberExpr(const Expr *base, bool isArrow, - NestedNameSpecifier *qualifier, - NamedDecl *firstQualifierLookup, - DeclarationName name, - unsigned knownArity); - void mangleExpression(const Expr *E, unsigned Arity = UnknownArity); - void mangleCXXCtorType(CXXCtorType T); - void mangleCXXDtorType(CXXDtorType T); - - void mangleTemplateArgs(const ASTTemplateArgumentListInfo &TemplateArgs); - void mangleTemplateArgs(const TemplateArgument *TemplateArgs, - unsigned NumTemplateArgs); - void mangleTemplateArgs(const TemplateArgumentList &AL); - void mangleTemplateArg(TemplateArgument A); - - void mangleTemplateParameter(unsigned Index); - - void mangleFunctionParam(const ParmVarDecl *parm); -}; - -} - -static bool isInCLinkageSpecification(const Decl *D) { - D = D->getCanonicalDecl(); - for (const DeclContext *DC = getEffectiveDeclContext(D); - !DC->isTranslationUnit(); DC = getEffectiveParentContext(DC)) { - if (const LinkageSpecDecl *Linkage = dyn_cast(DC)) - return Linkage->getLanguage() == LinkageSpecDecl::lang_c; - } - - return false; -} - -bool ItaniumMangleContext::shouldMangleDeclName(const NamedDecl *D) { - // In C, functions with no attributes never need to be mangled. Fastpath them. - if (!getASTContext().getLangOpts().CPlusPlus && !D->hasAttrs()) - return false; - - // Any decl can be declared with __asm("foo") on it, and this takes precedence - // over all other naming in the .o file. - if (D->hasAttr()) - return true; - - // Clang's "overloadable" attribute extension to C/C++ implies name mangling - // (always) as does passing a C++ member function and a function - // whose name is not a simple identifier. - const FunctionDecl *FD = dyn_cast(D); - if (FD && (FD->hasAttr() || isa(FD) || - !FD->getDeclName().isIdentifier())) - return true; - - // Otherwise, no mangling is done outside C++ mode. - if (!getASTContext().getLangOpts().CPlusPlus) - return false; - - // Variables at global scope with non-internal linkage are not mangled - if (!FD) { - const DeclContext *DC = getEffectiveDeclContext(D); - // Check for extern variable declared locally. - if (DC->isFunctionOrMethod() && D->hasLinkage()) - while (!DC->isNamespace() && !DC->isTranslationUnit()) - DC = getEffectiveParentContext(DC); - if (DC->isTranslationUnit() && D->getLinkage() != InternalLinkage) - return false; - } - - // Class members are always mangled. - if (getEffectiveDeclContext(D)->isRecord()) - return true; - - // C functions and "main" are not mangled. - if ((FD && FD->isMain()) || isInCLinkageSpecification(D)) - return false; - - return true; -} - -void CXXNameMangler::mangle(const NamedDecl *D, StringRef Prefix) { - // Any decl can be declared with __asm("foo") on it, and this takes precedence - // over all other naming in the .o file. - if (const AsmLabelAttr *ALA = D->getAttr()) { - // If we have an asm name, then we use it as the mangling. - - // Adding the prefix can cause problems when one file has a "foo" and - // another has a "\01foo". That is known to happen on ELF with the - // tricks normally used for producing aliases (PR9177). Fortunately the - // llvm mangler on ELF is a nop, so we can just avoid adding the \01 - // marker. We also avoid adding the marker if this is an alias for an - // LLVM intrinsic. - StringRef UserLabelPrefix = - getASTContext().getTargetInfo().getUserLabelPrefix(); - if (!UserLabelPrefix.empty() && !ALA->getLabel().startswith("llvm.")) - Out << '\01'; // LLVM IR Marker for __asm("foo") - - Out << ALA->getLabel(); - return; - } - - // ::= _Z - // ::= - // ::= - Out << Prefix; - if (const FunctionDecl *FD = dyn_cast(D)) - mangleFunctionEncoding(FD); - else if (const VarDecl *VD = dyn_cast(D)) - mangleName(VD); - else - mangleName(cast(D)); -} - -void CXXNameMangler::mangleFunctionEncoding(const FunctionDecl *FD) { - // ::= - mangleName(FD); - - // Don't mangle in the type if this isn't a decl we should typically mangle. - if (!Context.shouldMangleDeclName(FD)) - return; - - // Whether the mangling of a function type includes the return type depends on - // the context and the nature of the function. The rules for deciding whether - // the return type is included are: - // - // 1. Template functions (names or types) have return types encoded, with - // the exceptions listed below. - // 2. Function types not appearing as part of a function name mangling, - // e.g. parameters, pointer types, etc., have return type encoded, with the - // exceptions listed below. - // 3. Non-template function names do not have return types encoded. - // - // The exceptions mentioned in (1) and (2) above, for which the return type is - // never included, are - // 1. Constructors. - // 2. Destructors. - // 3. Conversion operator functions, e.g. operator int. - bool MangleReturnType = false; - if (FunctionTemplateDecl *PrimaryTemplate = FD->getPrimaryTemplate()) { - if (!(isa(FD) || isa(FD) || - isa(FD))) - MangleReturnType = true; - - // Mangle the type of the primary template. - FD = PrimaryTemplate->getTemplatedDecl(); - } - - mangleBareFunctionType(FD->getType()->getAs(), - MangleReturnType); -} - -static const DeclContext *IgnoreLinkageSpecDecls(const DeclContext *DC) { - while (isa(DC)) { - DC = getEffectiveParentContext(DC); - } - - return DC; -} - -/// isStd - Return whether a given namespace is the 'std' namespace. -static bool isStd(const NamespaceDecl *NS) { - if (!IgnoreLinkageSpecDecls(getEffectiveParentContext(NS)) - ->isTranslationUnit()) - return false; - - const IdentifierInfo *II = NS->getOriginalNamespace()->getIdentifier(); - return II && II->isStr("std"); -} - -// isStdNamespace - Return whether a given decl context is a toplevel 'std' -// namespace. -static bool isStdNamespace(const DeclContext *DC) { - if (!DC->isNamespace()) - return false; - - return isStd(cast(DC)); -} - -static const TemplateDecl * -isTemplate(const NamedDecl *ND, const TemplateArgumentList *&TemplateArgs) { - // Check if we have a function template. - if (const FunctionDecl *FD = dyn_cast(ND)){ - if (const TemplateDecl *TD = FD->getPrimaryTemplate()) { - TemplateArgs = FD->getTemplateSpecializationArgs(); - return TD; - } - } - - // Check if we have a class template. - if (const ClassTemplateSpecializationDecl *Spec = - dyn_cast(ND)) { - TemplateArgs = &Spec->getTemplateArgs(); - return Spec->getSpecializedTemplate(); - } - - return 0; -} - -static bool isLambda(const NamedDecl *ND) { - const CXXRecordDecl *Record = dyn_cast(ND); - if (!Record) - return false; - - return Record->isLambda(); -} - -void CXXNameMangler::mangleName(const NamedDecl *ND) { - // ::= - // ::= - // ::= - // ::= - // - const DeclContext *DC = getEffectiveDeclContext(ND); - - // If this is an extern variable declared locally, the relevant DeclContext - // is that of the containing namespace, or the translation unit. - // FIXME: This is a hack; extern variables declared locally should have - // a proper semantic declaration context! - if (isa(DC) && ND->hasLinkage() && !isLambda(ND)) - while (!DC->isNamespace() && !DC->isTranslationUnit()) - DC = getEffectiveParentContext(DC); - else if (GetLocalClassDecl(ND)) { - mangleLocalName(ND); - return; - } - - DC = IgnoreLinkageSpecDecls(DC); - - if (DC->isTranslationUnit() || isStdNamespace(DC)) { - // Check if we have a template. - const TemplateArgumentList *TemplateArgs = 0; - if (const TemplateDecl *TD = isTemplate(ND, TemplateArgs)) { - mangleUnscopedTemplateName(TD); - mangleTemplateArgs(*TemplateArgs); - return; - } - - mangleUnscopedName(ND); - return; - } - - if (isa(DC) || isa(DC)) { - mangleLocalName(ND); - return; - } - - mangleNestedName(ND, DC); -} -void CXXNameMangler::mangleName(const TemplateDecl *TD, - const TemplateArgument *TemplateArgs, - unsigned NumTemplateArgs) { - const DeclContext *DC = IgnoreLinkageSpecDecls(getEffectiveDeclContext(TD)); - - if (DC->isTranslationUnit() || isStdNamespace(DC)) { - mangleUnscopedTemplateName(TD); - mangleTemplateArgs(TemplateArgs, NumTemplateArgs); - } else { - mangleNestedName(TD, TemplateArgs, NumTemplateArgs); - } -} - -void CXXNameMangler::mangleUnscopedName(const NamedDecl *ND) { - // ::= - // ::= St # ::std:: - - if (isStdNamespace(IgnoreLinkageSpecDecls(getEffectiveDeclContext(ND)))) - Out << "St"; - - mangleUnqualifiedName(ND); -} - -void CXXNameMangler::mangleUnscopedTemplateName(const TemplateDecl *ND) { - // ::= - // ::= - if (mangleSubstitution(ND)) - return; - - // ::= - if (const TemplateTemplateParmDecl *TTP - = dyn_cast(ND)) { - mangleTemplateParameter(TTP->getIndex()); - return; - } - - mangleUnscopedName(ND->getTemplatedDecl()); - addSubstitution(ND); -} - -void CXXNameMangler::mangleUnscopedTemplateName(TemplateName Template) { - // ::= - // ::= - if (TemplateDecl *TD = Template.getAsTemplateDecl()) - return mangleUnscopedTemplateName(TD); - - if (mangleSubstitution(Template)) - return; - - DependentTemplateName *Dependent = Template.getAsDependentTemplateName(); - assert(Dependent && "Not a dependent template name?"); - if (const IdentifierInfo *Id = Dependent->getIdentifier()) - mangleSourceName(Id); - else - mangleOperatorName(Dependent->getOperator(), UnknownArity); - - addSubstitution(Template); -} - -void CXXNameMangler::mangleFloat(const llvm::APFloat &f) { - // ABI: - // Floating-point literals are encoded using a fixed-length - // lowercase hexadecimal string corresponding to the internal - // representation (IEEE on Itanium), high-order bytes first, - // without leading zeroes. For example: "Lf bf800000 E" is -1.0f - // on Itanium. - // The 'without leading zeroes' thing seems to be an editorial - // mistake; see the discussion on cxx-abi-dev beginning on - // 2012-01-16. - - // Our requirements here are just barely weird enough to justify - // using a custom algorithm instead of post-processing APInt::toString(). - - llvm::APInt valueBits = f.bitcastToAPInt(); - unsigned numCharacters = (valueBits.getBitWidth() + 3) / 4; - assert(numCharacters != 0); - - // Allocate a buffer of the right number of characters. - llvm::SmallVector buffer; - buffer.set_size(numCharacters); - - // Fill the buffer left-to-right. - for (unsigned stringIndex = 0; stringIndex != numCharacters; ++stringIndex) { - // The bit-index of the next hex digit. - unsigned digitBitIndex = 4 * (numCharacters - stringIndex - 1); - - // Project out 4 bits starting at 'digitIndex'. - llvm::integerPart hexDigit - = valueBits.getRawData()[digitBitIndex / llvm::integerPartWidth]; - hexDigit >>= (digitBitIndex % llvm::integerPartWidth); - hexDigit &= 0xF; - - // Map that over to a lowercase hex digit. - static const char charForHex[16] = { - '0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' - }; - buffer[stringIndex] = charForHex[hexDigit]; - } - - Out.write(buffer.data(), numCharacters); -} - -void CXXNameMangler::mangleNumber(const llvm::APSInt &Value) { - if (Value.isSigned() && Value.isNegative()) { - Out << 'n'; - Value.abs().print(Out, /*signed*/ false); - } else { - Value.print(Out, /*signed*/ false); - } -} - -void CXXNameMangler::mangleNumber(int64_t Number) { - // ::= [n] - if (Number < 0) { - Out << 'n'; - Number = -Number; - } - - Out << Number; -} - -void CXXNameMangler::mangleCallOffset(int64_t NonVirtual, int64_t Virtual) { - // ::= h _ - // ::= v _ - // ::= # non-virtual base override - // ::= _ - // # virtual base override, with vcall offset - if (!Virtual) { - Out << 'h'; - mangleNumber(NonVirtual); - Out << '_'; - return; - } - - Out << 'v'; - mangleNumber(NonVirtual); - Out << '_'; - mangleNumber(Virtual); - Out << '_'; -} - -void CXXNameMangler::manglePrefix(QualType type) { - if (const TemplateSpecializationType *TST = - type->getAs()) { - if (!mangleSubstitution(QualType(TST, 0))) { - mangleTemplatePrefix(TST->getTemplateName()); - - // FIXME: GCC does not appear to mangle the template arguments when - // the template in question is a dependent template name. Should we - // emulate that badness? - mangleTemplateArgs(TST->getArgs(), TST->getNumArgs()); - addSubstitution(QualType(TST, 0)); - } - } else if (const DependentTemplateSpecializationType *DTST - = type->getAs()) { - TemplateName Template - = getASTContext().getDependentTemplateName(DTST->getQualifier(), - DTST->getIdentifier()); - mangleTemplatePrefix(Template); - - // FIXME: GCC does not appear to mangle the template arguments when - // the template in question is a dependent template name. Should we - // emulate that badness? - mangleTemplateArgs(DTST->getArgs(), DTST->getNumArgs()); - } else { - // We use the QualType mangle type variant here because it handles - // substitutions. - mangleType(type); - } -} - -/// Mangle everything prior to the base-unresolved-name in an unresolved-name. -/// -/// \param firstQualifierLookup - the entity found by unqualified lookup -/// for the first name in the qualifier, if this is for a member expression -/// \param recursive - true if this is being called recursively, -/// i.e. if there is more prefix "to the right". -void CXXNameMangler::mangleUnresolvedPrefix(NestedNameSpecifier *qualifier, - NamedDecl *firstQualifierLookup, - bool recursive) { - - // x, ::x - // ::= [gs] - - // T::x / decltype(p)::x - // ::= sr - - // T::N::x /decltype(p)::N::x - // ::= srN + E - // - - // A::x, N::y, A::z; "gs" means leading "::" - // ::= [gs] sr + E - // - - switch (qualifier->getKind()) { - case NestedNameSpecifier::Global: - Out << "gs"; - - // We want an 'sr' unless this is the entire NNS. - if (recursive) - Out << "sr"; - - // We never want an 'E' here. - return; - - case NestedNameSpecifier::Namespace: - if (qualifier->getPrefix()) - mangleUnresolvedPrefix(qualifier->getPrefix(), firstQualifierLookup, - /*recursive*/ true); - else - Out << "sr"; - mangleSourceName(qualifier->getAsNamespace()->getIdentifier()); - break; - case NestedNameSpecifier::NamespaceAlias: - if (qualifier->getPrefix()) - mangleUnresolvedPrefix(qualifier->getPrefix(), firstQualifierLookup, - /*recursive*/ true); - else - Out << "sr"; - mangleSourceName(qualifier->getAsNamespaceAlias()->getIdentifier()); - break; - - case NestedNameSpecifier::TypeSpec: - case NestedNameSpecifier::TypeSpecWithTemplate: { - const Type *type = qualifier->getAsType(); - - // We only want to use an unresolved-type encoding if this is one of: - // - a decltype - // - a template type parameter - // - a template template parameter with arguments - // In all of these cases, we should have no prefix. - if (qualifier->getPrefix()) { - mangleUnresolvedPrefix(qualifier->getPrefix(), firstQualifierLookup, - /*recursive*/ true); - } else { - // Otherwise, all the cases want this. - Out << "sr"; - } - - // Only certain other types are valid as prefixes; enumerate them. - switch (type->getTypeClass()) { - case Type::Builtin: - case Type::Complex: - case Type::Pointer: - case Type::BlockPointer: - case Type::LValueReference: - case Type::RValueReference: - case Type::MemberPointer: - case Type::ConstantArray: - case Type::IncompleteArray: - case Type::VariableArray: - case Type::DependentSizedArray: - case Type::DependentSizedExtVector: - case Type::Vector: - case Type::ExtVector: - case Type::FunctionProto: - case Type::FunctionNoProto: - case Type::Enum: - case Type::Paren: - case Type::Elaborated: - case Type::Attributed: - case Type::Auto: - case Type::PackExpansion: - case Type::ObjCObject: - case Type::ObjCInterface: - case Type::ObjCObjectPointer: - case Type::Atomic: - llvm_unreachable("type is illegal as a nested name specifier"); - - case Type::SubstTemplateTypeParmPack: - // FIXME: not clear how to mangle this! - // template class A { - // template void foo(decltype(T::foo(U())) x...); - // }; - Out << "_SUBSTPACK_"; - break; - - // ::= - // ::= - // ::= - // (this last is not official yet) - case Type::TypeOfExpr: - case Type::TypeOf: - case Type::Decltype: - case Type::TemplateTypeParm: - case Type::UnaryTransform: - case Type::SubstTemplateTypeParm: - unresolvedType: - assert(!qualifier->getPrefix()); - - // We only get here recursively if we're followed by identifiers. - if (recursive) Out << 'N'; - - // This seems to do everything we want. It's not really - // sanctioned for a substituted template parameter, though. - mangleType(QualType(type, 0)); - - // We never want to print 'E' directly after an unresolved-type, - // so we return directly. - return; - - case Type::Typedef: - mangleSourceName(cast(type)->getDecl()->getIdentifier()); - break; - - case Type::UnresolvedUsing: - mangleSourceName(cast(type)->getDecl() - ->getIdentifier()); - break; - - case Type::Record: - mangleSourceName(cast(type)->getDecl()->getIdentifier()); - break; - - case Type::TemplateSpecialization: { - const TemplateSpecializationType *tst - = cast(type); - TemplateName name = tst->getTemplateName(); - switch (name.getKind()) { - case TemplateName::Template: - case TemplateName::QualifiedTemplate: { - TemplateDecl *temp = name.getAsTemplateDecl(); - - // If the base is a template template parameter, this is an - // unresolved type. - assert(temp && "no template for template specialization type"); - if (isa(temp)) goto unresolvedType; - - mangleSourceName(temp->getIdentifier()); - break; - } - - case TemplateName::OverloadedTemplate: - case TemplateName::DependentTemplate: - llvm_unreachable("invalid base for a template specialization type"); - - case TemplateName::SubstTemplateTemplateParm: { - SubstTemplateTemplateParmStorage *subst - = name.getAsSubstTemplateTemplateParm(); - mangleExistingSubstitution(subst->getReplacement()); - break; - } - - case TemplateName::SubstTemplateTemplateParmPack: { - // FIXME: not clear how to mangle this! - // template