Make Type an enum class (C++11 ftw)

This commit is contained in:
Markus Hauschild
2013-06-01 16:22:01 +02:00
parent 4d805b34db
commit 6d2e40778c
10 changed files with 38 additions and 21 deletions

View File

@@ -1,7 +1,7 @@
#include "AST/FunctionDefinition.h"
#include "AST/ASTVisitor.h"
FunctionDefinition::FunctionDefinition(Type *type, std::string name, ParameterList *params, StatementList *sl) : type_(type), name_(name), params_(params), sl_(sl) {
FunctionDefinition::FunctionDefinition(Type type, std::string name, ParameterList *params, StatementList *sl) : type_(type), name_(name), params_(params), sl_(sl) {
//
}
@@ -13,7 +13,7 @@ void FunctionDefinition::accept(ASTVisitor* visitor) {
visitor->visit(this);
}
Type* FunctionDefinition::getType() {
Type FunctionDefinition::getType() {
return type_;
}

View File

@@ -13,7 +13,7 @@ void ParameterList::accept(ASTVisitor* visitor) {
visitor->visit(this);
}
void ParameterList::addParameter(Type* type, std::string name) {
void ParameterList::addParameter(Type type, std::string name) {
params_.push_back(Parameter(type, name));
}

View File

@@ -107,7 +107,7 @@ void PrintVisitor::visit(FunctionDefinition* e) {
println(ss.str());
ss.str("");
ss.clear();
ss << "Type: " << e->getType();
ss << "Type: " << typeToString(e->getType());
println(ss.str());
ParameterList* params = e->getParams();
if (params) {
@@ -140,7 +140,7 @@ void PrintVisitor::visit(ParameterList* e) {
println(ss.str());
ss.str("");
ss.clear();
ss << "Type: " << p.first->getName();
ss << "Type: " << typeToString(p.first);
println(ss.str());
}
level_--;
@@ -216,7 +216,7 @@ void PrintVisitor::visit(VariableDefinition* e) {
println(ss.str());
ss.str("");
ss.clear();
ss << "Type: " << e->getType()->getName();
ss << "Type: " << typeToString(e->getType());
println(ss.str());
level_--;
}

View File

@@ -1 +1,16 @@
#include "AST/Type.h"
std::string typeToString(Type type) {
switch (type) {
case Type::BOOL:
return "bool";
case Type::INT:
return "int";
case Type::STRING:
return "string";
case Type::VOID:
return "void";
default:
return "ERROR";
}
}

View File

@@ -1,7 +1,7 @@
#include "AST/VariableDefinition.h"
#include "AST/ASTVisitor.h"
VariableDefinition::VariableDefinition(Type* type, std::string name) : type_(type), name_(name) {
VariableDefinition::VariableDefinition(Type type, std::string name) : type_(type), name_(name) {
//
}
@@ -13,7 +13,7 @@ void VariableDefinition::accept(ASTVisitor* visitor) {
visitor->visit(this);
}
Type* VariableDefinition::getType() {
Type VariableDefinition::getType() {
return type_;
}