| summaryrefslogtreecommitdiff | 
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-07-19 20:24:40 +0200 | 
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-07-19 20:24:40 +0200 | 
| commit | 158f8ef180d4ea448b351599529db53ff5e88f8c (patch) | |
| tree | 2982efaacb22dea8fb86850abc149b768ee428db /ast-to-instr/src | |
| parent | 0362751e41f731b22b7bfe511af4aa71a02be70a (diff) | |
Starting a Java implementation of ast-to-instr.
Keeping things clean, this time.
Diffstat (limited to 'ast-to-instr/src')
| -rw-r--r-- | ast-to-instr/src/IDs.java | 78 | ||||
| -rw-r--r-- | ast-to-instr/src/Main.java | 0 | ||||
| -rw-r--r-- | ast-to-instr/src/Parameters.java | 0 | ||||
| -rw-r--r-- | ast-to-instr/src/ParsableXML.java | 28 | ||||
| -rw-r--r-- | ast-to-instr/src/Strings.java | 30 | ||||
| -rw-r--r-- | ast-to-instr/src/VHDLArchitecture.java | 316 | ||||
| -rw-r--r-- | ast-to-instr/src/VHDLEntity.java | 292 | ||||
| -rw-r--r-- | ast-to-instr/src/VHDLFile.java | 112 | ||||
| -rw-r--r-- | ast-to-instr/src/Waveforms.java | 30 | 
9 files changed, 886 insertions, 0 deletions
| diff --git a/ast-to-instr/src/IDs.java b/ast-to-instr/src/IDs.java new file mode 100644 index 0000000..e3b9db4 --- /dev/null +++ b/ast-to-instr/src/IDs.java @@ -0,0 +1,78 @@ +import java.util.ArrayList; +import java.util.Collection; +import java.util.Map; +import java.util.HashMap; + +public class IDs +{ +   /** Static *****************************************************************/ +   private static final Map<String, IDs> FROM_XML; +   private static final Collection<IDs> ALL_IDS; +   private static int next_id; + +   static +   { +      next_id = 0; + +      FROM_XML = new HashMap<String, IDs>(); +      ALL_IDS = new ArrayList<IDs>(); +   } + + +   public static IDs get_id_from_xml_id +   ( +      final String xml_id, +      final String type +   ) +   { +      IDs result; + +      result = FROM_XML.get(xml_id); + +      if (result == null) +      { +         result = new IDs(type); + +         FROM_XML.put(xml_id, result); +      } + +      return result; +   } + +   public static IDs generate_new_id +   ( +      final String type +   ) +   { +      final IDs result; + +      result = new IDs(type); + +      ALL_IDS.add(result); + +      return result; +   } + +   /** Non-Static *************************************************************/ +   private final String type; +   private final int value; + +   private IDs (final String type) +   { +      this.type = type; + +      value = IDs.next_id; + +      IDs.next_id += 1; +   } + +   public String get_type () +   { +      return type; +   } + +   public int get_value () +   { +      return value; +   } +} diff --git a/ast-to-instr/src/Main.java b/ast-to-instr/src/Main.java new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/ast-to-instr/src/Main.java diff --git a/ast-to-instr/src/Parameters.java b/ast-to-instr/src/Parameters.java new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/ast-to-instr/src/Parameters.java diff --git a/ast-to-instr/src/ParsableXML.java b/ast-to-instr/src/ParsableXML.java new file mode 100644 index 0000000..b190b48 --- /dev/null +++ b/ast-to-instr/src/ParsableXML.java @@ -0,0 +1,28 @@ +import org.w3c.dom.Node; + +import java.util.ArrayList; +import java.util.Collection; + +import javax.xml.xpath.XPathExpressionException; + +public abstract class ParsableXML +{ +   protected final IDs parent_id; +   protected final Node xml_node; + +   public ParsableXML +   ( +      final IDs parent_id, +      final Node xml_node +   ) +   { +      this.parent_id = parent_id; +      this.xml_node = xml_node; +   } + +   public Collection<ParsableXML> parse () +   throws XPathExpressionException +   { +      return new ArrayList<ParsableXML>(); +   } +} diff --git a/ast-to-instr/src/Strings.java b/ast-to-instr/src/Strings.java new file mode 100644 index 0000000..bc1778f --- /dev/null +++ b/ast-to-instr/src/Strings.java @@ -0,0 +1,30 @@ +import java.util.Map; +import java.util.HashMap; + +public class Strings +{ +   private static final Map<String, IDs> TO_ID; + +   static +   { +      TO_ID = new HashMap<String, IDs>(); +   } + +   private Strings () {} /* Utility class. */ + +   public static IDs get_id_from_string (final String string) +   { +      IDs result; + +      result = TO_ID.get(string); + +      if (result == null) +      { +         result = IDs.generate_new_id("string"); + +         TO_ID.put(string, result); +      } + +      return result; +   } +} diff --git a/ast-to-instr/src/VHDLArchitecture.java b/ast-to-instr/src/VHDLArchitecture.java new file mode 100644 index 0000000..ec8aa2a --- /dev/null +++ b/ast-to-instr/src/VHDLArchitecture.java @@ -0,0 +1,316 @@ +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathExpressionException; + +import java.util.ArrayList; +import java.util.Collection; + +public class VHDLArchitecture extends ParsableXML +{ +   private static final XPathExpression GET_ENTITIES; + +   static +   { +      GET_ENTITIES = null; +      /* TODO +         Main.get_xpath().compile +         ( +         ); +      */ +       //     "./*/*/library_unit[@kind=\"entity_declaration\"]" +   } + +   public VHDLArchitecture +   ( +      final IDs parent_id, +      final Node xml_node +   ) +   { +      super(parent_id, xml_node); +   } + +   @Override +   public Collection<ParsableXML> parse () +   throws XPathExpressionException +   { +      final Collection<ParsableXML> result; +      final String xml_id; +      final IDs local_id; + +      result = new ArrayList<ParsableXML>(); + +      xml_id = null; /* TODO: elem.attrib.get("id") */ + +      local_id = IDs.get_id_from_xml_id(xml_id, "architecture"); + +      /** Parent **************************************************************/ +      handle_link_to_file(local_id); +      handle_link_to_entity(local_id); + +      /** Functions ***********************************************************/ +      handle_function_line(local_id); +      handle_function_column(local_id); +      handle_function_identifier(local_id); + +      /** Predicates **********************************************************/ +      handle_predicate_has_foreign_flag(local_id); +      handle_predicate_has_visible_flag(local_id); +      handle_predicate_is_withing_flag(local_id); +      handle_predicate_end_has_reserved_id(local_id); +      handle_predicate_end_has_identifier(local_id); + +      /** Children ************************************************************/ +      result.addAll(handle_child_signals(local_id)); +      result.addAll(handle_child_processes(local_id)); +      result.addAll(handle_child_components(local_id)); + +      return null; +   } + +   /***************************************************************************/ +   /** Parents ****************************************************************/ +   /***************************************************************************/ +   private void handle_link_to_file +   ( +      final IDs local_id +   ) +   { +      final IDs params[]; + +      params = +         new IDs[] +         { +            local_id, +            parent_id +         }; + +      /* TODO */ +   } + +   private void handle_link_to_entity +   ( +      final IDs local_id +   ) +   { +      final IDs params[]; + +      /* TODO */ +   } + + +   /***************************************************************************/ +   /** Functions **************************************************************/ +   /***************************************************************************/ +   private void handle_function_line +   ( +      final IDs local_id +   ) +   { +      final IDs params[]; + +      params = +         new IDs[] +         { +            local_id, +            Strings.get_id_from_string +            ( +               null /* TODO: get attribute */ +            ) +         }; + +      /* Functions.add_entry("filename", params); */ +   } + +   private void handle_function_column +   ( +      final IDs local_id +   ) +   { +      final IDs params[]; + +      params = +         new IDs[] +         { +            local_id, +            Strings.get_id_from_string +            ( +               null /* TODO: get attribute */ +            ) +         }; + +      /* Functions.add_entry("filename", params); */ +   } + +   private void handle_function_identifier +   ( +      final IDs local_id +   ) +   { +      final IDs params[]; + +      params = +         new IDs[] +         { +            local_id, +            Strings.get_id_from_string +            ( +               null /* TODO: get attribute */ +            ) +         }; + +      /* Functions.add_entry("filename", params); */ +   } + +   /***************************************************************************/ +   /** Predicates *************************************************************/ +   /***************************************************************************/ +   private void handle_predicate_has_foreign_flag +   ( +      final IDs local_id +   ) +   { +      final IDs params[]; + +      params = +         new IDs[] +         { +            local_id, +            Strings.get_id_from_string +            ( +               null /* TODO: get attribute */ +            ) +         }; + +      /* Functions.add_entry("filename", params); */ +   } + +   private void handle_predicate_has_visible_flag +   ( +      final IDs local_id +   ) +   { +      final IDs params[]; + +      params = +         new IDs[] +         { +            local_id, +            Strings.get_id_from_string +            ( +               null /* TODO: get attribute */ +            ) +         }; + +      /* Functions.add_entry("filename", params); */ +   } + +   private void handle_predicate_is_withing_flag +   ( +      final IDs local_id +   ) +   { +      final IDs params[]; + +      params = +         new IDs[] +         { +            local_id, +            Strings.get_id_from_string +            ( +               null /* TODO: get attribute */ +            ) +         }; + +      /* Functions.add_entry("filename", params); */ +   } + +   private void handle_predicate_end_has_reserved_id +   ( +      final IDs local_id +   ) +   { +      final IDs params[]; + +      params = +         new IDs[] +         { +            local_id, +            Strings.get_id_from_string +            ( +               null /* TODO: get attribute */ +            ) +         }; + +      /* Functions.add_entry("filename", params); */ +   } + +   private void handle_predicate_end_has_identifier +   ( +      final IDs local_id +   ) +   { +      final IDs params[]; + +      params = +         new IDs[] +         { +            local_id, +            Strings.get_id_from_string +            ( +               null /* TODO: get attribute */ +            ) +         }; + +      /* Functions.add_entry("filename", params); */ +   } + +   /***************************************************************************/ +   /** Children ***************************************************************/ +   /***************************************************************************/ +   private Collection<ParsableXML> handle_child_signals +   ( +      final IDs local_id +   ) +   throws XPathExpressionException +   { +      final Collection<ParsableXML> result; +      final NodeList entities; + +      entities = +         (NodeList) GET_ENTITIES.evaluate +         ( +            xml_node, +            XPathConstants.NODESET +         ); + +      /* TODO */ +      return null; +   } + +   private Collection<ParsableXML> handle_child_processes +   ( +      final IDs local_id +   ) +   throws XPathExpressionException +   { +      final Collection<ParsableXML> result; + +      /* TODO */ +      return null; +   } + +   private Collection<ParsableXML> handle_child_components +   ( +      final IDs local_id +   ) +   throws XPathExpressionException +   { +      final Collection<ParsableXML> result; + +      /* TODO */ +      return null; +   } +} diff --git a/ast-to-instr/src/VHDLEntity.java b/ast-to-instr/src/VHDLEntity.java new file mode 100644 index 0000000..f56355c --- /dev/null +++ b/ast-to-instr/src/VHDLEntity.java @@ -0,0 +1,292 @@ +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathExpressionException; + +import java.util.ArrayList; +import java.util.Collection; + +public class VHDLEntity extends ParsableXML +{ +   private static final XPathExpression GET_ENTITIES; + +   static +   { +      GET_ENTITIES = null; +      /* TODO +         Main.get_xpath().compile +         ( +         ); +      */ +       //     "./*/*/library_unit[@kind=\"entity_declaration\"]" +   } + +   public VHDLEntity +   ( +      final IDs parent_id, +      final Node xml_node +   ) +   { +      super(parent_id, xml_node); +   } + +   @Override +   public Collection<ParsableXML> parse () +   throws XPathExpressionException +   { +      final Collection<ParsableXML> result; +      final String xml_id; +      final IDs local_id; + +      result = new ArrayList<ParsableXML>(); + +      xml_id = null; /* TODO: elem.attrib.get("id") */ + +      local_id = IDs.get_id_from_xml_id(xml_id, "entity"); + +      /** Parent **************************************************************/ +      handle_link_to_file(local_id); + +      /** Functions ***********************************************************/ +      handle_function_line(local_id); +      handle_function_column(local_id); +      handle_function_identifier(local_id); + +      /** Predicates **********************************************************/ +      handle_predicate_has_begin(local_id); +      handle_predicate_has_visible_flag(local_id); +      handle_predicate_is_withing_flag(local_id); +      handle_predicate_end_has_reserved_id(local_id); +      handle_predicate_end_has_identifier(local_id); + +      /** Children ************************************************************/ +      result.addAll(handle_child_ports(local_id)); +      result.addAll(handle_child_generics(local_id)); + +      return null; +   } + +   /***************************************************************************/ +   /** Parents ****************************************************************/ +   /***************************************************************************/ +   private void handle_link_to_file +   ( +      final IDs local_id +   ) +   { +      final IDs params[]; + +      params = +         new IDs[] +         { +            local_id, +            parent_id +         }; + +      /* TODO */ +   } + + +   /***************************************************************************/ +   /** Functions **************************************************************/ +   /***************************************************************************/ +   private void handle_function_line +   ( +      final IDs local_id +   ) +   { +      final IDs params[]; + +      params = +         new IDs[] +         { +            local_id, +            Strings.get_id_from_string +            ( +               null /* TODO: get attribute */ +            ) +         }; + +      /* Functions.add_entry("filename", params); */ +   } + +   private void handle_function_column +   ( +      final IDs local_id +   ) +   { +      final IDs params[]; + +      params = +         new IDs[] +         { +            local_id, +            Strings.get_id_from_string +            ( +               null /* TODO: get attribute */ +            ) +         }; + +      /* Functions.add_entry("filename", params); */ +   } + +   private void handle_function_identifier +   ( +      final IDs local_id +   ) +   { +      final IDs params[]; + +      params = +         new IDs[] +         { +            local_id, +            Strings.get_id_from_string +            ( +               null /* TODO: get attribute */ +            ) +         }; + +      /* Functions.add_entry("filename", params); */ +   } + +   /***************************************************************************/ +   /** Predicates *************************************************************/ +   /***************************************************************************/ +   private void handle_predicate_has_begin +   ( +      final IDs local_id +   ) +   { +      final IDs params[]; + +      params = +         new IDs[] +         { +            local_id, +            Strings.get_id_from_string +            ( +               null /* TODO: get attribute */ +            ) +         }; + +      /* Functions.add_entry("filename", params); */ +   } + +   private void handle_predicate_has_visible_flag +   ( +      final IDs local_id +   ) +   { +      final IDs params[]; + +      params = +         new IDs[] +         { +            local_id, +            Strings.get_id_from_string +            ( +               null /* TODO: get attribute */ +            ) +         }; + +      /* Functions.add_entry("filename", params); */ +   } + +   private void handle_predicate_is_withing_flag +   ( +      final IDs local_id +   ) +   { +      final IDs params[]; + +      params = +         new IDs[] +         { +            local_id, +            Strings.get_id_from_string +            ( +               null /* TODO: get attribute */ +            ) +         }; + +      /* Functions.add_entry("filename", params); */ +   } + +   private void handle_predicate_end_has_reserved_id +   ( +      final IDs local_id +   ) +   { +      final IDs params[]; + +      params = +         new IDs[] +         { +            local_id, +            Strings.get_id_from_string +            ( +               null /* TODO: get attribute */ +            ) +         }; + +      /* Functions.add_entry("filename", params); */ +   } + +   private void handle_predicate_end_has_identifier +   ( +      final IDs local_id +   ) +   { +      final IDs params[]; + +      params = +         new IDs[] +         { +            local_id, +            Strings.get_id_from_string +            ( +               null /* TODO: get attribute */ +            ) +         }; + +      /* Functions.add_entry("filename", params); */ +   } + +   /***************************************************************************/ +   /** Children ***************************************************************/ +   /***************************************************************************/ +   private Collection<ParsableXML> handle_child_ports +   ( +      final IDs local_id +   ) +   throws XPathExpressionException +   { +      final Collection<ParsableXML> result; +      final NodeList entities; + +      entities = +         (NodeList) GET_ENTITIES.evaluate +         ( +            xml_node, +            XPathConstants.NODESET +         ); + +      /* TODO */ +      return null; +   } + +   private Collection<ParsableXML> handle_child_generics +   ( +      final IDs local_id +   ) +   throws XPathExpressionException +   { +      final Collection<ParsableXML> result; + +      /* TODO */ +      return null; +   } +} diff --git a/ast-to-instr/src/VHDLFile.java b/ast-to-instr/src/VHDLFile.java new file mode 100644 index 0000000..beef2fe --- /dev/null +++ b/ast-to-instr/src/VHDLFile.java @@ -0,0 +1,112 @@ +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathExpressionException; + +import java.util.ArrayList; +import java.util.Collection; + +public class VHDLFile extends ParsableXML +{ +   private static final XPathExpression GET_ENTITIES; + +   static +   { +      GET_ENTITIES = null; +      /* TODO +         Main.get_xpath().compile +         ( +         ); +      */ +       //     "./*/*/library_unit[@kind=\"entity_declaration\"]" +   } + +   public VHDLFile +   ( +      final IDs parent_id, +      final Node xml_node +   ) +   { +      super(parent_id, xml_node); +   } + +   @Override +   public Collection<ParsableXML> parse () +   throws XPathExpressionException +   { +      final Collection<ParsableXML> result; +      final String xml_id; +      final IDs local_id; + +      result = new ArrayList<ParsableXML>(); + +      xml_id = null; /* TODO: elem.attrib.get("id") */ + +      local_id = IDs.get_id_from_xml_id(xml_id, "file"); + +      /** Functions ***********************************************************/ +      handle_function_filename(local_id); + +      /** Predicates **********************************************************/ + +      /** Children ************************************************************/ +      result.addAll(handle_child_entities(local_id)); +      result.addAll(handle_child_architectures(local_id)); + +      return null; +   } + +   private void handle_function_filename +   ( +      final IDs local_id +   ) +   { +      final IDs params[]; + +      params = +         new IDs[] +         { +            local_id, +            Strings.get_id_from_string +            ( +               null /* TODO: get attribute */ +            ) +         }; + +      /* Functions.add_entry("filename", params); */ +   } + +   private Collection<ParsableXML> handle_child_entities +   ( +      final IDs local_id +   ) +   throws XPathExpressionException +   { +      final Collection<ParsableXML> result; +      final NodeList entities; + +      entities = +         (NodeList) GET_ENTITIES.evaluate +         ( +            xml_node, +            XPathConstants.NODESET +         ); + +      /* TODO */ +      return null; +   } + +   private Collection<ParsableXML> handle_child_architectures +   ( +      final IDs local_id +   ) +   throws XPathExpressionException +   { +      final Collection<ParsableXML> result; + +      /* TODO */ +      return null; +   } +} diff --git a/ast-to-instr/src/Waveforms.java b/ast-to-instr/src/Waveforms.java new file mode 100644 index 0000000..753bae3 --- /dev/null +++ b/ast-to-instr/src/Waveforms.java @@ -0,0 +1,30 @@ +import java.util.Map; +import java.util.HashMap; + +public class Waveforms +{ +   private static final Map<IDs, IDs> TO_WAVEFORM; + +   static +   { +      TO_WAVEFORM = new HashMap<IDs, IDs>(); +   } + +   private Waveforms () {} /* Utility class. */ + +   public static IDs get_associated_waveform_id (final IDs source) +   { +      IDs result; + +      result = TO_WAVEFORM.get(source); + +      if (result == null) +      { +         result = IDs.generate_new_id("waveform"); + +         TO_WAVEFORM.put(source, result); +      } + +      return result; +   } +} | 


