diff --git a/ASTBasicTerm.class b/ASTBasicTerm.class index dfe0665a..f9e645e4 100644 Binary files a/ASTBasicTerm.class and b/ASTBasicTerm.class differ diff --git a/ASTBasicTerm.java b/ASTBasicTerm.java index 3bb7161d..1ec601bf 100644 --- a/ASTBasicTerm.java +++ b/ASTBasicTerm.java @@ -1,5 +1,5 @@ /****************************** -* Copyright (c) 2003--2024 Kevin Lano +* Copyright (c) 2003--2025 Kevin Lano * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0 @@ -2879,6 +2879,12 @@ public boolean updatesObject(ASTTerm t) public boolean callSideEffect() { return false; } + public boolean hasPreSideEffect() + { return false; } + + public boolean hasPostSideEffect() + { return false; } + public boolean hasSideEffect() { return false; } diff --git a/ASTCompositeTerm.class b/ASTCompositeTerm.class index 895196bd..52b93018 100644 Binary files a/ASTCompositeTerm.class and b/ASTCompositeTerm.class differ diff --git a/ASTCompositeTerm.java b/ASTCompositeTerm.java index 58266d04..261722de 100644 --- a/ASTCompositeTerm.java +++ b/ASTCompositeTerm.java @@ -5,7 +5,7 @@ /****************************** -* Copyright (c) 2003--2024 Kevin Lano +* Copyright (c) 2003--2025 Kevin Lano * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0 @@ -342,9 +342,9 @@ else if ("dataDescriptionEntryFormat1".equals(tag) && String fld = ntrm.literalForm(); if (ASTTerm.cobolDataDescriptionDataNames.contains(fld)) - { JOptionPane.showMessageDialog(null, this + + { /* JOptionPane.showMessageDialog(null, this + " Ambiguous field name: " + fld, - " ", JOptionPane.INFORMATION_MESSAGE); + " ", JOptionPane.INFORMATION_MESSAGE); */ ASTTerm.setTaggedValue(fld, "ambiguousName", "true"); ASTTerm.cobolAmbiguousDataNames.add(fld); @@ -29134,8 +29134,8 @@ else if ("remove".equals(called) && String callp = callarg.toKM3(); String tt = ASTTerm.getType(args); String pt = ASTTerm.getType(callarg); - System.out.println(">>> Type of " + args + " is: " + tt); - System.out.println(">>> Type of " + callp + " is: " + pt); + // System.out.println(">>> Type of " + args + " is: " + tt); + // System.out.println(">>> Type of " + callp + " is: " + pt); if (cargs.size() == 0) // it.remove() for iterator { if (arg.expression != null) { expression = @@ -34648,8 +34648,9 @@ public String toKM3() if (t.updatesObject(null)) { // System.out.println(">> Expression returning value, and with side-effect: " + t); statement = t.statement; // updateForm - // System.out.println(">> Update form: >> " + statement); - System.out.println(); + /* JOptionPane.showInputDialog(">> Update form of " + + this + " : >> " + statement); */ + // System.out.println(); String qf = t.queryForm(); expression = t.expression; // System.out.println(">> Query form: >> " + expression); @@ -35902,6 +35903,11 @@ else if ("NORM_PRIORITY".equals(e2 + "")) if ("=".equals(op + "") && e2.updatesObject(null)) { // e1x := result of e2x ; postsideeffect of e2x + String postEffect = e2.postSideEffect(); + + // JOptionPane.showInputDialog(">> Update form of " + + // this + " : >> " + e2.statement); + Statement updateF = e2.statement; String qf = e2.queryForm(); @@ -35922,7 +35928,7 @@ else if ("NORM_PRIORITY".equals(e2 + "")) expression = e1.expression; } - return "(" + e1x + " := " + qf + " ; " + e2x + ")"; + return "(" + e1x + " := " + qf + " ; " + postEffect + ")"; } if ("=".equals(op + "") && e1.hasSideEffect() && @@ -37997,19 +38003,24 @@ else if (typeTerm.modelElement instanceof Entity) if (att != null) { att.setInitialExpression(vInit.expression); } - String prese = vInit.preSideEffect(); - if (vInit.statement != null) - { sstatements.addStatement(0, vInit.statement); } + if (vInit.hasPreSideEffect()) + { String prese = vInit.preSideEffect(); + if (vInit.statement != null) + { sstatements.addStatement(0, vInit.statement); } - System.out.println(">+++> Pre side-effect of " + vInit + " : " + vInit.statement); + /* JOptionPane.showInputDialog(">+++> Pre side-effect of " + vInit + " : " + vInit.statement); */ + } vInit.statement = null; - String postse = vInit.postSideEffect(); - if (vInit.statement != null) // post side-effect - { sstatements.addStatement(tv.statement); } + if (vInit.hasSideEffect()) + { String postse = vInit.postSideEffect(); - System.out.println(">+++> Post side-effect: " + tv.statement); + if (vInit.statement != null) // post side-effect + { sstatements.addStatement(tv.statement); } + + /* JOptionPane.showInputDialog(">+++> Post side-effect: " + tv.statement); */ + } } System.out.println(">+++> Declaration statements: " + statement); @@ -40116,11 +40127,14 @@ else if ("expression".equals(tag)) { ASTTerm call = (ASTTerm) terms.get(2); return call.updatesObject((ASTTerm) terms.get(0)); } + if (terms.size() == 4 && "(".equals(terms.get(0) + "") && ")".equals(terms.get(2) + "")) { // casting - ASTTerm call = (ASTTerm) terms.get(3); + ASTTerm call = (ASTTerm) terms.get(3); + // JOptionPane.showInputDialog(this + " updates object: " + + // call.updatesObject(null)); return call.updatesObject(null); } } @@ -40135,6 +40149,16 @@ public ASTTerm updatedObject() { ASTTerm obj = (ASTTerm) terms.get(0); return obj.updatedObject(); } + + if (terms.size() == 4 && + "(".equals(terms.get(0) + "") && + ")".equals(terms.get(2) + "")) + { // casting + ASTTerm call = (ASTTerm) terms.get(3); + // JOptionPane.showInputDialog(this + " updated object: " + + // call.updatedObject()); + return call.updatedObject(); + } } if (terms.size() == 4 && "primary".equals(tag) && @@ -40217,7 +40241,12 @@ else if (terms.size() == 4 && "(".equals(terms.get(0) + "") && ")".equals(terms.get(2) + "")) { // casting - ASTTerm call = (ASTTerm) terms.get(3); + ASTTerm call = (ASTTerm) terms.get(3); + + // JOptionPane.showInputDialog(this + + // " has side effect: " + + // call.hasSideEffect()); + return call.hasSideEffect(); } else if (terms.size() == 3 && @@ -40256,6 +40285,205 @@ else if (terms.size() == 5 && "?".equals(terms.get(1) + "")) return false; } + public boolean hasPreSideEffect() + { if (terms.size() == 3 && + "(".equals(terms.get(0) + "") && + ")".equals(terms.get(2) + "")) + { // brackets + ASTTerm call = (ASTTerm) terms.get(1); + return call.hasPreSideEffect(); + } + + if ("primary".equals(tag) || "parExpression".equals(tag)) + { for (int i = 0; i < terms.size(); i++) + { ASTTerm tt = (ASTTerm) terms.get(i); + if (tt.hasPreSideEffect()) + { return true; } + } + } + + if ("variableInitializer".equals(tag)) + { ASTTerm t = (ASTTerm) terms.get(0); + return t.hasPreSideEffect(); + } + + + if ("expression".equals(tag)) + { if (terms.size() == 1) // Identifier or literal + { + ASTTerm t = (ASTTerm) terms.get(0); + return t.hasPreSideEffect(); + } + + if (terms.size() == 2) // UnaryExpression + { ASTTerm op = (ASTTerm) terms.get(0); + ASTTerm arg = (ASTTerm) terms.get(1); + + String op1 = op.toKM3(); + String arg1 = arg.toKM3(); + + if ("++".equals(op.literalForm())) + { if (arg.expression != null) + { return true; } + } + + if ("--".equals(op.literalForm())) + { if (arg.expression != null) + { return true; } + } + } + else if (terms.size() == 3) // BinaryExpression + { ASTTerm op = (ASTTerm) terms.get(1); + ASTTerm arg1 = (ASTTerm) terms.get(0); + ASTTerm arg2 = (ASTTerm) terms.get(2); + + if (".".equals(op) && + "methodCall".equals(arg2.getTag())) + { return false; } + + SequenceStatement ssres = new SequenceStatement(); + + return arg1.hasPreSideEffect() || + arg2.hasPreSideEffect(); + } + else if (terms.size() == 4 && + "(".equals(terms.get(0) + "") && + ")".equals(terms.get(2) + "")) + { // casting + ASTTerm call = (ASTTerm) terms.get(3); + return call.hasPreSideEffect(); + } + else if (terms.size() == 3 && + "(".equals(terms.get(0) + "") && + ")".equals(terms.get(2) + "")) + { // brackets + ASTTerm call = (ASTTerm) terms.get(1); + return call.hasPreSideEffect(); + } + else if (terms.size() == 4 && + "[".equals(terms.get(1) + "") && + "]".equals(terms.get(3) + "")) // array access + { ASTTerm arr = (ASTTerm) terms.get(0); + ASTTerm ind = (ASTTerm) terms.get(2); + + return arr.hasPreSideEffect() || + ind.hasPreSideEffect(); + } + else if (terms.size() == 5 && "?".equals(terms.get(1) + "")) + { // ConditionalExpression + ASTTerm cond = (ASTTerm) terms.get(0); + ASTTerm ifoption = (ASTTerm) terms.get(2); + ASTTerm elseoption = (ASTTerm) terms.get(4); + + return cond.hasPreSideEffect() || + ifoption.hasPreSideEffect() || + elseoption.hasPreSideEffect(); + + } + } + + return false; + } + + public boolean hasPostSideEffect() + { if ("methodCall".equals(tag)) + { + String called = terms.get(0) + ""; + // ASTTerm callargs = (ASTTerm) terms.get(2); + // Vector cargs = getCallArguments(callargs); + + if ("replaceAll".equals(called)) + { // System.out.println(">>> methodCall " + called + " has side-effect."); + + return true; + } + + return false; + } + + if ("primary".equals(tag) || "parExpression".equals(tag)) + { for (int i = 0; i < terms.size(); i++) + { ASTTerm tt = (ASTTerm) terms.get(i); + if (tt.hasPostSideEffect()) + { return true; } + } + } + + if ("variableInitializer".equals(tag)) + { ASTTerm t = (ASTTerm) terms.get(0); + return t.hasPostSideEffect(); + } + + if ("expression".equals(tag)) + { if (terms.size() == 1) // Identifier or literal + { + ASTTerm t = (ASTTerm) terms.get(0); + return t.hasPostSideEffect(); + } + + if (terms.size() == 2) // UnaryExpression + { ASTTerm op = (ASTTerm) terms.get(0); + ASTTerm arg = (ASTTerm) terms.get(1); + + if ("++".equals(arg.literalForm())) + { return true; } + + if ("--".equals(arg.literalForm())) + { return true; } + } + else if (terms.size() == 3) // BinaryExpression + { ASTTerm op = (ASTTerm) terms.get(1); + ASTTerm arg1 = (ASTTerm) terms.get(0); + ASTTerm arg2 = (ASTTerm) terms.get(2); + + if (".".equals(op + "")) + { if ("Collections".equals(arg1.literalForm()) && + arg2.hasPostSideEffect()) + { return true; } + return false; + } + + return arg1.hasPostSideEffect() || + arg2.hasPostSideEffect(); + } + else if (terms.size() == 4 && + "(".equals(terms.get(0) + "") && + ")".equals(terms.get(2) + "")) + { // casting + ASTTerm call = (ASTTerm) terms.get(3); + return call.hasPostSideEffect(); + } + else if (terms.size() == 3 && + "(".equals(terms.get(0) + "") && + ")".equals(terms.get(2) + "")) + { + ASTTerm call = (ASTTerm) terms.get(1); + return call.hasPostSideEffect(); + } + else if (terms.size() == 4 && + "[".equals(terms.get(1) + "") && + "]".equals(terms.get(3) + "")) // array access + { ASTTerm arr = (ASTTerm) terms.get(0); + ASTTerm ind = (ASTTerm) terms.get(2); + + return arr.hasPostSideEffect() || + ind.hasPostSideEffect(); + } + else if (terms.size() == 5 && "?".equals(terms.get(1) + "")) + { // ConditionalExpression + ASTTerm cond = (ASTTerm) terms.get(0); + ASTTerm ifoption = (ASTTerm) terms.get(2); + ASTTerm elseoption = (ASTTerm) terms.get(4); + return cond.hasPostSideEffect() || + ifoption.hasPostSideEffect() || + elseoption.hasPostSideEffect(); + + } + } + + return false; + } + public String preSideEffect() { if (terms.size() == 3 && "(".equals(terms.get(0) + "") && @@ -40653,6 +40881,9 @@ else if (terms.size() == 4 && ASTTerm call = (ASTTerm) terms.get(3); String res = call.postSideEffect(); statement = call.statement; + /* JOptionPane.showInputDialog("Post side effect of " + + this + + " = " + res + " " + statement); */ return res; } else if (terms.size() == 3 && @@ -40748,6 +40979,7 @@ else if (terms.size() == 5 && "?".equals(terms.get(1) + "")) return res; } } + return null; } @@ -43086,12 +43318,12 @@ public Vector cobolDataDefinitions(java.util.Map context, Vector invs) if (multiplicity == 1 && contMult == 1) { // fieldName = owner.subrange(startPos,endPos) - JOptionPane.showMessageDialog(null, + /* JOptionPane.showMessageDialog(null, progname + ":: " + fieldName + " = " + ownername + ".subrange(" + startPos + "," + endPos + ")", "", - JOptionPane.INFORMATION_MESSAGE); + JOptionPane.INFORMATION_MESSAGE); */ BasicExpression owner = BasicExpression.newAttributeBasicExpression( ownername, stringType); @@ -43120,12 +43352,12 @@ else if (multiplicity > 1 && contMult == 1) { // fieldName = owner.subrange(startPos,endPos) int fwdth = wdth/multiplicity; - JOptionPane.showMessageDialog(null, + /* JOptionPane.showMessageDialog(null, progname + ":: " + fieldName + "[i] = " + ownername + ".subrange(" + startPos + " + (i-1)*" + fwdth + ", i*" + fwdth + ")", "", - JOptionPane.INFORMATION_MESSAGE); + JOptionPane.INFORMATION_MESSAGE); */ BasicExpression owner = BasicExpression.newAttributeBasicExpression( ownername, stringType); @@ -43151,11 +43383,11 @@ else if (multiplicity > 1 && contMult == 1) else if (multiplicity == 1 & contMult > 1) { // fieldName[i] = owner[i].subrange(...) - JOptionPane.showMessageDialog(null, progname + ":: " + fieldName + + /* JOptionPane.showMessageDialog(null, progname + ":: " + fieldName + "[i] = " + ownername + "[i].subrange(" + startPos + "," + endPos + ")", "", - JOptionPane.INFORMATION_MESSAGE); + JOptionPane.INFORMATION_MESSAGE); */ BasicExpression indx = BasicExpression.newVariableBasicExpression( @@ -43452,12 +43684,12 @@ public static boolean is88Entry(ASTTerm trm) Expression dataValueConstraint = ((ASTCompositeTerm) t3).cobolDataValue(vattr); - JOptionPane.showMessageDialog(null, + /* JOptionPane.showMessageDialog(null, "Type of " + condName + " is boolean" + " (" + dataValueConstraint + " => " + condName + " = true)", "", - JOptionPane.INFORMATION_MESSAGE); + JOptionPane.INFORMATION_MESSAGE); */ Attribute condAttr = new Attribute(condName, @@ -43700,7 +43932,7 @@ public static boolean is88Entry(ASTTerm trm) // { fieldName = "FILLER$" + startPos + "$" + endPosn; } - JOptionPane.showMessageDialog(null, + /* JOptionPane.showMessageDialog(null, "Type of " + fieldName + " is " + typ + " Signed: " + isSigned + " Width: " + wdth + @@ -43709,7 +43941,7 @@ public static boolean is88Entry(ASTTerm trm) " Multiplicity: " + multiplicity + " Container multiplicity: " + contMult, "", - JOptionPane.INFORMATION_MESSAGE); + JOptionPane.INFORMATION_MESSAGE); */ ASTTerm.setTaggedValue(fieldName, "startPosition", "" + startPos); diff --git a/ASTSymbolTerm.class b/ASTSymbolTerm.class index a9f326a2..0010be66 100644 Binary files a/ASTSymbolTerm.class and b/ASTSymbolTerm.class differ diff --git a/ASTSymbolTerm.java b/ASTSymbolTerm.java index 971a533c..b24f7220 100644 --- a/ASTSymbolTerm.java +++ b/ASTSymbolTerm.java @@ -1,5 +1,5 @@ /****************************** -* Copyright (c) 2003--2024 Kevin Lano +* Copyright (c) 2003--2025 Kevin Lano * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0 @@ -1046,6 +1046,12 @@ public ASTTerm updatedObject() public boolean callSideEffect() { return false; } + public boolean hasPreSideEffect() + { return false; } + + public boolean hasPostSideEffect() + { return false; } + public boolean hasSideEffect() { return false; } diff --git a/ASTTerm.class b/ASTTerm.class index 5c04fb7d..75ef1880 100644 Binary files a/ASTTerm.class and b/ASTTerm.class differ diff --git a/ASTTerm.java b/ASTTerm.java index b37eb6dc..1868bbe3 100644 --- a/ASTTerm.java +++ b/ASTTerm.java @@ -1,5 +1,5 @@ /****************************** -* Copyright (c) 2003--2024 Kevin Lano +* Copyright (c) 2003--2025 Kevin Lano * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0 @@ -931,7 +931,12 @@ public abstract ASTTerm instantiate( public abstract boolean callSideEffect(); - // Only for programming languages. + // Only for programming languages. + + public abstract boolean hasPreSideEffect(); + + public abstract boolean hasPostSideEffect(); + public abstract boolean hasSideEffect(); public abstract boolean isIdentifier(); diff --git a/Compiler2.class b/Compiler2.class index c9166755..3bf19a51 100644 Binary files a/Compiler2.class and b/Compiler2.class differ diff --git a/Compiler2.java b/Compiler2.java index 7995df10..e1485ec0 100644 --- a/Compiler2.java +++ b/Compiler2.java @@ -6,7 +6,7 @@ import java.awt.*; /****************************** -* Copyright (c) 2003--2024 Kevin Lano +* Copyright (c) 2003--2025 Kevin Lano * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0 @@ -11386,8 +11386,11 @@ public static void main(String[] args) // c.nospacelexicalanalysis("Map{ \"Name\" |-> Sequence{\"Braund, Mr. Owen Harris\"}->union(Sequence{\"Allen, Mr. William Henry\"}->union(Sequence{ \"Bonnell, Miss. Elizabeth\" })) }->union(Map{ \"Age\" |-> Sequence{22}->union(Sequence{35}->union(Sequence{ 58 })) }->union(Map{ \"Sex\" |-> Sequence{\"male\"}->union(Sequence{\"male\"}->union(Sequence{ \"female\" })) }->union(Map{ \"Fare\" |-> Sequence{102.0}->union(Sequence{99.0}->union(Sequence{ 250.0 })) }) ) )"); +c.nospacelexicalanalysis("arr[i].x"); +Expression zz = c.parseExpression(); +System.out.println(zz); - c.nospacelexicalanalysis("table->restrict(table > v)"); + /* c.nospacelexicalanalysis("table->restrict(table > v)"); BinaryExpression zz = (BinaryExpression) c.parseExpression(); Expression zleft = zz.getLeft(); @@ -11397,7 +11400,7 @@ public static void main(String[] args) Expression yy = zz.transformPythonSelectExpressions(); - System.out.println(yy); + System.out.println(yy); */ /* c.nospacelexicalanalysis("execute (OclFile[\"system.in\"]).println(x)");