blob: d6f4ac110944a229d4931bcbf53bb1f0becc0f7d [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004-2008 Peter Pasztor, Akos Horvath, Gergely Varro, Istvan Rath and Daniel Varro
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Peter Pasztor, Akos Horvath, Gergely Varro, Istvan Rath - initial API and implementation
*******************************************************************************/
package org.eclipse.viatra2.gtasm.interpreter.impl.rules;
import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;
import org.eclipse.viatra2.gtasm.interpreter.exception.ASMInterpreterErrorStrings;
import org.eclipse.viatra2.gtasm.interpreter.exception.ViatraTransformationException;
import org.eclipse.viatra2.gtasm.interpreter.executionEnvironment.IExecutionEnvironment;
import org.eclipse.viatra2.gtasm.interpreter.impl.machine.ASMInterpreterException;
import org.eclipse.viatra2.gtasm.interpreter.term.rules.TermEvaluator;
import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.definitions.Variable;
import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.simpleRules.ASMRuleInvocation;
import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.simpleRules.RuleUpdate;
import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.simpleRules.RuleUpdateASMFunction;
import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.simpleRules.RuleUpdateVariable;
import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.terms.Term;
import org.eclipse.viatra2.interpreters.IProgressReport;
public class RuleUpdateInterpreter extends RuleInterpreter {
private static RuleUpdateInterpreter _instance = new RuleUpdateInterpreter();
public static RuleUpdateInterpreter getInstance() {
return _instance;
}
private RuleUpdateInterpreter()
{
;
}
@Override
public Boolean interpretRule(IExecutionEnvironment executionEnvironment, ASMRuleInvocation ruleToBeInterpreted, IProgressReport pr)
throws ViatraTransformationException
{
RuleUpdate ruleUpdate=(RuleUpdate)ruleToBeInterpreted;
if(ruleUpdate instanceof RuleUpdateVariable)
{Variable var = ((RuleUpdateVariable)ruleUpdate).getVariable().getVariable();
try {
executionEnvironment.setVariableValue(var,TermEvaluator.getInstance().evaluate(executionEnvironment, ((RuleUpdateVariable)ruleUpdate).getValue()));
return Boolean.TRUE;
} catch (ViatraTransformationException e) {
String[] context = {var.getName(), e.getMessage()};
throw new ASMInterpreterException(ASMInterpreterErrorStrings.SET_VAR_VALUE_AFTER_UPDATE_RULE
,context
,ruleUpdate);
}
//org.eclipse.viatra2.gtasm.interpreter.executionEnvironment.setVariableValue(((RuleUpdateVariable)ruleUpdate).getVariable().getVariable(),((RuleUpdateVariable)ruleUpdate).getValue());
//return Boolean.TRUE;
}
else if(ruleUpdate instanceof RuleUpdateASMFunction)
{
EList<Object> paramList = new BasicEList<Object>();
for (Term location : ((RuleUpdateASMFunction)ruleUpdate).getLocations()) {
paramList.add(TermEvaluator.getInstance().evaluate(executionEnvironment, location));
}
executionEnvironment.updateASMFunction(((RuleUpdateASMFunction)ruleUpdate).getFunction(),paramList,TermEvaluator.getInstance().evaluate(executionEnvironment,((RuleUpdateASMFunction)ruleUpdate).getValue()));
return Boolean.TRUE;
}
return Boolean.FALSE;
}
}