Ejemplo n.º 1
0
QString GeneratorForCallGenerator::commonGeneratedString(const QSharedPointer<ElementIdentifier> &calledIdentifier
		, const QSharedPointer<Identifier> &generatorNameNode
		, const GeneratorConfigurer &generatorConfigurer
		, ScopeInfo &scopeInfo)
{
	const auto currentElementId = GeneratorForElementIdentifierNode::neededElementId(calledIdentifier
			, generatorConfigurer, scopeInfo);
	const auto currentElementType = TypeQualifier::elementIdentifierType(calledIdentifier
			, generatorConfigurer, scopeInfo);

	const auto diagramId = generatorConfigurer.diagramId();
	const auto editorManagerInterface = generatorConfigurer.editorManagerInterface();

	const auto elementIdInMetamodel = idInMetamodel(editorManagerInterface, currentElementType, diagramId);

	const auto generationRuleForCurrentElement = editorManagerInterface->generationRule(elementIdInMetamodel);
	QSharedPointer<Node> generatedTree = TreeGeneratorFromString::generatedTreeFromString(generationRuleForCurrentElement);

	scopeInfo.currentScope().changeCurrentId(currentElementId);

	QString resultOfGeneration = "";
	if (!generatorNameNode) {
		resultOfGeneration = CommonGenerator::generatedResult(generatedTree, generatorConfigurer, scopeInfo);
	} else {
		QString generatorName = generatorNameNode->name();
		scopeInfo.currentScope().changeCurrentGeneratorName(generatorName);

		resultOfGeneration = CommonGenerator::generatedResult(generatedTree, generatorConfigurer, scopeInfo);
	}

	scopeInfo.currentScope().removeLastCurrentId();

	return resultOfGeneration;
}
qReal::Id GeneratorForElementIdentifierNode::neededElementId(
		const QSharedPointer<ElementIdentifier> &elementIdentifierNode
		, const GeneratorConfigurer &generatorConfigurer
		, ScopeInfo &scopeInfo)
{
	const auto identifierPart = elementIdentifierNode->identifierPart();
	const auto optionalTransitionPart = elementIdentifierNode->optionalTransitionPart();

	const auto logicalModelInterface = generatorConfigurer.logicalModelInterface();

	qReal::Id elementId;
	if (identifierPart->is<Identifier>()) {
		elementId = scopeInfo.variablesTable().currentId(qrtext::as<Identifier>(identifierPart)->name());
	} else {
		elementId = scopeInfo.currentScope().currentId();
	}

	if (optionalTransitionPart) {
		// we have to return transitionEnd or transitionStart for this element
		if (optionalTransitionPart->is<TransitionEnd>()) {
			return logicalModelInterface->to(elementId);
		} else if (optionalTransitionPart->is<TransitionStart>()) {
			return logicalModelInterface->from(elementId);
		} else {
			// TODO: throw exception
			qDebug() << "ERROR";
			return qReal::Id::rootId();
		}
	} else {
		return elementId;
	}
}