From d0f3d30643b485c6fb16237a0a294ed323dbd574 Mon Sep 17 00:00:00 2001 From: Stefano Sanfilippo Date: Thu, 27 Nov 2014 22:10:10 +0100 Subject: [PATCH] Fixing two NPEs in case of missing else and missing main. --- Nodes.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Nodes.cpp b/Nodes.cpp index db18654..d1db6b0 100644 --- a/Nodes.cpp +++ b/Nodes.cpp @@ -89,10 +89,12 @@ void Branch::emit(std::ostream &stream, int indent) { } } - stream << " else {\n"; - els->emit(stream, indent + 1); - emitIndent(stream, indent); - stream << "}"; + if (els != nullptr) { + stream << " else {\n"; + els->emit(stream, indent + 1); + emitIndent(stream, indent); + stream << "}"; + } } void VarDeclaration::emit(std::ostream &stream, int indent) { @@ -186,6 +188,8 @@ void Program::emit(std::ostream &stream, int indent) { f->emit(stream); } - main->emit(stream); + if (main != nullptr) { + main->emit(stream); + } }