ASTContext.h revision 71993dd85eed9cc42c6b2fa61ee5c53026b74817
1710632d07b13609444626367bebd34c0af3acb6aMikhail Glushenkov//===--- ASTContext.h - Context to hold long-lived AST nodes ----*- C++ -*-===// 26091ebd172a16a10f1ea66061a5fa7cbf5139e56Reid Spencer// 36091ebd172a16a10f1ea66061a5fa7cbf5139e56Reid Spencer// The LLVM Compiler Infrastructure 46091ebd172a16a10f1ea66061a5fa7cbf5139e56Reid Spencer// 57ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// This file was developed by Chris Lattner and is distributed under 67ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// the University of Illinois Open Source License. See LICENSE.TXT for details. 76091ebd172a16a10f1ea66061a5fa7cbf5139e56Reid Spencer// 86091ebd172a16a10f1ea66061a5fa7cbf5139e56Reid Spencer//===----------------------------------------------------------------------===// 927107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendling// 1027107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendling// This file defines the ASTContext interface. 1127107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendling// 1227107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendling//===----------------------------------------------------------------------===// 1327107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendling 146091ebd172a16a10f1ea66061a5fa7cbf5139e56Reid Spencer#ifndef LLVM_CLANG_AST_ASTCONTEXT_H 156091ebd172a16a10f1ea66061a5fa7cbf5139e56Reid Spencer#define LLVM_CLANG_AST_ASTCONTEXT_H 16674be02d525d4e24bc6943ed9274958c580bcfbcJakub Staszak 17674be02d525d4e24bc6943ed9274958c580bcfbcJakub Staszak#include "clang/AST/Builtins.h" 186091ebd172a16a10f1ea66061a5fa7cbf5139e56Reid Spencer#include "clang/AST/Expr.h" 19d509d0b532ec2358b3f341d4a4cd1411cb8b5db2Chris Lattner#include "clang/AST/RecordLayout.h" 203467e30edf63b6d8a8d446186674ba9e4b7885a9Bill Wendling#include "clang/AST/Type.h" 21c835b8c30127d15599de2d614434d39a6cc3ae17Benjamin Kramer#include "llvm/ADT/DenseMap.h" 223f213e7b3a6829a154d4e8ceb7d8689b389bd5dcBenjamin Kramer#include <vector> 2322bd64173981bf1251c4b3bfc684207340534ba3Bill Wendling 24ea59f896a672c2e1ef9f02277bce60257aa60989Bill Wendlingnamespace clang { 2558d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner class TargetInfo; 266091ebd172a16a10f1ea66061a5fa7cbf5139e56Reid Spencer 276091ebd172a16a10f1ea66061a5fa7cbf5139e56Reid Spencer/// ASTContext - This class holds long-lived AST nodes (such as types and 28d426a642a23a234547cbc7061f5bfec157673249Bill Wendling/// decls) that can be referred to throughout the semantic analysis of a file. 29702cc91aa1bd41540e8674921ae7ac89a4ff061fBill Wendlingclass ASTContext { 30f6670729aabc1fab85238d2b306a1c1767a807bbBill Wendling std::vector<Type*> Types; 31817abdd8b055059e5930a15704b9f52da4236456Bill Wendling llvm::FoldingSet<ComplexType> ComplexTypes; 32817abdd8b055059e5930a15704b9f52da4236456Bill Wendling llvm::FoldingSet<PointerType> PointerTypes; 336dc3781d44e56f0addf28b06232a50f3f9e6b1afBill Wendling llvm::FoldingSet<ReferenceType> ReferenceTypes; 34c835b8c30127d15599de2d614434d39a6cc3ae17Benjamin Kramer llvm::FoldingSet<ArrayType> ArrayTypes; 352c79ecbd704c656178ffa43d5a58ebe3ca188b40Bill Wendling llvm::FoldingSet<VectorType> VectorTypes; 36ad9a9e15595bc9d5ba1ed752caf8572957f77a3dDuncan Sands llvm::FoldingSet<FunctionTypeNoProto> FunctionTypeNoProtos; 37ad9a9e15595bc9d5ba1ed752caf8572957f77a3dDuncan Sands llvm::FoldingSet<FunctionTypeProto> FunctionTypeProtos; 381d3dcfe4246b4d45fa78a8dfd0a11c7fff842c15Bill Wendling llvm::DenseMap<const RecordDecl*, const RecordLayout*> RecordLayoutInfo; 3927107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendling RecordDecl *CFConstantStringTypeDecl; 4027107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendlingpublic: 411d3dcfe4246b4d45fa78a8dfd0a11c7fff842c15Bill Wendling TargetInfo &Target; 421d3dcfe4246b4d45fa78a8dfd0a11c7fff842c15Bill Wendling IdentifierTable &Idents; 431d3dcfe4246b4d45fa78a8dfd0a11c7fff842c15Bill Wendling Builtin::Context BuiltinInfo; 44034b94b17006f51722886b0f2283fb6fb19aca1fBill Wendling 456765834754cbb3cb0f15b4b15e98c5e73fa50066Bill Wendling // Builtin Types. 461d3dcfe4246b4d45fa78a8dfd0a11c7fff842c15Bill Wendling QualType VoidTy; 4773dee180c836270644dfa7d90f9c5ba877567999Bill Wendling QualType BoolTy; 48f3d1500ab2c7364d3d0fb73a7e1b8c6339ab48b1Bill Wendling QualType CharTy; 4973dee180c836270644dfa7d90f9c5ba877567999Bill Wendling QualType SignedCharTy, ShortTy, IntTy, LongTy, LongLongTy; 5073dee180c836270644dfa7d90f9c5ba877567999Bill Wendling QualType UnsignedCharTy, UnsignedShortTy, UnsignedIntTy, UnsignedLongTy; 5173dee180c836270644dfa7d90f9c5ba877567999Bill Wendling QualType UnsignedLongLongTy; 52f3d1500ab2c7364d3d0fb73a7e1b8c6339ab48b1Bill Wendling QualType FloatTy, DoubleTy, LongDoubleTy; 5373dee180c836270644dfa7d90f9c5ba877567999Bill Wendling QualType FloatComplexTy, DoubleComplexTy, LongDoubleComplexTy; 5411d00420e42ba88c3b48cab997965a7be79315e2Bill Wendling 5511d00420e42ba88c3b48cab997965a7be79315e2Bill Wendling ASTContext(TargetInfo &t, IdentifierTable &idents) : 56f3d1500ab2c7364d3d0fb73a7e1b8c6339ab48b1Bill Wendling CFConstantStringTypeDecl(0), Target(t), Idents(idents) { 5711d00420e42ba88c3b48cab997965a7be79315e2Bill Wendling InitBuiltinTypes(); 5811d00420e42ba88c3b48cab997965a7be79315e2Bill Wendling BuiltinInfo.InitializeBuiltins(idents, Target); 5911d00420e42ba88c3b48cab997965a7be79315e2Bill Wendling } 6011d00420e42ba88c3b48cab997965a7be79315e2Bill Wendling ~ASTContext(); 6111d00420e42ba88c3b48cab997965a7be79315e2Bill Wendling 6211d00420e42ba88c3b48cab997965a7be79315e2Bill Wendling void PrintStats() const; 63629fb82419d9bfff6ae475363bcce66192dfcc8eBill Wendling 645a0eeb5a9d727940b1dbe8dff6e9aa292ada0f6aBill Wendling //===--------------------------------------------------------------------===// 65480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling // Type Constructors 66480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling //===--------------------------------------------------------------------===// 676765834754cbb3cb0f15b4b15e98c5e73fa50066Bill Wendling 68f6670729aabc1fab85238d2b306a1c1767a807bbBill Wendling /// getComplexType - Return the uniqued reference to the type for a complex 69480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling /// number with the specified element type. 702253a2f52f3c46ae75cd05f5885acb987bd1d6b6Michael Gottesman QualType getComplexType(QualType T); 712253a2f52f3c46ae75cd05f5885acb987bd1d6b6Michael Gottesman 72480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling /// getPointerType - Return the uniqued reference to the type for a pointer to 7377226a03dca98e6237c1068f2652fe41bea7b687Diego Novillo /// the specified type. 74480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling QualType getPointerType(QualType T); 75480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling 769a419f656e278b96e9dfe739cd63c7bff9a4e1fdQuentin Colombet /// getReferenceType - Return the uniqued reference to the type for a 77480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling /// reference to the specified type. 78480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling QualType getReferenceType(QualType T); 79480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling 80143d46476cdcf5b88b9ee18ebd799e5820a2db0eBill Wendling /// getArrayType - Return the unique reference to the type for an array of the 81480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling /// specified element type. 8267ae13575900e8efd056672987249fd0adbf5e73James Molloy QualType getArrayType(QualType EltTy, ArrayType::ArraySizeModifier ASM, 83480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling unsigned EltTypeQuals, Expr *NumElts); 84480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling 85480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling /// getVectorType - Return the unique reference to a vector type of 863a106e60366a51b4594ec303ff8dbbc58913227fBill Wendling /// the specified element type and size. VectorType must be a built-in type. 87480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling QualType getVectorType(QualType VectorType, unsigned NumElts); 88480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling 89480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling /// getOCUVectorType - Return the unique reference to an OCU vector type of 90480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling /// the specified element type and size. VectorType must be a built-in type. 915768bb8d77892926dff0d078b1fb08c14ea791f3Andrea Di Biagio QualType getOCUVectorType(QualType VectorType, unsigned NumElts); 92480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling 93480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling /// getFunctionTypeNoProto - Return a K&R style C function type like 'int()'. 94456ca048af35163b9f52187e92a23ee0a9f059e8Stephen Lin /// 95480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling QualType getFunctionTypeNoProto(QualType ResultTy); 96480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling 97480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling /// getFunctionType - Return a normal function type with a typed argument 986765834754cbb3cb0f15b4b15e98c5e73fa50066Bill Wendling /// list. isVariadic indicates whether the argument list includes '...'. 996765834754cbb3cb0f15b4b15e98c5e73fa50066Bill Wendling QualType getFunctionType(QualType ResultTy, QualType *ArgArray, 100f6670729aabc1fab85238d2b306a1c1767a807bbBill Wendling unsigned NumArgs, bool isVariadic); 101480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling 102480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling /// getTypedefType - Return the unique reference to the type for the 103114baee1fa017daefad2339c77b45b9ca3d79a41Bill Wendling /// specified typename decl. 104480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling QualType getTypedefType(TypedefDecl *Decl); 1058eec41fc778e99d42172a7f6de76faa43a6d8847Kostya Serebryany 1068eec41fc778e99d42172a7f6de76faa43a6d8847Kostya Serebryany /// getTypeOfType - GCC extension. 1078eec41fc778e99d42172a7f6de76faa43a6d8847Kostya Serebryany QualType getTypeOfExpr(Expr *e); 108480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling QualType getTypeOfType(QualType t); 1090319888773b36dd61d7d2283cb9a26cac1e5abe8Bill Wendling 1100319888773b36dd61d7d2283cb9a26cac1e5abe8Bill Wendling /// getTagDeclType - Return the unique reference to the type for the 111886a7663c72cb04eaee58cb6997c394f5096a8b9Benjamin Kramer /// specified TagDecl (struct/union/class/enum) decl. 1126765834754cbb3cb0f15b4b15e98c5e73fa50066Bill Wendling QualType getTagDeclType(TagDecl *Decl); 1136765834754cbb3cb0f15b4b15e98c5e73fa50066Bill Wendling 11427107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendling /// getSizeType - Return the unique type for "size_t" (C99 7.17), defined 11527107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendling /// in <stddef.h>. The sizeof operator requires this (C99 6.5.3.4p4). 116d426a642a23a234547cbc7061f5bfec157673249Bill Wendling QualType getSizeType() const; 11727107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendling 1182c79ecbd704c656178ffa43d5a58ebe3ca188b40Bill Wendling /// getPointerDiffType - Return the unique type for "ptrdiff_t" (ref?) 119c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling /// defined in <stddef.h>. Pointer - pointer requires this (C99 6.5.6p9). 120c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling QualType getPointerDiffType() const; 121c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling 122c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling // getCFConstantStringType - Return the type used for constant CFStrings. 123c08a5ef6581f2c7550e92d31f63cd65ec29c39e0Bill Wendling QualType getCFConstantStringType(); 1248c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling 1258c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling //===--------------------------------------------------------------------===// 1268c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling // Type Sizing and Analysis 1272c79ecbd704c656178ffa43d5a58ebe3ca188b40Bill Wendling //===--------------------------------------------------------------------===// 128c08a5ef6581f2c7550e92d31f63cd65ec29c39e0Bill Wendling 129c08a5ef6581f2c7550e92d31f63cd65ec29c39e0Bill Wendling /// getTypeInfo - Get the size and alignment of the specified complete type in 130c08a5ef6581f2c7550e92d31f63cd65ec29c39e0Bill Wendling /// bits. 131c08a5ef6581f2c7550e92d31f63cd65ec29c39e0Bill Wendling std::pair<uint64_t, unsigned> getTypeInfo(QualType T, SourceLocation L); 132c08a5ef6581f2c7550e92d31f63cd65ec29c39e0Bill Wendling 133c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling /// getTypeSize - Return the size of the specified type, in bits. This method 134c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling /// does not work on incomplete types. 135c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling uint64_t getTypeSize(QualType T, SourceLocation L) { 136c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling return getTypeInfo(T, L).first; 1378c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling } 1388c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling 1398c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling /// getTypeAlign - Return the alignment of the specified type, in bits. This 1408c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling /// method does not work on incomplete types. 1418c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling unsigned getTypeAlign(QualType T, SourceLocation L) { 1428c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling return getTypeInfo(T, L).second; 1438c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling } 1448c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling 1458c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling /// getRecordLayout - Get or compute information about the layout of the 1468c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling /// specified record (struct/union/class), which indicates its size and field 147eddab1550ee10cce3bb26a26e88529cb19451aa3NAKAMURA Takumi /// position information. 148eddab1550ee10cce3bb26a26e88529cb19451aa3NAKAMURA Takumi const RecordLayout &getRecordLayout(const RecordDecl *D, SourceLocation L); 149eddab1550ee10cce3bb26a26e88529cb19451aa3NAKAMURA Takumi 15064754f499058b5dc748ea6d06a084af0ed539ec4Bill Wendling //===--------------------------------------------------------------------===// 15164754f499058b5dc748ea6d06a084af0ed539ec4Bill Wendling // Type Operators 15264754f499058b5dc748ea6d06a084af0ed539ec4Bill Wendling //===--------------------------------------------------------------------===// 1538c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling 1548c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling /// getIntegerBitwidth - Return the bitwidth of the specified integer type 1558c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling /// according to the target. 'Loc' specifies the source location that 1566dc3781d44e56f0addf28b06232a50f3f9e6b1afBill Wendling /// requires evaluation of this property. 1578c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling unsigned getIntegerBitwidth(QualType T, SourceLocation Loc); 1588c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling 1598c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling /// maxIntegerType - Returns the highest ranked integer type. Handles 3 1608c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling /// different type combos: unsigned/unsigned, signed/signed, signed/unsigned. 1618c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling static QualType maxIntegerType(QualType lhs, QualType rhs); 1628c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling 1638c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling /// maxFloatingType - Returns the highest ranked float type. Both input 1648c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling /// types are required to be floats. 1658c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling static QualType maxFloatingType(QualType lt, QualType rt); 1668c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling 1678c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling /// maxComplexType - Returns the highest ranked complex type. Handles 3 1686dc3781d44e56f0addf28b06232a50f3f9e6b1afBill Wendling /// different type combos: complex/complex, complex/float, float/complex. 1691d3dcfe4246b4d45fa78a8dfd0a11c7fff842c15Bill Wendling QualType maxComplexType(QualType lt, QualType rt) const; 170ef99fe8efaa6cb74c66e570a6ef467debca92911Bill Wendling 171e66f3d3ba0ea9f82f65a29c47fc37e997cbf0aceBill Wendlingprivate: 172ef99fe8efaa6cb74c66e570a6ef467debca92911Bill Wendling ASTContext(const ASTContext&); // DO NOT IMPLEMENT 1731d3dcfe4246b4d45fa78a8dfd0a11c7fff842c15Bill Wendling void operator=(const ASTContext&); // DO NOT IMPLEMENT 174943c29135e03e55f9a5dab393786171a4a536482Bill Wendling 175e66f3d3ba0ea9f82f65a29c47fc37e997cbf0aceBill Wendling void InitBuiltinTypes(); 17630b483c94001927b3593ed200e823104bab51660Bill Wendling void InitBuiltinType(QualType &R, BuiltinType::Kind K); 177c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling}; 178c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling 179b29ce26ea60f7516c853318ffbfc107fde9ad897Bill Wendling} // end namespace clang 180c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling 1818c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling#endif 1822d5be6c313c0f9e23e56620fa8f8ae8d9b539bf0Bill Wendling