//===--- Type.h - C Language Family Type Representation ---------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines the Type interface and subclasses.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_AST_TYPE_H
#define LLVM_CLANG_AST_TYPE_H
#include "llvm/Support/Casting.h"
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/APSInt.h"
#include "llvm/Bitcode/SerializationFwd.h"
using llvm::isa;
using llvm::cast;
using llvm::cast_or_null;
using llvm::dyn_cast;
using llvm::dyn_cast_or_null;
namespace clang {
class ASTContext;
class Type;
class TypedefDecl;
class TagDecl;
class RecordDecl;
class EnumDecl;
class FieldDecl;
class ObjCInterfaceDecl;
class ObjCProtocolDecl;
class ObjCMethodDecl;
class Expr;
class SourceLocation;
class PointerLikeType;
class PointerType;
class ReferenceType;
class VectorType;
class ArrayType;
class ConstantArrayType;
class VariableArrayType;
class IncompleteArrayType;
class RecordType;
class ComplexType;
class TagType;
class TypedefType;
class FunctionType;
class ExtVectorType;
class BuiltinType;
class ObjCInterfaceType;
class ObjCQualifiedIdType;
class ObjCQualifiedInterfaceType;
class StmtIteratorBase;
/// QualType - For efficiency, we don't store CVR-qualified types as nodes on
/// their own: instead each reference to a type stores the qualifiers. This
/// greatly reduces the number of nodes we need to allocate for types (for
/// example we only need one for 'int', 'const int', 'volatile int',
/// 'const volatile int', etc).
///
/// As an added efficiency bonus, instead of making this a pair, we just store
/// the three bits we care about in the low bits of the pointer. To handle the
/// packing/unpacking, we make QualType be a simple wrapper class that acts like
/// a smart pointer.
class QualType {
uintptr_t ThePtr;
public:
enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ.
Const = 0x1,
Restrict = 0x2,
Volatile = 0x4,
CVRFlags = Const|Restrict|Volatile
};
QualType() : ThePtr(0) {}
QualType(Type *Ptr, unsigned Quals) {
assert((Quals & ~CVRFlags) == 0 && "Invalid type qualifiers!");
ThePtr = reinterpret_cast<uintptr_t>(Ptr);
assert((ThePtr & CVRFlags) == 0 && "Type pointer not 8-byte aligned?");
ThePtr |= Quals;
}
static QualType getFromOpaquePtr(void *Ptr) {
QualType T;
T.ThePtr = reinterpret_cast<uintptr_t>(Ptr);
return T;
}
unsigned getCVRQualifiers() const {
return ThePtr & CVRFlags;
}
Type *getTypePtr() const {