diff --git a/Nodes.cpp b/Nodes.cpp index 6b85e04..755baa4 100644 --- a/Nodes.cpp +++ b/Nodes.cpp @@ -4,6 +4,28 @@ using namespace monicelli; static const std::string BLOCK = " "; +std::ostream& monicelli::operator<<(std::ostream &stream, const Type &type) { + switch (type) { + case Type::INT: + stream << "int"; + break; + case Type::CHAR: + stream << "char"; + break; + case Type::FLOAT: + stream << "float"; + break; + case Type::BOOL: + stream << "bool"; + break; + case Type::DOUBLE: + stream << "double"; + break; + } + + return stream; +} + void emitIndent(std::ostream &stream, int indent) { for (int i = 0; i < indent; ++i) { stream << BLOCK; @@ -98,25 +120,7 @@ void Branch::emit(std::ostream &stream, int indent) { } void VarDeclaration::emit(std::ostream &stream, int indent) { - switch (type) { - case Type::INT: - stream << "int"; - break; - case Type::CHAR: - stream << "char"; - break; - case Type::FLOAT: - stream << "float"; - break; - case Type::BOOL: - stream << "bool"; - break; - case Type::DOUBLE: - stream << "double"; - break; - } - - stream << ' '; + stream << type << ' '; if (point) stream << '*'; name->emit(stream); diff --git a/Nodes.hpp b/Nodes.hpp index 601f75a..97b00ce 100644 --- a/Nodes.hpp +++ b/Nodes.hpp @@ -15,6 +15,8 @@ enum class Type { DOUBLE }; +std::ostream& operator<<(std::ostream &stream, const Type &type); + template using Pointer = std::unique_ptr;