Commit ad8763fd authored by Carlos Galindo's avatar Carlos Galindo
Browse files

Full support for records and code printing

- Full support for records, with their own access constraints
- e-Knife can now print Erlang code that contains newly supported data structures (record, bin, try, catch, throw...)
parent b909e059
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -327,6 +327,12 @@ public class LASTBuilder {
		return node.getId();
	}

	public static int addRecordAccess(LAST last, int parentId, Where where, LDASTNodeInfo info) {
		Node parent = LASTBuilder.getParentNode(last, parentId, where);
		Node node = LASTBuilder.addNode(last, parent, Node.Type.RecordAccess, "record_access", info);
		return node.getId();
	}

	public static int addRecordIndex(LAST last, int parentId, Where where, LDASTNodeInfo info) {
		Node parent = LASTBuilder.getParentNode(last, parentId, where);
		Node node = LASTBuilder.addNode(last, parent, Node.Type.RecordIndex, "record_index", info);
@@ -1059,6 +1065,7 @@ public class LASTBuilder {
			case MapFieldExact:
			case Record:
			case RecordField:
			case RecordAccess:
			case RecordIndex:
				if (where == null)
					return parentNode;
+22 −10
Original line number Diff line number Diff line
@@ -597,15 +597,18 @@ public abstract class LASTFactory
		this.branches.pop();
	}

	protected void addBin(Object exp, LDASTNodeInfo info) {
	protected <R> void addBin(Iterable<R> binElements, LDASTNodeInfo info) {
		final R[] elements0 = this.getArray(binElements);
		this.addBin(elements0, info);
	}
	protected <R> void addBin(R[] exp, LDASTNodeInfo info) {
		final Branch parent = this.branches.peek();
		final int id = LASTBuilder.addBin(this.last, parent.getNodeId(), parent.getWhere(), info);

		this.branches.push(new Branch(id, Node.Type.Bin, info));
		processElement(exp, 1, 1);
		this.processElements(exp);
		this.branches.pop();
	}

	protected void addBinElement(Object exp, LDASTNodeInfo info) {
		final Branch parent = this.branches.peek();
		final int id = LASTBuilder.addBinElement(this.last, parent.getNodeId(), parent.getWhere(), info);
@@ -654,26 +657,24 @@ public abstract class LASTFactory
		this.branches.pop();
	}

	protected void addRecord(Object record, Object[] fields, LDASTNodeInfo info) {
	protected void addRecord(Object[] fields, LDASTNodeInfo info) {
		final Branch parent = this.branches.peek();
		final int id = LASTBuilder.addRecord(this.last, parent.getNodeId(), parent.getWhere(), info);

		this.branches.push(new Branch(id, Node.Type.Record, info));
		processElement(record, 1, fields.length + 1);
		for (int i = 0; i < fields.length; i++)
			processElement(fields[i], i + 1, fields.length + 1);
			processElement(fields[i], i + 1, fields.length);
		this.branches.pop();
	}

	protected void addRecord(Object name, Object record, Object[] fields, LDASTNodeInfo info) {
	protected void addRecord(Object name, Object[] fields, LDASTNodeInfo info) {
		final Branch parent = this.branches.peek();
		final int id = LASTBuilder.addRecord(this.last, parent.getNodeId(), parent.getWhere(), info);

		this.branches.push(new Branch(id, Node.Type.Record, info));
		processElement(name, 1, fields.length + 2);
		processElement(record, 2, fields.length + 2);
		processElement(name, 1, fields.length + 1);
		for (int i = 0; i < fields.length; i++)
			processElement(fields[i], i + 2, fields.length + 2);
			processElement(fields[i], i + 2, fields.length + 1);
		this.branches.pop();
	}

@@ -687,6 +688,17 @@ public abstract class LASTFactory
		this.branches.pop();
	}

	protected void addRecordAccess(Object name, Object value1, Object value2, LDASTNodeInfo info) {
		final Branch parent = this.branches.peek();
		final int id = LASTBuilder.addRecordAccess(this.last, parent.getNodeId(), parent.getWhere(), info);

		this.branches.push(new Branch(id, Node.Type.RecordAccess, info));
		processElement(name, 1, 3);
		processElement(value1, 2, 3);
		processElement(value2, 3, 3);
		this.branches.pop();
	}

	protected void addRecordIndex(Object name, Object assign, LDASTNodeInfo info) {
		final int id = LASTBuilder.addRecordIndex(last, branches.peek().getNodeId(), branches.peek().getWhere(), info);

+1 −1
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@ import java.util.List;
public abstract class AccessConstraint extends EdgeConstraint {
	public enum Operation {Add, Remove}

	public enum CompositeType {DataConstructor, List, ListComprehension}//, Literal}
	public enum CompositeType {DataConstructor, List, ListComprehension, Record}//, Literal}

	protected final Operation operation;
	protected final CompositeType compositeType;
+63 −0
Original line number Diff line number Diff line
package edg.constraint;

import java.util.LinkedList;
import java.util.List;

import edg.slicing.Phase;

public class RecordConstraint extends AccessConstraint
{
	private String field;

	public RecordConstraint(Operation operation, String field)
	{
		super(operation, AccessConstraint.CompositeType.Record);

		this.field = field;
	}

	public String getField()
	{
		return this.field;
	}

	public boolean equals(Object object)
	{
		if (!(object instanceof RecordConstraint))
			return false;
		if (!super.equals(object))
			return false;

		final RecordConstraint constraint = (RecordConstraint) object;

		if (!this.field.equals(constraint.field))
			return false;
		return true;
	}
	public String toString()
	{
		return super.toString() + this.field;
	}

	public RecordConstraint opposite()
	{
		if (this.operation == Operation.Add)
			return new RecordConstraint(Operation.Remove, this.field);
		return new RecordConstraint(Operation.Add, this.field);
	}

	public List<Constraints> resolve(Phase phase, Constraints constraintsStack)
	{
		final List<Constraints> constraintsStacks = new LinkedList<Constraints>();



		return constraintsStacks;
	}
	public List<Constraints> resolve(Phase phase, Constraints constraintsStack, Constraint topConstraint)
	{
		final List<Constraints> constraintsStacks = new LinkedList<Constraints>();

		return constraintsStacks;
	}
}
 No newline at end of file
+8 −0
Original line number Diff line number Diff line
@@ -759,6 +759,14 @@ public class LAST extends GraphWithRoot {
					case List:
						return getChild(node, 1);
				}
			case RecordField:
				switch (type)
				{
					case Name:
						return getChild(node, 0);
					case Value:
						return getChild(node, 1);
				}
			default:
				break;

Loading