ASTContext.h revision 050785860b8541c837982beef3f06d292d1d0c1d
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===--- ASTContext.h - Context to hold long-lived AST nodes ----*- C++ -*-===// 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The LLVM Compiler Infrastructure 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// This file was developed by Chris Lattner and is distributed under 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the University of Illinois Open Source License. See LICENSE.TXT for details. 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===----------------------------------------------------------------------===// 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This file defines the ASTContext interface. 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===----------------------------------------------------------------------===// 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef LLVM_CLANG_AST_ASTCONTEXT_H 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define LLVM_CLANG_AST_ASTCONTEXT_H 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "clang/AST/Builtins.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "clang/AST/Expr.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "clang/AST/RecordLayout.h" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "clang/AST/Type.h" 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "llvm/ADT/DenseMap.h" 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector> 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace clang { 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class TargetInfo; 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// ASTContext - This class holds long-lived AST nodes (such as types and 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// decls) that can be referred to throughout the semantic analysis of a file. 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ASTContext { 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::vector<Type*> Types; 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) llvm::FoldingSet<ComplexType> ComplexTypes; 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) llvm::FoldingSet<PointerType> PointerTypes; 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) llvm::FoldingSet<ReferenceType> ReferenceTypes; 343551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) llvm::FoldingSet<ArrayType> ArrayTypes; 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) llvm::FoldingSet<VectorType> VectorTypes; 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) llvm::FoldingSet<FunctionTypeNoProto> FunctionTypeNoProtos; 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) llvm::FoldingSet<FunctionTypeProto> FunctionTypeProtos; 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) llvm::DenseMap<const RecordDecl*, const RecordLayout*> RecordLayoutInfo; 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RecordDecl *CFConstantStringTypeDecl; 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public: 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) TargetInfo &Target; 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) IdentifierTable &Idents; 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Builtin::Context BuiltinInfo; 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Builtin Types. 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) QualType VoidTy; 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) QualType BoolTy; 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) QualType CharTy; 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) QualType SignedCharTy, ShortTy, IntTy, LongTy, LongLongTy; 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) QualType UnsignedCharTy, UnsignedShortTy, UnsignedIntTy, UnsignedLongTy; 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) QualType UnsignedLongLongTy; 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) QualType FloatTy, DoubleTy, LongDoubleTy; 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) QualType FloatComplexTy, DoubleComplexTy, LongDoubleComplexTy; 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASTContext(TargetInfo &t, IdentifierTable &idents) : 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CFConstantStringTypeDecl(0), Target(t), Idents(idents) { 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) InitBuiltinTypes(); 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BuiltinInfo.InitializeBuiltins(idents, Target); 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ~ASTContext(); 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void PrintStats() const; 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) //===--------------------------------------------------------------------===// 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Type Constructors 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) //===--------------------------------------------------------------------===// 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// getComplexType - Return the uniqued reference to the type for a complex 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// number with the specified element type. 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) QualType getComplexType(QualType T); 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 72c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) /// getPointerType - Return the uniqued reference to the type for a pointer to 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// the specified type. 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) QualType getPointerType(QualType T); 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// getReferenceType - Return the uniqued reference to the type for a 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// reference to the specified type. 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) QualType getReferenceType(QualType T); 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// getArrayType - Return the unique reference to the type for an array of the 813551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) /// specified element type. 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) QualType getArrayType(QualType EltTy, ArrayType::ArraySizeModifier ASM, 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) unsigned EltTypeQuals, Expr *NumElts); 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// getVectorType - Return the unique reference to a vector type of 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// the specified element type and size. VectorType must be a built-in type. 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) QualType getVectorType(QualType VectorType, unsigned NumElts); 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// getOCUVectorType - Return the unique reference to an OCU vector type of 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// the specified element type and size. VectorType must be a built-in type. 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) QualType getOCUVectorType(QualType VectorType, unsigned NumElts); 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// getFunctionTypeNoProto - Return a K&R style C function type like 'int()'. 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) QualType getFunctionTypeNoProto(QualType ResultTy); 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// getFunctionType - Return a normal function type with a typed argument 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// list. isVariadic indicates whether the argument list includes '...'. 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) QualType getFunctionType(QualType ResultTy, QualType *ArgArray, 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) unsigned NumArgs, bool isVariadic); 1013551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 1023551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) /// getTypedefType - Return the unique reference to the type for the 1033551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) /// specified typename decl. 1043551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) QualType getTypedefType(TypedefDecl *Decl); 1053551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// getTypeOfType - GCC extension. 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) QualType getTypeOfExpr(Expr *e); 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) QualType getTypeOfType(QualType t); 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// getTagDeclType - Return the unique reference to the type for the 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// specified TagDecl (struct/union/class/enum) decl. 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) QualType getTagDeclType(TagDecl *Decl); 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// getSizeType - Return the unique type for "size_t" (C99 7.17), defined 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// in <stddef.h>. The sizeof operator requires this (C99 6.5.3.4p4). 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) QualType getSizeType() const; 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// getPointerDiffType - Return the unique type for "ptrdiff_t" (ref?) 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// defined in <stddef.h>. Pointer - pointer requires this (C99 6.5.6p9). 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) QualType getPointerDiffType() const; 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // getCFConstantStringType - Return the type used for constant CFStrings. 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) QualType getCFConstantStringType(); 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) //===--------------------------------------------------------------------===// 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Type Sizing and Analysis 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) //===--------------------------------------------------------------------===// 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 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 /// getEnumDeclIntegerType - returns the integer type compatible with the 151 /// given enum type. 152 QualType getEnumDeclIntegerType(const EnumDecl *ED) const; 153 154 //===--------------------------------------------------------------------===// 155 // Type Operators 156 //===--------------------------------------------------------------------===// 157 158 /// maxIntegerType - Returns the highest ranked integer type. Handles 3 159 /// different type combos: unsigned/unsigned, signed/signed, signed/unsigned. 160 static QualType maxIntegerType(QualType lhs, QualType rhs); 161 162 /// compareFloatingType - Handles 3 different combos: 163 /// float/float, float/complex, complex/complex. 164 /// If lt > rt, return 1. If lt == rt, return 0. If lt < rt, return -1. 165 static int compareFloatingType(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