From 351b7b7d8ade98df2bde285e3c8fb8cb7ba70178 Mon Sep 17 00:00:00 2001 From: lempinen Date: Thu, 19 Jan 2012 13:18:03 +0000 Subject: [PATCH] changed the declaration of Enum_size = Enum.size and Enum_elements = Enum.elements to Enumeration instead of Redeclaration. The parameters are now declared always once. (refs #3134) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@24005 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../sysdyn/representation/Enumeration.java | 3 ++ .../sysdyn/representation/Module.java | 5 -- .../sysdyn/representation/Redeclaration.java | 49 +------------------ 3 files changed, 5 insertions(+), 52 deletions(-) diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Enumeration.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Enumeration.java index 152d2988..51996a19 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Enumeration.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Enumeration.java @@ -46,6 +46,9 @@ public class Enumeration extends Variable { sb.append(this.name + "_class"); sb.append(" " + this.name); sb.append(";\n"); + + sb.append(" parameter Integer " + this.name + "_size = " + this.name + ".size;\n"); + sb.append(" parameter Integer " + this.name + "_elements[:] = " + this.name + ".elements;\n"); return sb.toString(); } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Module.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Module.java index 9a89df02..c5ece68c 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Module.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Module.java @@ -65,17 +65,13 @@ public class Module implements IElement { */ public String getDeclaration() { - StringBuilder parameters = new StringBuilder(); StringBuilder redeclarations = new StringBuilder(); - - if(!getRedeclarations().isEmpty()) { redeclarations.append("("); Iterator i = getRedeclarations().iterator(); while(i.hasNext()) { Redeclaration rd = i.next(); redeclarations.append(rd.getRedeclaration()); - parameters.append(rd.getParameters()); if(i.hasNext()) redeclarations.append(","); } @@ -84,7 +80,6 @@ public class Module implements IElement { StringBuilder sb = new StringBuilder(); - sb.append(parameters); sb.append(" "); sb.append(getType().getName()); sb.append(" "); diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Redeclaration.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Redeclaration.java index 40d5ade7..6f1e8b3c 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Redeclaration.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Redeclaration.java @@ -28,63 +28,18 @@ public class Redeclaration { if(replacedEnumeration == null || replacingEnumeration == null) { return ""; } - String separator = getSeparator(); StringBuilder sb = new StringBuilder(); sb.append(replacedEnumeration.getName()); sb.append(".size = "); sb.append(replacingEnumeration.getName()); - sb.append(separator + "size, "); + sb.append("_size, "); sb.append(replacedEnumeration.getName()); sb.append(".elements = "); sb.append(replacingEnumeration.getName()); - sb.append(separator + "elements"); + sb.append("_elements"); return sb.toString(); } - - /** - * Change the name of the re-declaration parameters to enable the use of - * enumerations with same names. - * - * @return - */ - public String getParameters() { - String separator = getSeparator(); - StringBuilder sb = new StringBuilder(); - sb.append(" parameter Integer " + replacingEnumeration.getName() + separator + "size = " + replacingEnumeration.getName() + ".size;\n"); - sb.append(" parameter Integer " + replacingEnumeration.getName() + separator + "elements[:] = " + replacingEnumeration.getName() + ".elements;\n"); - return sb.toString(); - } - - private String getSeparator() { - return getSeparator(this, "_"); - } - - /** - * Add enough separation marks that name conflicts would not exist. - * - * @param redeclaration - * @param separator - * @return - */ - private String getSeparator(Redeclaration redeclaration, String separator) { - if(redeclaration == null || redeclaration.replacedEnumeration == null || - redeclaration.replacedEnumeration.getParentConfiguration() == null) - return separator = "_"; - for(IElement e : redeclaration.replacedEnumeration.getParentConfiguration().getElements()) { - if(e instanceof Module) { - for(Redeclaration rd : ((Module)e).getRedeclarations()) { - if(rd.replacedEnumeration.name.equals(redeclaration.replacedEnumeration.name) && - rd.replacingEnumeration.equals(redeclaration.replacedEnumeration)) { - String separatorTmp = getSeparator(rd, separator); - if(separatorTmp.length() > separator.length()) - separator = separatorTmp; - } - } - } - } - return separator + "_"; - } public Enumeration getReplacedEnumeration() { return replacedEnumeration; -- 2.47.1