2006-11-10 06:34:16 +00:00
|
|
|
//===--- ASTContext.cpp - Context to hold long-lived AST nodes ------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by Chris Lattner and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the ASTContext interface.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/AST/ASTContext.h"
|
2006-11-12 00:37:36 +00:00
|
|
|
#include "clang/AST/Type.h"
|
2006-11-10 06:34:16 +00:00
|
|
|
#include "clang/Lex/Preprocessor.h"
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
ASTContext::ASTContext(Preprocessor &pp)
|
|
|
|
: PP(pp), Target(pp.getTargetInfo()) {
|
2006-11-12 00:37:36 +00:00
|
|
|
InitBuiltinTypes();
|
|
|
|
}
|
|
|
|
|
2006-11-12 00:53:46 +00:00
|
|
|
ASTContext::~ASTContext() {
|
|
|
|
// Deallocate all the types.
|
|
|
|
while (!Types.empty()) {
|
|
|
|
delete Types.back();
|
|
|
|
Types.pop_back();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ASTContext::InitBuiltinType(TypeRef &R, const char *Name) {
|
|
|
|
Types.push_back((R = new BuiltinType(Name)).getTypePtr());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-12 00:37:36 +00:00
|
|
|
void ASTContext::InitBuiltinTypes() {
|
|
|
|
assert(VoidTy.isNull() && "Context reinitialized?");
|
|
|
|
|
|
|
|
// C99 6.2.5p19.
|
2006-11-12 00:53:46 +00:00
|
|
|
InitBuiltinType(VoidTy, "void");
|
2006-11-12 00:37:36 +00:00
|
|
|
|
|
|
|
// C99 6.2.5p2.
|
2006-11-12 00:53:46 +00:00
|
|
|
InitBuiltinType(BoolTy, "_Bool");
|
2006-11-12 00:37:36 +00:00
|
|
|
// C99 6.2.5p3.
|
2006-11-12 00:53:46 +00:00
|
|
|
InitBuiltinType(CharTy, "char");
|
2006-11-12 00:37:36 +00:00
|
|
|
// C99 6.2.5p4.
|
2006-11-12 00:53:46 +00:00
|
|
|
InitBuiltinType(SignedCharTy, "signed char");
|
|
|
|
InitBuiltinType(ShortTy, "short");
|
|
|
|
InitBuiltinType(IntTy, "int");
|
|
|
|
InitBuiltinType(LongTy, "long");
|
|
|
|
InitBuiltinType(LongLongTy, "long long");
|
2006-11-12 00:37:36 +00:00
|
|
|
|
|
|
|
// C99 6.2.5p6.
|
2006-11-12 00:53:46 +00:00
|
|
|
InitBuiltinType(UnsignedCharTy, "unsigned char");
|
|
|
|
InitBuiltinType(UnsignedShortTy, "unsigned short");
|
|
|
|
InitBuiltinType(UnsignedIntTy, "unsigned int");
|
|
|
|
InitBuiltinType(UnsignedLongTy, "unsigned long");
|
|
|
|
InitBuiltinType(UnsignedLongLongTy, "unsigned long long");
|
2006-11-12 00:37:36 +00:00
|
|
|
|
|
|
|
// C99 6.2.5p10.
|
2006-11-12 00:53:46 +00:00
|
|
|
InitBuiltinType(FloatTy, "float");
|
|
|
|
InitBuiltinType(DoubleTy, "double");
|
|
|
|
InitBuiltinType(LongDoubleTy, "long double");
|
2006-11-12 00:37:36 +00:00
|
|
|
|
|
|
|
// C99 6.2.5p11.
|
2006-11-12 00:53:46 +00:00
|
|
|
InitBuiltinType(FloatComplexTy, "float _Complex");
|
|
|
|
InitBuiltinType(DoubleComplexTy, "double _Complex");
|
|
|
|
InitBuiltinType(LongDoubleComplexTy, "long double _Complex");
|
2006-11-12 00:37:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getPointerType - Return the uniqued reference to the type for a pointer to
|
|
|
|
/// the specified type.
|
2006-11-12 08:50:50 +00:00
|
|
|
TypeRef ASTContext::getPointerType(TypeRef T) {
|
2006-11-12 00:53:46 +00:00
|
|
|
// FIXME: This is obviously braindead!
|
|
|
|
// Unique pointers, to guarantee there is only one pointer of a particular
|
|
|
|
// structure.
|
|
|
|
for (unsigned i = 0, e = Types.size(); i != e; ++i)
|
2006-11-12 00:56:20 +00:00
|
|
|
if (PointerType *PTy = dyn_cast<PointerType>(Types[i]))
|
2006-11-12 08:50:50 +00:00
|
|
|
if (PTy->getPointeeType() == T)
|
2006-11-12 00:53:46 +00:00
|
|
|
return Types[i];
|
2006-11-12 00:37:36 +00:00
|
|
|
|
2006-11-12 08:50:50 +00:00
|
|
|
// If the pointee type isn't canonical, this won't be a canonical type either,
|
|
|
|
// so fill in the canonical type field.
|
2006-11-12 00:37:36 +00:00
|
|
|
Type *Canonical = 0;
|
|
|
|
if (!T->isCanonical())
|
|
|
|
Canonical = getPointerType(T.getCanonicalType()).getTypePtr();
|
2006-11-12 00:53:46 +00:00
|
|
|
|
|
|
|
Types.push_back(new PointerType(T, Canonical));
|
|
|
|
return Types.back();
|
2006-11-10 06:34:16 +00:00
|
|
|
}
|
|
|
|
|
2006-11-12 08:50:50 +00:00
|
|
|
/// getArrayType - Return the unique reference to the type for an array of the
|
|
|
|
/// specified element type.
|
|
|
|
TypeRef ASTContext::getArrayType(TypeRef EltTy,ArrayType::ArraySizeModifier ASM,
|
|
|
|
unsigned EltTypeQuals, void *NumElts) {
|
|
|
|
#warning "IGNORING SIZE"
|
|
|
|
|
|
|
|
// FIXME: This is obviously braindead!
|
|
|
|
// Unique array, to guarantee there is only one array of a particular
|
|
|
|
// structure.
|
|
|
|
for (unsigned i = 0, e = Types.size(); i != e; ++i)
|
|
|
|
if (ArrayType *ATy = dyn_cast<ArrayType>(Types[i]))
|
|
|
|
if (ATy->getElementType() == EltTy &&
|
|
|
|
ATy->getSizeModifier() == ASM &&
|
|
|
|
ATy->getIndexTypeQualifier() == EltTypeQuals)
|
|
|
|
return Types[i];
|
|
|
|
|
|
|
|
// If the element type isn't canonical, this won't be a canonical type either,
|
|
|
|
// so fill in the canonical type field.
|
|
|
|
Type *Canonical = 0;
|
|
|
|
if (!EltTy->isCanonical())
|
|
|
|
Canonical = getArrayType(EltTy.getCanonicalType(), ASM, EltTypeQuals,
|
|
|
|
NumElts).getTypePtr();
|
|
|
|
|
|
|
|
Types.push_back(new ArrayType(EltTy, ASM, EltTypeQuals, Canonical));
|
|
|
|
return Types.back();
|
|
|
|
}
|
|
|
|
|
2006-11-10 07:17:23 +00:00
|
|
|
|