<commit_before>#include "generatorBase/parts/variables.h"

using namespace generatorBase;
using namespace parts;
using namespace qReal;

Variables::Variables(QString const &pathToTemplates
		, interpreterBase::robotModel::RobotModelInterface const &robotModel)
	: TemplateParametrizedEntity(pathToTemplates)
	, mRobotModel(robotModel)
{
}

void Variables::reinit(qrRepo::RepoApi const &api)
{
	mVariables.clear();
	QMap<QString, enums::variableType::VariableType> const reservedVars = reservedVariables();
	foreach (QString const &var, reservedVars.keys()) {
		mVariables.insert(var, reservedVars[var]);
	}

	QStringList expressions;
	IdList const blocks = api.elementsByType("Function");
	foreach (Id const &block, blocks) {
		if (api.hasProperty(block, "Body")) {
			expressions << api.stringProperty(block, "Body");
		}
	}

	inferTypes(expressions);
}

QString Variables::generateVariableString() const
{
	QStringList const reservedNames = reservedVariables().keys();
	QMap<QString, int> const intConsts = intConstants();
	QMap<QString, float> const floatConsts = floatConstants();
	QString result = "\n";

	// TODO: read it from template
	foreach (QString const &intConst, intConsts.keys()) {
		result += QString(intConstantDeclaration()).replace("@@NAME@@", intConst)
				.replace("@@VALUE@@", QString::number(intConsts[intConst]));
	}

	foreach (QString const &floatConst, floatConsts.keys()) {
		result += QString(floatConstantDeclaration()).replace("@@NAME@@", floatConst)
				.replace("@@VALUE@@", QString::number(floatConsts[floatConst]));<commit_msg>Variable init block supported in type inferer<commit_after>#include "generatorBase/parts/variables.h"

using namespace generatorBase;
using namespace parts;
using namespace qReal;

Variables::Variables(QString const &pathToTemplates
		, interpreterBase::robotModel::RobotModelInterface const &robotModel)
	: TemplateParametrizedEntity(pathToTemplates)
	, mRobotModel(robotModel)
{
}

void Variables::reinit(qrRepo::RepoApi const &api)
{
	mVariables.clear();
	QMap<QString, enums::variableType::VariableType> const reservedVars = reservedVariables();
	foreach (QString const &var, reservedVars.keys()) {
		mVariables.insert(var, reservedVars[var]);
	}

	QStringList expressions;
	IdList const funtionBlocks = api.elementsByType("Function");
	for (Id const &block : funtionBlocks) {
		if (api.hasProperty(block, "Body")) {
			expressions << api.stringProperty(block, "Body");
		}
	}

	IdList const initializationBlocks = api.elementsByType("VariableInit");
	for (Id const &block : initializationBlocks) {
		if (api.hasProperty(block, "variable") && api.hasProperty(block, "value")) {
			expressions << api.stringProperty(block, "variable") + " = " + api.stringProperty(block, "value");
		}
	}

	inferTypes(expressions);
}

QString Variables::generateVariableString() const
{
	QStringList const reservedNames = reservedVariables().keys();
	QMap<QString, int> const intConsts = intConstants();
	QMap<QString, float> const floatConsts = floatConstants();
	QString result = "\n";

	// TODO: read it from template
	foreach (QString const &intConst, intConsts.keys()) {
		result += QString(intConstantDeclaration()).replace("@@NAME@@", intConst)
				.replace("@@VALUE@@", QString::number(intConsts[intConst]));
	}

	foreach (QString const &floatConst, floatConsts.keys()) {
		result += QString(floatConstantDeclaration()).replace("@@NAME@@", floatConst)
				.replace("@@VALUE@@", QString::number(floatConsts[floatConst]));
{'fraction_non_alphanumeric': 0.14359712230215826, 'fraction_numerical': 0.0, 'mean_word_length': 6.828828828828829, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 9, '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': '6960106', 'n_tokens_mistral': 1085, 'n_tokens_neox': 1040, 'n_words': 222}