2006-11-12 06:59:23 +08:00
|
|
|
//===--- Type.cpp - Type representation and manipulation ------------------===//
|
|
|
|
//
|
|
|
|
// 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 type-related functionality.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/AST/Type.h"
|
2006-11-12 08:37:36 +08:00
|
|
|
#include <iostream>
|
2006-11-12 06:59:23 +08:00
|
|
|
using namespace llvm;
|
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
Type::~Type() {}
|
|
|
|
|
2006-11-12 08:37:36 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Type Printing
|
|
|
|
//===----------------------------------------------------------------------===//
|
2006-11-12 06:59:23 +08:00
|
|
|
|
2006-11-12 07:56:48 +08:00
|
|
|
void TypeRef::dump() const {
|
2006-11-12 08:37:36 +08:00
|
|
|
print(std::cerr);
|
|
|
|
std::cerr << "\n";
|
|
|
|
}
|
|
|
|
|
2006-11-12 16:50:50 +08:00
|
|
|
static void PrintTypeQualList(std::ostream &OS, unsigned TypeQuals) {
|
|
|
|
// Note: funkiness to ensure we get a space only between quals.
|
|
|
|
bool NonePrinted = true;
|
|
|
|
if (TypeQuals & TypeRef::Const)
|
|
|
|
OS << "const", NonePrinted = false;
|
|
|
|
if (TypeQuals & TypeRef::Volatile)
|
|
|
|
OS << (NonePrinted+" volatile"), NonePrinted = false;
|
|
|
|
if (TypeQuals & TypeRef::Restrict)
|
|
|
|
OS << (NonePrinted+" restrict"), NonePrinted = false;
|
|
|
|
}
|
|
|
|
|
2006-11-12 08:37:36 +08:00
|
|
|
void TypeRef::print(std::ostream &OS) const {
|
2006-11-12 07:56:48 +08:00
|
|
|
if (isNull()) {
|
2006-11-12 08:37:36 +08:00
|
|
|
OS << "NULL TYPE\n";
|
2006-11-12 07:56:48 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-11-12 08:37:36 +08:00
|
|
|
getTypePtr()->print(OS);
|
2006-11-12 07:56:48 +08:00
|
|
|
|
|
|
|
// Print qualifiers as appropriate.
|
2006-11-12 16:50:50 +08:00
|
|
|
if (unsigned TQ = getQualifiers()) {
|
|
|
|
OS << " ";
|
|
|
|
PrintTypeQualList(OS, TQ);
|
|
|
|
}
|
2006-11-12 08:37:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void BuiltinType::print(std::ostream &OS) const {
|
|
|
|
OS << Name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PointerType::print(std::ostream &OS) const {
|
|
|
|
PointeeType.print(OS);
|
|
|
|
OS << "*";
|
2006-11-12 07:56:48 +08:00
|
|
|
}
|
2006-11-12 16:50:50 +08:00
|
|
|
|
|
|
|
void ArrayType::print(std::ostream &OS) const {
|
|
|
|
ElementType.print(OS);
|
|
|
|
OS << "[";
|
|
|
|
|
|
|
|
if (IndexTypeQuals) {
|
|
|
|
PrintTypeQualList(OS, IndexTypeQuals);
|
|
|
|
OS << " ";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SizeModifier == Static)
|
|
|
|
OS << "static";
|
|
|
|
else if (SizeModifier == Star)
|
|
|
|
OS << "*";
|
|
|
|
|
|
|
|
OS << "]";
|
|
|
|
}
|