Adding operator << for Type enum.

This commit is contained in:
Stefano Sanfilippo 2014-11-28 20:18:50 +01:00
parent f96376438c
commit b31feeb4ea
2 changed files with 25 additions and 19 deletions

View File

@ -4,6 +4,28 @@ using namespace monicelli;
static const std::string BLOCK = " "; 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) { void emitIndent(std::ostream &stream, int indent) {
for (int i = 0; i < indent; ++i) { for (int i = 0; i < indent; ++i) {
stream << BLOCK; stream << BLOCK;
@ -98,25 +120,7 @@ void Branch::emit(std::ostream &stream, int indent) {
} }
void VarDeclaration::emit(std::ostream &stream, int indent) { void VarDeclaration::emit(std::ostream &stream, int indent) {
switch (type) { stream << 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 << ' ';
if (point) stream << '*'; if (point) stream << '*';
name->emit(stream); name->emit(stream);

View File

@ -15,6 +15,8 @@ enum class Type {
DOUBLE DOUBLE
}; };
std::ostream& operator<<(std::ostream &stream, const Type &type);
template <class T> template <class T>
using Pointer = std::unique_ptr<T>; using Pointer = std::unique_ptr<T>;