summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2017-07-20 18:07:47 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2017-07-20 18:07:47 +0200
commit45b091f8a44c422d89f9d3bcaf25e5df91da31a7 (patch)
treeaaa809eed731bbc4650dbfb7cfde8076d6f047a0
parent72b3069a20b8573ceff73b27936a76213aacc344 (diff)
Fixes stupid mistakes, adds some nodes.
-rw-r--r--ast-to-instr/src/VHDLCSNode.java261
-rw-r--r--ast-to-instr/src/VHDLISNode.java9
-rw-r--r--ast-to-instr/src/VHDLProcess.java1
-rw-r--r--ast-to-instr/src/VHDLSSASNode.java6
-rw-r--r--ast-to-instr/src/VHDLWNode.java139
-rw-r--r--instr-scripts/process_internals.py23
6 files changed, 413 insertions, 26 deletions
diff --git a/ast-to-instr/src/VHDLCSNode.java b/ast-to-instr/src/VHDLCSNode.java
index de11c7b..8c30795 100644
--- a/ast-to-instr/src/VHDLCSNode.java
+++ b/ast-to-instr/src/VHDLCSNode.java
@@ -9,16 +9,31 @@ import java.util.ArrayList;
import java.util.Collection;
/* If Statement Node */
-public class VHDLISNode extends VHDLNode
+public class VHDLCSNode extends VHDLNode
{
- private static final XPathExpression XPE_FIND_SUB_NODES;
+ private static final XPathExpression XPE_FIND_SOURCES;
+ private static final XPathExpression XPE_FIND_OTHERS_BRANCH;
+ private static final XPathExpression XPE_FIND_WHEN_BRANCHES;
static
{
- XPE_FIND_SUB_NODES = XMLManager.compile_or_die("./el");
+ XPE_FIND_SOURCES = XMLManager.compile_or_die
+ (
+ "./expression//named_entity"
+ );
+
+ XPE_FIND_OTHERS_BRANCH = XMLManager.compile_or_die
+ (
+ "./case_statement_alternative_chain/el[@kind=\"choice_by_others\"]"
+ );
+
+ XPE_FIND_WHEN_BRANCHES = XMLManager.compile_or_die
+ (
+ "./case_statement_alternative_chain/el[@kind=\"choice_by_expression\"]"
+ );
}
- public VHDLISNode
+ public VHDLCSNode
(
final IDs parent_id,
final Node xml_node,
@@ -41,7 +56,243 @@ public class VHDLISNode extends VHDLNode
public Collection<ParsableXML> parse ()
throws XPathExpressionException
{
+ final Collection<ParsableXML> result;
+ final String xml_id;
+ final IDs local_id;
+
+ result = new ArrayList<ParsableXML>();
+
+ xml_id = XMLManager.get_attribute(xml_node, "id");
+
+ local_id = IDs.get_id_from_xml_id(xml_id, "node");
+
+ /** Functions ***********************************************************/
+ handle_function_label(local_id);
+ handle_function_kind(local_id);
+ handle_function_depth(local_id);
+ handle_function_expression(local_id);
+
+ /** Predicates **********************************************************/
+ handle_predicate_has_option(local_id);
+ handle_predicate_expr_reads(local_id);
+
+ /** Children ************************************************************/
+ result.addAll(handle_when_branches(local_id));
+ result.addAll(handle_others_branch(local_id));
+
+ return result;
+ }
+
+ /***************************************************************************/
+ /** Functions **************************************************************/
+ /***************************************************************************/
+ private void handle_function_label
+ (
+ final IDs local_id
+ )
+ {
+ Functions.add_entry
+ (
+ "label",
+ local_id,
+ Strings.get_id_from_string
+ (
+ XMLManager.get_attribute(xml_node, "label")
+ )
+ );
+ }
+
+ private void handle_function_kind
+ (
+ final IDs local_id
+ )
+ {
+ Functions.add_entry
+ (
+ "kind",
+ local_id,
+ Strings.get_id_from_string("case")
+ );
+ }
+
+ private void handle_function_depth
+ (
+ final IDs local_id
+ )
+ {
+ Functions.add_entry
+ (
+ "depth",
+ local_id,
+ Strings.get_id_from_string
+ (
+ Integer.toString(depth)
+ )
+ );
+ }
+
+ private void handle_function_expression
+ (
+ final IDs local_id
+ )
+ {
/* TODO */
- return null;
+ }
+
+ /***************************************************************************/
+ /** Predicates *************************************************************/
+ /***************************************************************************/
+ private void handle_predicate_has_option
+ (
+ final IDs local_id
+ )
+ {
+ for (final String s: attributes)
+ {
+ Predicates.add_entry
+ (
+ "has_option",
+ local_id,
+ Strings.get_id_from_string(s)
+ );
+ }
+ }
+
+ private void handle_predicate_expr_reads
+ (
+ final IDs local_id
+ )
+ throws XPathExpressionException
+ {
+ final NodeList named_entities;
+ final int named_entities_count;
+
+ named_entities =
+ (NodeList) XPE_FIND_SOURCES.evaluate
+ (
+ xml_node,
+ XPathConstants.NODESET
+ );
+
+ named_entities_count = named_entities.getLength();
+
+ for (int i = 0; i < named_entities_count; ++i)
+ {
+ final String ref;
+
+ ref = XMLManager.get_attribute(named_entities.item(0), "ref");
+
+ if (!Main.node_is_function_or_literal(ref))
+ {
+ Predicates.add_entry
+ (
+ "expr_reads",
+ local_id,
+ Waveforms.get_associated_waveform_id
+ (
+ IDs.get_id_from_xml_id(ref, (String) null)
+ )
+ );
+ }
+ }
+ }
+
+ /***************************************************************************/
+ /** Children ***************************************************************/
+ /***************************************************************************/
+ private Collection<ParsableXML> handle_when_branches
+ (
+ final IDs local_id
+ )
+ throws XPathExpressionException
+ {
+ final Collection<ParsableXML> result;
+ final NodeList when_branches;
+ final int when_branches_length;
+
+ result = new ArrayList<ParsableXML>();
+
+ when_branches =
+ (NodeList) XPE_FIND_WHEN_BRANCHES.evaluate
+ (
+ xml_node,
+ XPathConstants.NODESET
+ );
+
+
+ when_branches_length = when_branches.getLength();
+
+ for (int i = 0; i < when_branches_length; ++i)
+ {
+ result.add
+ (
+ new VHDLWNode
+ (
+ parent_id,
+ when_branches.item(i),
+ next_node,
+ (depth + 1),
+ new String[0]
+ )
+ );
+ }
+
+ return result;
+ }
+
+ private Collection<ParsableXML> handle_others_branch
+ (
+ final IDs local_id
+ )
+ throws XPathExpressionException
+ {
+ final Collection<ParsableXML> result;
+ final Node others_branch;
+
+ result = new ArrayList<ParsableXML>();
+
+ others_branch =
+ (Node) XPE_FIND_OTHERS_BRANCH.evaluate
+ (
+ xml_node,
+ XPathConstants.NODE
+ );
+
+ if (others_branch == (Node) null)
+ {
+ if (next_node == (IDs) null)
+ {
+ Predicates.add_entry
+ (
+ "is_final",
+ local_id
+ );
+ }
+ else
+ {
+ Predicates.add_entry
+ (
+ "node_connect",
+ local_id,
+ next_node
+ );
+ }
+ }
+ else
+ {
+ result.add
+ (
+ new VHDLWNode
+ (
+ parent_id,
+ others_branch,
+ next_node,
+ (depth + 1),
+ new String[] {"WHEN_OTHERS"}
+ )
+ );
+ }
+
+ return result;
}
}
diff --git a/ast-to-instr/src/VHDLISNode.java b/ast-to-instr/src/VHDLISNode.java
index 66eb52a..9bf7810 100644
--- a/ast-to-instr/src/VHDLISNode.java
+++ b/ast-to-instr/src/VHDLISNode.java
@@ -11,15 +11,16 @@ import java.util.Collection;
/* If Statement Node */
public class VHDLISNode extends VHDLNode
{
- private static final XPathExpression XPE_FIND_CONDITION;
private static final XPathExpression XPE_FIND_NAMED_ENTITIES;
private static final XPathExpression XPE_FIND_TRUE_BRANCH;
private static final XPathExpression XPE_FIND_ELSE_BRANCH;
static
{
- XPE_FIND_CONDITION = XMLManager.compile_or_die("./condition");
- XPE_FIND_NAMED_ENTITIES = XMLManager.compile_or_die(".//named_entity");
+ XPE_FIND_NAMED_ENTITIES = XMLManager.compile_or_die
+ (
+ "./condition//named_entity"
+ );
XPE_FIND_TRUE_BRANCH = XMLManager.compile_or_die
(
@@ -121,7 +122,7 @@ public class VHDLISNode extends VHDLNode
{
Functions.add_entry
(
- "kind",
+ "depth",
local_id,
Strings.get_id_from_string
(
diff --git a/ast-to-instr/src/VHDLProcess.java b/ast-to-instr/src/VHDLProcess.java
index 36634fe..4f4ef73 100644
--- a/ast-to-instr/src/VHDLProcess.java
+++ b/ast-to-instr/src/VHDLProcess.java
@@ -465,6 +465,7 @@ public class VHDLProcess extends ParsableXML
(
final IDs local_id
)
+ throws XPathExpressionException
{
final Node start_node;
final Collection<ParsableXML> result;
diff --git a/ast-to-instr/src/VHDLSSASNode.java b/ast-to-instr/src/VHDLSSASNode.java
index 3e61396..dd7d9cd 100644
--- a/ast-to-instr/src/VHDLSSASNode.java
+++ b/ast-to-instr/src/VHDLSSASNode.java
@@ -105,7 +105,7 @@ public class VHDLSSASNode extends VHDLNode
(
"kind",
local_id,
- Strings.get_id_from_string("if")
+ Strings.get_id_from_string("signal_assignement")
);
}
@@ -116,7 +116,7 @@ public class VHDLSSASNode extends VHDLNode
{
Functions.add_entry
(
- "kind",
+ "depth",
local_id,
Strings.get_id_from_string
(
@@ -266,7 +266,7 @@ public class VHDLSSASNode extends VHDLNode
/***************************************************************************/
/** Children ***************************************************************/
/***************************************************************************/
- public void handle_next_node
+ private void handle_next_node
(
final IDs local_id
)
diff --git a/ast-to-instr/src/VHDLWNode.java b/ast-to-instr/src/VHDLWNode.java
index de11c7b..ac23be8 100644
--- a/ast-to-instr/src/VHDLWNode.java
+++ b/ast-to-instr/src/VHDLWNode.java
@@ -9,7 +9,7 @@ import java.util.ArrayList;
import java.util.Collection;
/* If Statement Node */
-public class VHDLISNode extends VHDLNode
+public class VHDLWNode extends VHDLNode
{
private static final XPathExpression XPE_FIND_SUB_NODES;
@@ -18,7 +18,7 @@ public class VHDLISNode extends VHDLNode
XPE_FIND_SUB_NODES = XMLManager.compile_or_die("./el");
}
- public VHDLISNode
+ public VHDLWNode
(
final IDs parent_id,
final Node xml_node,
@@ -41,7 +41,140 @@ public class VHDLISNode extends VHDLNode
public Collection<ParsableXML> parse ()
throws XPathExpressionException
{
+ final Collection<ParsableXML> result;
+ final String xml_id;
+ final IDs local_id;
+
+ result = new ArrayList<ParsableXML>();
+
+ xml_id = XMLManager.get_attribute(xml_node, "id");
+
+ local_id = IDs.get_id_from_xml_id(xml_id, "node");
+
+ /** Functions ***********************************************************/
+ handle_function_label(local_id);
+ handle_function_kind(local_id);
+ handle_function_depth(local_id);
+ handle_function_expression(local_id);
+
+ /** Predicates **********************************************************/
+ handle_predicate_has_option(local_id);
+ handle_predicate_expr_reads(local_id);
+
+ return result;
+ }
+
+ /***************************************************************************/
+ /** Functions **************************************************************/
+ /***************************************************************************/
+ private void handle_function_label
+ (
+ final IDs local_id
+ )
+ {
+ Functions.add_entry
+ (
+ "label",
+ local_id,
+ Strings.get_id_from_string
+ (
+ XMLManager.get_attribute(xml_node, "label")
+ )
+ );
+ }
+
+ private void handle_function_kind
+ (
+ final IDs local_id
+ )
+ {
+ Functions.add_entry
+ (
+ "kind",
+ local_id,
+ Strings.get_id_from_string("when")
+ );
+ }
+
+ private void handle_function_depth
+ (
+ final IDs local_id
+ )
+ {
+ Functions.add_entry
+ (
+ "depth",
+ local_id,
+ Strings.get_id_from_string
+ (
+ Integer.toString(depth)
+ )
+ );
+ }
+
+ private void handle_function_expression
+ (
+ final IDs local_id
+ )
+ {
/* TODO */
- return null;
+ }
+
+ /***************************************************************************/
+ /** Predicates *************************************************************/
+ /***************************************************************************/
+ private void handle_predicate_has_option
+ (
+ final IDs local_id
+ )
+ {
+ for (final String s: attributes)
+ {
+ Predicates.add_entry
+ (
+ "has_option",
+ local_id,
+ Strings.get_id_from_string(s)
+ );
+ }
+ }
+
+ private void handle_predicate_expr_reads
+ (
+ final IDs local_id
+ )
+ throws XPathExpressionException
+ {
+ final NodeList named_entities;
+ final int named_entities_count;
+
+ named_entities =
+ (NodeList) XPE_FIND_SOURCES.evaluate
+ (
+ xml_node,
+ XPathConstants.NODESET
+ );
+
+ named_entities_count = named_entities.getLength();
+
+ for (int i = 0; i < named_entities_count; ++i)
+ {
+ final String ref;
+
+ ref = XMLManager.get_attribute(named_entities.item(0), "ref");
+
+ if (!Main.node_is_function_or_literal(ref))
+ {
+ Predicates.add_entry
+ (
+ "expr_reads",
+ local_id,
+ Waveforms.get_associated_waveform_id
+ (
+ IDs.get_id_from_xml_id(ref, (String) null)
+ )
+ );
+ }
+ }
}
}
diff --git a/instr-scripts/process_internals.py b/instr-scripts/process_internals.py
index fbbf04e..c7d4e82 100644
--- a/instr-scripts/process_internals.py
+++ b/instr-scripts/process_internals.py
@@ -530,17 +530,18 @@ class Process_Internals:
[]
)
- false_branch_xml = xml.find("./else_cause/sequential_statement_chain")
-
- if (false_branch_xml == None):
- exit_points += prev_nodes
- else:
- exit_points += self.handle_sequential_statement_chain (
- false_branch_xml,
- [cond_node_id],
- (node_depth + 2),
- ["COND_WAS_FALSE"]
- )
+ # Re-reading this, I doubt this is ever found. Copy/paste mistake?
+# false_branch_xml = xml.find("./else_cause/sequential_statement_chain")
+#
+# if (false_branch_xml == None):
+# exit_points += prev_nodes
+# else:
+# exit_points += self.handle_sequential_statement_chain (
+# false_branch_xml,
+# [cond_node_id],
+# (node_depth + 2),
+# ["COND_WAS_FALSE"]
+# )
return exit_points