ASTContext.h revision 716c7304ff5d27a95e1e7823acd1d09d5ec3e37f
16b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavine//===--- ASTContext.h - Context to hold long-lived AST nodes ----*- C++ -*-===// 26b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavine// 36b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavine// The LLVM Compiler Infrastructure 46b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavine// 56b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavine// This file was developed by Chris Lattner and is distributed under 66b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavine// the University of Illinois Open Source License. See LICENSE.TXT for details. 76b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavine// 86b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavine//===----------------------------------------------------------------------===// 96b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavine// 106b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavine// This file defines the ASTContext interface. 116b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavine// 126b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavine//===----------------------------------------------------------------------===// 136b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavine 146b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavine#ifndef LLVM_CLANG_AST_ASTCONTEXT_H 156b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavine#define LLVM_CLANG_AST_ASTCONTEXT_H 166b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavine 176b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavine#include "clang/AST/Builtins.h" 186b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavine#include "clang/AST/Expr.h" 196b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavine#include "clang/AST/RecordLayout.h" 206b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavine#include "clang/AST/Type.h" 216b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavine#include "llvm/ADT/DenseMap.h" 226b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavine#include <vector> 236b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavine 246b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavinenamespace clang { 256b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavine class TargetInfo; 266b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavine 276b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavine/// ASTContext - This class holds long-lived AST nodes (such as types and 286b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavine/// decls) that can be referred to throughout the semantic analysis of a file. 296b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavineclass ASTContext { 306b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavine std::vector<Type*> Types; 316b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavine llvm::FoldingSet<ComplexType> ComplexTypes; 326b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavine llvm::FoldingSet<PointerType> PointerTypes; 336b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavine llvm::FoldingSet<ReferenceType> ReferenceTypes; 346b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavine llvm::FoldingSet<ArrayType> ArrayTypes; 356b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavine llvm::FoldingSet<VectorType> VectorTypes; 366b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavine llvm::FoldingSet<FunctionTypeNoProto> FunctionTypeNoProtos; 376b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavine llvm::FoldingSet<FunctionTypeProto> FunctionTypeProtos; 386b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavine llvm::DenseMap<const RecordDecl*, const RecordLayout*> RecordLayoutInfo; 396b1e88e5d09a88dd77e631918aa7122a95a7ff4bMaxim Siniavine RecordDecl *CFConstantStringTypeDecl; 40public: 41 TargetInfo &Target; 42 IdentifierTable &Idents; 43 Builtin::Context BuiltinInfo; 44 45 // Builtin Types. 46 QualType VoidTy; 47 QualType BoolTy; 48 QualType CharTy; 49 QualType SignedCharTy, ShortTy, IntTy, LongTy, LongLongTy; 50 QualType UnsignedCharTy, UnsignedShortTy, UnsignedIntTy, UnsignedLongTy; 51 QualType UnsignedLongLongTy; 52 QualType FloatTy, DoubleTy, LongDoubleTy; 53 QualType FloatComplexTy, DoubleComplexTy, LongDoubleComplexTy; 54 55 ASTContext(TargetInfo &t, IdentifierTable &idents) : 56 CFConstantStringTypeDecl(0), Target(t), Idents(idents) { 57 InitBuiltinTypes(); 58 BuiltinInfo.InitializeBuiltins(idents, Target); 59 } 60 ~ASTContext(); 61 62 void PrintStats() const; 63 64 //===--------------------------------------------------------------------===// 65 // Type Constructors 66 //===--------------------------------------------------------------------===// 67 68 /// getComplexType - Return the uniqued reference to the type for a complex 69 /// number with the specified element type. 70 QualType getComplexType(QualType T); 71 72 /// getPointerType - Return the uniqued reference to the type for a pointer to 73 /// the specified type. 74 QualType getPointerType(QualType T); 75 76 /// getReferenceType - Return the uniqued reference to the type for a 77 /// reference to the specified type. 78 QualType getReferenceType(QualType T); 79 80 /// getArrayType - Return the unique reference to the type for an array of the 81 /// specified element type. 82 QualType getArrayType(QualType EltTy, ArrayType::ArraySizeModifier ASM, 83 unsigned EltTypeQuals, Expr *NumElts); 84 85 /// getVectorType - Return the unique reference to a vector type of 86 /// the specified element type and size. VectorType must be a built-in type. 87 QualType getVectorType(QualType VectorType, unsigned NumElts); 88 89 /// getOCUVectorType - Return the unique reference to an OCU vector type of 90 /// the specified element type and size. VectorType must be a built-in type. 91 QualType getOCUVectorType(QualType VectorType, unsigned NumElts); 92 93 /// getFunctionTypeNoProto - Return a K&R style C function type like 'int()'. 94 /// 95 QualType getFunctionTypeNoProto(QualType ResultTy); 96 97 /// getFunctionType - Return a normal function type with a typed argument 98 /// list. isVariadic indicates whether the argument list includes '...'. 99 QualType getFunctionType(QualType ResultTy, QualType *ArgArray, 100 unsigned NumArgs, bool isVariadic); 101 102 /// getTypedefType - Return the unique reference to the type for the 103 /// specified typename decl. 104 QualType getTypedefType(TypedefDecl *Decl); 105 106 /// getTypeOfType - GCC extension. 107 QualType getTypeOfExpr(Expr *e); 108 QualType getTypeOfType(QualType t); 109 110 /// getTagDeclType - Return the unique reference to the type for the 111 /// specified TagDecl (struct/union/class/enum) decl. 112 QualType getTagDeclType(TagDecl *Decl); 113 114 /// getSizeType - Return the unique type for "size_t" (C99 7.17), defined 115 /// in <stddef.h>. The sizeof operator requires this (C99 6.5.3.4p4). 116 QualType getSizeType() const; 117 118 /// getPointerDiffType - Return the unique type for "ptrdiff_t" (ref?) 119 /// defined in <stddef.h>. Pointer - pointer requires this (C99 6.5.6p9). 120 QualType getPointerDiffType() const; 121 122 // getCFConstantStringType - Return the type used for constant CFStrings. 123 QualType getCFConstantStringType(); 124 125 //===--------------------------------------------------------------------===// 126 // Type Sizing and Analysis 127 //===--------------------------------------------------------------------===// 128 129 /// getTypeInfo - Get the size and alignment of the specified complete type in 130 /// bits. 131 std::pair<uint64_t, unsigned> getTypeInfo(QualType T, SourceLocation L); 132 133 /// getTypeSize - Return the size of the specified type, in bits. This method 134 /// does not work on incomplete types. 135 uint64_t getTypeSize(QualType T, SourceLocation L) { 136 return getTypeInfo(T, L).first; 137 } 138 139 /// getTypeAlign - Return the alignment of the specified type, in bits. This 140 /// method does not work on incomplete types. 141 unsigned getTypeAlign(QualType T, SourceLocation L) { 142 return getTypeInfo(T, L).second; 143 } 144 145 /// getRecordLayout - Get or compute information about the layout of the 146 /// specified record (struct/union/class), which indicates its size and field 147 /// position information. 148 const RecordLayout &getRecordLayout(const RecordDecl *D, SourceLocation L); 149 150 //===--------------------------------------------------------------------===// 151 // Type Operators 152 //===--------------------------------------------------------------------===// 153 154 /// getIntegerBitwidth - Return the bitwidth of the specified integer type 155 /// according to the target. 'Loc' specifies the source location that 156 /// requires evaluation of this property. 157 unsigned getIntegerBitwidth(QualType T, SourceLocation Loc); 158 159 /// maxIntegerType - Returns the highest ranked integer type. Handles 3 160 /// different type combos: unsigned/unsigned, signed/signed, signed/unsigned. 161 static QualType maxIntegerType(QualType lhs, QualType rhs); 162 163 /// maxFloatingType - Returns the highest ranked float type. Handles 3 164 /// different combos: float/float, float/complex, complex/complex. 165 static QualType maxFloatingType(QualType lt, QualType rt); 166 167 /// getFloatingTypeOfSizeWithinDomain - Returns a real floating 168 /// point or a complex type (based on typeDomain/typeSize). 169 /// 'typeDomain' is a real floating point or complex type. 170 /// 'typeSize' is a real floating point or complex type. 171 QualType getFloatingTypeOfSizeWithinDomain(QualType typeSize, 172 QualType typeDomain) const; 173private: 174 ASTContext(const ASTContext&); // DO NOT IMPLEMENT 175 void operator=(const ASTContext&); // DO NOT IMPLEMENT 176 177 void InitBuiltinTypes(); 178 void InitBuiltinType(QualType &R, BuiltinType::Kind K); 179}; 180 181} // end namespace clang 182 183#endif 184