Fixed a ton of stuff with function templates. Works well now. Next up: multiple template types and fixing object definition ordering (both where templates should go and objects with other pointers)

This commit is contained in:
Nathan Braswell
2014-05-19 20:00:35 -04:00
parent b2c61b00f2
commit 39f945940d
8 changed files with 174 additions and 47 deletions

View File

@@ -19,6 +19,7 @@ Type::Type(ValueType typeIn, int indirectionIn) {
baseType = typeIn;
typeDefinition = NULL;
templateDefinition = NULL;
if (indirection < 0) SEGFAULT
}
Type::Type(NodeTree<ASTData>* typeDefinitionIn) {
@@ -32,6 +33,7 @@ Type::Type(NodeTree<ASTData>* typeDefinitionIn, int indirectionIn) {
baseType = none;
typeDefinition = typeDefinitionIn;
templateDefinition = NULL;
if (indirection < 0) SEGFAULT
}
Type::Type(ValueType typeIn, NodeTree<ASTData>* typeDefinitionIn, int indirectionIn) {
@@ -39,6 +41,7 @@ Type::Type(ValueType typeIn, NodeTree<ASTData>* typeDefinitionIn, int indirectio
indirection = indirectionIn;
typeDefinition = typeDefinitionIn;
templateDefinition = NULL;
if (indirection < 0) SEGFAULT
}
Type::Type(ValueType typeIn, NodeTree<Symbol>* templateDefinitionIn) {
indirection = 0;
@@ -70,6 +73,10 @@ std::string Type::toString() {
break;
case template_type:
typeString = "template: " + templateDefinition->getDataRef()->toString();
break;
case template_type_type:
typeString = "template_type_type";
break;
case void_type:
typeString = "void";
break;
@@ -96,9 +103,34 @@ std::string Type::toString() {
}
for (int i = 0; i < indirection; i++)
typeString += "*";
//std::cout << "Extra components of " << typeString << " are " << indirection << " " << typeDefinition << " " << templateDefinition << std::endl;
return typeString;
}
Type* Type::clone() {
return new Type(baseType, typeDefinition, indirection);
}
void Type::check() {
if (indirection < 0) SEGFAULT
}
int Type::getIndirection() {
return indirection;
}
void Type::setIndirection(int indirectionIn) {
indirection = indirectionIn;
check();
}
void Type::increaseIndirection() {
setIndirection(indirection+1);
}
void Type::decreaseIndirection() {
setIndirection(indirection-1);
}
void Type::modifyIndirection(int mod) {
setIndirection(indirection + mod);
}