Making output operator for Type and Operator part of the iface.

This commit is contained in:
Stefano Sanfilippo 2015-03-12 17:52:27 +01:00
parent 09c69f163f
commit 1ba0e79c01
3 changed files with 72 additions and 68 deletions

View File

@ -270,34 +270,6 @@ bool CppEmitter::emit(Function const& function) {
return stream;
}
std::ostream& operator<<(std::ostream &stream, Type const& 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;
case Type::VOID:
stream << "void";
break;
case Type::UNKNOWN:
stream << "???????????";
break;
}
return stream;
}
bool CppEmitter::emitFunctionParams(PointerList<FunArg> const& funargs) {
if (funargs.empty()) return stream;
@ -347,46 +319,6 @@ bool CppEmitter::emit(VarDeclaration const& decl) {
return stream;
}
std::ostream& operator<<(std::ostream &stream, Operator op) {
switch (op) {
case Operator::PLUS:
stream << '+';
break;
case Operator::MINUS:
stream << '-';
break;
case Operator::TIMES:
stream << '*';
break;
case Operator::DIV:
stream << '/';
break;
case Operator::SHL:
stream << "<<";
break;
case Operator::SHR:
stream << ">>";
break;
case Operator::LT:
stream << '<';
break;
case Operator::GT:
stream << '>';
break;
case Operator::GTE:
stream << ">=";
break;
case Operator::LTE:
stream << "<=";
break;
case Operator::EQ:
stream << "==";
break;
}
return stream;
}
bool CppEmitter::emit(BinaryExpression const& node) {
GUARDED(node.getLeft().emit(this));
stream << ' ' << node.getOperator() << ' ';

View File

@ -32,3 +32,71 @@ Function *monicelli::makeMain(PointerList<Statement> *body) {
return new Function(proto, body);
}
std::ostream& monicelli::operator<<(std::ostream &stream, Type const& 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;
case Type::VOID:
stream << "void";
break;
case Type::UNKNOWN:
stream << "???????????";
break;
}
return stream;
}
std::ostream& monicelli::operator<<(std::ostream &stream, Operator const& op) {
switch (op) {
case Operator::PLUS:
stream << '+';
break;
case Operator::MINUS:
stream << '-';
break;
case Operator::TIMES:
stream << '*';
break;
case Operator::DIV:
stream << '/';
break;
case Operator::SHL:
stream << "<<";
break;
case Operator::SHR:
stream << ">>";
break;
case Operator::LT:
stream << '<';
break;
case Operator::GT:
stream << '>';
break;
case Operator::GTE:
stream << ">=";
break;
case Operator::LTE:
stream << "<=";
break;
case Operator::EQ:
stream << "==";
break;
}
return stream;
}

View File

@ -42,12 +42,16 @@ enum class Type {
UNKNOWN
};
std::ostream& operator<<(std::ostream&, Type const&);
enum class Operator {
PLUS, MINUS, TIMES, DIV,
SHL, SHR,
LT, GT, GTE, LTE, EQ
};
std::ostream& operator<<(std::ostream&, Operator const&);
class Emittable {
public:
virtual ~Emittable() {}