Newer
Older
AlgebraicDataflowArchitectureModel / AlgebraicDataflowArchitectureModel / src / models / algebra / Field.java
package models.algebra;

import code.ast.IExpressionVisitor;
import generators.JavaImplementationVisitor;

/**
 * A field in the implementation (regarded as a constant in the algebraic system)
 *
 * @author Nitta
 *
 */
public class Field extends Constant {
	
	public Field(String name) {
		super(name);
	}
	
	public Field(String name, Type type) {
		super(name);
		symbol.setSignature(new Type[]{type});
	}
	
	public Field(Symbol symbol) {
		super(symbol);
	}
	
	public Type getType() {
		if (symbol.getSignature() != null && symbol.getSignature().length >= 1) {
			return symbol.getSignature()[0];
		}
		return null;
	}
	
	@Override
	public boolean equals(Object another) {
		if (!(another instanceof Field)) return false;
		return symbol.equals(((Field) another).symbol);
	}
	
	@Override
	public Object clone() {
		return new Field(symbol);
	}
	
	public String toImplementation(String[] sideEffects) {
		return accept(new JavaImplementationVisitor(), sideEffects).toString();
	}
	
	@Override
	public <T> T accept(IExpressionVisitor<T> visitor, String[] sideEffects) {
		return visitor.visit(this, sideEffects);
	}
}