Make Type an enum class (C++11 ftw)
This commit is contained in:
@@ -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_;
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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_--;
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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_;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user