| /******************************************************************************* |
| * 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.executionEnvironment; |
| |
| import java.util.Hashtable; |
| import java.util.Map; |
| |
| import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.definitions.Rule; |
| import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.definitions.SymbolicRuleParameter; |
| import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.definitions.Variable; |
| import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.enums.DirectionKind; |
| import org.eclipse.viatra2.framework.IFramework; |
| |
| public class CallRuleExecutionEnvironment extends ExecutionEnvironment { |
| /* |
| * The symbolic-actual parameter mapping should be done. --> at the onBegin |
| * for in and inout, and at the onTerminate for inout and out types. Out and |
| * inout types must be Variables |
| */ |
| |
| private Rule rule; |
| |
| public CallRuleExecutionEnvironment(IFramework framework, Rule called) { |
| super(framework); |
| rule = called; |
| } |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see org.eclipse.viatra2.gtasm.interpreter.executionEnvironment.ExecutionEnvironment#onBegin() |
| */ |
| public void onBegin(Map<Variable, Object> variables) { |
| variableValues.putAll(variables); |
| |
| // super.onBegin(); |
| } |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see org.eclipse.viatra2.gtasm.interpreter.executionEnvironment.ExecutionEnvironment#onTerminate() |
| */ |
| @Override |
| public Map<Variable, Object> onTerminate() { |
| Hashtable<Variable, Object> returnVariables = new Hashtable<Variable, Object>(); |
| |
| for (Object symbolicRuleParameter : rule.getSymParameters()) { |
| |
| // Only the OUT or INOUT type symbolic variables' values are |
| // returned |
| if (!DirectionKind.IN_LITERAL |
| .equals(((SymbolicRuleParameter) symbolicRuleParameter) |
| .getDirection())) { |
| returnVariables |
| .put( |
| ((SymbolicRuleParameter) symbolicRuleParameter) |
| .getVariable(), |
| variableValues |
| .get(((SymbolicRuleParameter) symbolicRuleParameter) |
| .getVariable())); |
| } |
| } |
| return returnVariables; |
| } |
| |
| } |