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-13 14:22:30 +08:00
|
|
|
std::string R;
|
|
|
|
AppendToString(R);
|
|
|
|
std::cerr << R << "\n";
|
2006-11-12 08:37:36 +08:00
|
|
|
}
|
|
|
|
|
2006-11-13 14:22:30 +08:00
|
|
|
static void AppendTypeQualList(std::string &S, unsigned TypeQuals) {
|
2006-11-12 16:50:50 +08:00
|
|
|
// Note: funkiness to ensure we get a space only between quals.
|
|
|
|
bool NonePrinted = true;
|
|
|
|
if (TypeQuals & TypeRef::Const)
|
2006-11-13 14:22:30 +08:00
|
|
|
S += "const", NonePrinted = false;
|
2006-11-12 16:50:50 +08:00
|
|
|
if (TypeQuals & TypeRef::Volatile)
|
2006-11-13 14:22:30 +08:00
|
|
|
S += (NonePrinted+" volatile"), NonePrinted = false;
|
2006-11-12 16:50:50 +08:00
|
|
|
if (TypeQuals & TypeRef::Restrict)
|
2006-11-13 14:22:30 +08:00
|
|
|
S += (NonePrinted+" restrict"), NonePrinted = false;
|
|
|
|
}
|
2006-11-12 16:50:50 +08:00
|
|
|
|
2006-11-13 14:22:30 +08:00
|
|
|
void TypeRef::AppendToString(std::string &S) const {
|
2006-11-12 07:56:48 +08:00
|
|
|
if (isNull()) {
|
2006-11-13 14:22:30 +08:00
|
|
|
S += "NULL TYPE\n";
|
2006-11-12 07:56:48 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-11-13 14:22:30 +08:00
|
|
|
getTypePtr()->AppendToString(S);
|
2006-11-12 07:56:48 +08:00
|
|
|
|
|
|
|
// Print qualifiers as appropriate.
|
2006-11-12 16:50:50 +08:00
|
|
|
if (unsigned TQ = getQualifiers()) {
|
2006-11-13 14:22:30 +08:00
|
|
|
S += ' ';
|
|
|
|
AppendTypeQualList(S, TQ);
|
2006-11-12 16:50:50 +08:00
|
|
|
}
|
2006-11-12 08:37:36 +08:00
|
|
|
}
|
|
|
|
|
2006-11-13 14:22:30 +08:00
|
|
|
void BuiltinType::AppendToString(std::string &S) const {
|
|
|
|
S += Name;
|
2006-11-12 08:37:36 +08:00
|
|
|
}
|
|
|
|
|
2006-11-13 14:22:30 +08:00
|
|
|
void PointerType::AppendToString(std::string &S) const {
|
|
|
|
PointeeType.AppendToString(S);
|
|
|
|
S += '*';
|
2006-11-12 07:56:48 +08:00
|
|
|
}
|
2006-11-12 16:50:50 +08:00
|
|
|
|
2006-11-13 14:22:30 +08:00
|
|
|
void ArrayType::AppendToString(std::string &S) const {
|
|
|
|
ElementType.AppendToString(S);
|
|
|
|
S += '[';
|
2006-11-12 16:50:50 +08:00
|
|
|
|
|
|
|
if (IndexTypeQuals) {
|
2006-11-13 14:22:30 +08:00
|
|
|
AppendTypeQualList(S, IndexTypeQuals);
|
|
|
|
S += ' ';
|
2006-11-12 16:50:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (SizeModifier == Static)
|
2006-11-13 14:22:30 +08:00
|
|
|
S += "static";
|
2006-11-12 16:50:50 +08:00
|
|
|
else if (SizeModifier == Star)
|
2006-11-13 14:22:30 +08:00
|
|
|
S += '*';
|
2006-11-12 16:50:50 +08:00
|
|
|
|
2006-11-13 14:22:30 +08:00
|
|
|
S += ']';
|
2006-11-12 16:50:50 +08:00
|
|
|
}
|