From 51edef030be94b7aa23631f7e40225c60878473f Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Thu, 27 Jul 2017 11:25:42 +0200 Subject: First shot at depths operators. --- ast-to-instr/src/Depths.java | 72 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 ast-to-instr/src/Depths.java (limited to 'ast-to-instr/src/Depths.java') diff --git a/ast-to-instr/src/Depths.java b/ast-to-instr/src/Depths.java new file mode 100644 index 0000000..ade01c8 --- /dev/null +++ b/ast-to-instr/src/Depths.java @@ -0,0 +1,72 @@ +import java.util.Map; +import java.util.HashMap; + +public class Depths +{ + private static final Map TO_ID; + private static final OutputFile DEPTHS_OUTPUT; + private static int highest_depth; + + static + { + highest_depth = -1; + + TO_ID = new HashMap(); + + /* TODO: filename as a param? */ + DEPTHS_OUTPUT = OutputFile.new_output_file("depths.mod"); + } + + private Depths () {} /* Utility class. */ + + public static IDs get_id_from_depth + ( + final String depth + ) + { + return get_id_from_depth(Integer.valueOf(depth)); + } + + public static IDs get_id_from_depth + ( + final Integer depth + ) + { + IDs result; + + result = TO_ID.get(depth); + + if (result == null) + { + result = IDs.generate_new_id(DEPTHS_OUTPUT, "depth"); + + TO_ID.put(depth, result); + } + + if (depth.intValue() > highest_depth) + { + highest_depth = depth.intValue(); + } + + return result; + } + + public static void generate_predicates () + { + for + ( + int current_depth = highest_depth; + current_depth > 0; + --current_depth + ) + { + Predicates.add_entry + ( + DEPTHS_OUTPUT, + "is_lower_than", + get_id_from_depth(new Integer(current_depth - 1)), + get_id_from_depth(new Integer(current_depth)) + ); + } + } +} -- cgit v1.2.3-70-g09d2