From 0a49ccfeca6fa1f7b275479650ac429cc1628b50 Mon Sep 17 00:00:00 2001 From: Stefano Sanfilippo Date: Sun, 30 Nov 2014 13:05:59 +0100 Subject: [PATCH] Emitting prototypes for all declared functions. --- Nodes.cpp | 18 +++++++++++++++--- Nodes.hpp | 1 + 2 files changed, 16 insertions(+), 3 deletions(-) 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;