Emitting prototypes for all declared functions.

This commit is contained in:
Stefano Sanfilippo 2014-11-30 13:05:59 +01:00
parent 76a4e3d7f2
commit 0a49ccfeca
2 changed files with 16 additions and 3 deletions

View File

@ -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 <iostream>\n";
stream << "#include <cstdlib>\n\n";
for (Function *f: functions) {
f->emitSignature(stream);
stream << ";\n";
}
stream << "\n";
for (Function *f: functions) {
f->emit(stream);
}

View File

@ -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<Id> name;