blob: ee74b9f2321e30dfc445524e9e8e89a550dad873 [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 java.util.Collection;
import org.eclipse.viatra2.gtasm.interpreter.exception.ViatraTransformationException;
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.internal.PatternMatcherErrorStrings;
import org.eclipse.viatra2.gtasm.patternmatcher.patterns.IPatternMatcher;
import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.definitions.Variable;
import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.enums.ValueKind;
import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.terms.GTPatternCall;
import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.terms.VariableReference;
/**
* NACCheckOperation checks an embedded negative pattern.
*/
public class NACCheckOperation extends CheckOperation {
private IPatternMatcher patternMatcher;
private int[] actualParameterMapping;
private Collection<Variable> passingVariables;
private GTPatternCall nacCall;
public NACCheckOperation(IPatternMatcher matcher,
int[] actualParameterMapping, GTPatternCall call, Collection<Variable> passingVariables) {
this.patternMatcher = matcher;
this.actualParameterMapping = actualParameterMapping;
nacCall = call;
this.passingVariables = passingVariables;
}
protected boolean check(MatchingFrame frame) throws PatternMatcherRuntimeException{
Object[] actualParameters = new Object[actualParameterMapping.length];
for (int i = 0; i < actualParameterMapping.length; i++) {
actualParameters[i] = frame.getValue(actualParameterMapping[i]);
if(actualParameters[i] == null
|| actualParameters[i].equals(ValueKind.UNDEF_LITERAL))
{
if(passingVariables.contains(((VariableReference)nacCall.getActualParameters().get(i)).getVariable()))
{
String[] context =
{nacCall.getCalledPattern().getName()
,nacCall.getCalledPattern().getSymParameters().get(i).getName()};
throw new PatternMatcherRuntimeException(
PatternMatcherErrorStrings.NAC_CALL_WITH_UNBOUND_PARAMETER
,context
,nacCall);
}
//TODO: else? it is a local variable that is only used in the NAC call
}
}
try {
return !patternMatcher.match(actualParameters);
} catch (ViatraTransformationException e) {
throw new PatternMatcherRuntimeException(e,nacCall);
}
}
public AnnotatedElement getErrorfulElement(MatchingFrame frame) {
return nacCall;
}
}