//===--- Type.cpp - Type representation and manipulation ------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements type-related functionality.
//
//===----------------------------------------------------------------------===//
#include "clang/AST/ASTContext.h"
#include "clang/AST/Type.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/Expr.h"
#include "llvm/ADT/StringExtras.h"
using namespace clang;
bool QualType::isConstant(ASTContext &Ctx) const {
if (isConstQualified())
return true;
if (getTypePtr()->isArrayType())
return Ctx.getAsArrayType(*this)->getElementType().isConstant(Ctx);
return false;
}
void Type::Destroy(ASTContext& C) {
this->~Type();
C.Deallocate(this);
}
void VariableArrayType::Destroy(ASTContext& C) {
SizeExpr->Destroy(C);
this->~VariableArrayType();
C.Deallocate(this);
}
void DependentSizedArrayType::Destroy(ASTContext& C) {
SizeExpr->Destroy(C);
this->~DependentSizedArrayType();
C.Deallocate(this);
}
/// getArrayElementTypeNoTypeQual - If this is an array type, return the
/// element type of the array, potentially with type qualifiers missing.
/// This method should never be used when type qualifiers are meaningful.
const Type *Type::getArrayElementTypeNoTypeQual() const {
// If this is directly an array type, return it.
if (const ArrayType *ATy = dyn_cast<ArrayType>(this))
return ATy->getElementType().getTypePtr();
// If the canonical form of this type isn't the right kind, reject it.
if (!isa<ArrayType>(CanonicalType)) {
// Look through type qualifiers
if (ArrayType *AT = dyn_cast<ArrayType>(CanonicalType.getUnqualifiedType()))
return AT->getElementType().getTypePtr();
return 0;
}
// If this is a typedef for an array type, strip the typedef off without
// losing all typedef information.
return getDesugaredType()->getArrayElementTypeNoTypeQual();
}
/// getDesugaredType - Return the specified type with any "sugar" removed from
/// type type. This takes off typedefs, typeof's etc. If the outer level of
/// the type is already concrete, it returns it unmodified. This is similar
/// to getting the canonical type, but it doesn't remove *all* typedefs. For
/// example, it return "T*" as "T*", (not as "int*"), because the pointer is
/// concrete.
QualType Type::getDesugaredType() const {
if (const