diff --git a/Nodes.cpp b/Nodes.cpp index 1ed587b..8df3fe3 100644 --- a/Nodes.cpp +++ b/Nodes.cpp @@ -194,15 +194,20 @@ void FunArg::emit(std::ostream &stream, int indent) { } void Function::emit(std::ostream &stream, int indent) { + emitSignature(stream, indent); + stream << " {\n"; + body->emit(stream, indent + 1); + stream << "}\n\n"; +} + +void Function::emitSignature(std::ostream &stream, int indent) { emitIndent(stream, indent); stream << type << ' '; name->emit(stream); stream << "("; args->emit(stream); - stream << ") {\n"; - body->emit(stream, indent + 1); - stream << "}\n\n"; + stream << ")"; } void Main::emit(std::ostream &stream, int indent) { @@ -217,6 +222,13 @@ void Program::emit(std::ostream &stream, int indent) { stream << "#include \n"; stream << "#include \n\n"; + for (Function *f: functions) { + f->emitSignature(stream); + stream << ";\n"; + } + + stream << "\n"; + for (Function *f: functions) { f->emit(stream); } diff --git a/Nodes.hpp b/Nodes.hpp index b51aeaa..b7e18c3 100644 --- a/Nodes.hpp +++ b/Nodes.hpp @@ -310,6 +310,7 @@ public: virtual ~Function() {} virtual void emit(std::ostream &stream, int indent = 0); + void emitSignature(std::ostream &stream, int indent = 0); private: Pointer name;