2013-12-23 01:26:24 -06:00
|
|
|
#include "Type.h"
|
|
|
|
|
|
|
|
|
|
Type::Type() {
|
|
|
|
|
indirection = 0;
|
|
|
|
|
baseType = none;
|
2014-01-19 18:20:52 -05:00
|
|
|
typeDefinition = NULL;
|
2013-12-23 01:26:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Type::Type(ValueType typeIn) {
|
|
|
|
|
indirection = 0;
|
|
|
|
|
baseType = typeIn;
|
2014-01-19 18:20:52 -05:00
|
|
|
typeDefinition = NULL;
|
2013-12-23 01:26:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Type::Type(ValueType typeIn, int indirectionIn) {
|
|
|
|
|
indirection = indirectionIn;
|
|
|
|
|
baseType = typeIn;
|
2014-01-19 18:20:52 -05:00
|
|
|
typeDefinition = NULL;
|
2013-12-23 01:26:24 -06:00
|
|
|
}
|
|
|
|
|
|
2014-01-07 13:14:58 -05:00
|
|
|
Type::Type(NodeTree<ASTData>* typeDefinitionIn) {
|
2013-12-23 01:26:24 -06:00
|
|
|
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;
|
2013-12-23 01:26:24 -06:00
|
|
|
}
|
|
|
|
|
|
2014-01-07 13:14:58 -05:00
|
|
|
Type::Type(ValueType typeIn, NodeTree<ASTData>* typeDefinitionIn, int indirectionIn) {
|
|
|
|
|
baseType = typeIn;
|
|
|
|
|
indirection = indirectionIn;
|
|
|
|
|
typeDefinition = typeDefinitionIn;
|
|
|
|
|
}
|
2013-12-23 01:26:24 -06:00
|
|
|
|
|
|
|
|
Type::~Type() {
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-06 13:13:40 -05:00
|
|
|
const bool Type::operator==(const Type &other) const {
|
|
|
|
|
return( baseType == other.baseType && indirection == other.indirection && typeDefinition == other.typeDefinition);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const bool Type::operator!=(const Type &other) const {
|
|
|
|
|
return(!this->operator==(other));
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-23 01:26:24 -06:00
|
|
|
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";
|
2013-12-23 01:26:24 -06:00
|
|
|
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";
|
2013-12-23 01:26:24 -06:00
|
|
|
}
|
|
|
|
|
for (int i = 0; i < indirection; i++)
|
|
|
|
|
typeString += "*";
|
|
|
|
|
return typeString;
|
|
|
|
|
}
|