<commit_before>#include "details/pass/build-ast-to-ir/scope.h"
#include "details/grammar/nany.h"

using namespace Yuni;





namespace Nany
{
namespace IR
{
namespace Producer
{


	bool Scope::visitASTExprIf(Node& node, LVID& localvar)
	{
		assert(node.rule == rgIf);
		assert(not node.children.empty());

		localvar = 0;
		uint32_t childcount = static_cast<uint32_t>(node.children.size());
		if (unlikely(childcount != 2 and childcount != 3))
		{
			ICE(node) << "if: invalid number of children";
			return false;
		}

		auto& out = program();
		bool success = true;
		// new scope for the condition
		IR::Producer::Scope scopeIf{*this};
		// evalation of the condition
		uint32_t condlvid = out.emitStackalloc(scopeIf.nextvar(), nyt_bool);

		bool hasElseClause = (childcount == 3);

		// expression
		{
			auto& condition = *(node.children[0]);
			uint32_t exprEval = 0;
			success &= scopeIf.visitASTExpr(condition, exprEval, false);
			out.emitAssign(condlvid, exprEval, false);
		}

		uint32_t labelElse = (hasElseClause ? scopeIf.nextvar() : 0);
		uint32_t labelEnd  = scopeIf.nextvar();

		// jump to the 'else' clause if false (or end)
		out.emitJz(condlvid, 0, (hasElseClause ? labelElse : labelEnd));

		// if-then...
		{
			IR::Producer::Scope scopeThen{scopeIf};
			auto& thenClause = *(node.children[1]);
			scopeThen.emitDebugpos(thenClause);

			for (auto& stmt: thenClause.children)
				scopeThen.visitASTStmt(*stmt);
		}
		if (hasElseClause)
		{
			// jump to the end to not execute the 'else' clause
			out.emitJmp(labelEnd);
		}

		// ...else
		if (hasElseClause)
		{
			IR::Producer::Scope scopeElse{scopeIf};
			out.emitLabel(labelElse);
			auto& elseClause = *(node.children[2]);
			scopeElse.emitDebugpos(elseClause);

			for (auto& stmt: elseClause.children)
				scopeElse.visitASTStmt(*stmt);
		}

		out.emitLabel(labelEnd);
		return success;
	}






} // namespace Producer
} // namespace IR
} // namespace Nany<commit_msg>if: added missing error status checking<commit_after>#include "details/pass/build-ast-to-ir/scope.h"
#include "details/grammar/nany.h"

using namespace Yuni;





namespace Nany
{
namespace IR
{
namespace Producer
{


	bool Scope::visitASTExprIf(Node& node, LVID& localvar)
	{
		assert(node.rule == rgIf);
		assert(not node.children.empty());

		localvar = 0;
		uint32_t childcount = static_cast<uint32_t>(node.children.size());
		if (unlikely(childcount != 2 and childcount != 3))
		{
			ICE(node) << "if: invalid number of children";
			return false;
		}

		auto& out = program();
		bool success = true;
		// new scope for the condition
		IR::Producer::Scope scopeIf{*this};
		// evalation of the condition
		uint32_t condlvid = out.emitStackalloc(scopeIf.nextvar(), nyt_bool);

		bool hasElseClause = (childcount == 3);

		// expression
		{
			auto& condition = *(node.children[0]);
			uint32_t exprEval = 0;
			success &= scopeIf.visitASTExpr(condition, exprEval, false);
			out.emitAssign(condlvid, exprEval, false);
		}

		uint32_t labelElse = (hasElseClause ? scopeIf.nextvar() : 0);
		uint32_t labelEnd  = scopeIf.nextvar();

		// jump to the 'else' clause if false (or end)
		out.emitJz(condlvid, 0, (hasElseClause ? labelElse : labelEnd));

		// if-then...
		{
			IR::Producer::Scope scopeThen{scopeIf};
			auto& thenClause = *(node.children[1]);
			scopeThen.emitDebugpos(thenClause);

			for (auto& stmt: thenClause.children)
				success &= scopeThen.visitASTStmt(*stmt);
		}
		if (hasElseClause)
		{
			// jump to the end to not execute the 'else' clause
			out.emitJmp(labelEnd);
		}

		// ...else
		if (hasElseClause)
		{
			IR::Producer::Scope scopeElse{scopeIf};
			out.emitLabel(labelElse);
			auto& elseClause = *(node.children[2]);
			scopeElse.emitDebugpos(elseClause);

			for (auto& stmt: elseClause.children)
				success &= scopeElse.visitASTStmt(*stmt);
		}

		out.emitLabel(labelEnd);
		return success;
	}






} // namespace Producer
} // namespace IR
} // namespace Nany
{'fraction_non_alphanumeric': 0.14101265822784811, 'fraction_numerical': 0.011139240506329114, 'mean_word_length': 3.7035714285714287, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1889307', 'n_tokens_mistral': 1583, 'n_tokens_neox': 1372, 'n_words': 308}