Files
kraken/src/Type.cpp

75 lines
1.5 KiB
C++
Raw Normal View History

#include "Type.h"
Type::Type() {
indirection = 0;
baseType = none;
}
Type::Type(ValueType typeIn) {
indirection = 0;
baseType = typeIn;
}
Type::Type(ValueType typeIn, int indirectionIn) {
indirection = indirectionIn;
baseType = typeIn;
}
2014-01-07 13:14:58 -05:00
Type::Type(NodeTree<ASTData>* typeDefinitionIn) {
indirection = 0;
2014-01-07 13:14:58 -05:00
baseType = none;
typeDefinition = typeDefinitionIn;
}
Type::Type(NodeTree<ASTData>* typeDefinitionIn, int indirectionIn) {
indirection = indirectionIn;
baseType = none;
typeDefinition = typeDefinitionIn;
}
2014-01-07 13:14:58 -05:00
Type::Type(ValueType typeIn, NodeTree<ASTData>* typeDefinitionIn, int indirectionIn) {
baseType = typeIn;
indirection = indirectionIn;
typeDefinition = typeDefinitionIn;
}
Type::~Type() {
}
std::string Type::toString() {
std::string typeString;
switch (baseType) {
case none:
2014-01-07 13:14:58 -05:00
if (typeDefinition)
typeString = typeDefinition->getDataRef()->symbol.getName();
else
typeString = "none";
break;
case void_type:
typeString = "void";
break;
case boolean:
typeString = "bool";
break;
case integer:
typeString = "int";
break;
case floating:
typeString = "float";
break;
case double_percision:
typeString = "double";
break;
case character:
typeString = "char";
break;
default:
2014-01-07 13:14:58 -05:00
if (typeDefinition)
typeString = typeDefinition->getDataRef()->symbol.getName();
else
typeString = "unknown_type";
}
for (int i = 0; i < indirection; i++)
typeString += "*";
return typeString;
}