ASTContext.h revision d2d2a11a91d7ddf468bfb70f66362d24806ed601
1//===--- ASTContext.h - Context to hold long-lived AST nodes ----*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file was developed by Chris Lattner and is distributed under 6// the University of Illinois Open Source License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file defines the ASTContext interface. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef LLVM_CLANG_AST_ASTCONTEXT_H 15#define LLVM_CLANG_AST_ASTCONTEXT_H 16 17#include "clang/AST/Builtins.h" 18#include "clang/AST/Type.h" 19#include "clang/AST/Expr.h" 20#include <vector> 21 22namespace clang { 23 class TargetInfo; 24 25/// ASTContext - This class holds long-lived AST nodes (such as types and 26/// decls) that can be referred to throughout the semantic analysis of a file. 27class ASTContext { 28 std::vector<Type*> Types; 29 llvm::FoldingSet<ComplexType> ComplexTypes; 30 llvm::FoldingSet<PointerType> PointerTypes; 31 llvm::FoldingSet<ReferenceType> ReferenceTypes; 32 llvm::FoldingSet<ArrayType> ArrayTypes; 33 llvm::FoldingSet<VectorType> VectorTypes; 34 llvm::FoldingSet<FunctionTypeNoProto> FunctionTypeNoProtos; 35 llvm::FoldingSet<FunctionTypeProto> FunctionTypeProtos; 36public: 37 TargetInfo &Target; 38 Builtin::Context BuiltinInfo; 39 40 // Builtin Types. 41 QualType VoidTy; 42 QualType BoolTy; 43 QualType CharTy; 44 QualType SignedCharTy, ShortTy, IntTy, LongTy, LongLongTy; 45 QualType UnsignedCharTy, UnsignedShortTy, UnsignedIntTy, UnsignedLongTy; 46 QualType UnsignedLongLongTy; 47 QualType FloatTy, DoubleTy, LongDoubleTy; 48 QualType FloatComplexTy, DoubleComplexTy, LongDoubleComplexTy; 49 50 ASTContext(TargetInfo &t, IdentifierTable &idents) : Target(t) { 51 InitBuiltinTypes(); 52 BuiltinInfo.InitializeBuiltins(idents, Target); 53 } 54 ~ASTContext(); 55 56 void PrintStats() const; 57 58 /// getTypeInfo - Get the size and alignment of the specified complete type in 59 /// bits. 60 std::pair<uint64_t, unsigned> getTypeInfo(QualType T, SourceLocation L); 61 62 /// getTypeSize - Return the size of the specified type, in bits. This method 63 /// does not work on incomplete types. 64 uint64_t getTypeSize(QualType T, SourceLocation L) { 65 return getTypeInfo(T, L).first; 66 } 67 68 /// getTypeAlign - Return the alignment of the specified type, in bits. This 69 /// method does not work on incomplete types. 70 unsigned getTypeAlign(QualType T, SourceLocation L) { 71 return getTypeInfo(T, L).second; 72 } 73 74 /// getComplexType - Return the uniqued reference to the type for a complex 75 /// number with the specified element type. 76 QualType getComplexType(QualType T); 77 78 /// getPointerType - Return the uniqued reference to the type for a pointer to 79 /// the specified type. 80 QualType getPointerType(QualType T); 81 82 /// getReferenceType - Return the uniqued reference to the type for a 83 /// reference to the specified type. 84 QualType getReferenceType(QualType T); 85 86 /// getArrayType - Return the unique reference to the type for an array of the 87 /// specified element type. 88 QualType getArrayType(QualType EltTy, ArrayType::ArraySizeModifier ASM, 89 unsigned EltTypeQuals, Expr *NumElts); 90 91 /// convertToVectorType - Return the unique reference to a vector type of 92 /// the specified element type and size. VectorType can be a pointer, array, 93 /// function, or built-in type (i.e. _Bool, integer, or float). 94 QualType convertToVectorType(QualType VectorType, unsigned NumElts); 95 96 /// getFunctionTypeNoProto - Return a K&R style C function type like 'int()'. 97 /// 98 QualType getFunctionTypeNoProto(QualType ResultTy); 99 100 /// getFunctionType - Return a normal function type with a typed argument 101 /// list. isVariadic indicates whether the argument list includes '...'. 102 QualType getFunctionType(QualType ResultTy, QualType *ArgArray, 103 unsigned NumArgs, bool isVariadic); 104 105 /// getTypedefType - Return the unique reference to the type for the 106 /// specified typename decl. 107 QualType getTypedefType(TypedefDecl *Decl); 108 109 /// getTagDeclType - Return the unique reference to the type for the 110 /// specified TagDecl (struct/union/class/enum) decl. 111 QualType getTagDeclType(TagDecl *Decl); 112 113 /// getSizeType - Return the unique type for "size_t" (C99 7.17), defined 114 /// in <stddef.h>. The sizeof operator requires this (C99 6.5.3.4p4). 115 QualType getSizeType() const; 116 117 /// getPointerDiffType - Return the unique type for "ptrdiff_t" (ref?) 118 /// defined in <stddef.h>. Pointer - pointer requires this (C99 6.5.6p9). 119 QualType getPointerDiffType() const; 120 121 /// getIntegerBitwidth - Return the bitwidth of the specified integer type 122 /// according to the target. 'Loc' specifies the source location that 123 /// requires evaluation of this property. 124 unsigned getIntegerBitwidth(QualType T, SourceLocation Loc); 125 126 // maxIntegerType - Returns the highest ranked integer type. Handles 3 127 // different type combos: unsigned/unsigned, signed/signed, signed/unsigned. 128 static QualType maxIntegerType(QualType lhs, QualType rhs); 129 130 // maxFloatingType - Returns the highest ranked float type. Both input 131 // types are required to be floats. 132 static QualType maxFloatingType(QualType lt, QualType rt); 133 134 // maxComplexType - Returns the highest ranked complex type. Handles 3 135 // different type combos: complex/complex, complex/float, float/complex. 136 QualType maxComplexType(QualType lt, QualType rt) const; 137 138private: 139 ASTContext(const ASTContext&); // DO NOT IMPLEMENT 140 void operator=(const ASTContext&); // DO NOT IMPLEMENT 141 142 void InitBuiltinTypes(); 143 void InitBuiltinType(QualType &R, BuiltinType::Kind K); 144}; 145 146} // end namespace clang 147 148#endif 149