diff --git a/src/Makefile b/src/Makefile index 117e16b..d842505 100644 --- a/src/Makefile +++ b/src/Makefile @@ -8,7 +8,7 @@ SRC_PATH = ${PSS_HOME}/src ANTLR4 = java -jar $(ANTLR4_JAR_PATH) GRUN = java -classpath $(PSSGEN_JAR_PATH):$(ANTLR4_JAR_PATH) org.antlr.v4.gui.TestRig PSS model -gui -f -JAVAC = javac -classpath $(SRC_PATH):$(ANTLR4_JAR_PATH) +JAVAC = javac --release 13 -classpath $(SRC_PATH):$(ANTLR4_JAR_PATH) PSSGEN = java -classpath $(PSSGEN_JAR_PATH):$(ANTLR4_JAR_PATH) PSSGenMain diff --git a/src/PSSEnumInst.java b/src/PSSEnumInst.java index 0a0b19d..5439752 100644 --- a/src/PSSEnumInst.java +++ b/src/PSSEnumInst.java @@ -1,8 +1,19 @@ -import java.util.*; +import java.math.BigInteger; public class PSSEnumInst extends PSSIntInst { - public PSSEnumInst(String id, String type, PSSModel type_decl, boolean rand) { + public PSSEnumInst(String id, String type, PSSEnumModel type_decl, boolean rand) { super(id, rand, 32, true); + + /* + * PSS 2.0, Section 8.4 Enumeration types: + * When not initialized, the default value of an enum field shall be the first + * enum_item in the list. This is not necessarily the value 0 nor the enum_item + * with the minimum value. + */ + String[] items = type_decl.getEnumItems(); + if (items.length > 0) { + m_val = new PSSIntVal(BigInteger.valueOf(type_decl.getEnumItemValue(items[0]))); + } } } diff --git a/src/PSSEnumModel.java b/src/PSSEnumModel.java index 17ca367..85aebc6 100644 --- a/src/PSSEnumModel.java +++ b/src/PSSEnumModel.java @@ -2,16 +2,35 @@ public class PSSEnumModel extends PSSModel { - private HashMap m_items; + private LinkedHashMap m_items; private Integer m_default_val; public PSSEnumModel(String id) { super(id); - m_items = new HashMap(); + m_items = new LinkedHashMap(); m_default_val = 0; } + /** + * Returns items in this enum. + * + * @return items in this enum. + */ + public String[] getEnumItems() { + return m_items.keySet().toArray(new String[0]); + } + + /** + * Returns the value of a specified item in this enum. + * + * @param item an item in this enum + * @return the value of item in this enum + */ + public int getEnumItemValue(String item) { + return m_items.get(item); + } + public void addEnumItem(String id) { m_items.put(id, m_default_val); m_default_val++; diff --git a/src/PSSInst.java b/src/PSSInst.java index 02e3307..af82e8d 100644 --- a/src/PSSInst.java +++ b/src/PSSInst.java @@ -170,13 +170,15 @@ public PSSInst findInstanceUnder(String hierarchy_id) { public PSSInst findStaticInst(String hierarchiy_id) { // Currently, find enum items only. + PSSInst res = null; PSSModel m = getTypeModel(); - while (!(m instanceof PSSComponentModel) && m != null) + while (m != null) { + res = m.findStaticInst(hierarchiy_id); + if (res != null) + break; m = m.m_parent; - if (m != null) { - return m.findStaticInst(hierarchiy_id); } - return null; + return res; } public PSSInst findInstance(String hierarchy_id, boolean local_scope) { diff --git a/src/PSSMemberPathElemExpression.java b/src/PSSMemberPathElemExpression.java index 31ff18a..b2423d6 100644 --- a/src/PSSMemberPathElemExpression.java +++ b/src/PSSMemberPathElemExpression.java @@ -157,9 +157,12 @@ private PSSExecKind getContextExecKind(PSSInst inst) { */ private PSSInst getInstOne(PSSModel pkg, PSSInst ctx, PSSInst parent) { PSSInst inst = null; - if (m_function_parameter_list == null) { - inst = m_parent == null ? ctx.findInstance(m_id) : parent.findInstanceUnder(m_id); + if (pkg == null || m_parent != null) { + inst = m_parent == null ? ctx.findInstance(m_id) : parent.findInstanceUnder(m_id); + } else { + inst = pkg.findStaticInst(m_id); + } if (inst == null) PSSMessage.Error("PSSMemberPathElemExpression", getUpperHierarchicalID() + " is not defined."); } else if (m_parent == null || parent instanceof PSSComponentInst) { @@ -188,7 +191,8 @@ private PSSInst getInstOne(PSSModel pkg, PSSInst ctx, PSSInst parent) { PSSMessage.Error("PSS 2.0 Section 22.4.1.3", "The function call " + getUpperHierarchicalID() + "(" + String.join(", ", - m_function_parameter_list.stream().map(p -> p.getText()).collect(Collectors.toList())) + m_function_parameter_list.stream().map(p -> p.getText()) + .collect(Collectors.toList())) + ") is not available in its platform " + k + "."); } @@ -255,6 +259,21 @@ private PSSInst getInst(PSSModel pkg, PSSInst ctx, PSSInst parent) { return inst; } + /** + * Resolve the whole hierarchical reference path. + * + * @param pkg an optional package containing m_id (m_parent != null implies + * pkg == null) + * @param var the containing instance + * @return the resolved instance of the whole hierarchical reference path + */ + public PSSInst getInst(PSSModel pkg, PSSInst var) { + if (m_parent != null) + PSSMessage.Error("PSSMemberPathElemExpression", + "Cannot evaluate a partial member path reference: " + getLowerHierarchicalID()); + return getInst(pkg, var, var); + } + @Override public PSSInst getInst(PSSInst var) { if (m_parent != null) diff --git a/src/PSSModel.java b/src/PSSModel.java index 588cf72..b83ee76 100644 --- a/src/PSSModel.java +++ b/src/PSSModel.java @@ -131,9 +131,9 @@ public void declEnumInst(PSSInst inst) { child.declEnumItem(inst); } - // if (m_parent != null) { - // m_parent.declEnumInst(inst); - // } + if (m_parent != null) { + m_parent.declEnumInst(inst); + } } public void init_up(PSSInst inst) { diff --git a/src/PSSRefPathExpression.java b/src/PSSRefPathExpression.java index 177a758..791c685 100644 --- a/src/PSSRefPathExpression.java +++ b/src/PSSRefPathExpression.java @@ -75,11 +75,14 @@ public static PSSRefPathExpression fromString(PSSModel root, String str) { @Override public PSSInst getInst(PSSInst var) { + PSSInst inst = null; if (m_type_identifier_elems != null && !m_type_identifier_elems.equals("")) { - PSSMessage.Fatal("[" + getClass().getName() + "] type_identifier_elems is not implemented"); + PSSModel m = var.getTypeModel().findDeclaration(m_type_identifier_elems); + inst = m_ref_path.getInst(m, var); + } else { + inst = m_ref_path.getInst(var); } - PSSInst inst = m_ref_path.getInst(var); if (m_bit_slice_from != null && m_bit_slice_to != null) PSSMessage.Fatal("[" + getClass().getName() + "] bit_slice is not implemented");