| /******************************************************************************* |
| * 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;
|
|
|
| import org.eclipse.viatra2.gtasm.patternmatcher.IMatching; |
| import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph.FlattenedPattern; |
| import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.definitions.Variable; |
|
|
| /**
|
| * MatchingFrame represents an array that contains the actual
|
| * mappings of variables to constants. A MatchingFrame maintains
|
| * a reference to a corresponding FlattenedPattern.
|
| *
|
| * The following mappings are used by the interpreted engine:
|
| * VariableType => PatternVariable
|
| * ValueType => AnyModelElement
|
| */
|
| public class MatchingFrame implements Cloneable,IMatching {
|
|
|
| /**
|
| * An internal, array-based representation of a matching.
|
| * Arrays are indexed by integers and contain values showing
|
| * the actual values.
|
| *
|
| * If a MatchingFrame represents a matching for a recursive
|
| * FlattenedPattern, then parent points to the
|
| * matching frame which is extended to get this matching.
|
| */
|
| private MatchingFrame parent;
|
|
|
| /**
|
| * The pattern variant for which this MatchingFrame is a
|
| * matching.
|
| */
|
| private FlattenedPattern pattern;
|
|
|
| /**
|
| * The array that physically holds the values.
|
| */
|
| private Object[] frame;
|
|
|
| public MatchingFrame(FlattenedPattern pattern) {
|
| this.parent = null;
|
| this.pattern = pattern;
|
| // this.frame = (IModelElement[]) new Object[pattern.getFrameSize()];
|
| this.frame = new Object[pattern.getFrameSize()];
|
| }
|
|
|
| MatchingFrame(FlattenedPattern pattern, MatchingFrame parent) {
|
| this.parent = parent;
|
| this.pattern = pattern;
|
| this.frame = new Object[pattern.getFrameSize()];
|
| }
|
|
|
| /**
|
| *
|
| * @param position
|
| * @return
|
| */
|
| public Object getValue(Integer position) {
|
| // TODO gervarro: return (position < frame.length ? frame[position] : pattern.get);
|
| return frame[position];
|
| }
|
|
|
| /**
|
| *
|
| * @param position
|
| * @param value
|
| */
|
| public void setValue(Integer position, Object value) {
|
| frame[position] = value;
|
| }
|
|
|
| public boolean testAndSetValue(Integer position, Object value) {
|
| if (frame[position] == null) {
|
| frame[position] = value;
|
| return true;
|
| } else {
|
| return frame[position].equals(value);
|
| }
|
| }
|
|
|
| /**
|
| * @return the parent
|
| */
|
| public MatchingFrame getParent() {
|
| return parent;
|
| }
|
|
|
| /**
|
| * @param parent the parent to set
|
| */
|
| public void setParent(MatchingFrame parent) {
|
| this.parent = parent;
|
| }
|
|
|
| /**
|
| * @return the pattern
|
| */
|
| public FlattenedPattern getPattern() {
|
| return pattern;
|
| }
|
|
|
| /**
|
| * @param pattern the pattern to set
|
| */
|
| public void setPattern(FlattenedPattern pattern) {
|
| this.pattern = pattern;
|
| }
|
|
|
| public Object clone() {
|
| MatchingFrame clone = new MatchingFrame(pattern, parent);
|
| clone.frame = frame.clone();
|
| return clone;
|
| }
|
|
|
| public String toString() {
|
| StringBuffer buf = new StringBuffer();
|
| for (int i = 0; i < frame.length; i++) {
|
| buf.append("frame[" + i + "]\t" + frame[i].toString() + "\n");
|
| }
|
| return buf.toString();
|
| }
|
|
|
| public Object lookup(Variable variable) {
|
| return null;
|
| }
|
|
|
| public Object lookup(int position) {
|
| if (position >= 0 && position < frame.length) {
|
| return frame[position];
|
| } else {
|
| // TODO gervarro: Exception or return null;
|
| return null;
|
| }
|
| }
|
|
|
| public int size() {
|
| return frame.length;
|
| }
|
| }
|