blob: 13e469542bf14d388754a46383978d4be184e57b [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004-2008 Akos Horvath, Gergely Varro 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:
* Akos Horvath, Gergely Varro - initial API and implementation
*******************************************************************************/
package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.operation;
import org.eclipse.viatra2.gtasm.interpreter.exception.ViatraTransformationException;
import org.eclipse.viatra2.gtasm.interpreter.executionEnvironment.IExecutionEnvironment;
import org.eclipse.viatra2.gtasm.interpreter.term.rules.TermEvaluator;
import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException;
import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.term.AbstractTermCheckOperation;
import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.term.TermCheckExecutionEnvironment;
import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.terms.Term;
import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.ContainmentConstraint;
import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTPattern;
public class TermEvaluationOperation extends AbstractTermCheckOperation {
private IExecutionEnvironment parentEnv;
private GTPattern pattern;
private int uid;
private Term term;
private int resultSlot;
private ContainmentConstraint containmentConstraint;
public TermEvaluationOperation(IExecutionEnvironment parentEnv,
GTPattern pattern, int uid, Term term, int resultSlot) {
this.parentEnv = parentEnv;
this.pattern = pattern;
this.uid = uid;
this.term = term;
this.containmentConstraint = null;
this.resultSlot = resultSlot;
}
public TermEvaluationOperation(IExecutionEnvironment parentEnv,
GTPattern pattern, int uid, ContainmentConstraint conCons, int resultSlot) {
this.parentEnv = parentEnv;
this.pattern = pattern;
this.uid = uid;
this.term = conCons.getParent();
this.containmentConstraint = conCons;
this.resultSlot = resultSlot;
}
protected boolean check(MatchingFrame frame)throws PatternMatcherRuntimeException{
TermCheckExecutionEnvironment env = new TermCheckExecutionEnvironment(parentEnv, pattern, uid, frame);
Object result = null;
try {
result = TermEvaluator.getInstance().evaluate(env, term);
} catch (ViatraTransformationException e) {
throw new PatternMatcherRuntimeException(e,containmentConstraint != null? containmentConstraint: term);
}
return (result != null ? frame.testAndSetValue(resultSlot, result) : false);
}
public AnnotatedElement getErrorfulElement(MatchingFrame frame) {
return containmentConstraint != null? containmentConstraint: term;
}
}