clang API Documentation
00001 //===--- ASTContext.h - Context to hold long-lived AST nodes ----*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines the ASTContext interface. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_CLANG_AST_ASTCONTEXT_H 00015 #define LLVM_CLANG_AST_ASTCONTEXT_H 00016 00017 #include "clang/Basic/IdentifierTable.h" 00018 #include "clang/Basic/LangOptions.h" 00019 #include "clang/Basic/OperatorKinds.h" 00020 #include "clang/AST/Attr.h" 00021 #include "clang/AST/Decl.h" 00022 #include "clang/AST/NestedNameSpecifier.h" 00023 #include "clang/AST/PrettyPrinter.h" 00024 #include "clang/AST/TemplateName.h" 00025 #include "clang/AST/Type.h" 00026 #include "clang/AST/CanonicalType.h" 00027 #include "llvm/ADT/DenseMap.h" 00028 #include "llvm/ADT/FoldingSet.h" 00029 #include "llvm/ADT/OwningPtr.h" 00030 #include "llvm/ADT/SmallPtrSet.h" 00031 #include "llvm/Support/Allocator.h" 00032 #include <vector> 00033 00034 namespace llvm { 00035 struct fltSemantics; 00036 } 00037 00038 namespace clang { 00039 class FileManager; 00040 class ASTRecordLayout; 00041 class BlockExpr; 00042 class CharUnits; 00043 class Diagnostic; 00044 class Expr; 00045 class ExternalASTSource; 00046 class IdentifierTable; 00047 class SelectorTable; 00048 class SourceManager; 00049 class TargetInfo; 00050 // Decls 00051 class DeclContext; 00052 class CXXMethodDecl; 00053 class CXXRecordDecl; 00054 class Decl; 00055 class FieldDecl; 00056 class ObjCIvarDecl; 00057 class ObjCIvarRefExpr; 00058 class ObjCPropertyDecl; 00059 class RecordDecl; 00060 class TagDecl; 00061 class TemplateTypeParmDecl; 00062 class TranslationUnitDecl; 00063 class TypeDecl; 00064 class TypedefDecl; 00065 class UsingDecl; 00066 class UsingShadowDecl; 00067 class UnresolvedSetIterator; 00068 00069 namespace Builtin { class Context; } 00070 00071 /// \brief A vector of C++ member functions that is optimized for 00072 /// storing a single method. 00073 class CXXMethodVector { 00074 /// \brief Storage for the vector. 00075 /// 00076 /// When the low bit is zero, this is a const CXXMethodDecl *. When the 00077 /// low bit is one, this is a std::vector<const CXXMethodDecl *> *. 00078 mutable uintptr_t Storage; 00079 00080 typedef std::vector<const CXXMethodDecl *> vector_type; 00081 00082 public: 00083 CXXMethodVector() : Storage(0) { } 00084 00085 typedef const CXXMethodDecl **iterator; 00086 iterator begin() const; 00087 iterator end() const; 00088 00089 void push_back(const CXXMethodDecl *Method); 00090 void Destroy(); 00091 }; 00092 00093 /// ASTContext - This class holds long-lived AST nodes (such as types and 00094 /// decls) that can be referred to throughout the semantic analysis of a file. 00095 class ASTContext { 00096 std::vector<Type*> Types; 00097 llvm::FoldingSet<ExtQuals> ExtQualNodes; 00098 llvm::FoldingSet<ComplexType> ComplexTypes; 00099 llvm::FoldingSet<PointerType> PointerTypes; 00100 llvm::FoldingSet<BlockPointerType> BlockPointerTypes; 00101 llvm::FoldingSet<LValueReferenceType> LValueReferenceTypes; 00102 llvm::FoldingSet<RValueReferenceType> RValueReferenceTypes; 00103 llvm::FoldingSet<MemberPointerType> MemberPointerTypes; 00104 llvm::FoldingSet<ConstantArrayType> ConstantArrayTypes; 00105 llvm::FoldingSet<IncompleteArrayType> IncompleteArrayTypes; 00106 std::vector<VariableArrayType*> VariableArrayTypes; 00107 llvm::FoldingSet<DependentSizedArrayType> DependentSizedArrayTypes; 00108 llvm::FoldingSet<DependentSizedExtVectorType> DependentSizedExtVectorTypes; 00109 llvm::FoldingSet<VectorType> VectorTypes; 00110 llvm::FoldingSet<FunctionNoProtoType> FunctionNoProtoTypes; 00111 llvm::FoldingSet<FunctionProtoType> FunctionProtoTypes; 00112 llvm::FoldingSet<DependentTypeOfExprType> DependentTypeOfExprTypes; 00113 llvm::FoldingSet<DependentDecltypeType> DependentDecltypeTypes; 00114 llvm::FoldingSet<TemplateTypeParmType> TemplateTypeParmTypes; 00115 llvm::FoldingSet<SubstTemplateTypeParmType> SubstTemplateTypeParmTypes; 00116 llvm::FoldingSet<TemplateSpecializationType> TemplateSpecializationTypes; 00117 llvm::FoldingSet<QualifiedNameType> QualifiedNameTypes; 00118 llvm::FoldingSet<TypenameType> TypenameTypes; 00119 llvm::FoldingSet<ObjCInterfaceType> ObjCInterfaceTypes; 00120 llvm::FoldingSet<ObjCObjectPointerType> ObjCObjectPointerTypes; 00121 llvm::FoldingSet<ElaboratedType> ElaboratedTypes; 00122 00123 llvm::FoldingSet<QualifiedTemplateName> QualifiedTemplateNames; 00124 llvm::FoldingSet<DependentTemplateName> DependentTemplateNames; 00125 00126 /// \brief The set of nested name specifiers. 00127 /// 00128 /// This set is managed by the NestedNameSpecifier class. 00129 llvm::FoldingSet<NestedNameSpecifier> NestedNameSpecifiers; 00130 NestedNameSpecifier *GlobalNestedNameSpecifier; 00131 friend class NestedNameSpecifier; 00132 00133 /// ASTRecordLayouts - A cache mapping from RecordDecls to ASTRecordLayouts. 00134 /// This is lazily created. This is intentionally not serialized. 00135 llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*> ASTRecordLayouts; 00136 llvm::DenseMap<const ObjCContainerDecl*, const ASTRecordLayout*> ObjCLayouts; 00137 00138 /// KeyFunctions - A cache mapping from CXXRecordDecls to key functions. 00139 llvm::DenseMap<const CXXRecordDecl*, const CXXMethodDecl*> KeyFunctions; 00140 00141 /// \brief Mapping from ObjCContainers to their ObjCImplementations. 00142 llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*> ObjCImpls; 00143 00144 /// BuiltinVaListType - built-in va list type. 00145 /// This is initially null and set by Sema::LazilyCreateBuiltin when 00146 /// a builtin that takes a valist is encountered. 00147 QualType BuiltinVaListType; 00148 00149 /// ObjCIdType - a pseudo built-in typedef type (set by Sema). 00150 QualType ObjCIdTypedefType; 00151 00152 /// ObjCSelType - another pseudo built-in typedef type (set by Sema). 00153 QualType ObjCSelTypedefType; 00154 00155 /// ObjCProtoType - another pseudo built-in typedef type (set by Sema). 00156 QualType ObjCProtoType; 00157 const RecordType *ProtoStructType; 00158 00159 /// ObjCClassType - another pseudo built-in typedef type (set by Sema). 00160 QualType ObjCClassTypedefType; 00161 00162 QualType ObjCConstantStringType; 00163 RecordDecl *CFConstantStringTypeDecl; 00164 00165 RecordDecl *ObjCFastEnumerationStateTypeDecl; 00166 00167 /// \brief The type for the C FILE type. 00168 TypeDecl *FILEDecl; 00169 00170 /// \brief The type for the C jmp_buf type. 00171 TypeDecl *jmp_bufDecl; 00172 00173 /// \brief The type for the C sigjmp_buf type. 00174 TypeDecl *sigjmp_bufDecl; 00175 00176 /// \brief Type for the Block descriptor for Blocks CodeGen. 00177 RecordDecl *BlockDescriptorType; 00178 00179 /// \brief Type for the Block descriptor for Blocks CodeGen. 00180 RecordDecl *BlockDescriptorExtendedType; 00181 00182 /// \brief Keeps track of all declaration attributes. 00183 /// 00184 /// Since so few decls have attrs, we keep them in a hash map instead of 00185 /// wasting space in the Decl class. 00186 llvm::DenseMap<const Decl*, Attr*> DeclAttrs; 00187 00188 /// \brief Keeps track of the static data member templates from which 00189 /// static data members of class template specializations were instantiated. 00190 /// 00191 /// This data structure stores the mapping from instantiations of static 00192 /// data members to the static data member representations within the 00193 /// class template from which they were instantiated along with the kind 00194 /// of instantiation or specialization (a TemplateSpecializationKind - 1). 00195 /// 00196 /// Given the following example: 00197 /// 00198 /// \code 00199 /// template<typename T> 00200 /// struct X { 00201 /// static T value; 00202 /// }; 00203 /// 00204 /// template<typename T> 00205 /// T X<T>::value = T(17); 00206 /// 00207 /// int *x = &X<int>::value; 00208 /// \endcode 00209 /// 00210 /// This mapping will contain an entry that maps from the VarDecl for 00211 /// X<int>::value to the corresponding VarDecl for X<T>::value (within the 00212 /// class template X) and will be marked TSK_ImplicitInstantiation. 00213 llvm::DenseMap<const VarDecl *, MemberSpecializationInfo *> 00214 InstantiatedFromStaticDataMember; 00215 00216 /// \brief Keeps track of the declaration from which a UsingDecl was 00217 /// created during instantiation. The source declaration is always 00218 /// a UsingDecl, an UnresolvedUsingValueDecl, or an 00219 /// UnresolvedUsingTypenameDecl. 00220 /// 00221 /// For example: 00222 /// \code 00223 /// template<typename T> 00224 /// struct A { 00225 /// void f(); 00226 /// }; 00227 /// 00228 /// template<typename T> 00229 /// struct B : A<T> { 00230 /// using A<T>::f; 00231 /// }; 00232 /// 00233 /// template struct B<int>; 00234 /// \endcode 00235 /// 00236 /// This mapping will contain an entry that maps from the UsingDecl in 00237 /// B<int> to the UnresolvedUsingDecl in B<T>. 00238 llvm::DenseMap<UsingDecl *, NamedDecl *> InstantiatedFromUsingDecl; 00239 00240 llvm::DenseMap<UsingShadowDecl*, UsingShadowDecl*> 00241 InstantiatedFromUsingShadowDecl; 00242 00243 llvm::DenseMap<FieldDecl *, FieldDecl *> InstantiatedFromUnnamedFieldDecl; 00244 00245 /// \brief Mapping that stores the methods overridden by a given C++ 00246 /// member function. 00247 /// 00248 /// Since most C++ member functions aren't virtual and therefore 00249 /// don't override anything, we store the overridden functions in 00250 /// this map on the side rather than within the CXXMethodDecl structure. 00251 llvm::DenseMap<const CXXMethodDecl *, CXXMethodVector> OverriddenMethods; 00252 00253 TranslationUnitDecl *TUDecl; 00254 00255 /// SourceMgr - The associated SourceManager object. 00256 SourceManager &SourceMgr; 00257 00258 /// LangOpts - The language options used to create the AST associated with 00259 /// this ASTContext object. 00260 LangOptions LangOpts; 00261 00262 /// \brief Whether we have already loaded comment source ranges from an 00263 /// external source. 00264 bool LoadedExternalComments; 00265 00266 /// MallocAlloc/BumpAlloc - The allocator objects used to create AST objects. 00267 bool FreeMemory; 00268 llvm::MallocAllocator MallocAlloc; 00269 llvm::BumpPtrAllocator BumpAlloc; 00270 00271 /// \brief Mapping from declarations to their comments, once we have 00272 /// already looked up the comment associated with a given declaration. 00273 llvm::DenseMap<const Decl *, std::string> DeclComments; 00274 00275 public: 00276 const TargetInfo &Target; 00277 IdentifierTable &Idents; 00278 SelectorTable &Selectors; 00279 Builtin::Context &BuiltinInfo; 00280 DeclarationNameTable DeclarationNames; 00281 llvm::OwningPtr<ExternalASTSource> ExternalSource; 00282 clang::PrintingPolicy PrintingPolicy; 00283 00284 // Typedefs which may be provided defining the structure of Objective-C 00285 // pseudo-builtins 00286 QualType ObjCIdRedefinitionType; 00287 QualType ObjCClassRedefinitionType; 00288 QualType ObjCSelRedefinitionType; 00289 00290 /// \brief Source ranges for all of the comments in the source file, 00291 /// sorted in order of appearance in the translation unit. 00292 std::vector<SourceRange> Comments; 00293 00294 SourceManager& getSourceManager() { return SourceMgr; } 00295 const SourceManager& getSourceManager() const { return SourceMgr; } 00296 void *Allocate(unsigned Size, unsigned Align = 8) { 00297 return FreeMemory ? MallocAlloc.Allocate(Size, Align) : 00298 BumpAlloc.Allocate(Size, Align); 00299 } 00300 void Deallocate(void *Ptr) { 00301 if (FreeMemory) 00302 MallocAlloc.Deallocate(Ptr); 00303 } 00304 const LangOptions& getLangOptions() const { return LangOpts; } 00305 00306 FullSourceLoc getFullLoc(SourceLocation Loc) const { 00307 return FullSourceLoc(Loc,SourceMgr); 00308 } 00309 00310 /// \brief Retrieve the attributes for the given declaration. 00311 Attr*& getDeclAttrs(const Decl *D) { return DeclAttrs[D]; } 00312 00313 /// \brief Erase the attributes corresponding to the given declaration. 00314 void eraseDeclAttrs(const Decl *D) { DeclAttrs.erase(D); } 00315 00316 /// \brief If this variable is an instantiated static data member of a 00317 /// class template specialization, returns the templated static data member 00318 /// from which it was instantiated. 00319 MemberSpecializationInfo *getInstantiatedFromStaticDataMember( 00320 const VarDecl *Var); 00321 00322 /// \brief Note that the static data member \p Inst is an instantiation of 00323 /// the static data member template \p Tmpl of a class template. 00324 void setInstantiatedFromStaticDataMember(VarDecl *Inst, VarDecl *Tmpl, 00325 TemplateSpecializationKind TSK); 00326 00327 /// \brief If the given using decl is an instantiation of a 00328 /// (possibly unresolved) using decl from a template instantiation, 00329 /// return it. 00330 NamedDecl *getInstantiatedFromUsingDecl(UsingDecl *Inst); 00331 00332 /// \brief Remember that the using decl \p Inst is an instantiation 00333 /// of the using decl \p Pattern of a class template. 00334 void setInstantiatedFromUsingDecl(UsingDecl *Inst, NamedDecl *Pattern); 00335 00336 void setInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst, 00337 UsingShadowDecl *Pattern); 00338 UsingShadowDecl *getInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst); 00339 00340 FieldDecl *getInstantiatedFromUnnamedFieldDecl(FieldDecl *Field); 00341 00342 void setInstantiatedFromUnnamedFieldDecl(FieldDecl *Inst, FieldDecl *Tmpl); 00343 00344 // Access to the set of methods overridden by the given C++ method. 00345 typedef CXXMethodVector::iterator overridden_cxx_method_iterator; 00346 overridden_cxx_method_iterator 00347 overridden_methods_begin(const CXXMethodDecl *Method) const; 00348 00349 overridden_cxx_method_iterator 00350 overridden_methods_end(const CXXMethodDecl *Method) const; 00351 00352 /// \brief Note that the given C++ \p Method overrides the given \p 00353 /// Overridden method. 00354 void addOverriddenMethod(const CXXMethodDecl *Method, 00355 const CXXMethodDecl *Overridden); 00356 00357 TranslationUnitDecl *getTranslationUnitDecl() const { return TUDecl; } 00358 00359 00360 const char *getCommentForDecl(const Decl *D); 00361 00362 // Builtin Types. 00363 CanQualType VoidTy; 00364 CanQualType BoolTy; 00365 CanQualType CharTy; 00366 CanQualType WCharTy; // [C++ 3.9.1p5], integer type in C99. 00367 CanQualType Char16Ty; // [C++0x 3.9.1p5], integer type in C99. 00368 CanQualType Char32Ty; // [C++0x 3.9.1p5], integer type in C99. 00369 CanQualType SignedCharTy, ShortTy, IntTy, LongTy, LongLongTy, Int128Ty; 00370 CanQualType UnsignedCharTy, UnsignedShortTy, UnsignedIntTy, UnsignedLongTy; 00371 CanQualType UnsignedLongLongTy, UnsignedInt128Ty; 00372 CanQualType FloatTy, DoubleTy, LongDoubleTy; 00373 CanQualType FloatComplexTy, DoubleComplexTy, LongDoubleComplexTy; 00374 CanQualType VoidPtrTy, NullPtrTy; 00375 CanQualType OverloadTy; 00376 CanQualType DependentTy; 00377 CanQualType UndeducedAutoTy; 00378 CanQualType ObjCBuiltinIdTy, ObjCBuiltinClassTy, ObjCBuiltinSelTy; 00379 00380 ASTContext(const LangOptions& LOpts, SourceManager &SM, const TargetInfo &t, 00381 IdentifierTable &idents, SelectorTable &sels, 00382 Builtin::Context &builtins, 00383 bool FreeMemory = true, unsigned size_reserve=0); 00384 00385 ~ASTContext(); 00386 00387 /// \brief Attach an external AST source to the AST context. 00388 /// 00389 /// The external AST source provides the ability to load parts of 00390 /// the abstract syntax tree as needed from some external storage, 00391 /// e.g., a precompiled header. 00392 void setExternalSource(llvm::OwningPtr<ExternalASTSource> &Source); 00393 00394 /// \brief Retrieve a pointer to the external AST source associated 00395 /// with this AST context, if any. 00396 ExternalASTSource *getExternalSource() const { return ExternalSource.get(); } 00397 00398 void PrintStats() const; 00399 const std::vector<Type*>& getTypes() const { return Types; } 00400 00401 //===--------------------------------------------------------------------===// 00402 // Type Constructors 00403 //===--------------------------------------------------------------------===// 00404 00405 private: 00406 /// getExtQualType - Return a type with extended qualifiers. 00407 QualType getExtQualType(const Type *Base, Qualifiers Quals); 00408 00409 QualType getTypeDeclTypeSlow(const TypeDecl *Decl); 00410 00411 public: 00412 /// getAddSpaceQualType - Return the uniqued reference to the type for an 00413 /// address space qualified type with the specified type and address space. 00414 /// The resulting type has a union of the qualifiers from T and the address 00415 /// space. If T already has an address space specifier, it is silently 00416 /// replaced. 00417 QualType getAddrSpaceQualType(QualType T, unsigned AddressSpace); 00418 00419 /// getObjCGCQualType - Returns the uniqued reference to the type for an 00420 /// objc gc qualified type. The retulting type has a union of the qualifiers 00421 /// from T and the gc attribute. 00422 QualType getObjCGCQualType(QualType T, Qualifiers::GC gcAttr); 00423 00424 /// getRestrictType - Returns the uniqued reference to the type for a 00425 /// 'restrict' qualified type. The resulting type has a union of the 00426 /// qualifiers from T and 'restrict'. 00427 QualType getRestrictType(QualType T) { 00428 return T.withFastQualifiers(Qualifiers::Restrict); 00429 } 00430 00431 /// getVolatileType - Returns the uniqued reference to the type for a 00432 /// 'volatile' qualified type. The resulting type has a union of the 00433 /// qualifiers from T and 'volatile'. 00434 QualType getVolatileType(QualType T); 00435 00436 /// getConstType - Returns the uniqued reference to the type for a 00437 /// 'const' qualified type. The resulting type has a union of the 00438 /// qualifiers from T and 'const'. 00439 /// 00440 /// It can be reasonably expected that this will always be 00441 /// equivalent to calling T.withConst(). 00442 QualType getConstType(QualType T) { return T.withConst(); } 00443 00444 /// getNoReturnType - Add or remove the noreturn attribute to the given type 00445 /// which must be a FunctionType or a pointer to an allowable type or a 00446 /// BlockPointer. 00447 QualType getNoReturnType(QualType T, bool AddNoReturn = true); 00448 00449 /// getCallConvType - Adds the specified calling convention attribute to 00450 /// the given type, which must be a FunctionType or a pointer to an 00451 /// allowable type. 00452 QualType getCallConvType(QualType T, CallingConv CallConv); 00453 00454 /// getComplexType - Return the uniqued reference to the type for a complex 00455 /// number with the specified element type. 00456 QualType getComplexType(QualType T); 00457 CanQualType getComplexType(CanQualType T) { 00458 return CanQualType::CreateUnsafe(getComplexType((QualType) T)); 00459 } 00460 00461 /// getPointerType - Return the uniqued reference to the type for a pointer to 00462 /// the specified type. 00463 QualType getPointerType(QualType T); 00464 CanQualType getPointerType(CanQualType T) { 00465 return CanQualType::CreateUnsafe(getPointerType((QualType) T)); 00466 } 00467 00468 /// getBlockPointerType - Return the uniqued reference to the type for a block 00469 /// of the specified type. 00470 QualType getBlockPointerType(QualType T); 00471 00472 /// This gets the struct used to keep track of the descriptor for pointer to 00473 /// blocks. 00474 QualType getBlockDescriptorType(); 00475 00476 // Set the type for a Block descriptor type. 00477 void setBlockDescriptorType(QualType T); 00478 /// Get the BlockDescriptorType type, or NULL if it hasn't yet been built. 00479 QualType getRawBlockdescriptorType() { 00480 if (BlockDescriptorType) 00481 return getTagDeclType(BlockDescriptorType); 00482 return QualType(); 00483 } 00484 00485 /// This gets the struct used to keep track of the extended descriptor for 00486 /// pointer to blocks. 00487 QualType getBlockDescriptorExtendedType(); 00488 00489 // Set the type for a Block descriptor extended type. 00490 void setBlockDescriptorExtendedType(QualType T); 00491 /// Get the BlockDescriptorExtendedType type, or NULL if it hasn't yet been 00492 /// built. 00493 QualType getRawBlockdescriptorExtendedType() { 00494 if (BlockDescriptorExtendedType) 00495 return getTagDeclType(BlockDescriptorExtendedType); 00496 return QualType(); 00497 } 00498 00499 /// This gets the struct used to keep track of pointer to blocks, complete 00500 /// with captured variables. 00501 QualType getBlockParmType(bool BlockHasCopyDispose, 00502 llvm::SmallVector<const Expr *, 8> &BDRDs); 00503 00504 /// This builds the struct used for __block variables. 00505 QualType BuildByRefType(const char *DeclName, QualType Ty); 00506 00507 /// Returns true iff we need copy/dispose helpers for the given type. 00508 bool BlockRequiresCopying(QualType Ty); 00509 00510 /// getLValueReferenceType - Return the uniqued reference to the type for an 00511 /// lvalue reference to the specified type. 00512 QualType getLValueReferenceType(QualType T, bool SpelledAsLValue = true); 00513 00514 /// getRValueReferenceType - Return the uniqued reference to the type for an 00515 /// rvalue reference to the specified type. 00516 QualType getRValueReferenceType(QualType T); 00517 00518 /// getMemberPointerType - Return the uniqued reference to the type for a 00519 /// member pointer to the specified type in the specified class. The class 00520 /// is a Type because it could be a dependent name. 00521 QualType getMemberPointerType(QualType T, const Type *Cls); 00522 00523 /// getVariableArrayType - Returns a non-unique reference to the type for a 00524 /// variable array of the specified element type. 00525 QualType getVariableArrayType(QualType EltTy, Expr *NumElts, 00526 ArrayType::ArraySizeModifier ASM, 00527 unsigned EltTypeQuals, 00528 SourceRange Brackets); 00529 00530 /// getDependentSizedArrayType - Returns a non-unique reference to 00531 /// the type for a dependently-sized array of the specified element 00532 /// type. FIXME: We will need these to be uniqued, or at least 00533 /// comparable, at some point. 00534 QualType getDependentSizedArrayType(QualType EltTy, Expr *NumElts, 00535 ArrayType::ArraySizeModifier ASM, 00536 unsigned EltTypeQuals, 00537 SourceRange Brackets); 00538 00539 /// getIncompleteArrayType - Returns a unique reference to the type for a 00540 /// incomplete array of the specified element type. 00541 QualType getIncompleteArrayType(QualType EltTy, 00542 ArrayType::ArraySizeModifier ASM, 00543 unsigned EltTypeQuals); 00544 00545 /// getConstantArrayType - Return the unique reference to the type for a 00546 /// constant array of the specified element type. 00547 QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, 00548 ArrayType::ArraySizeModifier ASM, 00549 unsigned EltTypeQuals); 00550 00551 /// getVectorType - Return the unique reference to a vector type of 00552 /// the specified element type and size. VectorType must be a built-in type. 00553 QualType getVectorType(QualType VectorType, unsigned NumElts, 00554 bool AltiVec, bool IsPixel); 00555 00556 /// getExtVectorType - Return the unique reference to an extended vector type 00557 /// of the specified element type and size. VectorType must be a built-in 00558 /// type. 00559 QualType getExtVectorType(QualType VectorType, unsigned NumElts); 00560 00561 /// getDependentSizedExtVectorType - Returns a non-unique reference to 00562 /// the type for a dependently-sized vector of the specified element 00563 /// type. FIXME: We will need these to be uniqued, or at least 00564 /// comparable, at some point. 00565 QualType getDependentSizedExtVectorType(QualType VectorType, 00566 Expr *SizeExpr, 00567 SourceLocation AttrLoc); 00568 00569 /// getFunctionNoProtoType - Return a K&R style C function type like 'int()'. 00570 /// 00571 QualType getFunctionNoProtoType(QualType ResultTy, bool NoReturn = false, 00572 CallingConv CallConv = CC_Default); 00573 00574 /// getFunctionType - Return a normal function type with a typed argument 00575 /// list. isVariadic indicates whether the argument list includes '...'. 00576 QualType getFunctionType(QualType ResultTy, const QualType *ArgArray, 00577 unsigned NumArgs, bool isVariadic, 00578 unsigned TypeQuals, bool hasExceptionSpec, 00579 bool hasAnyExceptionSpec, 00580 unsigned NumExs, const QualType *ExArray, 00581 bool NoReturn, 00582 CallingConv CallConv); 00583 00584 /// getTypeDeclType - Return the unique reference to the type for 00585 /// the specified type declaration. 00586 QualType getTypeDeclType(const TypeDecl *Decl, 00587 const TypeDecl *PrevDecl = 0) { 00588 assert(Decl && "Passed null for Decl param"); 00589 if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0); 00590 00591 if (PrevDecl) { 00592 assert(PrevDecl->TypeForDecl && "previous decl has no TypeForDecl"); 00593 Decl->TypeForDecl = PrevDecl->TypeForDecl; 00594 return QualType(PrevDecl->TypeForDecl, 0); 00595 } 00596 00597 return getTypeDeclTypeSlow(Decl); 00598 } 00599 00600 /// getTypedefType - Return the unique reference to the type for the 00601 /// specified typename decl. 00602 QualType getTypedefType(const TypedefDecl *Decl); 00603 00604 QualType getInjectedClassNameType(CXXRecordDecl *Decl, QualType TST); 00605 00606 QualType getSubstTemplateTypeParmType(const TemplateTypeParmType *Replaced, 00607 QualType Replacement); 00608 00609 QualType getTemplateTypeParmType(unsigned Depth, unsigned Index, 00610 bool ParameterPack, 00611 IdentifierInfo *Name = 0); 00612 00613 QualType getTemplateSpecializationType(TemplateName T, 00614 const TemplateArgument *Args, 00615 unsigned NumArgs, 00616 QualType Canon = QualType()); 00617 00618 QualType getTemplateSpecializationType(TemplateName T, 00619 const TemplateArgumentListInfo &Args, 00620 QualType Canon = QualType()); 00621 00622 TypeSourceInfo * 00623 getTemplateSpecializationTypeInfo(TemplateName T, SourceLocation TLoc, 00624 const TemplateArgumentListInfo &Args, 00625 QualType Canon = QualType()); 00626 00627 QualType getQualifiedNameType(NestedNameSpecifier *NNS, 00628 QualType NamedType); 00629 QualType getTypenameType(NestedNameSpecifier *NNS, 00630 const IdentifierInfo *Name, 00631 QualType Canon = QualType()); 00632 QualType getTypenameType(NestedNameSpecifier *NNS, 00633 const TemplateSpecializationType *TemplateId, 00634 QualType Canon = QualType()); 00635 QualType getElaboratedType(QualType UnderlyingType, 00636 ElaboratedType::TagKind Tag); 00637 00638 QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl, 00639 ObjCProtocolDecl **Protocols = 0, 00640 unsigned NumProtocols = 0); 00641 00642 /// getObjCObjectPointerType - Return a ObjCObjectPointerType type for the 00643 /// given interface decl and the conforming protocol list. 00644 QualType getObjCObjectPointerType(QualType OIT, 00645 ObjCProtocolDecl **ProtocolList = 0, 00646 unsigned NumProtocols = 0, 00647 unsigned Quals = 0); 00648 00649 /// getTypeOfType - GCC extension. 00650 QualType getTypeOfExprType(Expr *e); 00651 QualType getTypeOfType(QualType t); 00652 00653 /// getDecltypeType - C++0x decltype. 00654 QualType getDecltypeType(Expr *e); 00655 00656 /// getTagDeclType - Return the unique reference to the type for the 00657 /// specified TagDecl (struct/union/class/enum) decl. 00658 QualType getTagDeclType(const TagDecl *Decl); 00659 00660 /// getSizeType - Return the unique type for "size_t" (C99 7.17), defined 00661 /// in <stddef.h>. The sizeof operator requires this (C99 6.5.3.4p4). 00662 CanQualType getSizeType() const; 00663 00664 /// getWCharType - In C++, this returns the unique wchar_t type. In C99, this 00665 /// returns a type compatible with the type defined in <stddef.h> as defined 00666 /// by the target. 00667 QualType getWCharType() const { return WCharTy; } 00668 00669 /// getSignedWCharType - Return the type of "signed wchar_t". 00670 /// Used when in C++, as a GCC extension. 00671 QualType getSignedWCharType() const; 00672 00673 /// getUnsignedWCharType - Return the type of "unsigned wchar_t". 00674 /// Used when in C++, as a GCC extension. 00675 QualType getUnsignedWCharType() const; 00676 00677 /// getPointerDiffType - Return the unique type for "ptrdiff_t" (ref?) 00678 /// defined in <stddef.h>. Pointer - pointer requires this (C99 6.5.6p9). 00679 QualType getPointerDiffType() const; 00680 00681 // getCFConstantStringType - Return the C structure type used to represent 00682 // constant CFStrings. 00683 QualType getCFConstantStringType(); 00684 00685 /// Get the structure type used to representation CFStrings, or NULL 00686 /// if it hasn't yet been built. 00687 QualType getRawCFConstantStringType() { 00688 if (CFConstantStringTypeDecl) 00689 return getTagDeclType(CFConstantStringTypeDecl); 00690 return QualType(); 00691 } 00692 void setCFConstantStringType(QualType T); 00693 00694 // This setter/getter represents the ObjC type for an NSConstantString. 00695 void setObjCConstantStringInterface(ObjCInterfaceDecl *Decl); 00696 QualType getObjCConstantStringInterface() const { 00697 return ObjCConstantStringType; 00698 } 00699 00700 //// This gets the struct used to keep track of fast enumerations. 00701 QualType getObjCFastEnumerationStateType(); 00702 00703 /// Get the ObjCFastEnumerationState type, or NULL if it hasn't yet 00704 /// been built. 00705 QualType getRawObjCFastEnumerationStateType() { 00706 if (ObjCFastEnumerationStateTypeDecl) 00707 return getTagDeclType(ObjCFastEnumerationStateTypeDecl); 00708 return QualType(); 00709 } 00710 00711 void setObjCFastEnumerationStateType(QualType T); 00712 00713 /// \brief Set the type for the C FILE type. 00714 void setFILEDecl(TypeDecl *FILEDecl) { this->FILEDecl = FILEDecl; } 00715 00716 /// \brief Retrieve the C FILE type. 00717 QualType getFILEType() { 00718 if (FILEDecl) 00719 return getTypeDeclType(FILEDecl); 00720 return QualType(); 00721 } 00722 00723 /// \brief Set the type for the C jmp_buf type. 00724 void setjmp_bufDecl(TypeDecl *jmp_bufDecl) { 00725 this->jmp_bufDecl = jmp_bufDecl; 00726 } 00727 00728 /// \brief Retrieve the C jmp_buf type. 00729 QualType getjmp_bufType() { 00730 if (jmp_bufDecl) 00731 return getTypeDeclType(jmp_bufDecl); 00732 return QualType(); 00733 } 00734 00735 /// \brief Set the type for the C sigjmp_buf type. 00736 void setsigjmp_bufDecl(TypeDecl *sigjmp_bufDecl) { 00737 this->sigjmp_bufDecl = sigjmp_bufDecl; 00738 } 00739 00740 /// \brief Retrieve the C sigjmp_buf type. 00741 QualType getsigjmp_bufType() { 00742 if (sigjmp_bufDecl) 00743 return getTypeDeclType(sigjmp_bufDecl); 00744 return QualType(); 00745 } 00746 00747 /// getObjCEncodingForType - Emit the ObjC type encoding for the 00748 /// given type into \arg S. If \arg NameFields is specified then 00749 /// record field names are also encoded. 00750 void getObjCEncodingForType(QualType t, std::string &S, 00751 const FieldDecl *Field=0); 00752 00753 void getLegacyIntegralTypeEncoding(QualType &t) const; 00754 00755 // Put the string version of type qualifiers into S. 00756 void getObjCEncodingForTypeQualifier(Decl::ObjCDeclQualifier QT, 00757 std::string &S) const; 00758 00759 /// getObjCEncodingForMethodDecl - Return the encoded type for this method 00760 /// declaration. 00761 void getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl, std::string &S); 00762 00763 /// getObjCEncodingForBlockDecl - Return the encoded type for this block 00764 /// declaration. 00765 void getObjCEncodingForBlock(const BlockExpr *Expr, std::string& S); 00766 00767 /// getObjCEncodingForPropertyDecl - Return the encoded type for 00768 /// this method declaration. If non-NULL, Container must be either 00769 /// an ObjCCategoryImplDecl or ObjCImplementationDecl; it should 00770 /// only be NULL when getting encodings for protocol properties. 00771 void getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD, 00772 const Decl *Container, 00773 std::string &S); 00774 00775 bool ProtocolCompatibleWithProtocol(ObjCProtocolDecl *lProto, 00776 ObjCProtocolDecl *rProto); 00777 00778 /// getObjCEncodingTypeSize returns size of type for objective-c encoding 00779 /// purpose in characters. 00780 CharUnits getObjCEncodingTypeSize(QualType t); 00781 00782 /// This setter/getter represents the ObjC 'id' type. It is setup lazily, by 00783 /// Sema. id is always a (typedef for a) pointer type, a pointer to a struct. 00784 QualType getObjCIdType() const { return ObjCIdTypedefType; } 00785 void setObjCIdType(QualType T); 00786 00787 void setObjCSelType(QualType T); 00788 QualType getObjCSelType() const { return ObjCSelTypedefType; } 00789 00790 void setObjCProtoType(QualType QT); 00791 QualType getObjCProtoType() const { return ObjCProtoType; } 00792 00793 /// This setter/getter repreents the ObjC 'Class' type. It is setup lazily, by 00794 /// Sema. 'Class' is always a (typedef for a) pointer type, a pointer to a 00795 /// struct. 00796 QualType getObjCClassType() const { return ObjCClassTypedefType; } 00797 void setObjCClassType(QualType T); 00798 00799 void setBuiltinVaListType(QualType T); 00800 QualType getBuiltinVaListType() const { return BuiltinVaListType; } 00801 00802 /// getCVRQualifiedType - Returns a type with additional const, 00803 /// volatile, or restrict qualifiers. 00804 QualType getCVRQualifiedType(QualType T, unsigned CVR) { 00805 return getQualifiedType(T, Qualifiers::fromCVRMask(CVR)); 00806 } 00807 00808 /// getQualifiedType - Returns a type with additional qualifiers. 00809 QualType getQualifiedType(QualType T, Qualifiers Qs) { 00810 if (!Qs.hasNonFastQualifiers()) 00811 return T.withFastQualifiers(Qs.getFastQualifiers()); 00812 QualifierCollector Qc(Qs); 00813 const Type *Ptr = Qc.strip(T); 00814 return getExtQualType(Ptr, Qc); 00815 } 00816 00817 /// getQualifiedType - Returns a type with additional qualifiers. 00818 QualType getQualifiedType(const Type *T, Qualifiers Qs) { 00819 if (!Qs.hasNonFastQualifiers()) 00820 return QualType(T, Qs.getFastQualifiers()); 00821 return getExtQualType(T, Qs); 00822 } 00823 00824 DeclarationName getNameForTemplate(TemplateName Name); 00825 00826 TemplateName getOverloadedTemplateName(UnresolvedSetIterator Begin, 00827 UnresolvedSetIterator End); 00828 00829 TemplateName getQualifiedTemplateName(NestedNameSpecifier *NNS, 00830 bool TemplateKeyword, 00831 TemplateDecl *Template); 00832 00833 TemplateName getDependentTemplateName(NestedNameSpecifier *NNS, 00834 const IdentifierInfo *Name); 00835 TemplateName getDependentTemplateName(NestedNameSpecifier *NNS, 00836 OverloadedOperatorKind Operator); 00837 00838 enum GetBuiltinTypeError { 00839 GE_None, //< No error 00840 GE_Missing_stdio, //< Missing a type from <stdio.h> 00841 GE_Missing_setjmp //< Missing a type from <setjmp.h> 00842 }; 00843 00844 /// GetBuiltinType - Return the type for the specified builtin. 00845 QualType GetBuiltinType(unsigned ID, GetBuiltinTypeError &Error); 00846 00847 private: 00848 CanQualType getFromTargetType(unsigned Type) const; 00849 00850 //===--------------------------------------------------------------------===// 00851 // Type Predicates. 00852 //===--------------------------------------------------------------------===// 00853 00854 public: 00855 /// getObjCGCAttr - Returns one of GCNone, Weak or Strong objc's 00856 /// garbage collection attribute. 00857 /// 00858 Qualifiers::GC getObjCGCAttrKind(const QualType &Ty) const; 00859 00860 /// isObjCNSObjectType - Return true if this is an NSObject object with 00861 /// its NSObject attribute set. 00862 bool isObjCNSObjectType(QualType Ty) const; 00863 00864 //===--------------------------------------------------------------------===// 00865 // Type Sizing and Analysis 00866 //===--------------------------------------------------------------------===// 00867 00868 /// getFloatTypeSemantics - Return the APFloat 'semantics' for the specified 00869 /// scalar floating point type. 00870 const llvm::fltSemantics &getFloatTypeSemantics(QualType T) const; 00871 00872 /// getTypeInfo - Get the size and alignment of the specified complete type in 00873 /// bits. 00874 std::pair<uint64_t, unsigned> getTypeInfo(const Type *T); 00875 std::pair<uint64_t, unsigned> getTypeInfo(QualType T) { 00876 return getTypeInfo(T.getTypePtr()); 00877 } 00878 00879 /// getTypeSize - Return the size of the specified type, in bits. This method 00880 /// does not work on incomplete types. 00881 uint64_t getTypeSize(QualType T) { 00882 return getTypeInfo(T).first; 00883 } 00884 uint64_t getTypeSize(const Type *T) { 00885 return getTypeInfo(T).first; 00886 } 00887 00888 /// getCharWidth - Return the size of the character type, in bits 00889 uint64_t getCharWidth() { 00890 return getTypeSize(CharTy); 00891 } 00892 00893 /// getTypeSizeInChars - Return the size of the specified type, in characters. 00894 /// This method does not work on incomplete types. 00895 CharUnits getTypeSizeInChars(QualType T); 00896 CharUnits getTypeSizeInChars(const Type *T); 00897 00898 /// getTypeAlign - Return the ABI-specified alignment of a type, in bits. 00899 /// This method does not work on incomplete types. 00900 unsigned getTypeAlign(QualType T) { 00901 return getTypeInfo(T).second; 00902 } 00903 unsigned getTypeAlign(const Type *T) { 00904 return getTypeInfo(T).second; 00905 } 00906 00907 /// getTypeAlignInChars - Return the ABI-specified alignment of a type, in 00908 /// characters. This method does not work on incomplete types. 00909 CharUnits getTypeAlignInChars(QualType T); 00910 CharUnits getTypeAlignInChars(const Type *T); 00911 00912 /// getPreferredTypeAlign - Return the "preferred" alignment of the specified 00913 /// type for the current target in bits. This can be different than the ABI 00914 /// alignment in cases where it is beneficial for performance to overalign 00915 /// a data type. 00916 unsigned getPreferredTypeAlign(const Type *T); 00917 00918 /// getDeclAlign - Return a conservative estimate of the alignment of 00919 /// the specified decl. Note that bitfields do not have a valid alignment, so 00920 /// this method will assert on them. 00921 /// If @p RefAsPointee, references are treated like their underlying type 00922 /// (for alignof), else they're treated like pointers (for CodeGen). 00923 CharUnits getDeclAlign(const Decl *D, bool RefAsPointee = false); 00924 00925 /// getASTRecordLayout - Get or compute information about the layout of the 00926 /// specified record (struct/union/class), which indicates its size and field 00927 /// position information. 00928 const ASTRecordLayout &getASTRecordLayout(const RecordDecl *D); 00929 00930 /// getASTObjCInterfaceLayout - Get or compute information about the 00931 /// layout of the specified Objective-C interface. 00932 const ASTRecordLayout &getASTObjCInterfaceLayout(const ObjCInterfaceDecl *D); 00933 00934 /// getASTObjCImplementationLayout - Get or compute information about 00935 /// the layout of the specified Objective-C implementation. This may 00936 /// differ from the interface if synthesized ivars are present. 00937 const ASTRecordLayout & 00938 getASTObjCImplementationLayout(const ObjCImplementationDecl *D); 00939 00940 /// getKeyFunction - Get the key function for the given record decl. 00941 /// The key function is, according to the Itanium C++ ABI section 5.2.3: 00942 /// 00943 /// ...the first non-pure virtual function that is not inline at the point 00944 /// of class definition. 00945 const CXXMethodDecl *getKeyFunction(const CXXRecordDecl *RD); 00946 00947 void CollectObjCIvars(const ObjCInterfaceDecl *OI, 00948 llvm::SmallVectorImpl<FieldDecl*> &Fields); 00949 00950 void ShallowCollectObjCIvars(const ObjCInterfaceDecl *OI, 00951 llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars); 00952 void CollectNonClassIvars(const ObjCInterfaceDecl *OI, 00953 llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars); 00954 unsigned CountSynthesizedIvars(const ObjCInterfaceDecl *OI); 00955 unsigned CountProtocolSynthesizedIvars(const ObjCProtocolDecl *PD); 00956 void CollectInheritedProtocols(const Decl *CDecl, 00957 llvm::SmallPtrSet<ObjCProtocolDecl*, 8> &Protocols); 00958 00959 //===--------------------------------------------------------------------===// 00960 // Type Operators 00961 //===--------------------------------------------------------------------===// 00962 00963 /// getCanonicalType - Return the canonical (structural) type corresponding to 00964 /// the specified potentially non-canonical type. The non-canonical version 00965 /// of a type may have many "decorated" versions of types. Decorators can 00966 /// include typedefs, 'typeof' operators, etc. The returned type is guaranteed 00967 /// to be free of any of these, allowing two canonical types to be compared 00968 /// for exact equality with a simple pointer comparison. 00969 CanQualType getCanonicalType(QualType T); 00970 const Type *getCanonicalType(const Type *T) { 00971 return T->getCanonicalTypeInternal().getTypePtr(); 00972 } 00973 00974 /// getCanonicalParamType - Return the canonical parameter type 00975 /// corresponding to the specific potentially non-canonical one. 00976 /// Qualifiers are stripped off, functions are turned into function 00977 /// pointers, and arrays decay one level into pointers. 00978 CanQualType getCanonicalParamType(QualType T); 00979 00980 /// \brief Determine whether the given types are equivalent. 00981 bool hasSameType(QualType T1, QualType T2) { 00982 return getCanonicalType(T1) == getCanonicalType(T2); 00983 } 00984 00985 /// \brief Returns this type as a completely-unqualified array type, 00986 /// capturing the qualifiers in Quals. This will remove the minimal amount of 00987 /// sugaring from the types, similar to the behavior of 00988 /// QualType::getUnqualifiedType(). 00989 /// 00990 /// \param T is the qualified type, which may be an ArrayType 00991 /// 00992 /// \param Quals will receive the full set of qualifiers that were 00993 /// applied to the array. 00994 /// 00995 /// \returns if this is an array type, the completely unqualified array type 00996 /// that corresponds to it. Otherwise, returns T.getUnqualifiedType(). 00997 QualType getUnqualifiedArrayType(QualType T, Qualifiers &Quals); 00998 00999 /// \brief Determine whether the given types are equivalent after 01000 /// cvr-qualifiers have been removed. 01001 bool hasSameUnqualifiedType(QualType T1, QualType T2) { 01002 CanQualType CT1 = getCanonicalType(T1); 01003 CanQualType CT2 = getCanonicalType(T2); 01004 01005 Qualifiers Quals; 01006 QualType UnqualT1 = getUnqualifiedArrayType(CT1, Quals); 01007 QualType UnqualT2 = getUnqualifiedArrayType(CT2, Quals); 01008 return UnqualT1 == UnqualT2; 01009 } 01010 01011 /// \brief Retrieves the "canonical" declaration of 01012 01013 /// \brief Retrieves the "canonical" nested name specifier for a 01014 /// given nested name specifier. 01015 /// 01016 /// The canonical nested name specifier is a nested name specifier 01017 /// that uniquely identifies a type or namespace within the type 01018 /// system. For example, given: 01019 /// 01020 /// \code 01021 /// namespace N { 01022 /// struct S { 01023 /// template<typename T> struct X { typename T* type; }; 01024 /// }; 01025 /// } 01026 /// 01027 /// template<typename T> struct Y { 01028 /// typename N::S::X<T>::type member; 01029 /// }; 01030 /// \endcode 01031 /// 01032 /// Here, the nested-name-specifier for N::S::X<T>:: will be 01033 /// S::X<template-param-0-0>, since 'S' and 'X' are uniquely defined 01034 /// by declarations in the type system and the canonical type for 01035 /// the template type parameter 'T' is template-param-0-0. 01036 NestedNameSpecifier * 01037 getCanonicalNestedNameSpecifier(NestedNameSpecifier *NNS); 01038 01039 /// \brief Retrieves the canonical representation of the given 01040 /// calling convention. 01041 CallingConv getCanonicalCallConv(CallingConv CC) { 01042 if (CC == CC_C) 01043 return CC_Default; 01044 return CC; 01045 } 01046 01047 /// \brief Determines whether two calling conventions name the same 01048 /// calling convention. 01049 bool isSameCallConv(CallingConv lcc, CallingConv rcc) { 01050 return (getCanonicalCallConv(lcc) == getCanonicalCallConv(rcc)); 01051 } 01052 01053 /// \brief Retrieves the "canonical" template name that refers to a 01054 /// given template. 01055 /// 01056 /// The canonical template name is the simplest expression that can 01057 /// be used to refer to a given template. For most templates, this 01058 /// expression is just the template declaration itself. For example, 01059 /// the template std::vector can be referred to via a variety of 01060 /// names---std::vector, ::std::vector, vector (if vector is in 01061 /// scope), etc.---but all of these names map down to the same 01062 /// TemplateDecl, which is used to form the canonical template name. 01063 /// 01064 /// Dependent template names are more interesting. Here, the 01065 /// template name could be something like T::template apply or 01066 /// std::allocator<T>::template rebind, where the nested name 01067 /// specifier itself is dependent. In this case, the canonical 01068 /// template name uses the shortest form of the dependent 01069 /// nested-name-specifier, which itself contains all canonical 01070 /// types, values, and templates. 01071 TemplateName getCanonicalTemplateName(TemplateName Name); 01072 01073 /// \brief Determine whether the given template names refer to the same 01074 /// template. 01075 bool hasSameTemplateName(TemplateName X, TemplateName Y); 01076 01077 /// \brief Retrieve the "canonical" template argument. 01078 /// 01079 /// The canonical template argument is the simplest template argument 01080 /// (which may be a type, value, expression, or declaration) that 01081 /// expresses the value of the argument. 01082 TemplateArgument getCanonicalTemplateArgument(const TemplateArgument &Arg); 01083 01084 /// Type Query functions. If the type is an instance of the specified class, 01085 /// return the Type pointer for the underlying maximally pretty type. This 01086 /// is a member of ASTContext because this may need to do some amount of 01087 /// canonicalization, e.g. to move type qualifiers into the element type. 01088 const ArrayType *getAsArrayType(QualType T); 01089 const ConstantArrayType *getAsConstantArrayType(QualType T) { 01090 return dyn_cast_or_null<ConstantArrayType>(getAsArrayType(T)); 01091 } 01092 const VariableArrayType *getAsVariableArrayType(QualType T) { 01093 return dyn_cast_or_null<VariableArrayType>(getAsArrayType(T)); 01094 } 01095 const IncompleteArrayType *getAsIncompleteArrayType(QualType T) { 01096 return dyn_cast_or_null<IncompleteArrayType>(getAsArrayType(T)); 01097 } 01098 const DependentSizedArrayType *getAsDependentSizedArrayType(QualType T) { 01099 return dyn_cast_or_null<DependentSizedArrayType>(getAsArrayType(T)); 01100 } 01101 01102 /// getBaseElementType - Returns the innermost element type of an array type. 01103 /// For example, will return "int" for int[m][n] 01104 QualType getBaseElementType(const ArrayType *VAT); 01105 01106 /// getBaseElementType - Returns the innermost element type of a type 01107 /// (which needn't actually be an array type). 01108 QualType getBaseElementType(QualType QT); 01109 01110 /// getConstantArrayElementCount - Returns number of constant array elements. 01111 uint64_t getConstantArrayElementCount(const ConstantArrayType *CA) const; 01112 01113 /// getArrayDecayedType - Return the properly qualified result of decaying the 01114 /// specified array type to a pointer. This operation is non-trivial when 01115 /// handling typedefs etc. The canonical type of "T" must be an array type, 01116 /// this returns a pointer to a properly qualified element of the array. 01117 /// 01118 /// See C99 6.7.5.3p7 and C99 6.3.2.1p3. 01119 QualType getArrayDecayedType(QualType T); 01120 01121 /// getPromotedIntegerType - Returns the type that Promotable will 01122 /// promote to: C99 6.3.1.1p2, assuming that Promotable is a promotable 01123 /// integer type. 01124 QualType getPromotedIntegerType(QualType PromotableType); 01125 01126 /// \brief Whether this is a promotable bitfield reference according 01127 /// to C99 6.3.1.1p2, bullet 2 (and GCC extensions). 01128 /// 01129 /// \returns the type this bit-field will promote to, or NULL if no 01130 /// promotion occurs. 01131 QualType isPromotableBitField(Expr *E); 01132 01133 /// getIntegerTypeOrder - Returns the highest ranked integer type: 01134 /// C99 6.3.1.8p1. If LHS > RHS, return 1. If LHS == RHS, return 0. If 01135 /// LHS < RHS, return -1. 01136 int getIntegerTypeOrder(QualType LHS, QualType RHS); 01137 01138 /// getFloatingTypeOrder - Compare the rank of the two specified floating 01139 /// point types, ignoring the domain of the type (i.e. 'double' == 01140 /// '_Complex double'). If LHS > RHS, return 1. If LHS == RHS, return 0. If 01141 /// LHS < RHS, return -1. 01142 int getFloatingTypeOrder(QualType LHS, QualType RHS); 01143 01144 /// getFloatingTypeOfSizeWithinDomain - Returns a real floating 01145 /// point or a complex type (based on typeDomain/typeSize). 01146 /// 'typeDomain' is a real floating point or complex type. 01147 /// 'typeSize' is a real floating point or complex type. 01148 QualType getFloatingTypeOfSizeWithinDomain(QualType typeSize, 01149 QualType typeDomain) const; 01150 01151 private: 01152 // Helper for integer ordering 01153 unsigned getIntegerRank(Type* T); 01154 01155 public: 01156 01157 //===--------------------------------------------------------------------===// 01158 // Type Compatibility Predicates 01159 //===--------------------------------------------------------------------===// 01160 01161 /// Compatibility predicates used to check assignment expressions. 01162 bool typesAreCompatible(QualType, QualType); // C99 6.2.7p1 01163 01164 bool typesAreBlockPointerCompatible(QualType, QualType); 01165 01166 bool isObjCIdType(QualType T) const { 01167 return T == ObjCIdTypedefType; 01168 } 01169 bool isObjCClassType(QualType T) const { 01170 return T == ObjCClassTypedefType; 01171 } 01172 bool isObjCSelType(QualType T) const { 01173 return T == ObjCSelTypedefType; 01174 } 01175 bool QualifiedIdConformsQualifiedId(QualType LHS, QualType RHS); 01176 bool ObjCQualifiedIdTypesAreCompatible(QualType LHS, QualType RHS, 01177 bool ForCompare); 01178 01179 // Check the safety of assignment from LHS to RHS 01180 bool canAssignObjCInterfaces(const ObjCObjectPointerType *LHSOPT, 01181 const ObjCObjectPointerType *RHSOPT); 01182 bool canAssignObjCInterfaces(const ObjCInterfaceType *LHS, 01183 const ObjCInterfaceType *RHS); 01184 bool canAssignObjCInterfacesInBlockPointer( 01185 const ObjCObjectPointerType *LHSOPT, 01186 const ObjCObjectPointerType *RHSOPT); 01187 bool areComparableObjCPointerTypes(QualType LHS, QualType RHS); 01188 QualType areCommonBaseCompatible(const ObjCObjectPointerType *LHSOPT, 01189 const ObjCObjectPointerType *RHSOPT); 01190 01191 // Functions for calculating composite types 01192 QualType mergeTypes(QualType, QualType, bool OfBlockPointer=false); 01193 QualType mergeFunctionTypes(QualType, QualType, bool OfBlockPointer=false); 01194 01195 /// UsualArithmeticConversionsType - handles the various conversions 01196 /// that are common to binary operators (C99 6.3.1.8, C++ [expr]p9) 01197 /// and returns the result type of that conversion. 01198 QualType UsualArithmeticConversionsType(QualType lhs, QualType rhs); 01199 01200 //===--------------------------------------------------------------------===// 01201 // Integer Predicates 01202 //===--------------------------------------------------------------------===// 01203 01204 // The width of an integer, as defined in C99 6.2.6.2. This is the number 01205 // of bits in an integer type excluding any padding bits. 01206 unsigned getIntWidth(QualType T); 01207 01208 // Per C99 6.2.5p6, for every signed integer type, there is a corresponding 01209 // unsigned integer type. This method takes a signed type, and returns the 01210 // corresponding unsigned integer type. 01211 QualType getCorrespondingUnsignedType(QualType T); 01212 01213 //===--------------------------------------------------------------------===// 01214 // Type Iterators. 01215 //===--------------------------------------------------------------------===// 01216 01217 typedef std::vector<Type*>::iterator type_iterator; 01218 typedef std::vector<Type*>::const_iterator const_type_iterator; 01219 01220 type_iterator types_begin() { return Types.begin(); } 01221 type_iterator types_end() { return Types.end(); } 01222 const_type_iterator types_begin() const { return Types.begin(); } 01223 const_type_iterator types_end() const { return Types.end(); } 01224 01225 //===--------------------------------------------------------------------===// 01226 // Integer Values 01227 //===--------------------------------------------------------------------===// 01228 01229 /// MakeIntValue - Make an APSInt of the appropriate width and 01230 /// signedness for the given \arg Value and integer \arg Type. 01231 llvm::APSInt MakeIntValue(uint64_t Value, QualType Type) { 01232 llvm::APSInt Res(getIntWidth(Type), !Type->isSignedIntegerType()); 01233 Res = Value; 01234 return Res; 01235 } 01236 01237 /// \brief Get the implementation of ObjCInterfaceDecl,or NULL if none exists. 01238 ObjCImplementationDecl *getObjCImplementation(ObjCInterfaceDecl *D); 01239 /// \brief Get the implementation of ObjCCategoryDecl, or NULL if none exists. 01240 ObjCCategoryImplDecl *getObjCImplementation(ObjCCategoryDecl *D); 01241 01242 /// \brief Set the implementation of ObjCInterfaceDecl. 01243 void setObjCImplementation(ObjCInterfaceDecl *IFaceD, 01244 ObjCImplementationDecl *ImplD); 01245 /// \brief Set the implementation of ObjCCategoryDecl. 01246 void setObjCImplementation(ObjCCategoryDecl *CatD, 01247 ObjCCategoryImplDecl *ImplD); 01248 01249 /// \brief Allocate an uninitialized TypeSourceInfo. 01250 /// 01251 /// The caller should initialize the memory held by TypeSourceInfo using 01252 /// the TypeLoc wrappers. 01253 /// 01254 /// \param T the type that will be the basis for type source info. This type 01255 /// should refer to how the declarator was written in source code, not to 01256 /// what type semantic analysis resolved the declarator to. 01257 /// 01258 /// \param Size the size of the type info to create, or 0 if the size 01259 /// should be calculated based on the type. 01260 TypeSourceInfo *CreateTypeSourceInfo(QualType T, unsigned Size = 0); 01261 01262 /// \brief Allocate a TypeSourceInfo where all locations have been 01263 /// initialized to a given location, which defaults to the empty 01264 /// location. 01265 TypeSourceInfo * 01266 getTrivialTypeSourceInfo(QualType T, SourceLocation Loc = SourceLocation()); 01267 01268 private: 01269 ASTContext(const ASTContext&); // DO NOT IMPLEMENT 01270 void operator=(const ASTContext&); // DO NOT IMPLEMENT 01271 01272 void InitBuiltinTypes(); 01273 void InitBuiltinType(CanQualType &R, BuiltinType::Kind K); 01274 01275 // Return the ObjC type encoding for a given type. 01276 void getObjCEncodingForTypeImpl(QualType t, std::string &S, 01277 bool ExpandPointedToStructures, 01278 bool ExpandStructures, 01279 const FieldDecl *Field, 01280 bool OutermostType = false, 01281 bool EncodingProperty = false); 01282 01283 const ASTRecordLayout &getObjCLayout(const ObjCInterfaceDecl *D, 01284 const ObjCImplementationDecl *Impl); 01285 01286 private: 01287 // FIXME: This currently contains the set of StoredDeclMaps used 01288 // by DeclContext objects. This probably should not be in ASTContext, 01289 // but we include it here so that ASTContext can quickly deallocate them. 01290 std::vector<void*> SDMs; 01291 friend class DeclContext; 01292 void *CreateStoredDeclsMap(); 01293 void ReleaseDeclContextMaps(); 01294 }; 01295 01296 /// @brief Utility function for constructing a nullary selector. 01297 static inline Selector GetNullarySelector(const char* name, ASTContext& Ctx) { 01298 IdentifierInfo* II = &Ctx.Idents.get(name); 01299 return Ctx.Selectors.getSelector(0, &II); 01300 } 01301 01302 /// @brief Utility function for constructing an unary selector. 01303 static inline Selector GetUnarySelector(const char* name, ASTContext& Ctx) { 01304 IdentifierInfo* II = &Ctx.Idents.get(name); 01305 return Ctx.Selectors.getSelector(1, &II); 01306 } 01307 01308 } // end namespace clang 01309 01310 // operator new and delete aren't allowed inside namespaces. 01311 // The throw specifications are mandated by the standard. 01312 /// @brief Placement new for using the ASTContext's allocator. 01313 /// 01314 /// This placement form of operator new uses the ASTContext's allocator for 01315 /// obtaining memory. It is a non-throwing new, which means that it returns 01316 /// null on error. (If that is what the allocator does. The current does, so if 01317 /// this ever changes, this operator will have to be changed, too.) 01318 /// Usage looks like this (assuming there's an ASTContext 'Context' in scope): 01319 /// @code 01320 /// // Default alignment (16) 01321 /// IntegerLiteral *Ex = new (Context) IntegerLiteral(arguments); 01322 /// // Specific alignment 01323 /// IntegerLiteral *Ex2 = new (Context, 8) IntegerLiteral(arguments); 01324 /// @endcode 01325 /// Please note that you cannot use delete on the pointer; it must be 01326 /// deallocated using an explicit destructor call followed by 01327 /// @c Context.Deallocate(Ptr). 01328 /// 01329 /// @param Bytes The number of bytes to allocate. Calculated by the compiler. 01330 /// @param C The ASTContext that provides the allocator. 01331 /// @param Alignment The alignment of the allocated memory (if the underlying 01332 /// allocator supports it). 01333 /// @return The allocated memory. Could be NULL. 01334 inline void *operator new(size_t Bytes, clang::ASTContext &C, 01335 size_t Alignment) throw () { 01336 return C.Allocate(Bytes, Alignment); 01337 } 01338 /// @brief Placement delete companion to the new above. 01339 /// 01340 /// This operator is just a companion to the new above. There is no way of 01341 /// invoking it directly; see the new operator for more details. This operator 01342 /// is called implicitly by the compiler if a placement new expression using 01343 /// the ASTContext throws in the object constructor. 01344 inline void operator delete(void *Ptr, clang::ASTContext &C, size_t) 01345 throw () { 01346 C.Deallocate(Ptr); 01347 } 01348 01349 /// This placement form of operator new[] uses the ASTContext's allocator for 01350 /// obtaining memory. It is a non-throwing new[], which means that it returns 01351 /// null on error. 01352 /// Usage looks like this (assuming there's an ASTContext 'Context' in scope): 01353 /// @code 01354 /// // Default alignment (16) 01355 /// char *data = new (Context) char[10]; 01356 /// // Specific alignment 01357 /// char *data = new (Context, 8) char[10]; 01358 /// @endcode 01359 /// Please note that you cannot use delete on the pointer; it must be 01360 /// deallocated using an explicit destructor call followed by 01361 /// @c Context.Deallocate(Ptr). 01362 /// 01363 /// @param Bytes The number of bytes to allocate. Calculated by the compiler. 01364 /// @param C The ASTContext that provides the allocator. 01365 /// @param Alignment The alignment of the allocated memory (if the underlying 01366 /// allocator supports it). 01367 /// @return The allocated memory. Could be NULL. 01368 inline void *operator new[](size_t Bytes, clang::ASTContext& C, 01369 size_t Alignment = 16) throw () { 01370 return C.Allocate(Bytes, Alignment); 01371 } 01372 01373 /// @brief Placement delete[] companion to the new[] above. 01374 /// 01375 /// This operator is just a companion to the new[] above. There is no way of 01376 /// invoking it directly; see the new[] operator for more details. This operator 01377 /// is called implicitly by the compiler if a placement new[] expression using 01378 /// the ASTContext throws in the object constructor. 01379 inline void operator delete[](void *Ptr, clang::ASTContext &C, size_t) 01380 throw () { 01381 C.Deallocate(Ptr); 01382 } 01383 01384 #endif