From be99aecdd88b8a098c4b6ef78415e69243043be4 Mon Sep 17 00:00:00 2001 From: Dennis Hendriks Date: Sat, 4 Jun 2022 18:09:24 +0200 Subject: [PATCH 01/23] #370 ModelWalkerGenerator: generate also composite model walkers. --- .../codegen/java/ModelWalkerGenerator.java | 240 ++++++++++++++++-- 1 file changed, 221 insertions(+), 19 deletions(-) diff --git a/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/java/ModelWalkerGenerator.java b/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/java/ModelWalkerGenerator.java index a8f018287..918eb642f 100644 --- a/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/java/ModelWalkerGenerator.java +++ b/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/java/ModelWalkerGenerator.java @@ -39,6 +39,16 @@ import org.eclipse.escet.common.java.JavaCodeUtils; * Java model walker class generator for Ecore models. * *

+ * Generates: + *

+ *

+ * + *

* The following Ecore features are currently not supported, and may lead to invalid code: *

* @throws IOException In case the code could not be written to a file; or in case the java class path extension * path is invalid. @@ -85,22 +84,21 @@ public class ModelWalkerGenerator extends EmfJavaCodeGenerator { throws IOException, ClassNotFoundException, NoSuchFieldException, IllegalAccessException { // Process arguments. - Assert.check(args.length == 7); + Assert.check(args.length == 6, args.length); String mainPkgClassName = args[0]; String binPath = args[1]; String outputPath = args[2]; String outputClassNameWalker = args[3]; String outputClassNameComposite = args[4]; String outputPackageName = args[5]; - String rootClassName = args[6]; // Resolve the package. EPackage mainPkg = loadEPackage(mainPkgClassName, binPath); // Generate code for the package. - CodeBox boxWalker = generateWalker(mainPkg, rootClassName, outputClassNameWalker, outputPackageName); - CodeBox boxComposite = generateCompositeWalker(mainPkg, rootClassName, outputClassNameWalker, - outputClassNameComposite, outputPackageName); + CodeBox boxWalker = generateWalker(mainPkg, outputClassNameWalker, outputPackageName); + CodeBox boxComposite = generateCompositeWalker(mainPkg, outputClassNameWalker, outputClassNameComposite, + outputPackageName); // Try to write the code to a file. String outputFilePathWalker = new File(new File(outputPath), outputClassNameWalker + ".java").getAbsolutePath(); @@ -118,14 +116,11 @@ public class ModelWalkerGenerator extends EmfJavaCodeGenerator { * Generate model walker class code for an {@link EPackage}. * * @param startPackage The {@link EPackage} to generate the code for. - * @param rootClassName The name of the {@link EClass} that is the root of all instances of the metamodel. * @param genClassNameWalker The name of the model walker Java class to generate. * @param genPackageName The name of the package that the generated Java class will be a part of. * @return The generated code. */ - private static CodeBox generateWalker(EPackage startPackage, String rootClassName, String genClassNameWalker, - String genPackageName) - { + private static CodeBox generateWalker(EPackage startPackage, String genClassNameWalker, String genPackageName) { CodeBox box = new MemoryCodeBox(); List packages = list(startPackage); @@ -260,14 +255,13 @@ public class ModelWalkerGenerator extends EmfJavaCodeGenerator { * Generate composite model walker class code for an {@link EPackage}. * * @param startPackage The {@link EPackage} to generate the code for. - * @param rootClassName The name of the {@link EClass} that is the root of all instances of the metamodel. * @param genClassNameWalker The name of the model walker Java class to generate. * @param genClassNameComposite The name of the composite model walker Java class to generate. * @param genPackageName The name of the package that the generated Java class will be a part of. * @return The generated code. */ - private static CodeBox generateCompositeWalker(EPackage startPackage, String rootClassName, - String genClassNameWalker, String genClassNameComposite, String genPackageName) + private static CodeBox generateCompositeWalker(EPackage startPackage, String genClassNameWalker, + String genClassNameComposite, String genPackageName) { CodeBox box = new MemoryCodeBox(); -- GitLab From 1439f320296b231cbcbb606d08da971f90b3651d Mon Sep 17 00:00:00 2001 From: Dennis Hendriks Date: Sat, 4 Jun 2022 18:16:08 +0200 Subject: [PATCH 04/23] #370 Removed 'v1x0x0' from JavaDoc. --- .../escet/common/emf/ecore/codegen/EmfCodeGenerator.java | 2 +- .../emf/ecore/codegen/java/EmfConstructorsGenerator.java | 6 +++--- .../common/emf/ecore/codegen/java/ModelWalkerGenerator.java | 6 +++--- .../codegen/latex/EmfLatexDocSkeletonDetailGenerator.java | 2 +- .../ecore/codegen/latex/EmfLatexDocSkeletonGenerator.java | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/EmfCodeGenerator.java b/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/EmfCodeGenerator.java index 665bf79eb..28032beb3 100644 --- a/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/EmfCodeGenerator.java +++ b/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/EmfCodeGenerator.java @@ -47,7 +47,7 @@ public abstract class EmfCodeGenerator { * Loads an {@link EPackage} via reflection. * * @param pkgClassName The full name of the {@link EPackage} Java class. For instance, {@code - * "bla.somelang.v1x0x0.metamodel.somelang.SomeLangPackage"}. + * "bla.somelang.metamodel.somelang.SomeLangPackage"}. * @param path The path to add to the Java class path to allow the main package Java class to be found. For * instance, {@code "bin"}. It is allowed to add multiple paths. For instance, {@code "bin|../bin"}. * @return The loaded {@link EPackage}. diff --git a/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/java/EmfConstructorsGenerator.java b/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/java/EmfConstructorsGenerator.java index 32ae28960..d02664640 100644 --- a/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/java/EmfConstructorsGenerator.java +++ b/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/java/EmfConstructorsGenerator.java @@ -45,12 +45,12 @@ public class EmfConstructorsGenerator extends EmfJavaCodeGenerator { * @param args Application arguments: *
    *
  • The full name of the main {@link EPackage} Java class. For instance, {@code - * "bla.somelang.v1x0x0.metamodel.somelang.SomeLangPackage"}.
  • + * "bla.somelang.metamodel.somelang.SomeLangPackage"}. *
  • The path to add to the Java class path to allow the main package Java class to be found. For instance, * {@code "bin"}. It is allowed to add multiple paths. For instance, {@code "bin|../bin"}.
  • - *
  • The output file name path. For instance, {@code "src/bla/somelang/v1x0x0/metamodel/java"}.
  • + *
  • The output file name path. For instance, {@code "src/bla/somelang/metamodel/java"}.
  • *
  • The output class name. For instance, {@code "SomeLangConstructors"}.
  • - *
  • The output package name. For instance, {@code "bla.somelang.v1x0x0.metamodel.java"}.
  • + *
  • The output package name. For instance, {@code "bla.somelang.metamodel.java"}.
  • *
* @throws IOException In case the code could not be written to a file; or in case the java class path extension * path is invalid. diff --git a/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/java/ModelWalkerGenerator.java b/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/java/ModelWalkerGenerator.java index 59f39a82c..9e499d501 100644 --- a/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/java/ModelWalkerGenerator.java +++ b/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/java/ModelWalkerGenerator.java @@ -66,13 +66,13 @@ public class ModelWalkerGenerator extends EmfJavaCodeGenerator { * @param args Application arguments: *
    *
  • The full name of the main {@link EPackage} Java class. For instance, {@code - * "bla.somelang.v1x0x0.metamodel.somelang.SomeLangPackage"}.
  • + * "bla.somelang.metamodel.somelang.SomeLangPackage"}. *
  • The path to add to the Java class path to allow the main package Java class to be found. For instance, * {@code "bin"}. It is allowed to add multiple paths. For instance, {@code "bin|../bin"}.
  • - *
  • The output file path. For instance, {@code "src/bla/somelang/v1x0x0/metamodel/java"}.
  • + *
  • The output file path. For instance, {@code "src/bla/somelang/metamodel/java"}.
  • *
  • The model walker output class name. For instance, {@code "SomeLangWalker"}.
  • *
  • The composite model walker output class name. For instance, {@code "CompositeSomeLangWalker"}.
  • - *
  • The output package name. For instance, {@code "bla.somelang.v1x0x0.metamodel.java"}.
  • + *
  • The output package name. For instance, {@code "bla.somelang.metamodel.java"}.
  • *
* @throws IOException In case the code could not be written to a file; or in case the java class path extension * path is invalid. diff --git a/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/latex/EmfLatexDocSkeletonDetailGenerator.java b/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/latex/EmfLatexDocSkeletonDetailGenerator.java index e1f085507..48f81f27c 100644 --- a/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/latex/EmfLatexDocSkeletonDetailGenerator.java +++ b/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/latex/EmfLatexDocSkeletonDetailGenerator.java @@ -56,7 +56,7 @@ public class EmfLatexDocSkeletonDetailGenerator extends EmfLatexCodeGenerator { * @param args Application arguments: *
    *
  • The full name of the main {@link EPackage} Java class. For instance, {@code - * "bla.somelang.v1x0x0.metamodel.somelang.SomeLangPackage"}.
  • + * "bla.somelang.metamodel.somelang.SomeLangPackage"}. *
  • The path to add to the Java class path to allow the main package Java class to be found. For instance, * {@code "bin"}. It is allowed to add multiple paths. For instance, {@code "bin|../bin"}.
  • *
  • The output file name path. For instance, {@code "docs"}.
  • diff --git a/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/latex/EmfLatexDocSkeletonGenerator.java b/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/latex/EmfLatexDocSkeletonGenerator.java index e27c0588d..61036b185 100644 --- a/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/latex/EmfLatexDocSkeletonGenerator.java +++ b/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/latex/EmfLatexDocSkeletonGenerator.java @@ -54,7 +54,7 @@ public class EmfLatexDocSkeletonGenerator extends EmfLatexCodeGenerator { * @param args Application arguments: *
      *
    • The full name of the main {@link EPackage} Java class. For instance, {@code - * "bla.somelang.v1x0x0.metamodel.somelang.SomeLangPackage"}.
    • + * "bla.somelang.metamodel.somelang.SomeLangPackage"}. *
    • The path to add to the Java class path to allow the main package Java class to be found. For instance, * {@code "bin"}. It is allowed to add multiple paths. For instance, {@code "bin|../bin"}.
    • *
    • The output file name path. For instance, {@code "docs"}.
    • -- GitLab From 02cce46dc0415f7e46b7d1b734b6993e9f0dc6d9 Mon Sep 17 00:00:00 2001 From: Dennis Hendriks Date: Sat, 4 Jun 2022 18:25:49 +0200 Subject: [PATCH 05/23] #370 Share code between composite and non-composite walker generation. --- .../codegen/java/ModelWalkerGenerator.java | 240 ++++++------------ 1 file changed, 74 insertions(+), 166 deletions(-) diff --git a/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/java/ModelWalkerGenerator.java b/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/java/ModelWalkerGenerator.java index 9e499d501..e435bfb59 100644 --- a/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/java/ModelWalkerGenerator.java +++ b/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/java/ModelWalkerGenerator.java @@ -96,8 +96,9 @@ public class ModelWalkerGenerator extends EmfJavaCodeGenerator { EPackage mainPkg = loadEPackage(mainPkgClassName, binPath); // Generate code for the package. - CodeBox boxWalker = generateWalker(mainPkg, outputClassNameWalker, outputPackageName); - CodeBox boxComposite = generateCompositeWalker(mainPkg, outputClassNameWalker, outputClassNameComposite, + CodeBox boxWalker = generateClass(false, mainPkg, outputClassNameWalker, outputClassNameComposite, + outputPackageName); + CodeBox boxComposite = generateClass(true, mainPkg, outputClassNameWalker, outputClassNameComposite, outputPackageName); // Try to write the code to a file. @@ -113,16 +114,23 @@ public class ModelWalkerGenerator extends EmfJavaCodeGenerator { } /** - * Generate model walker class code for an {@link EPackage}. + * Generate (composite) model walker class code for an {@link EPackage}. * + * @param genComposite Whether to generate a composite model walker ({@code true}) or a model walker + * ({@code false}). * @param startPackage The {@link EPackage} to generate the code for. * @param genClassNameWalker The name of the model walker Java class to generate. + * @param genClassNameComposite The name of the composite model walker Java class to generate. * @param genPackageName The name of the package that the generated Java class will be a part of. * @return The generated code. */ - private static CodeBox generateWalker(EPackage startPackage, String genClassNameWalker, String genPackageName) { + private static CodeBox generateClass(boolean genComposite, EPackage startPackage, String genClassNameWalker, + String genClassNameComposite, String genPackageName) + { + // Initialize the code. CodeBox box = new MemoryCodeBox(); + // Collect the classes and packages to consider. List packages = list(startPackage); List classes; while (true) { @@ -161,6 +169,7 @@ public class ModelWalkerGenerator extends EmfJavaCodeGenerator { } } + // Add the file header. box.add("//////////////////////////////////////////////////////////////////////////////"); box.add("// Copyright (c) 2010, 2022 Contributors to the Eclipse Foundation"); box.add("//"); @@ -182,13 +191,16 @@ public class ModelWalkerGenerator extends EmfJavaCodeGenerator { box.add("package %s;", genPackageName); box.add(); + // Add the imports. List imports = listc(classes.size()); - imports.add("java.util.List"); - imports.add("org.eclipse.escet.common.java.Assert"); + if (!genComposite) { + imports.add("java.util.List"); + imports.add("org.eclipse.escet.common.java.Assert"); + } for (EClass impClass: classes) { imports.add(getJavaTypeName(impClass)); - if (!impClass.isAbstract()) { + if (!genComposite && !impClass.isAbstract()) { if (!getDerivedClasses(impClass, classes).isEmpty()) { imports.add(getImplClassName(impClass)); } @@ -200,10 +212,11 @@ public class ModelWalkerGenerator extends EmfJavaCodeGenerator { } box.add(); + // Add the class JavaDoc. box.add("/**"); - box.add(" * A walker for \"%s\" models.", startPackage.getName()); + box.add(" * A %swalker for \"%s\" models.", genComposite ? "composite " : "", startPackage.getName()); box.add(" *"); - box.add(" *

      The walker works as follows:"); + box.add(" *

      The %swalker works as follows:", genComposite ? "composite " : ""); box.add(" *

        "); box.add(" *
      • Performs a top-down depth-first walk over the object tree, using the"); box.add(" * containment hierarchy.
      • "); @@ -225,10 +238,20 @@ public class ModelWalkerGenerator extends EmfJavaCodeGenerator { box.add(" *
      "); box.add(" *

      "); box.add(" *"); - box.add(" *

      By default, the pre-processing and post-processing methods do nothing"); - box.add(" * (they have an empty implementation). It is up to derived classes to"); - box.add(" * override methods and provide actual implementations. They may also override"); - box.add(" * walk and crawl methods, if desired.

      "); + if (genComposite) { + box.add(" *

      A composite walking does not perform any pre-processing or post-processing"); + box.add(" * by itself. It can be configured with any number of other (composite or"); + box.add(" * non-composite) model walkers. As pre-processing and post-processing the"); + box.add(" * composite model walker invokes pre-processing and post-processing on each"); + box.add(" * 'other' model walker, in the order they are supplied. The walking and"); + box.add(" * crawling methods of the non-composite of the 'other' model walkers are not"); + box.add(" * used.

      "); + } else { + box.add(" *

      By default, the pre-processing and post-processing methods do nothing"); + box.add(" * (they have an empty implementation). It is up to derived classes to"); + box.add(" * override methods and provide actual implementations. They may also override"); + box.add(" * walk and crawl methods, if desired.

      "); + } box.add(" *"); box.add(" *

      This abstract walker class has no public methods. It is up to the derived"); box.add(" * classes to add a public method as entry method. They can decide which"); @@ -236,167 +259,52 @@ public class ModelWalkerGenerator extends EmfJavaCodeGenerator { box.add(" * method a proper name, parameters, etc. They may even allow multiple public"); box.add(" * methods to allow starting from multiple classes.

      "); box.add(" */"); - box.add("public abstract class %s {", genClassNameWalker); - boolean first = true; - for (EClass cls: classes) { - if (!first) { - box.add(); - } - generateWalkerMethods(cls, classes, box); - first = false; + // Add the class header. + if (genComposite) { + box.add("public abstract class %s extends %s {", genClassNameComposite, genClassNameWalker); + } else { + box.add("public abstract class %s {", genClassNameWalker); } - box.add("}"); - return box; - } - - /** - * Generate composite model walker class code for an {@link EPackage}. - * - * @param startPackage The {@link EPackage} to generate the code for. - * @param genClassNameWalker The name of the model walker Java class to generate. - * @param genClassNameComposite The name of the composite model walker Java class to generate. - * @param genPackageName The name of the package that the generated Java class will be a part of. - * @return The generated code. - */ - private static CodeBox generateCompositeWalker(EPackage startPackage, String genClassNameWalker, - String genClassNameComposite, String genPackageName) - { - CodeBox box = new MemoryCodeBox(); - - List packages = list(startPackage); - List classes; - while (true) { - boolean done = true; - Set classSet = set(); - - // Get all classes for the packages and their sub-packages. - for (EPackage pkg: packages) { - classSet.addAll(getClasses(pkg, true)); - } - - // Add all classes that are used as types of the features. - Set classSet2 = copy(classSet); - for (EClass cls: classSet2) { - for (EStructuralFeature feat: cls.getEAllStructuralFeatures()) { - if (feat.getEType() instanceof EClass) { - classSet.add((EClass)feat.getEType()); - } - } + // Add the class body. + if (genComposite) { + // Add fields. + box.indent(); + box.add("/** The walkers to be composed by this composite walker. */"); + box.add("private %s[] walkers;", genClassNameWalker); + box.dedent(); + box.add(); + + // Add constructor. + box.indent(); + box.add("/**"); + box.add(" * Constructor of the {@link %s} class.", genClassNameComposite); + box.add(" *"); + box.add(" * @param walkers The walkers to be composed by this composite walker."); + box.add(" */"); + box.add("public %s(%s[] walkers) {", genClassNameComposite, genClassNameWalker); + box.add(" this.walkers = walkers;"); + box.add("}"); + box.dedent(); + + // Add methods. + for (EClass cls: classes) { + generateCompositeWalkerMethods(cls, genClassNameWalker, box); } - - // From the classes, get the root packages. If we have any new - // ones, we are not yet done, as we need another iteration. - for (EClass cls: classSet) { - EPackage newPackage = getRootPackage(cls); - if (!packages.contains(newPackage)) { - packages.add(newPackage); - done = false; + } else { + // Add methods. + boolean first = true; + for (EClass cls: classes) { + if (!first) { + box.add(); } + generateWalkerMethods(cls, classes, box); + first = false; } - - // If we are done, save the classes. - if (done) { - classes = sortedgeneric(classSet, new EClassSorter()); - break; - } - } - - box.add("//////////////////////////////////////////////////////////////////////////////"); - box.add("// Copyright (c) 2010, 2022 Contributors to the Eclipse Foundation"); - box.add("//"); - box.add("// See the NOTICE file(s) distributed with this work for additional"); - box.add("// information regarding copyright ownership."); - box.add("//"); - box.add("// This program and the accompanying materials are made available"); - box.add("// under the terms of the MIT License which is available at"); - box.add("// https://opensource.org/licenses/MIT"); - box.add("//"); - box.add("// SPDX-License-Identifier: MIT"); - box.add("//////////////////////////////////////////////////////////////////////////////"); - box.add(); - box.add("// Generated using the \"org.eclipse.escet.common.emf.ecore.codegen\" project."); - box.add(); - box.add("// Disable Eclipse Java formatter for generated code file:"); - box.add("// @formatter:off"); - box.add(); - box.add("package %s;", genPackageName); - box.add(); - - List imports = listc(classes.size()); - - for (EClass impClass: classes) { - imports.add(getJavaTypeName(impClass)); - } - - for (String imp: JavaCodeUtils.formatImports(imports, genPackageName)) { - box.add(imp); - } - box.add(); - - box.add("/**"); - box.add(" * A composite walker for \"%s\" models.", startPackage.getName()); - box.add(" *"); - box.add(" *

      The composite walker works as follows:"); - box.add(" *

        "); - box.add(" *
      • Performs a top-down depth-first walk over the object tree, using the"); - box.add(" * containment hierarchy.
      • "); - box.add(" *
      • No particular order should be assumed for walking over the child"); - box.add(" * features.
      • "); - box.add(" *
      • For each object encountered, pre-processing is performed before walking"); - box.add(" * over the children, and post-processing is performed after walking over"); - box.add(" * the children.
      • "); - box.add(" *
      • Pre-processing for objects is done by crawling up the inheritance"); - box.add(" * hierarchy of the object, performing pre-processing for each of the"); - box.add(" * types encountered in the type hierarchy. The pre-processing methods are"); - box.add(" * invoked from most general to most specific class (super classes before"); - box.add(" * base classes).
      • "); - box.add(" *
      • Post-processing for objects is done by crawling up the inheritance"); - box.add(" * hierarchy of the object, performing post-processing for each of the"); - box.add(" * types encountered in the type hierarchy. The post-processing methods are"); - box.add(" * invoked from most specific to most general class (base classes before"); - box.add(" * super classes).
      • "); - box.add(" *
      "); - box.add(" *

      "); - box.add(" *"); - box.add(" *

      A composite walking does not perform any pre-processing or post-processing"); - box.add(" * by itself. It can be configured with any number of other (composite or"); - box.add(" * non-composite) model walkers. As pre-processing and post-processing the"); - box.add(" * composite model walker invokes pre-processing and post-processing on each"); - box.add(" * 'other' model walker, in the order they are supplied. The walking and"); - box.add(" * crawling methods of the non-composite of the 'other' model walkers are not"); - box.add(" * used.

      "); - box.add(" *"); - box.add(" *

      This abstract walker class has no public methods. It is up to the derived"); - box.add(" * classes to add a public method as entry method. They can decide which"); - box.add(" * classes are to be used as starting point, and they can give the public"); - box.add(" * method a proper name, parameters, etc. They may even allow multiple public"); - box.add(" * methods to allow starting from multiple classes.

      "); - box.add(" */"); - box.add("public abstract class %s extends %s {", genClassNameComposite, genClassNameWalker); - - box.indent(); - box.add("/** The walkers to be composed by this composite walker. */"); - box.add("private %s[] walkers;", genClassNameWalker); - box.dedent(); - box.add(); - - box.indent(); - box.add("/**"); - box.add(" * Constructor of the {@link %s} class.", genClassNameComposite); - box.add(" *"); - box.add(" * @param walkers The walkers to be composed by this composite walker."); - box.add(" */"); - box.add("public %s(%s[] walkers) {", genClassNameComposite, genClassNameWalker); - box.add(" this.walkers = walkers;"); - box.add("}"); - box.dedent(); - - for (EClass cls: classes) { - generateCompositeWalkerMethods(cls, genClassNameWalker, box); } + // Close the class. box.add("}"); return box; } -- GitLab From 72659d6b7a591616a95dd5db588e089ce9751bd9 Mon Sep 17 00:00:00 2001 From: Dennis Hendriks Date: Sat, 4 Jun 2022 18:29:48 +0200 Subject: [PATCH 06/23] #370 Small improvements and alignments for EMF code generators. --- .../emf/ecore/codegen/java/EmfConstructorsGenerator.java | 4 ++-- .../common/emf/ecore/codegen/java/ModelWalkerGenerator.java | 2 +- .../codegen/latex/EmfLatexDocSkeletonDetailGenerator.java | 4 ++-- .../emf/ecore/codegen/latex/EmfLatexDocSkeletonGenerator.java | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/java/EmfConstructorsGenerator.java b/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/java/EmfConstructorsGenerator.java index d02664640..edd9a2b33 100644 --- a/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/java/EmfConstructorsGenerator.java +++ b/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/java/EmfConstructorsGenerator.java @@ -48,7 +48,7 @@ public class EmfConstructorsGenerator extends EmfJavaCodeGenerator { * "bla.somelang.metamodel.somelang.SomeLangPackage"}. *
    • The path to add to the Java class path to allow the main package Java class to be found. For instance, * {@code "bin"}. It is allowed to add multiple paths. For instance, {@code "bin|../bin"}.
    • - *
    • The output file name path. For instance, {@code "src/bla/somelang/metamodel/java"}.
    • + *
    • The output directory path. For instance, {@code "src/bla/somelang/metamodel/java"}.
    • *
    • The output class name. For instance, {@code "SomeLangConstructors"}.
    • *
    • The output package name. For instance, {@code "bla.somelang.metamodel.java"}.
    • *
    @@ -80,7 +80,7 @@ public class EmfConstructorsGenerator extends EmfJavaCodeGenerator { box.writeToFile(outputFilePath); // We are done. - System.out.print("Code written to: " + outputFilePath); + System.out.printf("Code written to: %s%n", outputFilePath); } /** diff --git a/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/java/ModelWalkerGenerator.java b/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/java/ModelWalkerGenerator.java index e435bfb59..f6f74f40c 100644 --- a/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/java/ModelWalkerGenerator.java +++ b/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/java/ModelWalkerGenerator.java @@ -69,7 +69,7 @@ public class ModelWalkerGenerator extends EmfJavaCodeGenerator { * "bla.somelang.metamodel.somelang.SomeLangPackage"}. *
  • The path to add to the Java class path to allow the main package Java class to be found. For instance, * {@code "bin"}. It is allowed to add multiple paths. For instance, {@code "bin|../bin"}.
  • - *
  • The output file path. For instance, {@code "src/bla/somelang/metamodel/java"}.
  • + *
  • The output directory path. For instance, {@code "src/bla/somelang/metamodel/java"}.
  • *
  • The model walker output class name. For instance, {@code "SomeLangWalker"}.
  • *
  • The composite model walker output class name. For instance, {@code "CompositeSomeLangWalker"}.
  • *
  • The output package name. For instance, {@code "bla.somelang.metamodel.java"}.
  • diff --git a/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/latex/EmfLatexDocSkeletonDetailGenerator.java b/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/latex/EmfLatexDocSkeletonDetailGenerator.java index 48f81f27c..723792014 100644 --- a/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/latex/EmfLatexDocSkeletonDetailGenerator.java +++ b/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/latex/EmfLatexDocSkeletonDetailGenerator.java @@ -59,7 +59,7 @@ public class EmfLatexDocSkeletonDetailGenerator extends EmfLatexCodeGenerator { * "bla.somelang.metamodel.somelang.SomeLangPackage"}. *
  • The path to add to the Java class path to allow the main package Java class to be found. For instance, * {@code "bin"}. It is allowed to add multiple paths. For instance, {@code "bin|../bin"}.
  • - *
  • The output file name path. For instance, {@code "docs"}.
  • + *
  • The output directory path. For instance, {@code "docs"}.
  • *
* @throws IOException In case the code could not be written to a file; or in case the java class path extension * path is invalid. @@ -88,7 +88,7 @@ public class EmfLatexDocSkeletonDetailGenerator extends EmfLatexCodeGenerator { box.writeToFile(outputFilePath); // We are done. - System.out.print("Code written to: " + outputFilePath); + System.out.printf("Code written to: %s%n", outputFilePath); } /** diff --git a/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/latex/EmfLatexDocSkeletonGenerator.java b/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/latex/EmfLatexDocSkeletonGenerator.java index 61036b185..aa5e75cad 100644 --- a/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/latex/EmfLatexDocSkeletonGenerator.java +++ b/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/latex/EmfLatexDocSkeletonGenerator.java @@ -57,7 +57,7 @@ public class EmfLatexDocSkeletonGenerator extends EmfLatexCodeGenerator { * "bla.somelang.metamodel.somelang.SomeLangPackage"}. *
  • The path to add to the Java class path to allow the main package Java class to be found. For instance, * {@code "bin"}. It is allowed to add multiple paths. For instance, {@code "bin|../bin"}.
  • - *
  • The output file name path. For instance, {@code "docs"}.
  • + *
  • The output directory path. For instance, {@code "docs"}.
  • * * @throws IOException In case the code could not be written to a file; or in case the java class path extension * path is invalid. @@ -85,7 +85,7 @@ public class EmfLatexDocSkeletonGenerator extends EmfLatexCodeGenerator { box.writeToFile(outputFilePath); // We are done. - System.out.print("Code written to: " + outputFilePath); + System.out.printf("Code written to: %s%n", outputFilePath); } /** -- GitLab From 1e2b1a2a482427858ef5c5636c5a2c01156a7b56 Mon Sep 17 00:00:00 2001 From: Dennis Hendriks Date: Sat, 4 Jun 2022 19:00:37 +0200 Subject: [PATCH 07/23] #370 Added CIF precondition check(er) functionality. --- .../META-INF/MANIFEST.MF | 3 +- .../escet/cif/common/checkers/CifCheck.java | 51 +++++++++++ .../common/checkers/CifCheckViolation.java | 73 +++++++++++++++ .../escet/cif/common/checkers/CifChecker.java | 88 +++++++++++++++++++ 4 files changed, 214 insertions(+), 1 deletion(-) create mode 100644 cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifCheck.java create mode 100644 cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifCheckViolation.java create mode 100644 cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifChecker.java diff --git a/cif/org.eclipse.escet.cif.common/META-INF/MANIFEST.MF b/cif/org.eclipse.escet.cif.common/META-INF/MANIFEST.MF index be7aa8710..9c858928c 100644 --- a/cif/org.eclipse.escet.cif.common/META-INF/MANIFEST.MF +++ b/cif/org.eclipse.escet.cif.common/META-INF/MANIFEST.MF @@ -6,7 +6,8 @@ Bundle-Version: 0.6.0.qualifier Bundle-Vendor: Eclipse ESCET Bundle-RequiredExecutionEnvironment: JavaSE-11 Bundle-ActivationPolicy: lazy -Export-Package: org.eclipse.escet.cif.common +Export-Package: org.eclipse.escet.cif.common, + org.eclipse.escet.cif.common.checkers Require-Bundle: org.eclipse.escet.cif.metamodel;bundle-version="0.6.0", org.eclipse.escet.common.java;bundle-version="0.6.0", org.eclipse.escet.cif.metamodel.java;bundle-version="0.6.0", diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifCheck.java new file mode 100644 index 000000000..f53523087 --- /dev/null +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifCheck.java @@ -0,0 +1,51 @@ +////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2022 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available +// under the terms of the MIT License which is available at +// https://opensource.org/licenses/MIT +// +// SPDX-License-Identifier: MIT +////////////////////////////////////////////////////////////////////////////// + +package org.eclipse.escet.cif.common.checkers; + +import java.util.Set; + +import org.eclipse.escet.cif.metamodel.java.CifWalker; +import org.eclipse.escet.common.position.metamodel.position.PositionObject; + +/** + * CIF check. Checks whether a given CIF specification satisfies a certain condition. + * + * @implSpec Override only the relevant {@code preprocess*} and {@code postprocess*} methods. The {@code *crawl*} and + * {@code walk*} methods should not be overridden, as they are ignored by {@link CifChecker}. + */ +public abstract class CifCheck extends CifWalker { + /** The violations collected so far. */ + private Set violations; + + /** + * Sets the set in which to collect violations. + * + * @param violations The set. + */ + public void setViolations(Set violations) { + this.violations = violations; + } + + /** + * Add a violation. + * + * @param object The named CIF object for which the violation is reported, or {@code null} for report it for the CIF + * specification. + * @param message The message describing the violation. E.g., {@code "event is a channel"}, + * {@code "automaton is a kindless/regular automaton"} or {@code "specification has no automata"}. + */ + protected void addViolation(PositionObject object, String message) { + violations.add(new CifCheckViolation(object, message)); + } +} diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifCheckViolation.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifCheckViolation.java new file mode 100644 index 000000000..89d99436f --- /dev/null +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifCheckViolation.java @@ -0,0 +1,73 @@ +////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2022 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available +// under the terms of the MIT License which is available at +// https://opensource.org/licenses/MIT +// +// SPDX-License-Identifier: MIT +////////////////////////////////////////////////////////////////////////////// + +package org.eclipse.escet.cif.common.checkers; + +import static org.eclipse.escet.common.java.Strings.fmt; + +import java.util.Objects; + +import org.eclipse.escet.cif.common.CifTextUtils; +import org.eclipse.escet.common.java.Assert; +import org.eclipse.escet.common.position.metamodel.position.PositionObject; + +/** CIF check condition violation. */ +public class CifCheckViolation { + /** + * The named CIF object for which the violation is reported, or {@code null} for report it for the CIF + * specification. + */ + private final PositionObject object; + + /** The message describing the violation. */ + private final String message; + + /** + * Constructor for the {@link CifCheckViolation} class. + * + * @param object The named CIF object for which the violation is reported, or {@code null} for report it for the CIF + * specification. + * @param message The message describing the violation. E.g., {@code "event is a channel"}, + * {@code "automaton is a kindless/regular automaton"} or {@code "specification has no automata"}. + */ + public CifCheckViolation(PositionObject object, String message) { + this.object = object; + this.message = message; + if (object != null) { + Assert.check(CifTextUtils.hasName(object), object); + } + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof CifCheckViolation)) { + return false; + } + if (this == obj) { + return true; + } + CifCheckViolation that = (CifCheckViolation)obj; + return this.object == that.object && this.message.equals(that.message); + } + + @Override + public int hashCode() { + return Objects.hash(object, message); + } + + @Override + public String toString() { + String name = (object == null) ? "specification" : "\"" + CifTextUtils.getAbsName(object) + "\""; + return fmt("%s: %s.", name, message); + } +} diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifChecker.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifChecker.java new file mode 100644 index 000000000..89b76fc8b --- /dev/null +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifChecker.java @@ -0,0 +1,88 @@ +////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2022 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available +// under the terms of the MIT License which is available at +// https://opensource.org/licenses/MIT +// +// SPDX-License-Identifier: MIT +////////////////////////////////////////////////////////////////////////////// + +package org.eclipse.escet.cif.common.checkers; + +import static org.eclipse.escet.common.java.Sets.set; + +import java.util.Collections; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +import org.eclipse.escet.cif.metamodel.cif.Specification; +import org.eclipse.escet.cif.metamodel.java.CompositeCifWalker; +import org.eclipse.escet.common.app.framework.exceptions.UnsupportedException; +import org.eclipse.escet.common.java.Assert; +import org.eclipse.escet.common.java.Strings; + +/** CIF checker. Checks whether a given CIF specification satisfies certain {@link CifCheck conditions}. */ +public class CifChecker extends CompositeCifWalker { + /** The conditions to check. */ + private final CifCheck[] conditions; + + /** + * Constructor for the {@link CifChecker} class. + * + * @param conditions The conditions to check. + */ + public CifChecker(List conditions) { + this(conditions.toArray(i -> new CifCheck[i])); + } + + /** + * Constructor for the {@link CifChecker} class. + * + * @param conditions The conditions to check. + */ + public CifChecker(CifCheck[] conditions) { + super(conditions); + this.conditions = conditions; + } + + /** + * Check whether a given CIF specification satisfies the given conditions. + * + * @param spec The CIF specification to check. + * @return The violations. + */ + public Set check(Specification spec) { + // Initialize. + Set violations = set(); + for (CifCheck condition: conditions) { + condition.setViolations(violations); + } + + // Check specification for condition violations. + walkSpecification(spec); + + // Return the violations. + return violations; + } + + /** + * Reports a tool failed to execute due to precondition violations indicating the specification is unsupported. + * + * @param violations The precondition violations. Must not be empty. + * @param toolName The human-readable name of the tool. + * @throws UnsupportedException Always thrown. + */ + public static void reportPreconditionViolations(Set violations, String toolName) { + Assert.check(!violations.isEmpty()); + List messages = violations.stream().map(v -> "Unsupported " + v.toString()) + .collect(Collectors.toList()); + Collections.sort(messages, Strings.SORTER); + String msg = toolName + " failed due to unsatisfied preconditions:\n - " + String.join("\n - ", messages); + throw new UnsupportedException(msg); + } +} -- GitLab From a822aab106d1d0510d202df13c5faf67c1dcd51e Mon Sep 17 00:00:00 2001 From: Dennis Hendriks Date: Sun, 5 Jun 2022 14:28:59 +0200 Subject: [PATCH 08/23] #370 Added CifTextUtils.hasName/getNamedAncestorOrSelf. --- .../escet/cif/common/CifTextUtils.java | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/CifTextUtils.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/CifTextUtils.java index bb1312236..956729a30 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/CifTextUtils.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/CifTextUtils.java @@ -1217,6 +1217,50 @@ public class CifTextUtils { return rslt.toString(); } + /** + * Returns whether the given CIF object has a name. + * + *

    + * Note that {@link Specification}s are considered not to have a name, as the name can't be specified in the textual + * syntax, and is fixed in the metamodel. + *

    + * + *

    + * Note that {@link Field}s are considered not to have a name, even when they do have one, for compatibility with + * {@link #getName}. The caller should handle fields as a special case, if relevant. + *

    + * + * @param obj The CIF object for which to determine whether it has a name. + * @return Whether the CIF object has a name ({@code true}) or not ({@code false}). + * @see #getName + * @see #getAbsName + */ + public static boolean hasName(PositionObject obj) { + if (obj instanceof Specification) { + return false; // Explicitly 'false'. See method JavaDoc. + } else if (obj instanceof Component) { + return true; // Non-specification component. + } else if (obj instanceof ComponentDef) { + return true; + } else if (obj instanceof Parameter) { + return true; + } else if (obj instanceof Declaration) { + return true; + } else if (obj instanceof EnumLiteral) { + return true; + } else if (obj instanceof Location) { + return ((Location)obj).getName() != null; + } else if (obj instanceof Invariant) { + return ((Invariant)obj).getName() != null; + } else if (obj instanceof FunctionParameter) { + return true; + } else if (obj instanceof Field) { + return false; // Explicitly 'false'. See method JavaDoc. + } else { + return false; // Not a CIF object with a name. + } + } + /** * Returns the name of the given CIF object. Names that are keywords are not escaped. For specifications, {@code ""} * is returned. @@ -1228,6 +1272,7 @@ public class CifTextUtils { * * @param obj The CIF object for which to return the name. Must be a named object. * @return The name of the CIF object. + * @see #hasName */ public static String getName(PositionObject obj) { if (obj instanceof Component) { @@ -1283,6 +1328,21 @@ public class CifTextUtils { return getName(obj); } + /** + * Returns the object itself if it is itself a named object, the closest named ancestor of the given object if one + * exists, or {@code null} if the given object is itself not a named object, and also has no named ancestor. + * + * @param obj The given object. + * @return The given object itself (if named), its closest named ancestor (if any), or {@code null} (otherwise). + */ + public static PositionObject getNamedAncestorOrSelf(PositionObject obj) { + PositionObject cur = obj; + while (cur != null && !hasName(cur)) { + cur = (PositionObject)cur.eContainer(); + } + return cur; + } + /** * Returns an end-user readable textual (reference) representation of a location, mostly for use in error messages. * -- GitLab From c5edd347d35602259132f21f6fb124da452d1ee5 Mon Sep 17 00:00:00 2001 From: Dennis Hendriks Date: Sun, 5 Jun 2022 14:29:49 +0200 Subject: [PATCH 09/23] #370 Added various preconditions checks. - Based on the ones used by CIF to Supremica. - Some more general checks as well. --- .../cif/common/checkers/NoChannelsCheck.java | 26 + .../checkers/NoContinuousVariablesCheck.java | 24 + .../NoDiscVarsWithMultiInitValuesCheck.java | 45 ++ .../checkers/NoIfUpdatesOnEdgesCheck.java | 45 ++ .../checkers/NoInitPredsInCompsCheck.java | 29 + .../checkers/NoInputVariablesCheck.java | 24 + .../checkers/NoKindlessAutomataCheck.java | 27 + .../NoKindlessStateEvtExclInvsCheck.java | 53 ++ .../checkers/NoMultiAssignOnEdgesCheck.java | 49 ++ .../NoPartialVarAssignOnEdgesCheck.java | 48 ++ .../checkers/NoSpecificBinaryExprsCheck.java | 502 ++++++++++++++++++ .../common/checkers/NoSpecificExprsCheck.java | 500 +++++++++++++++++ .../common/checkers/NoSpecificTypesCheck.java | 193 +++++++ .../checkers/NoSpecificUnaryExprsCheck.java | 144 +++++ .../checkers/NoStateInvsInLocsCheck.java | 44 ++ .../escet/cif/common/checkers/NoTauCheck.java | 54 ++ .../common/checkers/NoUrgentEdgesCheck.java | 33 ++ .../checkers/NoUrgentLocationsCheck.java | 40 ++ .../checkers/NoUserDefinedFunctionsCheck.java | 24 + .../checkers/OnlyAutsWithOneInitLocCheck.java | 91 ++++ .../OnlyEventsWithControllabilityCheck.java | 66 +++ .../OnlyReqStateInvsInCompsCheck.java | 38 ++ .../checkers/OnlySimpleAssignmentsCheck.java | 56 ++ .../OnlyStaticEvalMarkerPredsInLocsCheck.java | 57 ++ .../OnlyVarValueMarkerPredsInCompsCheck.java | 71 +++ 25 files changed, 2283 insertions(+) create mode 100644 cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoChannelsCheck.java create mode 100644 cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoContinuousVariablesCheck.java create mode 100644 cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoDiscVarsWithMultiInitValuesCheck.java create mode 100644 cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoIfUpdatesOnEdgesCheck.java create mode 100644 cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoInitPredsInCompsCheck.java create mode 100644 cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoInputVariablesCheck.java create mode 100644 cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoKindlessAutomataCheck.java create mode 100644 cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoKindlessStateEvtExclInvsCheck.java create mode 100644 cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoMultiAssignOnEdgesCheck.java create mode 100644 cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoPartialVarAssignOnEdgesCheck.java create mode 100644 cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificBinaryExprsCheck.java create mode 100644 cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificExprsCheck.java create mode 100644 cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificTypesCheck.java create mode 100644 cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificUnaryExprsCheck.java create mode 100644 cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoStateInvsInLocsCheck.java create mode 100644 cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoTauCheck.java create mode 100644 cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoUrgentEdgesCheck.java create mode 100644 cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoUrgentLocationsCheck.java create mode 100644 cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoUserDefinedFunctionsCheck.java create mode 100644 cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyAutsWithOneInitLocCheck.java create mode 100644 cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyEventsWithControllabilityCheck.java create mode 100644 cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyReqStateInvsInCompsCheck.java create mode 100644 cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlySimpleAssignmentsCheck.java create mode 100644 cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyStaticEvalMarkerPredsInLocsCheck.java create mode 100644 cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyVarValueMarkerPredsInCompsCheck.java diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoChannelsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoChannelsCheck.java new file mode 100644 index 000000000..0a02a8b5c --- /dev/null +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoChannelsCheck.java @@ -0,0 +1,26 @@ +////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2010, 2022 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available +// under the terms of the MIT License which is available at +// https://opensource.org/licenses/MIT +// +// SPDX-License-Identifier: MIT +////////////////////////////////////////////////////////////////////////////// + +package org.eclipse.escet.cif.common.checkers; + +import org.eclipse.escet.cif.metamodel.cif.declarations.Event; + +/** CIF check that does not allow channels. */ +public class NoChannelsCheck extends CifCheck { + @Override + protected void preprocessEvent(Event event) { + if (event.getType() != null) { + addViolation(event, "event is a channel (has a data type)"); + } + } +} diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoContinuousVariablesCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoContinuousVariablesCheck.java new file mode 100644 index 000000000..7dbe9ffdf --- /dev/null +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoContinuousVariablesCheck.java @@ -0,0 +1,24 @@ +////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2010, 2022 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available +// under the terms of the MIT License which is available at +// https://opensource.org/licenses/MIT +// +// SPDX-License-Identifier: MIT +////////////////////////////////////////////////////////////////////////////// + +package org.eclipse.escet.cif.common.checkers; + +import org.eclipse.escet.cif.metamodel.cif.declarations.ContVariable; + +/** CIF check that does not allow continuous variables. */ +public class NoContinuousVariablesCheck extends CifCheck { + @Override + protected void preprocessContVariable(ContVariable var) { + addViolation(var, "variable is a continuous variable"); + } +} diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoDiscVarsWithMultiInitValuesCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoDiscVarsWithMultiInitValuesCheck.java new file mode 100644 index 000000000..f2d5c3c21 --- /dev/null +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoDiscVarsWithMultiInitValuesCheck.java @@ -0,0 +1,45 @@ +////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2010, 2022 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available +// under the terms of the MIT License which is available at +// https://opensource.org/licenses/MIT +// +// SPDX-License-Identifier: MIT +////////////////////////////////////////////////////////////////////////////// + +package org.eclipse.escet.cif.common.checkers; + +import static org.eclipse.escet.common.java.Strings.fmt; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.escet.cif.metamodel.cif.ComplexComponent; +import org.eclipse.escet.cif.metamodel.cif.declarations.DiscVariable; + +/** CIF check that does not allow discrete variables with multiple potential initial values. */ +public class NoDiscVarsWithMultiInitValuesCheck extends CifCheck { + @Override + protected void preprocessDiscVariable(DiscVariable var) { + // Ignore discrete variables that represent function parameters or local variables of functions. + EObject parent = var.eContainer(); + if (!(parent instanceof ComplexComponent)) { + return; + } + + // Ignore variables implicit default value. + if (var.getValue() == null) { + return; + } + + // Check number of potential initial values. + int count = var.getValue().getValues().size(); + if (count == 0) { // 0 means 'any' initial value. + addViolation(var, fmt("discrete variable has multiple potential initial values", count)); + } else if (count > 1) { + addViolation(var, fmt("discrete variable has multiple (%d) potential initial values", count)); + } + } +} diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoIfUpdatesOnEdgesCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoIfUpdatesOnEdgesCheck.java new file mode 100644 index 000000000..193a78403 --- /dev/null +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoIfUpdatesOnEdgesCheck.java @@ -0,0 +1,45 @@ +////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2010, 2022 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available +// under the terms of the MIT License which is available at +// https://opensource.org/licenses/MIT +// +// SPDX-License-Identifier: MIT +////////////////////////////////////////////////////////////////////////////// + +package org.eclipse.escet.cif.common.checkers; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.escet.cif.metamodel.cif.automata.Automaton; +import org.eclipse.escet.cif.metamodel.cif.automata.IfUpdate; +import org.eclipse.escet.cif.metamodel.cif.automata.Location; +import org.eclipse.escet.common.java.Assert; + +/** + * CIF check that does not 'if' updates on edges. + * + * @note This check is included in {@link OnlySimpleAssignmentsCheck}. + */ +public class NoIfUpdatesOnEdgesCheck extends CifCheck { + @Override + protected void preprocessIfUpdate(IfUpdate update) { + // Get location. + EObject ancestor = update; + while (!(ancestor instanceof Location)) { + ancestor = ancestor.eContainer(); + } + Assert.check(ancestor instanceof Location); + Location loc = (Location)ancestor; + + // Report violation. + if (loc.getName() != null) { + addViolation(loc, "location has an edge with an 'if' update"); + } else { + addViolation((Automaton)loc.eContainer(), "automaton has an edge with an 'if' update"); + } + } +} diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoInitPredsInCompsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoInitPredsInCompsCheck.java new file mode 100644 index 000000000..f5bd91c67 --- /dev/null +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoInitPredsInCompsCheck.java @@ -0,0 +1,29 @@ +////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2010, 2022 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available +// under the terms of the MIT License which is available at +// https://opensource.org/licenses/MIT +// +// SPDX-License-Identifier: MIT +////////////////////////////////////////////////////////////////////////////// + +package org.eclipse.escet.cif.common.checkers; + +import org.eclipse.escet.cif.metamodel.cif.ComplexComponent; + +/** + * CIF check that does not allow initialization predicates in components, i.e., does not allow initialization predicates + * outside of locations. + */ +public class NoInitPredsInCompsCheck extends CifCheck { + @Override + protected void preprocessComplexComponent(ComplexComponent comp) { + if (!comp.getInitials().isEmpty()) { + addViolation(comp, "component contains an initialization predicate"); + } + } +} diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoInputVariablesCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoInputVariablesCheck.java new file mode 100644 index 000000000..e20806be8 --- /dev/null +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoInputVariablesCheck.java @@ -0,0 +1,24 @@ +////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2010, 2022 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available +// under the terms of the MIT License which is available at +// https://opensource.org/licenses/MIT +// +// SPDX-License-Identifier: MIT +////////////////////////////////////////////////////////////////////////////// + +package org.eclipse.escet.cif.common.checkers; + +import org.eclipse.escet.cif.metamodel.cif.declarations.InputVariable; + +/** CIF check that does not allow input variables. */ +public class NoInputVariablesCheck extends CifCheck { + @Override + protected void preprocessInputVariable(InputVariable var) { + addViolation(var, "variable is an input variable"); + } +} diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoKindlessAutomataCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoKindlessAutomataCheck.java new file mode 100644 index 000000000..9bed87b10 --- /dev/null +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoKindlessAutomataCheck.java @@ -0,0 +1,27 @@ +////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2010, 2022 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available +// under the terms of the MIT License which is available at +// https://opensource.org/licenses/MIT +// +// SPDX-License-Identifier: MIT +////////////////////////////////////////////////////////////////////////////// + +package org.eclipse.escet.cif.common.checkers; + +import org.eclipse.escet.cif.metamodel.cif.SupKind; +import org.eclipse.escet.cif.metamodel.cif.automata.Automaton; + +/** CIF check that does not allow kindless/regular automata. */ +public class NoKindlessAutomataCheck extends CifCheck { + @Override + protected void preprocessAutomaton(Automaton aut) { + if (aut.getKind() == SupKind.NONE) { + addViolation(aut, "automaton is a kindless/regular automaton"); + } + } +} diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoKindlessStateEvtExclInvsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoKindlessStateEvtExclInvsCheck.java new file mode 100644 index 000000000..698b0a104 --- /dev/null +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoKindlessStateEvtExclInvsCheck.java @@ -0,0 +1,53 @@ +////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2010, 2022 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available +// under the terms of the MIT License which is available at +// https://opensource.org/licenses/MIT +// +// SPDX-License-Identifier: MIT +////////////////////////////////////////////////////////////////////////////// + +package org.eclipse.escet.cif.common.checkers; + +import org.eclipse.escet.cif.metamodel.cif.ComplexComponent; +import org.eclipse.escet.cif.metamodel.cif.InvKind; +import org.eclipse.escet.cif.metamodel.cif.Invariant; +import org.eclipse.escet.cif.metamodel.cif.SupKind; +import org.eclipse.escet.cif.metamodel.cif.automata.Automaton; +import org.eclipse.escet.cif.metamodel.cif.automata.Location; + +/** CIF check that does not allow kindless state/event exclusion invariants. */ +public class NoKindlessStateEvtExclInvsCheck extends CifCheck { + @Override + protected void preprocessComplexComponent(ComplexComponent comp) { + for (Invariant inv: comp.getInvariants()) { + if (inv.getInvKind() == InvKind.EVENT_NEEDS || inv.getInvKind() == InvKind.EVENT_DISABLES) { + SupKind supKind = inv.getSupKind(); + if (supKind == SupKind.NONE) { + addViolation(comp, "component has a kindless state/event exclusion invariant"); + } + } + } + } + + @Override + protected void preprocessLocation(Location loc) { + for (Invariant inv: loc.getInvariants()) { + if (inv.getInvKind() == InvKind.EVENT_NEEDS || inv.getInvKind() == InvKind.EVENT_DISABLES) { + SupKind supKind = inv.getSupKind(); + if (supKind == SupKind.NONE) { + if (loc.getName() != null) { + addViolation(loc, "location has a kindless state/event exclusion invariant"); + } else { + addViolation((Automaton)loc.eContainer(), + "automaton has a location with a kindless state/event exclusion invariant"); + } + } + } + } + } +} diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoMultiAssignOnEdgesCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoMultiAssignOnEdgesCheck.java new file mode 100644 index 000000000..c69f149d4 --- /dev/null +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoMultiAssignOnEdgesCheck.java @@ -0,0 +1,49 @@ +////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2010, 2022 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available +// under the terms of the MIT License which is available at +// https://opensource.org/licenses/MIT +// +// SPDX-License-Identifier: MIT +////////////////////////////////////////////////////////////////////////////// + +package org.eclipse.escet.cif.common.checkers; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.escet.cif.metamodel.cif.automata.Assignment; +import org.eclipse.escet.cif.metamodel.cif.automata.Automaton; +import org.eclipse.escet.cif.metamodel.cif.automata.Location; +import org.eclipse.escet.cif.metamodel.cif.expressions.TupleExpression; +import org.eclipse.escet.common.java.Assert; + +/** + * CIF check that does not allow multi-assignments on edges. This check does not disallow multiple assignments on a + * single edge. + * + * @note This check is included in {@link OnlySimpleAssignmentsCheck}. + */ +public class NoMultiAssignOnEdgesCheck extends CifCheck { + @Override + protected void preprocessAssignment(Assignment asgn) { + if (asgn.getAddressable() instanceof TupleExpression) { + // Get location. + EObject ancestor = asgn; + while (!(ancestor instanceof Location)) { + ancestor = ancestor.eContainer(); + } + Assert.check(ancestor instanceof Location); + Location loc = (Location)ancestor; + + // Report violation. + if (loc.getName() != null) { + addViolation(loc, "location has an edge with a multi-assignment"); + } else { + addViolation((Automaton)loc.eContainer(), "automaton has an edge with a multi-assignment"); + } + } + } +} diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoPartialVarAssignOnEdgesCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoPartialVarAssignOnEdgesCheck.java new file mode 100644 index 000000000..7818f7619 --- /dev/null +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoPartialVarAssignOnEdgesCheck.java @@ -0,0 +1,48 @@ +////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2010, 2022 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available +// under the terms of the MIT License which is available at +// https://opensource.org/licenses/MIT +// +// SPDX-License-Identifier: MIT +////////////////////////////////////////////////////////////////////////////// + +package org.eclipse.escet.cif.common.checkers; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.escet.cif.metamodel.cif.automata.Assignment; +import org.eclipse.escet.cif.metamodel.cif.automata.Automaton; +import org.eclipse.escet.cif.metamodel.cif.automata.Location; +import org.eclipse.escet.cif.metamodel.cif.expressions.ProjectionExpression; +import org.eclipse.escet.common.java.Assert; + +/** + * CIF check that does not allow partial variable assignments on edges. + * + * @note This check is included in {@link OnlySimpleAssignmentsCheck}. + */ +public class NoPartialVarAssignOnEdgesCheck extends CifCheck { + @Override + protected void preprocessAssignment(Assignment asgn) { + if (asgn.getAddressable() instanceof ProjectionExpression) { + // Get location. + EObject ancestor = asgn; + while (!(ancestor instanceof Location)) { + ancestor = ancestor.eContainer(); + } + Assert.check(ancestor instanceof Location); + Location loc = (Location)ancestor; + + // Report violation. + if (loc.getName() != null) { + addViolation(loc, "location has an edge with a partial variable assignment"); + } else { + addViolation((Automaton)loc.eContainer(), "automaton has an edge with a partial variable assignment"); + } + } + } +} diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificBinaryExprsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificBinaryExprsCheck.java new file mode 100644 index 000000000..5f1e9c894 --- /dev/null +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificBinaryExprsCheck.java @@ -0,0 +1,502 @@ +////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2010, 2022 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available +// under the terms of the MIT License which is available at +// https://opensource.org/licenses/MIT +// +// SPDX-License-Identifier: MIT +////////////////////////////////////////////////////////////////////////////// + +package org.eclipse.escet.cif.common.checkers; + +import static org.eclipse.escet.cif.common.CifTextUtils.exprToStr; +import static org.eclipse.escet.cif.common.CifTextUtils.getNamedAncestorOrSelf; +import static org.eclipse.escet.cif.common.CifTextUtils.operatorToStr; +import static org.eclipse.escet.common.java.Strings.fmt; + +import org.eclipse.escet.cif.common.CifTypeUtils; +import org.eclipse.escet.cif.metamodel.cif.expressions.BinaryExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.BinaryOperator; +import org.eclipse.escet.cif.metamodel.cif.types.CifType; +import org.eclipse.escet.cif.metamodel.cif.types.DictType; +import org.eclipse.escet.cif.metamodel.cif.types.IntType; +import org.eclipse.escet.cif.metamodel.cif.types.ListType; +import org.eclipse.escet.cif.metamodel.cif.types.RealType; +import org.eclipse.escet.cif.metamodel.cif.types.SetType; +import org.eclipse.escet.cif.metamodel.cif.types.StringType; + +/** CIF check that does not allow certain binary expressions. */ +public class NoSpecificBinaryExprsCheck extends CifCheck { + /** Whether to disallow {@link BinaryOperator#ADDITION}. */ + public boolean disallowAddition; + + /** Whether to disallow {@link BinaryOperator#ADDITION} on rangeless integers. */ + public boolean disallowAdditionIntsRangeless; + + /** Whether to disallow {@link BinaryOperator#ADDITION} on reals. */ + public boolean disallowAdditionReals; + + /** Whether to disallow {@link BinaryOperator#ADDITION} on lists. */ + public boolean disallowAdditionLists; + + /** Whether to disallow {@link BinaryOperator#ADDITION} on strings. */ + public boolean disallowAdditionStrings; + + /** Whether to disallow {@link BinaryOperator#ADDITION} on dictionaries. */ + public boolean disallowAdditionDicts; + + /** Whether to disallow {@link BinaryOperator#BI_CONDITIONAL}. */ + public boolean disallowBiconditional; + + /** Whether to disallow {@link BinaryOperator#CONJUNCTION}. */ + public boolean disallowConjunction; + + /** Whether to disallow {@link BinaryOperator#CONJUNCTION} on sets. */ + public boolean disallowConjunctionSets; + + /** Whether to disallow {@link BinaryOperator#DISJUNCTION}. */ + public boolean disallowDisjunction; + + /** Whether to disallow {@link BinaryOperator#DISJUNCTION} on sets. */ + public boolean disallowDisjunctionSets; + + /** Whether to disallow {@link BinaryOperator#DIVISION}. */ + public boolean disallowDivision; + + /** Whether to disallow {@link BinaryOperator#ELEMENT_OF}. */ + public boolean disallowElementOf; + + /** Whether to disallow {@link BinaryOperator#ELEMENT_OF} on lists. */ + public boolean disallowElementOfLists; + + /** Whether to disallow {@link BinaryOperator#ELEMENT_OF} on sets. */ + public boolean disallowElementOfSets; + + /** Whether to disallow {@link BinaryOperator#ELEMENT_OF} on dictionaries. */ + public boolean disallowElementOfDicts; + + /** Whether to disallow {@link BinaryOperator#EQUAL}. */ + public boolean disallowEqual; + + /** Whether to disallow {@link BinaryOperator#GREATER_EQUAL}. */ + public boolean disallowGreaterEqual; + + /** Whether to disallow {@link BinaryOperator#GREATER_EQUAL} on rangeless integers. */ + public boolean disallowGreaterEqualIntsRangeless; + + /** Whether to disallow {@link BinaryOperator#GREATER_EQUAL} on reals. */ + public boolean disallowGreaterEqualReals; + + /** Whether to disallow {@link BinaryOperator#GREATER_THAN}. */ + public boolean disallowGreaterThan; + + /** Whether to disallow {@link BinaryOperator#GREATER_THAN} on rangeless integers. */ + public boolean disallowGreaterThanIntsRangeless; + + /** Whether to disallow {@link BinaryOperator#GREATER_THAN} on reals. */ + public boolean disallowGreaterThanReals; + + /** Whether to disallow {@link BinaryOperator#IMPLICATION}. */ + public boolean disallowImplication; + + /** Whether to disallow {@link BinaryOperator#INTEGER_DIVISION}. */ + public boolean disallowIntegerDivision; + + /** Whether to disallow {@link BinaryOperator#INTEGER_DIVISION} on rangeless integers. */ + public boolean disallowIntegerDivisionIntsRangeless; + + /** Whether to disallow {@link BinaryOperator#LESS_EQUAL}. */ + public boolean disallowLessEqual; + + /** Whether to disallow {@link BinaryOperator#LESS_EQUAL} on rangeless integers. */ + public boolean disallowLessEqualIntsRangeless; + + /** Whether to disallow {@link BinaryOperator#LESS_EQUAL} on reals. */ + public boolean disallowLessEqualReals; + + /** Whether to disallow {@link BinaryOperator#LESS_THAN}. */ + public boolean disallowLessThan; + + /** Whether to disallow {@link BinaryOperator#LESS_THAN} on rangeless integers. */ + public boolean disallowLessThanIntsRangeless; + + /** Whether to disallow {@link BinaryOperator#LESS_THAN} on reals. */ + public boolean disallowLessThanReals; + + /** Whether to disallow {@link BinaryOperator#MODULUS}. */ + public boolean disallowModulus; + + /** Whether to disallow {@link BinaryOperator#MODULUS} on rangeless integers. */ + public boolean disallowModulusIntsRangeless; + + /** Whether to disallow {@link BinaryOperator#MULTIPLICATION}. */ + public boolean disallowMultiplication; + + /** Whether to disallow {@link BinaryOperator#MULTIPLICATION} on rangeless integers. */ + public boolean disallowMultiplicationIntsRangeless; + + /** Whether to disallow {@link BinaryOperator#MULTIPLICATION} on reals. */ + public boolean disallowMultiplicationReals; + + /** Whether to disallow {@link BinaryOperator#SUBSET}. */ + public boolean disallowSubset; + + /** Whether to disallow {@link BinaryOperator#SUBTRACTION}. */ + public boolean disallowSubtraction; + + /** Whether to disallow {@link BinaryOperator#SUBTRACTION} on rangeless integers. */ + public boolean disallowSubtractionIntsRangeless; + + /** Whether to disallow {@link BinaryOperator#SUBTRACTION} on reals. */ + public boolean disallowSubtractionReals; + + /** Whether to disallow {@link BinaryOperator#SUBTRACTION} on lists. */ + public boolean disallowSubtractionLists; + + /** Whether to disallow {@link BinaryOperator#SUBTRACTION} on sets. */ + public boolean disallowSubtractionSets; + + /** Whether to disallow {@link BinaryOperator#SUBTRACTION} on dictionaries. */ + public boolean disallowSubtractionDicts; + + /** Whether to disallow {@link BinaryOperator#UNEQUAL}. */ + public boolean disallowUnequal; + + @Override + protected void preprocessBinaryExpression(BinaryExpression binExpr) { + BinaryOperator op = binExpr.getOperator(); + switch (op) { + case ADDITION: + if (disallowAddition) { + addExprViolationOperator(binExpr); + } else { + if (disallowAdditionIntsRangeless) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) + { + addExprViolationOperand(binExpr); + } + } + if (disallowAdditionReals) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if (ltype instanceof RealType || rtype instanceof RealType) { + addExprViolationOperand(binExpr); + } + } + if (disallowAdditionLists) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if (ltype instanceof ListType || rtype instanceof ListType) { + addExprViolationOperand(binExpr); + } + } + if (disallowAdditionStrings) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if (ltype instanceof StringType || rtype instanceof StringType) { + addExprViolationOperand(binExpr); + } + } + if (disallowAdditionDicts) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if (ltype instanceof DictType || rtype instanceof DictType) { + addExprViolationOperand(binExpr); + } + } + } + break; + case BI_CONDITIONAL: + if (disallowBiconditional) { + addExprViolationOperator(binExpr); + } + break; + case CONJUNCTION: + if (disallowConjunction) { + addExprViolationOperator(binExpr); + } else if (disallowConjunctionSets) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if (ltype instanceof SetType || rtype instanceof SetType) { + addExprViolationOperand(binExpr); + } + } + break; + case DISJUNCTION: + if (disallowDisjunction) { + addExprViolationOperator(binExpr); + } else if (disallowDisjunctionSets) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if (ltype instanceof SetType || rtype instanceof SetType) { + addExprViolationOperand(binExpr); + } + } + break; + case DIVISION: + if (disallowDivision) { + addExprViolationOperator(binExpr); + } + break; + case ELEMENT_OF: + if (disallowElementOf) { + addExprViolationOperator(binExpr); + } else { + if (disallowElementOfLists) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if (ltype instanceof ListType || rtype instanceof ListType) { + addExprViolationOperand(binExpr); + } + } + if (disallowElementOfSets) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if (ltype instanceof SetType || rtype instanceof SetType) { + addExprViolationOperand(binExpr); + } + } + if (disallowElementOfDicts) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if (ltype instanceof DictType || rtype instanceof DictType) { + addExprViolationOperand(binExpr); + } + } + } + break; + case EQUAL: + if (disallowEqual) { + addExprViolationOperator(binExpr); + } + break; + case GREATER_EQUAL: + if (disallowGreaterEqual) { + addExprViolationOperator(binExpr); + } else { + if (disallowGreaterEqualIntsRangeless) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) + { + addExprViolationOperand(binExpr); + } + } + if (disallowGreaterEqualReals) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if (ltype instanceof RealType || rtype instanceof RealType) { + addExprViolationOperand(binExpr); + } + } + } + break; + case GREATER_THAN: + if (disallowGreaterThan) { + addExprViolationOperator(binExpr); + } else { + if (disallowGreaterThanIntsRangeless) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) + { + addExprViolationOperand(binExpr); + } + } + if (disallowGreaterThanReals) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if (ltype instanceof RealType || rtype instanceof RealType) { + addExprViolationOperand(binExpr); + } + } + } + break; + case IMPLICATION: + if (disallowImplication) { + addExprViolationOperator(binExpr); + } + break; + case INTEGER_DIVISION: + if (disallowIntegerDivision) { + addExprViolationOperator(binExpr); + } else { + if (disallowIntegerDivisionIntsRangeless) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) + { + addExprViolationOperand(binExpr); + } + } + } + break; + case LESS_EQUAL: + if (disallowLessEqual) { + addExprViolationOperator(binExpr); + } else { + if (disallowLessEqualIntsRangeless) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) + { + addExprViolationOperand(binExpr); + } + } + if (disallowLessEqualReals) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if (ltype instanceof RealType || rtype instanceof RealType) { + addExprViolationOperand(binExpr); + } + } + } + break; + case LESS_THAN: + if (disallowLessThan) { + addExprViolationOperator(binExpr); + } else { + if (disallowLessThanIntsRangeless) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) + { + addExprViolationOperand(binExpr); + } + } + if (disallowLessThanReals) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if (ltype instanceof RealType || rtype instanceof RealType) { + addExprViolationOperand(binExpr); + } + } + } + break; + case MODULUS: + if (disallowModulus) { + addExprViolationOperator(binExpr); + } else { + if (disallowModulusIntsRangeless) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) + { + addExprViolationOperand(binExpr); + } + } + } + break; + case MULTIPLICATION: + if (disallowMultiplication) { + addExprViolationOperator(binExpr); + } else { + if (disallowMultiplicationIntsRangeless) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) + { + addExprViolationOperand(binExpr); + } + } + if (disallowMultiplicationReals) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if (ltype instanceof RealType || rtype instanceof RealType) { + addExprViolationOperand(binExpr); + } + } + } + break; + case SUBSET: + if (disallowSubset) { + addExprViolationOperator(binExpr); + } + break; + case SUBTRACTION: + if (disallowSubtraction) { + addExprViolationOperator(binExpr); + } else { + if (disallowSubtractionIntsRangeless) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) + { + addExprViolationOperand(binExpr); + } + } + if (disallowSubtractionReals) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if (ltype instanceof RealType || rtype instanceof RealType) { + addExprViolationOperand(binExpr); + } + } + if (disallowSubtractionLists) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if (ltype instanceof ListType || rtype instanceof ListType) { + addExprViolationOperand(binExpr); + } + } + if (disallowSubtractionSets) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if (ltype instanceof SetType || rtype instanceof SetType) { + addExprViolationOperand(binExpr); + } + } + if (disallowSubtractionDicts) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if (ltype instanceof DictType || rtype instanceof DictType) { + addExprViolationOperand(binExpr); + } + } + } + break; + case UNEQUAL: + if (disallowUnequal) { + addExprViolationOperator(binExpr); + } + break; + default: + throw new RuntimeException("Unknown binary operator: " + op); + } + } + + /** + * Add a violation for the operator of the given binary expression. + * + * @param binExpr The binary expression. + */ + private void addExprViolationOperator(BinaryExpression binExpr) { + super.addViolation(getNamedAncestorOrSelf(binExpr), + fmt("binary operator \"%s\": \"%s\"", operatorToStr(binExpr.getOperator()), exprToStr(binExpr))); + } + + /** + * Add a violation for an operand of the the given binary expression. + * + * @param binExpr The binary expression. + */ + private void addExprViolationOperand(BinaryExpression binExpr) { + super.addViolation(getNamedAncestorOrSelf(binExpr), fmt("binary operator \"%s\" on operands \"%s\" and \"%s\"", + operatorToStr(binExpr.getOperator()), exprToStr(binExpr.getLeft()), exprToStr(binExpr.getRight()))); + } +} diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificExprsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificExprsCheck.java new file mode 100644 index 000000000..ee5432bb7 --- /dev/null +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificExprsCheck.java @@ -0,0 +1,500 @@ +////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2010, 2022 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available +// under the terms of the MIT License which is available at +// https://opensource.org/licenses/MIT +// +// SPDX-License-Identifier: MIT +////////////////////////////////////////////////////////////////////////////// + +package org.eclipse.escet.cif.common.checkers; + +import static org.eclipse.escet.cif.common.CifTextUtils.exprToStr; +import static org.eclipse.escet.cif.common.CifTextUtils.getNamedAncestorOrSelf; +import static org.eclipse.escet.common.java.Strings.fmt; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.escet.cif.common.CifTypeUtils; +import org.eclipse.escet.cif.common.RangeCompat; +import org.eclipse.escet.cif.metamodel.cif.ComplexComponent; +import org.eclipse.escet.cif.metamodel.cif.expressions.AlgVariableExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.BinaryExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.BoolExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.CastExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.CompParamExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.ComponentExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.ConstantExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.ContVariableExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.DictExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.DiscVariableExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.EnumLiteralExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.Expression; +import org.eclipse.escet.cif.metamodel.cif.expressions.FieldExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.FunctionCallExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.FunctionExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.IfExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.InputVariableExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.IntExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.ListExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.LocationExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.ProjectionExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.RealExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.ReceivedExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.SelfExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.SetExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.SliceExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.StdLibFunctionExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.StringExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.SwitchExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.TimeExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.TupleExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.UnaryExpression; +import org.eclipse.escet.cif.metamodel.cif.functions.ExternalFunction; +import org.eclipse.escet.cif.metamodel.cif.functions.FunctionParameter; +import org.eclipse.escet.cif.metamodel.cif.functions.InternalFunction; +import org.eclipse.escet.cif.metamodel.cif.types.CifType; +import org.eclipse.escet.cif.metamodel.cif.types.DictType; +import org.eclipse.escet.cif.metamodel.cif.types.IntType; +import org.eclipse.escet.cif.metamodel.cif.types.ListType; +import org.eclipse.escet.cif.metamodel.cif.types.StringType; +import org.eclipse.escet.cif.metamodel.cif.types.TupleType; +import org.eclipse.escet.common.position.metamodel.position.PositionObject; + +/** CIF check that does not allow certain expressions. */ +public class NoSpecificExprsCheck extends CifCheck { + /** Whether to disallow references to algebraic variables. */ + public boolean disallowAlgVarRefs; + + /** Whether to disallow references to all functions (user-defined and standard library ones). */ + public boolean disallowFuncRefs; + + /** Whether to disallow references to all user-defined functions (internal and external ones). */ + public boolean disallowFuncRefsUserDef; + + /** Whether to disallow references to internal user-defined functions. */ + public boolean disallowFuncRefsUserDefInt; + + /** Whether to disallow references to external user-defined functions. */ + public boolean disallowFuncRefsUserDefExt; + + /** Whether to disallow references to standard library functions. */ + public boolean disallowFuncRefsStdLib; + + /** Whether to disallow all binary expressions. */ + public boolean disallowBinExprs; + + /** Whether to disallow boolean literals. */ + public boolean disallowBoolLits; + + /** Whether to disallow all cast expressions. */ + public boolean disallowCastExprs; + + /** Whether to disallow cast expressions that cast to a different type. */ + public boolean disallowCastExprsNonEqualType; + + /** Whether to disallow all component references (explicit components and 'self' references). */ + public boolean disallowCompRefs; + + /** Whether to disallow explicit component references. */ + public boolean disallowCompRefsExplicit; + + /** Whether to disallow component 'self' references. */ + public boolean disallowCompRefsSelf; + + /** Whether to disallow component parameter references. */ + public boolean disallowCompParamRefs; + + /** Whether to disallow constant references. */ + public boolean disallowConstRefs; + + /** Whether to disallow continuous variable references. */ + public boolean disallowContVarRefs; + + /** Whether to disallow dictionary literals. */ + public boolean disallowDictLits; + + /** Whether to disallow discrete variable references. */ + public boolean disallowDiscVarRefs; + + /** Whether to disallow user-defined function parameter references. */ + public boolean disallowUserDefFuncParamRefs; + + /** Whether to disallow references to local variables of internal user-defined functions. */ + public boolean disallowIntUserDefFuncLocalVarRefs; + + /** Whether to disallow enumeration literal references. */ + public boolean disallowEnumLitRefs; + + /** Whether to disallow tuple field references. */ + public boolean disallowTupleFieldRefs; + + /** Whether to disallow function calls (for user-defined functions and standard library functions). */ + public boolean disallowFuncCalls; + + /** Whether to disallow 'if' expressions (conditional expressions). */ + public boolean disallowIfExprs; + + /** Whether to disallow input variable references. */ + public boolean disallowInputVarRefs; + + /** Whether to disallow integer number literals. */ + public boolean disallowIntLits; + + /** Whether to disallow list literals. */ + public boolean disallowListLits; + + /** Whether to disallow location references. */ + public boolean disallowLocRefs; + + /** Whether to disallow projection expressions. */ + public boolean disallowProjectionExprs; + + /** Whether to disallow projection expressions on lists. */ + public boolean disallowProjectionExprsLists; + + /** Whether to disallow projection expressions on dictionaries. */ + public boolean disallowProjectionExprsDicts; + + /** Whether to disallow projection expressions on strings. */ + public boolean disallowProjectionExprsStrings; + + /** Whether to disallow projection expressions on tuples. */ + public boolean disallowProjectionExprsTuples; + + /** Whether to disallow projection expressions on tuples using index. */ + public boolean disallowProjectionExprsTuplesIndex; + + /** Whether to disallow projection expressions on tuples using field. */ + public boolean disallowProjectionExprsTuplesField; + + /** Whether to disallow real number expressions. */ + public boolean disallowRealLits; + + /** Whether to disallow received value expressions. */ + public boolean disallowReceiveExprs; + + /** Whether to disallow set literals. */ + public boolean disallowSetLits; + + /** Whether to disallow slice expressions. */ + public boolean disallowSliceExprs; + + /** Whether to disallow string literals. */ + public boolean disallowStringLits; + + /** Whether to disallow switch expressions. */ + public boolean disallowSwitchExprs; + + /** Whether to disallow 'time' variable references. */ + public boolean disallowTimeVarRefs; + + /** Whether to disallow tuple literal expressions. */ + public boolean disallowTupleLits; + + /** Whether to disallow all unary expressions. */ + public boolean disallowUnExprs; + + @Override + protected void preprocessAlgVariableExpression(AlgVariableExpression algRef) { + if (disallowAlgVarRefs) { + addExprViolation(algRef, "algebraic variable reference"); + } + } + + @Override + protected void preprocessFunctionExpression(FunctionExpression userDefFuncRef) { + if ((disallowFuncRefs || disallowFuncRefsUserDef || disallowFuncRefsUserDefInt) + && userDefFuncRef.getFunction() instanceof InternalFunction) + { + addExprViolation(userDefFuncRef, "internal user-defined function reference"); + } + + if ((disallowFuncRefs || disallowFuncRefsUserDef || disallowFuncRefsUserDefExt) + && userDefFuncRef.getFunction() instanceof ExternalFunction) + { + addExprViolation(userDefFuncRef, "external user-defined function reference"); + } + } + + @Override + protected void preprocessStdLibFunctionExpression(StdLibFunctionExpression stdLibRef) { + if (disallowFuncRefs || disallowFuncRefsStdLib) { + addExprViolation(stdLibRef, "standard library function reference"); + } + } + + @Override + protected void preprocessBinaryExpression(BinaryExpression binExpr) { + if (disallowBinExprs) { + addExprViolation(binExpr, "binary expression"); + } + } + + @Override + protected void preprocessBoolExpression(BoolExpression boolLit) { + if (disallowBoolLits) { + addExprViolation(boolLit, "boolean literal"); + } + } + + @Override + protected void preprocessCastExpression(CastExpression castExpr) { + if (disallowCastExprs) { + addExprViolation(castExpr, "cast expression"); + } else if (disallowCastExprsNonEqualType) { + CifType ctype = castExpr.getChild().getType(); + CifType rtype = castExpr.getType(); + if (CifTypeUtils.checkTypeCompat(ctype, rtype, RangeCompat.EQUAL)) { + // Ignore casting to the child type. + return; + } + addExprViolation(castExpr, "type-changing cast expression"); + } + } + + @Override + protected void preprocessComponentExpression(ComponentExpression compRef) { + if (disallowCompRefs || disallowCompRefsExplicit) { + addExprViolation(compRef, "component reference"); + } + } + + @Override + protected void preprocessCompParamExpression(CompParamExpression compParamRef) { + if (disallowCompParamRefs) { + addExprViolation(compParamRef, "component parameter reference"); + } + } + + @Override + protected void preprocessConstantExpression(ConstantExpression constRef) { + if (disallowConstRefs) { + addExprViolation(constRef, "constant reference"); + } + } + + @Override + protected void preprocessContVariableExpression(ContVariableExpression contRef) { + if (disallowContVarRefs) { + addExprViolation(contRef, "continuous variable reference"); + } + } + + @Override + protected void preprocessDictExpression(DictExpression dictLit) { + if (disallowDictLits) { + addExprViolation(dictLit, "dictionary literal"); + } + } + + @Override + protected void preprocessDiscVariableExpression(DiscVariableExpression discRef) { + EObject parent = discRef.getVariable().eContainer(); + if (parent instanceof ComplexComponent) { + if (disallowDiscVarRefs) { + addExprViolation(discRef, "discrete variable reference"); + } + } else if (parent instanceof FunctionParameter) { + if (disallowUserDefFuncParamRefs) { + addExprViolation(discRef, "user-defined function parameter reference"); + } + } else if (parent instanceof InternalFunction) { + if (disallowIntUserDefFuncLocalVarRefs) { + addExprViolation(discRef, "internal user-defined function local variable reference"); + } + } else { + throw new RuntimeException("Unexpected disc var parent: " + parent); + } + } + + @Override + protected void preprocessEnumLiteralExpression(EnumLiteralExpression enumLitRef) { + if (disallowEnumLitRefs) { + addExprViolation(enumLitRef, "enumeration literal reference"); + } + } + + @Override + protected void preprocessFieldExpression(FieldExpression fieldRef) { + if (disallowTupleFieldRefs) { + addExprViolation(fieldRef, "tuple field reference"); + } + } + + @Override + protected void preprocessFunctionCallExpression(FunctionCallExpression funcCall) { + if (disallowFuncCalls) { + addExprViolation(funcCall, "function call"); + } + } + + @Override + protected void preprocessIfExpression(IfExpression ifExpr) { + if (disallowIfExprs) { + addExprViolation(ifExpr, "conditional expression"); + } + } + + @Override + protected void preprocessInputVariableExpression(InputVariableExpression inputRef) { + if (disallowInputVarRefs) { + addExprViolation(inputRef, "input variable reference"); + } + } + + @Override + protected void preprocessIntExpression(IntExpression intLit) { + if (disallowIntLits) { + addExprViolation(intLit, "integer number literal"); + } + } + + @Override + protected void preprocessListExpression(ListExpression listLit) { + if (disallowListLits) { + addExprViolation(listLit, "list literal"); + } + } + + @Override + protected void preprocessLocationExpression(LocationExpression locRef) { + if (disallowLocRefs) { + addExprViolation(locRef, "location reference"); + } + } + + @Override + protected void preprocessProjectionExpression(ProjectionExpression projExpr) { + if (disallowProjectionExprs) { + addExprViolation(projExpr, "projection expression"); + } else { + if (disallowProjectionExprsLists) { + CifType ctype = CifTypeUtils.normalizeType(projExpr.getChild().getType()); + if (ctype instanceof ListType) { + addExprViolation(projExpr, "list projection expression"); + } + } + if (disallowProjectionExprsDicts) { + CifType ctype = CifTypeUtils.normalizeType(projExpr.getChild().getType()); + if (ctype instanceof DictType) { + addExprViolation(projExpr, "dictionary projection expression"); + } + } + if (disallowProjectionExprsStrings) { + CifType ctype = CifTypeUtils.normalizeType(projExpr.getChild().getType()); + if (ctype instanceof StringType) { + addExprViolation(projExpr, "string projection expression"); + } + } + if (disallowProjectionExprsTuples) { + CifType ctype = CifTypeUtils.normalizeType(projExpr.getChild().getType()); + if (ctype instanceof TupleType) { + addExprViolation(projExpr, "tuple projection expression"); + } + } else { + if (disallowProjectionExprsTuplesIndex) { + CifType ctype = CifTypeUtils.normalizeType(projExpr.getChild().getType()); + CifType itype = CifTypeUtils.normalizeType(projExpr.getIndex().getType()); + if (ctype instanceof TupleType && itype instanceof IntType) { + addExprViolation(projExpr, "tuple index-projection expression"); + } + } + if (disallowProjectionExprsTuplesField) { + CifType ctype = CifTypeUtils.normalizeType(projExpr.getChild().getType()); + if (ctype instanceof TupleType && projExpr.getIndex() instanceof FieldExpression) { + addExprViolation(projExpr, "tuple field-projection expression"); + } + } + } + } + } + + @Override + protected void preprocessRealExpression(RealExpression realLit) { + if (disallowRealLits) { + addExprViolation(realLit, "real number literal"); + } + } + + @Override + protected void preprocessReceivedExpression(ReceivedExpression receivedExpr) { + if (disallowReceiveExprs) { + addExprViolation(receivedExpr, "received value expression"); + } + } + + @Override + protected void preprocessSelfExpression(SelfExpression selfRef) { + if (disallowCompRefs || disallowCompRefsSelf) { + addExprViolation(selfRef, "component reference"); + } + } + + @Override + protected void preprocessSetExpression(SetExpression setLit) { + if (disallowSetLits) { + addExprViolation(setLit, "set literal"); + } + } + + @Override + protected void preprocessSliceExpression(SliceExpression sliceExpr) { + if (disallowSliceExprs) { + addExprViolation(sliceExpr, "slice expression"); + } + } + + @Override + protected void preprocessStringExpression(StringExpression stringLit) { + if (disallowStringLits) { + addExprViolation(stringLit, "string literal"); + } + } + + @Override + protected void preprocessSwitchExpression(SwitchExpression switchExpr) { + if (disallowSwitchExprs) { + addExprViolation(switchExpr, "switch expression"); + } + } + + @Override + protected void preprocessTimeExpression(TimeExpression timeRef) { + if (disallowTimeVarRefs) { + addExprViolation(timeRef, "time variable reference"); + } + } + + @Override + protected void preprocessTupleExpression(TupleExpression tupleLit) { + if (disallowTupleLits) { + addExprViolation(tupleLit, "tuple literal"); + } + } + + @Override + protected void preprocessUnaryExpression(UnaryExpression unExpr) { + if (disallowUnExprs) { + addExprViolation(unExpr, "unary expression"); + } + } + + @Override + protected void addViolation(PositionObject exprObj, String message) { + throw new UnsupportedOperationException(); // Use addExprViolation. + } + + /** + * Add a violation for the given expression. + * + * @param expr The expression. + * @param description The description of the expression. + */ + private void addExprViolation(Expression expr, String description) { + super.addViolation(getNamedAncestorOrSelf(expr), fmt("%s \"%s\"", description, exprToStr(expr))); + } +} diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificTypesCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificTypesCheck.java new file mode 100644 index 000000000..ad894702d --- /dev/null +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificTypesCheck.java @@ -0,0 +1,193 @@ +////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2010, 2022 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available +// under the terms of the MIT License which is available at +// https://opensource.org/licenses/MIT +// +// SPDX-License-Identifier: MIT +////////////////////////////////////////////////////////////////////////////// + +package org.eclipse.escet.cif.common.checkers; + +import static org.eclipse.escet.cif.common.CifTextUtils.getNamedAncestorOrSelf; +import static org.eclipse.escet.cif.common.CifTextUtils.typeToStr; +import static org.eclipse.escet.common.java.Strings.fmt; + +import org.eclipse.escet.cif.common.CifTypeUtils; +import org.eclipse.escet.cif.metamodel.cif.types.CifType; +import org.eclipse.escet.cif.metamodel.cif.types.ComponentDefType; +import org.eclipse.escet.cif.metamodel.cif.types.ComponentType; +import org.eclipse.escet.cif.metamodel.cif.types.DictType; +import org.eclipse.escet.cif.metamodel.cif.types.DistType; +import org.eclipse.escet.cif.metamodel.cif.types.EnumType; +import org.eclipse.escet.cif.metamodel.cif.types.FuncType; +import org.eclipse.escet.cif.metamodel.cif.types.IntType; +import org.eclipse.escet.cif.metamodel.cif.types.ListType; +import org.eclipse.escet.cif.metamodel.cif.types.RealType; +import org.eclipse.escet.cif.metamodel.cif.types.SetType; +import org.eclipse.escet.cif.metamodel.cif.types.StringType; +import org.eclipse.escet.cif.metamodel.cif.types.TupleType; +import org.eclipse.escet.cif.metamodel.cif.types.VoidType; +import org.eclipse.escet.common.position.metamodel.position.PositionObject; + +/** CIF check that does not allow certain types. */ +public class NoSpecificTypesCheck extends CifCheck { + /** Whether to disallow component definition types. */ + public boolean disallowCompDefTypes; + + /** Whether to disallow component types. */ + public boolean disallowCompTypes; + + /** Whether to disallow dictionary types. */ + public boolean disallowDictTypes; + + /** Whether to disallow distribution types. */ + public boolean disallowDistTypes; + + /** Whether to disallow enumeration types. */ + public boolean disallowEnumTypes; + + /** Whether to disallow function types. Note that this includes standard library function types. */ + public boolean disallowFuncTypes; + + /** Whether to disallow all integer types (ranged and rangeless ones). */ + public boolean disallowIntTypes; + + /** Whether to disallow rangeless integer types. */ + public boolean disallowIntTypesRangeless; + + /** Whether to disallow all list types (array and non-array ones). */ + public boolean disallowListTypes; + + /** Whether to disallow non-array list types. */ + public boolean disallowListTypesNonArray; + + /** Whether to disallow real types. */ + public boolean disallowRealTypes; + + /** Whether to disallow set types. */ + public boolean disallowSetTypes; + + /** Whether to disallow string types. */ + public boolean disallowStringTypes; + + /** Whether to disallow tuple types. Note that tuple types are also used for multi-assignments. */ + public boolean disallowTupleTypes; + + /** Whether to disallow void types (of channels). */ + public boolean disallowVoidTypes; + + @Override + protected void preprocessComponentDefType(ComponentDefType compDefType) { + if (disallowCompDefTypes) { + addTypeViolation(compDefType, "component definition type"); + } + } + + @Override + protected void preprocessComponentType(ComponentType compType) { + if (disallowCompTypes) { + addTypeViolation(compType, "component type"); + } + } + + @Override + protected void preprocessDictType(DictType dictType) { + if (disallowDictTypes) { + addTypeViolation(dictType, "dictionary type"); + } + } + + @Override + protected void preprocessDistType(DistType distType) { + if (disallowDistTypes) { + addTypeViolation(distType, "distribution type"); + } + } + + @Override + protected void preprocessEnumType(EnumType enumType) { + if (disallowEnumTypes) { + addTypeViolation(enumType, "enumeration type"); + } + } + + @Override + protected void preprocessFuncType(FuncType funcType) { + if (disallowFuncTypes) { + addTypeViolation(funcType, "function type"); + } + } + + @Override + protected void preprocessIntType(IntType intType) { + if (disallowIntTypes) { + addTypeViolation(intType, "integer type"); + } else if (disallowIntTypesRangeless && CifTypeUtils.isRangeless(intType)) { + addTypeViolation(intType, "rangeless integer type"); + } + } + + @Override + protected void preprocessListType(ListType listType) { + if (disallowListTypes) { + addTypeViolation(listType, "list type"); + } else if (disallowListTypesNonArray && !CifTypeUtils.isArrayType(listType)) { + addTypeViolation(listType, "non-array list type"); + } + } + + @Override + protected void preprocessRealType(RealType realType) { + if (disallowRealTypes) { + addTypeViolation(realType, "real type"); + } + } + + @Override + protected void preprocessSetType(SetType setType) { + if (disallowSetTypes) { + addTypeViolation(setType, "set type"); + } + } + + @Override + protected void preprocessStringType(StringType stringType) { + if (disallowStringTypes) { + addTypeViolation(stringType, "string type"); + } + } + + @Override + protected void preprocessTupleType(TupleType tupleType) { + if (disallowTupleTypes) { + addTypeViolation(tupleType, "tuple type"); + } + } + + @Override + protected void preprocessVoidType(VoidType voidType) { + if (disallowVoidTypes) { + addTypeViolation(voidType, "void type"); + } + } + + @Override + protected void addViolation(PositionObject typeObj, String message) { + throw new UnsupportedOperationException(); // Use addTypeViolation. + } + + /** + * Add a violation for the given type. + * + * @param type The type. + * @param description The description of the type. + */ + private void addTypeViolation(CifType type, String description) { + super.addViolation(getNamedAncestorOrSelf(type), fmt("%s \"%s\"", description, typeToStr(type))); + } +} diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificUnaryExprsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificUnaryExprsCheck.java new file mode 100644 index 000000000..0868d45b3 --- /dev/null +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificUnaryExprsCheck.java @@ -0,0 +1,144 @@ +////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2010, 2022 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available +// under the terms of the MIT License which is available at +// https://opensource.org/licenses/MIT +// +// SPDX-License-Identifier: MIT +////////////////////////////////////////////////////////////////////////////// + +package org.eclipse.escet.cif.common.checkers; + +import static org.eclipse.escet.cif.common.CifTextUtils.exprToStr; +import static org.eclipse.escet.cif.common.CifTextUtils.getNamedAncestorOrSelf; +import static org.eclipse.escet.cif.common.CifTextUtils.operatorToStr; +import static org.eclipse.escet.common.java.Strings.fmt; + +import org.eclipse.escet.cif.common.CifTypeUtils; +import org.eclipse.escet.cif.metamodel.cif.expressions.UnaryExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.UnaryOperator; +import org.eclipse.escet.cif.metamodel.cif.types.CifType; +import org.eclipse.escet.cif.metamodel.cif.types.IntType; +import org.eclipse.escet.cif.metamodel.cif.types.RealType; + +/** CIF check that does not allow certain unary expressions. */ +public class NoSpecificUnaryExprsCheck extends CifCheck { + /** Whether to disallow {@link UnaryOperator#INVERSE}. */ + public boolean disallowInverse; + + /** Whether to disallow {@link UnaryOperator#NEGATE}. */ + public boolean disallowNegate; + + /** Whether to disallow {@link UnaryOperator#NEGATE} on integer numbers. */ + public boolean disallowNegateInts; + + /** Whether to disallow {@link UnaryOperator#NEGATE} on rangeless integer numbers. */ + public boolean disallowNegateIntsRangeless; + + /** Whether to disallow {@link UnaryOperator#NEGATE} on real numbers. */ + public boolean disallowNegateReals; + + /** Whether to disallow {@link UnaryOperator#PLUS}. */ + public boolean disallowPlus; + + /** Whether to disallow {@link UnaryOperator#PLUS} on integer numbers. */ + public boolean disallowPlusInts; + + /** Whether to disallow {@link UnaryOperator#PLUS} on rangeless integer numbers. */ + public boolean disallowPlusIntsRangeless; + + /** Whether to disallow {@link UnaryOperator#PLUS} on real numbers. */ + public boolean disallowPlusReals; + + /** Whether to disallow {@link UnaryOperator#SAMPLE}. */ + public boolean disallowSample; + + @Override + protected void preprocessUnaryExpression(UnaryExpression unExpr) { + UnaryOperator op = unExpr.getOperator(); + switch (op) { + case INVERSE: + if (disallowInverse) { + addExprViolationOperator(unExpr); + } + break; + case NEGATE: + if (disallowNegate) { + addExprViolationOperator(unExpr); + } else { + if (disallowNegateInts) { + CifType ctype = CifTypeUtils.normalizeType(unExpr.getChild().getType()); + if (ctype instanceof IntType) { + addExprViolationOperand(unExpr); + } + } else if (disallowNegateIntsRangeless) { + CifType ctype = CifTypeUtils.normalizeType(unExpr.getChild().getType()); + if (ctype instanceof IntType && CifTypeUtils.isRangeless((IntType)ctype)) { + addExprViolationOperand(unExpr); + } + } + if (disallowNegateReals) { + CifType ctype = CifTypeUtils.normalizeType(unExpr.getChild().getType()); + if (ctype instanceof RealType) { + addExprViolationOperand(unExpr); + } + } + } + break; + case PLUS: + if (disallowPlus) { + addExprViolationOperator(unExpr); + } else { + if (disallowPlusInts) { + CifType ctype = CifTypeUtils.normalizeType(unExpr.getChild().getType()); + if (ctype instanceof IntType) { + addExprViolationOperand(unExpr); + } + } else if (disallowPlusIntsRangeless) { + CifType ctype = CifTypeUtils.normalizeType(unExpr.getChild().getType()); + if (ctype instanceof IntType && CifTypeUtils.isRangeless((IntType)ctype)) { + addExprViolationOperand(unExpr); + } + } + if (disallowPlusReals) { + CifType ctype = CifTypeUtils.normalizeType(unExpr.getChild().getType()); + if (ctype instanceof RealType) { + addExprViolationOperand(unExpr); + } + } + } + break; + case SAMPLE: + if (disallowSample) { + addExprViolationOperator(unExpr); + } + break; + default: + throw new RuntimeException("Unknown unary operator: " + op); + } + } + + /** + * Add a violation for the operator of the given unary expression. + * + * @param unExpr The unary expression. + */ + private void addExprViolationOperator(UnaryExpression unExpr) { + super.addViolation(getNamedAncestorOrSelf(unExpr), + fmt("unary operator \"%s\": \"%s\"", operatorToStr(unExpr.getOperator()), exprToStr(unExpr))); + } + + /** + * Add a violation for an operand of the the given unary expression. + * + * @param unExpr The unary expression. + */ + private void addExprViolationOperand(UnaryExpression unExpr) { + super.addViolation(getNamedAncestorOrSelf(unExpr), fmt("unary operator \"%s\" on operand \"%s\"", + operatorToStr(unExpr.getOperator()), exprToStr(unExpr.getChild()))); + } +} diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoStateInvsInLocsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoStateInvsInLocsCheck.java new file mode 100644 index 000000000..bf99d6d30 --- /dev/null +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoStateInvsInLocsCheck.java @@ -0,0 +1,44 @@ +////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2010, 2022 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available +// under the terms of the MIT License which is available at +// https://opensource.org/licenses/MIT +// +// SPDX-License-Identifier: MIT +////////////////////////////////////////////////////////////////////////////// + +package org.eclipse.escet.cif.common.checkers; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.escet.cif.metamodel.cif.InvKind; +import org.eclipse.escet.cif.metamodel.cif.Invariant; +import org.eclipse.escet.cif.metamodel.cif.LocationParameter; +import org.eclipse.escet.cif.metamodel.cif.automata.Automaton; +import org.eclipse.escet.cif.metamodel.cif.automata.Location; + +/** CIF check that does not allow state invariants in locations. */ +public class NoStateInvsInLocsCheck extends CifCheck { + @Override + protected void preprocessLocation(Location loc) { + // Skip location parameters. + EObject parent = loc.eContainer(); + if (parent instanceof LocationParameter) { + return; + } + + // Check for violation. + for (Invariant inv: loc.getInvariants()) { + if (inv.getInvKind() == InvKind.STATE) { + if (loc.getName() != null) { + addViolation(loc, "location has a state invariant"); + } else { + addViolation((Automaton)loc.eContainer(), "automaton has a location with a state invariant"); + } + } + } + } +} diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoTauCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoTauCheck.java new file mode 100644 index 000000000..66e23d381 --- /dev/null +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoTauCheck.java @@ -0,0 +1,54 @@ +////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2010, 2022 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available +// under the terms of the MIT License which is available at +// https://opensource.org/licenses/MIT +// +// SPDX-License-Identifier: MIT +////////////////////////////////////////////////////////////////////////////// + +package org.eclipse.escet.cif.common.checkers; + +import org.eclipse.escet.cif.common.CifEdgeUtils; +import org.eclipse.escet.cif.metamodel.cif.automata.Automaton; +import org.eclipse.escet.cif.metamodel.cif.automata.Edge; +import org.eclipse.escet.cif.metamodel.cif.automata.EdgeEvent; +import org.eclipse.escet.cif.metamodel.cif.automata.Location; +import org.eclipse.escet.cif.metamodel.cif.expressions.TauExpression; + +/** + * CIF check that does not allow the use of event 'tau', whether explicit or implicit. + * + * @note This check is included in {@link OnlyEventsWithControllabilityCheck}. + */ +public class NoTauCheck extends CifCheck { + @Override + protected void preprocessTauExpression(TauExpression tauExpr) { + // Explicit tau. + EdgeEvent edgeEvent = (EdgeEvent)tauExpr.eContainer(); + Edge edge = (Edge)edgeEvent.eContainer(); + Location loc = CifEdgeUtils.getSource(edge); + if (loc.getName() != null) { + addViolation(loc, "location has an edge with explicitly event \"tau\" on it"); + } else { + addViolation((Automaton)loc.eContainer(), "automaton has an edge with explicitly event \"tau\" on it"); + } + } + + @Override + protected void preprocessEdge(Edge edge) { + // Implicit tau. + if (edge.getEvents().isEmpty()) { + Location loc = CifEdgeUtils.getSource(edge); + if (loc.getName() != null) { + addViolation(loc, "location has an edge with implicitly event \"tau\" on it"); + } else { + addViolation((Automaton)loc.eContainer(), "automaton has an edge with implicitly event \"tau\" on it"); + } + } + } +} diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoUrgentEdgesCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoUrgentEdgesCheck.java new file mode 100644 index 000000000..6941a3481 --- /dev/null +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoUrgentEdgesCheck.java @@ -0,0 +1,33 @@ +////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2010, 2022 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available +// under the terms of the MIT License which is available at +// https://opensource.org/licenses/MIT +// +// SPDX-License-Identifier: MIT +////////////////////////////////////////////////////////////////////////////// + +package org.eclipse.escet.cif.common.checkers; + +import org.eclipse.escet.cif.metamodel.cif.automata.Automaton; +import org.eclipse.escet.cif.metamodel.cif.automata.Edge; +import org.eclipse.escet.cif.metamodel.cif.automata.Location; + +/** CIF check that does not allow urgent edges. */ +public class NoUrgentEdgesCheck extends CifCheck { + @Override + protected void preprocessEdge(Edge edge) { + if (edge.isUrgent()) { + Location loc = (Location)edge.eContainer(); + if (loc.getName() != null) { + addViolation(loc, "location has an urgent edge"); + } else { + addViolation((Automaton)loc.eContainer(), "automaton has an urgent edge"); + } + } + } +} diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoUrgentLocationsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoUrgentLocationsCheck.java new file mode 100644 index 000000000..788fb4fcc --- /dev/null +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoUrgentLocationsCheck.java @@ -0,0 +1,40 @@ +////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2010, 2022 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available +// under the terms of the MIT License which is available at +// https://opensource.org/licenses/MIT +// +// SPDX-License-Identifier: MIT +////////////////////////////////////////////////////////////////////////////// + +package org.eclipse.escet.cif.common.checkers; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.escet.cif.metamodel.cif.LocationParameter; +import org.eclipse.escet.cif.metamodel.cif.automata.Automaton; +import org.eclipse.escet.cif.metamodel.cif.automata.Location; + +/** CIF check that does not allow urgent locations. */ +public class NoUrgentLocationsCheck extends CifCheck { + @Override + protected void preprocessLocation(Location loc) { + // Skip location parameters. + EObject parent = loc.eContainer(); + if (parent instanceof LocationParameter) { + return; + } + + // Check for violation. + if (loc.isUrgent()) { + if (loc.getName() != null) { + addViolation(loc, "location is urgent"); + } else { + addViolation((Automaton)loc.eContainer(), "automaton has an urgent location"); + } + } + } +} diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoUserDefinedFunctionsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoUserDefinedFunctionsCheck.java new file mode 100644 index 000000000..b3b2d0258 --- /dev/null +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoUserDefinedFunctionsCheck.java @@ -0,0 +1,24 @@ +////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2010, 2022 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available +// under the terms of the MIT License which is available at +// https://opensource.org/licenses/MIT +// +// SPDX-License-Identifier: MIT +////////////////////////////////////////////////////////////////////////////// + +package org.eclipse.escet.cif.common.checkers; + +import org.eclipse.escet.cif.metamodel.cif.functions.Function; + +/** CIF check that does not allow user-defined functions. */ +public class NoUserDefinedFunctionsCheck extends CifCheck { + @Override + protected void preprocessFunction(Function func) { + addViolation(func, "function is a user-defined function"); + } +} diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyAutsWithOneInitLocCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyAutsWithOneInitLocCheck.java new file mode 100644 index 000000000..4cb9bbbf0 --- /dev/null +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyAutsWithOneInitLocCheck.java @@ -0,0 +1,91 @@ +////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2010, 2022 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available +// under the terms of the MIT License which is available at +// https://opensource.org/licenses/MIT +// +// SPDX-License-Identifier: MIT +////////////////////////////////////////////////////////////////////////////// + +package org.eclipse.escet.cif.common.checkers; + +import static org.eclipse.escet.cif.common.CifEvalUtils.evalPreds; +import static org.eclipse.escet.common.java.Strings.fmt; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.escet.cif.common.CifEvalException; +import org.eclipse.escet.cif.metamodel.cif.LocationParameter; +import org.eclipse.escet.cif.metamodel.cif.automata.Automaton; +import org.eclipse.escet.cif.metamodel.cif.automata.Location; +import org.eclipse.escet.common.app.framework.exceptions.UnsupportedException; + +/** + * CIF check that allows automata only if they have exactly one initial location. Automata for which this can not be + * determined statically, are also not allowed. + */ +public class OnlyAutsWithOneInitLocCheck extends CifCheck { + /** + * The number of initial locations found for the automaton being checked. Only valid while checking an automaton. Is + * set to {@code -1} to disable this check due to evaluation errors in initialization predicates. + */ + private int initLocCount; + + @Override + protected void preprocessAutomaton(Automaton aut) { + // Reset initial locations counter. + initLocCount = 0; + } + + @Override + protected void postprocessAutomaton(Automaton aut) { + // There must be exactly one initial location. + if (initLocCount == 0) { + addViolation(aut, "automaton has no initial location"); + } else if (initLocCount > 1) { + addViolation(aut, fmt("automata has multiple (%d) initial locations", initLocCount)); + } // Skip if check is disabled (negative value). + } + + @Override + protected void preprocessLocation(Location loc) { + // Skip location parameters. + EObject parent = loc.eContainer(); + if (parent instanceof LocationParameter) { + return; + } + + // Determine whether location is an initial location by statically evaluating the location's initialization + // predicates. + boolean initial = false; + String errMsg = null; + try { + initial = loc.getInitials().isEmpty() ? false : evalPreds(loc.getInitials(), true, true); + } catch (UnsupportedException e) { + // Can only fail if there is at least one predicate. + errMsg = "as one of its initialization predicates can not be statically evaluated"; + } catch (CifEvalException e) { + // Can only fail if there is at least one predicate. + errMsg = "as evaluating one of its initialization predicates resulted in an evaluation error"; + } + if (errMsg != null) { + if (loc.getName() != null) { + addViolation(loc, "failed to determine whether this is an initial location, " + errMsg); + } else { + addViolation((Automaton)loc.eContainer(), + "failed to determine whether the automaton's location is an initial location, " + errMsg); + } + + // Disable initial location count checking. + initLocCount = -1; + } + + // Update number of initial locations, if not disabled for this automaton. + if (initial && initLocCount != -1) { + initLocCount++; + } + } +} diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyEventsWithControllabilityCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyEventsWithControllabilityCheck.java new file mode 100644 index 000000000..f77121b0c --- /dev/null +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyEventsWithControllabilityCheck.java @@ -0,0 +1,66 @@ +////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2010, 2022 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available +// under the terms of the MIT License which is available at +// https://opensource.org/licenses/MIT +// +// SPDX-License-Identifier: MIT +////////////////////////////////////////////////////////////////////////////// + +package org.eclipse.escet.cif.common.checkers; + +import org.eclipse.escet.cif.common.CifEdgeUtils; +import org.eclipse.escet.cif.metamodel.cif.automata.Automaton; +import org.eclipse.escet.cif.metamodel.cif.automata.Edge; +import org.eclipse.escet.cif.metamodel.cif.automata.EdgeEvent; +import org.eclipse.escet.cif.metamodel.cif.automata.Location; +import org.eclipse.escet.cif.metamodel.cif.declarations.Event; +import org.eclipse.escet.cif.metamodel.cif.expressions.TauExpression; + +/** + * CIF check that allows events only if they are declared as controllable or uncontrollable. + * + * @note This check includes {@link NoTauCheck}. + */ +public class OnlyEventsWithControllabilityCheck extends CifCheck { + @Override + protected void preprocessEvent(Event event) { + if (event.getControllable() == null) { + addViolation(event, "event is not declared as controllable or uncontrollable"); + } + } + + @Override + protected void preprocessTauExpression(TauExpression tauExpr) { + // Explicit tau. + EdgeEvent edgeEvent = (EdgeEvent)tauExpr.eContainer(); + Edge edge = (Edge)edgeEvent.eContainer(); + Location loc = CifEdgeUtils.getSource(edge); + if (loc.getName() != null) { + addViolation(loc, "location has an edge with explicitly event \"tau\" on it, " + + "which is not controllable or uncontrollable"); + } else { + addViolation((Automaton)loc.eContainer(), "automaton has an edge with explicitly event \"tau\" on it, " + + "which is not controllable or uncontrollable"); + } + } + + @Override + protected void preprocessEdge(Edge edge) { + // Implicit tau. + if (edge.getEvents().isEmpty()) { + Location loc = CifEdgeUtils.getSource(edge); + if (loc.getName() != null) { + addViolation(loc, "location has an edge with implicitly event \"tau\" on it, " + + "which is not controllable or uncontrollable"); + } else { + addViolation((Automaton)loc.eContainer(), "automaton has an edge with implicitly event \"tau\" on it, " + + "which is not controllable or uncontrollable"); + } + } + } +} diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyReqStateInvsInCompsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyReqStateInvsInCompsCheck.java new file mode 100644 index 000000000..55f3d6ed5 --- /dev/null +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyReqStateInvsInCompsCheck.java @@ -0,0 +1,38 @@ +////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2010, 2022 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available +// under the terms of the MIT License which is available at +// https://opensource.org/licenses/MIT +// +// SPDX-License-Identifier: MIT +////////////////////////////////////////////////////////////////////////////// + +package org.eclipse.escet.cif.common.checkers; + +import static org.eclipse.escet.common.java.Strings.fmt; + +import org.eclipse.escet.cif.common.CifTextUtils; +import org.eclipse.escet.cif.metamodel.cif.ComplexComponent; +import org.eclipse.escet.cif.metamodel.cif.InvKind; +import org.eclipse.escet.cif.metamodel.cif.Invariant; +import org.eclipse.escet.cif.metamodel.cif.SupKind; + +/** CIF check that allows state invariants in components only if they are requirement invariants. */ +public class OnlyReqStateInvsInCompsCheck extends CifCheck { + @Override + protected void preprocessComplexComponent(ComplexComponent comp) { + for (Invariant inv: comp.getInvariants()) { + if (inv.getInvKind() == InvKind.STATE) { + SupKind supKind = inv.getSupKind(); + if (supKind != SupKind.REQUIREMENT) { + String kindTxt = (supKind == SupKind.NONE) ? "kindless" : CifTextUtils.kindToStr(supKind); + addViolation(comp, fmt("component has a %s state invariant", kindTxt)); + } + } + } + } +} diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlySimpleAssignmentsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlySimpleAssignmentsCheck.java new file mode 100644 index 000000000..7f7ca4f0a --- /dev/null +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlySimpleAssignmentsCheck.java @@ -0,0 +1,56 @@ +////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2010, 2022 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available +// under the terms of the MIT License which is available at +// https://opensource.org/licenses/MIT +// +// SPDX-License-Identifier: MIT +////////////////////////////////////////////////////////////////////////////// + +package org.eclipse.escet.cif.common.checkers; + +import java.util.Set; + +import org.eclipse.escet.cif.metamodel.cif.automata.Assignment; +import org.eclipse.escet.cif.metamodel.cif.automata.IfUpdate; + +/** + * CIF check that allows updates on edges only if they are simple assignments, i.e., no 'if' updates, multi-assignments + * and partial variable assignments. + * + * @note This check includes {@link NoIfUpdatesOnEdgesCheck}, {@link NoMultiAssignOnEdgesCheck} and + * {@link NoPartialVarAssignOnEdgesCheck}. + */ +public class OnlySimpleAssignmentsCheck extends CifCheck { + /** No 'if' updates check. */ + private NoIfUpdatesOnEdgesCheck noIf = new NoIfUpdatesOnEdgesCheck(); + + /** No multi-assignments check. */ + private NoMultiAssignOnEdgesCheck noMulti = new NoMultiAssignOnEdgesCheck(); + + /** No partial variable assignments check. */ + private NoPartialVarAssignOnEdgesCheck noPartial = new NoPartialVarAssignOnEdgesCheck(); + + @Override + public void setViolations(Set violations) { + super.setViolations(violations); + noIf.setViolations(violations); + noMulti.setViolations(violations); + noPartial.setViolations(violations); + } + + @Override + protected void preprocessIfUpdate(IfUpdate update) { + noIf.preprocessIfUpdate(update); + } + + @Override + protected void preprocessAssignment(Assignment asgn) { + noMulti.preprocessAssignment(asgn); + noPartial.preprocessAssignment(asgn); + } +} diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyStaticEvalMarkerPredsInLocsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyStaticEvalMarkerPredsInLocsCheck.java new file mode 100644 index 000000000..3e653bae5 --- /dev/null +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyStaticEvalMarkerPredsInLocsCheck.java @@ -0,0 +1,57 @@ +////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2010, 2022 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available +// under the terms of the MIT License which is available at +// https://opensource.org/licenses/MIT +// +// SPDX-License-Identifier: MIT +////////////////////////////////////////////////////////////////////////////// + +package org.eclipse.escet.cif.common.checkers; + +import static org.eclipse.escet.cif.common.CifEvalUtils.evalPreds; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.escet.cif.common.CifEvalException; +import org.eclipse.escet.cif.metamodel.cif.LocationParameter; +import org.eclipse.escet.cif.metamodel.cif.automata.Automaton; +import org.eclipse.escet.cif.metamodel.cif.automata.Location; +import org.eclipse.escet.common.app.framework.exceptions.UnsupportedException; + +/** CIF check that allows marker predicates in locations only if they can be evaluated statically. */ +public class OnlyStaticEvalMarkerPredsInLocsCheck extends CifCheck { + @Override + protected void preprocessLocation(Location loc) { + // Skip location parameters. + EObject parent = loc.eContainer(); + if (parent instanceof LocationParameter) { + return; + } + + // Check for violation. + if (!loc.getMarkeds().isEmpty()) { + try { + evalPreds(loc.getMarkeds(), false, true); + } catch (UnsupportedException e) { + if (loc.getName() != null) { + addViolation(loc, "location has a marker predicate that can not be evaluated statically"); + } else { + addViolation((Automaton)loc.eContainer(), + "automaton has a location with a marker predicate that can not be evaluated statically"); + } + } catch (CifEvalException e) { + if (loc.getName() != null) { + addViolation(loc, "location has a marker predicate for which static evaluation " + + "resulted in an evaluation error"); + } else { + addViolation((Automaton)loc.eContainer(), "automaton has a location with a marker predicate for " + + "which static evaluation resulted in an evaluation error"); + } + } + } + } +} diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyVarValueMarkerPredsInCompsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyVarValueMarkerPredsInCompsCheck.java new file mode 100644 index 000000000..9f3cd7820 --- /dev/null +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyVarValueMarkerPredsInCompsCheck.java @@ -0,0 +1,71 @@ +////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2010, 2022 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available +// under the terms of the MIT License which is available at +// https://opensource.org/licenses/MIT +// +// SPDX-License-Identifier: MIT +////////////////////////////////////////////////////////////////////////////// + +package org.eclipse.escet.cif.common.checkers; + +import static org.eclipse.escet.common.java.Maps.map; + +import java.util.Map; +import java.util.Set; + +import org.eclipse.escet.cif.metamodel.cif.ComplexComponent; +import org.eclipse.escet.cif.metamodel.cif.declarations.DiscVariable; +import org.eclipse.escet.cif.metamodel.cif.expressions.BinaryExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.BinaryOperator; +import org.eclipse.escet.cif.metamodel.cif.expressions.DiscVariableExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.Expression; + +/** + * CIF check that allows marker predicates in components only if they are of the form 'discrete_variable = + * marked_value', and only at most one per discrete variable. + */ +public class OnlyVarValueMarkerPredsInCompsCheck extends CifCheck { + /** Mapping from discrete variables to their marked values. Used to detect duplicates. */ + private Map markeds; + + @Override + public void setViolations(Set violations) { + // Initialization. + super.setViolations(violations); + markeds = map(); + } + + @Override + protected void preprocessComplexComponent(ComplexComponent comp) { + for (Expression marked: comp.getMarkeds()) { + // The only supported form is 'discrete_variable = marked_value'. + if (!(marked instanceof BinaryExpression)) { + addViolation(comp, "component has a marker predicate that is not of the form " + + "\"discrete_variable = marked_value\""); + continue; + } + BinaryExpression bexpr = (BinaryExpression)marked; + if (bexpr.getOperator() != BinaryOperator.EQUAL || !(bexpr.getLeft() instanceof DiscVariableExpression)) { + addViolation(comp, "component has a marker predicate that is not of the form " + + "\"discrete_variable = marked_value\""); + continue; + } + + // Add to mapping, to detect duplicates. + DiscVariableExpression vref = (DiscVariableExpression)bexpr.getLeft(); + DiscVariable var = vref.getVariable(); + Expression newValue = bexpr.getRight(); + Expression previousValue = markeds.get(var); + if (previousValue == null) { + markeds.put(var, newValue); + } else { + addViolation(var, "discrete variable has multiple predicates to specify its marked values"); + } + } + } +} -- GitLab From 6835013223113147eace7e097674fc0d1f9f01ec Mon Sep 17 00:00:00 2001 From: Dennis Hendriks Date: Sun, 5 Jun 2022 14:30:22 +0200 Subject: [PATCH 10/23] #370 Change CifToSupremicaPreChecker to use generic checker. --- .../cif/cif2supremica/CifToSupremica.java | 2 +- .../CifToSupremicaPreChecker.java | 825 ++++-------------- 2 files changed, 172 insertions(+), 655 deletions(-) diff --git a/cif/org.eclipse.escet.cif.cif2supremica/src/org/eclipse/escet/cif/cif2supremica/CifToSupremica.java b/cif/org.eclipse.escet.cif.cif2supremica/src/org/eclipse/escet/cif/cif2supremica/CifToSupremica.java index b276c59d5..732e869c3 100644 --- a/cif/org.eclipse.escet.cif.cif2supremica/src/org/eclipse/escet/cif/cif2supremica/CifToSupremica.java +++ b/cif/org.eclipse.escet.cif.cif2supremica/src/org/eclipse/escet/cif/cif2supremica/CifToSupremica.java @@ -140,7 +140,7 @@ public class CifToSupremica { } // Check preconditions and perform further preprocessing. - new CifToSupremicaPreChecker().check(spec); + CifToSupremicaPreChecker.check(spec); preprocess(spec, elimEnums); // Modify the CIF specification for state invariants. diff --git a/cif/org.eclipse.escet.cif.cif2supremica/src/org/eclipse/escet/cif/cif2supremica/CifToSupremicaPreChecker.java b/cif/org.eclipse.escet.cif.cif2supremica/src/org/eclipse/escet/cif/cif2supremica/CifToSupremicaPreChecker.java index c18d5befe..bebca9bbe 100644 --- a/cif/org.eclipse.escet.cif.cif2supremica/src/org/eclipse/escet/cif/cif2supremica/CifToSupremicaPreChecker.java +++ b/cif/org.eclipse.escet.cif.cif2supremica/src/org/eclipse/escet/cif/cif2supremica/CifToSupremicaPreChecker.java @@ -13,96 +13,44 @@ package org.eclipse.escet.cif.cif2supremica; -import static org.eclipse.escet.cif.common.CifEvalUtils.evalPreds; -import static org.eclipse.escet.cif.common.CifTextUtils.exprToStr; -import static org.eclipse.escet.cif.common.CifTextUtils.exprsToStr; -import static org.eclipse.escet.cif.common.CifTextUtils.getAbsName; -import static org.eclipse.escet.cif.common.CifTextUtils.getComponentText1; -import static org.eclipse.escet.cif.common.CifTextUtils.getLocationText1; -import static org.eclipse.escet.cif.common.CifTextUtils.invToStr; -import static org.eclipse.escet.cif.common.CifTextUtils.operatorToStr; -import static org.eclipse.escet.cif.common.CifTextUtils.typeToStr; -import static org.eclipse.escet.cif.common.CifTypeUtils.isRangeless; -import static org.eclipse.escet.cif.common.CifTypeUtils.normalizeType; import static org.eclipse.escet.common.java.Lists.list; -import static org.eclipse.escet.common.java.Maps.map; -import static org.eclipse.escet.common.java.Strings.fmt; -import java.util.Collections; import java.util.List; -import java.util.Map; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.escet.cif.common.CifEvalException; -import org.eclipse.escet.cif.common.CifTextUtils; -import org.eclipse.escet.cif.common.CifTypeUtils; -import org.eclipse.escet.cif.common.RangeCompat; -import org.eclipse.escet.cif.metamodel.cif.ComplexComponent; -import org.eclipse.escet.cif.metamodel.cif.InvKind; -import org.eclipse.escet.cif.metamodel.cif.Invariant; -import org.eclipse.escet.cif.metamodel.cif.LocationParameter; +import java.util.Set; + +import org.eclipse.escet.cif.common.checkers.CifCheck; +import org.eclipse.escet.cif.common.checkers.CifCheckViolation; +import org.eclipse.escet.cif.common.checkers.CifChecker; +import org.eclipse.escet.cif.common.checkers.NoChannelsCheck; +import org.eclipse.escet.cif.common.checkers.NoContinuousVariablesCheck; +import org.eclipse.escet.cif.common.checkers.NoDiscVarsWithMultiInitValuesCheck; +import org.eclipse.escet.cif.common.checkers.NoInitPredsInCompsCheck; +import org.eclipse.escet.cif.common.checkers.NoInputVariablesCheck; +import org.eclipse.escet.cif.common.checkers.NoKindlessAutomataCheck; +import org.eclipse.escet.cif.common.checkers.NoKindlessStateEvtExclInvsCheck; +import org.eclipse.escet.cif.common.checkers.NoSpecificBinaryExprsCheck; +import org.eclipse.escet.cif.common.checkers.NoSpecificExprsCheck; +import org.eclipse.escet.cif.common.checkers.NoSpecificTypesCheck; +import org.eclipse.escet.cif.common.checkers.NoSpecificUnaryExprsCheck; +import org.eclipse.escet.cif.common.checkers.NoStateInvsInLocsCheck; +import org.eclipse.escet.cif.common.checkers.NoUrgentEdgesCheck; +import org.eclipse.escet.cif.common.checkers.NoUrgentLocationsCheck; +import org.eclipse.escet.cif.common.checkers.NoUserDefinedFunctionsCheck; +import org.eclipse.escet.cif.common.checkers.OnlyAutsWithOneInitLocCheck; +import org.eclipse.escet.cif.common.checkers.OnlyEventsWithControllabilityCheck; +import org.eclipse.escet.cif.common.checkers.OnlyReqStateInvsInCompsCheck; +import org.eclipse.escet.cif.common.checkers.OnlySimpleAssignmentsCheck; +import org.eclipse.escet.cif.common.checkers.OnlyStaticEvalMarkerPredsInLocsCheck; +import org.eclipse.escet.cif.common.checkers.OnlyVarValueMarkerPredsInCompsCheck; import org.eclipse.escet.cif.metamodel.cif.Specification; -import org.eclipse.escet.cif.metamodel.cif.SupKind; -import org.eclipse.escet.cif.metamodel.cif.automata.Assignment; -import org.eclipse.escet.cif.metamodel.cif.automata.Automaton; -import org.eclipse.escet.cif.metamodel.cif.automata.Edge; -import org.eclipse.escet.cif.metamodel.cif.automata.IfUpdate; -import org.eclipse.escet.cif.metamodel.cif.automata.Location; -import org.eclipse.escet.cif.metamodel.cif.declarations.ContVariable; -import org.eclipse.escet.cif.metamodel.cif.declarations.DiscVariable; -import org.eclipse.escet.cif.metamodel.cif.declarations.Event; -import org.eclipse.escet.cif.metamodel.cif.declarations.InputVariable; -import org.eclipse.escet.cif.metamodel.cif.declarations.VariableValue; -import org.eclipse.escet.cif.metamodel.cif.expressions.BinaryExpression; -import org.eclipse.escet.cif.metamodel.cif.expressions.BinaryOperator; -import org.eclipse.escet.cif.metamodel.cif.expressions.CastExpression; -import org.eclipse.escet.cif.metamodel.cif.expressions.DictExpression; -import org.eclipse.escet.cif.metamodel.cif.expressions.DiscVariableExpression; -import org.eclipse.escet.cif.metamodel.cif.expressions.Expression; -import org.eclipse.escet.cif.metamodel.cif.expressions.FunctionCallExpression; -import org.eclipse.escet.cif.metamodel.cif.expressions.IfExpression; -import org.eclipse.escet.cif.metamodel.cif.expressions.ListExpression; -import org.eclipse.escet.cif.metamodel.cif.expressions.ProjectionExpression; -import org.eclipse.escet.cif.metamodel.cif.expressions.RealExpression; -import org.eclipse.escet.cif.metamodel.cif.expressions.SetExpression; -import org.eclipse.escet.cif.metamodel.cif.expressions.SliceExpression; -import org.eclipse.escet.cif.metamodel.cif.expressions.StringExpression; -import org.eclipse.escet.cif.metamodel.cif.expressions.SwitchExpression; -import org.eclipse.escet.cif.metamodel.cif.expressions.TauExpression; -import org.eclipse.escet.cif.metamodel.cif.expressions.TimeExpression; -import org.eclipse.escet.cif.metamodel.cif.expressions.TupleExpression; -import org.eclipse.escet.cif.metamodel.cif.expressions.UnaryExpression; -import org.eclipse.escet.cif.metamodel.cif.expressions.UnaryOperator; -import org.eclipse.escet.cif.metamodel.cif.functions.Function; -import org.eclipse.escet.cif.metamodel.cif.types.BoolType; -import org.eclipse.escet.cif.metamodel.cif.types.CifType; -import org.eclipse.escet.cif.metamodel.cif.types.DictType; -import org.eclipse.escet.cif.metamodel.cif.types.DistType; -import org.eclipse.escet.cif.metamodel.cif.types.FuncType; -import org.eclipse.escet.cif.metamodel.cif.types.IntType; -import org.eclipse.escet.cif.metamodel.cif.types.ListType; -import org.eclipse.escet.cif.metamodel.cif.types.RealType; -import org.eclipse.escet.cif.metamodel.cif.types.SetType; -import org.eclipse.escet.cif.metamodel.cif.types.StringType; -import org.eclipse.escet.cif.metamodel.cif.types.TupleType; -import org.eclipse.escet.cif.metamodel.java.CifWalker; import org.eclipse.escet.common.app.framework.exceptions.UnsupportedException; -import org.eclipse.escet.common.java.Assert; -import org.eclipse.escet.common.java.Strings; /** CIF to Supremica transformation precondition checker. */ -public class CifToSupremicaPreChecker extends CifWalker { - /** Precondition violations found so far. */ - private final List problems = list(); - - /** Mapping from discrete variables to their marked values. Filled during checking. */ - private Map> markeds = map(); - - /** - * The number of initial locations found for the automaton being checked. Only valid while checking an automaton. Is - * set to {@code -1} to disable this check due to evaluation errors in initialization predicates. - */ - private int initLocCount; +public class CifToSupremicaPreChecker { + /** Constructor for the {@link CifToSupremicaPreChecker} class. */ + private CifToSupremicaPreChecker() { + // Static class. + } /** * Checks the CIF specification to make sure it satisfies the preconditions for the transformation. @@ -110,585 +58,154 @@ public class CifToSupremicaPreChecker extends CifWalker { * @param spec The CIF specification to check. * @throws UnsupportedException If a precondition is violated. */ - public void check(Specification spec) { - // Find precondition violations. - walkSpecification(spec); - - // If we have any problems, the specification is unsupported. - Collections.sort(problems, Strings.SORTER); - if (!problems.isEmpty()) { - String msg = "CIF to Supremica transformation failed due to unsatisfied preconditions:\n - " - + String.join("\n - ", problems); - throw new UnsupportedException(msg); - } - } + public static void check(Specification spec) { + // Configure precondition checks. + List preconditions = list(); - @Override - protected void preprocessEvent(Event event) { - // Event must be controllable or uncontrollable. - if (event.getControllable() == null) { - String msg = fmt("Unsupported event \"%s\": event is not declared as controllable or uncontrollable.", - getAbsName(event)); - problems.add(msg); - } + // Kindless automata are not supported. + preconditions.add(new NoKindlessAutomataCheck()); - // Event must not have a data type. - if (event.getType() != null) { - String msg = fmt("Unsupported event \"%s\": event is a channel (has a data type).", getAbsName(event)); - problems.add(msg); - } - } + // Events must be controllable or uncontrollable. Tau events are thus not supported. + preconditions.add(new OnlyEventsWithControllabilityCheck()); - @Override - protected void preprocessTauExpression(TauExpression obj) { - problems.add( - "Unsupported event \"tau\": event is not controllable or uncontrollable (explicit use of \"tau\")."); - } + // Initialization predicates outside of locations are not supported. + preconditions.add(new NoInitPredsInCompsCheck()); - @Override - protected void preprocessComplexComponent(ComplexComponent comp) { - // Initialization predicates only in locations. - if (!comp.getInitials().isEmpty()) { - String msg = fmt("Unsupported %s: initialization predicates are currently only supported in locations.", - getComponentText1(comp)); - problems.add(msg); - } + // Marker predicates outside of locations are only supported if they have the form discrete_variable = + // marked_value. Discrete variables with multiple marker predicates are also not supported. + preconditions.add(new OnlyVarValueMarkerPredsInCompsCheck()); - // Check for supported/duplicate variable marking predicates. - for (Expression marked: comp.getMarkeds()) { - boolean supported = processComponentMarker(marked); - if (!supported) { - String msg = fmt("Unsupported %s: unsupported marker predicate \"%s\".", getComponentText1(comp), - exprToStr(marked)); - problems.add(msg); - } - } - - // Check supervisory and invariant kinds of invariants. State invariants must be requirements. State/event - // exclusion invariants are transformed into automata and must have a kind. - for (Invariant inv: comp.getInvariants()) { - SupKind supKind = inv.getSupKind(); + // Locations with initialization or marker predicates that are not trivially true or false are not supported. + // This check only checks marker predicates. The check for a single initial location in each automaton, checks + // the initialization predicates. + preconditions.add(new OnlyStaticEvalMarkerPredsInLocsCheck()); - if (inv.getInvKind() == InvKind.STATE) { - if (supKind != SupKind.REQUIREMENT) { - String kindTxt = (supKind == SupKind.NONE) ? "kindless" : CifTextUtils.kindToStr(supKind); - String msg = fmt("Unsupported %s: unsupported %s state invariant \"%s\".", getComponentText1(comp), - kindTxt, invToStr(inv, false)); - problems.add(msg); - } - } else if (inv.getInvKind() == InvKind.EVENT_NEEDS || inv.getInvKind() == InvKind.EVENT_DISABLES) { - if (supKind == SupKind.NONE) { - String msg = fmt("Unsupported %s: unsupported kindless state/event exclusion invariant \"%s\".", - getComponentText1(comp), invToStr(inv, false)); - problems.add(msg); - } - } else { - Assert.fail("Unexpected invariant kind."); - } - } - } - - /** - * Processes the given marker predicate of a component. The predicate should be of the form 'discrete_variable = - * marked_value'. Other forms are not supported. If supported, the variable and marked value are added to - * {@link #markeds}. Also checks for duplicate marked values for a single discrete variable. - * - * @param marker The marker predicate to process. - * @return Whether the marker predicate is supported ({@code true}) or not ({@code false}). Duplicate marked values - * do not affect the result of this method. - */ - private boolean processComponentMarker(Expression marker) { - // Analyze. - if (!(marker instanceof BinaryExpression)) { - return false; - } - BinaryExpression bexpr = (BinaryExpression)marker; - if (bexpr.getOperator() != BinaryOperator.EQUAL) { - return false; - } - if (!(bexpr.getLeft() instanceof DiscVariableExpression)) { - return false; - } - - // Add to supported marker predicates mapping. - DiscVariableExpression vref = (DiscVariableExpression)bexpr.getLeft(); - DiscVariable var = vref.getVariable(); - List values = markeds.get(var); - if (values == null) { - values = list(); - markeds.put(var, values); - } - values.add(bexpr.getRight()); - - // We only support at most one marker value. Report duplicates only - // once per variable. - if (values.size() == 2) { - String msg = fmt("Unsupported declaration \"%s\": discrete variables with multiple marker predicates are " - + "currently not supported.", getAbsName(var)); - problems.add(msg); - } - - // The predicate is supported, although it may be a duplicate. - return true; - } - - @Override - protected void preprocessAutomaton(Automaton aut) { - // Check kind. - if (aut.getKind() == SupKind.NONE) { - String msg = fmt("Unsupported automaton \"%s\": kindless/regular automata are currently not supported.", - getAbsName(aut)); - problems.add(msg); - } - - // Reset initial locations counter. - initLocCount = 0; - } + // Automata that do not have exactly one initial location are not supported. We allow only exactly one initial + // location to ensure that the elimination of location references in expressions does not introduce additional + // initialization predicates. + preconditions.add(new OnlyAutsWithOneInitLocCheck()); - @Override - protected void postprocessAutomaton(Automaton aut) { - // Exactly one initial location. This is required to ensure that the - // elimination of location references in expressions does not introduce - // additional initialization predicates. - if (initLocCount == 0) { - String msg = fmt("Unsupported automaton \"%s\": automata without an initial location are currently " - + "not supported.", getAbsName(aut)); - problems.add(msg); - } - - if (initLocCount > 1) { - String msg = fmt("Unsupported automaton \"%s\": automata with multiple (%d) initial locations are " - + "currently not supported.", getAbsName(aut), initLocCount); - problems.add(msg); - } - } - - @Override - protected void preprocessDiscVariable(DiscVariable var) { - // Discrete variables with multiple initial values are not supported. - // Actually, Supremica allows an initialization predicate, rather than - // a value, and the latest version seems to require initialization - // predicates instead of initial values. However, using - // 'x == 1 | x != 1' for a variable 'x' in range '0..9', in the latest - // version, seems to result in value '0' as initial value during - // simulation, without any way to get an other initial value. To be - // safe, we'll require a single initial value. - // - // Discrete variables that represent function parameters or local - // variables of functions are ignored here, as functions are already - // reported separately. - EObject parent = var.eContainer(); - if (parent instanceof ComplexComponent) { - VariableValue values = var.getValue(); - if (values != null && values.getValues().size() != 1) { - String msg = fmt("Unsupported declaration \"%s\": discrete variables with multiple potential initial " - + "values are currently not supported.", getAbsName(var)); - problems.add(msg); - } - } - } - - @Override - protected void preprocessContVariable(ContVariable var) { - // Continuous variables not supported. - String msg = fmt("Unsupported declaration \"%s\": continuous variables are currently unsupported.", - getAbsName(var)); - problems.add(msg); - } - - @Override - protected void preprocessInputVariable(InputVariable var) { - // Input variables not supported. - String msg = fmt("Unsupported declaration \"%s\": input variables are currently unsupported.", getAbsName(var)); - problems.add(msg); - } - - @Override - protected void preprocessLocation(Location loc) { - // Skip location parameters. - EObject parent = loc.eContainer(); - if (parent instanceof LocationParameter) { - return; - } - - // No urgent locations. - if (loc.isUrgent()) { - String msg = fmt("Unsupported %s: urgent locations are currently unsupported.", getLocationText1(loc)); - problems.add(msg); - } - - // Initialization. - boolean initial = false; - try { - initial = loc.getInitials().isEmpty() ? false : evalPreds(loc.getInitials(), true, true); - } catch (CifEvalException e) { - // Can only fail if there is at least one predicate. - String msg = fmt("Failed to evaluate initialization predicate(s): %s.", exprsToStr(loc.getInitials())); - problems.add(msg); - - // Disable initial location count checking. - initLocCount = -1; - } - - if (initial && initLocCount != -1) { - initLocCount++; - } - - // Marked. - if (!loc.getMarkeds().isEmpty()) { - try { - evalPreds(loc.getMarkeds(), false, true); - } catch (CifEvalException e) { - // Can only fail if there is at least one predicate. - String msg = fmt("Failed to evaluate marker predicate(s): %s.", exprsToStr(loc.getInitials())); - problems.add(msg); - } - } - - // No state invariants in locations. We would need to change 'invariant X' - // in location 'L' to 'invariant L => X' (in the automaton), but - // references to locations are not supported by the transformation. We do - // eliminate location references, so we could make a CIF to CIF - // transformation that lifts state invariants out of locations to the - // surrounding automaton, and apply that transformation before the + // State invariants in locations are not supported. We would need to change 'invariant X' in location 'L' to + // 'invariant L => X' (in the automaton), but references to locations are not supported by the transformation. + // We do eliminate location references, so we could make a CIF to CIF transformation that lifts state + // invariants out of locations to the surrounding automaton, and apply that transformation before the // elimination of location references. - for (Invariant inv: loc.getInvariants()) { - if (inv.getInvKind() == InvKind.STATE) { - String msg = fmt("Unsupported %s: state invariants in locations are currently unsupported.", - getLocationText1(loc)); - problems.add(msg); - } - } - } - - @Override - protected void preprocessEdge(Edge edge) { - // Tau unsupported. - if (edge.getEvents().isEmpty()) { - problems.add("Unsupported event \"tau\": event is not controllable or uncontrollable (implicit use of " - + "\"tau\")."); - } - - // No urgent edges. - if (edge.isUrgent()) { - Location loc = (Location)edge.eContainer(); - String msg = fmt("Unsupported %s: urgent edges are currently unsupported.", getLocationText1(loc)); - problems.add(msg); - } - } - - @Override - protected void preprocessAssignment(Assignment asgn) { - // Check for multi-assignment and partial variable assignment. - if (asgn.getAddressable() instanceof TupleExpression) { - // Multi-assignment unsupported. - EObject loc = asgn; - while (!(loc instanceof Location)) { - loc = loc.eContainer(); - } - Assert.check(loc instanceof Location); - - String msg = fmt("Unsupported %s: edges with multi-assignments are currently unsupported.", - getLocationText1((Location)loc)); - problems.add(msg); - } else if (asgn.getAddressable() instanceof ProjectionExpression) { - // Partial variable assignment unsupported. - EObject loc = asgn; - while (!(loc instanceof Location)) { - loc = loc.eContainer(); - } - Assert.check(loc instanceof Location); - - String msg = fmt("Unsupported %s: edges with partial variable assignments are currently unsupported.", - getLocationText1((Location)loc)); - problems.add(msg); - } - } - - @Override - protected void preprocessIfUpdate(IfUpdate update) { - // 'if' update unsupported. - EObject loc = update; - while (!(loc instanceof Location)) { - loc = loc.eContainer(); - } - Assert.check(loc instanceof Location); - - String msg = fmt("Unsupported %s: edges with 'if' updates are currently unsupported.", - getLocationText1((Location)loc)); - problems.add(msg); - } - - @Override - protected void preprocessFunction(Function func) { - // User-defined functions are unsupported. - String msg = fmt("Unsupported function \"%s\": user-defined functions are currently unsupported.", - getAbsName(func)); - problems.add(msg); - } - - @Override - protected void preprocessDictType(DictType type) { - String msg = fmt("Unsupported type \"%s\": dictionary types are currently not supported.", typeToStr(type)); - problems.add(msg); - } - - @Override - protected void preprocessDistType(DistType type) { - String msg = fmt("Unsupported type \"%s\": distribution types are currently not supported.", typeToStr(type)); - problems.add(msg); - } - - @Override - protected void preprocessFuncType(FuncType type) { - // User-defined functions as well as all standard library functions - // are unsupported. - String msg = fmt("Unsupported type \"%s\": function types are currently not supported.", typeToStr(type)); - problems.add(msg); - } - - @Override - protected void preprocessIntType(IntType type) { - // Rangeless integer types unsupported. - if (isRangeless(type)) { - String msg = fmt("Unsupported type \"%s\": rangeless integer types are currently not supported.", - typeToStr(type)); - problems.add(msg); + preconditions.add(new NoStateInvsInLocsCheck()); + + // State invariants in components are only supported if they are requirement invariants. + preconditions.add(new OnlyReqStateInvsInCompsCheck()); + + // State/event exclusion invariants are transformed into automata and must have a kind. + preconditions.add(new NoKindlessStateEvtExclInvsCheck()); + + // Discrete variables with multiple potential initial values are not supported. Actually, Supremica allows an + // initialization predicate, rather than a value, and the latest version seems to require initialization + // predicates instead of initial values. However, using 'x == 1 | x != 1' for a variable 'x' in range '0..9', + // in the latest version, seems to result in value '0' as initial value during simulation, without any way to + // get an other initial value. To be safe, we'll require a single initial value. + preconditions.add(new NoDiscVarsWithMultiInitValuesCheck()); + + // Continuous variables are not supported. + preconditions.add(new NoContinuousVariablesCheck()); + + // Input variables are not supported. + preconditions.add(new NoInputVariablesCheck()); + + // Multi-assignments, partial variable assignments and conditional updates on edges are not supported. + preconditions.add(new OnlySimpleAssignmentsCheck()); + + // Urgent locations and urgent edges are not supported. + preconditions.add(new NoUrgentLocationsCheck()); + preconditions.add(new NoUrgentEdgesCheck()); + + // User-defined functions are not supported. + preconditions.add(new NoUserDefinedFunctionsCheck()); + + // Channels are not supported. + preconditions.add(new NoChannelsCheck()); + + // Only the following data types are supported: boolean types, ranged integer types, and enumeration types. + NoSpecificTypesCheck typesCheck = new NoSpecificTypesCheck(); + typesCheck.disallowDictTypes = true; + typesCheck.disallowDistTypes = true; + typesCheck.disallowFuncTypes = true; // User-defined and stdlib both unsupported. + typesCheck.disallowIntTypesRangeless = true; + typesCheck.disallowListTypes = true; + typesCheck.disallowRealTypes = true; + typesCheck.disallowSetTypes = true; + typesCheck.disallowStringTypes = true; + typesCheck.disallowTupleTypes = true; // Tuples, tuple types, and multi-assignments are unsupported. + preconditions.add(typesCheck); + + // Only the following expressions are supported: boolean literal values, integer literal values, binary + // expressions (partially, see below), unary expressions (partially, see below), and references to constants, + // discrete variables, enumeration literals, and casts that don’t change the type. + NoSpecificExprsCheck exprsCheck = new NoSpecificExprsCheck(); + exprsCheck.disallowCastExprsNonEqualType = true; + exprsCheck.disallowDictLits = true; + exprsCheck.disallowFuncCalls = true; + exprsCheck.disallowIfExprs = true; + exprsCheck.disallowListLits = true; + exprsCheck.disallowProjectionExprs = true; + exprsCheck.disallowRealLits = true; + exprsCheck.disallowSetLits = true; + exprsCheck.disallowSliceExprs = true; + exprsCheck.disallowStringLits = true; + exprsCheck.disallowSwitchExprs = true; + exprsCheck.disallowTimeVarRefs = true; + exprsCheck.disallowTupleLits = true; + preconditions.add(exprsCheck); + + // Only the following binary operators are supported: logical equivalence (<=>), logical implication (=>), + // conjunction (and) on boolean operands, disjunction (or) on boolean operands, addition (+) on ranged integer + // operands, subtraction (-) on ranged integer operands, multiplication (*) on ranged integer operands, integer + // division (div) on ranged integer operands, integer modulus (mod) on ranged integer operands, equality (=), + // inequality (!=), less than (<) on ranged integer operands, less than or equal to (<=) on ranged integer + // operands, greater than (>) on ranged integer operands, and greater than or equal to (>=) on ranged integer + // operands. + NoSpecificBinaryExprsCheck binCheck = new NoSpecificBinaryExprsCheck(); + binCheck.disallowConjunctionSets = true; + binCheck.disallowDisjunctionSets = true; + binCheck.disallowAdditionDicts = true; + binCheck.disallowAdditionIntsRangeless = true; + binCheck.disallowAdditionLists = true; + binCheck.disallowAdditionReals = true; + binCheck.disallowAdditionStrings = true; + binCheck.disallowSubtractionDicts = true; + binCheck.disallowSubtractionIntsRangeless = true; + binCheck.disallowSubtractionLists = true; + binCheck.disallowSubtractionReals = true; + binCheck.disallowSubtractionSets = true; + binCheck.disallowMultiplicationIntsRangeless = true; + binCheck.disallowMultiplicationReals = true; + binCheck.disallowIntegerDivisionIntsRangeless = true; + binCheck.disallowModulusIntsRangeless = true; + binCheck.disallowGreaterEqualIntsRangeless = true; + binCheck.disallowGreaterEqualReals = true; + binCheck.disallowGreaterThanIntsRangeless = true; + binCheck.disallowGreaterThanReals = true; + binCheck.disallowLessEqualIntsRangeless = true; + binCheck.disallowLessEqualReals = true; + binCheck.disallowLessThanIntsRangeless = true; + binCheck.disallowLessThanReals = true; + binCheck.disallowDivision = true; + binCheck.disallowElementOf = true; + binCheck.disallowSubset = true; + preconditions.add(binCheck); + + // Only the following unary operators are supported: logical inverse (not), negation (-) on a ranged integer + // operand, and plus (+) on a ranged integer operand. + NoSpecificUnaryExprsCheck unCheck = new NoSpecificUnaryExprsCheck(); + unCheck.disallowNegateIntsRangeless = true; + unCheck.disallowPlusIntsRangeless = true; + unCheck.disallowSample = true; + preconditions.add(unCheck); + + // Perform precondition check. + CifChecker checker = new CifChecker(preconditions); + Set violations = checker.check(spec); + if (!violations.isEmpty()) { + CifChecker.reportPreconditionViolations(violations, "CIF to Supremica transformation"); } } - - @Override - protected void preprocessListType(ListType type) { - String msg = fmt("Unsupported type \"%s\": list types are currently not supported.", typeToStr(type)); - problems.add(msg); - } - - @Override - protected void preprocessRealType(RealType type) { - String msg = fmt("Unsupported type \"%s\": real types are currently not supported.", typeToStr(type)); - problems.add(msg); - } - - @Override - protected void preprocessSetType(SetType type) { - String msg = fmt("Unsupported type \"%s\": set types are currently not supported.", typeToStr(type)); - problems.add(msg); - } - - @Override - protected void preprocessStringType(StringType type) { - String msg = fmt("Unsupported type \"%s\": string types are currently not supported.", typeToStr(type)); - problems.add(msg); - } - - @Override - protected void preprocessTupleType(TupleType type) { - // Tuples, tuple types, and multi-assignments are unsupported. - String msg = fmt("Unsupported type \"%s\": tuple types are currently not supported.", typeToStr(type)); - problems.add(msg); - } - - @Override - protected void preprocessBinaryExpression(BinaryExpression expr) { - BinaryOperator op = expr.getOperator(); - switch (op) { - // Always boolean. - case IMPLICATION: - case BI_CONDITIONAL: - return; - - // Check boolean arguments. - case CONJUNCTION: - case DISJUNCTION: { - CifType ltype = normalizeType(expr.getLeft().getType()); - CifType rtype = normalizeType(expr.getRight().getType()); - if (ltype instanceof BoolType && rtype instanceof BoolType) { - return; - } - break; - } - - // Check rangeless integer arguments. - case ADDITION: - case SUBTRACTION: - case MULTIPLICATION: - case INTEGER_DIVISION: - case MODULUS: { - CifType ltype = normalizeType(expr.getLeft().getType()); - CifType rtype = normalizeType(expr.getRight().getType()); - if (ltype instanceof IntType && !isRangeless((IntType)ltype) && rtype instanceof IntType - && !isRangeless((IntType)rtype)) - { - return; - } - break; - } - - // Always OK, as same type operands, and types of operands checked - // elsewhere. - case EQUAL: - case UNEQUAL: - return; - - // Check rangeless integer arguments. - case GREATER_EQUAL: - case GREATER_THAN: - case LESS_EQUAL: - case LESS_THAN: { - CifType ltype = normalizeType(expr.getLeft().getType()); - CifType rtype = normalizeType(expr.getRight().getType()); - if (ltype instanceof IntType && !isRangeless((IntType)ltype) && rtype instanceof IntType - && !isRangeless((IntType)rtype)) - { - return; - } - break; - } - - // Unsupported, regardless of types of operands. - case DIVISION: // Real division. - case ELEMENT_OF: - case SUBSET: - break; - - // Error. - default: - throw new RuntimeException("Unknown bin op: " + op); - } - - // Unsupported. - String msg = fmt("Unsupported expression \"%s\": binary operator \"%s\" is currently not supported, " - + "or is not supported for the operands that are used.", exprToStr(expr), operatorToStr(op)); - problems.add(msg); - } - - @Override - protected void preprocessCastExpression(CastExpression expr) { - CifType ctype = expr.getChild().getType(); - CifType rtype = expr.getType(); - if (CifTypeUtils.checkTypeCompat(ctype, rtype, RangeCompat.EQUAL)) { - // Ignore casting to the child type. - return; - } - - String msg = fmt("Unsupported expression \"%s\": cast expressions are currently not supported.", - exprToStr(expr)); - problems.add(msg); - } - - @Override - protected void preprocessDictExpression(DictExpression expr) { - String msg = fmt("Unsupported expression \"%s\": dictionary expressions are currently not supported.", - exprToStr(expr)); - problems.add(msg); - } - - @Override - protected void preprocessFunctionCallExpression(FunctionCallExpression expr) { - String msg = fmt("Unsupported expression \"%s\": function calls are currently not supported.", exprToStr(expr)); - problems.add(msg); - } - - @Override - protected void preprocessIfExpression(IfExpression expr) { - String msg = fmt("Unsupported expression \"%s\": 'if' expressions are currently not supported.", - exprToStr(expr)); - problems.add(msg); - } - - @Override - protected void preprocessListExpression(ListExpression expr) { - String msg = fmt("Unsupported expression \"%s\": list expressions are currently not supported.", - exprToStr(expr)); - problems.add(msg); - } - - @Override - protected void preprocessProjectionExpression(ProjectionExpression expr) { - String msg = fmt("Unsupported expression \"%s\": projection expressions are currently not supported.", - exprToStr(expr)); - problems.add(msg); - } - - @Override - protected void preprocessRealExpression(RealExpression expr) { - String msg = fmt("Unsupported expression \"%s\": real number expressions are currently not supported.", - exprToStr(expr)); - problems.add(msg); - } - - @Override - protected void preprocessSetExpression(SetExpression expr) { - String msg = fmt("Unsupported expression \"%s\": set expressions are currently not supported.", - exprToStr(expr)); - problems.add(msg); - } - - @Override - protected void preprocessSliceExpression(SliceExpression expr) { - String msg = fmt("Unsupported expression \"%s\": slice expressions are currently not supported.", - exprToStr(expr)); - problems.add(msg); - } - - @Override - protected void preprocessStringExpression(StringExpression expr) { - String msg = fmt("Unsupported expression \"%s\": string literal expressions are currently not supported.", - exprToStr(expr)); - problems.add(msg); - } - - @Override - protected void preprocessSwitchExpression(SwitchExpression expr) { - String msg = fmt("Unsupported expression \"%s\": 'switch' expressions are currently not supported.", - exprToStr(expr)); - problems.add(msg); - } - - @Override - protected void preprocessTimeExpression(TimeExpression expr) { - String msg = fmt("Unsupported expression \"%s\": the use of variable \"time\" is currently not supported.", - exprToStr(expr)); - problems.add(msg); - } - - @Override - protected void preprocessTupleExpression(TupleExpression expr) { - String msg = fmt("Unsupported expression \"%s\": tuple expressions are currently not supported.", - exprToStr(expr)); - problems.add(msg); - } - - @Override - protected void preprocessUnaryExpression(UnaryExpression expr) { - UnaryOperator op = expr.getOperator(); - switch (op) { - // Always boolean. - case INVERSE: - return; - - // Check rangeless integer argument. - case NEGATE: - case PLUS: { - CifType ctype = normalizeType(expr.getChild().getType()); - if (ctype instanceof IntType && !isRangeless((IntType)ctype)) { - return; - } - break; - } - - // Unsupported. - case SAMPLE: - break; - - // Error. - default: - throw new RuntimeException("Unknown un op: " + op); - } - - // Unsupported. - String msg = fmt("Unsupported expression \"%s\": unary operator \"%s\" is currently not supported, " - + "or is not supported for the operand that is used.", exprToStr(expr), operatorToStr(op)); - problems.add(msg); - } } -- GitLab From a4b23c032500187236804c386a707e93edf136f6 Mon Sep 17 00:00:00 2001 From: Dennis Hendriks Date: Sun, 5 Jun 2022 14:30:50 +0200 Subject: [PATCH 11/23] #370 Update CIF to Supremica expected test output. --- .../tests/cif2supremica/invalid1.cif | 8 +- .../invalid1.cif.cif2supremica.err | 130 +++++------- .../tests/cif2supremica/invalid2.cif | 2 +- .../invalid2.cif.cif2supremica.err | 200 ++++++------------ .../tests/cif2supremica/invalid3.cif | 2 +- .../invalid3.cif.cif2supremica.err | 4 +- 6 files changed, 127 insertions(+), 219 deletions(-) diff --git a/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid1.cif b/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid1.cif index be34dd580..f06ff0181 100644 --- a/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid1.cif +++ b/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid1.cif @@ -15,7 +15,7 @@ group g: event e1; // Not (un)controllable. controllable int[0..5] e2; // Event with data type. - automaton a: // Automaton with 'automaton' kind. + automaton a: // Kindless automaton. location: initial; edge e1, e2, tau; // Explicit 'tau'. @@ -29,8 +29,8 @@ group g: end plant p0: // Automaton without initial location. - disc int[1..2] x1 in {1,2}; // Non-deterministic variable init. - disc int[1..2] x2 in any; // Non-deterministic variable init. + disc int[1..2] x1 in {1,2}; // Multiple potential initial values. + disc int[1..2] x2 in any; // Multiple potential initial values. cont cnt der 1.0; // Continuous variable, real type/value. input bool inp; // Input variable. disc list bool lb = [true]; // List type/expr. @@ -56,7 +56,7 @@ group g: initial sqrt(-1.0) > 0; // Eval/idx fail, real expr/type, -/>/sqrt. marked sqrt(-2.0) > 0; // Eval/idx fail, real expr/type, -/>/sqrt. - plant invariant 7 = 7; // Invariant in location (regardless kind). + plant invariant 7 = 7; // Invariant in location (regardless of kind). end plant p2: // Automaton with two initial locations. diff --git a/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid1.cif.cif2supremica.err b/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid1.cif.cif2supremica.err index 9df182c02..50b7460b1 100644 --- a/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid1.cif.cif2supremica.err +++ b/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid1.cif.cif2supremica.err @@ -1,77 +1,57 @@ WARNING: File "cif2supremica/invalid1.cif": Semantic warning at line 31, column 9: Automaton "g.p0" has no initial location. ERROR: CIF to Supremica transformation failed due to unsatisfied preconditions: - - Failed to evaluate initialization predicate(s): sqrt(-1.0) > 0. - - Failed to evaluate marker predicate(s): sqrt(-1.0) > 0. - - Unsupported automaton "g.a": kindless/regular automata are currently not supported. - - Unsupported automaton "g.p0": automata without an initial location are currently not supported. - - Unsupported automaton "g.p2": automata with multiple (2) initial locations are currently not supported. - - Unsupported declaration "g.p0.cnt": continuous variables are currently unsupported. - - Unsupported declaration "g.p0.inp": input variables are currently unsupported. - - Unsupported declaration "g.p0.lb": discrete variables with multiple marker predicates are currently not supported. - - Unsupported declaration "g.p0.x1": discrete variables with multiple marker predicates are currently not supported. - - Unsupported declaration "g.p0.x1": discrete variables with multiple potential initial values are currently not supported. - - Unsupported declaration "g.p0.x2": discrete variables with multiple potential initial values are currently not supported. - - Unsupported event "g.e1": event is not declared as controllable or uncontrollable. - - Unsupported event "g.e2": event is a channel (has a data type). - - Unsupported event "tau": event is not controllable or uncontrollable (explicit use of "tau"). - - Unsupported event "tau": event is not controllable or uncontrollable (implicit use of "tau"). - - Unsupported expression "(1, 2)": tuple expressions are currently not supported. - - Unsupported expression "(g.p0.x1, g.p0.x2)": tuple expressions are currently not supported. - - Unsupported expression "-1.0": unary operator "-" is currently not supported, or is not supported for the operand that is used. - - Unsupported expression "-2.0": unary operator "-" is currently not supported, or is not supported for the operand that is used. - - Unsupported expression "1.0": real number expressions are currently not supported. - - Unsupported expression "1.0": real number expressions are currently not supported. - - Unsupported expression "1.2": real number expressions are currently not supported. - - Unsupported expression "2.0": real number expressions are currently not supported. - - Unsupported expression "[false, true]": list expressions are currently not supported. - - Unsupported expression "[false]": list expressions are currently not supported. - - Unsupported expression "[true]": list expressions are currently not supported. - - Unsupported expression "[true]": list expressions are currently not supported. - - Unsupported expression "g.p0.lb[0]": projection expressions are currently not supported. - - Unsupported expression "sqrt(-1.0) > 0": binary operator ">" is currently not supported, or is not supported for the operands that are used. - - Unsupported expression "sqrt(-1.0)": function calls are currently not supported. - - Unsupported expression "sqrt(-2.0) > 0": binary operator ">" is currently not supported, or is not supported for the operands that are used. - - Unsupported expression "sqrt(-2.0)": function calls are currently not supported. - - Unsupported function "g.f": user-defined functions are currently unsupported. - - Unsupported group "g": initialization predicates are currently only supported in locations. - - Unsupported group "g": unsupported kindless state invariant "8 = 8". - - Unsupported group "g": unsupported kindless state/event exclusion invariant "g.e1 needs g.p0.x1 > 0". - - Unsupported group "g": unsupported kindless state/event exclusion invariant "g.p0.x1 > 0 disables g.e1". - - Unsupported group "g": unsupported marker predicate "1 > 2". - - Unsupported group "g": unsupported marker predicate "2 = 2". - - Unsupported group "g": unsupported marker predicate "g.p0.cnt = 1.2". - - Unsupported group "g": unsupported marker predicate "not false". - - Unsupported group "g": unsupported plant state invariant "9 = 9". - - Unsupported group "g": unsupported supervisor state invariant "10 = 10". - - Unsupported location of automaton "g.p0": edges with 'if' updates are currently unsupported. - - Unsupported location of automaton "g.p0": edges with multi-assignments are currently unsupported. - - Unsupported location of automaton "g.p0": edges with partial variable assignments are currently unsupported. - - Unsupported location of automaton "g.p0": urgent locations are currently unsupported. - - Unsupported location of automaton "g.p1": state invariants in locations are currently unsupported. - - Unsupported location of automaton "g.snd": urgent edges are currently unsupported. - - Unsupported type "func real(real)": function types are currently not supported. - - Unsupported type "func real(real)": function types are currently not supported. - - Unsupported type "list bool": list types are currently not supported. - - Unsupported type "list bool": list types are currently not supported. - - Unsupported type "list bool": list types are currently not supported. - - Unsupported type "list bool": list types are currently not supported. - - Unsupported type "list bool": list types are currently not supported. - - Unsupported type "list[1] bool": list types are currently not supported. - - Unsupported type "list[1] bool": list types are currently not supported. - - Unsupported type "list[1] bool": list types are currently not supported. - - Unsupported type "list[2] bool": list types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "tuple(int[1..1]; int[2..2])": tuple types are currently not supported. - - Unsupported type "tuple(int[1..2]; int[1..2])": tuple types are currently not supported. + - Unsupported "g": component contains an initialization predicate. + - Unsupported "g": component has a kindless state invariant. + - Unsupported "g": component has a kindless state/event exclusion invariant. + - Unsupported "g": component has a marker predicate that is not of the form "discrete_variable = marked_value". + - Unsupported "g": component has a plant state invariant. + - Unsupported "g": component has a supervisor state invariant. + - Unsupported "g": list literal "[false, true]". + - Unsupported "g": list literal "[false]". + - Unsupported "g": list literal "[true]". + - Unsupported "g": list type "list bool". + - Unsupported "g": list type "list[1] bool". + - Unsupported "g": list type "list[2] bool". + - Unsupported "g": real number literal "1.2". + - Unsupported "g": real type "real". + - Unsupported "g.a": automaton has an edge with explicitly event "tau" on it, which is not controllable or uncontrollable. + - Unsupported "g.a": automaton has an edge with implicitly event "tau" on it, which is not controllable or uncontrollable. + - Unsupported "g.a": automaton is a kindless/regular automaton. + - Unsupported "g.e1": event is not declared as controllable or uncontrollable. + - Unsupported "g.e2": event is a channel (has a data type). + - Unsupported "g.f": function is a user-defined function. + - Unsupported "g.p0": automaton has an edge with a multi-assignment. + - Unsupported "g.p0": automaton has an edge with a partial variable assignment. + - Unsupported "g.p0": automaton has an edge with an 'if' update. + - Unsupported "g.p0": automaton has an urgent location. + - Unsupported "g.p0": automaton has no initial location. + - Unsupported "g.p0": list type "list bool". + - Unsupported "g.p0": projection expression "g.p0.lb[0]". + - Unsupported "g.p0": tuple literal "(1, 2)". + - Unsupported "g.p0": tuple literal "(g.p0.x1, g.p0.x2)". + - Unsupported "g.p0": tuple type "tuple(int[1..1]; int[2..2])". + - Unsupported "g.p0": tuple type "tuple(int[1..2]; int[1..2])". + - Unsupported "g.p0.cnt": real number literal "1.0". + - Unsupported "g.p0.cnt": real type "real". + - Unsupported "g.p0.cnt": variable is a continuous variable. + - Unsupported "g.p0.inp": variable is an input variable. + - Unsupported "g.p0.lb": discrete variable has multiple predicates to specify its marked values. + - Unsupported "g.p0.lb": list literal "[true]". + - Unsupported "g.p0.lb": list type "list bool". + - Unsupported "g.p0.lb": list type "list[1] bool". + - Unsupported "g.p0.x1": discrete variable has multiple (2) potential initial values. + - Unsupported "g.p0.x1": discrete variable has multiple predicates to specify its marked values. + - Unsupported "g.p0.x2": discrete variable has multiple potential initial values. + - Unsupported "g.p1": automaton has a location with a marker predicate for which static evaluation resulted in an evaluation error. + - Unsupported "g.p1": automaton has a location with a state invariant. + - Unsupported "g.p1": binary operator ">" on operands "sqrt(-1.0)" and "0". + - Unsupported "g.p1": binary operator ">" on operands "sqrt(-2.0)" and "0". + - Unsupported "g.p1": failed to determine whether the automaton's location is an initial location, as evaluating one of its initialization predicates resulted in an evaluation error. + - Unsupported "g.p1": function call "sqrt(-1.0)". + - Unsupported "g.p1": function call "sqrt(-2.0)". + - Unsupported "g.p1": function type "func real(real)". + - Unsupported "g.p1": real number literal "1.0". + - Unsupported "g.p1": real number literal "2.0". + - Unsupported "g.p1": real type "real". + - Unsupported "g.p2": automata has multiple (2) initial locations. + - Unsupported "g.snd": automaton has an urgent edge. diff --git a/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid2.cif b/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid2.cif index 43dcb9ae5..6d37e0f8f 100644 --- a/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid2.cif +++ b/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid2.cif @@ -51,7 +51,7 @@ plant p: edge u do b := i >= i; // Rangeless int type and '>='. edge u do b := true in sb; // Set type, 'in' on set. edge u do b := sb sub sb; // Set type, 'sub' on set. - edge u do (b, db) := sample db; // Dict type/sample, multi-asgn. + edge u do (b, db) := sample db; // Dist type/sample, multi-asgn, tuple type. edge u do i := +i; // Rangeless int type and '+'. edge u do i := -i; // Rangeless int type and '-'. edge u do str := "a"; // String type/expr. diff --git a/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid2.cif.cif2supremica.err b/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid2.cif.cif2supremica.err index 82604a3b5..d394d9e06 100644 --- a/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid2.cif.cif2supremica.err +++ b/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid2.cif.cif2supremica.err @@ -1,138 +1,64 @@ ERROR: CIF to Supremica transformation failed due to unsatisfied preconditions: - - Unsupported expression ""a"": string literal expressions are currently not supported. - - Unsupported expression ""a"": string literal expressions are currently not supported. - - Unsupported expression "(p.b, p.db)": tuple expressions are currently not supported. - - Unsupported expression "(true, false)": tuple expressions are currently not supported. - - Unsupported expression "+p.i": unary operator "+" is currently not supported, or is not supported for the operand that is used. - - Unsupported expression "-p.i": unary operator "-" is currently not supported, or is not supported for the operand that is used. - - Unsupported expression "1.0": real number expressions are currently not supported. - - Unsupported expression "1.2": real number expressions are currently not supported. - - Unsupported expression "1": cast expressions are currently not supported. - - Unsupported expression "[true]": list expressions are currently not supported. - - Unsupported expression "constant(true)": function calls are currently not supported. - - Unsupported expression "if true: 1 else 2 end": 'if' expressions are currently not supported. - - Unsupported expression "p.i < p.i": binary operator "<" is currently not supported, or is not supported for the operands that are used. - - Unsupported expression "p.i <= p.i": binary operator "<=" is currently not supported, or is not supported for the operands that are used. - - Unsupported expression "p.i > p.i": binary operator ">" is currently not supported, or is not supported for the operands that are used. - - Unsupported expression "p.i >= p.i": binary operator ">=" is currently not supported, or is not supported for the operands that are used. - - Unsupported expression "p.i div p.i": binary operator "div" is currently not supported, or is not supported for the operands that are used. - - Unsupported expression "p.i mod p.i": binary operator "mod" is currently not supported, or is not supported for the operands that are used. - - Unsupported expression "p.lb[:]": slice expressions are currently not supported. - - Unsupported expression "p.r * p.r": binary operator "*" is currently not supported, or is not supported for the operands that are used. - - Unsupported expression "p.r + p.r": binary operator "+" is currently not supported, or is not supported for the operands that are used. - - Unsupported expression "p.r - p.r": binary operator "-" is currently not supported, or is not supported for the operands that are used. - - Unsupported expression "p.r / p.r": binary operator "/" is currently not supported, or is not supported for the operands that are used. - - Unsupported expression "p.sb sub p.sb": binary operator "sub" is currently not supported, or is not supported for the operands that are used. - - Unsupported expression "p.tbb[a]": projection expressions are currently not supported. - - Unsupported expression "sample p.db": unary operator "sample" is currently not supported, or is not supported for the operand that is used. - - Unsupported expression "switch 1: else 2 end": 'switch' expressions are currently not supported. - - Unsupported expression "switch p: case l: 3 end": 'switch' expressions are currently not supported. - - Unsupported expression "time": the use of variable "time" is currently not supported. - - Unsupported expression "true in p.sb": binary operator "in" is currently not supported, or is not supported for the operands that are used. - - Unsupported expression "{false}": set expressions are currently not supported. - - Unsupported expression "{false}": set expressions are currently not supported. - - Unsupported expression "{true: false}": dictionary expressions are currently not supported. - - Unsupported expression "{true: true}": dictionary expressions are currently not supported. - - Unsupported expression "{true} and {false}": binary operator "and" is currently not supported, or is not supported for the operands that are used. - - Unsupported expression "{true} or {false}": binary operator "or" is currently not supported, or is not supported for the operands that are used. - - Unsupported expression "{true}": set expressions are currently not supported. - - Unsupported expression "{true}": set expressions are currently not supported. - - Unsupported expression "{true}": set expressions are currently not supported. - - Unsupported function "f": user-defined functions are currently unsupported. - - Unsupported location "l" of automaton "p": edges with multi-assignments are currently unsupported. - - Unsupported location "l" of automaton "p": edges with partial variable assignments are currently unsupported. - - Unsupported location "l" of automaton "p": state invariants in locations are currently unsupported. - - Unsupported type "dict(bool:bool)": dictionary types are currently not supported. - - Unsupported type "dict(bool:bool)": dictionary types are currently not supported. - - Unsupported type "dict(bool:bool)": dictionary types are currently not supported. - - Unsupported type "dict(bool:bool)": dictionary types are currently not supported. - - Unsupported type "dist bool": distribution types are currently not supported. - - Unsupported type "dist bool": distribution types are currently not supported. - - Unsupported type "dist bool": distribution types are currently not supported. - - Unsupported type "dist bool": distribution types are currently not supported. - - Unsupported type "dist bool": distribution types are currently not supported. - - Unsupported type "dist bool": distribution types are currently not supported. - - Unsupported type "dist bool": distribution types are currently not supported. - - Unsupported type "func bool(bool)": function types are currently not supported. - - Unsupported type "func bool(bool)": function types are currently not supported. - - Unsupported type "func bool(bool)": function types are currently not supported. - - Unsupported type "func bool(bool)": function types are currently not supported. - - Unsupported type "func dist bool(bool)": function types are currently not supported. - - Unsupported type "int": rangeless integer types are currently not supported. - - Unsupported type "int": rangeless integer types are currently not supported. - - Unsupported type "int": rangeless integer types are currently not supported. - - Unsupported type "int": rangeless integer types are currently not supported. - - Unsupported type "int": rangeless integer types are currently not supported. - - Unsupported type "int": rangeless integer types are currently not supported. - - Unsupported type "int": rangeless integer types are currently not supported. - - Unsupported type "int": rangeless integer types are currently not supported. - - Unsupported type "int": rangeless integer types are currently not supported. - - Unsupported type "int": rangeless integer types are currently not supported. - - Unsupported type "int": rangeless integer types are currently not supported. - - Unsupported type "int": rangeless integer types are currently not supported. - - Unsupported type "int": rangeless integer types are currently not supported. - - Unsupported type "int": rangeless integer types are currently not supported. - - Unsupported type "int": rangeless integer types are currently not supported. - - Unsupported type "int": rangeless integer types are currently not supported. - - Unsupported type "int": rangeless integer types are currently not supported. - - Unsupported type "int": rangeless integer types are currently not supported. - - Unsupported type "int": rangeless integer types are currently not supported. - - Unsupported type "int": rangeless integer types are currently not supported. - - Unsupported type "int": rangeless integer types are currently not supported. - - Unsupported type "int": rangeless integer types are currently not supported. - - Unsupported type "int": rangeless integer types are currently not supported. - - Unsupported type "int": rangeless integer types are currently not supported. - - Unsupported type "int": rangeless integer types are currently not supported. - - Unsupported type "int": rangeless integer types are currently not supported. - - Unsupported type "list bool": list types are currently not supported. - - Unsupported type "list bool": list types are currently not supported. - - Unsupported type "list bool": list types are currently not supported. - - Unsupported type "list bool": list types are currently not supported. - - Unsupported type "list[1] bool": list types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "real": real types are currently not supported. - - Unsupported type "set bool": set types are currently not supported. - - Unsupported type "set bool": set types are currently not supported. - - Unsupported type "set bool": set types are currently not supported. - - Unsupported type "set bool": set types are currently not supported. - - Unsupported type "set bool": set types are currently not supported. - - Unsupported type "set bool": set types are currently not supported. - - Unsupported type "set bool": set types are currently not supported. - - Unsupported type "set bool": set types are currently not supported. - - Unsupported type "set bool": set types are currently not supported. - - Unsupported type "set bool": set types are currently not supported. - - Unsupported type "set bool": set types are currently not supported. - - Unsupported type "set bool": set types are currently not supported. - - Unsupported type "set bool": set types are currently not supported. - - Unsupported type "string": string types are currently not supported. - - Unsupported type "string": string types are currently not supported. - - Unsupported type "string": string types are currently not supported. - - Unsupported type "string": string types are currently not supported. - - Unsupported type "tuple(bool a; bool b)": tuple types are currently not supported. - - Unsupported type "tuple(bool a; bool b)": tuple types are currently not supported. - - Unsupported type "tuple(bool; bool)": tuple types are currently not supported. - - Unsupported type "tuple(bool; dist bool)": tuple types are currently not supported. - - Unsupported type "tuple(bool; dist bool)": tuple types are currently not supported. + - Unsupported "f": function is a user-defined function. + - Unsupported "p.db": distribution type "dist bool". + - Unsupported "p.db": function call "constant(true)". + - Unsupported "p.db": function type "func dist bool(bool)". + - Unsupported "p.dbb": dictionary literal "{true: false}". + - Unsupported "p.dbb": dictionary type "dict(bool:bool)". + - Unsupported "p.fbb": function type "func bool(bool)". + - Unsupported "p.i": rangeless integer type "int". + - Unsupported "p.l": binary operator "*" on operands "p.r" and "p.r". + - Unsupported "p.l": binary operator "+" on operands "p.r" and "p.r". + - Unsupported "p.l": binary operator "-" on operands "p.r" and "p.r". + - Unsupported "p.l": binary operator "/": "p.r / p.r". + - Unsupported "p.l": binary operator "<" on operands "p.i" and "p.i". + - Unsupported "p.l": binary operator "<=" on operands "p.i" and "p.i". + - Unsupported "p.l": binary operator ">" on operands "p.i" and "p.i". + - Unsupported "p.l": binary operator ">=" on operands "p.i" and "p.i". + - Unsupported "p.l": binary operator "and" on operands "{true}" and "{false}". + - Unsupported "p.l": binary operator "div" on operands "p.i" and "p.i". + - Unsupported "p.l": binary operator "in": "true in p.sb". + - Unsupported "p.l": binary operator "mod" on operands "p.i" and "p.i". + - Unsupported "p.l": binary operator "or" on operands "{true}" and "{false}". + - Unsupported "p.l": binary operator "sub": "p.sb sub p.sb". + - Unsupported "p.l": conditional expression "if true: 1 else 2 end". + - Unsupported "p.l": dictionary literal "{true: true}". + - Unsupported "p.l": dictionary type "dict(bool:bool)". + - Unsupported "p.l": distribution type "dist bool". + - Unsupported "p.l": function type "func bool(bool)". + - Unsupported "p.l": list type "list bool". + - Unsupported "p.l": location has a state invariant. + - Unsupported "p.l": location has an edge with a multi-assignment. + - Unsupported "p.l": location has an edge with a partial variable assignment. + - Unsupported "p.l": projection expression "p.tbb[a]". + - Unsupported "p.l": rangeless integer type "int". + - Unsupported "p.l": real number literal "1.0". + - Unsupported "p.l": real type "real". + - Unsupported "p.l": set literal "{false}". + - Unsupported "p.l": set literal "{true}". + - Unsupported "p.l": set type "set bool". + - Unsupported "p.l": slice expression "p.lb[:]". + - Unsupported "p.l": string literal ""a"". + - Unsupported "p.l": string type "string". + - Unsupported "p.l": switch expression "switch 1: else 2 end". + - Unsupported "p.l": switch expression "switch p: case l: 3 end". + - Unsupported "p.l": time variable reference "time". + - Unsupported "p.l": tuple literal "(p.b, p.db)". + - Unsupported "p.l": tuple type "tuple(bool a; bool b)". + - Unsupported "p.l": tuple type "tuple(bool; dist bool)". + - Unsupported "p.l": type-changing cast expression "1". + - Unsupported "p.l": unary operator "+" on operand "p.i". + - Unsupported "p.l": unary operator "-" on operand "p.i". + - Unsupported "p.l": unary operator "sample": "sample p.db". + - Unsupported "p.lb": list literal "[true]". + - Unsupported "p.lb": list type "list bool". + - Unsupported "p.lb": list type "list[1] bool". + - Unsupported "p.r": real number literal "1.2". + - Unsupported "p.r": real type "real". + - Unsupported "p.sb": set literal "{true}". + - Unsupported "p.sb": set type "set bool". + - Unsupported "p.str": string literal ""a"". + - Unsupported "p.str": string type "string". + - Unsupported "p.tbb": tuple literal "(true, false)". + - Unsupported "p.tbb": tuple type "tuple(bool a; bool b)". + - Unsupported "p.tbb": tuple type "tuple(bool; bool)". diff --git a/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid3.cif b/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid3.cif index 184f9b83d..f47f45b55 100644 --- a/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid3.cif +++ b/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid3.cif @@ -12,7 +12,7 @@ ////////////////////////////////////////////////////////////////////////////// plant p: - disc bool b in any; + disc bool b in any; // Multiple potential initial values. location: initial b; // Non-static eval. diff --git a/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid3.cif.cif2supremica.err b/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid3.cif.cif2supremica.err index 8b289c213..c6fce43a5 100644 --- a/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid3.cif.cif2supremica.err +++ b/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid3.cif.cif2supremica.err @@ -1 +1,3 @@ -ERROR: Predicate "p.b" can not statically be evaluated to a single value. +ERROR: CIF to Supremica transformation failed due to unsatisfied preconditions: + - Unsupported "p": failed to determine whether the automaton's location is an initial location, as one of its initialization predicates can not be statically evaluated. + - Unsupported "p.b": discrete variable has multiple potential initial values. -- GitLab From 2f2ef056803282514e62d4fe1996834eb1ed78d0 Mon Sep 17 00:00:00 2001 From: Dennis Hendriks Date: Tue, 7 Jun 2022 22:59:36 +0200 Subject: [PATCH 12/23] #370 Addressed review comments for (precondition) checker changes. - CIF to Supremica precondition checker now checks for +/- on real. - As the test model already indicated. - Some JavaDoc improvements. - Improved some message resulting from checks. - Added missing all/range int 'disallows' for binary/unary expr checks. --- .../CifToSupremicaPreChecker.java | 2 + .../escet/cif/common/checkers/CifCheck.java | 5 +- .../common/checkers/CifCheckViolation.java | 8 +- .../checkers/NoIfUpdatesOnEdgesCheck.java | 2 +- .../checkers/NoKindlessAutomataCheck.java | 4 +- .../NoKindlessStateEvtExclInvsCheck.java | 11 +- .../checkers/NoSpecificBinaryExprsCheck.java | 279 +++++++++++++++--- .../checkers/NoSpecificUnaryExprsCheck.java | 38 ++- 8 files changed, 292 insertions(+), 57 deletions(-) diff --git a/cif/org.eclipse.escet.cif.cif2supremica/src/org/eclipse/escet/cif/cif2supremica/CifToSupremicaPreChecker.java b/cif/org.eclipse.escet.cif.cif2supremica/src/org/eclipse/escet/cif/cif2supremica/CifToSupremicaPreChecker.java index bebca9bbe..987b4db55 100644 --- a/cif/org.eclipse.escet.cif.cif2supremica/src/org/eclipse/escet/cif/cif2supremica/CifToSupremicaPreChecker.java +++ b/cif/org.eclipse.escet.cif.cif2supremica/src/org/eclipse/escet/cif/cif2supremica/CifToSupremicaPreChecker.java @@ -197,7 +197,9 @@ public class CifToSupremicaPreChecker { // operand, and plus (+) on a ranged integer operand. NoSpecificUnaryExprsCheck unCheck = new NoSpecificUnaryExprsCheck(); unCheck.disallowNegateIntsRangeless = true; + unCheck.disallowNegateReals = true; unCheck.disallowPlusIntsRangeless = true; + unCheck.disallowPlusReals = true; unCheck.disallowSample = true; preconditions.add(unCheck); diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifCheck.java index f53523087..dfa0eb182 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifCheck.java @@ -40,10 +40,11 @@ public abstract class CifCheck extends CifWalker { /** * Add a violation. * - * @param object The named CIF object for which the violation is reported, or {@code null} for report it for the CIF + * @param object The named CIF object for which the violation is reported, or {@code null} to report it for the CIF * specification. * @param message The message describing the violation. E.g., {@code "event is a channel"}, - * {@code "automaton is a kindless/regular automaton"} or {@code "specification has no automata"}. + * {@code "automaton is a kindless automaton, lacking a supervisory kind"} or + * {@code "specification has no automata"}. */ protected void addViolation(PositionObject object, String message) { violations.add(new CifCheckViolation(object, message)); diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifCheckViolation.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifCheckViolation.java index 89d99436f..bb6f2e830 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifCheckViolation.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifCheckViolation.java @@ -24,8 +24,7 @@ import org.eclipse.escet.common.position.metamodel.position.PositionObject; /** CIF check condition violation. */ public class CifCheckViolation { /** - * The named CIF object for which the violation is reported, or {@code null} for report it for the CIF - * specification. + * The named CIF object for which the violation is reported, or {@code null} to report it for the CIF specification. */ private final PositionObject object; @@ -35,10 +34,11 @@ public class CifCheckViolation { /** * Constructor for the {@link CifCheckViolation} class. * - * @param object The named CIF object for which the violation is reported, or {@code null} for report it for the CIF + * @param object The named CIF object for which the violation is reported, or {@code null} to report it for the CIF * specification. * @param message The message describing the violation. E.g., {@code "event is a channel"}, - * {@code "automaton is a kindless/regular automaton"} or {@code "specification has no automata"}. + * {@code "automaton is a kindless automaton, lacking a supervisory kind"} or + * {@code "specification has no automata"}. */ public CifCheckViolation(PositionObject object, String message) { this.object = object; diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoIfUpdatesOnEdgesCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoIfUpdatesOnEdgesCheck.java index 193a78403..5bc6a464b 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoIfUpdatesOnEdgesCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoIfUpdatesOnEdgesCheck.java @@ -20,7 +20,7 @@ import org.eclipse.escet.cif.metamodel.cif.automata.Location; import org.eclipse.escet.common.java.Assert; /** - * CIF check that does not 'if' updates on edges. + * CIF check that does not allow 'if' updates on edges. * * @note This check is included in {@link OnlySimpleAssignmentsCheck}. */ diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoKindlessAutomataCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoKindlessAutomataCheck.java index 9bed87b10..9de417766 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoKindlessAutomataCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoKindlessAutomataCheck.java @@ -16,12 +16,12 @@ package org.eclipse.escet.cif.common.checkers; import org.eclipse.escet.cif.metamodel.cif.SupKind; import org.eclipse.escet.cif.metamodel.cif.automata.Automaton; -/** CIF check that does not allow kindless/regular automata. */ +/** CIF check that does not allow kindless automata (without a supervisory kind). */ public class NoKindlessAutomataCheck extends CifCheck { @Override protected void preprocessAutomaton(Automaton aut) { if (aut.getKind() == SupKind.NONE) { - addViolation(aut, "automaton is a kindless/regular automaton"); + addViolation(aut, "automaton is a kindless automaton, lacking a supervisory kind"); } } } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoKindlessStateEvtExclInvsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoKindlessStateEvtExclInvsCheck.java index 698b0a104..5ca70de60 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoKindlessStateEvtExclInvsCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoKindlessStateEvtExclInvsCheck.java @@ -20,7 +20,7 @@ import org.eclipse.escet.cif.metamodel.cif.SupKind; import org.eclipse.escet.cif.metamodel.cif.automata.Automaton; import org.eclipse.escet.cif.metamodel.cif.automata.Location; -/** CIF check that does not allow kindless state/event exclusion invariants. */ +/** CIF check that does not allow kindless state/event exclusion invariants (without a supervisory kind). */ public class NoKindlessStateEvtExclInvsCheck extends CifCheck { @Override protected void preprocessComplexComponent(ComplexComponent comp) { @@ -28,7 +28,8 @@ public class NoKindlessStateEvtExclInvsCheck extends CifCheck { if (inv.getInvKind() == InvKind.EVENT_NEEDS || inv.getInvKind() == InvKind.EVENT_DISABLES) { SupKind supKind = inv.getSupKind(); if (supKind == SupKind.NONE) { - addViolation(comp, "component has a kindless state/event exclusion invariant"); + addViolation(comp, + "component has a kindless state/event exclusion invariant, lacking a supervisory kind"); } } } @@ -41,10 +42,12 @@ public class NoKindlessStateEvtExclInvsCheck extends CifCheck { SupKind supKind = inv.getSupKind(); if (supKind == SupKind.NONE) { if (loc.getName() != null) { - addViolation(loc, "location has a kindless state/event exclusion invariant"); + addViolation(loc, + "location has a kindless state/event exclusion invariant, lacking a supervisory kind"); } else { addViolation((Automaton)loc.eContainer(), - "automaton has a location with a kindless state/event exclusion invariant"); + "automaton has a location with a kindless state/event exclusion invariant, " + + "lacking a supervisory kind"); } } } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificBinaryExprsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificBinaryExprsCheck.java index 5f1e9c894..86fdf45a5 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificBinaryExprsCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificBinaryExprsCheck.java @@ -34,6 +34,12 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { /** Whether to disallow {@link BinaryOperator#ADDITION}. */ public boolean disallowAddition; + /** Whether to disallow {@link BinaryOperator#ADDITION} on integers. */ + public boolean disallowAdditionInts; + + /** Whether to disallow {@link BinaryOperator#ADDITION} on ranged integers. */ + public boolean disallowAdditionIntsRanged; + /** Whether to disallow {@link BinaryOperator#ADDITION} on rangeless integers. */ public boolean disallowAdditionIntsRangeless; @@ -85,6 +91,12 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { /** Whether to disallow {@link BinaryOperator#GREATER_EQUAL}. */ public boolean disallowGreaterEqual; + /** Whether to disallow {@link BinaryOperator#GREATER_EQUAL} on integers. */ + public boolean disallowGreaterEqualInts; + + /** Whether to disallow {@link BinaryOperator#GREATER_EQUAL} on ranged integers. */ + public boolean disallowGreaterEqualIntsRanged; + /** Whether to disallow {@link BinaryOperator#GREATER_EQUAL} on rangeless integers. */ public boolean disallowGreaterEqualIntsRangeless; @@ -94,6 +106,12 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { /** Whether to disallow {@link BinaryOperator#GREATER_THAN}. */ public boolean disallowGreaterThan; + /** Whether to disallow {@link BinaryOperator#GREATER_THAN} on integers. */ + public boolean disallowGreaterThanInts; + + /** Whether to disallow {@link BinaryOperator#GREATER_THAN} on ranged integers. */ + public boolean disallowGreaterThanIntsRanged; + /** Whether to disallow {@link BinaryOperator#GREATER_THAN} on rangeless integers. */ public boolean disallowGreaterThanIntsRangeless; @@ -106,12 +124,24 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { /** Whether to disallow {@link BinaryOperator#INTEGER_DIVISION}. */ public boolean disallowIntegerDivision; + /** Whether to disallow {@link BinaryOperator#INTEGER_DIVISION} on integers. */ + public boolean disallowIntegerDivisionInts; + + /** Whether to disallow {@link BinaryOperator#INTEGER_DIVISION} on ranged integers. */ + public boolean disallowIntegerDivisionIntsRanged; + /** Whether to disallow {@link BinaryOperator#INTEGER_DIVISION} on rangeless integers. */ public boolean disallowIntegerDivisionIntsRangeless; /** Whether to disallow {@link BinaryOperator#LESS_EQUAL}. */ public boolean disallowLessEqual; + /** Whether to disallow {@link BinaryOperator#LESS_EQUAL} on integers. */ + public boolean disallowLessEqualInts; + + /** Whether to disallow {@link BinaryOperator#LESS_EQUAL} on ranged integers. */ + public boolean disallowLessEqualIntsRanged; + /** Whether to disallow {@link BinaryOperator#LESS_EQUAL} on rangeless integers. */ public boolean disallowLessEqualIntsRangeless; @@ -121,6 +151,12 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { /** Whether to disallow {@link BinaryOperator#LESS_THAN}. */ public boolean disallowLessThan; + /** Whether to disallow {@link BinaryOperator#LESS_THAN} on integers. */ + public boolean disallowLessThanInts; + + /** Whether to disallow {@link BinaryOperator#LESS_THAN} on ranged integers. */ + public boolean disallowLessThanIntsRanged; + /** Whether to disallow {@link BinaryOperator#LESS_THAN} on rangeless integers. */ public boolean disallowLessThanIntsRangeless; @@ -130,12 +166,24 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { /** Whether to disallow {@link BinaryOperator#MODULUS}. */ public boolean disallowModulus; + /** Whether to disallow {@link BinaryOperator#MODULUS} on integers. */ + public boolean disallowModulusInts; + + /** Whether to disallow {@link BinaryOperator#MODULUS} on ranged integers. */ + public boolean disallowModulusIntsRanged; + /** Whether to disallow {@link BinaryOperator#MODULUS} on rangeless integers. */ public boolean disallowModulusIntsRangeless; /** Whether to disallow {@link BinaryOperator#MULTIPLICATION}. */ public boolean disallowMultiplication; + /** Whether to disallow {@link BinaryOperator#MULTIPLICATION} on integers. */ + public boolean disallowMultiplicationInts; + + /** Whether to disallow {@link BinaryOperator#MULTIPLICATION} on ranged integers. */ + public boolean disallowMultiplicationIntsRanged; + /** Whether to disallow {@link BinaryOperator#MULTIPLICATION} on rangeless integers. */ public boolean disallowMultiplicationIntsRangeless; @@ -148,6 +196,12 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { /** Whether to disallow {@link BinaryOperator#SUBTRACTION}. */ public boolean disallowSubtraction; + /** Whether to disallow {@link BinaryOperator#SUBTRACTION} on integers. */ + public boolean disallowSubtractionInts; + + /** Whether to disallow {@link BinaryOperator#SUBTRACTION} on ranged integers. */ + public boolean disallowSubtractionIntsRanged; + /** Whether to disallow {@link BinaryOperator#SUBTRACTION} on rangeless integers. */ public boolean disallowSubtractionIntsRangeless; @@ -174,14 +228,31 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { if (disallowAddition) { addExprViolationOperator(binExpr); } else { - if (disallowAdditionIntsRangeless) { + if (disallowAdditionInts) { CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); - if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) - || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) - { + if (ltype instanceof IntType || rtype instanceof IntType) { addExprViolationOperand(binExpr); } + } else { + if (disallowAdditionIntsRanged) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype))) + { + addExprViolationOperand(binExpr); + } + } + if (disallowAdditionIntsRangeless) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) + { + addExprViolationOperand(binExpr); + } + } } if (disallowAdditionReals) { CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); @@ -281,14 +352,31 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { if (disallowGreaterEqual) { addExprViolationOperator(binExpr); } else { - if (disallowGreaterEqualIntsRangeless) { + if (disallowGreaterEqualInts) { CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); - if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) - || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) - { + if (ltype instanceof IntType || rtype instanceof IntType) { addExprViolationOperand(binExpr); } + } else { + if (disallowGreaterEqualIntsRanged) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype))) + { + addExprViolationOperand(binExpr); + } + } + if (disallowGreaterEqualIntsRangeless) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) + { + addExprViolationOperand(binExpr); + } + } } if (disallowGreaterEqualReals) { CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); @@ -303,14 +391,31 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { if (disallowGreaterThan) { addExprViolationOperator(binExpr); } else { - if (disallowGreaterThanIntsRangeless) { + if (disallowGreaterThanInts) { CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); - if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) - || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) - { + if (ltype instanceof IntType || rtype instanceof IntType) { addExprViolationOperand(binExpr); } + } else { + if (disallowGreaterThanIntsRanged) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype))) + { + addExprViolationOperand(binExpr); + } + } + if (disallowGreaterThanIntsRangeless) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) + { + addExprViolationOperand(binExpr); + } + } } if (disallowGreaterThanReals) { CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); @@ -330,14 +435,31 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { if (disallowIntegerDivision) { addExprViolationOperator(binExpr); } else { - if (disallowIntegerDivisionIntsRangeless) { + if (disallowIntegerDivisionInts) { CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); - if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) - || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) - { + if (ltype instanceof IntType || rtype instanceof IntType) { addExprViolationOperand(binExpr); } + } else { + if (disallowIntegerDivisionIntsRanged) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype))) + { + addExprViolationOperand(binExpr); + } + } + if (disallowIntegerDivisionIntsRangeless) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) + { + addExprViolationOperand(binExpr); + } + } } } break; @@ -345,14 +467,31 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { if (disallowLessEqual) { addExprViolationOperator(binExpr); } else { - if (disallowLessEqualIntsRangeless) { + if (disallowLessEqualInts) { CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); - if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) - || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) - { + if (ltype instanceof IntType || rtype instanceof IntType) { addExprViolationOperand(binExpr); } + } else { + if (disallowLessEqualIntsRanged) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype))) + { + addExprViolationOperand(binExpr); + } + } + if (disallowLessEqualIntsRangeless) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) + { + addExprViolationOperand(binExpr); + } + } } if (disallowLessEqualReals) { CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); @@ -367,14 +506,31 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { if (disallowLessThan) { addExprViolationOperator(binExpr); } else { - if (disallowLessThanIntsRangeless) { + if (disallowLessThanInts) { CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); - if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) - || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) - { + if (ltype instanceof IntType || rtype instanceof IntType) { addExprViolationOperand(binExpr); } + } else { + if (disallowLessThanIntsRanged) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype))) + { + addExprViolationOperand(binExpr); + } + } + if (disallowLessThanIntsRangeless) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) + { + addExprViolationOperand(binExpr); + } + } } if (disallowLessThanReals) { CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); @@ -389,14 +545,31 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { if (disallowModulus) { addExprViolationOperator(binExpr); } else { - if (disallowModulusIntsRangeless) { + if (disallowModulusInts) { CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); - if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) - || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) - { + if (ltype instanceof IntType || rtype instanceof IntType) { addExprViolationOperand(binExpr); } + } else { + if (disallowModulusIntsRanged) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype))) + { + addExprViolationOperand(binExpr); + } + } + if (disallowModulusIntsRangeless) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) + { + addExprViolationOperand(binExpr); + } + } } } break; @@ -404,14 +577,31 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { if (disallowMultiplication) { addExprViolationOperator(binExpr); } else { - if (disallowMultiplicationIntsRangeless) { + if (disallowMultiplicationInts) { CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); - if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) - || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) - { + if (ltype instanceof IntType || rtype instanceof IntType) { addExprViolationOperand(binExpr); } + } else { + if (disallowMultiplicationIntsRanged) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype))) + { + addExprViolationOperand(binExpr); + } + } + if (disallowMultiplicationIntsRangeless) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) + { + addExprViolationOperand(binExpr); + } + } } if (disallowMultiplicationReals) { CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); @@ -431,14 +621,31 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { if (disallowSubtraction) { addExprViolationOperator(binExpr); } else { - if (disallowSubtractionIntsRangeless) { + if (disallowSubtractionInts) { CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); - if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) - || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) - { + if (ltype instanceof IntType || rtype instanceof IntType) { addExprViolationOperand(binExpr); } + } else { + if (disallowSubtractionIntsRanged) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype))) + { + addExprViolationOperand(binExpr); + } + } + if (disallowSubtractionIntsRangeless) { + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) + { + addExprViolationOperand(binExpr); + } + } } if (disallowSubtractionReals) { CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificUnaryExprsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificUnaryExprsCheck.java index 0868d45b3..237b43ac7 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificUnaryExprsCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificUnaryExprsCheck.java @@ -36,6 +36,9 @@ public class NoSpecificUnaryExprsCheck extends CifCheck { /** Whether to disallow {@link UnaryOperator#NEGATE} on integer numbers. */ public boolean disallowNegateInts; + /** Whether to disallow {@link UnaryOperator#NEGATE} on ranged integer numbers. */ + public boolean disallowNegateIntsRanged; + /** Whether to disallow {@link UnaryOperator#NEGATE} on rangeless integer numbers. */ public boolean disallowNegateIntsRangeless; @@ -48,6 +51,9 @@ public class NoSpecificUnaryExprsCheck extends CifCheck { /** Whether to disallow {@link UnaryOperator#PLUS} on integer numbers. */ public boolean disallowPlusInts; + /** Whether to disallow {@link UnaryOperator#PLUS} on ranged integer numbers. */ + public boolean disallowPlusIntsRanged; + /** Whether to disallow {@link UnaryOperator#PLUS} on rangeless integer numbers. */ public boolean disallowPlusIntsRangeless; @@ -75,10 +81,18 @@ public class NoSpecificUnaryExprsCheck extends CifCheck { if (ctype instanceof IntType) { addExprViolationOperand(unExpr); } - } else if (disallowNegateIntsRangeless) { - CifType ctype = CifTypeUtils.normalizeType(unExpr.getChild().getType()); - if (ctype instanceof IntType && CifTypeUtils.isRangeless((IntType)ctype)) { - addExprViolationOperand(unExpr); + } else { + if (disallowNegateIntsRanged) { + CifType ctype = CifTypeUtils.normalizeType(unExpr.getChild().getType()); + if (ctype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ctype)) { + addExprViolationOperand(unExpr); + } + } + if (disallowNegateIntsRangeless) { + CifType ctype = CifTypeUtils.normalizeType(unExpr.getChild().getType()); + if (ctype instanceof IntType && CifTypeUtils.isRangeless((IntType)ctype)) { + addExprViolationOperand(unExpr); + } } } if (disallowNegateReals) { @@ -98,10 +112,18 @@ public class NoSpecificUnaryExprsCheck extends CifCheck { if (ctype instanceof IntType) { addExprViolationOperand(unExpr); } - } else if (disallowPlusIntsRangeless) { - CifType ctype = CifTypeUtils.normalizeType(unExpr.getChild().getType()); - if (ctype instanceof IntType && CifTypeUtils.isRangeless((IntType)ctype)) { - addExprViolationOperand(unExpr); + } else { + if (disallowPlusIntsRanged) { + CifType ctype = CifTypeUtils.normalizeType(unExpr.getChild().getType()); + if (ctype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ctype)) { + addExprViolationOperand(unExpr); + } + } + if (disallowPlusIntsRangeless) { + CifType ctype = CifTypeUtils.normalizeType(unExpr.getChild().getType()); + if (ctype instanceof IntType && CifTypeUtils.isRangeless((IntType)ctype)) { + addExprViolationOperand(unExpr); + } } } if (disallowPlusReals) { -- GitLab From d98b2d9121ac7ea114fbd46e849d37f1674abb12 Mon Sep 17 00:00:00 2001 From: Dennis Hendriks Date: Tue, 7 Jun 2022 23:13:57 +0200 Subject: [PATCH 13/23] #370 Improved NoSpecific*Check violation messages. --- .../common/checkers/NoSpecificBinaryExprsCheck.java | 11 ++++++++--- .../cif/common/checkers/NoSpecificExprsCheck.java | 3 ++- .../cif/common/checkers/NoSpecificTypesCheck.java | 2 +- .../common/checkers/NoSpecificUnaryExprsCheck.java | 11 +++++++---- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificBinaryExprsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificBinaryExprsCheck.java index 86fdf45a5..a760ca6d6 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificBinaryExprsCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificBinaryExprsCheck.java @@ -16,6 +16,7 @@ package org.eclipse.escet.cif.common.checkers; import static org.eclipse.escet.cif.common.CifTextUtils.exprToStr; import static org.eclipse.escet.cif.common.CifTextUtils.getNamedAncestorOrSelf; import static org.eclipse.escet.cif.common.CifTextUtils.operatorToStr; +import static org.eclipse.escet.cif.common.CifTextUtils.typeToStr; import static org.eclipse.escet.common.java.Strings.fmt; import org.eclipse.escet.cif.common.CifTypeUtils; @@ -694,7 +695,8 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { */ private void addExprViolationOperator(BinaryExpression binExpr) { super.addViolation(getNamedAncestorOrSelf(binExpr), - fmt("binary operator \"%s\": \"%s\"", operatorToStr(binExpr.getOperator()), exprToStr(binExpr))); + fmt("uses binary operator \"%s\" in binary expression \"%s\"", operatorToStr(binExpr.getOperator()), + exprToStr(binExpr))); } /** @@ -703,7 +705,10 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { * @param binExpr The binary expression. */ private void addExprViolationOperand(BinaryExpression binExpr) { - super.addViolation(getNamedAncestorOrSelf(binExpr), fmt("binary operator \"%s\" on operands \"%s\" and \"%s\"", - operatorToStr(binExpr.getOperator()), exprToStr(binExpr.getLeft()), exprToStr(binExpr.getRight()))); + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); + super.addViolation(getNamedAncestorOrSelf(binExpr), + fmt("uses binary operator \"%s\" on operands of types \"%s\" and \"%s\" in binary expression \"%s\"", + operatorToStr(binExpr.getOperator()), typeToStr(ltype), typeToStr(rtype), exprToStr(binExpr))); } } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificExprsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificExprsCheck.java index ee5432bb7..366e86d94 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificExprsCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificExprsCheck.java @@ -495,6 +495,7 @@ public class NoSpecificExprsCheck extends CifCheck { * @param description The description of the expression. */ private void addExprViolation(Expression expr, String description) { - super.addViolation(getNamedAncestorOrSelf(expr), fmt("%s \"%s\"", description, exprToStr(expr))); + super.addViolation(getNamedAncestorOrSelf(expr), + fmt("uses %s \"%s\"", description, exprToStr(expr))); } } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificTypesCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificTypesCheck.java index ad894702d..89686c46b 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificTypesCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificTypesCheck.java @@ -188,6 +188,6 @@ public class NoSpecificTypesCheck extends CifCheck { * @param description The description of the type. */ private void addTypeViolation(CifType type, String description) { - super.addViolation(getNamedAncestorOrSelf(type), fmt("%s \"%s\"", description, typeToStr(type))); + super.addViolation(getNamedAncestorOrSelf(type), fmt("uses %s \"%s\"", description, typeToStr(type))); } } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificUnaryExprsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificUnaryExprsCheck.java index 237b43ac7..25b7710b1 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificUnaryExprsCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificUnaryExprsCheck.java @@ -16,6 +16,7 @@ package org.eclipse.escet.cif.common.checkers; import static org.eclipse.escet.cif.common.CifTextUtils.exprToStr; import static org.eclipse.escet.cif.common.CifTextUtils.getNamedAncestorOrSelf; import static org.eclipse.escet.cif.common.CifTextUtils.operatorToStr; +import static org.eclipse.escet.cif.common.CifTextUtils.typeToStr; import static org.eclipse.escet.common.java.Strings.fmt; import org.eclipse.escet.cif.common.CifTypeUtils; @@ -150,8 +151,8 @@ public class NoSpecificUnaryExprsCheck extends CifCheck { * @param unExpr The unary expression. */ private void addExprViolationOperator(UnaryExpression unExpr) { - super.addViolation(getNamedAncestorOrSelf(unExpr), - fmt("unary operator \"%s\": \"%s\"", operatorToStr(unExpr.getOperator()), exprToStr(unExpr))); + super.addViolation(getNamedAncestorOrSelf(unExpr), fmt("uses unary operator \"%s\" in unary expression \"%s\"", + operatorToStr(unExpr.getOperator()), exprToStr(unExpr))); } /** @@ -160,7 +161,9 @@ public class NoSpecificUnaryExprsCheck extends CifCheck { * @param unExpr The unary expression. */ private void addExprViolationOperand(UnaryExpression unExpr) { - super.addViolation(getNamedAncestorOrSelf(unExpr), fmt("unary operator \"%s\" on operand \"%s\"", - operatorToStr(unExpr.getOperator()), exprToStr(unExpr.getChild()))); + CifType ctype = CifTypeUtils.normalizeType(unExpr.getChild().getType()); + super.addViolation(getNamedAncestorOrSelf(unExpr), + fmt("uses unary operator \"%s\" on an operand of type \"%s\" in unary expression \"%s\"", + operatorToStr(unExpr.getOperator()), typeToStr(ctype), exprToStr(unExpr))); } } -- GitLab From b294ce7317042c6acc3ed74be24d8d6149c8e0d6 Mon Sep 17 00:00:00 2001 From: Dennis Hendriks Date: Tue, 7 Jun 2022 23:19:02 +0200 Subject: [PATCH 14/23] #370 Update CIF to Supremica tests expected output. --- .../invalid1.cif.cif2supremica.err | 60 ++++----- .../invalid2.cif.cif2supremica.err | 118 +++++++++--------- 2 files changed, 90 insertions(+), 88 deletions(-) diff --git a/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid1.cif.cif2supremica.err b/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid1.cif.cif2supremica.err index 50b7460b1..481e29d67 100644 --- a/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid1.cif.cif2supremica.err +++ b/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid1.cif.cif2supremica.err @@ -2,21 +2,21 @@ WARNING: File "cif2supremica/invalid1.cif": Semantic warning at line 31, column ERROR: CIF to Supremica transformation failed due to unsatisfied preconditions: - Unsupported "g": component contains an initialization predicate. - Unsupported "g": component has a kindless state invariant. - - Unsupported "g": component has a kindless state/event exclusion invariant. + - Unsupported "g": component has a kindless state/event exclusion invariant, lacking a supervisory kind. - Unsupported "g": component has a marker predicate that is not of the form "discrete_variable = marked_value". - Unsupported "g": component has a plant state invariant. - Unsupported "g": component has a supervisor state invariant. - - Unsupported "g": list literal "[false, true]". - - Unsupported "g": list literal "[false]". - - Unsupported "g": list literal "[true]". - - Unsupported "g": list type "list bool". - - Unsupported "g": list type "list[1] bool". - - Unsupported "g": list type "list[2] bool". - - Unsupported "g": real number literal "1.2". - - Unsupported "g": real type "real". + - Unsupported "g": uses list literal "[false, true]". + - Unsupported "g": uses list literal "[false]". + - Unsupported "g": uses list literal "[true]". + - Unsupported "g": uses list type "list bool". + - Unsupported "g": uses list type "list[1] bool". + - Unsupported "g": uses list type "list[2] bool". + - Unsupported "g": uses real number literal "1.2". + - Unsupported "g": uses real type "real". - Unsupported "g.a": automaton has an edge with explicitly event "tau" on it, which is not controllable or uncontrollable. - Unsupported "g.a": automaton has an edge with implicitly event "tau" on it, which is not controllable or uncontrollable. - - Unsupported "g.a": automaton is a kindless/regular automaton. + - Unsupported "g.a": automaton is a kindless automaton, lacking a supervisory kind. - Unsupported "g.e1": event is not declared as controllable or uncontrollable. - Unsupported "g.e2": event is a channel (has a data type). - Unsupported "g.f": function is a user-defined function. @@ -25,33 +25,35 @@ ERROR: CIF to Supremica transformation failed due to unsatisfied preconditions: - Unsupported "g.p0": automaton has an edge with an 'if' update. - Unsupported "g.p0": automaton has an urgent location. - Unsupported "g.p0": automaton has no initial location. - - Unsupported "g.p0": list type "list bool". - - Unsupported "g.p0": projection expression "g.p0.lb[0]". - - Unsupported "g.p0": tuple literal "(1, 2)". - - Unsupported "g.p0": tuple literal "(g.p0.x1, g.p0.x2)". - - Unsupported "g.p0": tuple type "tuple(int[1..1]; int[2..2])". - - Unsupported "g.p0": tuple type "tuple(int[1..2]; int[1..2])". - - Unsupported "g.p0.cnt": real number literal "1.0". - - Unsupported "g.p0.cnt": real type "real". + - Unsupported "g.p0": uses list type "list bool". + - Unsupported "g.p0": uses projection expression "g.p0.lb[0]". + - Unsupported "g.p0": uses tuple literal "(1, 2)". + - Unsupported "g.p0": uses tuple literal "(g.p0.x1, g.p0.x2)". + - Unsupported "g.p0": uses tuple type "tuple(int[1..1]; int[2..2])". + - Unsupported "g.p0": uses tuple type "tuple(int[1..2]; int[1..2])". + - Unsupported "g.p0.cnt": uses real number literal "1.0". + - Unsupported "g.p0.cnt": uses real type "real". - Unsupported "g.p0.cnt": variable is a continuous variable. - Unsupported "g.p0.inp": variable is an input variable. - Unsupported "g.p0.lb": discrete variable has multiple predicates to specify its marked values. - - Unsupported "g.p0.lb": list literal "[true]". - - Unsupported "g.p0.lb": list type "list bool". - - Unsupported "g.p0.lb": list type "list[1] bool". + - Unsupported "g.p0.lb": uses list literal "[true]". + - Unsupported "g.p0.lb": uses list type "list bool". + - Unsupported "g.p0.lb": uses list type "list[1] bool". - Unsupported "g.p0.x1": discrete variable has multiple (2) potential initial values. - Unsupported "g.p0.x1": discrete variable has multiple predicates to specify its marked values. - Unsupported "g.p0.x2": discrete variable has multiple potential initial values. - Unsupported "g.p1": automaton has a location with a marker predicate for which static evaluation resulted in an evaluation error. - Unsupported "g.p1": automaton has a location with a state invariant. - - Unsupported "g.p1": binary operator ">" on operands "sqrt(-1.0)" and "0". - - Unsupported "g.p1": binary operator ">" on operands "sqrt(-2.0)" and "0". - Unsupported "g.p1": failed to determine whether the automaton's location is an initial location, as evaluating one of its initialization predicates resulted in an evaluation error. - - Unsupported "g.p1": function call "sqrt(-1.0)". - - Unsupported "g.p1": function call "sqrt(-2.0)". - - Unsupported "g.p1": function type "func real(real)". - - Unsupported "g.p1": real number literal "1.0". - - Unsupported "g.p1": real number literal "2.0". - - Unsupported "g.p1": real type "real". + - Unsupported "g.p1": uses binary operator ">" on operands of types "real" and "int[0..0]" in binary expression "sqrt(-1.0) > 0". + - Unsupported "g.p1": uses binary operator ">" on operands of types "real" and "int[0..0]" in binary expression "sqrt(-2.0) > 0". + - Unsupported "g.p1": uses function call "sqrt(-1.0)". + - Unsupported "g.p1": uses function call "sqrt(-2.0)". + - Unsupported "g.p1": uses function type "func real(real)". + - Unsupported "g.p1": uses real number literal "1.0". + - Unsupported "g.p1": uses real number literal "2.0". + - Unsupported "g.p1": uses real type "real". + - Unsupported "g.p1": uses unary operator "-" on an operand of type "real" in unary expression "-1.0". + - Unsupported "g.p1": uses unary operator "-" on an operand of type "real" in unary expression "-2.0". - Unsupported "g.p2": automata has multiple (2) initial locations. - Unsupported "g.snd": automaton has an urgent edge. diff --git a/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid2.cif.cif2supremica.err b/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid2.cif.cif2supremica.err index d394d9e06..3f75bc28a 100644 --- a/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid2.cif.cif2supremica.err +++ b/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid2.cif.cif2supremica.err @@ -1,64 +1,64 @@ ERROR: CIF to Supremica transformation failed due to unsatisfied preconditions: - Unsupported "f": function is a user-defined function. - - Unsupported "p.db": distribution type "dist bool". - - Unsupported "p.db": function call "constant(true)". - - Unsupported "p.db": function type "func dist bool(bool)". - - Unsupported "p.dbb": dictionary literal "{true: false}". - - Unsupported "p.dbb": dictionary type "dict(bool:bool)". - - Unsupported "p.fbb": function type "func bool(bool)". - - Unsupported "p.i": rangeless integer type "int". - - Unsupported "p.l": binary operator "*" on operands "p.r" and "p.r". - - Unsupported "p.l": binary operator "+" on operands "p.r" and "p.r". - - Unsupported "p.l": binary operator "-" on operands "p.r" and "p.r". - - Unsupported "p.l": binary operator "/": "p.r / p.r". - - Unsupported "p.l": binary operator "<" on operands "p.i" and "p.i". - - Unsupported "p.l": binary operator "<=" on operands "p.i" and "p.i". - - Unsupported "p.l": binary operator ">" on operands "p.i" and "p.i". - - Unsupported "p.l": binary operator ">=" on operands "p.i" and "p.i". - - Unsupported "p.l": binary operator "and" on operands "{true}" and "{false}". - - Unsupported "p.l": binary operator "div" on operands "p.i" and "p.i". - - Unsupported "p.l": binary operator "in": "true in p.sb". - - Unsupported "p.l": binary operator "mod" on operands "p.i" and "p.i". - - Unsupported "p.l": binary operator "or" on operands "{true}" and "{false}". - - Unsupported "p.l": binary operator "sub": "p.sb sub p.sb". - - Unsupported "p.l": conditional expression "if true: 1 else 2 end". - - Unsupported "p.l": dictionary literal "{true: true}". - - Unsupported "p.l": dictionary type "dict(bool:bool)". - - Unsupported "p.l": distribution type "dist bool". - - Unsupported "p.l": function type "func bool(bool)". - - Unsupported "p.l": list type "list bool". + - Unsupported "p.db": uses distribution type "dist bool". + - Unsupported "p.db": uses function call "constant(true)". + - Unsupported "p.db": uses function type "func dist bool(bool)". + - Unsupported "p.dbb": uses dictionary literal "{true: false}". + - Unsupported "p.dbb": uses dictionary type "dict(bool:bool)". + - Unsupported "p.fbb": uses function type "func bool(bool)". + - Unsupported "p.i": uses rangeless integer type "int". - Unsupported "p.l": location has a state invariant. - Unsupported "p.l": location has an edge with a multi-assignment. - Unsupported "p.l": location has an edge with a partial variable assignment. - - Unsupported "p.l": projection expression "p.tbb[a]". - - Unsupported "p.l": rangeless integer type "int". - - Unsupported "p.l": real number literal "1.0". - - Unsupported "p.l": real type "real". - - Unsupported "p.l": set literal "{false}". - - Unsupported "p.l": set literal "{true}". - - Unsupported "p.l": set type "set bool". - - Unsupported "p.l": slice expression "p.lb[:]". - - Unsupported "p.l": string literal ""a"". - - Unsupported "p.l": string type "string". - - Unsupported "p.l": switch expression "switch 1: else 2 end". - - Unsupported "p.l": switch expression "switch p: case l: 3 end". - - Unsupported "p.l": time variable reference "time". - - Unsupported "p.l": tuple literal "(p.b, p.db)". - - Unsupported "p.l": tuple type "tuple(bool a; bool b)". - - Unsupported "p.l": tuple type "tuple(bool; dist bool)". - - Unsupported "p.l": type-changing cast expression "1". - - Unsupported "p.l": unary operator "+" on operand "p.i". - - Unsupported "p.l": unary operator "-" on operand "p.i". - - Unsupported "p.l": unary operator "sample": "sample p.db". - - Unsupported "p.lb": list literal "[true]". - - Unsupported "p.lb": list type "list bool". - - Unsupported "p.lb": list type "list[1] bool". - - Unsupported "p.r": real number literal "1.2". - - Unsupported "p.r": real type "real". - - Unsupported "p.sb": set literal "{true}". - - Unsupported "p.sb": set type "set bool". - - Unsupported "p.str": string literal ""a"". - - Unsupported "p.str": string type "string". - - Unsupported "p.tbb": tuple literal "(true, false)". - - Unsupported "p.tbb": tuple type "tuple(bool a; bool b)". - - Unsupported "p.tbb": tuple type "tuple(bool; bool)". + - Unsupported "p.l": uses binary operator "*" on operands of types "real" and "real" in binary expression "p.r * p.r". + - Unsupported "p.l": uses binary operator "+" on operands of types "real" and "real" in binary expression "p.r + p.r". + - Unsupported "p.l": uses binary operator "-" on operands of types "real" and "real" in binary expression "p.r - p.r". + - Unsupported "p.l": uses binary operator "/" in binary expression "p.r / p.r". + - Unsupported "p.l": uses binary operator "<" on operands of types "int" and "int" in binary expression "p.i < p.i". + - Unsupported "p.l": uses binary operator "<=" on operands of types "int" and "int" in binary expression "p.i <= p.i". + - Unsupported "p.l": uses binary operator ">" on operands of types "int" and "int" in binary expression "p.i > p.i". + - Unsupported "p.l": uses binary operator ">=" on operands of types "int" and "int" in binary expression "p.i >= p.i". + - Unsupported "p.l": uses binary operator "and" on operands of types "set bool" and "set bool" in binary expression "{true} and {false}". + - Unsupported "p.l": uses binary operator "div" on operands of types "int" and "int" in binary expression "p.i div p.i". + - Unsupported "p.l": uses binary operator "in" in binary expression "true in p.sb". + - Unsupported "p.l": uses binary operator "mod" on operands of types "int" and "int" in binary expression "p.i mod p.i". + - Unsupported "p.l": uses binary operator "or" on operands of types "set bool" and "set bool" in binary expression "{true} or {false}". + - Unsupported "p.l": uses binary operator "sub" in binary expression "p.sb sub p.sb". + - Unsupported "p.l": uses conditional expression "if true: 1 else 2 end". + - Unsupported "p.l": uses dictionary literal "{true: true}". + - Unsupported "p.l": uses dictionary type "dict(bool:bool)". + - Unsupported "p.l": uses distribution type "dist bool". + - Unsupported "p.l": uses function type "func bool(bool)". + - Unsupported "p.l": uses list type "list bool". + - Unsupported "p.l": uses projection expression "p.tbb[a]". + - Unsupported "p.l": uses rangeless integer type "int". + - Unsupported "p.l": uses real number literal "1.0". + - Unsupported "p.l": uses real type "real". + - Unsupported "p.l": uses set literal "{false}". + - Unsupported "p.l": uses set literal "{true}". + - Unsupported "p.l": uses set type "set bool". + - Unsupported "p.l": uses slice expression "p.lb[:]". + - Unsupported "p.l": uses string literal ""a"". + - Unsupported "p.l": uses string type "string". + - Unsupported "p.l": uses switch expression "switch 1: else 2 end". + - Unsupported "p.l": uses switch expression "switch p: case l: 3 end". + - Unsupported "p.l": uses time variable reference "time". + - Unsupported "p.l": uses tuple literal "(p.b, p.db)". + - Unsupported "p.l": uses tuple type "tuple(bool a; bool b)". + - Unsupported "p.l": uses tuple type "tuple(bool; dist bool)". + - Unsupported "p.l": uses type-changing cast expression "1". + - Unsupported "p.l": uses unary operator "+" on an operand of type "int" in unary expression "+p.i". + - Unsupported "p.l": uses unary operator "-" on an operand of type "int" in unary expression "-p.i". + - Unsupported "p.l": uses unary operator "sample" in unary expression "sample p.db". + - Unsupported "p.lb": uses list literal "[true]". + - Unsupported "p.lb": uses list type "list bool". + - Unsupported "p.lb": uses list type "list[1] bool". + - Unsupported "p.r": uses real number literal "1.2". + - Unsupported "p.r": uses real type "real". + - Unsupported "p.sb": uses set literal "{true}". + - Unsupported "p.sb": uses set type "set bool". + - Unsupported "p.str": uses string literal ""a"". + - Unsupported "p.str": uses string type "string". + - Unsupported "p.tbb": uses tuple literal "(true, false)". + - Unsupported "p.tbb": uses tuple type "tuple(bool a; bool b)". + - Unsupported "p.tbb": uses tuple type "tuple(bool; bool)". -- GitLab From 06e2b7baf24b2754e67468f61186fa0ea63893fb Mon Sep 17 00:00:00 2001 From: Dennis Hendriks Date: Fri, 10 Jun 2022 19:02:55 +0200 Subject: [PATCH 15/23] #370 Reduce duplicate statements for binary/unary expr checks. --- .../checkers/NoSpecificBinaryExprsCheck.java | 92 +------------------ .../checkers/NoSpecificUnaryExprsCheck.java | 9 +- 2 files changed, 3 insertions(+), 98 deletions(-) diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificBinaryExprsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificBinaryExprsCheck.java index a760ca6d6..bfd5af722 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificBinaryExprsCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificBinaryExprsCheck.java @@ -224,21 +224,19 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { @Override protected void preprocessBinaryExpression(BinaryExpression binExpr) { BinaryOperator op = binExpr.getOperator(); + CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); + CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); switch (op) { case ADDITION: if (disallowAddition) { addExprViolationOperator(binExpr); } else { if (disallowAdditionInts) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if (ltype instanceof IntType || rtype instanceof IntType) { addExprViolationOperand(binExpr); } } else { if (disallowAdditionIntsRanged) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype))) { @@ -246,8 +244,6 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { } } if (disallowAdditionIntsRangeless) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) { @@ -256,29 +252,21 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { } } if (disallowAdditionReals) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if (ltype instanceof RealType || rtype instanceof RealType) { addExprViolationOperand(binExpr); } } if (disallowAdditionLists) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if (ltype instanceof ListType || rtype instanceof ListType) { addExprViolationOperand(binExpr); } } if (disallowAdditionStrings) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if (ltype instanceof StringType || rtype instanceof StringType) { addExprViolationOperand(binExpr); } } if (disallowAdditionDicts) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if (ltype instanceof DictType || rtype instanceof DictType) { addExprViolationOperand(binExpr); } @@ -294,8 +282,6 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { if (disallowConjunction) { addExprViolationOperator(binExpr); } else if (disallowConjunctionSets) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if (ltype instanceof SetType || rtype instanceof SetType) { addExprViolationOperand(binExpr); } @@ -305,8 +291,6 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { if (disallowDisjunction) { addExprViolationOperator(binExpr); } else if (disallowDisjunctionSets) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if (ltype instanceof SetType || rtype instanceof SetType) { addExprViolationOperand(binExpr); } @@ -322,22 +306,16 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { addExprViolationOperator(binExpr); } else { if (disallowElementOfLists) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if (ltype instanceof ListType || rtype instanceof ListType) { addExprViolationOperand(binExpr); } } if (disallowElementOfSets) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if (ltype instanceof SetType || rtype instanceof SetType) { addExprViolationOperand(binExpr); } } if (disallowElementOfDicts) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if (ltype instanceof DictType || rtype instanceof DictType) { addExprViolationOperand(binExpr); } @@ -354,15 +332,11 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { addExprViolationOperator(binExpr); } else { if (disallowGreaterEqualInts) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if (ltype instanceof IntType || rtype instanceof IntType) { addExprViolationOperand(binExpr); } } else { if (disallowGreaterEqualIntsRanged) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype))) { @@ -370,8 +344,6 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { } } if (disallowGreaterEqualIntsRangeless) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) { @@ -380,8 +352,6 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { } } if (disallowGreaterEqualReals) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if (ltype instanceof RealType || rtype instanceof RealType) { addExprViolationOperand(binExpr); } @@ -393,15 +363,11 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { addExprViolationOperator(binExpr); } else { if (disallowGreaterThanInts) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if (ltype instanceof IntType || rtype instanceof IntType) { addExprViolationOperand(binExpr); } } else { if (disallowGreaterThanIntsRanged) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype))) { @@ -409,8 +375,6 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { } } if (disallowGreaterThanIntsRangeless) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) { @@ -419,8 +383,6 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { } } if (disallowGreaterThanReals) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if (ltype instanceof RealType || rtype instanceof RealType) { addExprViolationOperand(binExpr); } @@ -437,15 +399,11 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { addExprViolationOperator(binExpr); } else { if (disallowIntegerDivisionInts) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if (ltype instanceof IntType || rtype instanceof IntType) { addExprViolationOperand(binExpr); } } else { if (disallowIntegerDivisionIntsRanged) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype))) { @@ -453,8 +411,6 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { } } if (disallowIntegerDivisionIntsRangeless) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) { @@ -469,15 +425,11 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { addExprViolationOperator(binExpr); } else { if (disallowLessEqualInts) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if (ltype instanceof IntType || rtype instanceof IntType) { addExprViolationOperand(binExpr); } } else { if (disallowLessEqualIntsRanged) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype))) { @@ -485,8 +437,6 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { } } if (disallowLessEqualIntsRangeless) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) { @@ -495,8 +445,6 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { } } if (disallowLessEqualReals) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if (ltype instanceof RealType || rtype instanceof RealType) { addExprViolationOperand(binExpr); } @@ -508,15 +456,11 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { addExprViolationOperator(binExpr); } else { if (disallowLessThanInts) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if (ltype instanceof IntType || rtype instanceof IntType) { addExprViolationOperand(binExpr); } } else { if (disallowLessThanIntsRanged) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype))) { @@ -524,8 +468,6 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { } } if (disallowLessThanIntsRangeless) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) { @@ -534,8 +476,6 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { } } if (disallowLessThanReals) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if (ltype instanceof RealType || rtype instanceof RealType) { addExprViolationOperand(binExpr); } @@ -547,15 +487,11 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { addExprViolationOperator(binExpr); } else { if (disallowModulusInts) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if (ltype instanceof IntType || rtype instanceof IntType) { addExprViolationOperand(binExpr); } } else { if (disallowModulusIntsRanged) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype))) { @@ -563,8 +499,6 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { } } if (disallowModulusIntsRangeless) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) { @@ -579,15 +513,11 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { addExprViolationOperator(binExpr); } else { if (disallowMultiplicationInts) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if (ltype instanceof IntType || rtype instanceof IntType) { addExprViolationOperand(binExpr); } } else { if (disallowMultiplicationIntsRanged) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype))) { @@ -595,8 +525,6 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { } } if (disallowMultiplicationIntsRangeless) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) { @@ -605,8 +533,6 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { } } if (disallowMultiplicationReals) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if (ltype instanceof RealType || rtype instanceof RealType) { addExprViolationOperand(binExpr); } @@ -623,15 +549,11 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { addExprViolationOperator(binExpr); } else { if (disallowSubtractionInts) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if (ltype instanceof IntType || rtype instanceof IntType) { addExprViolationOperand(binExpr); } } else { if (disallowSubtractionIntsRanged) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype))) { @@ -639,8 +561,6 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { } } if (disallowSubtractionIntsRangeless) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) { @@ -649,29 +569,21 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { } } if (disallowSubtractionReals) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if (ltype instanceof RealType || rtype instanceof RealType) { addExprViolationOperand(binExpr); } } if (disallowSubtractionLists) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if (ltype instanceof ListType || rtype instanceof ListType) { addExprViolationOperand(binExpr); } } if (disallowSubtractionSets) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if (ltype instanceof SetType || rtype instanceof SetType) { addExprViolationOperand(binExpr); } } if (disallowSubtractionDicts) { - CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); - CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); if (ltype instanceof DictType || rtype instanceof DictType) { addExprViolationOperand(binExpr); } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificUnaryExprsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificUnaryExprsCheck.java index 25b7710b1..af759aa67 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificUnaryExprsCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificUnaryExprsCheck.java @@ -67,6 +67,7 @@ public class NoSpecificUnaryExprsCheck extends CifCheck { @Override protected void preprocessUnaryExpression(UnaryExpression unExpr) { UnaryOperator op = unExpr.getOperator(); + CifType ctype = CifTypeUtils.normalizeType(unExpr.getChild().getType()); switch (op) { case INVERSE: if (disallowInverse) { @@ -78,26 +79,22 @@ public class NoSpecificUnaryExprsCheck extends CifCheck { addExprViolationOperator(unExpr); } else { if (disallowNegateInts) { - CifType ctype = CifTypeUtils.normalizeType(unExpr.getChild().getType()); if (ctype instanceof IntType) { addExprViolationOperand(unExpr); } } else { if (disallowNegateIntsRanged) { - CifType ctype = CifTypeUtils.normalizeType(unExpr.getChild().getType()); if (ctype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ctype)) { addExprViolationOperand(unExpr); } } if (disallowNegateIntsRangeless) { - CifType ctype = CifTypeUtils.normalizeType(unExpr.getChild().getType()); if (ctype instanceof IntType && CifTypeUtils.isRangeless((IntType)ctype)) { addExprViolationOperand(unExpr); } } } if (disallowNegateReals) { - CifType ctype = CifTypeUtils.normalizeType(unExpr.getChild().getType()); if (ctype instanceof RealType) { addExprViolationOperand(unExpr); } @@ -109,26 +106,22 @@ public class NoSpecificUnaryExprsCheck extends CifCheck { addExprViolationOperator(unExpr); } else { if (disallowPlusInts) { - CifType ctype = CifTypeUtils.normalizeType(unExpr.getChild().getType()); if (ctype instanceof IntType) { addExprViolationOperand(unExpr); } } else { if (disallowPlusIntsRanged) { - CifType ctype = CifTypeUtils.normalizeType(unExpr.getChild().getType()); if (ctype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ctype)) { addExprViolationOperand(unExpr); } } if (disallowPlusIntsRangeless) { - CifType ctype = CifTypeUtils.normalizeType(unExpr.getChild().getType()); if (ctype instanceof IntType && CifTypeUtils.isRangeless((IntType)ctype)) { addExprViolationOperand(unExpr); } } } if (disallowPlusReals) { - CifType ctype = CifTypeUtils.normalizeType(unExpr.getChild().getType()); if (ctype instanceof RealType) { addExprViolationOperand(unExpr); } -- GitLab From ed320c5cb89c6a3743fbd9c9f0d65a86faa8f5c9 Mon Sep 17 00:00:00 2001 From: Dennis Hendriks Date: Fri, 10 Jun 2022 19:13:01 +0200 Subject: [PATCH 16/23] #370 Reduce number of nested 'ifs' for binary/unary expr checks. --- .../checkers/NoSpecificBinaryExprsCheck.java | 306 ++++++++---------- .../checkers/NoSpecificUnaryExprsCheck.java | 44 ++- 2 files changed, 146 insertions(+), 204 deletions(-) diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificBinaryExprsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificBinaryExprsCheck.java index bfd5af722..46de02be5 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificBinaryExprsCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificBinaryExprsCheck.java @@ -236,40 +236,30 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { addExprViolationOperand(binExpr); } } else { - if (disallowAdditionIntsRanged) { - if ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) - || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype))) - { - addExprViolationOperand(binExpr); - } - } - if (disallowAdditionIntsRangeless) { - if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) - || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) - { - addExprViolationOperand(binExpr); - } - } - } - if (disallowAdditionReals) { - if (ltype instanceof RealType || rtype instanceof RealType) { + if (disallowAdditionIntsRanged + && ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype)))) + { addExprViolationOperand(binExpr); } - } - if (disallowAdditionLists) { - if (ltype instanceof ListType || rtype instanceof ListType) { + if (disallowAdditionIntsRangeless + && ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype)))) + { addExprViolationOperand(binExpr); } } - if (disallowAdditionStrings) { - if (ltype instanceof StringType || rtype instanceof StringType) { - addExprViolationOperand(binExpr); - } + if (disallowAdditionReals && (ltype instanceof RealType || rtype instanceof RealType)) { + addExprViolationOperand(binExpr); } - if (disallowAdditionDicts) { - if (ltype instanceof DictType || rtype instanceof DictType) { - addExprViolationOperand(binExpr); - } + if (disallowAdditionLists && (ltype instanceof ListType || rtype instanceof ListType)) { + addExprViolationOperand(binExpr); + } + if (disallowAdditionStrings && (ltype instanceof StringType || rtype instanceof StringType)) { + addExprViolationOperand(binExpr); + } + if (disallowAdditionDicts && (ltype instanceof DictType || rtype instanceof DictType)) { + addExprViolationOperand(binExpr); } } break; @@ -281,19 +271,15 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { case CONJUNCTION: if (disallowConjunction) { addExprViolationOperator(binExpr); - } else if (disallowConjunctionSets) { - if (ltype instanceof SetType || rtype instanceof SetType) { - addExprViolationOperand(binExpr); - } + } else if (disallowConjunctionSets && (ltype instanceof SetType || rtype instanceof SetType)) { + addExprViolationOperand(binExpr); } break; case DISJUNCTION: if (disallowDisjunction) { addExprViolationOperator(binExpr); - } else if (disallowDisjunctionSets) { - if (ltype instanceof SetType || rtype instanceof SetType) { - addExprViolationOperand(binExpr); - } + } else if (disallowDisjunctionSets && (ltype instanceof SetType || rtype instanceof SetType)) { + addExprViolationOperand(binExpr); } break; case DIVISION: @@ -305,20 +291,14 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { if (disallowElementOf) { addExprViolationOperator(binExpr); } else { - if (disallowElementOfLists) { - if (ltype instanceof ListType || rtype instanceof ListType) { - addExprViolationOperand(binExpr); - } + if (disallowElementOfLists && (ltype instanceof ListType || rtype instanceof ListType)) { + addExprViolationOperand(binExpr); } - if (disallowElementOfSets) { - if (ltype instanceof SetType || rtype instanceof SetType) { - addExprViolationOperand(binExpr); - } + if (disallowElementOfSets && (ltype instanceof SetType || rtype instanceof SetType)) { + addExprViolationOperand(binExpr); } - if (disallowElementOfDicts) { - if (ltype instanceof DictType || rtype instanceof DictType) { - addExprViolationOperand(binExpr); - } + if (disallowElementOfDicts && (ltype instanceof DictType || rtype instanceof DictType)) { + addExprViolationOperand(binExpr); } } break; @@ -336,26 +316,22 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { addExprViolationOperand(binExpr); } } else { - if (disallowGreaterEqualIntsRanged) { - if ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) - || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype))) - { - addExprViolationOperand(binExpr); - } - } - if (disallowGreaterEqualIntsRangeless) { - if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) - || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) - { - addExprViolationOperand(binExpr); - } + if (disallowGreaterEqualIntsRanged + && ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype)))) + { + addExprViolationOperand(binExpr); } - } - if (disallowGreaterEqualReals) { - if (ltype instanceof RealType || rtype instanceof RealType) { + if (disallowGreaterEqualIntsRangeless + && ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype)))) + { addExprViolationOperand(binExpr); } } + if (disallowGreaterEqualReals && (ltype instanceof RealType || rtype instanceof RealType)) { + addExprViolationOperand(binExpr); + } } break; case GREATER_THAN: @@ -367,26 +343,22 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { addExprViolationOperand(binExpr); } } else { - if (disallowGreaterThanIntsRanged) { - if ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) - || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype))) - { - addExprViolationOperand(binExpr); - } - } - if (disallowGreaterThanIntsRangeless) { - if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) - || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) - { - addExprViolationOperand(binExpr); - } + if (disallowGreaterThanIntsRanged + && ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype)))) + { + addExprViolationOperand(binExpr); } - } - if (disallowGreaterThanReals) { - if (ltype instanceof RealType || rtype instanceof RealType) { + if (disallowGreaterThanIntsRangeless + && ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype)))) + { addExprViolationOperand(binExpr); } } + if (disallowGreaterThanReals && (ltype instanceof RealType || rtype instanceof RealType)) { + addExprViolationOperand(binExpr); + } } break; case IMPLICATION: @@ -403,19 +375,17 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { addExprViolationOperand(binExpr); } } else { - if (disallowIntegerDivisionIntsRanged) { - if ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) - || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype))) - { - addExprViolationOperand(binExpr); - } + if (disallowIntegerDivisionIntsRanged + && ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype)))) + { + addExprViolationOperand(binExpr); } - if (disallowIntegerDivisionIntsRangeless) { - if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) - || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) - { - addExprViolationOperand(binExpr); - } + if (disallowIntegerDivisionIntsRangeless + && ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype)))) + { + addExprViolationOperand(binExpr); } } } @@ -429,26 +399,22 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { addExprViolationOperand(binExpr); } } else { - if (disallowLessEqualIntsRanged) { - if ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) - || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype))) - { - addExprViolationOperand(binExpr); - } - } - if (disallowLessEqualIntsRangeless) { - if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) - || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) - { - addExprViolationOperand(binExpr); - } + if (disallowLessEqualIntsRanged + && ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype)))) + { + addExprViolationOperand(binExpr); } - } - if (disallowLessEqualReals) { - if (ltype instanceof RealType || rtype instanceof RealType) { + if (disallowLessEqualIntsRangeless + && ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype)))) + { addExprViolationOperand(binExpr); } } + if (disallowLessEqualReals && (ltype instanceof RealType || rtype instanceof RealType)) { + addExprViolationOperand(binExpr); + } } break; case LESS_THAN: @@ -460,26 +426,22 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { addExprViolationOperand(binExpr); } } else { - if (disallowLessThanIntsRanged) { - if ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) - || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype))) - { - addExprViolationOperand(binExpr); - } - } - if (disallowLessThanIntsRangeless) { - if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) - || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) - { - addExprViolationOperand(binExpr); - } + if (disallowLessThanIntsRanged + && ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype)))) + { + addExprViolationOperand(binExpr); } - } - if (disallowLessThanReals) { - if (ltype instanceof RealType || rtype instanceof RealType) { + if (disallowLessThanIntsRangeless + && ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype)))) + { addExprViolationOperand(binExpr); } } + if (disallowLessThanReals && (ltype instanceof RealType || rtype instanceof RealType)) { + addExprViolationOperand(binExpr); + } } break; case MODULUS: @@ -491,19 +453,17 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { addExprViolationOperand(binExpr); } } else { - if (disallowModulusIntsRanged) { - if ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) - || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype))) - { - addExprViolationOperand(binExpr); - } + if (disallowModulusIntsRanged + && ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype)))) + { + addExprViolationOperand(binExpr); } - if (disallowModulusIntsRangeless) { - if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) - || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) - { - addExprViolationOperand(binExpr); - } + if (disallowModulusIntsRangeless + && ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype)))) + { + addExprViolationOperand(binExpr); } } } @@ -517,26 +477,22 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { addExprViolationOperand(binExpr); } } else { - if (disallowMultiplicationIntsRanged) { - if ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) - || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype))) - { - addExprViolationOperand(binExpr); - } - } - if (disallowMultiplicationIntsRangeless) { - if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) - || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) - { - addExprViolationOperand(binExpr); - } + if (disallowMultiplicationIntsRanged + && ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype)))) + { + addExprViolationOperand(binExpr); } - } - if (disallowMultiplicationReals) { - if (ltype instanceof RealType || rtype instanceof RealType) { + if (disallowMultiplicationIntsRangeless + && ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype)))) + { addExprViolationOperand(binExpr); } } + if (disallowMultiplicationReals && (ltype instanceof RealType || rtype instanceof RealType)) { + addExprViolationOperand(binExpr); + } } break; case SUBSET: @@ -553,40 +509,30 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { addExprViolationOperand(binExpr); } } else { - if (disallowSubtractionIntsRanged) { - if ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) - || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype))) - { - addExprViolationOperand(binExpr); - } - } - if (disallowSubtractionIntsRangeless) { - if ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) - || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype))) - { - addExprViolationOperand(binExpr); - } - } - } - if (disallowSubtractionReals) { - if (ltype instanceof RealType || rtype instanceof RealType) { + if (disallowSubtractionIntsRanged + && ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype)))) + { addExprViolationOperand(binExpr); } - } - if (disallowSubtractionLists) { - if (ltype instanceof ListType || rtype instanceof ListType) { + if (disallowSubtractionIntsRangeless + && ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) + || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype)))) + { addExprViolationOperand(binExpr); } } - if (disallowSubtractionSets) { - if (ltype instanceof SetType || rtype instanceof SetType) { - addExprViolationOperand(binExpr); - } + if (disallowSubtractionReals && (ltype instanceof RealType || rtype instanceof RealType)) { + addExprViolationOperand(binExpr); } - if (disallowSubtractionDicts) { - if (ltype instanceof DictType || rtype instanceof DictType) { - addExprViolationOperand(binExpr); - } + if (disallowSubtractionLists && (ltype instanceof ListType || rtype instanceof ListType)) { + addExprViolationOperand(binExpr); + } + if (disallowSubtractionSets && (ltype instanceof SetType || rtype instanceof SetType)) { + addExprViolationOperand(binExpr); + } + if (disallowSubtractionDicts && (ltype instanceof DictType || rtype instanceof DictType)) { + addExprViolationOperand(binExpr); } } break; diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificUnaryExprsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificUnaryExprsCheck.java index af759aa67..989a51599 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificUnaryExprsCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificUnaryExprsCheck.java @@ -83,22 +83,20 @@ public class NoSpecificUnaryExprsCheck extends CifCheck { addExprViolationOperand(unExpr); } } else { - if (disallowNegateIntsRanged) { - if (ctype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ctype)) { - addExprViolationOperand(unExpr); - } - } - if (disallowNegateIntsRangeless) { - if (ctype instanceof IntType && CifTypeUtils.isRangeless((IntType)ctype)) { - addExprViolationOperand(unExpr); - } + if (disallowNegateIntsRanged && ctype instanceof IntType + && !CifTypeUtils.isRangeless((IntType)ctype)) + { + addExprViolationOperand(unExpr); } - } - if (disallowNegateReals) { - if (ctype instanceof RealType) { + if (disallowNegateIntsRangeless && ctype instanceof IntType + && CifTypeUtils.isRangeless((IntType)ctype)) + { addExprViolationOperand(unExpr); } } + if (disallowNegateReals && ctype instanceof RealType) { + addExprViolationOperand(unExpr); + } } break; case PLUS: @@ -110,22 +108,20 @@ public class NoSpecificUnaryExprsCheck extends CifCheck { addExprViolationOperand(unExpr); } } else { - if (disallowPlusIntsRanged) { - if (ctype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ctype)) { - addExprViolationOperand(unExpr); - } - } - if (disallowPlusIntsRangeless) { - if (ctype instanceof IntType && CifTypeUtils.isRangeless((IntType)ctype)) { - addExprViolationOperand(unExpr); - } + if (disallowPlusIntsRanged && ctype instanceof IntType + && !CifTypeUtils.isRangeless((IntType)ctype)) + { + addExprViolationOperand(unExpr); } - } - if (disallowPlusReals) { - if (ctype instanceof RealType) { + if (disallowPlusIntsRangeless && ctype instanceof IntType + && CifTypeUtils.isRangeless((IntType)ctype)) + { addExprViolationOperand(unExpr); } } + if (disallowPlusReals && ctype instanceof RealType) { + addExprViolationOperand(unExpr); + } } break; case SAMPLE: -- GitLab From 72d3055272df06291c53e9940a880d127f759bac Mon Sep 17 00:00:00 2001 From: Dennis Hendriks Date: Fri, 10 Jun 2022 19:24:57 +0200 Subject: [PATCH 17/23] #370 Various small improvements to CIF checkers. --- .../src/org/eclipse/escet/cif/common/CifTextUtils.java | 2 +- .../checkers/NoDiscVarsWithMultiInitValuesCheck.java | 2 +- .../cif/common/checkers/NoSpecificBinaryExprsCheck.java | 6 +++--- .../escet/cif/common/checkers/NoSpecificExprsCheck.java | 4 ++-- .../escet/cif/common/checkers/NoSpecificTypesCheck.java | 4 ++-- .../cif/common/checkers/NoSpecificUnaryExprsCheck.java | 6 +++--- .../checkers/OnlyStaticEvalMarkerPredsInLocsCheck.java | 8 ++++---- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/CifTextUtils.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/CifTextUtils.java index 956729a30..f9aba5eba 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/CifTextUtils.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/CifTextUtils.java @@ -1335,7 +1335,7 @@ public class CifTextUtils { * @param obj The given object. * @return The given object itself (if named), its closest named ancestor (if any), or {@code null} (otherwise). */ - public static PositionObject getNamedAncestorOrSelf(PositionObject obj) { + public static PositionObject getNamedSelfOrAncestor(PositionObject obj) { PositionObject cur = obj; while (cur != null && !hasName(cur)) { cur = (PositionObject)cur.eContainer(); diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoDiscVarsWithMultiInitValuesCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoDiscVarsWithMultiInitValuesCheck.java index f2d5c3c21..7c0a9b3b8 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoDiscVarsWithMultiInitValuesCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoDiscVarsWithMultiInitValuesCheck.java @@ -37,7 +37,7 @@ public class NoDiscVarsWithMultiInitValuesCheck extends CifCheck { // Check number of potential initial values. int count = var.getValue().getValues().size(); if (count == 0) { // 0 means 'any' initial value. - addViolation(var, fmt("discrete variable has multiple potential initial values", count)); + addViolation(var, "discrete variable has multiple (\"any\" value in its domain) potential initial values"); } else if (count > 1) { addViolation(var, fmt("discrete variable has multiple (%d) potential initial values", count)); } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificBinaryExprsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificBinaryExprsCheck.java index 46de02be5..e7b93e315 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificBinaryExprsCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificBinaryExprsCheck.java @@ -14,7 +14,7 @@ package org.eclipse.escet.cif.common.checkers; import static org.eclipse.escet.cif.common.CifTextUtils.exprToStr; -import static org.eclipse.escet.cif.common.CifTextUtils.getNamedAncestorOrSelf; +import static org.eclipse.escet.cif.common.CifTextUtils.getNamedSelfOrAncestor; import static org.eclipse.escet.cif.common.CifTextUtils.operatorToStr; import static org.eclipse.escet.cif.common.CifTextUtils.typeToStr; import static org.eclipse.escet.common.java.Strings.fmt; @@ -552,7 +552,7 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { * @param binExpr The binary expression. */ private void addExprViolationOperator(BinaryExpression binExpr) { - super.addViolation(getNamedAncestorOrSelf(binExpr), + super.addViolation(getNamedSelfOrAncestor(binExpr), fmt("uses binary operator \"%s\" in binary expression \"%s\"", operatorToStr(binExpr.getOperator()), exprToStr(binExpr))); } @@ -565,7 +565,7 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { private void addExprViolationOperand(BinaryExpression binExpr) { CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); - super.addViolation(getNamedAncestorOrSelf(binExpr), + super.addViolation(getNamedSelfOrAncestor(binExpr), fmt("uses binary operator \"%s\" on operands of types \"%s\" and \"%s\" in binary expression \"%s\"", operatorToStr(binExpr.getOperator()), typeToStr(ltype), typeToStr(rtype), exprToStr(binExpr))); } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificExprsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificExprsCheck.java index 366e86d94..52f09c8ad 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificExprsCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificExprsCheck.java @@ -14,7 +14,7 @@ package org.eclipse.escet.cif.common.checkers; import static org.eclipse.escet.cif.common.CifTextUtils.exprToStr; -import static org.eclipse.escet.cif.common.CifTextUtils.getNamedAncestorOrSelf; +import static org.eclipse.escet.cif.common.CifTextUtils.getNamedSelfOrAncestor; import static org.eclipse.escet.common.java.Strings.fmt; import org.eclipse.emf.ecore.EObject; @@ -495,7 +495,7 @@ public class NoSpecificExprsCheck extends CifCheck { * @param description The description of the expression. */ private void addExprViolation(Expression expr, String description) { - super.addViolation(getNamedAncestorOrSelf(expr), + super.addViolation(getNamedSelfOrAncestor(expr), fmt("uses %s \"%s\"", description, exprToStr(expr))); } } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificTypesCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificTypesCheck.java index 89686c46b..d42e40b39 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificTypesCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificTypesCheck.java @@ -13,7 +13,7 @@ package org.eclipse.escet.cif.common.checkers; -import static org.eclipse.escet.cif.common.CifTextUtils.getNamedAncestorOrSelf; +import static org.eclipse.escet.cif.common.CifTextUtils.getNamedSelfOrAncestor; import static org.eclipse.escet.cif.common.CifTextUtils.typeToStr; import static org.eclipse.escet.common.java.Strings.fmt; @@ -188,6 +188,6 @@ public class NoSpecificTypesCheck extends CifCheck { * @param description The description of the type. */ private void addTypeViolation(CifType type, String description) { - super.addViolation(getNamedAncestorOrSelf(type), fmt("uses %s \"%s\"", description, typeToStr(type))); + super.addViolation(getNamedSelfOrAncestor(type), fmt("uses %s \"%s\"", description, typeToStr(type))); } } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificUnaryExprsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificUnaryExprsCheck.java index 989a51599..a7e93c582 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificUnaryExprsCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificUnaryExprsCheck.java @@ -14,7 +14,7 @@ package org.eclipse.escet.cif.common.checkers; import static org.eclipse.escet.cif.common.CifTextUtils.exprToStr; -import static org.eclipse.escet.cif.common.CifTextUtils.getNamedAncestorOrSelf; +import static org.eclipse.escet.cif.common.CifTextUtils.getNamedSelfOrAncestor; import static org.eclipse.escet.cif.common.CifTextUtils.operatorToStr; import static org.eclipse.escet.cif.common.CifTextUtils.typeToStr; import static org.eclipse.escet.common.java.Strings.fmt; @@ -140,7 +140,7 @@ public class NoSpecificUnaryExprsCheck extends CifCheck { * @param unExpr The unary expression. */ private void addExprViolationOperator(UnaryExpression unExpr) { - super.addViolation(getNamedAncestorOrSelf(unExpr), fmt("uses unary operator \"%s\" in unary expression \"%s\"", + super.addViolation(getNamedSelfOrAncestor(unExpr), fmt("uses unary operator \"%s\" in unary expression \"%s\"", operatorToStr(unExpr.getOperator()), exprToStr(unExpr))); } @@ -151,7 +151,7 @@ public class NoSpecificUnaryExprsCheck extends CifCheck { */ private void addExprViolationOperand(UnaryExpression unExpr) { CifType ctype = CifTypeUtils.normalizeType(unExpr.getChild().getType()); - super.addViolation(getNamedAncestorOrSelf(unExpr), + super.addViolation(getNamedSelfOrAncestor(unExpr), fmt("uses unary operator \"%s\" on an operand of type \"%s\" in unary expression \"%s\"", operatorToStr(unExpr.getOperator()), typeToStr(ctype), exprToStr(unExpr))); } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyStaticEvalMarkerPredsInLocsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyStaticEvalMarkerPredsInLocsCheck.java index 3e653bae5..b526c5256 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyStaticEvalMarkerPredsInLocsCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyStaticEvalMarkerPredsInLocsCheck.java @@ -45,11 +45,11 @@ public class OnlyStaticEvalMarkerPredsInLocsCheck extends CifCheck { } } catch (CifEvalException e) { if (loc.getName() != null) { - addViolation(loc, "location has a marker predicate for which static evaluation " - + "resulted in an evaluation error"); + addViolation(loc, + "static evaluation of a marker predicate in the location resulted in an evaluation error"); } else { - addViolation((Automaton)loc.eContainer(), "automaton has a location with a marker predicate for " - + "which static evaluation resulted in an evaluation error"); + addViolation((Automaton)loc.eContainer(), "static evaluation of a marker predicate in the " + + "location of the automaton resulted in an evaluation error"); } } } -- GitLab From aecfcc8de896230565af8ada96a0cdf20d148648 Mon Sep 17 00:00:00 2001 From: Dennis Hendriks Date: Fri, 10 Jun 2022 19:40:48 +0200 Subject: [PATCH 18/23] #370 Various CIF checker and composite walker improvements. --- .../CifToSupremicaPreChecker.java | 10 +-- .../escet/cif/common/checkers/CifCheck.java | 8 +-- .../common/checkers/CifCheckViolation.java | 26 +++---- .../escet/cif/common/checkers/CifChecker.java | 21 ------ .../checkers/CifPreconditionChecker.java | 69 +++++++++++++++++++ .../metamodel/java/CompositeCifWalker.java | 2 +- .../codegen/java/ModelWalkerGenerator.java | 2 +- 7 files changed, 90 insertions(+), 48 deletions(-) create mode 100644 cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifPreconditionChecker.java diff --git a/cif/org.eclipse.escet.cif.cif2supremica/src/org/eclipse/escet/cif/cif2supremica/CifToSupremicaPreChecker.java b/cif/org.eclipse.escet.cif.cif2supremica/src/org/eclipse/escet/cif/cif2supremica/CifToSupremicaPreChecker.java index 987b4db55..46d6b05b1 100644 --- a/cif/org.eclipse.escet.cif.cif2supremica/src/org/eclipse/escet/cif/cif2supremica/CifToSupremicaPreChecker.java +++ b/cif/org.eclipse.escet.cif.cif2supremica/src/org/eclipse/escet/cif/cif2supremica/CifToSupremicaPreChecker.java @@ -16,11 +16,9 @@ package org.eclipse.escet.cif.cif2supremica; import static org.eclipse.escet.common.java.Lists.list; import java.util.List; -import java.util.Set; import org.eclipse.escet.cif.common.checkers.CifCheck; -import org.eclipse.escet.cif.common.checkers.CifCheckViolation; -import org.eclipse.escet.cif.common.checkers.CifChecker; +import org.eclipse.escet.cif.common.checkers.CifPreconditionChecker; import org.eclipse.escet.cif.common.checkers.NoChannelsCheck; import org.eclipse.escet.cif.common.checkers.NoContinuousVariablesCheck; import org.eclipse.escet.cif.common.checkers.NoDiscVarsWithMultiInitValuesCheck; @@ -204,10 +202,6 @@ public class CifToSupremicaPreChecker { preconditions.add(unCheck); // Perform precondition check. - CifChecker checker = new CifChecker(preconditions); - Set violations = checker.check(spec); - if (!violations.isEmpty()) { - CifChecker.reportPreconditionViolations(violations, "CIF to Supremica transformation"); - } + new CifPreconditionChecker(preconditions).reportPreconditionViolations(spec, "CIF to Supremica transformation"); } } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifCheck.java index dfa0eb182..42ea0262c 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifCheck.java @@ -40,13 +40,13 @@ public abstract class CifCheck extends CifWalker { /** * Add a violation. * - * @param object The named CIF object for which the violation is reported, or {@code null} to report it for the CIF - * specification. + * @param cifObject The named CIF object for which the violation is reported, or {@code null} to report it for the + * CIF specification. * @param message The message describing the violation. E.g., {@code "event is a channel"}, * {@code "automaton is a kindless automaton, lacking a supervisory kind"} or * {@code "specification has no automata"}. */ - protected void addViolation(PositionObject object, String message) { - violations.add(new CifCheckViolation(object, message)); + protected void addViolation(PositionObject cifObject, String message) { + violations.add(new CifCheckViolation(cifObject, message)); } } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifCheckViolation.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifCheckViolation.java index bb6f2e830..ffb3c84f4 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifCheckViolation.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifCheckViolation.java @@ -26,7 +26,7 @@ public class CifCheckViolation { /** * The named CIF object for which the violation is reported, or {@code null} to report it for the CIF specification. */ - private final PositionObject object; + private final PositionObject cifObject; /** The message describing the violation. */ private final String message; @@ -34,40 +34,40 @@ public class CifCheckViolation { /** * Constructor for the {@link CifCheckViolation} class. * - * @param object The named CIF object for which the violation is reported, or {@code null} to report it for the CIF - * specification. + * @param cifObject The named CIF object for which the violation is reported, or {@code null} to report it for the + * CIF specification. * @param message The message describing the violation. E.g., {@code "event is a channel"}, * {@code "automaton is a kindless automaton, lacking a supervisory kind"} or * {@code "specification has no automata"}. */ - public CifCheckViolation(PositionObject object, String message) { - this.object = object; + public CifCheckViolation(PositionObject cifObject, String message) { + this.cifObject = cifObject; this.message = message; - if (object != null) { - Assert.check(CifTextUtils.hasName(object), object); + if (cifObject != null) { + Assert.check(CifTextUtils.hasName(cifObject), cifObject); } } @Override public boolean equals(Object obj) { - if (!(obj instanceof CifCheckViolation)) { - return false; - } if (this == obj) { return true; } + if (!(obj instanceof CifCheckViolation)) { + return false; + } CifCheckViolation that = (CifCheckViolation)obj; - return this.object == that.object && this.message.equals(that.message); + return this.cifObject == that.cifObject && this.message.equals(that.message); } @Override public int hashCode() { - return Objects.hash(object, message); + return Objects.hash(cifObject, message); } @Override public String toString() { - String name = (object == null) ? "specification" : "\"" + CifTextUtils.getAbsName(object) + "\""; + String name = (cifObject == null) ? "specification" : "\"" + CifTextUtils.getAbsName(cifObject) + "\""; return fmt("%s: %s.", name, message); } } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifChecker.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifChecker.java index 89b76fc8b..2f48f80d8 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifChecker.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifChecker.java @@ -15,16 +15,11 @@ package org.eclipse.escet.cif.common.checkers; import static org.eclipse.escet.common.java.Sets.set; -import java.util.Collections; import java.util.List; import java.util.Set; -import java.util.stream.Collectors; import org.eclipse.escet.cif.metamodel.cif.Specification; import org.eclipse.escet.cif.metamodel.java.CompositeCifWalker; -import org.eclipse.escet.common.app.framework.exceptions.UnsupportedException; -import org.eclipse.escet.common.java.Assert; -import org.eclipse.escet.common.java.Strings; /** CIF checker. Checks whether a given CIF specification satisfies certain {@link CifCheck conditions}. */ public class CifChecker extends CompositeCifWalker { @@ -69,20 +64,4 @@ public class CifChecker extends CompositeCifWalker { // Return the violations. return violations; } - - /** - * Reports a tool failed to execute due to precondition violations indicating the specification is unsupported. - * - * @param violations The precondition violations. Must not be empty. - * @param toolName The human-readable name of the tool. - * @throws UnsupportedException Always thrown. - */ - public static void reportPreconditionViolations(Set violations, String toolName) { - Assert.check(!violations.isEmpty()); - List messages = violations.stream().map(v -> "Unsupported " + v.toString()) - .collect(Collectors.toList()); - Collections.sort(messages, Strings.SORTER); - String msg = toolName + " failed due to unsatisfied preconditions:\n - " + String.join("\n - ", messages); - throw new UnsupportedException(msg); - } } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifPreconditionChecker.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifPreconditionChecker.java new file mode 100644 index 000000000..70eca5ae5 --- /dev/null +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifPreconditionChecker.java @@ -0,0 +1,69 @@ +////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2022 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available +// under the terms of the MIT License which is available at +// https://opensource.org/licenses/MIT +// +// SPDX-License-Identifier: MIT +////////////////////////////////////////////////////////////////////////////// + +package org.eclipse.escet.cif.common.checkers; + +import java.util.Collections; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +import org.eclipse.escet.cif.metamodel.cif.Specification; +import org.eclipse.escet.common.app.framework.exceptions.UnsupportedException; +import org.eclipse.escet.common.java.Strings; + +/** + * CIF precondition checker. Checks whether a given CIF specification satisfies certain {@link CifCheck preconditions}. + */ +public class CifPreconditionChecker extends CifChecker { + /** + * Constructor for the {@link CifPreconditionChecker} class. + * + * @param preconditions The preconditions to check. + */ + public CifPreconditionChecker(List preconditions) { + super(preconditions); + } + + /** + * Constructor for the {@link CifPreconditionChecker} class. + * + * @param preconditions The preconditions to check. + */ + public CifPreconditionChecker(CifCheck[] preconditions) { + super(preconditions); + } + + /** + * Check whether a given CIF specification satisfies its preconditions. If any of the preconditions is violated, + * report that the tool failed to execute due to precondition violations indicating that the specification is + * unsupported. + * + * @param spec The CIF specification to check. + * @param toolName The human-readable name of the tool. + * @throws UnsupportedException If there are any precondition violations. + */ + public void reportPreconditionViolations(Specification spec, String toolName) { + // Check specification. + Set violations = check(spec); + + // Report unsupported specification, if there are any precondition violations. + if (!violations.isEmpty()) { + List messages = violations.stream().map(v -> "Unsupported " + v.toString()) + .collect(Collectors.toList()); + Collections.sort(messages, Strings.SORTER); + String msg = toolName + " failed due to unsatisfied preconditions:\n - " + String.join("\n - ", messages); + throw new UnsupportedException(msg); + } + } +} diff --git a/cif/org.eclipse.escet.cif.metamodel.java/src-gen/org/eclipse/escet/cif/metamodel/java/CompositeCifWalker.java b/cif/org.eclipse.escet.cif.metamodel.java/src-gen/org/eclipse/escet/cif/metamodel/java/CompositeCifWalker.java index c631d9b34..8ac6d468a 100644 --- a/cif/org.eclipse.escet.cif.metamodel.java/src-gen/org/eclipse/escet/cif/metamodel/java/CompositeCifWalker.java +++ b/cif/org.eclipse.escet.cif.metamodel.java/src-gen/org/eclipse/escet/cif/metamodel/java/CompositeCifWalker.java @@ -182,7 +182,7 @@ import org.eclipse.escet.common.position.metamodel.position.PositionObject; */ public abstract class CompositeCifWalker extends CifWalker { /** The walkers to be composed by this composite walker. */ - private CifWalker[] walkers; + private final CifWalker[] walkers; /** * Constructor of the {@link CompositeCifWalker} class. diff --git a/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/java/ModelWalkerGenerator.java b/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/java/ModelWalkerGenerator.java index f6f74f40c..a63240abb 100644 --- a/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/java/ModelWalkerGenerator.java +++ b/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/java/ModelWalkerGenerator.java @@ -272,7 +272,7 @@ public class ModelWalkerGenerator extends EmfJavaCodeGenerator { // Add fields. box.indent(); box.add("/** The walkers to be composed by this composite walker. */"); - box.add("private %s[] walkers;", genClassNameWalker); + box.add("private final %s[] walkers;", genClassNameWalker); box.dedent(); box.add(); -- GitLab From 84fc573ee86ecd0ad7f7764040ea7b2042c403ef Mon Sep 17 00:00:00 2001 From: Dennis Hendriks Date: Fri, 10 Jun 2022 20:38:26 +0200 Subject: [PATCH 19/23] #370 Changed NoSpecific*Check.disallow* fields to enums. --- .../CifToSupremicaPreChecker.java | 121 ++-- .../checkers/NoSpecificBinaryExprsCheck.java | 553 ++++++++++-------- .../common/checkers/NoSpecificExprsCheck.java | 364 ++++++------ .../common/checkers/NoSpecificTypesCheck.java | 133 +++-- .../checkers/NoSpecificUnaryExprsCheck.java | 109 ++-- 5 files changed, 695 insertions(+), 585 deletions(-) diff --git a/cif/org.eclipse.escet.cif.cif2supremica/src/org/eclipse/escet/cif/cif2supremica/CifToSupremicaPreChecker.java b/cif/org.eclipse.escet.cif.cif2supremica/src/org/eclipse/escet/cif/cif2supremica/CifToSupremicaPreChecker.java index 46d6b05b1..e2689bf18 100644 --- a/cif/org.eclipse.escet.cif.cif2supremica/src/org/eclipse/escet/cif/cif2supremica/CifToSupremicaPreChecker.java +++ b/cif/org.eclipse.escet.cif.cif2supremica/src/org/eclipse/escet/cif/cif2supremica/CifToSupremicaPreChecker.java @@ -15,6 +15,7 @@ package org.eclipse.escet.cif.cif2supremica; import static org.eclipse.escet.common.java.Lists.list; +import java.util.EnumSet; import java.util.List; import org.eclipse.escet.cif.common.checkers.CifCheck; @@ -27,9 +28,13 @@ import org.eclipse.escet.cif.common.checkers.NoInputVariablesCheck; import org.eclipse.escet.cif.common.checkers.NoKindlessAutomataCheck; import org.eclipse.escet.cif.common.checkers.NoKindlessStateEvtExclInvsCheck; import org.eclipse.escet.cif.common.checkers.NoSpecificBinaryExprsCheck; +import org.eclipse.escet.cif.common.checkers.NoSpecificBinaryExprsCheck.NoSpecificBinaryOp; import org.eclipse.escet.cif.common.checkers.NoSpecificExprsCheck; +import org.eclipse.escet.cif.common.checkers.NoSpecificExprsCheck.NoSpecificExpr; import org.eclipse.escet.cif.common.checkers.NoSpecificTypesCheck; +import org.eclipse.escet.cif.common.checkers.NoSpecificTypesCheck.NoSpecificType; import org.eclipse.escet.cif.common.checkers.NoSpecificUnaryExprsCheck; +import org.eclipse.escet.cif.common.checkers.NoSpecificUnaryExprsCheck.NoSpecificUnaryOp; import org.eclipse.escet.cif.common.checkers.NoStateInvsInLocsCheck; import org.eclipse.escet.cif.common.checkers.NoUrgentEdgesCheck; import org.eclipse.escet.cif.common.checkers.NoUrgentLocationsCheck; @@ -123,35 +128,35 @@ public class CifToSupremicaPreChecker { preconditions.add(new NoChannelsCheck()); // Only the following data types are supported: boolean types, ranged integer types, and enumeration types. - NoSpecificTypesCheck typesCheck = new NoSpecificTypesCheck(); - typesCheck.disallowDictTypes = true; - typesCheck.disallowDistTypes = true; - typesCheck.disallowFuncTypes = true; // User-defined and stdlib both unsupported. - typesCheck.disallowIntTypesRangeless = true; - typesCheck.disallowListTypes = true; - typesCheck.disallowRealTypes = true; - typesCheck.disallowSetTypes = true; - typesCheck.disallowStringTypes = true; - typesCheck.disallowTupleTypes = true; // Tuples, tuple types, and multi-assignments are unsupported. + NoSpecificTypesCheck typesCheck = new NoSpecificTypesCheck(EnumSet.of( // + NoSpecificType.DICT_TYPES, // + NoSpecificType.DIST_TYPES, // + NoSpecificType.FUNC_TYPES, // + NoSpecificType.INT_TYPES_RANGELESS, // + NoSpecificType.LIST_TYPES, // + NoSpecificType.REAL_TYPES, // + NoSpecificType.SET_TYPES, // + NoSpecificType.STRING_TYPES, // + NoSpecificType.TUPLE_TYPES)); preconditions.add(typesCheck); // Only the following expressions are supported: boolean literal values, integer literal values, binary // expressions (partially, see below), unary expressions (partially, see below), and references to constants, // discrete variables, enumeration literals, and casts that don’t change the type. - NoSpecificExprsCheck exprsCheck = new NoSpecificExprsCheck(); - exprsCheck.disallowCastExprsNonEqualType = true; - exprsCheck.disallowDictLits = true; - exprsCheck.disallowFuncCalls = true; - exprsCheck.disallowIfExprs = true; - exprsCheck.disallowListLits = true; - exprsCheck.disallowProjectionExprs = true; - exprsCheck.disallowRealLits = true; - exprsCheck.disallowSetLits = true; - exprsCheck.disallowSliceExprs = true; - exprsCheck.disallowStringLits = true; - exprsCheck.disallowSwitchExprs = true; - exprsCheck.disallowTimeVarRefs = true; - exprsCheck.disallowTupleLits = true; + NoSpecificExprsCheck exprsCheck = new NoSpecificExprsCheck(EnumSet.of( // + NoSpecificExpr.CAST_EXPRS_NON_EQUAL_TYPE, // + NoSpecificExpr.DICT_LITS, // + NoSpecificExpr.FUNC_CALLS, // + NoSpecificExpr.IF_EXPRS, // + NoSpecificExpr.LIST_LITS, // + NoSpecificExpr.PROJECTION_EXPRS, // + NoSpecificExpr.REAL_LITS, // + NoSpecificExpr.SET_LITS, // + NoSpecificExpr.SLICE_EXPRS, // + NoSpecificExpr.STRING_LITS, // + NoSpecificExpr.SWITCH_EXPRS, // + NoSpecificExpr.TIME_VAR_REFS, // + NoSpecificExpr.TUPLE_LITS)); preconditions.add(exprsCheck); // Only the following binary operators are supported: logical equivalence (<=>), logical implication (=>), @@ -161,44 +166,44 @@ public class CifToSupremicaPreChecker { // inequality (!=), less than (<) on ranged integer operands, less than or equal to (<=) on ranged integer // operands, greater than (>) on ranged integer operands, and greater than or equal to (>=) on ranged integer // operands. - NoSpecificBinaryExprsCheck binCheck = new NoSpecificBinaryExprsCheck(); - binCheck.disallowConjunctionSets = true; - binCheck.disallowDisjunctionSets = true; - binCheck.disallowAdditionDicts = true; - binCheck.disallowAdditionIntsRangeless = true; - binCheck.disallowAdditionLists = true; - binCheck.disallowAdditionReals = true; - binCheck.disallowAdditionStrings = true; - binCheck.disallowSubtractionDicts = true; - binCheck.disallowSubtractionIntsRangeless = true; - binCheck.disallowSubtractionLists = true; - binCheck.disallowSubtractionReals = true; - binCheck.disallowSubtractionSets = true; - binCheck.disallowMultiplicationIntsRangeless = true; - binCheck.disallowMultiplicationReals = true; - binCheck.disallowIntegerDivisionIntsRangeless = true; - binCheck.disallowModulusIntsRangeless = true; - binCheck.disallowGreaterEqualIntsRangeless = true; - binCheck.disallowGreaterEqualReals = true; - binCheck.disallowGreaterThanIntsRangeless = true; - binCheck.disallowGreaterThanReals = true; - binCheck.disallowLessEqualIntsRangeless = true; - binCheck.disallowLessEqualReals = true; - binCheck.disallowLessThanIntsRangeless = true; - binCheck.disallowLessThanReals = true; - binCheck.disallowDivision = true; - binCheck.disallowElementOf = true; - binCheck.disallowSubset = true; + NoSpecificBinaryExprsCheck binCheck = new NoSpecificBinaryExprsCheck(EnumSet.of( // + NoSpecificBinaryOp.CONJUNCTION_SETS, // + NoSpecificBinaryOp.DISJUNCTION_SETS, // + NoSpecificBinaryOp.ADDITION_DICTS, // + NoSpecificBinaryOp.ADDITION_INTS_RANGELESS, // + NoSpecificBinaryOp.ADDITION_LISTS, // + NoSpecificBinaryOp.ADDITION_REALS, // + NoSpecificBinaryOp.ADDITION_STRINGS, // + NoSpecificBinaryOp.SUBTRACTION_DICTS, // + NoSpecificBinaryOp.SUBTRACTION_INTS_RANGELESS, // + NoSpecificBinaryOp.SUBTRACTION_LISTS, // + NoSpecificBinaryOp.SUBTRACTION_REALS, // + NoSpecificBinaryOp.SUBTRACTION_SETS, // + NoSpecificBinaryOp.MULTIPLICATION_INTS_RANGELESS, // + NoSpecificBinaryOp.MULTIPLICATION_REALS, // + NoSpecificBinaryOp.INTEGER_DIVISION_INTS_RANGELESS, // + NoSpecificBinaryOp.MODULUS_INTS_RANGELESS, // + NoSpecificBinaryOp.GREATER_EQUAL_INTS_RANGELESS, // + NoSpecificBinaryOp.GREATER_EQUAL_REALS, // + NoSpecificBinaryOp.GREATER_THAN_INTS_RANGELESS, // + NoSpecificBinaryOp.GREATER_THAN_REALS, // + NoSpecificBinaryOp.LESS_EQUAL_INTS_RANGELESS, // + NoSpecificBinaryOp.LESS_EQUAL_REALS, // + NoSpecificBinaryOp.LESS_THAN_INTS_RANGELESS, // + NoSpecificBinaryOp.LESS_THAN_REALS, // + NoSpecificBinaryOp.DIVISION, // + NoSpecificBinaryOp.ELEMENT_OF, // + NoSpecificBinaryOp.SUBSET)); preconditions.add(binCheck); // Only the following unary operators are supported: logical inverse (not), negation (-) on a ranged integer // operand, and plus (+) on a ranged integer operand. - NoSpecificUnaryExprsCheck unCheck = new NoSpecificUnaryExprsCheck(); - unCheck.disallowNegateIntsRangeless = true; - unCheck.disallowNegateReals = true; - unCheck.disallowPlusIntsRangeless = true; - unCheck.disallowPlusReals = true; - unCheck.disallowSample = true; + NoSpecificUnaryExprsCheck unCheck = new NoSpecificUnaryExprsCheck(EnumSet.of( // + NoSpecificUnaryOp.NEGATE_INTS_RANGELESS, // + NoSpecificUnaryOp.NEGATE_REALS, // + NoSpecificUnaryOp.PLUS_INTS_RANGELESS, // + NoSpecificUnaryOp.PLUS_REALS, // + NoSpecificUnaryOp.SAMPLE)); preconditions.add(unCheck); // Perform precondition check. diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificBinaryExprsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificBinaryExprsCheck.java index e7b93e315..89ae1bf97 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificBinaryExprsCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificBinaryExprsCheck.java @@ -19,6 +19,8 @@ import static org.eclipse.escet.cif.common.CifTextUtils.operatorToStr; import static org.eclipse.escet.cif.common.CifTextUtils.typeToStr; import static org.eclipse.escet.common.java.Strings.fmt; +import java.util.EnumSet; + import org.eclipse.escet.cif.common.CifTypeUtils; import org.eclipse.escet.cif.metamodel.cif.expressions.BinaryExpression; import org.eclipse.escet.cif.metamodel.cif.expressions.BinaryOperator; @@ -32,194 +34,17 @@ import org.eclipse.escet.cif.metamodel.cif.types.StringType; /** CIF check that does not allow certain binary expressions. */ public class NoSpecificBinaryExprsCheck extends CifCheck { - /** Whether to disallow {@link BinaryOperator#ADDITION}. */ - public boolean disallowAddition; - - /** Whether to disallow {@link BinaryOperator#ADDITION} on integers. */ - public boolean disallowAdditionInts; - - /** Whether to disallow {@link BinaryOperator#ADDITION} on ranged integers. */ - public boolean disallowAdditionIntsRanged; - - /** Whether to disallow {@link BinaryOperator#ADDITION} on rangeless integers. */ - public boolean disallowAdditionIntsRangeless; - - /** Whether to disallow {@link BinaryOperator#ADDITION} on reals. */ - public boolean disallowAdditionReals; - - /** Whether to disallow {@link BinaryOperator#ADDITION} on lists. */ - public boolean disallowAdditionLists; - - /** Whether to disallow {@link BinaryOperator#ADDITION} on strings. */ - public boolean disallowAdditionStrings; - - /** Whether to disallow {@link BinaryOperator#ADDITION} on dictionaries. */ - public boolean disallowAdditionDicts; - - /** Whether to disallow {@link BinaryOperator#BI_CONDITIONAL}. */ - public boolean disallowBiconditional; - - /** Whether to disallow {@link BinaryOperator#CONJUNCTION}. */ - public boolean disallowConjunction; - - /** Whether to disallow {@link BinaryOperator#CONJUNCTION} on sets. */ - public boolean disallowConjunctionSets; - - /** Whether to disallow {@link BinaryOperator#DISJUNCTION}. */ - public boolean disallowDisjunction; - - /** Whether to disallow {@link BinaryOperator#DISJUNCTION} on sets. */ - public boolean disallowDisjunctionSets; - - /** Whether to disallow {@link BinaryOperator#DIVISION}. */ - public boolean disallowDivision; - - /** Whether to disallow {@link BinaryOperator#ELEMENT_OF}. */ - public boolean disallowElementOf; - - /** Whether to disallow {@link BinaryOperator#ELEMENT_OF} on lists. */ - public boolean disallowElementOfLists; - - /** Whether to disallow {@link BinaryOperator#ELEMENT_OF} on sets. */ - public boolean disallowElementOfSets; - - /** Whether to disallow {@link BinaryOperator#ELEMENT_OF} on dictionaries. */ - public boolean disallowElementOfDicts; - - /** Whether to disallow {@link BinaryOperator#EQUAL}. */ - public boolean disallowEqual; - - /** Whether to disallow {@link BinaryOperator#GREATER_EQUAL}. */ - public boolean disallowGreaterEqual; - - /** Whether to disallow {@link BinaryOperator#GREATER_EQUAL} on integers. */ - public boolean disallowGreaterEqualInts; - - /** Whether to disallow {@link BinaryOperator#GREATER_EQUAL} on ranged integers. */ - public boolean disallowGreaterEqualIntsRanged; - - /** Whether to disallow {@link BinaryOperator#GREATER_EQUAL} on rangeless integers. */ - public boolean disallowGreaterEqualIntsRangeless; - - /** Whether to disallow {@link BinaryOperator#GREATER_EQUAL} on reals. */ - public boolean disallowGreaterEqualReals; - - /** Whether to disallow {@link BinaryOperator#GREATER_THAN}. */ - public boolean disallowGreaterThan; - - /** Whether to disallow {@link BinaryOperator#GREATER_THAN} on integers. */ - public boolean disallowGreaterThanInts; - - /** Whether to disallow {@link BinaryOperator#GREATER_THAN} on ranged integers. */ - public boolean disallowGreaterThanIntsRanged; - - /** Whether to disallow {@link BinaryOperator#GREATER_THAN} on rangeless integers. */ - public boolean disallowGreaterThanIntsRangeless; - - /** Whether to disallow {@link BinaryOperator#GREATER_THAN} on reals. */ - public boolean disallowGreaterThanReals; - - /** Whether to disallow {@link BinaryOperator#IMPLICATION}. */ - public boolean disallowImplication; - - /** Whether to disallow {@link BinaryOperator#INTEGER_DIVISION}. */ - public boolean disallowIntegerDivision; - - /** Whether to disallow {@link BinaryOperator#INTEGER_DIVISION} on integers. */ - public boolean disallowIntegerDivisionInts; - - /** Whether to disallow {@link BinaryOperator#INTEGER_DIVISION} on ranged integers. */ - public boolean disallowIntegerDivisionIntsRanged; + /** The binary operators, or binary operators operating on certain operand types, to disallow. */ + private final EnumSet disalloweds; - /** Whether to disallow {@link BinaryOperator#INTEGER_DIVISION} on rangeless integers. */ - public boolean disallowIntegerDivisionIntsRangeless; - - /** Whether to disallow {@link BinaryOperator#LESS_EQUAL}. */ - public boolean disallowLessEqual; - - /** Whether to disallow {@link BinaryOperator#LESS_EQUAL} on integers. */ - public boolean disallowLessEqualInts; - - /** Whether to disallow {@link BinaryOperator#LESS_EQUAL} on ranged integers. */ - public boolean disallowLessEqualIntsRanged; - - /** Whether to disallow {@link BinaryOperator#LESS_EQUAL} on rangeless integers. */ - public boolean disallowLessEqualIntsRangeless; - - /** Whether to disallow {@link BinaryOperator#LESS_EQUAL} on reals. */ - public boolean disallowLessEqualReals; - - /** Whether to disallow {@link BinaryOperator#LESS_THAN}. */ - public boolean disallowLessThan; - - /** Whether to disallow {@link BinaryOperator#LESS_THAN} on integers. */ - public boolean disallowLessThanInts; - - /** Whether to disallow {@link BinaryOperator#LESS_THAN} on ranged integers. */ - public boolean disallowLessThanIntsRanged; - - /** Whether to disallow {@link BinaryOperator#LESS_THAN} on rangeless integers. */ - public boolean disallowLessThanIntsRangeless; - - /** Whether to disallow {@link BinaryOperator#LESS_THAN} on reals. */ - public boolean disallowLessThanReals; - - /** Whether to disallow {@link BinaryOperator#MODULUS}. */ - public boolean disallowModulus; - - /** Whether to disallow {@link BinaryOperator#MODULUS} on integers. */ - public boolean disallowModulusInts; - - /** Whether to disallow {@link BinaryOperator#MODULUS} on ranged integers. */ - public boolean disallowModulusIntsRanged; - - /** Whether to disallow {@link BinaryOperator#MODULUS} on rangeless integers. */ - public boolean disallowModulusIntsRangeless; - - /** Whether to disallow {@link BinaryOperator#MULTIPLICATION}. */ - public boolean disallowMultiplication; - - /** Whether to disallow {@link BinaryOperator#MULTIPLICATION} on integers. */ - public boolean disallowMultiplicationInts; - - /** Whether to disallow {@link BinaryOperator#MULTIPLICATION} on ranged integers. */ - public boolean disallowMultiplicationIntsRanged; - - /** Whether to disallow {@link BinaryOperator#MULTIPLICATION} on rangeless integers. */ - public boolean disallowMultiplicationIntsRangeless; - - /** Whether to disallow {@link BinaryOperator#MULTIPLICATION} on reals. */ - public boolean disallowMultiplicationReals; - - /** Whether to disallow {@link BinaryOperator#SUBSET}. */ - public boolean disallowSubset; - - /** Whether to disallow {@link BinaryOperator#SUBTRACTION}. */ - public boolean disallowSubtraction; - - /** Whether to disallow {@link BinaryOperator#SUBTRACTION} on integers. */ - public boolean disallowSubtractionInts; - - /** Whether to disallow {@link BinaryOperator#SUBTRACTION} on ranged integers. */ - public boolean disallowSubtractionIntsRanged; - - /** Whether to disallow {@link BinaryOperator#SUBTRACTION} on rangeless integers. */ - public boolean disallowSubtractionIntsRangeless; - - /** Whether to disallow {@link BinaryOperator#SUBTRACTION} on reals. */ - public boolean disallowSubtractionReals; - - /** Whether to disallow {@link BinaryOperator#SUBTRACTION} on lists. */ - public boolean disallowSubtractionLists; - - /** Whether to disallow {@link BinaryOperator#SUBTRACTION} on sets. */ - public boolean disallowSubtractionSets; - - /** Whether to disallow {@link BinaryOperator#SUBTRACTION} on dictionaries. */ - public boolean disallowSubtractionDicts; - - /** Whether to disallow {@link BinaryOperator#UNEQUAL}. */ - public boolean disallowUnequal; + /** + * Constructor for the {@link NoSpecificBinaryExprsCheck} class. + * + * @param disalloweds The binary operators, or binary operators operating on certain operand types, to disallow. + */ + public NoSpecificBinaryExprsCheck(EnumSet disalloweds) { + this.disalloweds = disalloweds; + } @Override protected void preprocessBinaryExpression(BinaryExpression binExpr) { @@ -228,160 +53,182 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); switch (op) { case ADDITION: - if (disallowAddition) { + if (disalloweds.contains(NoSpecificBinaryOp.ADDITION)) { addExprViolationOperator(binExpr); } else { - if (disallowAdditionInts) { + if (disalloweds.contains(NoSpecificBinaryOp.ADDITION_INTS)) { if (ltype instanceof IntType || rtype instanceof IntType) { addExprViolationOperand(binExpr); } } else { - if (disallowAdditionIntsRanged + if (disalloweds.contains(NoSpecificBinaryOp.ADDITION_INTS_RANGED) && ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype)))) { addExprViolationOperand(binExpr); } - if (disallowAdditionIntsRangeless + if (disalloweds.contains(NoSpecificBinaryOp.ADDITION_INTS_RANGELESS) && ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype)))) { addExprViolationOperand(binExpr); } } - if (disallowAdditionReals && (ltype instanceof RealType || rtype instanceof RealType)) { + if (disalloweds.contains(NoSpecificBinaryOp.ADDITION_REALS) + && (ltype instanceof RealType || rtype instanceof RealType)) + { addExprViolationOperand(binExpr); } - if (disallowAdditionLists && (ltype instanceof ListType || rtype instanceof ListType)) { + if (disalloweds.contains(NoSpecificBinaryOp.ADDITION_LISTS) + && (ltype instanceof ListType || rtype instanceof ListType)) + { addExprViolationOperand(binExpr); } - if (disallowAdditionStrings && (ltype instanceof StringType || rtype instanceof StringType)) { + if (disalloweds.contains(NoSpecificBinaryOp.ADDITION_STRINGS) + && (ltype instanceof StringType || rtype instanceof StringType)) + { addExprViolationOperand(binExpr); } - if (disallowAdditionDicts && (ltype instanceof DictType || rtype instanceof DictType)) { + if (disalloweds.contains(NoSpecificBinaryOp.ADDITION_DICTS) + && (ltype instanceof DictType || rtype instanceof DictType)) + { addExprViolationOperand(binExpr); } } break; case BI_CONDITIONAL: - if (disallowBiconditional) { + if (disalloweds.contains(NoSpecificBinaryOp.BI_CONDITIONAL)) { addExprViolationOperator(binExpr); } break; case CONJUNCTION: - if (disallowConjunction) { + if (disalloweds.contains(NoSpecificBinaryOp.CONJUNCTION)) { addExprViolationOperator(binExpr); - } else if (disallowConjunctionSets && (ltype instanceof SetType || rtype instanceof SetType)) { + } else if (disalloweds.contains(NoSpecificBinaryOp.CONJUNCTION_SETS) + && (ltype instanceof SetType || rtype instanceof SetType)) + { addExprViolationOperand(binExpr); } break; case DISJUNCTION: - if (disallowDisjunction) { + if (disalloweds.contains(NoSpecificBinaryOp.DISJUNCTION)) { addExprViolationOperator(binExpr); - } else if (disallowDisjunctionSets && (ltype instanceof SetType || rtype instanceof SetType)) { + } else if (disalloweds.contains(NoSpecificBinaryOp.DISJUNCTION_SETS) + && (ltype instanceof SetType || rtype instanceof SetType)) + { addExprViolationOperand(binExpr); } break; case DIVISION: - if (disallowDivision) { + if (disalloweds.contains(NoSpecificBinaryOp.DIVISION)) { addExprViolationOperator(binExpr); } break; case ELEMENT_OF: - if (disallowElementOf) { + if (disalloweds.contains(NoSpecificBinaryOp.ELEMENT_OF)) { addExprViolationOperator(binExpr); } else { - if (disallowElementOfLists && (ltype instanceof ListType || rtype instanceof ListType)) { + if (disalloweds.contains(NoSpecificBinaryOp.ELEMENT_OF_LISTS) + && (ltype instanceof ListType || rtype instanceof ListType)) + { addExprViolationOperand(binExpr); } - if (disallowElementOfSets && (ltype instanceof SetType || rtype instanceof SetType)) { + if (disalloweds.contains(NoSpecificBinaryOp.ELEMENT_OF_SETS) + && (ltype instanceof SetType || rtype instanceof SetType)) + { addExprViolationOperand(binExpr); } - if (disallowElementOfDicts && (ltype instanceof DictType || rtype instanceof DictType)) { + if (disalloweds.contains(NoSpecificBinaryOp.ELEMENT_OF_DICTS) + && (ltype instanceof DictType || rtype instanceof DictType)) + { addExprViolationOperand(binExpr); } } break; case EQUAL: - if (disallowEqual) { + if (disalloweds.contains(NoSpecificBinaryOp.EQUAL)) { addExprViolationOperator(binExpr); } break; case GREATER_EQUAL: - if (disallowGreaterEqual) { + if (disalloweds.contains(NoSpecificBinaryOp.GREATER_EQUAL)) { addExprViolationOperator(binExpr); } else { - if (disallowGreaterEqualInts) { + if (disalloweds.contains(NoSpecificBinaryOp.GREATER_EQUAL_INTS)) { if (ltype instanceof IntType || rtype instanceof IntType) { addExprViolationOperand(binExpr); } } else { - if (disallowGreaterEqualIntsRanged + if (disalloweds.contains(NoSpecificBinaryOp.GREATER_EQUAL_INTS_RANGED) && ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype)))) { addExprViolationOperand(binExpr); } - if (disallowGreaterEqualIntsRangeless + if (disalloweds.contains(NoSpecificBinaryOp.GREATER_EQUAL_INTS_RANGELESS) && ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype)))) { addExprViolationOperand(binExpr); } } - if (disallowGreaterEqualReals && (ltype instanceof RealType || rtype instanceof RealType)) { + if (disalloweds.contains(NoSpecificBinaryOp.GREATER_EQUAL_REALS) + && (ltype instanceof RealType || rtype instanceof RealType)) + { addExprViolationOperand(binExpr); } } break; case GREATER_THAN: - if (disallowGreaterThan) { + if (disalloweds.contains(NoSpecificBinaryOp.GREATER_THAN)) { addExprViolationOperator(binExpr); } else { - if (disallowGreaterThanInts) { + if (disalloweds.contains(NoSpecificBinaryOp.GREATER_THAN_INTS)) { if (ltype instanceof IntType || rtype instanceof IntType) { addExprViolationOperand(binExpr); } } else { - if (disallowGreaterThanIntsRanged + if (disalloweds.contains(NoSpecificBinaryOp.GREATER_THAN_INTS_RANGED) && ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype)))) { addExprViolationOperand(binExpr); } - if (disallowGreaterThanIntsRangeless + if (disalloweds.contains(NoSpecificBinaryOp.GREATER_THAN_INTS_RANGELESS) && ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype)))) { addExprViolationOperand(binExpr); } } - if (disallowGreaterThanReals && (ltype instanceof RealType || rtype instanceof RealType)) { + if (disalloweds.contains(NoSpecificBinaryOp.GREATER_THAN_REALS) + && (ltype instanceof RealType || rtype instanceof RealType)) + { addExprViolationOperand(binExpr); } } break; case IMPLICATION: - if (disallowImplication) { + if (disalloweds.contains(NoSpecificBinaryOp.IMPLICATION)) { addExprViolationOperator(binExpr); } break; case INTEGER_DIVISION: - if (disallowIntegerDivision) { + if (disalloweds.contains(NoSpecificBinaryOp.INTEGER_DIVISION)) { addExprViolationOperator(binExpr); } else { - if (disallowIntegerDivisionInts) { + if (disalloweds.contains(NoSpecificBinaryOp.INTEGER_DIVISION_INTS)) { if (ltype instanceof IntType || rtype instanceof IntType) { addExprViolationOperand(binExpr); } } else { - if (disallowIntegerDivisionIntsRanged + if (disalloweds.contains(NoSpecificBinaryOp.INTEGER_DIVISION_INTS_RANGED) && ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype)))) { addExprViolationOperand(binExpr); } - if (disallowIntegerDivisionIntsRangeless + if (disalloweds.contains(NoSpecificBinaryOp.INTEGER_DIVISION_INTS_RANGELESS) && ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype)))) { @@ -391,75 +238,79 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { } break; case LESS_EQUAL: - if (disallowLessEqual) { + if (disalloweds.contains(NoSpecificBinaryOp.LESS_EQUAL)) { addExprViolationOperator(binExpr); } else { - if (disallowLessEqualInts) { + if (disalloweds.contains(NoSpecificBinaryOp.LESS_EQUAL_INTS)) { if (ltype instanceof IntType || rtype instanceof IntType) { addExprViolationOperand(binExpr); } } else { - if (disallowLessEqualIntsRanged + if (disalloweds.contains(NoSpecificBinaryOp.LESS_EQUAL_INTS_RANGED) && ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype)))) { addExprViolationOperand(binExpr); } - if (disallowLessEqualIntsRangeless + if (disalloweds.contains(NoSpecificBinaryOp.LESS_EQUAL_INTS_RANGELESS) && ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype)))) { addExprViolationOperand(binExpr); } } - if (disallowLessEqualReals && (ltype instanceof RealType || rtype instanceof RealType)) { + if (disalloweds.contains(NoSpecificBinaryOp.LESS_EQUAL_REALS) + && (ltype instanceof RealType || rtype instanceof RealType)) + { addExprViolationOperand(binExpr); } } break; case LESS_THAN: - if (disallowLessThan) { + if (disalloweds.contains(NoSpecificBinaryOp.LESS_THAN)) { addExprViolationOperator(binExpr); } else { - if (disallowLessThanInts) { + if (disalloweds.contains(NoSpecificBinaryOp.LESS_THAN_INTS)) { if (ltype instanceof IntType || rtype instanceof IntType) { addExprViolationOperand(binExpr); } } else { - if (disallowLessThanIntsRanged + if (disalloweds.contains(NoSpecificBinaryOp.LESS_THAN_INTS_RANGED) && ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype)))) { addExprViolationOperand(binExpr); } - if (disallowLessThanIntsRangeless + if (disalloweds.contains(NoSpecificBinaryOp.LESS_THAN_INTS_RANGELESS) && ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype)))) { addExprViolationOperand(binExpr); } } - if (disallowLessThanReals && (ltype instanceof RealType || rtype instanceof RealType)) { + if (disalloweds.contains(NoSpecificBinaryOp.LESS_THAN_REALS) + && (ltype instanceof RealType || rtype instanceof RealType)) + { addExprViolationOperand(binExpr); } } break; case MODULUS: - if (disallowModulus) { + if (disalloweds.contains(NoSpecificBinaryOp.MODULUS)) { addExprViolationOperator(binExpr); } else { - if (disallowModulusInts) { + if (disalloweds.contains(NoSpecificBinaryOp.MODULUS_INTS)) { if (ltype instanceof IntType || rtype instanceof IntType) { addExprViolationOperand(binExpr); } } else { - if (disallowModulusIntsRanged + if (disalloweds.contains(NoSpecificBinaryOp.MODULUS_INTS_RANGED) && ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype)))) { addExprViolationOperand(binExpr); } - if (disallowModulusIntsRangeless + if (disalloweds.contains(NoSpecificBinaryOp.MODULUS_INTS_RANGELESS) && ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype)))) { @@ -469,75 +320,85 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { } break; case MULTIPLICATION: - if (disallowMultiplication) { + if (disalloweds.contains(NoSpecificBinaryOp.MULTIPLICATION)) { addExprViolationOperator(binExpr); } else { - if (disallowMultiplicationInts) { + if (disalloweds.contains(NoSpecificBinaryOp.MULTIPLICATION_INTS)) { if (ltype instanceof IntType || rtype instanceof IntType) { addExprViolationOperand(binExpr); } } else { - if (disallowMultiplicationIntsRanged + if (disalloweds.contains(NoSpecificBinaryOp.MULTIPLICATION_INTS_RANGED) && ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype)))) { addExprViolationOperand(binExpr); } - if (disallowMultiplicationIntsRangeless + if (disalloweds.contains(NoSpecificBinaryOp.MULTIPLICATION_INTS_RANGELESS) && ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype)))) { addExprViolationOperand(binExpr); } } - if (disallowMultiplicationReals && (ltype instanceof RealType || rtype instanceof RealType)) { + if (disalloweds.contains(NoSpecificBinaryOp.MULTIPLICATION_REALS) + && (ltype instanceof RealType || rtype instanceof RealType)) + { addExprViolationOperand(binExpr); } } break; case SUBSET: - if (disallowSubset) { + if (disalloweds.contains(NoSpecificBinaryOp.SUBSET)) { addExprViolationOperator(binExpr); } break; case SUBTRACTION: - if (disallowSubtraction) { + if (disalloweds.contains(NoSpecificBinaryOp.SUBTRACTION)) { addExprViolationOperator(binExpr); } else { - if (disallowSubtractionInts) { + if (disalloweds.contains(NoSpecificBinaryOp.SUBTRACTION_INTS)) { if (ltype instanceof IntType || rtype instanceof IntType) { addExprViolationOperand(binExpr); } } else { - if (disallowSubtractionIntsRanged + if (disalloweds.contains(NoSpecificBinaryOp.SUBTRACTION_INTS_RANGED) && ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype)))) { addExprViolationOperand(binExpr); } - if (disallowSubtractionIntsRangeless + if (disalloweds.contains(NoSpecificBinaryOp.SUBTRACTION_INTS_RANGELESS) && ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype)))) { addExprViolationOperand(binExpr); } } - if (disallowSubtractionReals && (ltype instanceof RealType || rtype instanceof RealType)) { + if (disalloweds.contains(NoSpecificBinaryOp.SUBTRACTION_REALS) + && (ltype instanceof RealType || rtype instanceof RealType)) + { addExprViolationOperand(binExpr); } - if (disallowSubtractionLists && (ltype instanceof ListType || rtype instanceof ListType)) { + if (disalloweds.contains(NoSpecificBinaryOp.SUBTRACTION_LISTS) + && (ltype instanceof ListType || rtype instanceof ListType)) + { addExprViolationOperand(binExpr); } - if (disallowSubtractionSets && (ltype instanceof SetType || rtype instanceof SetType)) { + if (disalloweds.contains(NoSpecificBinaryOp.SUBTRACTION_SETS) + && (ltype instanceof SetType || rtype instanceof SetType)) + { addExprViolationOperand(binExpr); } - if (disallowSubtractionDicts && (ltype instanceof DictType || rtype instanceof DictType)) { + if (disalloweds.contains(NoSpecificBinaryOp.SUBTRACTION_DICTS) + && (ltype instanceof DictType || rtype instanceof DictType)) + { addExprViolationOperand(binExpr); } } break; case UNEQUAL: - if (disallowUnequal) { + if (disalloweds.contains(NoSpecificBinaryOp.UNEQUAL)) { addExprViolationOperator(binExpr); } break; @@ -569,4 +430,196 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { fmt("uses binary operator \"%s\" on operands of types \"%s\" and \"%s\" in binary expression \"%s\"", operatorToStr(binExpr.getOperator()), typeToStr(ltype), typeToStr(rtype), exprToStr(binExpr))); } + + /** The binary operator, or binary operator operating on certain operand types, to disallow. */ + public static enum NoSpecificBinaryOp { + /** Disallow {@link BinaryOperator#ADDITION}. */ + ADDITION, + + /** Disallow {@link BinaryOperator#ADDITION} on integers. */ + ADDITION_INTS, + + /** Disallow {@link BinaryOperator#ADDITION} on ranged integers. */ + ADDITION_INTS_RANGED, + + /** Disallow {@link BinaryOperator#ADDITION} on rangeless integers. */ + ADDITION_INTS_RANGELESS, + + /** Disallow {@link BinaryOperator#ADDITION} on reals. */ + ADDITION_REALS, + + /** Disallow {@link BinaryOperator#ADDITION} on lists. */ + ADDITION_LISTS, + + /** Disallow {@link BinaryOperator#ADDITION} on strings. */ + ADDITION_STRINGS, + + /** Disallow {@link BinaryOperator#ADDITION} on dictionaries. */ + ADDITION_DICTS, + + /** Disallow {@link BinaryOperator#BI_CONDITIONAL}. */ + BI_CONDITIONAL, + + /** Disallow {@link BinaryOperator#CONJUNCTION}. */ + CONJUNCTION, + + /** Disallow {@link BinaryOperator#CONJUNCTION} on sets. */ + CONJUNCTION_SETS, + + /** Disallow {@link BinaryOperator#DISJUNCTION}. */ + DISJUNCTION, + + /** Disallow {@link BinaryOperator#DISJUNCTION} on sets. */ + DISJUNCTION_SETS, + + /** Disallow {@link BinaryOperator#DIVISION}. */ + DIVISION, + + /** Disallow {@link BinaryOperator#ELEMENT_OF}. */ + ELEMENT_OF, + + /** Disallow {@link BinaryOperator#ELEMENT_OF} on lists. */ + ELEMENT_OF_LISTS, + + /** Disallow {@link BinaryOperator#ELEMENT_OF} on sets. */ + ELEMENT_OF_SETS, + + /** Disallow {@link BinaryOperator#ELEMENT_OF} on dictionaries. */ + ELEMENT_OF_DICTS, + + /** Disallow {@link BinaryOperator#EQUAL}. */ + EQUAL, + + /** Disallow {@link BinaryOperator#GREATER_EQUAL}. */ + GREATER_EQUAL, + + /** Disallow {@link BinaryOperator#GREATER_EQUAL} on integers. */ + GREATER_EQUAL_INTS, + + /** Disallow {@link BinaryOperator#GREATER_EQUAL} on ranged integers. */ + GREATER_EQUAL_INTS_RANGED, + + /** Disallow {@link BinaryOperator#GREATER_EQUAL} on rangeless integers. */ + GREATER_EQUAL_INTS_RANGELESS, + + /** Disallow {@link BinaryOperator#GREATER_EQUAL} on reals. */ + GREATER_EQUAL_REALS, + + /** Disallow {@link BinaryOperator#GREATER_THAN}. */ + GREATER_THAN, + + /** Disallow {@link BinaryOperator#GREATER_THAN} on integers. */ + GREATER_THAN_INTS, + + /** Disallow {@link BinaryOperator#GREATER_THAN} on ranged integers. */ + GREATER_THAN_INTS_RANGED, + + /** Disallow {@link BinaryOperator#GREATER_THAN} on rangeless integers. */ + GREATER_THAN_INTS_RANGELESS, + + /** Disallow {@link BinaryOperator#GREATER_THAN} on reals. */ + GREATER_THAN_REALS, + + /** Disallow {@link BinaryOperator#IMPLICATION}. */ + IMPLICATION, + + /** Disallow {@link BinaryOperator#INTEGER_DIVISION}. */ + INTEGER_DIVISION, + + /** Disallow {@link BinaryOperator#INTEGER_DIVISION} on integers. */ + INTEGER_DIVISION_INTS, + + /** Disallow {@link BinaryOperator#INTEGER_DIVISION} on ranged integers. */ + INTEGER_DIVISION_INTS_RANGED, + + /** Disallow {@link BinaryOperator#INTEGER_DIVISION} on rangeless integers. */ + INTEGER_DIVISION_INTS_RANGELESS, + + /** Disallow {@link BinaryOperator#LESS_EQUAL}. */ + LESS_EQUAL, + + /** Disallow {@link BinaryOperator#LESS_EQUAL} on integers. */ + LESS_EQUAL_INTS, + + /** Disallow {@link BinaryOperator#LESS_EQUAL} on ranged integers. */ + LESS_EQUAL_INTS_RANGED, + + /** Disallow {@link BinaryOperator#LESS_EQUAL} on rangeless integers. */ + LESS_EQUAL_INTS_RANGELESS, + + /** Disallow {@link BinaryOperator#LESS_EQUAL} on reals. */ + LESS_EQUAL_REALS, + + /** Disallow {@link BinaryOperator#LESS_THAN}. */ + LESS_THAN, + + /** Disallow {@link BinaryOperator#LESS_THAN} on integers. */ + LESS_THAN_INTS, + + /** Disallow {@link BinaryOperator#LESS_THAN} on ranged integers. */ + LESS_THAN_INTS_RANGED, + + /** Disallow {@link BinaryOperator#LESS_THAN} on rangeless integers. */ + LESS_THAN_INTS_RANGELESS, + + /** Disallow {@link BinaryOperator#LESS_THAN} on reals. */ + LESS_THAN_REALS, + + /** Disallow {@link BinaryOperator#MODULUS}. */ + MODULUS, + + /** Disallow {@link BinaryOperator#MODULUS} on integers. */ + MODULUS_INTS, + + /** Disallow {@link BinaryOperator#MODULUS} on ranged integers. */ + MODULUS_INTS_RANGED, + + /** Disallow {@link BinaryOperator#MODULUS} on rangeless integers. */ + MODULUS_INTS_RANGELESS, + + /** Disallow {@link BinaryOperator#MULTIPLICATION}. */ + MULTIPLICATION, + + /** Disallow {@link BinaryOperator#MULTIPLICATION} on integers. */ + MULTIPLICATION_INTS, + + /** Disallow {@link BinaryOperator#MULTIPLICATION} on ranged integers. */ + MULTIPLICATION_INTS_RANGED, + + /** Disallow {@link BinaryOperator#MULTIPLICATION} on rangeless integers. */ + MULTIPLICATION_INTS_RANGELESS, + + /** Disallow {@link BinaryOperator#MULTIPLICATION} on reals. */ + MULTIPLICATION_REALS, + + /** Disallow {@link BinaryOperator#SUBSET}. */ + SUBSET, + + /** Disallow {@link BinaryOperator#SUBTRACTION}. */ + SUBTRACTION, + + /** Disallow {@link BinaryOperator#SUBTRACTION} on integers. */ + SUBTRACTION_INTS, + + /** Disallow {@link BinaryOperator#SUBTRACTION} on ranged integers. */ + SUBTRACTION_INTS_RANGED, + + /** Disallow {@link BinaryOperator#SUBTRACTION} on rangeless integers. */ + SUBTRACTION_INTS_RANGELESS, + + /** Disallow {@link BinaryOperator#SUBTRACTION} on reals. */ + SUBTRACTION_REALS, + + /** Disallow {@link BinaryOperator#SUBTRACTION} on lists. */ + SUBTRACTION_LISTS, + + /** Disallow {@link BinaryOperator#SUBTRACTION} on sets. */ + SUBTRACTION_SETS, + + /** Disallow {@link BinaryOperator#SUBTRACTION} on dictionaries. */ + SUBTRACTION_DICTS, + + /** Disallow {@link BinaryOperator#UNEQUAL}. */ + UNEQUAL, + } } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificExprsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificExprsCheck.java index 52f09c8ad..be7ddcf1a 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificExprsCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificExprsCheck.java @@ -17,6 +17,8 @@ import static org.eclipse.escet.cif.common.CifTextUtils.exprToStr; import static org.eclipse.escet.cif.common.CifTextUtils.getNamedSelfOrAncestor; import static org.eclipse.escet.common.java.Strings.fmt; +import java.util.EnumSet; + import org.eclipse.emf.ecore.EObject; import org.eclipse.escet.cif.common.CifTypeUtils; import org.eclipse.escet.cif.common.RangeCompat; @@ -66,154 +68,36 @@ import org.eclipse.escet.common.position.metamodel.position.PositionObject; /** CIF check that does not allow certain expressions. */ public class NoSpecificExprsCheck extends CifCheck { - /** Whether to disallow references to algebraic variables. */ - public boolean disallowAlgVarRefs; - - /** Whether to disallow references to all functions (user-defined and standard library ones). */ - public boolean disallowFuncRefs; - - /** Whether to disallow references to all user-defined functions (internal and external ones). */ - public boolean disallowFuncRefsUserDef; - - /** Whether to disallow references to internal user-defined functions. */ - public boolean disallowFuncRefsUserDefInt; - - /** Whether to disallow references to external user-defined functions. */ - public boolean disallowFuncRefsUserDefExt; - - /** Whether to disallow references to standard library functions. */ - public boolean disallowFuncRefsStdLib; - - /** Whether to disallow all binary expressions. */ - public boolean disallowBinExprs; - - /** Whether to disallow boolean literals. */ - public boolean disallowBoolLits; - - /** Whether to disallow all cast expressions. */ - public boolean disallowCastExprs; - - /** Whether to disallow cast expressions that cast to a different type. */ - public boolean disallowCastExprsNonEqualType; - - /** Whether to disallow all component references (explicit components and 'self' references). */ - public boolean disallowCompRefs; - - /** Whether to disallow explicit component references. */ - public boolean disallowCompRefsExplicit; - - /** Whether to disallow component 'self' references. */ - public boolean disallowCompRefsSelf; - - /** Whether to disallow component parameter references. */ - public boolean disallowCompParamRefs; - - /** Whether to disallow constant references. */ - public boolean disallowConstRefs; - - /** Whether to disallow continuous variable references. */ - public boolean disallowContVarRefs; - - /** Whether to disallow dictionary literals. */ - public boolean disallowDictLits; - - /** Whether to disallow discrete variable references. */ - public boolean disallowDiscVarRefs; - - /** Whether to disallow user-defined function parameter references. */ - public boolean disallowUserDefFuncParamRefs; - - /** Whether to disallow references to local variables of internal user-defined functions. */ - public boolean disallowIntUserDefFuncLocalVarRefs; - - /** Whether to disallow enumeration literal references. */ - public boolean disallowEnumLitRefs; - - /** Whether to disallow tuple field references. */ - public boolean disallowTupleFieldRefs; - - /** Whether to disallow function calls (for user-defined functions and standard library functions). */ - public boolean disallowFuncCalls; + /** The expressions to disallow. */ + private final EnumSet disalloweds; - /** Whether to disallow 'if' expressions (conditional expressions). */ - public boolean disallowIfExprs; - - /** Whether to disallow input variable references. */ - public boolean disallowInputVarRefs; - - /** Whether to disallow integer number literals. */ - public boolean disallowIntLits; - - /** Whether to disallow list literals. */ - public boolean disallowListLits; - - /** Whether to disallow location references. */ - public boolean disallowLocRefs; - - /** Whether to disallow projection expressions. */ - public boolean disallowProjectionExprs; - - /** Whether to disallow projection expressions on lists. */ - public boolean disallowProjectionExprsLists; - - /** Whether to disallow projection expressions on dictionaries. */ - public boolean disallowProjectionExprsDicts; - - /** Whether to disallow projection expressions on strings. */ - public boolean disallowProjectionExprsStrings; - - /** Whether to disallow projection expressions on tuples. */ - public boolean disallowProjectionExprsTuples; - - /** Whether to disallow projection expressions on tuples using index. */ - public boolean disallowProjectionExprsTuplesIndex; - - /** Whether to disallow projection expressions on tuples using field. */ - public boolean disallowProjectionExprsTuplesField; - - /** Whether to disallow real number expressions. */ - public boolean disallowRealLits; - - /** Whether to disallow received value expressions. */ - public boolean disallowReceiveExprs; - - /** Whether to disallow set literals. */ - public boolean disallowSetLits; - - /** Whether to disallow slice expressions. */ - public boolean disallowSliceExprs; - - /** Whether to disallow string literals. */ - public boolean disallowStringLits; - - /** Whether to disallow switch expressions. */ - public boolean disallowSwitchExprs; - - /** Whether to disallow 'time' variable references. */ - public boolean disallowTimeVarRefs; - - /** Whether to disallow tuple literal expressions. */ - public boolean disallowTupleLits; - - /** Whether to disallow all unary expressions. */ - public boolean disallowUnExprs; + /** + * Constructor for the {@link NoSpecificExprsCheck} class. + * + * @param disalloweds The expressions to disallow. + */ + public NoSpecificExprsCheck(EnumSet disalloweds) { + this.disalloweds = disalloweds; + } @Override protected void preprocessAlgVariableExpression(AlgVariableExpression algRef) { - if (disallowAlgVarRefs) { + if (disalloweds.contains(NoSpecificExpr.ALG_VAR_REFS)) { addExprViolation(algRef, "algebraic variable reference"); } } @Override protected void preprocessFunctionExpression(FunctionExpression userDefFuncRef) { - if ((disallowFuncRefs || disallowFuncRefsUserDef || disallowFuncRefsUserDefInt) + if ((disalloweds.contains(NoSpecificExpr.FUNC_REFS) || disalloweds.contains(NoSpecificExpr.FUNC_REFS_USER_DEF) + || disalloweds.contains(NoSpecificExpr.FUNC_REFS_USER_DEF_INT)) && userDefFuncRef.getFunction() instanceof InternalFunction) { addExprViolation(userDefFuncRef, "internal user-defined function reference"); } - if ((disallowFuncRefs || disallowFuncRefsUserDef || disallowFuncRefsUserDefExt) + if ((disalloweds.contains(NoSpecificExpr.FUNC_REFS) || disalloweds.contains(NoSpecificExpr.FUNC_REFS_USER_DEF) + || disalloweds.contains(NoSpecificExpr.FUNC_REFS_USER_DEF_EXT)) && userDefFuncRef.getFunction() instanceof ExternalFunction) { addExprViolation(userDefFuncRef, "external user-defined function reference"); @@ -222,30 +106,30 @@ public class NoSpecificExprsCheck extends CifCheck { @Override protected void preprocessStdLibFunctionExpression(StdLibFunctionExpression stdLibRef) { - if (disallowFuncRefs || disallowFuncRefsStdLib) { + if (disalloweds.contains(NoSpecificExpr.FUNC_REFS) || disalloweds.contains(NoSpecificExpr.FUNC_REFS_STD_LIB)) { addExprViolation(stdLibRef, "standard library function reference"); } } @Override protected void preprocessBinaryExpression(BinaryExpression binExpr) { - if (disallowBinExprs) { + if (disalloweds.contains(NoSpecificExpr.BINARY_EXPRS)) { addExprViolation(binExpr, "binary expression"); } } @Override protected void preprocessBoolExpression(BoolExpression boolLit) { - if (disallowBoolLits) { + if (disalloweds.contains(NoSpecificExpr.BOOL_LITS)) { addExprViolation(boolLit, "boolean literal"); } } @Override protected void preprocessCastExpression(CastExpression castExpr) { - if (disallowCastExprs) { + if (disalloweds.contains(NoSpecificExpr.CAST_EXPRS)) { addExprViolation(castExpr, "cast expression"); - } else if (disallowCastExprsNonEqualType) { + } else if (disalloweds.contains(NoSpecificExpr.CAST_EXPRS_NON_EQUAL_TYPE)) { CifType ctype = castExpr.getChild().getType(); CifType rtype = castExpr.getType(); if (CifTypeUtils.checkTypeCompat(ctype, rtype, RangeCompat.EQUAL)) { @@ -258,35 +142,35 @@ public class NoSpecificExprsCheck extends CifCheck { @Override protected void preprocessComponentExpression(ComponentExpression compRef) { - if (disallowCompRefs || disallowCompRefsExplicit) { + if (disalloweds.contains(NoSpecificExpr.COMP_REFS) || disalloweds.contains(NoSpecificExpr.COMP_REFS_EXPLICIT)) { addExprViolation(compRef, "component reference"); } } @Override protected void preprocessCompParamExpression(CompParamExpression compParamRef) { - if (disallowCompParamRefs) { + if (disalloweds.contains(NoSpecificExpr.COMP_PARAM_REFS)) { addExprViolation(compParamRef, "component parameter reference"); } } @Override protected void preprocessConstantExpression(ConstantExpression constRef) { - if (disallowConstRefs) { + if (disalloweds.contains(NoSpecificExpr.CONST_REFS)) { addExprViolation(constRef, "constant reference"); } } @Override protected void preprocessContVariableExpression(ContVariableExpression contRef) { - if (disallowContVarRefs) { + if (disalloweds.contains(NoSpecificExpr.CONT_VAR_REFS)) { addExprViolation(contRef, "continuous variable reference"); } } @Override protected void preprocessDictExpression(DictExpression dictLit) { - if (disallowDictLits) { + if (disalloweds.contains(NoSpecificExpr.DICT_LITS)) { addExprViolation(dictLit, "dictionary literal"); } } @@ -295,15 +179,15 @@ public class NoSpecificExprsCheck extends CifCheck { protected void preprocessDiscVariableExpression(DiscVariableExpression discRef) { EObject parent = discRef.getVariable().eContainer(); if (parent instanceof ComplexComponent) { - if (disallowDiscVarRefs) { + if (disalloweds.contains(NoSpecificExpr.DISC_VAR_REFS)) { addExprViolation(discRef, "discrete variable reference"); } } else if (parent instanceof FunctionParameter) { - if (disallowUserDefFuncParamRefs) { + if (disalloweds.contains(NoSpecificExpr.USER_DEF_FUNC_PARAM_REFS)) { addExprViolation(discRef, "user-defined function parameter reference"); } } else if (parent instanceof InternalFunction) { - if (disallowIntUserDefFuncLocalVarRefs) { + if (disalloweds.contains(NoSpecificExpr.INT_USER_DEF_FUNC_LOCAL_VAR_REFS)) { addExprViolation(discRef, "internal user-defined function local variable reference"); } } else { @@ -313,97 +197,97 @@ public class NoSpecificExprsCheck extends CifCheck { @Override protected void preprocessEnumLiteralExpression(EnumLiteralExpression enumLitRef) { - if (disallowEnumLitRefs) { + if (disalloweds.contains(NoSpecificExpr.ENUM_LIT_REFS)) { addExprViolation(enumLitRef, "enumeration literal reference"); } } @Override protected void preprocessFieldExpression(FieldExpression fieldRef) { - if (disallowTupleFieldRefs) { + if (disalloweds.contains(NoSpecificExpr.TUPLE_FIELD_REFS)) { addExprViolation(fieldRef, "tuple field reference"); } } @Override protected void preprocessFunctionCallExpression(FunctionCallExpression funcCall) { - if (disallowFuncCalls) { + if (disalloweds.contains(NoSpecificExpr.FUNC_CALLS)) { addExprViolation(funcCall, "function call"); } } @Override protected void preprocessIfExpression(IfExpression ifExpr) { - if (disallowIfExprs) { + if (disalloweds.contains(NoSpecificExpr.IF_EXPRS)) { addExprViolation(ifExpr, "conditional expression"); } } @Override protected void preprocessInputVariableExpression(InputVariableExpression inputRef) { - if (disallowInputVarRefs) { + if (disalloweds.contains(NoSpecificExpr.INPUT_VAR_REFS)) { addExprViolation(inputRef, "input variable reference"); } } @Override protected void preprocessIntExpression(IntExpression intLit) { - if (disallowIntLits) { + if (disalloweds.contains(NoSpecificExpr.INT_LITS)) { addExprViolation(intLit, "integer number literal"); } } @Override protected void preprocessListExpression(ListExpression listLit) { - if (disallowListLits) { + if (disalloweds.contains(NoSpecificExpr.LIST_LITS)) { addExprViolation(listLit, "list literal"); } } @Override protected void preprocessLocationExpression(LocationExpression locRef) { - if (disallowLocRefs) { + if (disalloweds.contains(NoSpecificExpr.LOC_REFS)) { addExprViolation(locRef, "location reference"); } } @Override protected void preprocessProjectionExpression(ProjectionExpression projExpr) { - if (disallowProjectionExprs) { + if (disalloweds.contains(NoSpecificExpr.PROJECTION_EXPRS)) { addExprViolation(projExpr, "projection expression"); } else { - if (disallowProjectionExprsLists) { + if (disalloweds.contains(NoSpecificExpr.PROJECTION_EXPRS_LISTS)) { CifType ctype = CifTypeUtils.normalizeType(projExpr.getChild().getType()); if (ctype instanceof ListType) { addExprViolation(projExpr, "list projection expression"); } } - if (disallowProjectionExprsDicts) { + if (disalloweds.contains(NoSpecificExpr.PROJECTION_EXPRS_DICTS)) { CifType ctype = CifTypeUtils.normalizeType(projExpr.getChild().getType()); if (ctype instanceof DictType) { addExprViolation(projExpr, "dictionary projection expression"); } } - if (disallowProjectionExprsStrings) { + if (disalloweds.contains(NoSpecificExpr.PROJECTION_EXPRS_STRINGS)) { CifType ctype = CifTypeUtils.normalizeType(projExpr.getChild().getType()); if (ctype instanceof StringType) { addExprViolation(projExpr, "string projection expression"); } } - if (disallowProjectionExprsTuples) { + if (disalloweds.contains(NoSpecificExpr.PROJECTION_EXPRS_TUPLES)) { CifType ctype = CifTypeUtils.normalizeType(projExpr.getChild().getType()); if (ctype instanceof TupleType) { addExprViolation(projExpr, "tuple projection expression"); } } else { - if (disallowProjectionExprsTuplesIndex) { + if (disalloweds.contains(NoSpecificExpr.PROJECTION_EXPRS_TUPLES_INDEX)) { CifType ctype = CifTypeUtils.normalizeType(projExpr.getChild().getType()); CifType itype = CifTypeUtils.normalizeType(projExpr.getIndex().getType()); if (ctype instanceof TupleType && itype instanceof IntType) { addExprViolation(projExpr, "tuple index-projection expression"); } } - if (disallowProjectionExprsTuplesField) { + if (disalloweds.contains(NoSpecificExpr.PROJECTION_EXPRS_TUPLES_FIELD)) { CifType ctype = CifTypeUtils.normalizeType(projExpr.getChild().getType()); if (ctype instanceof TupleType && projExpr.getIndex() instanceof FieldExpression) { addExprViolation(projExpr, "tuple field-projection expression"); @@ -415,70 +299,70 @@ public class NoSpecificExprsCheck extends CifCheck { @Override protected void preprocessRealExpression(RealExpression realLit) { - if (disallowRealLits) { + if (disalloweds.contains(NoSpecificExpr.REAL_LITS)) { addExprViolation(realLit, "real number literal"); } } @Override protected void preprocessReceivedExpression(ReceivedExpression receivedExpr) { - if (disallowReceiveExprs) { + if (disalloweds.contains(NoSpecificExpr.RECEIVE_EXPRS)) { addExprViolation(receivedExpr, "received value expression"); } } @Override protected void preprocessSelfExpression(SelfExpression selfRef) { - if (disallowCompRefs || disallowCompRefsSelf) { + if (disalloweds.contains(NoSpecificExpr.COMP_REFS) || disalloweds.contains(NoSpecificExpr.COMP_REFS_SELF)) { addExprViolation(selfRef, "component reference"); } } @Override protected void preprocessSetExpression(SetExpression setLit) { - if (disallowSetLits) { + if (disalloweds.contains(NoSpecificExpr.SET_LITS)) { addExprViolation(setLit, "set literal"); } } @Override protected void preprocessSliceExpression(SliceExpression sliceExpr) { - if (disallowSliceExprs) { + if (disalloweds.contains(NoSpecificExpr.SLICE_EXPRS)) { addExprViolation(sliceExpr, "slice expression"); } } @Override protected void preprocessStringExpression(StringExpression stringLit) { - if (disallowStringLits) { + if (disalloweds.contains(NoSpecificExpr.STRING_LITS)) { addExprViolation(stringLit, "string literal"); } } @Override protected void preprocessSwitchExpression(SwitchExpression switchExpr) { - if (disallowSwitchExprs) { + if (disalloweds.contains(NoSpecificExpr.SWITCH_EXPRS)) { addExprViolation(switchExpr, "switch expression"); } } @Override protected void preprocessTimeExpression(TimeExpression timeRef) { - if (disallowTimeVarRefs) { + if (disalloweds.contains(NoSpecificExpr.TIME_VAR_REFS)) { addExprViolation(timeRef, "time variable reference"); } } @Override protected void preprocessTupleExpression(TupleExpression tupleLit) { - if (disallowTupleLits) { + if (disalloweds.contains(NoSpecificExpr.TUPLE_LITS)) { addExprViolation(tupleLit, "tuple literal"); } } @Override protected void preprocessUnaryExpression(UnaryExpression unExpr) { - if (disallowUnExprs) { + if (disalloweds.contains(NoSpecificExpr.UNARY_EXPRS)) { addExprViolation(unExpr, "unary expression"); } } @@ -495,7 +379,141 @@ public class NoSpecificExprsCheck extends CifCheck { * @param description The description of the expression. */ private void addExprViolation(Expression expr, String description) { - super.addViolation(getNamedSelfOrAncestor(expr), - fmt("uses %s \"%s\"", description, exprToStr(expr))); + super.addViolation(getNamedSelfOrAncestor(expr), fmt("uses %s \"%s\"", description, exprToStr(expr))); + } + + /** The expression to disallow. */ + public static enum NoSpecificExpr { + /** Disallow references to algebraic variables. */ + ALG_VAR_REFS, + + /** Disallow references to all functions (user-defined and standard library ones). */ + FUNC_REFS, + + /** Disallow references to all user-defined functions (internal and external ones). */ + FUNC_REFS_USER_DEF, + + /** Disallow references to internal user-defined functions. */ + FUNC_REFS_USER_DEF_INT, + + /** Disallow references to external user-defined functions. */ + FUNC_REFS_USER_DEF_EXT, + + /** Disallow references to standard library functions. */ + FUNC_REFS_STD_LIB, + + /** Disallow all binary expressions. */ + BINARY_EXPRS, + + /** Disallow boolean literals. */ + BOOL_LITS, + + /** Disallow all cast expressions. */ + CAST_EXPRS, + + /** Disallow cast expressions that cast to a different type. */ + CAST_EXPRS_NON_EQUAL_TYPE, + + /** Disallow all component references (explicit components and 'self' references). */ + COMP_REFS, + + /** Disallow explicit component references. */ + COMP_REFS_EXPLICIT, + + /** Disallow component 'self' references. */ + COMP_REFS_SELF, + + /** Disallow component parameter references. */ + COMP_PARAM_REFS, + + /** Disallow constant references. */ + CONST_REFS, + + /** Disallow continuous variable references. */ + CONT_VAR_REFS, + + /** Disallow dictionary literals. */ + DICT_LITS, + + /** Disallow discrete variable references. */ + DISC_VAR_REFS, + + /** Disallow user-defined function parameter references. */ + USER_DEF_FUNC_PARAM_REFS, + + /** Disallow references to local variables of internal user-defined functions. */ + INT_USER_DEF_FUNC_LOCAL_VAR_REFS, + + /** Disallow enumeration literal references. */ + ENUM_LIT_REFS, + + /** Disallow tuple field references. */ + TUPLE_FIELD_REFS, + + /** Disallow function calls (for user-defined functions and standard library functions). */ + FUNC_CALLS, + + /** Disallow 'if' expressions (conditional expressions). */ + IF_EXPRS, + + /** Disallow input variable references. */ + INPUT_VAR_REFS, + + /** Disallow integer number literals. */ + INT_LITS, + + /** Disallow list literals. */ + LIST_LITS, + + /** Disallow location references. */ + LOC_REFS, + + /** Disallow projection expressions. */ + PROJECTION_EXPRS, + + /** Disallow projection expressions on lists. */ + PROJECTION_EXPRS_LISTS, + + /** Disallow projection expressions on dictionaries. */ + PROJECTION_EXPRS_DICTS, + + /** Disallow projection expressions on strings. */ + PROJECTION_EXPRS_STRINGS, + + /** Disallow projection expressions on tuples. */ + PROJECTION_EXPRS_TUPLES, + + /** Disallow projection expressions on tuples using index. */ + PROJECTION_EXPRS_TUPLES_INDEX, + + /** Disallow projection expressions on tuples using field. */ + PROJECTION_EXPRS_TUPLES_FIELD, + + /** Disallow real number expressions. */ + REAL_LITS, + + /** Disallow received value expressions. */ + RECEIVE_EXPRS, + + /** Disallow set literals. */ + SET_LITS, + + /** Disallow slice expressions. */ + SLICE_EXPRS, + + /** Disallow string literals. */ + STRING_LITS, + + /** Disallow switch expressions. */ + SWITCH_EXPRS, + + /** Disallow 'time' variable references. */ + TIME_VAR_REFS, + + /** Disallow tuple literal expressions. */ + TUPLE_LITS, + + /** Disallow all unary expressions. */ + UNARY_EXPRS, } } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificTypesCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificTypesCheck.java index d42e40b39..276327870 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificTypesCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificTypesCheck.java @@ -17,6 +17,8 @@ import static org.eclipse.escet.cif.common.CifTextUtils.getNamedSelfOrAncestor; import static org.eclipse.escet.cif.common.CifTextUtils.typeToStr; import static org.eclipse.escet.common.java.Strings.fmt; +import java.util.EnumSet; + import org.eclipse.escet.cif.common.CifTypeUtils; import org.eclipse.escet.cif.metamodel.cif.types.CifType; import org.eclipse.escet.cif.metamodel.cif.types.ComponentDefType; @@ -36,142 +38,109 @@ import org.eclipse.escet.common.position.metamodel.position.PositionObject; /** CIF check that does not allow certain types. */ public class NoSpecificTypesCheck extends CifCheck { - /** Whether to disallow component definition types. */ - public boolean disallowCompDefTypes; - - /** Whether to disallow component types. */ - public boolean disallowCompTypes; - - /** Whether to disallow dictionary types. */ - public boolean disallowDictTypes; - - /** Whether to disallow distribution types. */ - public boolean disallowDistTypes; - - /** Whether to disallow enumeration types. */ - public boolean disallowEnumTypes; - - /** Whether to disallow function types. Note that this includes standard library function types. */ - public boolean disallowFuncTypes; - - /** Whether to disallow all integer types (ranged and rangeless ones). */ - public boolean disallowIntTypes; - - /** Whether to disallow rangeless integer types. */ - public boolean disallowIntTypesRangeless; - - /** Whether to disallow all list types (array and non-array ones). */ - public boolean disallowListTypes; + /** The types, or sub-types, to disallow. */ + private final EnumSet disalloweds; - /** Whether to disallow non-array list types. */ - public boolean disallowListTypesNonArray; - - /** Whether to disallow real types. */ - public boolean disallowRealTypes; - - /** Whether to disallow set types. */ - public boolean disallowSetTypes; - - /** Whether to disallow string types. */ - public boolean disallowStringTypes; - - /** Whether to disallow tuple types. Note that tuple types are also used for multi-assignments. */ - public boolean disallowTupleTypes; - - /** Whether to disallow void types (of channels). */ - public boolean disallowVoidTypes; + /** + * Constructor for the {@link NoSpecificTypesCheck} class. + * + * @param disalloweds The types, or sub-types, to disallow. + */ + public NoSpecificTypesCheck(EnumSet disalloweds) { + this.disalloweds = disalloweds; + } @Override protected void preprocessComponentDefType(ComponentDefType compDefType) { - if (disallowCompDefTypes) { + if (disalloweds.contains(NoSpecificType.COMP_DEF_TYPES)) { addTypeViolation(compDefType, "component definition type"); } } @Override protected void preprocessComponentType(ComponentType compType) { - if (disallowCompTypes) { + if (disalloweds.contains(NoSpecificType.COMP_TYPES)) { addTypeViolation(compType, "component type"); } } @Override protected void preprocessDictType(DictType dictType) { - if (disallowDictTypes) { + if (disalloweds.contains(NoSpecificType.DICT_TYPES)) { addTypeViolation(dictType, "dictionary type"); } } @Override protected void preprocessDistType(DistType distType) { - if (disallowDistTypes) { + if (disalloweds.contains(NoSpecificType.DIST_TYPES)) { addTypeViolation(distType, "distribution type"); } } @Override protected void preprocessEnumType(EnumType enumType) { - if (disallowEnumTypes) { + if (disalloweds.contains(NoSpecificType.ENUM_TYPES)) { addTypeViolation(enumType, "enumeration type"); } } @Override protected void preprocessFuncType(FuncType funcType) { - if (disallowFuncTypes) { + if (disalloweds.contains(NoSpecificType.FUNC_TYPES)) { addTypeViolation(funcType, "function type"); } } @Override protected void preprocessIntType(IntType intType) { - if (disallowIntTypes) { + if (disalloweds.contains(NoSpecificType.INT_TYPES)) { addTypeViolation(intType, "integer type"); - } else if (disallowIntTypesRangeless && CifTypeUtils.isRangeless(intType)) { + } else if (disalloweds.contains(NoSpecificType.INT_TYPES_RANGELESS) && CifTypeUtils.isRangeless(intType)) { addTypeViolation(intType, "rangeless integer type"); } } @Override protected void preprocessListType(ListType listType) { - if (disallowListTypes) { + if (disalloweds.contains(NoSpecificType.LIST_TYPES)) { addTypeViolation(listType, "list type"); - } else if (disallowListTypesNonArray && !CifTypeUtils.isArrayType(listType)) { + } else if (disalloweds.contains(NoSpecificType.LIST_TYPES_NON_ARRAY) && !CifTypeUtils.isArrayType(listType)) { addTypeViolation(listType, "non-array list type"); } } @Override protected void preprocessRealType(RealType realType) { - if (disallowRealTypes) { + if (disalloweds.contains(NoSpecificType.REAL_TYPES)) { addTypeViolation(realType, "real type"); } } @Override protected void preprocessSetType(SetType setType) { - if (disallowSetTypes) { + if (disalloweds.contains(NoSpecificType.SET_TYPES)) { addTypeViolation(setType, "set type"); } } @Override protected void preprocessStringType(StringType stringType) { - if (disallowStringTypes) { + if (disalloweds.contains(NoSpecificType.STRING_TYPES)) { addTypeViolation(stringType, "string type"); } } @Override protected void preprocessTupleType(TupleType tupleType) { - if (disallowTupleTypes) { + if (disalloweds.contains(NoSpecificType.TUPLE_TYPES)) { addTypeViolation(tupleType, "tuple type"); } } @Override protected void preprocessVoidType(VoidType voidType) { - if (disallowVoidTypes) { + if (disalloweds.contains(NoSpecificType.VOID_TYPES)) { addTypeViolation(voidType, "void type"); } } @@ -190,4 +159,52 @@ public class NoSpecificTypesCheck extends CifCheck { private void addTypeViolation(CifType type, String description) { super.addViolation(getNamedSelfOrAncestor(type), fmt("uses %s \"%s\"", description, typeToStr(type))); } + + /** The type, or sub-type, to disallow. */ + public static enum NoSpecificType { + /** Disallow component definition types. */ + COMP_DEF_TYPES, + + /** Disallow component types. */ + COMP_TYPES, + + /** Disallow dictionary types. */ + DICT_TYPES, + + /** Disallow distribution types. */ + DIST_TYPES, + + /** Disallow enumeration types. */ + ENUM_TYPES, + + /** Disallow function types. Note that this includes standard library function types. */ + FUNC_TYPES, + + /** Disallow all integer types (ranged and rangeless ones). */ + INT_TYPES, + + /** Disallow rangeless integer types. */ + INT_TYPES_RANGELESS, + + /** Disallow all list types (array and non-array ones). */ + LIST_TYPES, + + /** Disallow non-array list types. */ + LIST_TYPES_NON_ARRAY, + + /** Disallow real types. */ + REAL_TYPES, + + /** Disallow set types. */ + SET_TYPES, + + /** Disallow string types. */ + STRING_TYPES, + + /** Disallow tuple types. Note that tuple types are also used for multi-assignments. */ + TUPLE_TYPES, + + /** Disallow void types (of channels). */ + VOID_TYPES, + } } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificUnaryExprsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificUnaryExprsCheck.java index a7e93c582..512fe0ce2 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificUnaryExprsCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificUnaryExprsCheck.java @@ -19,6 +19,8 @@ import static org.eclipse.escet.cif.common.CifTextUtils.operatorToStr; import static org.eclipse.escet.cif.common.CifTextUtils.typeToStr; import static org.eclipse.escet.common.java.Strings.fmt; +import java.util.EnumSet; + import org.eclipse.escet.cif.common.CifTypeUtils; import org.eclipse.escet.cif.metamodel.cif.expressions.UnaryExpression; import org.eclipse.escet.cif.metamodel.cif.expressions.UnaryOperator; @@ -28,41 +30,17 @@ import org.eclipse.escet.cif.metamodel.cif.types.RealType; /** CIF check that does not allow certain unary expressions. */ public class NoSpecificUnaryExprsCheck extends CifCheck { - /** Whether to disallow {@link UnaryOperator#INVERSE}. */ - public boolean disallowInverse; - - /** Whether to disallow {@link UnaryOperator#NEGATE}. */ - public boolean disallowNegate; - - /** Whether to disallow {@link UnaryOperator#NEGATE} on integer numbers. */ - public boolean disallowNegateInts; - - /** Whether to disallow {@link UnaryOperator#NEGATE} on ranged integer numbers. */ - public boolean disallowNegateIntsRanged; - - /** Whether to disallow {@link UnaryOperator#NEGATE} on rangeless integer numbers. */ - public boolean disallowNegateIntsRangeless; - - /** Whether to disallow {@link UnaryOperator#NEGATE} on real numbers. */ - public boolean disallowNegateReals; - - /** Whether to disallow {@link UnaryOperator#PLUS}. */ - public boolean disallowPlus; + /** The unary operators, or unary operators operating on certain operand types, to disallow. */ + private final EnumSet disalloweds; - /** Whether to disallow {@link UnaryOperator#PLUS} on integer numbers. */ - public boolean disallowPlusInts; - - /** Whether to disallow {@link UnaryOperator#PLUS} on ranged integer numbers. */ - public boolean disallowPlusIntsRanged; - - /** Whether to disallow {@link UnaryOperator#PLUS} on rangeless integer numbers. */ - public boolean disallowPlusIntsRangeless; - - /** Whether to disallow {@link UnaryOperator#PLUS} on real numbers. */ - public boolean disallowPlusReals; - - /** Whether to disallow {@link UnaryOperator#SAMPLE}. */ - public boolean disallowSample; + /** + * Constructor for the {@link NoSpecificUnaryExprsCheck} class. + * + * @param disalloweds The unary operators, or unary operators operating on certain operand types, to disallow. + */ + public NoSpecificUnaryExprsCheck(EnumSet disalloweds) { + this.disalloweds = disalloweds; + } @Override protected void preprocessUnaryExpression(UnaryExpression unExpr) { @@ -70,62 +48,62 @@ public class NoSpecificUnaryExprsCheck extends CifCheck { CifType ctype = CifTypeUtils.normalizeType(unExpr.getChild().getType()); switch (op) { case INVERSE: - if (disallowInverse) { + if (disalloweds.contains(NoSpecificUnaryOp.INVERSE)) { addExprViolationOperator(unExpr); } break; case NEGATE: - if (disallowNegate) { + if (disalloweds.contains(NoSpecificUnaryOp.NEGATE)) { addExprViolationOperator(unExpr); } else { - if (disallowNegateInts) { + if (disalloweds.contains(NoSpecificUnaryOp.NEGATE_INTS)) { if (ctype instanceof IntType) { addExprViolationOperand(unExpr); } } else { - if (disallowNegateIntsRanged && ctype instanceof IntType + if (disalloweds.contains(NoSpecificUnaryOp.NEGATE_INTS_RANGED) && ctype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ctype)) { addExprViolationOperand(unExpr); } - if (disallowNegateIntsRangeless && ctype instanceof IntType + if (disalloweds.contains(NoSpecificUnaryOp.NEGATE_INTS_RANGELESS) && ctype instanceof IntType && CifTypeUtils.isRangeless((IntType)ctype)) { addExprViolationOperand(unExpr); } } - if (disallowNegateReals && ctype instanceof RealType) { + if (disalloweds.contains(NoSpecificUnaryOp.NEGATE_REALS) && ctype instanceof RealType) { addExprViolationOperand(unExpr); } } break; case PLUS: - if (disallowPlus) { + if (disalloweds.contains(NoSpecificUnaryOp.PLUS)) { addExprViolationOperator(unExpr); } else { - if (disallowPlusInts) { + if (disalloweds.contains(NoSpecificUnaryOp.PLUS_INTS)) { if (ctype instanceof IntType) { addExprViolationOperand(unExpr); } } else { - if (disallowPlusIntsRanged && ctype instanceof IntType + if (disalloweds.contains(NoSpecificUnaryOp.PLUS_INTS_RANGED) && ctype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ctype)) { addExprViolationOperand(unExpr); } - if (disallowPlusIntsRangeless && ctype instanceof IntType + if (disalloweds.contains(NoSpecificUnaryOp.PLUS_INTS_RANGELESS) && ctype instanceof IntType && CifTypeUtils.isRangeless((IntType)ctype)) { addExprViolationOperand(unExpr); } } - if (disallowPlusReals && ctype instanceof RealType) { + if (disalloweds.contains(NoSpecificUnaryOp.PLUS_REALS) && ctype instanceof RealType) { addExprViolationOperand(unExpr); } } break; case SAMPLE: - if (disallowSample) { + if (disalloweds.contains(NoSpecificUnaryOp.SAMPLE)) { addExprViolationOperator(unExpr); } break; @@ -155,4 +133,43 @@ public class NoSpecificUnaryExprsCheck extends CifCheck { fmt("uses unary operator \"%s\" on an operand of type \"%s\" in unary expression \"%s\"", operatorToStr(unExpr.getOperator()), typeToStr(ctype), exprToStr(unExpr))); } + + /** The unary operator, or unary operator operating on certain operand types, to disallow. */ + public static enum NoSpecificUnaryOp { + /** Disallow {@link UnaryOperator#INVERSE}. */ + INVERSE, + + /** Disallow {@link UnaryOperator#NEGATE}. */ + NEGATE, + + /** Disallow {@link UnaryOperator#NEGATE} on integer numbers. */ + NEGATE_INTS, + + /** Disallow {@link UnaryOperator#NEGATE} on ranged integer numbers. */ + NEGATE_INTS_RANGED, + + /** Disallow {@link UnaryOperator#NEGATE} on rangeless integer numbers. */ + NEGATE_INTS_RANGELESS, + + /** Disallow {@link UnaryOperator#NEGATE} on real numbers. */ + NEGATE_REALS, + + /** Disallow {@link UnaryOperator#PLUS}. */ + PLUS, + + /** Disallow {@link UnaryOperator#PLUS} on integer numbers. */ + PLUS_INTS, + + /** Disallow {@link UnaryOperator#PLUS} on ranged integer numbers. */ + PLUS_INTS_RANGED, + + /** Disallow {@link UnaryOperator#PLUS} on rangeless integer numbers. */ + PLUS_INTS_RANGELESS, + + /** Disallow {@link UnaryOperator#PLUS} on real numbers. */ + PLUS_REALS, + + /** Disallow {@link UnaryOperator#SAMPLE}. */ + SAMPLE, + } } -- GitLab From fc37f60621c2334609fd25eec2d54fa081e42252 Mon Sep 17 00:00:00 2001 From: Dennis Hendriks Date: Fri, 10 Jun 2022 20:56:52 +0200 Subject: [PATCH 20/23] #370 Small CIF check improvement + update cif2supremica tests. --- .../common/checkers/NoDiscVarsWithMultiInitValuesCheck.java | 2 +- .../tests/cif2supremica/invalid1.cif.cif2supremica.err | 4 ++-- .../tests/cif2supremica/invalid3.cif.cif2supremica.err | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoDiscVarsWithMultiInitValuesCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoDiscVarsWithMultiInitValuesCheck.java index 7c0a9b3b8..63ef98288 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoDiscVarsWithMultiInitValuesCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoDiscVarsWithMultiInitValuesCheck.java @@ -37,7 +37,7 @@ public class NoDiscVarsWithMultiInitValuesCheck extends CifCheck { // Check number of potential initial values. int count = var.getValue().getValues().size(); if (count == 0) { // 0 means 'any' initial value. - addViolation(var, "discrete variable has multiple (\"any\" value in its domain) potential initial values"); + addViolation(var, "discrete variable has multiple potential initial values (any value in its domain)"); } else if (count > 1) { addViolation(var, fmt("discrete variable has multiple (%d) potential initial values", count)); } diff --git a/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid1.cif.cif2supremica.err b/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid1.cif.cif2supremica.err index 481e29d67..764cb6f25 100644 --- a/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid1.cif.cif2supremica.err +++ b/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid1.cif.cif2supremica.err @@ -41,10 +41,10 @@ ERROR: CIF to Supremica transformation failed due to unsatisfied preconditions: - Unsupported "g.p0.lb": uses list type "list[1] bool". - Unsupported "g.p0.x1": discrete variable has multiple (2) potential initial values. - Unsupported "g.p0.x1": discrete variable has multiple predicates to specify its marked values. - - Unsupported "g.p0.x2": discrete variable has multiple potential initial values. - - Unsupported "g.p1": automaton has a location with a marker predicate for which static evaluation resulted in an evaluation error. + - Unsupported "g.p0.x2": discrete variable has multiple potential initial values (any value in its domain). - Unsupported "g.p1": automaton has a location with a state invariant. - Unsupported "g.p1": failed to determine whether the automaton's location is an initial location, as evaluating one of its initialization predicates resulted in an evaluation error. + - Unsupported "g.p1": static evaluation of a marker predicate in the location of the automaton resulted in an evaluation error. - Unsupported "g.p1": uses binary operator ">" on operands of types "real" and "int[0..0]" in binary expression "sqrt(-1.0) > 0". - Unsupported "g.p1": uses binary operator ">" on operands of types "real" and "int[0..0]" in binary expression "sqrt(-2.0) > 0". - Unsupported "g.p1": uses function call "sqrt(-1.0)". diff --git a/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid3.cif.cif2supremica.err b/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid3.cif.cif2supremica.err index c6fce43a5..861b059d3 100644 --- a/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid3.cif.cif2supremica.err +++ b/cif/org.eclipse.escet.cif.tests/tests/cif2supremica/invalid3.cif.cif2supremica.err @@ -1,3 +1,3 @@ ERROR: CIF to Supremica transformation failed due to unsatisfied preconditions: - Unsupported "p": failed to determine whether the automaton's location is an initial location, as one of its initialization predicates can not be statically evaluated. - - Unsupported "p.b": discrete variable has multiple potential initial values. + - Unsupported "p.b": discrete variable has multiple potential initial values (any value in its domain). -- GitLab From 8cd357ea65789fd17eae5504e4ea141d9a6beb63 Mon Sep 17 00:00:00 2001 From: Dennis Hendriks Date: Sat, 11 Jun 2022 07:52:53 +0200 Subject: [PATCH 21/23] #370 Generate CIF (composite) walkers with extra-argument methods. --- .../gen-cif-walker.launch | 2 +- .../cif/metamodel/java/CifWithArgWalker.java | 8136 +++++++++++++++++ .../java/CompositeCifWithArgWalker.java | 1906 ++++ .../codegen/java/ModelWalkerGenerator.java | 115 +- 4 files changed, 10124 insertions(+), 35 deletions(-) create mode 100644 cif/org.eclipse.escet.cif.metamodel.java/src-gen/org/eclipse/escet/cif/metamodel/java/CifWithArgWalker.java create mode 100644 cif/org.eclipse.escet.cif.metamodel.java/src-gen/org/eclipse/escet/cif/metamodel/java/CompositeCifWithArgWalker.java diff --git a/cif/org.eclipse.escet.cif.metamodel.java/gen-cif-walker.launch b/cif/org.eclipse.escet.cif.metamodel.java/gen-cif-walker.launch index 2134b035e..dd6a35d79 100644 --- a/cif/org.eclipse.escet.cif.metamodel.java/gen-cif-walker.launch +++ b/cif/org.eclipse.escet.cif.metamodel.java/gen-cif-walker.launch @@ -8,7 +8,7 @@ - + diff --git a/cif/org.eclipse.escet.cif.metamodel.java/src-gen/org/eclipse/escet/cif/metamodel/java/CifWithArgWalker.java b/cif/org.eclipse.escet.cif.metamodel.java/src-gen/org/eclipse/escet/cif/metamodel/java/CifWithArgWalker.java new file mode 100644 index 000000000..025fbc65a --- /dev/null +++ b/cif/org.eclipse.escet.cif.metamodel.java/src-gen/org/eclipse/escet/cif/metamodel/java/CifWithArgWalker.java @@ -0,0 +1,8136 @@ +////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2010, 2022 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available +// under the terms of the MIT License which is available at +// https://opensource.org/licenses/MIT +// +// SPDX-License-Identifier: MIT +////////////////////////////////////////////////////////////////////////////// + +// Generated using the "org.eclipse.escet.common.emf.ecore.codegen" project. + +// Disable Eclipse Java formatter for generated code file: +// @formatter:off + +package org.eclipse.escet.cif.metamodel.java; + +import java.util.List; + +import org.eclipse.escet.cif.metamodel.cif.AlgParameter; +import org.eclipse.escet.cif.metamodel.cif.ComplexComponent; +import org.eclipse.escet.cif.metamodel.cif.Component; +import org.eclipse.escet.cif.metamodel.cif.ComponentDef; +import org.eclipse.escet.cif.metamodel.cif.ComponentInst; +import org.eclipse.escet.cif.metamodel.cif.ComponentParameter; +import org.eclipse.escet.cif.metamodel.cif.Equation; +import org.eclipse.escet.cif.metamodel.cif.EventParameter; +import org.eclipse.escet.cif.metamodel.cif.Group; +import org.eclipse.escet.cif.metamodel.cif.Invariant; +import org.eclipse.escet.cif.metamodel.cif.IoDecl; +import org.eclipse.escet.cif.metamodel.cif.LocationParameter; +import org.eclipse.escet.cif.metamodel.cif.Parameter; +import org.eclipse.escet.cif.metamodel.cif.Specification; +import org.eclipse.escet.cif.metamodel.cif.automata.Alphabet; +import org.eclipse.escet.cif.metamodel.cif.automata.Assignment; +import org.eclipse.escet.cif.metamodel.cif.automata.Automaton; +import org.eclipse.escet.cif.metamodel.cif.automata.Edge; +import org.eclipse.escet.cif.metamodel.cif.automata.EdgeEvent; +import org.eclipse.escet.cif.metamodel.cif.automata.EdgeReceive; +import org.eclipse.escet.cif.metamodel.cif.automata.EdgeSend; +import org.eclipse.escet.cif.metamodel.cif.automata.ElifUpdate; +import org.eclipse.escet.cif.metamodel.cif.automata.IfUpdate; +import org.eclipse.escet.cif.metamodel.cif.automata.Location; +import org.eclipse.escet.cif.metamodel.cif.automata.Monitors; +import org.eclipse.escet.cif.metamodel.cif.automata.Update; +import org.eclipse.escet.cif.metamodel.cif.automata.impl.EdgeEventImpl; +import org.eclipse.escet.cif.metamodel.cif.cifsvg.SvgCopy; +import org.eclipse.escet.cif.metamodel.cif.cifsvg.SvgFile; +import org.eclipse.escet.cif.metamodel.cif.cifsvg.SvgIn; +import org.eclipse.escet.cif.metamodel.cif.cifsvg.SvgInEvent; +import org.eclipse.escet.cif.metamodel.cif.cifsvg.SvgInEventIf; +import org.eclipse.escet.cif.metamodel.cif.cifsvg.SvgInEventIfEntry; +import org.eclipse.escet.cif.metamodel.cif.cifsvg.SvgInEventSingle; +import org.eclipse.escet.cif.metamodel.cif.cifsvg.SvgMove; +import org.eclipse.escet.cif.metamodel.cif.cifsvg.SvgOut; +import org.eclipse.escet.cif.metamodel.cif.declarations.AlgVariable; +import org.eclipse.escet.cif.metamodel.cif.declarations.Constant; +import org.eclipse.escet.cif.metamodel.cif.declarations.ContVariable; +import org.eclipse.escet.cif.metamodel.cif.declarations.Declaration; +import org.eclipse.escet.cif.metamodel.cif.declarations.DiscVariable; +import org.eclipse.escet.cif.metamodel.cif.declarations.EnumDecl; +import org.eclipse.escet.cif.metamodel.cif.declarations.EnumLiteral; +import org.eclipse.escet.cif.metamodel.cif.declarations.Event; +import org.eclipse.escet.cif.metamodel.cif.declarations.InputVariable; +import org.eclipse.escet.cif.metamodel.cif.declarations.TypeDecl; +import org.eclipse.escet.cif.metamodel.cif.declarations.VariableValue; +import org.eclipse.escet.cif.metamodel.cif.expressions.AlgVariableExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.BaseFunctionExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.BinaryExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.BoolExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.CastExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.CompInstWrapExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.CompParamExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.CompParamWrapExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.ComponentExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.ConstantExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.ContVariableExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.DictExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.DictPair; +import org.eclipse.escet.cif.metamodel.cif.expressions.DiscVariableExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.ElifExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.EnumLiteralExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.EventExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.Expression; +import org.eclipse.escet.cif.metamodel.cif.expressions.FieldExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.FunctionCallExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.FunctionExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.IfExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.InputVariableExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.IntExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.ListExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.LocationExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.ProjectionExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.RealExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.ReceivedExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.SelfExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.SetExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.SliceExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.StdLibFunctionExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.StringExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.SwitchCase; +import org.eclipse.escet.cif.metamodel.cif.expressions.SwitchExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.TauExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.TimeExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.TupleExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.UnaryExpression; +import org.eclipse.escet.cif.metamodel.cif.functions.AssignmentFuncStatement; +import org.eclipse.escet.cif.metamodel.cif.functions.BreakFuncStatement; +import org.eclipse.escet.cif.metamodel.cif.functions.ContinueFuncStatement; +import org.eclipse.escet.cif.metamodel.cif.functions.ElifFuncStatement; +import org.eclipse.escet.cif.metamodel.cif.functions.ExternalFunction; +import org.eclipse.escet.cif.metamodel.cif.functions.Function; +import org.eclipse.escet.cif.metamodel.cif.functions.FunctionParameter; +import org.eclipse.escet.cif.metamodel.cif.functions.FunctionStatement; +import org.eclipse.escet.cif.metamodel.cif.functions.IfFuncStatement; +import org.eclipse.escet.cif.metamodel.cif.functions.InternalFunction; +import org.eclipse.escet.cif.metamodel.cif.functions.ReturnFuncStatement; +import org.eclipse.escet.cif.metamodel.cif.functions.WhileFuncStatement; +import org.eclipse.escet.cif.metamodel.cif.impl.GroupImpl; +import org.eclipse.escet.cif.metamodel.cif.print.Print; +import org.eclipse.escet.cif.metamodel.cif.print.PrintFile; +import org.eclipse.escet.cif.metamodel.cif.print.PrintFor; +import org.eclipse.escet.cif.metamodel.cif.types.BoolType; +import org.eclipse.escet.cif.metamodel.cif.types.CifType; +import org.eclipse.escet.cif.metamodel.cif.types.CompInstWrapType; +import org.eclipse.escet.cif.metamodel.cif.types.CompParamWrapType; +import org.eclipse.escet.cif.metamodel.cif.types.ComponentDefType; +import org.eclipse.escet.cif.metamodel.cif.types.ComponentType; +import org.eclipse.escet.cif.metamodel.cif.types.DictType; +import org.eclipse.escet.cif.metamodel.cif.types.DistType; +import org.eclipse.escet.cif.metamodel.cif.types.EnumType; +import org.eclipse.escet.cif.metamodel.cif.types.Field; +import org.eclipse.escet.cif.metamodel.cif.types.FuncType; +import org.eclipse.escet.cif.metamodel.cif.types.IntType; +import org.eclipse.escet.cif.metamodel.cif.types.ListType; +import org.eclipse.escet.cif.metamodel.cif.types.RealType; +import org.eclipse.escet.cif.metamodel.cif.types.SetType; +import org.eclipse.escet.cif.metamodel.cif.types.StringType; +import org.eclipse.escet.cif.metamodel.cif.types.TupleType; +import org.eclipse.escet.cif.metamodel.cif.types.TypeRef; +import org.eclipse.escet.cif.metamodel.cif.types.VoidType; +import org.eclipse.escet.common.java.Assert; +import org.eclipse.escet.common.position.metamodel.position.Position; +import org.eclipse.escet.common.position.metamodel.position.PositionObject; + +/** + * A walker for "cif" models. + * + *

    The walker works as follows: + *

      + *
    • Performs a top-down depth-first walk over the object tree, using the + * containment hierarchy.
    • + *
    • No particular order should be assumed for walking over the child + * features.
    • + *
    • For each object encountered, pre-processing is performed before walking + * over the children, and post-processing is performed after walking over + * the children.
    • + *
    • Pre-processing for objects is done by crawling up the inheritance + * hierarchy of the object, performing pre-processing for each of the + * types encountered in the type hierarchy. The pre-processing methods are + * invoked from most general to most specific class (super classes before + * base classes).
    • + *
    • Post-processing for objects is done by crawling up the inheritance + * hierarchy of the object, performing post-processing for each of the + * types encountered in the type hierarchy. The post-processing methods are + * invoked from most specific to most general class (base classes before + * super classes).
    • + *
    + *

    + * + *

    By default, the pre-processing and post-processing methods do nothing + * (they have an empty implementation). It is up to derived classes to + * override methods and provide actual implementations. They may also override + * walk and crawl methods, if desired.

    + * + *

    This abstract walker class has no public methods. It is up to the derived + * classes to add a public method as entry method. They can decide which + * classes are to be used as starting point, and they can give the public + * method a proper name, parameters, etc. They may even allow multiple public + * methods to allow starting from multiple classes.

    + * + * @param The type of the extra argument provided to the walking, crawling + * and processing methods. + */ +public abstract class CifWithArgWalker { + /** + * Walking function for the {@link AlgParameter} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkAlgParameter(AlgParameter obj, T arg) { + precrawlAlgParameter(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + AlgVariable _variable = obj.getVariable(); + walkAlgVariable(_variable, arg); + postcrawlAlgParameter(obj, arg); + } + + /** + * Pre-crawling function for the {@link AlgParameter} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlAlgParameter(AlgParameter obj, T arg) { + precrawlParameter(obj, arg); + preprocessAlgParameter(obj, arg); + } + + /** + * Post-crawling function for the {@link AlgParameter} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlAlgParameter(AlgParameter obj, T arg) { + postprocessAlgParameter(obj, arg); + postcrawlParameter(obj, arg); + } + + /** + * Pre-processing function for the {@link AlgParameter} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessAlgParameter(AlgParameter obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link AlgParameter} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessAlgParameter(AlgParameter obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link AlgVariable} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkAlgVariable(AlgVariable obj, T arg) { + precrawlAlgVariable(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + Expression _value = obj.getValue(); + if (_value != null) { + walkExpression(_value, arg); + } + postcrawlAlgVariable(obj, arg); + } + + /** + * Pre-crawling function for the {@link AlgVariable} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlAlgVariable(AlgVariable obj, T arg) { + precrawlDeclaration(obj, arg); + preprocessAlgVariable(obj, arg); + } + + /** + * Post-crawling function for the {@link AlgVariable} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlAlgVariable(AlgVariable obj, T arg) { + postprocessAlgVariable(obj, arg); + postcrawlDeclaration(obj, arg); + } + + /** + * Pre-processing function for the {@link AlgVariable} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessAlgVariable(AlgVariable obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link AlgVariable} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessAlgVariable(AlgVariable obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link AlgVariableExpression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkAlgVariableExpression(AlgVariableExpression obj, T arg) { + precrawlAlgVariableExpression(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlAlgVariableExpression(obj, arg); + } + + /** + * Pre-crawling function for the {@link AlgVariableExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlAlgVariableExpression(AlgVariableExpression obj, T arg) { + precrawlExpression(obj, arg); + preprocessAlgVariableExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link AlgVariableExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlAlgVariableExpression(AlgVariableExpression obj, T arg) { + postprocessAlgVariableExpression(obj, arg); + postcrawlExpression(obj, arg); + } + + /** + * Pre-processing function for the {@link AlgVariableExpression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessAlgVariableExpression(AlgVariableExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link AlgVariableExpression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessAlgVariableExpression(AlgVariableExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link Alphabet} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkAlphabet(Alphabet obj, T arg) { + precrawlAlphabet(obj, arg); + List _events = obj.getEvents(); + for (Expression x: _events) { + walkExpression(x, arg); + } + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + postcrawlAlphabet(obj, arg); + } + + /** + * Pre-crawling function for the {@link Alphabet} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlAlphabet(Alphabet obj, T arg) { + precrawlPositionObject(obj, arg); + preprocessAlphabet(obj, arg); + } + + /** + * Post-crawling function for the {@link Alphabet} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlAlphabet(Alphabet obj, T arg) { + postprocessAlphabet(obj, arg); + postcrawlPositionObject(obj, arg); + } + + /** + * Pre-processing function for the {@link Alphabet} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessAlphabet(Alphabet obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link Alphabet} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessAlphabet(Alphabet obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link Assignment} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkAssignment(Assignment obj, T arg) { + precrawlAssignment(obj, arg); + Expression _addressable = obj.getAddressable(); + walkExpression(_addressable, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + Expression _value = obj.getValue(); + walkExpression(_value, arg); + postcrawlAssignment(obj, arg); + } + + /** + * Pre-crawling function for the {@link Assignment} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlAssignment(Assignment obj, T arg) { + precrawlUpdate(obj, arg); + preprocessAssignment(obj, arg); + } + + /** + * Post-crawling function for the {@link Assignment} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlAssignment(Assignment obj, T arg) { + postprocessAssignment(obj, arg); + postcrawlUpdate(obj, arg); + } + + /** + * Pre-processing function for the {@link Assignment} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessAssignment(Assignment obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link Assignment} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessAssignment(Assignment obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link AssignmentFuncStatement} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkAssignmentFuncStatement(AssignmentFuncStatement obj, T arg) { + precrawlAssignmentFuncStatement(obj, arg); + Expression _addressable = obj.getAddressable(); + walkExpression(_addressable, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + Expression _value = obj.getValue(); + walkExpression(_value, arg); + postcrawlAssignmentFuncStatement(obj, arg); + } + + /** + * Pre-crawling function for the {@link AssignmentFuncStatement} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlAssignmentFuncStatement(AssignmentFuncStatement obj, T arg) { + precrawlFunctionStatement(obj, arg); + preprocessAssignmentFuncStatement(obj, arg); + } + + /** + * Post-crawling function for the {@link AssignmentFuncStatement} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlAssignmentFuncStatement(AssignmentFuncStatement obj, T arg) { + postprocessAssignmentFuncStatement(obj, arg); + postcrawlFunctionStatement(obj, arg); + } + + /** + * Pre-processing function for the {@link AssignmentFuncStatement} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessAssignmentFuncStatement(AssignmentFuncStatement obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link AssignmentFuncStatement} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessAssignmentFuncStatement(AssignmentFuncStatement obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link Automaton} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkAutomaton(Automaton obj, T arg) { + precrawlAutomaton(obj, arg); + Alphabet _alphabet = obj.getAlphabet(); + if (_alphabet != null) { + walkAlphabet(_alphabet, arg); + } + List _declarations = obj.getDeclarations(); + for (Declaration x: _declarations) { + walkDeclaration(x, arg); + } + List _equations = obj.getEquations(); + for (Equation x: _equations) { + walkEquation(x, arg); + } + List _initials = obj.getInitials(); + for (Expression x: _initials) { + walkExpression(x, arg); + } + List _invariants = obj.getInvariants(); + for (Invariant x: _invariants) { + walkInvariant(x, arg); + } + List _ioDecls = obj.getIoDecls(); + for (IoDecl x: _ioDecls) { + walkIoDecl(x, arg); + } + List _locations = obj.getLocations(); + for (Location x: _locations) { + walkLocation(x, arg); + } + List _markeds = obj.getMarkeds(); + for (Expression x: _markeds) { + walkExpression(x, arg); + } + Monitors _monitors = obj.getMonitors(); + if (_monitors != null) { + walkMonitors(_monitors, arg); + } + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + postcrawlAutomaton(obj, arg); + } + + /** + * Pre-crawling function for the {@link Automaton} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlAutomaton(Automaton obj, T arg) { + precrawlComplexComponent(obj, arg); + preprocessAutomaton(obj, arg); + } + + /** + * Post-crawling function for the {@link Automaton} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlAutomaton(Automaton obj, T arg) { + postprocessAutomaton(obj, arg); + postcrawlComplexComponent(obj, arg); + } + + /** + * Pre-processing function for the {@link Automaton} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessAutomaton(Automaton obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link Automaton} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessAutomaton(Automaton obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link BaseFunctionExpression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkBaseFunctionExpression(BaseFunctionExpression obj, T arg) { + if (obj instanceof FunctionExpression) { + walkFunctionExpression((FunctionExpression)obj, arg); + return; + } + if (obj instanceof StdLibFunctionExpression) { + walkStdLibFunctionExpression((StdLibFunctionExpression)obj, arg); + return; + } + String msg = "No redirect; unexpected object type: " + obj; + throw new IllegalArgumentException(msg); + } + + /** + * Pre-crawling function for the {@link BaseFunctionExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlBaseFunctionExpression(BaseFunctionExpression obj, T arg) { + precrawlExpression(obj, arg); + preprocessBaseFunctionExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link BaseFunctionExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlBaseFunctionExpression(BaseFunctionExpression obj, T arg) { + postprocessBaseFunctionExpression(obj, arg); + postcrawlExpression(obj, arg); + } + + /** + * Pre-processing function for the {@link BaseFunctionExpression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessBaseFunctionExpression(BaseFunctionExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link BaseFunctionExpression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessBaseFunctionExpression(BaseFunctionExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link BinaryExpression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkBinaryExpression(BinaryExpression obj, T arg) { + precrawlBinaryExpression(obj, arg); + Expression _left = obj.getLeft(); + walkExpression(_left, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + Expression _right = obj.getRight(); + walkExpression(_right, arg); + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlBinaryExpression(obj, arg); + } + + /** + * Pre-crawling function for the {@link BinaryExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlBinaryExpression(BinaryExpression obj, T arg) { + precrawlExpression(obj, arg); + preprocessBinaryExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link BinaryExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlBinaryExpression(BinaryExpression obj, T arg) { + postprocessBinaryExpression(obj, arg); + postcrawlExpression(obj, arg); + } + + /** + * Pre-processing function for the {@link BinaryExpression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessBinaryExpression(BinaryExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link BinaryExpression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessBinaryExpression(BinaryExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link BoolExpression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkBoolExpression(BoolExpression obj, T arg) { + precrawlBoolExpression(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlBoolExpression(obj, arg); + } + + /** + * Pre-crawling function for the {@link BoolExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlBoolExpression(BoolExpression obj, T arg) { + precrawlExpression(obj, arg); + preprocessBoolExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link BoolExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlBoolExpression(BoolExpression obj, T arg) { + postprocessBoolExpression(obj, arg); + postcrawlExpression(obj, arg); + } + + /** + * Pre-processing function for the {@link BoolExpression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessBoolExpression(BoolExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link BoolExpression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessBoolExpression(BoolExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link BoolType} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkBoolType(BoolType obj, T arg) { + precrawlBoolType(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + postcrawlBoolType(obj, arg); + } + + /** + * Pre-crawling function for the {@link BoolType} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlBoolType(BoolType obj, T arg) { + precrawlCifType(obj, arg); + preprocessBoolType(obj, arg); + } + + /** + * Post-crawling function for the {@link BoolType} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlBoolType(BoolType obj, T arg) { + postprocessBoolType(obj, arg); + postcrawlCifType(obj, arg); + } + + /** + * Pre-processing function for the {@link BoolType} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessBoolType(BoolType obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link BoolType} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessBoolType(BoolType obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link BreakFuncStatement} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkBreakFuncStatement(BreakFuncStatement obj, T arg) { + precrawlBreakFuncStatement(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + postcrawlBreakFuncStatement(obj, arg); + } + + /** + * Pre-crawling function for the {@link BreakFuncStatement} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlBreakFuncStatement(BreakFuncStatement obj, T arg) { + precrawlFunctionStatement(obj, arg); + preprocessBreakFuncStatement(obj, arg); + } + + /** + * Post-crawling function for the {@link BreakFuncStatement} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlBreakFuncStatement(BreakFuncStatement obj, T arg) { + postprocessBreakFuncStatement(obj, arg); + postcrawlFunctionStatement(obj, arg); + } + + /** + * Pre-processing function for the {@link BreakFuncStatement} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessBreakFuncStatement(BreakFuncStatement obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link BreakFuncStatement} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessBreakFuncStatement(BreakFuncStatement obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link CastExpression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkCastExpression(CastExpression obj, T arg) { + precrawlCastExpression(obj, arg); + Expression _child = obj.getChild(); + walkExpression(_child, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlCastExpression(obj, arg); + } + + /** + * Pre-crawling function for the {@link CastExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlCastExpression(CastExpression obj, T arg) { + precrawlExpression(obj, arg); + preprocessCastExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link CastExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlCastExpression(CastExpression obj, T arg) { + postprocessCastExpression(obj, arg); + postcrawlExpression(obj, arg); + } + + /** + * Pre-processing function for the {@link CastExpression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessCastExpression(CastExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link CastExpression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessCastExpression(CastExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link CifType} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkCifType(CifType obj, T arg) { + if (obj instanceof BoolType) { + walkBoolType((BoolType)obj, arg); + return; + } + if (obj instanceof CompInstWrapType) { + walkCompInstWrapType((CompInstWrapType)obj, arg); + return; + } + if (obj instanceof CompParamWrapType) { + walkCompParamWrapType((CompParamWrapType)obj, arg); + return; + } + if (obj instanceof ComponentDefType) { + walkComponentDefType((ComponentDefType)obj, arg); + return; + } + if (obj instanceof ComponentType) { + walkComponentType((ComponentType)obj, arg); + return; + } + if (obj instanceof DictType) { + walkDictType((DictType)obj, arg); + return; + } + if (obj instanceof DistType) { + walkDistType((DistType)obj, arg); + return; + } + if (obj instanceof EnumType) { + walkEnumType((EnumType)obj, arg); + return; + } + if (obj instanceof FuncType) { + walkFuncType((FuncType)obj, arg); + return; + } + if (obj instanceof IntType) { + walkIntType((IntType)obj, arg); + return; + } + if (obj instanceof ListType) { + walkListType((ListType)obj, arg); + return; + } + if (obj instanceof RealType) { + walkRealType((RealType)obj, arg); + return; + } + if (obj instanceof SetType) { + walkSetType((SetType)obj, arg); + return; + } + if (obj instanceof StringType) { + walkStringType((StringType)obj, arg); + return; + } + if (obj instanceof TupleType) { + walkTupleType((TupleType)obj, arg); + return; + } + if (obj instanceof TypeRef) { + walkTypeRef((TypeRef)obj, arg); + return; + } + if (obj instanceof VoidType) { + walkVoidType((VoidType)obj, arg); + return; + } + String msg = "No redirect; unexpected object type: " + obj; + throw new IllegalArgumentException(msg); + } + + /** + * Pre-crawling function for the {@link CifType} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlCifType(CifType obj, T arg) { + precrawlPositionObject(obj, arg); + preprocessCifType(obj, arg); + } + + /** + * Post-crawling function for the {@link CifType} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlCifType(CifType obj, T arg) { + postprocessCifType(obj, arg); + postcrawlPositionObject(obj, arg); + } + + /** + * Pre-processing function for the {@link CifType} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessCifType(CifType obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link CifType} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessCifType(CifType obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link CompInstWrapExpression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkCompInstWrapExpression(CompInstWrapExpression obj, T arg) { + precrawlCompInstWrapExpression(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + Expression _reference = obj.getReference(); + walkExpression(_reference, arg); + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlCompInstWrapExpression(obj, arg); + } + + /** + * Pre-crawling function for the {@link CompInstWrapExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlCompInstWrapExpression(CompInstWrapExpression obj, T arg) { + precrawlExpression(obj, arg); + preprocessCompInstWrapExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link CompInstWrapExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlCompInstWrapExpression(CompInstWrapExpression obj, T arg) { + postprocessCompInstWrapExpression(obj, arg); + postcrawlExpression(obj, arg); + } + + /** + * Pre-processing function for the {@link CompInstWrapExpression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessCompInstWrapExpression(CompInstWrapExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link CompInstWrapExpression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessCompInstWrapExpression(CompInstWrapExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link CompInstWrapType} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkCompInstWrapType(CompInstWrapType obj, T arg) { + precrawlCompInstWrapType(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _reference = obj.getReference(); + walkCifType(_reference, arg); + postcrawlCompInstWrapType(obj, arg); + } + + /** + * Pre-crawling function for the {@link CompInstWrapType} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlCompInstWrapType(CompInstWrapType obj, T arg) { + precrawlCifType(obj, arg); + preprocessCompInstWrapType(obj, arg); + } + + /** + * Post-crawling function for the {@link CompInstWrapType} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlCompInstWrapType(CompInstWrapType obj, T arg) { + postprocessCompInstWrapType(obj, arg); + postcrawlCifType(obj, arg); + } + + /** + * Pre-processing function for the {@link CompInstWrapType} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessCompInstWrapType(CompInstWrapType obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link CompInstWrapType} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessCompInstWrapType(CompInstWrapType obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link CompParamExpression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkCompParamExpression(CompParamExpression obj, T arg) { + precrawlCompParamExpression(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlCompParamExpression(obj, arg); + } + + /** + * Pre-crawling function for the {@link CompParamExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlCompParamExpression(CompParamExpression obj, T arg) { + precrawlExpression(obj, arg); + preprocessCompParamExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link CompParamExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlCompParamExpression(CompParamExpression obj, T arg) { + postprocessCompParamExpression(obj, arg); + postcrawlExpression(obj, arg); + } + + /** + * Pre-processing function for the {@link CompParamExpression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessCompParamExpression(CompParamExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link CompParamExpression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessCompParamExpression(CompParamExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link CompParamWrapExpression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkCompParamWrapExpression(CompParamWrapExpression obj, T arg) { + precrawlCompParamWrapExpression(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + Expression _reference = obj.getReference(); + walkExpression(_reference, arg); + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlCompParamWrapExpression(obj, arg); + } + + /** + * Pre-crawling function for the {@link CompParamWrapExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlCompParamWrapExpression(CompParamWrapExpression obj, T arg) { + precrawlExpression(obj, arg); + preprocessCompParamWrapExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link CompParamWrapExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlCompParamWrapExpression(CompParamWrapExpression obj, T arg) { + postprocessCompParamWrapExpression(obj, arg); + postcrawlExpression(obj, arg); + } + + /** + * Pre-processing function for the {@link CompParamWrapExpression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessCompParamWrapExpression(CompParamWrapExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link CompParamWrapExpression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessCompParamWrapExpression(CompParamWrapExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link CompParamWrapType} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkCompParamWrapType(CompParamWrapType obj, T arg) { + precrawlCompParamWrapType(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _reference = obj.getReference(); + walkCifType(_reference, arg); + postcrawlCompParamWrapType(obj, arg); + } + + /** + * Pre-crawling function for the {@link CompParamWrapType} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlCompParamWrapType(CompParamWrapType obj, T arg) { + precrawlCifType(obj, arg); + preprocessCompParamWrapType(obj, arg); + } + + /** + * Post-crawling function for the {@link CompParamWrapType} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlCompParamWrapType(CompParamWrapType obj, T arg) { + postprocessCompParamWrapType(obj, arg); + postcrawlCifType(obj, arg); + } + + /** + * Pre-processing function for the {@link CompParamWrapType} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessCompParamWrapType(CompParamWrapType obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link CompParamWrapType} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessCompParamWrapType(CompParamWrapType obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link ComplexComponent} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkComplexComponent(ComplexComponent obj, T arg) { + if (obj instanceof Automaton) { + walkAutomaton((Automaton)obj, arg); + return; + } + if (obj instanceof Group) { + walkGroup((Group)obj, arg); + return; + } + String msg = "No redirect; unexpected object type: " + obj; + throw new IllegalArgumentException(msg); + } + + /** + * Pre-crawling function for the {@link ComplexComponent} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlComplexComponent(ComplexComponent obj, T arg) { + precrawlComponent(obj, arg); + preprocessComplexComponent(obj, arg); + } + + /** + * Post-crawling function for the {@link ComplexComponent} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlComplexComponent(ComplexComponent obj, T arg) { + postprocessComplexComponent(obj, arg); + postcrawlComponent(obj, arg); + } + + /** + * Pre-processing function for the {@link ComplexComponent} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessComplexComponent(ComplexComponent obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link ComplexComponent} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessComplexComponent(ComplexComponent obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link Component} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkComponent(Component obj, T arg) { + if (obj instanceof ComplexComponent) { + walkComplexComponent((ComplexComponent)obj, arg); + return; + } + if (obj instanceof ComponentInst) { + walkComponentInst((ComponentInst)obj, arg); + return; + } + String msg = "No redirect; unexpected object type: " + obj; + throw new IllegalArgumentException(msg); + } + + /** + * Pre-crawling function for the {@link Component} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlComponent(Component obj, T arg) { + precrawlPositionObject(obj, arg); + preprocessComponent(obj, arg); + } + + /** + * Post-crawling function for the {@link Component} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlComponent(Component obj, T arg) { + postprocessComponent(obj, arg); + postcrawlPositionObject(obj, arg); + } + + /** + * Pre-processing function for the {@link Component} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessComponent(Component obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link Component} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessComponent(Component obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link ComponentDef} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkComponentDef(ComponentDef obj, T arg) { + precrawlComponentDef(obj, arg); + ComplexComponent _body = obj.getBody(); + walkComplexComponent(_body, arg); + List _parameters = obj.getParameters(); + for (Parameter x: _parameters) { + walkParameter(x, arg); + } + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + postcrawlComponentDef(obj, arg); + } + + /** + * Pre-crawling function for the {@link ComponentDef} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlComponentDef(ComponentDef obj, T arg) { + precrawlPositionObject(obj, arg); + preprocessComponentDef(obj, arg); + } + + /** + * Post-crawling function for the {@link ComponentDef} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlComponentDef(ComponentDef obj, T arg) { + postprocessComponentDef(obj, arg); + postcrawlPositionObject(obj, arg); + } + + /** + * Pre-processing function for the {@link ComponentDef} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessComponentDef(ComponentDef obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link ComponentDef} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessComponentDef(ComponentDef obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link ComponentDefType} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkComponentDefType(ComponentDefType obj, T arg) { + precrawlComponentDefType(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + postcrawlComponentDefType(obj, arg); + } + + /** + * Pre-crawling function for the {@link ComponentDefType} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlComponentDefType(ComponentDefType obj, T arg) { + precrawlCifType(obj, arg); + preprocessComponentDefType(obj, arg); + } + + /** + * Post-crawling function for the {@link ComponentDefType} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlComponentDefType(ComponentDefType obj, T arg) { + postprocessComponentDefType(obj, arg); + postcrawlCifType(obj, arg); + } + + /** + * Pre-processing function for the {@link ComponentDefType} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessComponentDefType(ComponentDefType obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link ComponentDefType} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessComponentDefType(ComponentDefType obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link ComponentExpression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkComponentExpression(ComponentExpression obj, T arg) { + precrawlComponentExpression(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlComponentExpression(obj, arg); + } + + /** + * Pre-crawling function for the {@link ComponentExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlComponentExpression(ComponentExpression obj, T arg) { + precrawlExpression(obj, arg); + preprocessComponentExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link ComponentExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlComponentExpression(ComponentExpression obj, T arg) { + postprocessComponentExpression(obj, arg); + postcrawlExpression(obj, arg); + } + + /** + * Pre-processing function for the {@link ComponentExpression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessComponentExpression(ComponentExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link ComponentExpression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessComponentExpression(ComponentExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link ComponentInst} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkComponentInst(ComponentInst obj, T arg) { + precrawlComponentInst(obj, arg); + CifType _definition = obj.getDefinition(); + walkCifType(_definition, arg); + List _parameters = obj.getParameters(); + for (Expression x: _parameters) { + walkExpression(x, arg); + } + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + postcrawlComponentInst(obj, arg); + } + + /** + * Pre-crawling function for the {@link ComponentInst} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlComponentInst(ComponentInst obj, T arg) { + precrawlComponent(obj, arg); + preprocessComponentInst(obj, arg); + } + + /** + * Post-crawling function for the {@link ComponentInst} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlComponentInst(ComponentInst obj, T arg) { + postprocessComponentInst(obj, arg); + postcrawlComponent(obj, arg); + } + + /** + * Pre-processing function for the {@link ComponentInst} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessComponentInst(ComponentInst obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link ComponentInst} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessComponentInst(ComponentInst obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link ComponentParameter} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkComponentParameter(ComponentParameter obj, T arg) { + precrawlComponentParameter(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlComponentParameter(obj, arg); + } + + /** + * Pre-crawling function for the {@link ComponentParameter} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlComponentParameter(ComponentParameter obj, T arg) { + precrawlParameter(obj, arg); + preprocessComponentParameter(obj, arg); + } + + /** + * Post-crawling function for the {@link ComponentParameter} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlComponentParameter(ComponentParameter obj, T arg) { + postprocessComponentParameter(obj, arg); + postcrawlParameter(obj, arg); + } + + /** + * Pre-processing function for the {@link ComponentParameter} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessComponentParameter(ComponentParameter obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link ComponentParameter} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessComponentParameter(ComponentParameter obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link ComponentType} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkComponentType(ComponentType obj, T arg) { + precrawlComponentType(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + postcrawlComponentType(obj, arg); + } + + /** + * Pre-crawling function for the {@link ComponentType} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlComponentType(ComponentType obj, T arg) { + precrawlCifType(obj, arg); + preprocessComponentType(obj, arg); + } + + /** + * Post-crawling function for the {@link ComponentType} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlComponentType(ComponentType obj, T arg) { + postprocessComponentType(obj, arg); + postcrawlCifType(obj, arg); + } + + /** + * Pre-processing function for the {@link ComponentType} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessComponentType(ComponentType obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link ComponentType} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessComponentType(ComponentType obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link Constant} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkConstant(Constant obj, T arg) { + precrawlConstant(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + Expression _value = obj.getValue(); + walkExpression(_value, arg); + postcrawlConstant(obj, arg); + } + + /** + * Pre-crawling function for the {@link Constant} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlConstant(Constant obj, T arg) { + precrawlDeclaration(obj, arg); + preprocessConstant(obj, arg); + } + + /** + * Post-crawling function for the {@link Constant} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlConstant(Constant obj, T arg) { + postprocessConstant(obj, arg); + postcrawlDeclaration(obj, arg); + } + + /** + * Pre-processing function for the {@link Constant} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessConstant(Constant obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link Constant} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessConstant(Constant obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link ConstantExpression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkConstantExpression(ConstantExpression obj, T arg) { + precrawlConstantExpression(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlConstantExpression(obj, arg); + } + + /** + * Pre-crawling function for the {@link ConstantExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlConstantExpression(ConstantExpression obj, T arg) { + precrawlExpression(obj, arg); + preprocessConstantExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link ConstantExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlConstantExpression(ConstantExpression obj, T arg) { + postprocessConstantExpression(obj, arg); + postcrawlExpression(obj, arg); + } + + /** + * Pre-processing function for the {@link ConstantExpression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessConstantExpression(ConstantExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link ConstantExpression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessConstantExpression(ConstantExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link ContVariable} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkContVariable(ContVariable obj, T arg) { + precrawlContVariable(obj, arg); + Expression _derivative = obj.getDerivative(); + if (_derivative != null) { + walkExpression(_derivative, arg); + } + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + Expression _value = obj.getValue(); + if (_value != null) { + walkExpression(_value, arg); + } + postcrawlContVariable(obj, arg); + } + + /** + * Pre-crawling function for the {@link ContVariable} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlContVariable(ContVariable obj, T arg) { + precrawlDeclaration(obj, arg); + preprocessContVariable(obj, arg); + } + + /** + * Post-crawling function for the {@link ContVariable} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlContVariable(ContVariable obj, T arg) { + postprocessContVariable(obj, arg); + postcrawlDeclaration(obj, arg); + } + + /** + * Pre-processing function for the {@link ContVariable} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessContVariable(ContVariable obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link ContVariable} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessContVariable(ContVariable obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link ContVariableExpression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkContVariableExpression(ContVariableExpression obj, T arg) { + precrawlContVariableExpression(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlContVariableExpression(obj, arg); + } + + /** + * Pre-crawling function for the {@link ContVariableExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlContVariableExpression(ContVariableExpression obj, T arg) { + precrawlExpression(obj, arg); + preprocessContVariableExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link ContVariableExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlContVariableExpression(ContVariableExpression obj, T arg) { + postprocessContVariableExpression(obj, arg); + postcrawlExpression(obj, arg); + } + + /** + * Pre-processing function for the {@link ContVariableExpression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessContVariableExpression(ContVariableExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link ContVariableExpression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessContVariableExpression(ContVariableExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link ContinueFuncStatement} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkContinueFuncStatement(ContinueFuncStatement obj, T arg) { + precrawlContinueFuncStatement(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + postcrawlContinueFuncStatement(obj, arg); + } + + /** + * Pre-crawling function for the {@link ContinueFuncStatement} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlContinueFuncStatement(ContinueFuncStatement obj, T arg) { + precrawlFunctionStatement(obj, arg); + preprocessContinueFuncStatement(obj, arg); + } + + /** + * Post-crawling function for the {@link ContinueFuncStatement} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlContinueFuncStatement(ContinueFuncStatement obj, T arg) { + postprocessContinueFuncStatement(obj, arg); + postcrawlFunctionStatement(obj, arg); + } + + /** + * Pre-processing function for the {@link ContinueFuncStatement} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessContinueFuncStatement(ContinueFuncStatement obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link ContinueFuncStatement} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessContinueFuncStatement(ContinueFuncStatement obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link Declaration} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkDeclaration(Declaration obj, T arg) { + if (obj instanceof AlgVariable) { + walkAlgVariable((AlgVariable)obj, arg); + return; + } + if (obj instanceof Constant) { + walkConstant((Constant)obj, arg); + return; + } + if (obj instanceof ContVariable) { + walkContVariable((ContVariable)obj, arg); + return; + } + if (obj instanceof DiscVariable) { + walkDiscVariable((DiscVariable)obj, arg); + return; + } + if (obj instanceof EnumDecl) { + walkEnumDecl((EnumDecl)obj, arg); + return; + } + if (obj instanceof Event) { + walkEvent((Event)obj, arg); + return; + } + if (obj instanceof Function) { + walkFunction((Function)obj, arg); + return; + } + if (obj instanceof InputVariable) { + walkInputVariable((InputVariable)obj, arg); + return; + } + if (obj instanceof TypeDecl) { + walkTypeDecl((TypeDecl)obj, arg); + return; + } + String msg = "No redirect; unexpected object type: " + obj; + throw new IllegalArgumentException(msg); + } + + /** + * Pre-crawling function for the {@link Declaration} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlDeclaration(Declaration obj, T arg) { + precrawlPositionObject(obj, arg); + preprocessDeclaration(obj, arg); + } + + /** + * Post-crawling function for the {@link Declaration} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlDeclaration(Declaration obj, T arg) { + postprocessDeclaration(obj, arg); + postcrawlPositionObject(obj, arg); + } + + /** + * Pre-processing function for the {@link Declaration} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessDeclaration(Declaration obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link Declaration} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessDeclaration(Declaration obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link DictExpression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkDictExpression(DictExpression obj, T arg) { + precrawlDictExpression(obj, arg); + List _pairs = obj.getPairs(); + for (DictPair x: _pairs) { + walkDictPair(x, arg); + } + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlDictExpression(obj, arg); + } + + /** + * Pre-crawling function for the {@link DictExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlDictExpression(DictExpression obj, T arg) { + precrawlExpression(obj, arg); + preprocessDictExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link DictExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlDictExpression(DictExpression obj, T arg) { + postprocessDictExpression(obj, arg); + postcrawlExpression(obj, arg); + } + + /** + * Pre-processing function for the {@link DictExpression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessDictExpression(DictExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link DictExpression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessDictExpression(DictExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link DictPair} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkDictPair(DictPair obj, T arg) { + precrawlDictPair(obj, arg); + Expression _key = obj.getKey(); + walkExpression(_key, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + Expression _value = obj.getValue(); + walkExpression(_value, arg); + postcrawlDictPair(obj, arg); + } + + /** + * Pre-crawling function for the {@link DictPair} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlDictPair(DictPair obj, T arg) { + precrawlPositionObject(obj, arg); + preprocessDictPair(obj, arg); + } + + /** + * Post-crawling function for the {@link DictPair} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlDictPair(DictPair obj, T arg) { + postprocessDictPair(obj, arg); + postcrawlPositionObject(obj, arg); + } + + /** + * Pre-processing function for the {@link DictPair} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessDictPair(DictPair obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link DictPair} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessDictPair(DictPair obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link DictType} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkDictType(DictType obj, T arg) { + precrawlDictType(obj, arg); + CifType _keyType = obj.getKeyType(); + walkCifType(_keyType, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _valueType = obj.getValueType(); + walkCifType(_valueType, arg); + postcrawlDictType(obj, arg); + } + + /** + * Pre-crawling function for the {@link DictType} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlDictType(DictType obj, T arg) { + precrawlCifType(obj, arg); + preprocessDictType(obj, arg); + } + + /** + * Post-crawling function for the {@link DictType} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlDictType(DictType obj, T arg) { + postprocessDictType(obj, arg); + postcrawlCifType(obj, arg); + } + + /** + * Pre-processing function for the {@link DictType} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessDictType(DictType obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link DictType} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessDictType(DictType obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link DiscVariable} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkDiscVariable(DiscVariable obj, T arg) { + precrawlDiscVariable(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + VariableValue _value = obj.getValue(); + if (_value != null) { + walkVariableValue(_value, arg); + } + postcrawlDiscVariable(obj, arg); + } + + /** + * Pre-crawling function for the {@link DiscVariable} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlDiscVariable(DiscVariable obj, T arg) { + precrawlDeclaration(obj, arg); + preprocessDiscVariable(obj, arg); + } + + /** + * Post-crawling function for the {@link DiscVariable} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlDiscVariable(DiscVariable obj, T arg) { + postprocessDiscVariable(obj, arg); + postcrawlDeclaration(obj, arg); + } + + /** + * Pre-processing function for the {@link DiscVariable} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessDiscVariable(DiscVariable obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link DiscVariable} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessDiscVariable(DiscVariable obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link DiscVariableExpression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkDiscVariableExpression(DiscVariableExpression obj, T arg) { + precrawlDiscVariableExpression(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlDiscVariableExpression(obj, arg); + } + + /** + * Pre-crawling function for the {@link DiscVariableExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlDiscVariableExpression(DiscVariableExpression obj, T arg) { + precrawlExpression(obj, arg); + preprocessDiscVariableExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link DiscVariableExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlDiscVariableExpression(DiscVariableExpression obj, T arg) { + postprocessDiscVariableExpression(obj, arg); + postcrawlExpression(obj, arg); + } + + /** + * Pre-processing function for the {@link DiscVariableExpression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessDiscVariableExpression(DiscVariableExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link DiscVariableExpression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessDiscVariableExpression(DiscVariableExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link DistType} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkDistType(DistType obj, T arg) { + precrawlDistType(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _sampleType = obj.getSampleType(); + walkCifType(_sampleType, arg); + postcrawlDistType(obj, arg); + } + + /** + * Pre-crawling function for the {@link DistType} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlDistType(DistType obj, T arg) { + precrawlCifType(obj, arg); + preprocessDistType(obj, arg); + } + + /** + * Post-crawling function for the {@link DistType} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlDistType(DistType obj, T arg) { + postprocessDistType(obj, arg); + postcrawlCifType(obj, arg); + } + + /** + * Pre-processing function for the {@link DistType} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessDistType(DistType obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link DistType} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessDistType(DistType obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link Edge} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkEdge(Edge obj, T arg) { + precrawlEdge(obj, arg); + List _events = obj.getEvents(); + for (EdgeEvent x: _events) { + walkEdgeEvent(x, arg); + } + List _guards = obj.getGuards(); + for (Expression x: _guards) { + walkExpression(x, arg); + } + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + List _updates = obj.getUpdates(); + for (Update x: _updates) { + walkUpdate(x, arg); + } + postcrawlEdge(obj, arg); + } + + /** + * Pre-crawling function for the {@link Edge} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlEdge(Edge obj, T arg) { + precrawlPositionObject(obj, arg); + preprocessEdge(obj, arg); + } + + /** + * Post-crawling function for the {@link Edge} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlEdge(Edge obj, T arg) { + postprocessEdge(obj, arg); + postcrawlPositionObject(obj, arg); + } + + /** + * Pre-processing function for the {@link Edge} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessEdge(Edge obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link Edge} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessEdge(Edge obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link EdgeEvent} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkEdgeEvent(EdgeEvent obj, T arg) { + if (obj instanceof EdgeReceive) { + walkEdgeReceive((EdgeReceive)obj, arg); + return; + } + if (obj instanceof EdgeSend) { + walkEdgeSend((EdgeSend)obj, arg); + return; + } + Assert.check(obj.getClass() == EdgeEventImpl.class); + precrawlEdgeEvent(obj, arg); + Expression _event = obj.getEvent(); + walkExpression(_event, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + postcrawlEdgeEvent(obj, arg); + } + + /** + * Pre-crawling function for the {@link EdgeEvent} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlEdgeEvent(EdgeEvent obj, T arg) { + precrawlPositionObject(obj, arg); + preprocessEdgeEvent(obj, arg); + } + + /** + * Post-crawling function for the {@link EdgeEvent} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlEdgeEvent(EdgeEvent obj, T arg) { + postprocessEdgeEvent(obj, arg); + postcrawlPositionObject(obj, arg); + } + + /** + * Pre-processing function for the {@link EdgeEvent} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessEdgeEvent(EdgeEvent obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link EdgeEvent} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessEdgeEvent(EdgeEvent obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link EdgeReceive} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkEdgeReceive(EdgeReceive obj, T arg) { + precrawlEdgeReceive(obj, arg); + Expression _event = obj.getEvent(); + walkExpression(_event, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + postcrawlEdgeReceive(obj, arg); + } + + /** + * Pre-crawling function for the {@link EdgeReceive} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlEdgeReceive(EdgeReceive obj, T arg) { + precrawlEdgeEvent(obj, arg); + preprocessEdgeReceive(obj, arg); + } + + /** + * Post-crawling function for the {@link EdgeReceive} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlEdgeReceive(EdgeReceive obj, T arg) { + postprocessEdgeReceive(obj, arg); + postcrawlEdgeEvent(obj, arg); + } + + /** + * Pre-processing function for the {@link EdgeReceive} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessEdgeReceive(EdgeReceive obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link EdgeReceive} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessEdgeReceive(EdgeReceive obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link EdgeSend} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkEdgeSend(EdgeSend obj, T arg) { + precrawlEdgeSend(obj, arg); + Expression _event = obj.getEvent(); + walkExpression(_event, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + Expression _value = obj.getValue(); + if (_value != null) { + walkExpression(_value, arg); + } + postcrawlEdgeSend(obj, arg); + } + + /** + * Pre-crawling function for the {@link EdgeSend} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlEdgeSend(EdgeSend obj, T arg) { + precrawlEdgeEvent(obj, arg); + preprocessEdgeSend(obj, arg); + } + + /** + * Post-crawling function for the {@link EdgeSend} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlEdgeSend(EdgeSend obj, T arg) { + postprocessEdgeSend(obj, arg); + postcrawlEdgeEvent(obj, arg); + } + + /** + * Pre-processing function for the {@link EdgeSend} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessEdgeSend(EdgeSend obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link EdgeSend} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessEdgeSend(EdgeSend obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link ElifExpression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkElifExpression(ElifExpression obj, T arg) { + precrawlElifExpression(obj, arg); + List _guards = obj.getGuards(); + for (Expression x: _guards) { + walkExpression(x, arg); + } + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + Expression _then = obj.getThen(); + walkExpression(_then, arg); + postcrawlElifExpression(obj, arg); + } + + /** + * Pre-crawling function for the {@link ElifExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlElifExpression(ElifExpression obj, T arg) { + precrawlPositionObject(obj, arg); + preprocessElifExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link ElifExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlElifExpression(ElifExpression obj, T arg) { + postprocessElifExpression(obj, arg); + postcrawlPositionObject(obj, arg); + } + + /** + * Pre-processing function for the {@link ElifExpression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessElifExpression(ElifExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link ElifExpression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessElifExpression(ElifExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link ElifFuncStatement} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkElifFuncStatement(ElifFuncStatement obj, T arg) { + precrawlElifFuncStatement(obj, arg); + List _guards = obj.getGuards(); + for (Expression x: _guards) { + walkExpression(x, arg); + } + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + List _thens = obj.getThens(); + for (FunctionStatement x: _thens) { + walkFunctionStatement(x, arg); + } + postcrawlElifFuncStatement(obj, arg); + } + + /** + * Pre-crawling function for the {@link ElifFuncStatement} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlElifFuncStatement(ElifFuncStatement obj, T arg) { + precrawlPositionObject(obj, arg); + preprocessElifFuncStatement(obj, arg); + } + + /** + * Post-crawling function for the {@link ElifFuncStatement} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlElifFuncStatement(ElifFuncStatement obj, T arg) { + postprocessElifFuncStatement(obj, arg); + postcrawlPositionObject(obj, arg); + } + + /** + * Pre-processing function for the {@link ElifFuncStatement} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessElifFuncStatement(ElifFuncStatement obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link ElifFuncStatement} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessElifFuncStatement(ElifFuncStatement obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link ElifUpdate} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkElifUpdate(ElifUpdate obj, T arg) { + precrawlElifUpdate(obj, arg); + List _guards = obj.getGuards(); + for (Expression x: _guards) { + walkExpression(x, arg); + } + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + List _thens = obj.getThens(); + for (Update x: _thens) { + walkUpdate(x, arg); + } + postcrawlElifUpdate(obj, arg); + } + + /** + * Pre-crawling function for the {@link ElifUpdate} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlElifUpdate(ElifUpdate obj, T arg) { + precrawlPositionObject(obj, arg); + preprocessElifUpdate(obj, arg); + } + + /** + * Post-crawling function for the {@link ElifUpdate} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlElifUpdate(ElifUpdate obj, T arg) { + postprocessElifUpdate(obj, arg); + postcrawlPositionObject(obj, arg); + } + + /** + * Pre-processing function for the {@link ElifUpdate} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessElifUpdate(ElifUpdate obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link ElifUpdate} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessElifUpdate(ElifUpdate obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link EnumDecl} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkEnumDecl(EnumDecl obj, T arg) { + precrawlEnumDecl(obj, arg); + List _literals = obj.getLiterals(); + for (EnumLiteral x: _literals) { + walkEnumLiteral(x, arg); + } + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + postcrawlEnumDecl(obj, arg); + } + + /** + * Pre-crawling function for the {@link EnumDecl} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlEnumDecl(EnumDecl obj, T arg) { + precrawlDeclaration(obj, arg); + preprocessEnumDecl(obj, arg); + } + + /** + * Post-crawling function for the {@link EnumDecl} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlEnumDecl(EnumDecl obj, T arg) { + postprocessEnumDecl(obj, arg); + postcrawlDeclaration(obj, arg); + } + + /** + * Pre-processing function for the {@link EnumDecl} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessEnumDecl(EnumDecl obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link EnumDecl} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessEnumDecl(EnumDecl obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link EnumLiteral} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkEnumLiteral(EnumLiteral obj, T arg) { + precrawlEnumLiteral(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + postcrawlEnumLiteral(obj, arg); + } + + /** + * Pre-crawling function for the {@link EnumLiteral} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlEnumLiteral(EnumLiteral obj, T arg) { + precrawlPositionObject(obj, arg); + preprocessEnumLiteral(obj, arg); + } + + /** + * Post-crawling function for the {@link EnumLiteral} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlEnumLiteral(EnumLiteral obj, T arg) { + postprocessEnumLiteral(obj, arg); + postcrawlPositionObject(obj, arg); + } + + /** + * Pre-processing function for the {@link EnumLiteral} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessEnumLiteral(EnumLiteral obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link EnumLiteral} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessEnumLiteral(EnumLiteral obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link EnumLiteralExpression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkEnumLiteralExpression(EnumLiteralExpression obj, T arg) { + precrawlEnumLiteralExpression(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlEnumLiteralExpression(obj, arg); + } + + /** + * Pre-crawling function for the {@link EnumLiteralExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlEnumLiteralExpression(EnumLiteralExpression obj, T arg) { + precrawlExpression(obj, arg); + preprocessEnumLiteralExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link EnumLiteralExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlEnumLiteralExpression(EnumLiteralExpression obj, T arg) { + postprocessEnumLiteralExpression(obj, arg); + postcrawlExpression(obj, arg); + } + + /** + * Pre-processing function for the {@link EnumLiteralExpression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessEnumLiteralExpression(EnumLiteralExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link EnumLiteralExpression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessEnumLiteralExpression(EnumLiteralExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link EnumType} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkEnumType(EnumType obj, T arg) { + precrawlEnumType(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + postcrawlEnumType(obj, arg); + } + + /** + * Pre-crawling function for the {@link EnumType} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlEnumType(EnumType obj, T arg) { + precrawlCifType(obj, arg); + preprocessEnumType(obj, arg); + } + + /** + * Post-crawling function for the {@link EnumType} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlEnumType(EnumType obj, T arg) { + postprocessEnumType(obj, arg); + postcrawlCifType(obj, arg); + } + + /** + * Pre-processing function for the {@link EnumType} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessEnumType(EnumType obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link EnumType} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessEnumType(EnumType obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link Equation} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkEquation(Equation obj, T arg) { + precrawlEquation(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + Expression _value = obj.getValue(); + walkExpression(_value, arg); + postcrawlEquation(obj, arg); + } + + /** + * Pre-crawling function for the {@link Equation} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlEquation(Equation obj, T arg) { + precrawlPositionObject(obj, arg); + preprocessEquation(obj, arg); + } + + /** + * Post-crawling function for the {@link Equation} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlEquation(Equation obj, T arg) { + postprocessEquation(obj, arg); + postcrawlPositionObject(obj, arg); + } + + /** + * Pre-processing function for the {@link Equation} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessEquation(Equation obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link Equation} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessEquation(Equation obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link Event} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkEvent(Event obj, T arg) { + precrawlEvent(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + if (_type != null) { + walkCifType(_type, arg); + } + postcrawlEvent(obj, arg); + } + + /** + * Pre-crawling function for the {@link Event} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlEvent(Event obj, T arg) { + precrawlDeclaration(obj, arg); + preprocessEvent(obj, arg); + } + + /** + * Post-crawling function for the {@link Event} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlEvent(Event obj, T arg) { + postprocessEvent(obj, arg); + postcrawlDeclaration(obj, arg); + } + + /** + * Pre-processing function for the {@link Event} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessEvent(Event obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link Event} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessEvent(Event obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link EventExpression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkEventExpression(EventExpression obj, T arg) { + precrawlEventExpression(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlEventExpression(obj, arg); + } + + /** + * Pre-crawling function for the {@link EventExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlEventExpression(EventExpression obj, T arg) { + precrawlExpression(obj, arg); + preprocessEventExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link EventExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlEventExpression(EventExpression obj, T arg) { + postprocessEventExpression(obj, arg); + postcrawlExpression(obj, arg); + } + + /** + * Pre-processing function for the {@link EventExpression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessEventExpression(EventExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link EventExpression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessEventExpression(EventExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link EventParameter} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkEventParameter(EventParameter obj, T arg) { + precrawlEventParameter(obj, arg); + Event _event = obj.getEvent(); + walkEvent(_event, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + postcrawlEventParameter(obj, arg); + } + + /** + * Pre-crawling function for the {@link EventParameter} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlEventParameter(EventParameter obj, T arg) { + precrawlParameter(obj, arg); + preprocessEventParameter(obj, arg); + } + + /** + * Post-crawling function for the {@link EventParameter} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlEventParameter(EventParameter obj, T arg) { + postprocessEventParameter(obj, arg); + postcrawlParameter(obj, arg); + } + + /** + * Pre-processing function for the {@link EventParameter} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessEventParameter(EventParameter obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link EventParameter} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessEventParameter(EventParameter obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link Expression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkExpression(Expression obj, T arg) { + if (obj instanceof AlgVariableExpression) { + walkAlgVariableExpression((AlgVariableExpression)obj, arg); + return; + } + if (obj instanceof BaseFunctionExpression) { + walkBaseFunctionExpression((BaseFunctionExpression)obj, arg); + return; + } + if (obj instanceof BinaryExpression) { + walkBinaryExpression((BinaryExpression)obj, arg); + return; + } + if (obj instanceof BoolExpression) { + walkBoolExpression((BoolExpression)obj, arg); + return; + } + if (obj instanceof CastExpression) { + walkCastExpression((CastExpression)obj, arg); + return; + } + if (obj instanceof CompInstWrapExpression) { + walkCompInstWrapExpression((CompInstWrapExpression)obj, arg); + return; + } + if (obj instanceof CompParamExpression) { + walkCompParamExpression((CompParamExpression)obj, arg); + return; + } + if (obj instanceof CompParamWrapExpression) { + walkCompParamWrapExpression((CompParamWrapExpression)obj, arg); + return; + } + if (obj instanceof ComponentExpression) { + walkComponentExpression((ComponentExpression)obj, arg); + return; + } + if (obj instanceof ConstantExpression) { + walkConstantExpression((ConstantExpression)obj, arg); + return; + } + if (obj instanceof ContVariableExpression) { + walkContVariableExpression((ContVariableExpression)obj, arg); + return; + } + if (obj instanceof DictExpression) { + walkDictExpression((DictExpression)obj, arg); + return; + } + if (obj instanceof DiscVariableExpression) { + walkDiscVariableExpression((DiscVariableExpression)obj, arg); + return; + } + if (obj instanceof EnumLiteralExpression) { + walkEnumLiteralExpression((EnumLiteralExpression)obj, arg); + return; + } + if (obj instanceof EventExpression) { + walkEventExpression((EventExpression)obj, arg); + return; + } + if (obj instanceof FieldExpression) { + walkFieldExpression((FieldExpression)obj, arg); + return; + } + if (obj instanceof FunctionCallExpression) { + walkFunctionCallExpression((FunctionCallExpression)obj, arg); + return; + } + if (obj instanceof IfExpression) { + walkIfExpression((IfExpression)obj, arg); + return; + } + if (obj instanceof InputVariableExpression) { + walkInputVariableExpression((InputVariableExpression)obj, arg); + return; + } + if (obj instanceof IntExpression) { + walkIntExpression((IntExpression)obj, arg); + return; + } + if (obj instanceof ListExpression) { + walkListExpression((ListExpression)obj, arg); + return; + } + if (obj instanceof LocationExpression) { + walkLocationExpression((LocationExpression)obj, arg); + return; + } + if (obj instanceof ProjectionExpression) { + walkProjectionExpression((ProjectionExpression)obj, arg); + return; + } + if (obj instanceof RealExpression) { + walkRealExpression((RealExpression)obj, arg); + return; + } + if (obj instanceof ReceivedExpression) { + walkReceivedExpression((ReceivedExpression)obj, arg); + return; + } + if (obj instanceof SelfExpression) { + walkSelfExpression((SelfExpression)obj, arg); + return; + } + if (obj instanceof SetExpression) { + walkSetExpression((SetExpression)obj, arg); + return; + } + if (obj instanceof SliceExpression) { + walkSliceExpression((SliceExpression)obj, arg); + return; + } + if (obj instanceof StringExpression) { + walkStringExpression((StringExpression)obj, arg); + return; + } + if (obj instanceof SwitchExpression) { + walkSwitchExpression((SwitchExpression)obj, arg); + return; + } + if (obj instanceof TauExpression) { + walkTauExpression((TauExpression)obj, arg); + return; + } + if (obj instanceof TimeExpression) { + walkTimeExpression((TimeExpression)obj, arg); + return; + } + if (obj instanceof TupleExpression) { + walkTupleExpression((TupleExpression)obj, arg); + return; + } + if (obj instanceof UnaryExpression) { + walkUnaryExpression((UnaryExpression)obj, arg); + return; + } + String msg = "No redirect; unexpected object type: " + obj; + throw new IllegalArgumentException(msg); + } + + /** + * Pre-crawling function for the {@link Expression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlExpression(Expression obj, T arg) { + precrawlPositionObject(obj, arg); + preprocessExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link Expression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlExpression(Expression obj, T arg) { + postprocessExpression(obj, arg); + postcrawlPositionObject(obj, arg); + } + + /** + * Pre-processing function for the {@link Expression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessExpression(Expression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link Expression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessExpression(Expression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link ExternalFunction} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkExternalFunction(ExternalFunction obj, T arg) { + precrawlExternalFunction(obj, arg); + List _parameters = obj.getParameters(); + for (FunctionParameter x: _parameters) { + walkFunctionParameter(x, arg); + } + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + List _returnTypes = obj.getReturnTypes(); + for (CifType x: _returnTypes) { + walkCifType(x, arg); + } + postcrawlExternalFunction(obj, arg); + } + + /** + * Pre-crawling function for the {@link ExternalFunction} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlExternalFunction(ExternalFunction obj, T arg) { + precrawlFunction(obj, arg); + preprocessExternalFunction(obj, arg); + } + + /** + * Post-crawling function for the {@link ExternalFunction} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlExternalFunction(ExternalFunction obj, T arg) { + postprocessExternalFunction(obj, arg); + postcrawlFunction(obj, arg); + } + + /** + * Pre-processing function for the {@link ExternalFunction} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessExternalFunction(ExternalFunction obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link ExternalFunction} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessExternalFunction(ExternalFunction obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link Field} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkField(Field obj, T arg) { + precrawlField(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlField(obj, arg); + } + + /** + * Pre-crawling function for the {@link Field} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlField(Field obj, T arg) { + precrawlPositionObject(obj, arg); + preprocessField(obj, arg); + } + + /** + * Post-crawling function for the {@link Field} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlField(Field obj, T arg) { + postprocessField(obj, arg); + postcrawlPositionObject(obj, arg); + } + + /** + * Pre-processing function for the {@link Field} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessField(Field obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link Field} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessField(Field obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link FieldExpression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkFieldExpression(FieldExpression obj, T arg) { + precrawlFieldExpression(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlFieldExpression(obj, arg); + } + + /** + * Pre-crawling function for the {@link FieldExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlFieldExpression(FieldExpression obj, T arg) { + precrawlExpression(obj, arg); + preprocessFieldExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link FieldExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlFieldExpression(FieldExpression obj, T arg) { + postprocessFieldExpression(obj, arg); + postcrawlExpression(obj, arg); + } + + /** + * Pre-processing function for the {@link FieldExpression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessFieldExpression(FieldExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link FieldExpression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessFieldExpression(FieldExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link FuncType} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkFuncType(FuncType obj, T arg) { + precrawlFuncType(obj, arg); + List _paramTypes = obj.getParamTypes(); + for (CifType x: _paramTypes) { + walkCifType(x, arg); + } + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _returnType = obj.getReturnType(); + walkCifType(_returnType, arg); + postcrawlFuncType(obj, arg); + } + + /** + * Pre-crawling function for the {@link FuncType} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlFuncType(FuncType obj, T arg) { + precrawlCifType(obj, arg); + preprocessFuncType(obj, arg); + } + + /** + * Post-crawling function for the {@link FuncType} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlFuncType(FuncType obj, T arg) { + postprocessFuncType(obj, arg); + postcrawlCifType(obj, arg); + } + + /** + * Pre-processing function for the {@link FuncType} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessFuncType(FuncType obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link FuncType} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessFuncType(FuncType obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link Function} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkFunction(Function obj, T arg) { + if (obj instanceof ExternalFunction) { + walkExternalFunction((ExternalFunction)obj, arg); + return; + } + if (obj instanceof InternalFunction) { + walkInternalFunction((InternalFunction)obj, arg); + return; + } + String msg = "No redirect; unexpected object type: " + obj; + throw new IllegalArgumentException(msg); + } + + /** + * Pre-crawling function for the {@link Function} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlFunction(Function obj, T arg) { + precrawlDeclaration(obj, arg); + preprocessFunction(obj, arg); + } + + /** + * Post-crawling function for the {@link Function} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlFunction(Function obj, T arg) { + postprocessFunction(obj, arg); + postcrawlDeclaration(obj, arg); + } + + /** + * Pre-processing function for the {@link Function} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessFunction(Function obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link Function} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessFunction(Function obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link FunctionCallExpression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkFunctionCallExpression(FunctionCallExpression obj, T arg) { + precrawlFunctionCallExpression(obj, arg); + Expression _function = obj.getFunction(); + walkExpression(_function, arg); + List _params = obj.getParams(); + for (Expression x: _params) { + walkExpression(x, arg); + } + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlFunctionCallExpression(obj, arg); + } + + /** + * Pre-crawling function for the {@link FunctionCallExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlFunctionCallExpression(FunctionCallExpression obj, T arg) { + precrawlExpression(obj, arg); + preprocessFunctionCallExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link FunctionCallExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlFunctionCallExpression(FunctionCallExpression obj, T arg) { + postprocessFunctionCallExpression(obj, arg); + postcrawlExpression(obj, arg); + } + + /** + * Pre-processing function for the {@link FunctionCallExpression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessFunctionCallExpression(FunctionCallExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link FunctionCallExpression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessFunctionCallExpression(FunctionCallExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link FunctionExpression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkFunctionExpression(FunctionExpression obj, T arg) { + precrawlFunctionExpression(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlFunctionExpression(obj, arg); + } + + /** + * Pre-crawling function for the {@link FunctionExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlFunctionExpression(FunctionExpression obj, T arg) { + precrawlBaseFunctionExpression(obj, arg); + preprocessFunctionExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link FunctionExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlFunctionExpression(FunctionExpression obj, T arg) { + postprocessFunctionExpression(obj, arg); + postcrawlBaseFunctionExpression(obj, arg); + } + + /** + * Pre-processing function for the {@link FunctionExpression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessFunctionExpression(FunctionExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link FunctionExpression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessFunctionExpression(FunctionExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link FunctionParameter} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkFunctionParameter(FunctionParameter obj, T arg) { + precrawlFunctionParameter(obj, arg); + DiscVariable _parameter = obj.getParameter(); + walkDiscVariable(_parameter, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + postcrawlFunctionParameter(obj, arg); + } + + /** + * Pre-crawling function for the {@link FunctionParameter} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlFunctionParameter(FunctionParameter obj, T arg) { + precrawlPositionObject(obj, arg); + preprocessFunctionParameter(obj, arg); + } + + /** + * Post-crawling function for the {@link FunctionParameter} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlFunctionParameter(FunctionParameter obj, T arg) { + postprocessFunctionParameter(obj, arg); + postcrawlPositionObject(obj, arg); + } + + /** + * Pre-processing function for the {@link FunctionParameter} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessFunctionParameter(FunctionParameter obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link FunctionParameter} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessFunctionParameter(FunctionParameter obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link FunctionStatement} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkFunctionStatement(FunctionStatement obj, T arg) { + if (obj instanceof AssignmentFuncStatement) { + walkAssignmentFuncStatement((AssignmentFuncStatement)obj, arg); + return; + } + if (obj instanceof BreakFuncStatement) { + walkBreakFuncStatement((BreakFuncStatement)obj, arg); + return; + } + if (obj instanceof ContinueFuncStatement) { + walkContinueFuncStatement((ContinueFuncStatement)obj, arg); + return; + } + if (obj instanceof IfFuncStatement) { + walkIfFuncStatement((IfFuncStatement)obj, arg); + return; + } + if (obj instanceof ReturnFuncStatement) { + walkReturnFuncStatement((ReturnFuncStatement)obj, arg); + return; + } + if (obj instanceof WhileFuncStatement) { + walkWhileFuncStatement((WhileFuncStatement)obj, arg); + return; + } + String msg = "No redirect; unexpected object type: " + obj; + throw new IllegalArgumentException(msg); + } + + /** + * Pre-crawling function for the {@link FunctionStatement} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlFunctionStatement(FunctionStatement obj, T arg) { + precrawlPositionObject(obj, arg); + preprocessFunctionStatement(obj, arg); + } + + /** + * Post-crawling function for the {@link FunctionStatement} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlFunctionStatement(FunctionStatement obj, T arg) { + postprocessFunctionStatement(obj, arg); + postcrawlPositionObject(obj, arg); + } + + /** + * Pre-processing function for the {@link FunctionStatement} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessFunctionStatement(FunctionStatement obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link FunctionStatement} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessFunctionStatement(FunctionStatement obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link Group} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkGroup(Group obj, T arg) { + if (obj instanceof Specification) { + walkSpecification((Specification)obj, arg); + return; + } + Assert.check(obj.getClass() == GroupImpl.class); + precrawlGroup(obj, arg); + List _components = obj.getComponents(); + for (Component x: _components) { + walkComponent(x, arg); + } + List _declarations = obj.getDeclarations(); + for (Declaration x: _declarations) { + walkDeclaration(x, arg); + } + List _definitions = obj.getDefinitions(); + for (ComponentDef x: _definitions) { + walkComponentDef(x, arg); + } + List _equations = obj.getEquations(); + for (Equation x: _equations) { + walkEquation(x, arg); + } + List _initials = obj.getInitials(); + for (Expression x: _initials) { + walkExpression(x, arg); + } + List _invariants = obj.getInvariants(); + for (Invariant x: _invariants) { + walkInvariant(x, arg); + } + List _ioDecls = obj.getIoDecls(); + for (IoDecl x: _ioDecls) { + walkIoDecl(x, arg); + } + List _markeds = obj.getMarkeds(); + for (Expression x: _markeds) { + walkExpression(x, arg); + } + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + postcrawlGroup(obj, arg); + } + + /** + * Pre-crawling function for the {@link Group} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlGroup(Group obj, T arg) { + precrawlComplexComponent(obj, arg); + preprocessGroup(obj, arg); + } + + /** + * Post-crawling function for the {@link Group} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlGroup(Group obj, T arg) { + postprocessGroup(obj, arg); + postcrawlComplexComponent(obj, arg); + } + + /** + * Pre-processing function for the {@link Group} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessGroup(Group obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link Group} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessGroup(Group obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link IfExpression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkIfExpression(IfExpression obj, T arg) { + precrawlIfExpression(obj, arg); + List _elifs = obj.getElifs(); + for (ElifExpression x: _elifs) { + walkElifExpression(x, arg); + } + Expression _else = obj.getElse(); + walkExpression(_else, arg); + List _guards = obj.getGuards(); + for (Expression x: _guards) { + walkExpression(x, arg); + } + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + Expression _then = obj.getThen(); + walkExpression(_then, arg); + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlIfExpression(obj, arg); + } + + /** + * Pre-crawling function for the {@link IfExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlIfExpression(IfExpression obj, T arg) { + precrawlExpression(obj, arg); + preprocessIfExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link IfExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlIfExpression(IfExpression obj, T arg) { + postprocessIfExpression(obj, arg); + postcrawlExpression(obj, arg); + } + + /** + * Pre-processing function for the {@link IfExpression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessIfExpression(IfExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link IfExpression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessIfExpression(IfExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link IfFuncStatement} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkIfFuncStatement(IfFuncStatement obj, T arg) { + precrawlIfFuncStatement(obj, arg); + List _elifs = obj.getElifs(); + for (ElifFuncStatement x: _elifs) { + walkElifFuncStatement(x, arg); + } + List _elses = obj.getElses(); + for (FunctionStatement x: _elses) { + walkFunctionStatement(x, arg); + } + List _guards = obj.getGuards(); + for (Expression x: _guards) { + walkExpression(x, arg); + } + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + List _thens = obj.getThens(); + for (FunctionStatement x: _thens) { + walkFunctionStatement(x, arg); + } + postcrawlIfFuncStatement(obj, arg); + } + + /** + * Pre-crawling function for the {@link IfFuncStatement} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlIfFuncStatement(IfFuncStatement obj, T arg) { + precrawlFunctionStatement(obj, arg); + preprocessIfFuncStatement(obj, arg); + } + + /** + * Post-crawling function for the {@link IfFuncStatement} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlIfFuncStatement(IfFuncStatement obj, T arg) { + postprocessIfFuncStatement(obj, arg); + postcrawlFunctionStatement(obj, arg); + } + + /** + * Pre-processing function for the {@link IfFuncStatement} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessIfFuncStatement(IfFuncStatement obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link IfFuncStatement} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessIfFuncStatement(IfFuncStatement obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link IfUpdate} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkIfUpdate(IfUpdate obj, T arg) { + precrawlIfUpdate(obj, arg); + List _elifs = obj.getElifs(); + for (ElifUpdate x: _elifs) { + walkElifUpdate(x, arg); + } + List _elses = obj.getElses(); + for (Update x: _elses) { + walkUpdate(x, arg); + } + List _guards = obj.getGuards(); + for (Expression x: _guards) { + walkExpression(x, arg); + } + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + List _thens = obj.getThens(); + for (Update x: _thens) { + walkUpdate(x, arg); + } + postcrawlIfUpdate(obj, arg); + } + + /** + * Pre-crawling function for the {@link IfUpdate} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlIfUpdate(IfUpdate obj, T arg) { + precrawlUpdate(obj, arg); + preprocessIfUpdate(obj, arg); + } + + /** + * Post-crawling function for the {@link IfUpdate} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlIfUpdate(IfUpdate obj, T arg) { + postprocessIfUpdate(obj, arg); + postcrawlUpdate(obj, arg); + } + + /** + * Pre-processing function for the {@link IfUpdate} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessIfUpdate(IfUpdate obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link IfUpdate} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessIfUpdate(IfUpdate obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link InputVariable} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkInputVariable(InputVariable obj, T arg) { + precrawlInputVariable(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlInputVariable(obj, arg); + } + + /** + * Pre-crawling function for the {@link InputVariable} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlInputVariable(InputVariable obj, T arg) { + precrawlDeclaration(obj, arg); + preprocessInputVariable(obj, arg); + } + + /** + * Post-crawling function for the {@link InputVariable} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlInputVariable(InputVariable obj, T arg) { + postprocessInputVariable(obj, arg); + postcrawlDeclaration(obj, arg); + } + + /** + * Pre-processing function for the {@link InputVariable} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessInputVariable(InputVariable obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link InputVariable} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessInputVariable(InputVariable obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link InputVariableExpression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkInputVariableExpression(InputVariableExpression obj, T arg) { + precrawlInputVariableExpression(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlInputVariableExpression(obj, arg); + } + + /** + * Pre-crawling function for the {@link InputVariableExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlInputVariableExpression(InputVariableExpression obj, T arg) { + precrawlExpression(obj, arg); + preprocessInputVariableExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link InputVariableExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlInputVariableExpression(InputVariableExpression obj, T arg) { + postprocessInputVariableExpression(obj, arg); + postcrawlExpression(obj, arg); + } + + /** + * Pre-processing function for the {@link InputVariableExpression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessInputVariableExpression(InputVariableExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link InputVariableExpression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessInputVariableExpression(InputVariableExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link IntExpression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkIntExpression(IntExpression obj, T arg) { + precrawlIntExpression(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlIntExpression(obj, arg); + } + + /** + * Pre-crawling function for the {@link IntExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlIntExpression(IntExpression obj, T arg) { + precrawlExpression(obj, arg); + preprocessIntExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link IntExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlIntExpression(IntExpression obj, T arg) { + postprocessIntExpression(obj, arg); + postcrawlExpression(obj, arg); + } + + /** + * Pre-processing function for the {@link IntExpression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessIntExpression(IntExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link IntExpression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessIntExpression(IntExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link IntType} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkIntType(IntType obj, T arg) { + precrawlIntType(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + postcrawlIntType(obj, arg); + } + + /** + * Pre-crawling function for the {@link IntType} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlIntType(IntType obj, T arg) { + precrawlCifType(obj, arg); + preprocessIntType(obj, arg); + } + + /** + * Post-crawling function for the {@link IntType} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlIntType(IntType obj, T arg) { + postprocessIntType(obj, arg); + postcrawlCifType(obj, arg); + } + + /** + * Pre-processing function for the {@link IntType} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessIntType(IntType obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link IntType} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessIntType(IntType obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link InternalFunction} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkInternalFunction(InternalFunction obj, T arg) { + precrawlInternalFunction(obj, arg); + List _parameters = obj.getParameters(); + for (FunctionParameter x: _parameters) { + walkFunctionParameter(x, arg); + } + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + List _returnTypes = obj.getReturnTypes(); + for (CifType x: _returnTypes) { + walkCifType(x, arg); + } + List _statements = obj.getStatements(); + for (FunctionStatement x: _statements) { + walkFunctionStatement(x, arg); + } + List _variables = obj.getVariables(); + for (DiscVariable x: _variables) { + walkDiscVariable(x, arg); + } + postcrawlInternalFunction(obj, arg); + } + + /** + * Pre-crawling function for the {@link InternalFunction} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlInternalFunction(InternalFunction obj, T arg) { + precrawlFunction(obj, arg); + preprocessInternalFunction(obj, arg); + } + + /** + * Post-crawling function for the {@link InternalFunction} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlInternalFunction(InternalFunction obj, T arg) { + postprocessInternalFunction(obj, arg); + postcrawlFunction(obj, arg); + } + + /** + * Pre-processing function for the {@link InternalFunction} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessInternalFunction(InternalFunction obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link InternalFunction} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessInternalFunction(InternalFunction obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link Invariant} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkInvariant(Invariant obj, T arg) { + precrawlInvariant(obj, arg); + Expression _event = obj.getEvent(); + if (_event != null) { + walkExpression(_event, arg); + } + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + Expression _predicate = obj.getPredicate(); + walkExpression(_predicate, arg); + postcrawlInvariant(obj, arg); + } + + /** + * Pre-crawling function for the {@link Invariant} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlInvariant(Invariant obj, T arg) { + precrawlPositionObject(obj, arg); + preprocessInvariant(obj, arg); + } + + /** + * Post-crawling function for the {@link Invariant} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlInvariant(Invariant obj, T arg) { + postprocessInvariant(obj, arg); + postcrawlPositionObject(obj, arg); + } + + /** + * Pre-processing function for the {@link Invariant} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessInvariant(Invariant obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link Invariant} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessInvariant(Invariant obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link IoDecl} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkIoDecl(IoDecl obj, T arg) { + if (obj instanceof Print) { + walkPrint((Print)obj, arg); + return; + } + if (obj instanceof PrintFile) { + walkPrintFile((PrintFile)obj, arg); + return; + } + if (obj instanceof SvgCopy) { + walkSvgCopy((SvgCopy)obj, arg); + return; + } + if (obj instanceof SvgFile) { + walkSvgFile((SvgFile)obj, arg); + return; + } + if (obj instanceof SvgIn) { + walkSvgIn((SvgIn)obj, arg); + return; + } + if (obj instanceof SvgMove) { + walkSvgMove((SvgMove)obj, arg); + return; + } + if (obj instanceof SvgOut) { + walkSvgOut((SvgOut)obj, arg); + return; + } + String msg = "No redirect; unexpected object type: " + obj; + throw new IllegalArgumentException(msg); + } + + /** + * Pre-crawling function for the {@link IoDecl} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlIoDecl(IoDecl obj, T arg) { + precrawlPositionObject(obj, arg); + preprocessIoDecl(obj, arg); + } + + /** + * Post-crawling function for the {@link IoDecl} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlIoDecl(IoDecl obj, T arg) { + postprocessIoDecl(obj, arg); + postcrawlPositionObject(obj, arg); + } + + /** + * Pre-processing function for the {@link IoDecl} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessIoDecl(IoDecl obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link IoDecl} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessIoDecl(IoDecl obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link ListExpression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkListExpression(ListExpression obj, T arg) { + precrawlListExpression(obj, arg); + List _elements = obj.getElements(); + for (Expression x: _elements) { + walkExpression(x, arg); + } + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlListExpression(obj, arg); + } + + /** + * Pre-crawling function for the {@link ListExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlListExpression(ListExpression obj, T arg) { + precrawlExpression(obj, arg); + preprocessListExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link ListExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlListExpression(ListExpression obj, T arg) { + postprocessListExpression(obj, arg); + postcrawlExpression(obj, arg); + } + + /** + * Pre-processing function for the {@link ListExpression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessListExpression(ListExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link ListExpression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessListExpression(ListExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link ListType} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkListType(ListType obj, T arg) { + precrawlListType(obj, arg); + CifType _elementType = obj.getElementType(); + walkCifType(_elementType, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + postcrawlListType(obj, arg); + } + + /** + * Pre-crawling function for the {@link ListType} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlListType(ListType obj, T arg) { + precrawlCifType(obj, arg); + preprocessListType(obj, arg); + } + + /** + * Post-crawling function for the {@link ListType} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlListType(ListType obj, T arg) { + postprocessListType(obj, arg); + postcrawlCifType(obj, arg); + } + + /** + * Pre-processing function for the {@link ListType} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessListType(ListType obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link ListType} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessListType(ListType obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link Location} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkLocation(Location obj, T arg) { + precrawlLocation(obj, arg); + List _edges = obj.getEdges(); + for (Edge x: _edges) { + walkEdge(x, arg); + } + List _equations = obj.getEquations(); + for (Equation x: _equations) { + walkEquation(x, arg); + } + List _initials = obj.getInitials(); + for (Expression x: _initials) { + walkExpression(x, arg); + } + List _invariants = obj.getInvariants(); + for (Invariant x: _invariants) { + walkInvariant(x, arg); + } + List _markeds = obj.getMarkeds(); + for (Expression x: _markeds) { + walkExpression(x, arg); + } + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + postcrawlLocation(obj, arg); + } + + /** + * Pre-crawling function for the {@link Location} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlLocation(Location obj, T arg) { + precrawlPositionObject(obj, arg); + preprocessLocation(obj, arg); + } + + /** + * Post-crawling function for the {@link Location} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlLocation(Location obj, T arg) { + postprocessLocation(obj, arg); + postcrawlPositionObject(obj, arg); + } + + /** + * Pre-processing function for the {@link Location} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessLocation(Location obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link Location} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessLocation(Location obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link LocationExpression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkLocationExpression(LocationExpression obj, T arg) { + precrawlLocationExpression(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlLocationExpression(obj, arg); + } + + /** + * Pre-crawling function for the {@link LocationExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlLocationExpression(LocationExpression obj, T arg) { + precrawlExpression(obj, arg); + preprocessLocationExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link LocationExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlLocationExpression(LocationExpression obj, T arg) { + postprocessLocationExpression(obj, arg); + postcrawlExpression(obj, arg); + } + + /** + * Pre-processing function for the {@link LocationExpression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessLocationExpression(LocationExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link LocationExpression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessLocationExpression(LocationExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link LocationParameter} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkLocationParameter(LocationParameter obj, T arg) { + precrawlLocationParameter(obj, arg); + Location _location = obj.getLocation(); + walkLocation(_location, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + postcrawlLocationParameter(obj, arg); + } + + /** + * Pre-crawling function for the {@link LocationParameter} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlLocationParameter(LocationParameter obj, T arg) { + precrawlParameter(obj, arg); + preprocessLocationParameter(obj, arg); + } + + /** + * Post-crawling function for the {@link LocationParameter} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlLocationParameter(LocationParameter obj, T arg) { + postprocessLocationParameter(obj, arg); + postcrawlParameter(obj, arg); + } + + /** + * Pre-processing function for the {@link LocationParameter} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessLocationParameter(LocationParameter obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link LocationParameter} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessLocationParameter(LocationParameter obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link Monitors} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkMonitors(Monitors obj, T arg) { + precrawlMonitors(obj, arg); + List _events = obj.getEvents(); + for (Expression x: _events) { + walkExpression(x, arg); + } + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + postcrawlMonitors(obj, arg); + } + + /** + * Pre-crawling function for the {@link Monitors} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlMonitors(Monitors obj, T arg) { + precrawlPositionObject(obj, arg); + preprocessMonitors(obj, arg); + } + + /** + * Post-crawling function for the {@link Monitors} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlMonitors(Monitors obj, T arg) { + postprocessMonitors(obj, arg); + postcrawlPositionObject(obj, arg); + } + + /** + * Pre-processing function for the {@link Monitors} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessMonitors(Monitors obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link Monitors} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessMonitors(Monitors obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link Parameter} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkParameter(Parameter obj, T arg) { + if (obj instanceof AlgParameter) { + walkAlgParameter((AlgParameter)obj, arg); + return; + } + if (obj instanceof ComponentParameter) { + walkComponentParameter((ComponentParameter)obj, arg); + return; + } + if (obj instanceof EventParameter) { + walkEventParameter((EventParameter)obj, arg); + return; + } + if (obj instanceof LocationParameter) { + walkLocationParameter((LocationParameter)obj, arg); + return; + } + String msg = "No redirect; unexpected object type: " + obj; + throw new IllegalArgumentException(msg); + } + + /** + * Pre-crawling function for the {@link Parameter} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlParameter(Parameter obj, T arg) { + precrawlPositionObject(obj, arg); + preprocessParameter(obj, arg); + } + + /** + * Post-crawling function for the {@link Parameter} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlParameter(Parameter obj, T arg) { + postprocessParameter(obj, arg); + postcrawlPositionObject(obj, arg); + } + + /** + * Pre-processing function for the {@link Parameter} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessParameter(Parameter obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link Parameter} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessParameter(Parameter obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link Position} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkPosition(Position obj, T arg) { + precrawlPosition(obj, arg); + postcrawlPosition(obj, arg); + } + + /** + * Pre-crawling function for the {@link Position} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlPosition(Position obj, T arg) { + preprocessPosition(obj, arg); + } + + /** + * Post-crawling function for the {@link Position} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlPosition(Position obj, T arg) { + postprocessPosition(obj, arg); + } + + /** + * Pre-processing function for the {@link Position} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessPosition(Position obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link Position} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessPosition(Position obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link PositionObject} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkPositionObject(PositionObject obj, T arg) { + if (obj instanceof Alphabet) { + walkAlphabet((Alphabet)obj, arg); + return; + } + if (obj instanceof CifType) { + walkCifType((CifType)obj, arg); + return; + } + if (obj instanceof Component) { + walkComponent((Component)obj, arg); + return; + } + if (obj instanceof ComponentDef) { + walkComponentDef((ComponentDef)obj, arg); + return; + } + if (obj instanceof Declaration) { + walkDeclaration((Declaration)obj, arg); + return; + } + if (obj instanceof DictPair) { + walkDictPair((DictPair)obj, arg); + return; + } + if (obj instanceof Edge) { + walkEdge((Edge)obj, arg); + return; + } + if (obj instanceof EdgeEvent) { + walkEdgeEvent((EdgeEvent)obj, arg); + return; + } + if (obj instanceof ElifExpression) { + walkElifExpression((ElifExpression)obj, arg); + return; + } + if (obj instanceof ElifFuncStatement) { + walkElifFuncStatement((ElifFuncStatement)obj, arg); + return; + } + if (obj instanceof ElifUpdate) { + walkElifUpdate((ElifUpdate)obj, arg); + return; + } + if (obj instanceof EnumLiteral) { + walkEnumLiteral((EnumLiteral)obj, arg); + return; + } + if (obj instanceof Equation) { + walkEquation((Equation)obj, arg); + return; + } + if (obj instanceof Expression) { + walkExpression((Expression)obj, arg); + return; + } + if (obj instanceof Field) { + walkField((Field)obj, arg); + return; + } + if (obj instanceof FunctionParameter) { + walkFunctionParameter((FunctionParameter)obj, arg); + return; + } + if (obj instanceof FunctionStatement) { + walkFunctionStatement((FunctionStatement)obj, arg); + return; + } + if (obj instanceof Invariant) { + walkInvariant((Invariant)obj, arg); + return; + } + if (obj instanceof IoDecl) { + walkIoDecl((IoDecl)obj, arg); + return; + } + if (obj instanceof Location) { + walkLocation((Location)obj, arg); + return; + } + if (obj instanceof Monitors) { + walkMonitors((Monitors)obj, arg); + return; + } + if (obj instanceof Parameter) { + walkParameter((Parameter)obj, arg); + return; + } + if (obj instanceof PrintFor) { + walkPrintFor((PrintFor)obj, arg); + return; + } + if (obj instanceof SvgInEvent) { + walkSvgInEvent((SvgInEvent)obj, arg); + return; + } + if (obj instanceof SvgInEventIfEntry) { + walkSvgInEventIfEntry((SvgInEventIfEntry)obj, arg); + return; + } + if (obj instanceof SwitchCase) { + walkSwitchCase((SwitchCase)obj, arg); + return; + } + if (obj instanceof Update) { + walkUpdate((Update)obj, arg); + return; + } + if (obj instanceof VariableValue) { + walkVariableValue((VariableValue)obj, arg); + return; + } + String msg = "No redirect; unexpected object type: " + obj; + throw new IllegalArgumentException(msg); + } + + /** + * Pre-crawling function for the {@link PositionObject} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlPositionObject(PositionObject obj, T arg) { + preprocessPositionObject(obj, arg); + } + + /** + * Post-crawling function for the {@link PositionObject} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlPositionObject(PositionObject obj, T arg) { + postprocessPositionObject(obj, arg); + } + + /** + * Pre-processing function for the {@link PositionObject} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessPositionObject(PositionObject obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link PositionObject} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessPositionObject(PositionObject obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link Print} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkPrint(Print obj, T arg) { + precrawlPrint(obj, arg); + PrintFile _file = obj.getFile(); + if (_file != null) { + walkPrintFile(_file, arg); + } + List _fors = obj.getFors(); + for (PrintFor x: _fors) { + walkPrintFor(x, arg); + } + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + Expression _txtPost = obj.getTxtPost(); + if (_txtPost != null) { + walkExpression(_txtPost, arg); + } + Expression _txtPre = obj.getTxtPre(); + if (_txtPre != null) { + walkExpression(_txtPre, arg); + } + Expression _whenPost = obj.getWhenPost(); + if (_whenPost != null) { + walkExpression(_whenPost, arg); + } + Expression _whenPre = obj.getWhenPre(); + if (_whenPre != null) { + walkExpression(_whenPre, arg); + } + postcrawlPrint(obj, arg); + } + + /** + * Pre-crawling function for the {@link Print} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlPrint(Print obj, T arg) { + precrawlIoDecl(obj, arg); + preprocessPrint(obj, arg); + } + + /** + * Post-crawling function for the {@link Print} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlPrint(Print obj, T arg) { + postprocessPrint(obj, arg); + postcrawlIoDecl(obj, arg); + } + + /** + * Pre-processing function for the {@link Print} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessPrint(Print obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link Print} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessPrint(Print obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link PrintFile} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkPrintFile(PrintFile obj, T arg) { + precrawlPrintFile(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + postcrawlPrintFile(obj, arg); + } + + /** + * Pre-crawling function for the {@link PrintFile} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlPrintFile(PrintFile obj, T arg) { + precrawlIoDecl(obj, arg); + preprocessPrintFile(obj, arg); + } + + /** + * Post-crawling function for the {@link PrintFile} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlPrintFile(PrintFile obj, T arg) { + postprocessPrintFile(obj, arg); + postcrawlIoDecl(obj, arg); + } + + /** + * Pre-processing function for the {@link PrintFile} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessPrintFile(PrintFile obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link PrintFile} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessPrintFile(PrintFile obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link PrintFor} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkPrintFor(PrintFor obj, T arg) { + precrawlPrintFor(obj, arg); + Expression _event = obj.getEvent(); + if (_event != null) { + walkExpression(_event, arg); + } + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + postcrawlPrintFor(obj, arg); + } + + /** + * Pre-crawling function for the {@link PrintFor} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlPrintFor(PrintFor obj, T arg) { + precrawlPositionObject(obj, arg); + preprocessPrintFor(obj, arg); + } + + /** + * Post-crawling function for the {@link PrintFor} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlPrintFor(PrintFor obj, T arg) { + postprocessPrintFor(obj, arg); + postcrawlPositionObject(obj, arg); + } + + /** + * Pre-processing function for the {@link PrintFor} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessPrintFor(PrintFor obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link PrintFor} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessPrintFor(PrintFor obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link ProjectionExpression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkProjectionExpression(ProjectionExpression obj, T arg) { + precrawlProjectionExpression(obj, arg); + Expression _child = obj.getChild(); + walkExpression(_child, arg); + Expression _index = obj.getIndex(); + walkExpression(_index, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlProjectionExpression(obj, arg); + } + + /** + * Pre-crawling function for the {@link ProjectionExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlProjectionExpression(ProjectionExpression obj, T arg) { + precrawlExpression(obj, arg); + preprocessProjectionExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link ProjectionExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlProjectionExpression(ProjectionExpression obj, T arg) { + postprocessProjectionExpression(obj, arg); + postcrawlExpression(obj, arg); + } + + /** + * Pre-processing function for the {@link ProjectionExpression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessProjectionExpression(ProjectionExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link ProjectionExpression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessProjectionExpression(ProjectionExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link RealExpression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkRealExpression(RealExpression obj, T arg) { + precrawlRealExpression(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlRealExpression(obj, arg); + } + + /** + * Pre-crawling function for the {@link RealExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlRealExpression(RealExpression obj, T arg) { + precrawlExpression(obj, arg); + preprocessRealExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link RealExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlRealExpression(RealExpression obj, T arg) { + postprocessRealExpression(obj, arg); + postcrawlExpression(obj, arg); + } + + /** + * Pre-processing function for the {@link RealExpression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessRealExpression(RealExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link RealExpression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessRealExpression(RealExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link RealType} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkRealType(RealType obj, T arg) { + precrawlRealType(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + postcrawlRealType(obj, arg); + } + + /** + * Pre-crawling function for the {@link RealType} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlRealType(RealType obj, T arg) { + precrawlCifType(obj, arg); + preprocessRealType(obj, arg); + } + + /** + * Post-crawling function for the {@link RealType} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlRealType(RealType obj, T arg) { + postprocessRealType(obj, arg); + postcrawlCifType(obj, arg); + } + + /** + * Pre-processing function for the {@link RealType} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessRealType(RealType obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link RealType} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessRealType(RealType obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link ReceivedExpression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkReceivedExpression(ReceivedExpression obj, T arg) { + precrawlReceivedExpression(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlReceivedExpression(obj, arg); + } + + /** + * Pre-crawling function for the {@link ReceivedExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlReceivedExpression(ReceivedExpression obj, T arg) { + precrawlExpression(obj, arg); + preprocessReceivedExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link ReceivedExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlReceivedExpression(ReceivedExpression obj, T arg) { + postprocessReceivedExpression(obj, arg); + postcrawlExpression(obj, arg); + } + + /** + * Pre-processing function for the {@link ReceivedExpression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessReceivedExpression(ReceivedExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link ReceivedExpression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessReceivedExpression(ReceivedExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link ReturnFuncStatement} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkReturnFuncStatement(ReturnFuncStatement obj, T arg) { + precrawlReturnFuncStatement(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + List _values = obj.getValues(); + for (Expression x: _values) { + walkExpression(x, arg); + } + postcrawlReturnFuncStatement(obj, arg); + } + + /** + * Pre-crawling function for the {@link ReturnFuncStatement} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlReturnFuncStatement(ReturnFuncStatement obj, T arg) { + precrawlFunctionStatement(obj, arg); + preprocessReturnFuncStatement(obj, arg); + } + + /** + * Post-crawling function for the {@link ReturnFuncStatement} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlReturnFuncStatement(ReturnFuncStatement obj, T arg) { + postprocessReturnFuncStatement(obj, arg); + postcrawlFunctionStatement(obj, arg); + } + + /** + * Pre-processing function for the {@link ReturnFuncStatement} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessReturnFuncStatement(ReturnFuncStatement obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link ReturnFuncStatement} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessReturnFuncStatement(ReturnFuncStatement obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link SelfExpression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkSelfExpression(SelfExpression obj, T arg) { + precrawlSelfExpression(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlSelfExpression(obj, arg); + } + + /** + * Pre-crawling function for the {@link SelfExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlSelfExpression(SelfExpression obj, T arg) { + precrawlExpression(obj, arg); + preprocessSelfExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link SelfExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlSelfExpression(SelfExpression obj, T arg) { + postprocessSelfExpression(obj, arg); + postcrawlExpression(obj, arg); + } + + /** + * Pre-processing function for the {@link SelfExpression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessSelfExpression(SelfExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link SelfExpression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessSelfExpression(SelfExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link SetExpression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkSetExpression(SetExpression obj, T arg) { + precrawlSetExpression(obj, arg); + List _elements = obj.getElements(); + for (Expression x: _elements) { + walkExpression(x, arg); + } + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlSetExpression(obj, arg); + } + + /** + * Pre-crawling function for the {@link SetExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlSetExpression(SetExpression obj, T arg) { + precrawlExpression(obj, arg); + preprocessSetExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link SetExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlSetExpression(SetExpression obj, T arg) { + postprocessSetExpression(obj, arg); + postcrawlExpression(obj, arg); + } + + /** + * Pre-processing function for the {@link SetExpression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessSetExpression(SetExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link SetExpression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessSetExpression(SetExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link SetType} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkSetType(SetType obj, T arg) { + precrawlSetType(obj, arg); + CifType _elementType = obj.getElementType(); + walkCifType(_elementType, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + postcrawlSetType(obj, arg); + } + + /** + * Pre-crawling function for the {@link SetType} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlSetType(SetType obj, T arg) { + precrawlCifType(obj, arg); + preprocessSetType(obj, arg); + } + + /** + * Post-crawling function for the {@link SetType} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlSetType(SetType obj, T arg) { + postprocessSetType(obj, arg); + postcrawlCifType(obj, arg); + } + + /** + * Pre-processing function for the {@link SetType} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessSetType(SetType obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link SetType} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessSetType(SetType obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link SliceExpression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkSliceExpression(SliceExpression obj, T arg) { + precrawlSliceExpression(obj, arg); + Expression _begin = obj.getBegin(); + if (_begin != null) { + walkExpression(_begin, arg); + } + Expression _child = obj.getChild(); + walkExpression(_child, arg); + Expression _end = obj.getEnd(); + if (_end != null) { + walkExpression(_end, arg); + } + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlSliceExpression(obj, arg); + } + + /** + * Pre-crawling function for the {@link SliceExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlSliceExpression(SliceExpression obj, T arg) { + precrawlExpression(obj, arg); + preprocessSliceExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link SliceExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlSliceExpression(SliceExpression obj, T arg) { + postprocessSliceExpression(obj, arg); + postcrawlExpression(obj, arg); + } + + /** + * Pre-processing function for the {@link SliceExpression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessSliceExpression(SliceExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link SliceExpression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessSliceExpression(SliceExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link Specification} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkSpecification(Specification obj, T arg) { + precrawlSpecification(obj, arg); + List _components = obj.getComponents(); + for (Component x: _components) { + walkComponent(x, arg); + } + List _declarations = obj.getDeclarations(); + for (Declaration x: _declarations) { + walkDeclaration(x, arg); + } + List _definitions = obj.getDefinitions(); + for (ComponentDef x: _definitions) { + walkComponentDef(x, arg); + } + List _equations = obj.getEquations(); + for (Equation x: _equations) { + walkEquation(x, arg); + } + List _initials = obj.getInitials(); + for (Expression x: _initials) { + walkExpression(x, arg); + } + List _invariants = obj.getInvariants(); + for (Invariant x: _invariants) { + walkInvariant(x, arg); + } + List _ioDecls = obj.getIoDecls(); + for (IoDecl x: _ioDecls) { + walkIoDecl(x, arg); + } + List _markeds = obj.getMarkeds(); + for (Expression x: _markeds) { + walkExpression(x, arg); + } + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + postcrawlSpecification(obj, arg); + } + + /** + * Pre-crawling function for the {@link Specification} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlSpecification(Specification obj, T arg) { + precrawlGroup(obj, arg); + preprocessSpecification(obj, arg); + } + + /** + * Post-crawling function for the {@link Specification} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlSpecification(Specification obj, T arg) { + postprocessSpecification(obj, arg); + postcrawlGroup(obj, arg); + } + + /** + * Pre-processing function for the {@link Specification} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessSpecification(Specification obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link Specification} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessSpecification(Specification obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link StdLibFunctionExpression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkStdLibFunctionExpression(StdLibFunctionExpression obj, T arg) { + precrawlStdLibFunctionExpression(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlStdLibFunctionExpression(obj, arg); + } + + /** + * Pre-crawling function for the {@link StdLibFunctionExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlStdLibFunctionExpression(StdLibFunctionExpression obj, T arg) { + precrawlBaseFunctionExpression(obj, arg); + preprocessStdLibFunctionExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link StdLibFunctionExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlStdLibFunctionExpression(StdLibFunctionExpression obj, T arg) { + postprocessStdLibFunctionExpression(obj, arg); + postcrawlBaseFunctionExpression(obj, arg); + } + + /** + * Pre-processing function for the {@link StdLibFunctionExpression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessStdLibFunctionExpression(StdLibFunctionExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link StdLibFunctionExpression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessStdLibFunctionExpression(StdLibFunctionExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link StringExpression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkStringExpression(StringExpression obj, T arg) { + precrawlStringExpression(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlStringExpression(obj, arg); + } + + /** + * Pre-crawling function for the {@link StringExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlStringExpression(StringExpression obj, T arg) { + precrawlExpression(obj, arg); + preprocessStringExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link StringExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlStringExpression(StringExpression obj, T arg) { + postprocessStringExpression(obj, arg); + postcrawlExpression(obj, arg); + } + + /** + * Pre-processing function for the {@link StringExpression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessStringExpression(StringExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link StringExpression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessStringExpression(StringExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link StringType} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkStringType(StringType obj, T arg) { + precrawlStringType(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + postcrawlStringType(obj, arg); + } + + /** + * Pre-crawling function for the {@link StringType} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlStringType(StringType obj, T arg) { + precrawlCifType(obj, arg); + preprocessStringType(obj, arg); + } + + /** + * Post-crawling function for the {@link StringType} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlStringType(StringType obj, T arg) { + postprocessStringType(obj, arg); + postcrawlCifType(obj, arg); + } + + /** + * Pre-processing function for the {@link StringType} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessStringType(StringType obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link StringType} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessStringType(StringType obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link SvgCopy} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkSvgCopy(SvgCopy obj, T arg) { + precrawlSvgCopy(obj, arg); + Expression _id = obj.getId(); + walkExpression(_id, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + Expression _post = obj.getPost(); + if (_post != null) { + walkExpression(_post, arg); + } + Expression _pre = obj.getPre(); + if (_pre != null) { + walkExpression(_pre, arg); + } + SvgFile _svgFile = obj.getSvgFile(); + if (_svgFile != null) { + walkSvgFile(_svgFile, arg); + } + postcrawlSvgCopy(obj, arg); + } + + /** + * Pre-crawling function for the {@link SvgCopy} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlSvgCopy(SvgCopy obj, T arg) { + precrawlIoDecl(obj, arg); + preprocessSvgCopy(obj, arg); + } + + /** + * Post-crawling function for the {@link SvgCopy} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlSvgCopy(SvgCopy obj, T arg) { + postprocessSvgCopy(obj, arg); + postcrawlIoDecl(obj, arg); + } + + /** + * Pre-processing function for the {@link SvgCopy} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessSvgCopy(SvgCopy obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link SvgCopy} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessSvgCopy(SvgCopy obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link SvgFile} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkSvgFile(SvgFile obj, T arg) { + precrawlSvgFile(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + postcrawlSvgFile(obj, arg); + } + + /** + * Pre-crawling function for the {@link SvgFile} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlSvgFile(SvgFile obj, T arg) { + precrawlIoDecl(obj, arg); + preprocessSvgFile(obj, arg); + } + + /** + * Post-crawling function for the {@link SvgFile} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlSvgFile(SvgFile obj, T arg) { + postprocessSvgFile(obj, arg); + postcrawlIoDecl(obj, arg); + } + + /** + * Pre-processing function for the {@link SvgFile} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessSvgFile(SvgFile obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link SvgFile} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessSvgFile(SvgFile obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link SvgIn} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkSvgIn(SvgIn obj, T arg) { + precrawlSvgIn(obj, arg); + SvgInEvent _event = obj.getEvent(); + walkSvgInEvent(_event, arg); + Expression _id = obj.getId(); + walkExpression(_id, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + SvgFile _svgFile = obj.getSvgFile(); + if (_svgFile != null) { + walkSvgFile(_svgFile, arg); + } + postcrawlSvgIn(obj, arg); + } + + /** + * Pre-crawling function for the {@link SvgIn} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlSvgIn(SvgIn obj, T arg) { + precrawlIoDecl(obj, arg); + preprocessSvgIn(obj, arg); + } + + /** + * Post-crawling function for the {@link SvgIn} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlSvgIn(SvgIn obj, T arg) { + postprocessSvgIn(obj, arg); + postcrawlIoDecl(obj, arg); + } + + /** + * Pre-processing function for the {@link SvgIn} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessSvgIn(SvgIn obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link SvgIn} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessSvgIn(SvgIn obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link SvgInEvent} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkSvgInEvent(SvgInEvent obj, T arg) { + if (obj instanceof SvgInEventIf) { + walkSvgInEventIf((SvgInEventIf)obj, arg); + return; + } + if (obj instanceof SvgInEventSingle) { + walkSvgInEventSingle((SvgInEventSingle)obj, arg); + return; + } + String msg = "No redirect; unexpected object type: " + obj; + throw new IllegalArgumentException(msg); + } + + /** + * Pre-crawling function for the {@link SvgInEvent} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlSvgInEvent(SvgInEvent obj, T arg) { + precrawlPositionObject(obj, arg); + preprocessSvgInEvent(obj, arg); + } + + /** + * Post-crawling function for the {@link SvgInEvent} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlSvgInEvent(SvgInEvent obj, T arg) { + postprocessSvgInEvent(obj, arg); + postcrawlPositionObject(obj, arg); + } + + /** + * Pre-processing function for the {@link SvgInEvent} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessSvgInEvent(SvgInEvent obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link SvgInEvent} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessSvgInEvent(SvgInEvent obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link SvgInEventIf} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkSvgInEventIf(SvgInEventIf obj, T arg) { + precrawlSvgInEventIf(obj, arg); + List _entries = obj.getEntries(); + for (SvgInEventIfEntry x: _entries) { + walkSvgInEventIfEntry(x, arg); + } + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + postcrawlSvgInEventIf(obj, arg); + } + + /** + * Pre-crawling function for the {@link SvgInEventIf} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlSvgInEventIf(SvgInEventIf obj, T arg) { + precrawlSvgInEvent(obj, arg); + preprocessSvgInEventIf(obj, arg); + } + + /** + * Post-crawling function for the {@link SvgInEventIf} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlSvgInEventIf(SvgInEventIf obj, T arg) { + postprocessSvgInEventIf(obj, arg); + postcrawlSvgInEvent(obj, arg); + } + + /** + * Pre-processing function for the {@link SvgInEventIf} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessSvgInEventIf(SvgInEventIf obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link SvgInEventIf} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessSvgInEventIf(SvgInEventIf obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link SvgInEventIfEntry} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkSvgInEventIfEntry(SvgInEventIfEntry obj, T arg) { + precrawlSvgInEventIfEntry(obj, arg); + Expression _event = obj.getEvent(); + walkExpression(_event, arg); + Expression _guard = obj.getGuard(); + if (_guard != null) { + walkExpression(_guard, arg); + } + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + postcrawlSvgInEventIfEntry(obj, arg); + } + + /** + * Pre-crawling function for the {@link SvgInEventIfEntry} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlSvgInEventIfEntry(SvgInEventIfEntry obj, T arg) { + precrawlPositionObject(obj, arg); + preprocessSvgInEventIfEntry(obj, arg); + } + + /** + * Post-crawling function for the {@link SvgInEventIfEntry} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlSvgInEventIfEntry(SvgInEventIfEntry obj, T arg) { + postprocessSvgInEventIfEntry(obj, arg); + postcrawlPositionObject(obj, arg); + } + + /** + * Pre-processing function for the {@link SvgInEventIfEntry} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessSvgInEventIfEntry(SvgInEventIfEntry obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link SvgInEventIfEntry} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessSvgInEventIfEntry(SvgInEventIfEntry obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link SvgInEventSingle} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkSvgInEventSingle(SvgInEventSingle obj, T arg) { + precrawlSvgInEventSingle(obj, arg); + Expression _event = obj.getEvent(); + walkExpression(_event, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + postcrawlSvgInEventSingle(obj, arg); + } + + /** + * Pre-crawling function for the {@link SvgInEventSingle} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlSvgInEventSingle(SvgInEventSingle obj, T arg) { + precrawlSvgInEvent(obj, arg); + preprocessSvgInEventSingle(obj, arg); + } + + /** + * Post-crawling function for the {@link SvgInEventSingle} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlSvgInEventSingle(SvgInEventSingle obj, T arg) { + postprocessSvgInEventSingle(obj, arg); + postcrawlSvgInEvent(obj, arg); + } + + /** + * Pre-processing function for the {@link SvgInEventSingle} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessSvgInEventSingle(SvgInEventSingle obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link SvgInEventSingle} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessSvgInEventSingle(SvgInEventSingle obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link SvgMove} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkSvgMove(SvgMove obj, T arg) { + precrawlSvgMove(obj, arg); + Expression _id = obj.getId(); + walkExpression(_id, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + SvgFile _svgFile = obj.getSvgFile(); + if (_svgFile != null) { + walkSvgFile(_svgFile, arg); + } + Expression _x = obj.getX(); + walkExpression(_x, arg); + Expression _y = obj.getY(); + walkExpression(_y, arg); + postcrawlSvgMove(obj, arg); + } + + /** + * Pre-crawling function for the {@link SvgMove} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlSvgMove(SvgMove obj, T arg) { + precrawlIoDecl(obj, arg); + preprocessSvgMove(obj, arg); + } + + /** + * Post-crawling function for the {@link SvgMove} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlSvgMove(SvgMove obj, T arg) { + postprocessSvgMove(obj, arg); + postcrawlIoDecl(obj, arg); + } + + /** + * Pre-processing function for the {@link SvgMove} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessSvgMove(SvgMove obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link SvgMove} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessSvgMove(SvgMove obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link SvgOut} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkSvgOut(SvgOut obj, T arg) { + precrawlSvgOut(obj, arg); + Position _attrTextPos = obj.getAttrTextPos(); + walkPosition(_attrTextPos, arg); + Expression _id = obj.getId(); + walkExpression(_id, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + SvgFile _svgFile = obj.getSvgFile(); + if (_svgFile != null) { + walkSvgFile(_svgFile, arg); + } + Expression _value = obj.getValue(); + walkExpression(_value, arg); + postcrawlSvgOut(obj, arg); + } + + /** + * Pre-crawling function for the {@link SvgOut} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlSvgOut(SvgOut obj, T arg) { + precrawlIoDecl(obj, arg); + preprocessSvgOut(obj, arg); + } + + /** + * Post-crawling function for the {@link SvgOut} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlSvgOut(SvgOut obj, T arg) { + postprocessSvgOut(obj, arg); + postcrawlIoDecl(obj, arg); + } + + /** + * Pre-processing function for the {@link SvgOut} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessSvgOut(SvgOut obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link SvgOut} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessSvgOut(SvgOut obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link SwitchCase} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkSwitchCase(SwitchCase obj, T arg) { + precrawlSwitchCase(obj, arg); + Expression _key = obj.getKey(); + if (_key != null) { + walkExpression(_key, arg); + } + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + Expression _value = obj.getValue(); + walkExpression(_value, arg); + postcrawlSwitchCase(obj, arg); + } + + /** + * Pre-crawling function for the {@link SwitchCase} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlSwitchCase(SwitchCase obj, T arg) { + precrawlPositionObject(obj, arg); + preprocessSwitchCase(obj, arg); + } + + /** + * Post-crawling function for the {@link SwitchCase} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlSwitchCase(SwitchCase obj, T arg) { + postprocessSwitchCase(obj, arg); + postcrawlPositionObject(obj, arg); + } + + /** + * Pre-processing function for the {@link SwitchCase} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessSwitchCase(SwitchCase obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link SwitchCase} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessSwitchCase(SwitchCase obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link SwitchExpression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkSwitchExpression(SwitchExpression obj, T arg) { + precrawlSwitchExpression(obj, arg); + List _cases = obj.getCases(); + for (SwitchCase x: _cases) { + walkSwitchCase(x, arg); + } + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + Expression _value = obj.getValue(); + walkExpression(_value, arg); + postcrawlSwitchExpression(obj, arg); + } + + /** + * Pre-crawling function for the {@link SwitchExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlSwitchExpression(SwitchExpression obj, T arg) { + precrawlExpression(obj, arg); + preprocessSwitchExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link SwitchExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlSwitchExpression(SwitchExpression obj, T arg) { + postprocessSwitchExpression(obj, arg); + postcrawlExpression(obj, arg); + } + + /** + * Pre-processing function for the {@link SwitchExpression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessSwitchExpression(SwitchExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link SwitchExpression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessSwitchExpression(SwitchExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link TauExpression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkTauExpression(TauExpression obj, T arg) { + precrawlTauExpression(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlTauExpression(obj, arg); + } + + /** + * Pre-crawling function for the {@link TauExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlTauExpression(TauExpression obj, T arg) { + precrawlExpression(obj, arg); + preprocessTauExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link TauExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlTauExpression(TauExpression obj, T arg) { + postprocessTauExpression(obj, arg); + postcrawlExpression(obj, arg); + } + + /** + * Pre-processing function for the {@link TauExpression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessTauExpression(TauExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link TauExpression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessTauExpression(TauExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link TimeExpression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkTimeExpression(TimeExpression obj, T arg) { + precrawlTimeExpression(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlTimeExpression(obj, arg); + } + + /** + * Pre-crawling function for the {@link TimeExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlTimeExpression(TimeExpression obj, T arg) { + precrawlExpression(obj, arg); + preprocessTimeExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link TimeExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlTimeExpression(TimeExpression obj, T arg) { + postprocessTimeExpression(obj, arg); + postcrawlExpression(obj, arg); + } + + /** + * Pre-processing function for the {@link TimeExpression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessTimeExpression(TimeExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link TimeExpression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessTimeExpression(TimeExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link TupleExpression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkTupleExpression(TupleExpression obj, T arg) { + precrawlTupleExpression(obj, arg); + List _fields = obj.getFields(); + for (Expression x: _fields) { + walkExpression(x, arg); + } + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlTupleExpression(obj, arg); + } + + /** + * Pre-crawling function for the {@link TupleExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlTupleExpression(TupleExpression obj, T arg) { + precrawlExpression(obj, arg); + preprocessTupleExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link TupleExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlTupleExpression(TupleExpression obj, T arg) { + postprocessTupleExpression(obj, arg); + postcrawlExpression(obj, arg); + } + + /** + * Pre-processing function for the {@link TupleExpression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessTupleExpression(TupleExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link TupleExpression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessTupleExpression(TupleExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link TupleType} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkTupleType(TupleType obj, T arg) { + precrawlTupleType(obj, arg); + List _fields = obj.getFields(); + for (Field x: _fields) { + walkField(x, arg); + } + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + postcrawlTupleType(obj, arg); + } + + /** + * Pre-crawling function for the {@link TupleType} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlTupleType(TupleType obj, T arg) { + precrawlCifType(obj, arg); + preprocessTupleType(obj, arg); + } + + /** + * Post-crawling function for the {@link TupleType} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlTupleType(TupleType obj, T arg) { + postprocessTupleType(obj, arg); + postcrawlCifType(obj, arg); + } + + /** + * Pre-processing function for the {@link TupleType} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessTupleType(TupleType obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link TupleType} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessTupleType(TupleType obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link TypeDecl} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkTypeDecl(TypeDecl obj, T arg) { + precrawlTypeDecl(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlTypeDecl(obj, arg); + } + + /** + * Pre-crawling function for the {@link TypeDecl} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlTypeDecl(TypeDecl obj, T arg) { + precrawlDeclaration(obj, arg); + preprocessTypeDecl(obj, arg); + } + + /** + * Post-crawling function for the {@link TypeDecl} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlTypeDecl(TypeDecl obj, T arg) { + postprocessTypeDecl(obj, arg); + postcrawlDeclaration(obj, arg); + } + + /** + * Pre-processing function for the {@link TypeDecl} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessTypeDecl(TypeDecl obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link TypeDecl} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessTypeDecl(TypeDecl obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link TypeRef} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkTypeRef(TypeRef obj, T arg) { + precrawlTypeRef(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + postcrawlTypeRef(obj, arg); + } + + /** + * Pre-crawling function for the {@link TypeRef} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlTypeRef(TypeRef obj, T arg) { + precrawlCifType(obj, arg); + preprocessTypeRef(obj, arg); + } + + /** + * Post-crawling function for the {@link TypeRef} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlTypeRef(TypeRef obj, T arg) { + postprocessTypeRef(obj, arg); + postcrawlCifType(obj, arg); + } + + /** + * Pre-processing function for the {@link TypeRef} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessTypeRef(TypeRef obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link TypeRef} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessTypeRef(TypeRef obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link UnaryExpression} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkUnaryExpression(UnaryExpression obj, T arg) { + precrawlUnaryExpression(obj, arg); + Expression _child = obj.getChild(); + walkExpression(_child, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + CifType _type = obj.getType(); + walkCifType(_type, arg); + postcrawlUnaryExpression(obj, arg); + } + + /** + * Pre-crawling function for the {@link UnaryExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlUnaryExpression(UnaryExpression obj, T arg) { + precrawlExpression(obj, arg); + preprocessUnaryExpression(obj, arg); + } + + /** + * Post-crawling function for the {@link UnaryExpression} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlUnaryExpression(UnaryExpression obj, T arg) { + postprocessUnaryExpression(obj, arg); + postcrawlExpression(obj, arg); + } + + /** + * Pre-processing function for the {@link UnaryExpression} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessUnaryExpression(UnaryExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link UnaryExpression} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessUnaryExpression(UnaryExpression obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link Update} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkUpdate(Update obj, T arg) { + if (obj instanceof Assignment) { + walkAssignment((Assignment)obj, arg); + return; + } + if (obj instanceof IfUpdate) { + walkIfUpdate((IfUpdate)obj, arg); + return; + } + String msg = "No redirect; unexpected object type: " + obj; + throw new IllegalArgumentException(msg); + } + + /** + * Pre-crawling function for the {@link Update} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlUpdate(Update obj, T arg) { + precrawlPositionObject(obj, arg); + preprocessUpdate(obj, arg); + } + + /** + * Post-crawling function for the {@link Update} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlUpdate(Update obj, T arg) { + postprocessUpdate(obj, arg); + postcrawlPositionObject(obj, arg); + } + + /** + * Pre-processing function for the {@link Update} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessUpdate(Update obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link Update} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessUpdate(Update obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link VariableValue} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkVariableValue(VariableValue obj, T arg) { + precrawlVariableValue(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + List _values = obj.getValues(); + for (Expression x: _values) { + walkExpression(x, arg); + } + postcrawlVariableValue(obj, arg); + } + + /** + * Pre-crawling function for the {@link VariableValue} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlVariableValue(VariableValue obj, T arg) { + precrawlPositionObject(obj, arg); + preprocessVariableValue(obj, arg); + } + + /** + * Post-crawling function for the {@link VariableValue} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlVariableValue(VariableValue obj, T arg) { + postprocessVariableValue(obj, arg); + postcrawlPositionObject(obj, arg); + } + + /** + * Pre-processing function for the {@link VariableValue} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessVariableValue(VariableValue obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link VariableValue} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessVariableValue(VariableValue obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link VoidType} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkVoidType(VoidType obj, T arg) { + precrawlVoidType(obj, arg); + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + postcrawlVoidType(obj, arg); + } + + /** + * Pre-crawling function for the {@link VoidType} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlVoidType(VoidType obj, T arg) { + precrawlCifType(obj, arg); + preprocessVoidType(obj, arg); + } + + /** + * Post-crawling function for the {@link VoidType} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlVoidType(VoidType obj, T arg) { + postprocessVoidType(obj, arg); + postcrawlCifType(obj, arg); + } + + /** + * Pre-processing function for the {@link VoidType} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessVoidType(VoidType obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link VoidType} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessVoidType(VoidType obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Walking function for the {@link WhileFuncStatement} class. + * + * @param obj The object to walk over. + * @param arg The extra argument provided to the walking method. + */ + protected void walkWhileFuncStatement(WhileFuncStatement obj, T arg) { + precrawlWhileFuncStatement(obj, arg); + List _guards = obj.getGuards(); + for (Expression x: _guards) { + walkExpression(x, arg); + } + Position _position = obj.getPosition(); + if (_position != null) { + walkPosition(_position, arg); + } + List _statements = obj.getStatements(); + for (FunctionStatement x: _statements) { + walkFunctionStatement(x, arg); + } + postcrawlWhileFuncStatement(obj, arg); + } + + /** + * Pre-crawling function for the {@link WhileFuncStatement} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the pre-crawling method. + */ + protected void precrawlWhileFuncStatement(WhileFuncStatement obj, T arg) { + precrawlFunctionStatement(obj, arg); + preprocessWhileFuncStatement(obj, arg); + } + + /** + * Post-crawling function for the {@link WhileFuncStatement} class. + * + * @param obj The object to crawl over. + * @param arg The extra argument provided to the post-crawling method. + */ + protected void postcrawlWhileFuncStatement(WhileFuncStatement obj, T arg) { + postprocessWhileFuncStatement(obj, arg); + postcrawlFunctionStatement(obj, arg); + } + + /** + * Pre-processing function for the {@link WhileFuncStatement} class. + * + * @param obj The object to pre-process. + * @param arg The extra argument provided to the pre-processing method. + */ + protected void preprocessWhileFuncStatement(WhileFuncStatement obj, T arg) { + // Derived classes may override this method to do actual processing. + } + + /** + * Post-processing function for the {@link WhileFuncStatement} class. + * + * @param obj The object to post-process. + * @param arg The extra argument provided to the post-processing method. + */ + protected void postprocessWhileFuncStatement(WhileFuncStatement obj, T arg) { + // Derived classes may override this method to do actual processing. + } +} diff --git a/cif/org.eclipse.escet.cif.metamodel.java/src-gen/org/eclipse/escet/cif/metamodel/java/CompositeCifWithArgWalker.java b/cif/org.eclipse.escet.cif.metamodel.java/src-gen/org/eclipse/escet/cif/metamodel/java/CompositeCifWithArgWalker.java new file mode 100644 index 000000000..b8c8ffbba --- /dev/null +++ b/cif/org.eclipse.escet.cif.metamodel.java/src-gen/org/eclipse/escet/cif/metamodel/java/CompositeCifWithArgWalker.java @@ -0,0 +1,1906 @@ +////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2010, 2022 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available +// under the terms of the MIT License which is available at +// https://opensource.org/licenses/MIT +// +// SPDX-License-Identifier: MIT +////////////////////////////////////////////////////////////////////////////// + +// Generated using the "org.eclipse.escet.common.emf.ecore.codegen" project. + +// Disable Eclipse Java formatter for generated code file: +// @formatter:off + +package org.eclipse.escet.cif.metamodel.java; + +import org.eclipse.escet.cif.metamodel.cif.AlgParameter; +import org.eclipse.escet.cif.metamodel.cif.ComplexComponent; +import org.eclipse.escet.cif.metamodel.cif.Component; +import org.eclipse.escet.cif.metamodel.cif.ComponentDef; +import org.eclipse.escet.cif.metamodel.cif.ComponentInst; +import org.eclipse.escet.cif.metamodel.cif.ComponentParameter; +import org.eclipse.escet.cif.metamodel.cif.Equation; +import org.eclipse.escet.cif.metamodel.cif.EventParameter; +import org.eclipse.escet.cif.metamodel.cif.Group; +import org.eclipse.escet.cif.metamodel.cif.Invariant; +import org.eclipse.escet.cif.metamodel.cif.IoDecl; +import org.eclipse.escet.cif.metamodel.cif.LocationParameter; +import org.eclipse.escet.cif.metamodel.cif.Parameter; +import org.eclipse.escet.cif.metamodel.cif.Specification; +import org.eclipse.escet.cif.metamodel.cif.automata.Alphabet; +import org.eclipse.escet.cif.metamodel.cif.automata.Assignment; +import org.eclipse.escet.cif.metamodel.cif.automata.Automaton; +import org.eclipse.escet.cif.metamodel.cif.automata.Edge; +import org.eclipse.escet.cif.metamodel.cif.automata.EdgeEvent; +import org.eclipse.escet.cif.metamodel.cif.automata.EdgeReceive; +import org.eclipse.escet.cif.metamodel.cif.automata.EdgeSend; +import org.eclipse.escet.cif.metamodel.cif.automata.ElifUpdate; +import org.eclipse.escet.cif.metamodel.cif.automata.IfUpdate; +import org.eclipse.escet.cif.metamodel.cif.automata.Location; +import org.eclipse.escet.cif.metamodel.cif.automata.Monitors; +import org.eclipse.escet.cif.metamodel.cif.automata.Update; +import org.eclipse.escet.cif.metamodel.cif.cifsvg.SvgCopy; +import org.eclipse.escet.cif.metamodel.cif.cifsvg.SvgFile; +import org.eclipse.escet.cif.metamodel.cif.cifsvg.SvgIn; +import org.eclipse.escet.cif.metamodel.cif.cifsvg.SvgInEvent; +import org.eclipse.escet.cif.metamodel.cif.cifsvg.SvgInEventIf; +import org.eclipse.escet.cif.metamodel.cif.cifsvg.SvgInEventIfEntry; +import org.eclipse.escet.cif.metamodel.cif.cifsvg.SvgInEventSingle; +import org.eclipse.escet.cif.metamodel.cif.cifsvg.SvgMove; +import org.eclipse.escet.cif.metamodel.cif.cifsvg.SvgOut; +import org.eclipse.escet.cif.metamodel.cif.declarations.AlgVariable; +import org.eclipse.escet.cif.metamodel.cif.declarations.Constant; +import org.eclipse.escet.cif.metamodel.cif.declarations.ContVariable; +import org.eclipse.escet.cif.metamodel.cif.declarations.Declaration; +import org.eclipse.escet.cif.metamodel.cif.declarations.DiscVariable; +import org.eclipse.escet.cif.metamodel.cif.declarations.EnumDecl; +import org.eclipse.escet.cif.metamodel.cif.declarations.EnumLiteral; +import org.eclipse.escet.cif.metamodel.cif.declarations.Event; +import org.eclipse.escet.cif.metamodel.cif.declarations.InputVariable; +import org.eclipse.escet.cif.metamodel.cif.declarations.TypeDecl; +import org.eclipse.escet.cif.metamodel.cif.declarations.VariableValue; +import org.eclipse.escet.cif.metamodel.cif.expressions.AlgVariableExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.BaseFunctionExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.BinaryExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.BoolExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.CastExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.CompInstWrapExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.CompParamExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.CompParamWrapExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.ComponentExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.ConstantExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.ContVariableExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.DictExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.DictPair; +import org.eclipse.escet.cif.metamodel.cif.expressions.DiscVariableExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.ElifExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.EnumLiteralExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.EventExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.Expression; +import org.eclipse.escet.cif.metamodel.cif.expressions.FieldExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.FunctionCallExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.FunctionExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.IfExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.InputVariableExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.IntExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.ListExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.LocationExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.ProjectionExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.RealExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.ReceivedExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.SelfExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.SetExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.SliceExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.StdLibFunctionExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.StringExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.SwitchCase; +import org.eclipse.escet.cif.metamodel.cif.expressions.SwitchExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.TauExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.TimeExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.TupleExpression; +import org.eclipse.escet.cif.metamodel.cif.expressions.UnaryExpression; +import org.eclipse.escet.cif.metamodel.cif.functions.AssignmentFuncStatement; +import org.eclipse.escet.cif.metamodel.cif.functions.BreakFuncStatement; +import org.eclipse.escet.cif.metamodel.cif.functions.ContinueFuncStatement; +import org.eclipse.escet.cif.metamodel.cif.functions.ElifFuncStatement; +import org.eclipse.escet.cif.metamodel.cif.functions.ExternalFunction; +import org.eclipse.escet.cif.metamodel.cif.functions.Function; +import org.eclipse.escet.cif.metamodel.cif.functions.FunctionParameter; +import org.eclipse.escet.cif.metamodel.cif.functions.FunctionStatement; +import org.eclipse.escet.cif.metamodel.cif.functions.IfFuncStatement; +import org.eclipse.escet.cif.metamodel.cif.functions.InternalFunction; +import org.eclipse.escet.cif.metamodel.cif.functions.ReturnFuncStatement; +import org.eclipse.escet.cif.metamodel.cif.functions.WhileFuncStatement; +import org.eclipse.escet.cif.metamodel.cif.print.Print; +import org.eclipse.escet.cif.metamodel.cif.print.PrintFile; +import org.eclipse.escet.cif.metamodel.cif.print.PrintFor; +import org.eclipse.escet.cif.metamodel.cif.types.BoolType; +import org.eclipse.escet.cif.metamodel.cif.types.CifType; +import org.eclipse.escet.cif.metamodel.cif.types.CompInstWrapType; +import org.eclipse.escet.cif.metamodel.cif.types.CompParamWrapType; +import org.eclipse.escet.cif.metamodel.cif.types.ComponentDefType; +import org.eclipse.escet.cif.metamodel.cif.types.ComponentType; +import org.eclipse.escet.cif.metamodel.cif.types.DictType; +import org.eclipse.escet.cif.metamodel.cif.types.DistType; +import org.eclipse.escet.cif.metamodel.cif.types.EnumType; +import org.eclipse.escet.cif.metamodel.cif.types.Field; +import org.eclipse.escet.cif.metamodel.cif.types.FuncType; +import org.eclipse.escet.cif.metamodel.cif.types.IntType; +import org.eclipse.escet.cif.metamodel.cif.types.ListType; +import org.eclipse.escet.cif.metamodel.cif.types.RealType; +import org.eclipse.escet.cif.metamodel.cif.types.SetType; +import org.eclipse.escet.cif.metamodel.cif.types.StringType; +import org.eclipse.escet.cif.metamodel.cif.types.TupleType; +import org.eclipse.escet.cif.metamodel.cif.types.TypeRef; +import org.eclipse.escet.cif.metamodel.cif.types.VoidType; +import org.eclipse.escet.common.position.metamodel.position.Position; +import org.eclipse.escet.common.position.metamodel.position.PositionObject; + +/** + * A composite walker for "cif" models. + * + *

    The composite walker works as follows: + *

      + *
    • Performs a top-down depth-first walk over the object tree, using the + * containment hierarchy.
    • + *
    • No particular order should be assumed for walking over the child + * features.
    • + *
    • For each object encountered, pre-processing is performed before walking + * over the children, and post-processing is performed after walking over + * the children.
    • + *
    • Pre-processing for objects is done by crawling up the inheritance + * hierarchy of the object, performing pre-processing for each of the + * types encountered in the type hierarchy. The pre-processing methods are + * invoked from most general to most specific class (super classes before + * base classes).
    • + *
    • Post-processing for objects is done by crawling up the inheritance + * hierarchy of the object, performing post-processing for each of the + * types encountered in the type hierarchy. The post-processing methods are + * invoked from most specific to most general class (base classes before + * super classes).
    • + *
    + *

    + * + *

    A composite walking does not perform any pre-processing or post-processing + * by itself. It can be configured with any number of other (composite or + * non-composite) model walkers. As pre-processing and post-processing the + * composite model walker invokes pre-processing and post-processing on each + * 'other' model walker, in the order they are supplied. The walking and + * crawling methods of the non-composite of the 'other' model walkers are not + * used.

    + * + *

    This abstract walker class has no public methods. It is up to the derived + * classes to add a public method as entry method. They can decide which + * classes are to be used as starting point, and they can give the public + * method a proper name, parameters, etc. They may even allow multiple public + * methods to allow starting from multiple classes.

    + * + * @param The type of the extra argument provided to the walking, crawling + * and processing methods. + */ +public abstract class CompositeCifWithArgWalker extends CifWithArgWalker { + /** The walkers to be composed by this composite walker. */ + private final CifWithArgWalker[] walkers; + + /** + * Constructor of the {@link CompositeCifWithArgWalker} class. + * + * @param walkers The walkers to be composed by this composite walker. + */ + public CompositeCifWithArgWalker(CifWithArgWalker[] walkers) { + this.walkers = walkers; + } + + @Override + protected void preprocessAlgParameter(AlgParameter obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessAlgParameter(obj, arg); + } + } + + @Override + protected void postprocessAlgParameter(AlgParameter obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessAlgParameter(obj, arg); + } + } + + @Override + protected void preprocessAlgVariable(AlgVariable obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessAlgVariable(obj, arg); + } + } + + @Override + protected void postprocessAlgVariable(AlgVariable obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessAlgVariable(obj, arg); + } + } + + @Override + protected void preprocessAlgVariableExpression(AlgVariableExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessAlgVariableExpression(obj, arg); + } + } + + @Override + protected void postprocessAlgVariableExpression(AlgVariableExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessAlgVariableExpression(obj, arg); + } + } + + @Override + protected void preprocessAlphabet(Alphabet obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessAlphabet(obj, arg); + } + } + + @Override + protected void postprocessAlphabet(Alphabet obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessAlphabet(obj, arg); + } + } + + @Override + protected void preprocessAssignment(Assignment obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessAssignment(obj, arg); + } + } + + @Override + protected void postprocessAssignment(Assignment obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessAssignment(obj, arg); + } + } + + @Override + protected void preprocessAssignmentFuncStatement(AssignmentFuncStatement obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessAssignmentFuncStatement(obj, arg); + } + } + + @Override + protected void postprocessAssignmentFuncStatement(AssignmentFuncStatement obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessAssignmentFuncStatement(obj, arg); + } + } + + @Override + protected void preprocessAutomaton(Automaton obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessAutomaton(obj, arg); + } + } + + @Override + protected void postprocessAutomaton(Automaton obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessAutomaton(obj, arg); + } + } + + @Override + protected void preprocessBaseFunctionExpression(BaseFunctionExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessBaseFunctionExpression(obj, arg); + } + } + + @Override + protected void postprocessBaseFunctionExpression(BaseFunctionExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessBaseFunctionExpression(obj, arg); + } + } + + @Override + protected void preprocessBinaryExpression(BinaryExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessBinaryExpression(obj, arg); + } + } + + @Override + protected void postprocessBinaryExpression(BinaryExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessBinaryExpression(obj, arg); + } + } + + @Override + protected void preprocessBoolExpression(BoolExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessBoolExpression(obj, arg); + } + } + + @Override + protected void postprocessBoolExpression(BoolExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessBoolExpression(obj, arg); + } + } + + @Override + protected void preprocessBoolType(BoolType obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessBoolType(obj, arg); + } + } + + @Override + protected void postprocessBoolType(BoolType obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessBoolType(obj, arg); + } + } + + @Override + protected void preprocessBreakFuncStatement(BreakFuncStatement obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessBreakFuncStatement(obj, arg); + } + } + + @Override + protected void postprocessBreakFuncStatement(BreakFuncStatement obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessBreakFuncStatement(obj, arg); + } + } + + @Override + protected void preprocessCastExpression(CastExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessCastExpression(obj, arg); + } + } + + @Override + protected void postprocessCastExpression(CastExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessCastExpression(obj, arg); + } + } + + @Override + protected void preprocessCifType(CifType obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessCifType(obj, arg); + } + } + + @Override + protected void postprocessCifType(CifType obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessCifType(obj, arg); + } + } + + @Override + protected void preprocessCompInstWrapExpression(CompInstWrapExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessCompInstWrapExpression(obj, arg); + } + } + + @Override + protected void postprocessCompInstWrapExpression(CompInstWrapExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessCompInstWrapExpression(obj, arg); + } + } + + @Override + protected void preprocessCompInstWrapType(CompInstWrapType obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessCompInstWrapType(obj, arg); + } + } + + @Override + protected void postprocessCompInstWrapType(CompInstWrapType obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessCompInstWrapType(obj, arg); + } + } + + @Override + protected void preprocessCompParamExpression(CompParamExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessCompParamExpression(obj, arg); + } + } + + @Override + protected void postprocessCompParamExpression(CompParamExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessCompParamExpression(obj, arg); + } + } + + @Override + protected void preprocessCompParamWrapExpression(CompParamWrapExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessCompParamWrapExpression(obj, arg); + } + } + + @Override + protected void postprocessCompParamWrapExpression(CompParamWrapExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessCompParamWrapExpression(obj, arg); + } + } + + @Override + protected void preprocessCompParamWrapType(CompParamWrapType obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessCompParamWrapType(obj, arg); + } + } + + @Override + protected void postprocessCompParamWrapType(CompParamWrapType obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessCompParamWrapType(obj, arg); + } + } + + @Override + protected void preprocessComplexComponent(ComplexComponent obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessComplexComponent(obj, arg); + } + } + + @Override + protected void postprocessComplexComponent(ComplexComponent obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessComplexComponent(obj, arg); + } + } + + @Override + protected void preprocessComponent(Component obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessComponent(obj, arg); + } + } + + @Override + protected void postprocessComponent(Component obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessComponent(obj, arg); + } + } + + @Override + protected void preprocessComponentDef(ComponentDef obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessComponentDef(obj, arg); + } + } + + @Override + protected void postprocessComponentDef(ComponentDef obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessComponentDef(obj, arg); + } + } + + @Override + protected void preprocessComponentDefType(ComponentDefType obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessComponentDefType(obj, arg); + } + } + + @Override + protected void postprocessComponentDefType(ComponentDefType obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessComponentDefType(obj, arg); + } + } + + @Override + protected void preprocessComponentExpression(ComponentExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessComponentExpression(obj, arg); + } + } + + @Override + protected void postprocessComponentExpression(ComponentExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessComponentExpression(obj, arg); + } + } + + @Override + protected void preprocessComponentInst(ComponentInst obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessComponentInst(obj, arg); + } + } + + @Override + protected void postprocessComponentInst(ComponentInst obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessComponentInst(obj, arg); + } + } + + @Override + protected void preprocessComponentParameter(ComponentParameter obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessComponentParameter(obj, arg); + } + } + + @Override + protected void postprocessComponentParameter(ComponentParameter obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessComponentParameter(obj, arg); + } + } + + @Override + protected void preprocessComponentType(ComponentType obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessComponentType(obj, arg); + } + } + + @Override + protected void postprocessComponentType(ComponentType obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessComponentType(obj, arg); + } + } + + @Override + protected void preprocessConstant(Constant obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessConstant(obj, arg); + } + } + + @Override + protected void postprocessConstant(Constant obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessConstant(obj, arg); + } + } + + @Override + protected void preprocessConstantExpression(ConstantExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessConstantExpression(obj, arg); + } + } + + @Override + protected void postprocessConstantExpression(ConstantExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessConstantExpression(obj, arg); + } + } + + @Override + protected void preprocessContVariable(ContVariable obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessContVariable(obj, arg); + } + } + + @Override + protected void postprocessContVariable(ContVariable obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessContVariable(obj, arg); + } + } + + @Override + protected void preprocessContVariableExpression(ContVariableExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessContVariableExpression(obj, arg); + } + } + + @Override + protected void postprocessContVariableExpression(ContVariableExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessContVariableExpression(obj, arg); + } + } + + @Override + protected void preprocessContinueFuncStatement(ContinueFuncStatement obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessContinueFuncStatement(obj, arg); + } + } + + @Override + protected void postprocessContinueFuncStatement(ContinueFuncStatement obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessContinueFuncStatement(obj, arg); + } + } + + @Override + protected void preprocessDeclaration(Declaration obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessDeclaration(obj, arg); + } + } + + @Override + protected void postprocessDeclaration(Declaration obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessDeclaration(obj, arg); + } + } + + @Override + protected void preprocessDictExpression(DictExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessDictExpression(obj, arg); + } + } + + @Override + protected void postprocessDictExpression(DictExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessDictExpression(obj, arg); + } + } + + @Override + protected void preprocessDictPair(DictPair obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessDictPair(obj, arg); + } + } + + @Override + protected void postprocessDictPair(DictPair obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessDictPair(obj, arg); + } + } + + @Override + protected void preprocessDictType(DictType obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessDictType(obj, arg); + } + } + + @Override + protected void postprocessDictType(DictType obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessDictType(obj, arg); + } + } + + @Override + protected void preprocessDiscVariable(DiscVariable obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessDiscVariable(obj, arg); + } + } + + @Override + protected void postprocessDiscVariable(DiscVariable obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessDiscVariable(obj, arg); + } + } + + @Override + protected void preprocessDiscVariableExpression(DiscVariableExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessDiscVariableExpression(obj, arg); + } + } + + @Override + protected void postprocessDiscVariableExpression(DiscVariableExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessDiscVariableExpression(obj, arg); + } + } + + @Override + protected void preprocessDistType(DistType obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessDistType(obj, arg); + } + } + + @Override + protected void postprocessDistType(DistType obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessDistType(obj, arg); + } + } + + @Override + protected void preprocessEdge(Edge obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessEdge(obj, arg); + } + } + + @Override + protected void postprocessEdge(Edge obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessEdge(obj, arg); + } + } + + @Override + protected void preprocessEdgeEvent(EdgeEvent obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessEdgeEvent(obj, arg); + } + } + + @Override + protected void postprocessEdgeEvent(EdgeEvent obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessEdgeEvent(obj, arg); + } + } + + @Override + protected void preprocessEdgeReceive(EdgeReceive obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessEdgeReceive(obj, arg); + } + } + + @Override + protected void postprocessEdgeReceive(EdgeReceive obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessEdgeReceive(obj, arg); + } + } + + @Override + protected void preprocessEdgeSend(EdgeSend obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessEdgeSend(obj, arg); + } + } + + @Override + protected void postprocessEdgeSend(EdgeSend obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessEdgeSend(obj, arg); + } + } + + @Override + protected void preprocessElifExpression(ElifExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessElifExpression(obj, arg); + } + } + + @Override + protected void postprocessElifExpression(ElifExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessElifExpression(obj, arg); + } + } + + @Override + protected void preprocessElifFuncStatement(ElifFuncStatement obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessElifFuncStatement(obj, arg); + } + } + + @Override + protected void postprocessElifFuncStatement(ElifFuncStatement obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessElifFuncStatement(obj, arg); + } + } + + @Override + protected void preprocessElifUpdate(ElifUpdate obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessElifUpdate(obj, arg); + } + } + + @Override + protected void postprocessElifUpdate(ElifUpdate obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessElifUpdate(obj, arg); + } + } + + @Override + protected void preprocessEnumDecl(EnumDecl obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessEnumDecl(obj, arg); + } + } + + @Override + protected void postprocessEnumDecl(EnumDecl obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessEnumDecl(obj, arg); + } + } + + @Override + protected void preprocessEnumLiteral(EnumLiteral obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessEnumLiteral(obj, arg); + } + } + + @Override + protected void postprocessEnumLiteral(EnumLiteral obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessEnumLiteral(obj, arg); + } + } + + @Override + protected void preprocessEnumLiteralExpression(EnumLiteralExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessEnumLiteralExpression(obj, arg); + } + } + + @Override + protected void postprocessEnumLiteralExpression(EnumLiteralExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessEnumLiteralExpression(obj, arg); + } + } + + @Override + protected void preprocessEnumType(EnumType obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessEnumType(obj, arg); + } + } + + @Override + protected void postprocessEnumType(EnumType obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessEnumType(obj, arg); + } + } + + @Override + protected void preprocessEquation(Equation obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessEquation(obj, arg); + } + } + + @Override + protected void postprocessEquation(Equation obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessEquation(obj, arg); + } + } + + @Override + protected void preprocessEvent(Event obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessEvent(obj, arg); + } + } + + @Override + protected void postprocessEvent(Event obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessEvent(obj, arg); + } + } + + @Override + protected void preprocessEventExpression(EventExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessEventExpression(obj, arg); + } + } + + @Override + protected void postprocessEventExpression(EventExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessEventExpression(obj, arg); + } + } + + @Override + protected void preprocessEventParameter(EventParameter obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessEventParameter(obj, arg); + } + } + + @Override + protected void postprocessEventParameter(EventParameter obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessEventParameter(obj, arg); + } + } + + @Override + protected void preprocessExpression(Expression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessExpression(obj, arg); + } + } + + @Override + protected void postprocessExpression(Expression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessExpression(obj, arg); + } + } + + @Override + protected void preprocessExternalFunction(ExternalFunction obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessExternalFunction(obj, arg); + } + } + + @Override + protected void postprocessExternalFunction(ExternalFunction obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessExternalFunction(obj, arg); + } + } + + @Override + protected void preprocessField(Field obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessField(obj, arg); + } + } + + @Override + protected void postprocessField(Field obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessField(obj, arg); + } + } + + @Override + protected void preprocessFieldExpression(FieldExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessFieldExpression(obj, arg); + } + } + + @Override + protected void postprocessFieldExpression(FieldExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessFieldExpression(obj, arg); + } + } + + @Override + protected void preprocessFuncType(FuncType obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessFuncType(obj, arg); + } + } + + @Override + protected void postprocessFuncType(FuncType obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessFuncType(obj, arg); + } + } + + @Override + protected void preprocessFunction(Function obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessFunction(obj, arg); + } + } + + @Override + protected void postprocessFunction(Function obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessFunction(obj, arg); + } + } + + @Override + protected void preprocessFunctionCallExpression(FunctionCallExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessFunctionCallExpression(obj, arg); + } + } + + @Override + protected void postprocessFunctionCallExpression(FunctionCallExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessFunctionCallExpression(obj, arg); + } + } + + @Override + protected void preprocessFunctionExpression(FunctionExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessFunctionExpression(obj, arg); + } + } + + @Override + protected void postprocessFunctionExpression(FunctionExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessFunctionExpression(obj, arg); + } + } + + @Override + protected void preprocessFunctionParameter(FunctionParameter obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessFunctionParameter(obj, arg); + } + } + + @Override + protected void postprocessFunctionParameter(FunctionParameter obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessFunctionParameter(obj, arg); + } + } + + @Override + protected void preprocessFunctionStatement(FunctionStatement obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessFunctionStatement(obj, arg); + } + } + + @Override + protected void postprocessFunctionStatement(FunctionStatement obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessFunctionStatement(obj, arg); + } + } + + @Override + protected void preprocessGroup(Group obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessGroup(obj, arg); + } + } + + @Override + protected void postprocessGroup(Group obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessGroup(obj, arg); + } + } + + @Override + protected void preprocessIfExpression(IfExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessIfExpression(obj, arg); + } + } + + @Override + protected void postprocessIfExpression(IfExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessIfExpression(obj, arg); + } + } + + @Override + protected void preprocessIfFuncStatement(IfFuncStatement obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessIfFuncStatement(obj, arg); + } + } + + @Override + protected void postprocessIfFuncStatement(IfFuncStatement obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessIfFuncStatement(obj, arg); + } + } + + @Override + protected void preprocessIfUpdate(IfUpdate obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessIfUpdate(obj, arg); + } + } + + @Override + protected void postprocessIfUpdate(IfUpdate obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessIfUpdate(obj, arg); + } + } + + @Override + protected void preprocessInputVariable(InputVariable obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessInputVariable(obj, arg); + } + } + + @Override + protected void postprocessInputVariable(InputVariable obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessInputVariable(obj, arg); + } + } + + @Override + protected void preprocessInputVariableExpression(InputVariableExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessInputVariableExpression(obj, arg); + } + } + + @Override + protected void postprocessInputVariableExpression(InputVariableExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessInputVariableExpression(obj, arg); + } + } + + @Override + protected void preprocessIntExpression(IntExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessIntExpression(obj, arg); + } + } + + @Override + protected void postprocessIntExpression(IntExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessIntExpression(obj, arg); + } + } + + @Override + protected void preprocessIntType(IntType obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessIntType(obj, arg); + } + } + + @Override + protected void postprocessIntType(IntType obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessIntType(obj, arg); + } + } + + @Override + protected void preprocessInternalFunction(InternalFunction obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessInternalFunction(obj, arg); + } + } + + @Override + protected void postprocessInternalFunction(InternalFunction obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessInternalFunction(obj, arg); + } + } + + @Override + protected void preprocessInvariant(Invariant obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessInvariant(obj, arg); + } + } + + @Override + protected void postprocessInvariant(Invariant obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessInvariant(obj, arg); + } + } + + @Override + protected void preprocessIoDecl(IoDecl obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessIoDecl(obj, arg); + } + } + + @Override + protected void postprocessIoDecl(IoDecl obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessIoDecl(obj, arg); + } + } + + @Override + protected void preprocessListExpression(ListExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessListExpression(obj, arg); + } + } + + @Override + protected void postprocessListExpression(ListExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessListExpression(obj, arg); + } + } + + @Override + protected void preprocessListType(ListType obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessListType(obj, arg); + } + } + + @Override + protected void postprocessListType(ListType obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessListType(obj, arg); + } + } + + @Override + protected void preprocessLocation(Location obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessLocation(obj, arg); + } + } + + @Override + protected void postprocessLocation(Location obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessLocation(obj, arg); + } + } + + @Override + protected void preprocessLocationExpression(LocationExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessLocationExpression(obj, arg); + } + } + + @Override + protected void postprocessLocationExpression(LocationExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessLocationExpression(obj, arg); + } + } + + @Override + protected void preprocessLocationParameter(LocationParameter obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessLocationParameter(obj, arg); + } + } + + @Override + protected void postprocessLocationParameter(LocationParameter obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessLocationParameter(obj, arg); + } + } + + @Override + protected void preprocessMonitors(Monitors obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessMonitors(obj, arg); + } + } + + @Override + protected void postprocessMonitors(Monitors obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessMonitors(obj, arg); + } + } + + @Override + protected void preprocessParameter(Parameter obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessParameter(obj, arg); + } + } + + @Override + protected void postprocessParameter(Parameter obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessParameter(obj, arg); + } + } + + @Override + protected void preprocessPosition(Position obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessPosition(obj, arg); + } + } + + @Override + protected void postprocessPosition(Position obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessPosition(obj, arg); + } + } + + @Override + protected void preprocessPositionObject(PositionObject obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessPositionObject(obj, arg); + } + } + + @Override + protected void postprocessPositionObject(PositionObject obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessPositionObject(obj, arg); + } + } + + @Override + protected void preprocessPrint(Print obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessPrint(obj, arg); + } + } + + @Override + protected void postprocessPrint(Print obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessPrint(obj, arg); + } + } + + @Override + protected void preprocessPrintFile(PrintFile obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessPrintFile(obj, arg); + } + } + + @Override + protected void postprocessPrintFile(PrintFile obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessPrintFile(obj, arg); + } + } + + @Override + protected void preprocessPrintFor(PrintFor obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessPrintFor(obj, arg); + } + } + + @Override + protected void postprocessPrintFor(PrintFor obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessPrintFor(obj, arg); + } + } + + @Override + protected void preprocessProjectionExpression(ProjectionExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessProjectionExpression(obj, arg); + } + } + + @Override + protected void postprocessProjectionExpression(ProjectionExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessProjectionExpression(obj, arg); + } + } + + @Override + protected void preprocessRealExpression(RealExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessRealExpression(obj, arg); + } + } + + @Override + protected void postprocessRealExpression(RealExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessRealExpression(obj, arg); + } + } + + @Override + protected void preprocessRealType(RealType obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessRealType(obj, arg); + } + } + + @Override + protected void postprocessRealType(RealType obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessRealType(obj, arg); + } + } + + @Override + protected void preprocessReceivedExpression(ReceivedExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessReceivedExpression(obj, arg); + } + } + + @Override + protected void postprocessReceivedExpression(ReceivedExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessReceivedExpression(obj, arg); + } + } + + @Override + protected void preprocessReturnFuncStatement(ReturnFuncStatement obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessReturnFuncStatement(obj, arg); + } + } + + @Override + protected void postprocessReturnFuncStatement(ReturnFuncStatement obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessReturnFuncStatement(obj, arg); + } + } + + @Override + protected void preprocessSelfExpression(SelfExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessSelfExpression(obj, arg); + } + } + + @Override + protected void postprocessSelfExpression(SelfExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessSelfExpression(obj, arg); + } + } + + @Override + protected void preprocessSetExpression(SetExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessSetExpression(obj, arg); + } + } + + @Override + protected void postprocessSetExpression(SetExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessSetExpression(obj, arg); + } + } + + @Override + protected void preprocessSetType(SetType obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessSetType(obj, arg); + } + } + + @Override + protected void postprocessSetType(SetType obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessSetType(obj, arg); + } + } + + @Override + protected void preprocessSliceExpression(SliceExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessSliceExpression(obj, arg); + } + } + + @Override + protected void postprocessSliceExpression(SliceExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessSliceExpression(obj, arg); + } + } + + @Override + protected void preprocessSpecification(Specification obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessSpecification(obj, arg); + } + } + + @Override + protected void postprocessSpecification(Specification obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessSpecification(obj, arg); + } + } + + @Override + protected void preprocessStdLibFunctionExpression(StdLibFunctionExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessStdLibFunctionExpression(obj, arg); + } + } + + @Override + protected void postprocessStdLibFunctionExpression(StdLibFunctionExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessStdLibFunctionExpression(obj, arg); + } + } + + @Override + protected void preprocessStringExpression(StringExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessStringExpression(obj, arg); + } + } + + @Override + protected void postprocessStringExpression(StringExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessStringExpression(obj, arg); + } + } + + @Override + protected void preprocessStringType(StringType obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessStringType(obj, arg); + } + } + + @Override + protected void postprocessStringType(StringType obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessStringType(obj, arg); + } + } + + @Override + protected void preprocessSvgCopy(SvgCopy obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessSvgCopy(obj, arg); + } + } + + @Override + protected void postprocessSvgCopy(SvgCopy obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessSvgCopy(obj, arg); + } + } + + @Override + protected void preprocessSvgFile(SvgFile obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessSvgFile(obj, arg); + } + } + + @Override + protected void postprocessSvgFile(SvgFile obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessSvgFile(obj, arg); + } + } + + @Override + protected void preprocessSvgIn(SvgIn obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessSvgIn(obj, arg); + } + } + + @Override + protected void postprocessSvgIn(SvgIn obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessSvgIn(obj, arg); + } + } + + @Override + protected void preprocessSvgInEvent(SvgInEvent obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessSvgInEvent(obj, arg); + } + } + + @Override + protected void postprocessSvgInEvent(SvgInEvent obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessSvgInEvent(obj, arg); + } + } + + @Override + protected void preprocessSvgInEventIf(SvgInEventIf obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessSvgInEventIf(obj, arg); + } + } + + @Override + protected void postprocessSvgInEventIf(SvgInEventIf obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessSvgInEventIf(obj, arg); + } + } + + @Override + protected void preprocessSvgInEventIfEntry(SvgInEventIfEntry obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessSvgInEventIfEntry(obj, arg); + } + } + + @Override + protected void postprocessSvgInEventIfEntry(SvgInEventIfEntry obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessSvgInEventIfEntry(obj, arg); + } + } + + @Override + protected void preprocessSvgInEventSingle(SvgInEventSingle obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessSvgInEventSingle(obj, arg); + } + } + + @Override + protected void postprocessSvgInEventSingle(SvgInEventSingle obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessSvgInEventSingle(obj, arg); + } + } + + @Override + protected void preprocessSvgMove(SvgMove obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessSvgMove(obj, arg); + } + } + + @Override + protected void postprocessSvgMove(SvgMove obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessSvgMove(obj, arg); + } + } + + @Override + protected void preprocessSvgOut(SvgOut obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessSvgOut(obj, arg); + } + } + + @Override + protected void postprocessSvgOut(SvgOut obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessSvgOut(obj, arg); + } + } + + @Override + protected void preprocessSwitchCase(SwitchCase obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessSwitchCase(obj, arg); + } + } + + @Override + protected void postprocessSwitchCase(SwitchCase obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessSwitchCase(obj, arg); + } + } + + @Override + protected void preprocessSwitchExpression(SwitchExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessSwitchExpression(obj, arg); + } + } + + @Override + protected void postprocessSwitchExpression(SwitchExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessSwitchExpression(obj, arg); + } + } + + @Override + protected void preprocessTauExpression(TauExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessTauExpression(obj, arg); + } + } + + @Override + protected void postprocessTauExpression(TauExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessTauExpression(obj, arg); + } + } + + @Override + protected void preprocessTimeExpression(TimeExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessTimeExpression(obj, arg); + } + } + + @Override + protected void postprocessTimeExpression(TimeExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessTimeExpression(obj, arg); + } + } + + @Override + protected void preprocessTupleExpression(TupleExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessTupleExpression(obj, arg); + } + } + + @Override + protected void postprocessTupleExpression(TupleExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessTupleExpression(obj, arg); + } + } + + @Override + protected void preprocessTupleType(TupleType obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessTupleType(obj, arg); + } + } + + @Override + protected void postprocessTupleType(TupleType obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessTupleType(obj, arg); + } + } + + @Override + protected void preprocessTypeDecl(TypeDecl obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessTypeDecl(obj, arg); + } + } + + @Override + protected void postprocessTypeDecl(TypeDecl obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessTypeDecl(obj, arg); + } + } + + @Override + protected void preprocessTypeRef(TypeRef obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessTypeRef(obj, arg); + } + } + + @Override + protected void postprocessTypeRef(TypeRef obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessTypeRef(obj, arg); + } + } + + @Override + protected void preprocessUnaryExpression(UnaryExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessUnaryExpression(obj, arg); + } + } + + @Override + protected void postprocessUnaryExpression(UnaryExpression obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessUnaryExpression(obj, arg); + } + } + + @Override + protected void preprocessUpdate(Update obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessUpdate(obj, arg); + } + } + + @Override + protected void postprocessUpdate(Update obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessUpdate(obj, arg); + } + } + + @Override + protected void preprocessVariableValue(VariableValue obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessVariableValue(obj, arg); + } + } + + @Override + protected void postprocessVariableValue(VariableValue obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessVariableValue(obj, arg); + } + } + + @Override + protected void preprocessVoidType(VoidType obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessVoidType(obj, arg); + } + } + + @Override + protected void postprocessVoidType(VoidType obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessVoidType(obj, arg); + } + } + + @Override + protected void preprocessWhileFuncStatement(WhileFuncStatement obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.preprocessWhileFuncStatement(obj, arg); + } + } + + @Override + protected void postprocessWhileFuncStatement(WhileFuncStatement obj, T arg) { + for (CifWithArgWalker walker: walkers) { + walker.postprocessWhileFuncStatement(obj, arg); + } + } +} diff --git a/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/java/ModelWalkerGenerator.java b/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/java/ModelWalkerGenerator.java index a63240abb..4724c5b6c 100644 --- a/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/java/ModelWalkerGenerator.java +++ b/common/org.eclipse.escet.common.emf.ecore.codegen/src/org/eclipse/escet/common/emf/ecore/codegen/java/ModelWalkerGenerator.java @@ -45,6 +45,8 @@ import org.eclipse.escet.common.java.JavaCodeUtils; *
  • Composite model walkers. They support combining multiple model walkers. This allows one to separate a large model * walker into separate smaller, simpler, easier-to-maintain model walkers and combining them to functionally obtain * back the original larger model walker.
  • + *
  • Model walkers and composite model walkers where the methods have an extra argument of some specified type, + * allowing to pass along some object while walking over the models.
  • * *

    * @@ -72,6 +74,9 @@ public class ModelWalkerGenerator extends EmfJavaCodeGenerator { *
  • The output directory path. For instance, {@code "src/bla/somelang/metamodel/java"}.
  • *
  • The model walker output class name. For instance, {@code "SomeLangWalker"}.
  • *
  • The composite model walker output class name. For instance, {@code "CompositeSomeLangWalker"}.
  • + *
  • The extra-argument model walker output class name. For instance, {@code "SomeLangWithArgWalker"}.
  • + *
  • The extra-argument composite model walker output class name. For instance, + * {@code "CompositeSomeLangWithArgWalker"}.
  • *
  • The output package name. For instance, {@code "bla.somelang.metamodel.java"}.
  • * * @throws IOException In case the code could not be written to a file; or in case the java class path extension @@ -84,33 +89,47 @@ public class ModelWalkerGenerator extends EmfJavaCodeGenerator { throws IOException, ClassNotFoundException, NoSuchFieldException, IllegalAccessException { // Process arguments. - Assert.check(args.length == 6, args.length); + Assert.check(args.length == 8, args.length); String mainPkgClassName = args[0]; String binPath = args[1]; String outputPath = args[2]; String outputClassNameWalker = args[3]; String outputClassNameComposite = args[4]; - String outputPackageName = args[5]; + String outputClassNameWalkerWithArg = args[5]; + String outputClassNameCompositeWithArg = args[6]; + String outputPackageName = args[7]; // Resolve the package. EPackage mainPkg = loadEPackage(mainPkgClassName, binPath); // Generate code for the package. CodeBox boxWalker = generateClass(false, mainPkg, outputClassNameWalker, outputClassNameComposite, - outputPackageName); + outputPackageName, false); CodeBox boxComposite = generateClass(true, mainPkg, outputClassNameWalker, outputClassNameComposite, - outputPackageName); + outputPackageName, false); + CodeBox boxWalkerWithArg = generateClass(false, mainPkg, outputClassNameWalkerWithArg, + outputClassNameCompositeWithArg, outputPackageName, true); + CodeBox boxCompositeWithArg = generateClass(true, mainPkg, outputClassNameWalkerWithArg, + outputClassNameCompositeWithArg, outputPackageName, true); // Try to write the code to a file. String outputFilePathWalker = new File(new File(outputPath), outputClassNameWalker + ".java").getAbsolutePath(); String outputFilePathComposite = new File(new File(outputPath), outputClassNameComposite + ".java") .getAbsolutePath(); + String outputFilePathWalkerWithArg = new File(new File(outputPath), outputClassNameWalkerWithArg + ".java") + .getAbsolutePath(); + String outputFilePathCompositeWithArg = new File(new File(outputPath), + outputClassNameCompositeWithArg + ".java").getAbsolutePath(); boxWalker.writeToFile(outputFilePathWalker); boxComposite.writeToFile(outputFilePathComposite); + boxWalkerWithArg.writeToFile(outputFilePathWalkerWithArg); + boxCompositeWithArg.writeToFile(outputFilePathCompositeWithArg); // We are done. System.out.printf("Walker code written to: %s%n", outputFilePathWalker); System.out.printf("Composite walker code written to: %s%n", outputFilePathComposite); + System.out.printf("Extra-argument walker code written to: %s%n", outputFilePathWalkerWithArg); + System.out.printf("Extra-argument composite walker code written to: %s%n", outputFilePathCompositeWithArg); } /** @@ -122,10 +141,11 @@ public class ModelWalkerGenerator extends EmfJavaCodeGenerator { * @param genClassNameWalker The name of the model walker Java class to generate. * @param genClassNameComposite The name of the composite model walker Java class to generate. * @param genPackageName The name of the package that the generated Java class will be a part of. + * @param withArg Whether to generate an extra-argument walker ({@code true}) or a regular walker ({@code false}). * @return The generated code. */ private static CodeBox generateClass(boolean genComposite, EPackage startPackage, String genClassNameWalker, - String genClassNameComposite, String genPackageName) + String genClassNameComposite, String genPackageName, boolean withArg) { // Initialize the code. CodeBox box = new MemoryCodeBox(); @@ -258,13 +278,19 @@ public class ModelWalkerGenerator extends EmfJavaCodeGenerator { box.add(" * classes are to be used as starting point, and they can give the public"); box.add(" * method a proper name, parameters, etc. They may even allow multiple public"); box.add(" * methods to allow starting from multiple classes.

    "); + if (withArg) { + box.add(" *"); + box.add(" * @param The type of the extra argument provided to the walking, crawling"); + box.add(" * and processing methods."); + } box.add(" */"); // Add the class header. if (genComposite) { - box.add("public abstract class %s extends %s {", genClassNameComposite, genClassNameWalker); + box.add("public abstract class %s%s extends %s%s {", genClassNameComposite, withArg ? "" : "", + genClassNameWalker, withArg ? "" : ""); } else { - box.add("public abstract class %s {", genClassNameWalker); + box.add("public abstract class %s%s {", genClassNameWalker, withArg ? "" : ""); } // Add the class body. @@ -272,7 +298,7 @@ public class ModelWalkerGenerator extends EmfJavaCodeGenerator { // Add fields. box.indent(); box.add("/** The walkers to be composed by this composite walker. */"); - box.add("private final %s[] walkers;", genClassNameWalker); + box.add("private final %s%s[] walkers;", genClassNameWalker, withArg ? "" : ""); box.dedent(); box.add(); @@ -283,14 +309,14 @@ public class ModelWalkerGenerator extends EmfJavaCodeGenerator { box.add(" *"); box.add(" * @param walkers The walkers to be composed by this composite walker."); box.add(" */"); - box.add("public %s(%s[] walkers) {", genClassNameComposite, genClassNameWalker); + box.add("public %s(%s%s[] walkers) {", genClassNameComposite, genClassNameWalker, withArg ? "" : ""); box.add(" this.walkers = walkers;"); box.add("}"); box.dedent(); // Add methods. for (EClass cls: classes) { - generateCompositeWalkerMethods(cls, genClassNameWalker, box); + generateCompositeWalkerMethods(cls, genClassNameWalker, withArg, box); } } else { // Add methods. @@ -299,7 +325,7 @@ public class ModelWalkerGenerator extends EmfJavaCodeGenerator { if (!first) { box.add(); } - generateWalkerMethods(cls, classes, box); + generateWalkerMethods(cls, classes, withArg, box); first = false; } } @@ -314,9 +340,10 @@ public class ModelWalkerGenerator extends EmfJavaCodeGenerator { * * @param cls The {@link EClass} to generate the code for. * @param classes The candidate derived classes for the given 'cls'. + * @param withArg Whether to generate an extra-argument methods ({@code true}) or regular methods ({@code false}). * @param box The generated code (appended in-place). */ - private static void generateWalkerMethods(EClass cls, List classes, CodeBox box) { + private static void generateWalkerMethods(EClass cls, List classes, boolean withArg, CodeBox box) { List derivedClasses = getDerivedClasses(cls, classes); // Walking function. @@ -325,8 +352,11 @@ public class ModelWalkerGenerator extends EmfJavaCodeGenerator { box.add(" * Walking function for the {@link %s} class.", cls.getName()); box.add(" *"); box.add(" * @param obj The object to walk over."); + if (withArg) { + box.add(" * @param arg The extra argument provided to the walking method."); + } box.add(" */"); - box.add("protected void walk%s(%s obj) {", cls.getName(), cls.getName()); + box.add("protected void walk%s(%s obj%s) {", cls.getName(), cls.getName(), withArg ? ", T arg" : ""); box.indent(); if (derivedClasses.size() > 0) { @@ -334,7 +364,7 @@ public class ModelWalkerGenerator extends EmfJavaCodeGenerator { box.add("if (obj instanceof %s) {", derived.getName()); box.indent(); - box.add("walk%s((%s)obj);", derived.getName(), derived.getName()); + box.add("walk%s((%s)obj%s);", derived.getName(), derived.getName(), withArg ? ", arg" : ""); box.add("return;"); box.dedent(); @@ -349,7 +379,7 @@ public class ModelWalkerGenerator extends EmfJavaCodeGenerator { if (derivedClasses.size() > 0) { box.add("Assert.check(obj.getClass() == %s.class);", getImplClassSimpleName(cls)); } - box.add("precrawl%s(obj);", cls.getName()); + box.add("precrawl%s(obj%s);", cls.getName(), withArg ? ", arg" : ""); List feats = getAllContainmentStructuralFeatures(cls); for (EReference feat: feats) { String methodName = feat.getName(); @@ -360,7 +390,7 @@ public class ModelWalkerGenerator extends EmfJavaCodeGenerator { box.add("List<%s> _%s = obj.%s();", feat.getEReferenceType().getName(), feat.getName(), methodName); box.add("for (%s x: _%s) {", feat.getEReferenceType().getName(), feat.getName()); box.indent(); - box.add("walk%s(x);", feat.getEReferenceType().getName()); + box.add("walk%s(x%s);", feat.getEReferenceType().getName(), withArg ? ", arg" : ""); box.dedent(); box.add("}"); } else { @@ -371,17 +401,19 @@ public class ModelWalkerGenerator extends EmfJavaCodeGenerator { // Case: [0..1] box.add("if (_%s != null) {", feat.getName()); box.indent(); - box.add("walk%s(_%s);", feat.getEReferenceType().getName(), feat.getName()); + box.add("walk%s(_%s%s);", feat.getEReferenceType().getName(), feat.getName(), + withArg ? ", arg" : ""); box.dedent(); box.add("}"); } else { // Case: [1] Assert.check(feat.getLowerBound() == 1); - box.add("walk%s(_%s);", feat.getEReferenceType().getName(), feat.getName()); + box.add("walk%s(_%s%s);", feat.getEReferenceType().getName(), feat.getName(), + withArg ? ", arg" : ""); } } } - box.add("postcrawl%s(obj);", cls.getName()); + box.add("postcrawl%s(obj%s);", cls.getName(), withArg ? ", arg" : ""); } box.dedent(); @@ -398,14 +430,17 @@ public class ModelWalkerGenerator extends EmfJavaCodeGenerator { box.add(" * Pre-crawling function for the {@link %s} class.", cls.getName()); box.add(" *"); box.add(" * @param obj The object to crawl over."); + if (withArg) { + box.add(" * @param arg The extra argument provided to the pre-crawling method."); + } box.add(" */"); - box.add("protected void precrawl%s(%s obj) {", cls.getName(), cls.getName()); + box.add("protected void precrawl%s(%s obj%s) {", cls.getName(), cls.getName(), withArg ? ", T arg" : ""); box.indent(); for (EClass superClass: superClasses) { - box.add("precrawl%s(obj);", superClass.getName()); + box.add("precrawl%s(obj%s);", superClass.getName(), withArg ? ", arg" : ""); } - box.add("preprocess%s(obj);", cls.getName()); + box.add("preprocess%s(obj%s);", cls.getName(), withArg ? ", arg" : ""); box.dedent(); box.add("}"); @@ -416,13 +451,16 @@ public class ModelWalkerGenerator extends EmfJavaCodeGenerator { box.add(" * Post-crawling function for the {@link %s} class.", cls.getName()); box.add(" *"); box.add(" * @param obj The object to crawl over."); + if (withArg) { + box.add(" * @param arg The extra argument provided to the post-crawling method."); + } box.add(" */"); - box.add("protected void postcrawl%s(%s obj) {", cls.getName(), cls.getName()); + box.add("protected void postcrawl%s(%s obj%s) {", cls.getName(), cls.getName(), withArg ? ", T arg" : ""); box.indent(); - box.add("postprocess%s(obj);", cls.getName()); + box.add("postprocess%s(obj%s);", cls.getName(), withArg ? ", arg" : ""); for (EClass superClass: superClasses) { - box.add("postcrawl%s(obj);", superClass.getName()); + box.add("postcrawl%s(obj%s);", superClass.getName(), withArg ? ", arg" : ""); } box.dedent(); @@ -434,8 +472,11 @@ public class ModelWalkerGenerator extends EmfJavaCodeGenerator { box.add(" * Pre-processing function for the {@link %s} class.", cls.getName()); box.add(" *"); box.add(" * @param obj The object to pre-process."); + if (withArg) { + box.add(" * @param arg The extra argument provided to the pre-processing method."); + } box.add(" */"); - box.add("protected void preprocess%s(%s obj) {", cls.getName(), cls.getName()); + box.add("protected void preprocess%s(%s obj%s) {", cls.getName(), cls.getName(), withArg ? ", T arg" : ""); box.add(" // Derived classes may override this method to do actual processing."); box.add("}"); box.add(); @@ -445,8 +486,11 @@ public class ModelWalkerGenerator extends EmfJavaCodeGenerator { box.add(" * Post-processing function for the {@link %s} class.", cls.getName()); box.add(" *"); box.add(" * @param obj The object to post-process."); + if (withArg) { + box.add(" * @param arg The extra argument provided to the post-processing method."); + } box.add(" */"); - box.add("protected void postprocess%s(%s obj) {", cls.getName(), cls.getName()); + box.add("protected void postprocess%s(%s obj%s) {", cls.getName(), cls.getName(), withArg ? ", T arg" : ""); box.add(" // Derived classes may override this method to do actual processing."); box.add("}"); box.dedent(); @@ -457,16 +501,19 @@ public class ModelWalkerGenerator extends EmfJavaCodeGenerator { * * @param cls The {@link EClass} to generate the code for. * @param genClassNameWalker The name of the model walker Java class to generate. + * @param withArg Whether to generate an extra-argument methods ({@code true}) or regular methods ({@code false}). * @param box The generated code (appended in-place). */ - private static void generateCompositeWalkerMethods(EClass cls, String genClassNameWalker, CodeBox box) { + private static void generateCompositeWalkerMethods(EClass cls, String genClassNameWalker, boolean withArg, + CodeBox box) + { // Pre-processing function. box.add(); box.indent(); box.add("@Override"); - box.add("protected void preprocess%s(%s obj) {", cls.getName(), cls.getName()); - box.add(" for (%s walker: walkers) {", genClassNameWalker); - box.add(" walker.preprocess%s(obj);", cls.getName()); + box.add("protected void preprocess%s(%s obj%s) {", cls.getName(), cls.getName(), withArg ? ", T arg" : ""); + box.add(" for (%s%s walker: walkers) {", genClassNameWalker, withArg ? "" : ""); + box.add(" walker.preprocess%s(obj%s);", cls.getName(), withArg ? ", arg" : ""); box.add(" }"); box.add("}"); box.dedent(); @@ -475,9 +522,9 @@ public class ModelWalkerGenerator extends EmfJavaCodeGenerator { box.add(); box.indent(); box.add("@Override"); - box.add("protected void postprocess%s(%s obj) {", cls.getName(), cls.getName()); - box.add(" for (%s walker: walkers) {", genClassNameWalker); - box.add(" walker.postprocess%s(obj);", cls.getName()); + box.add("protected void postprocess%s(%s obj%s) {", cls.getName(), cls.getName(), withArg ? ", T arg" : ""); + box.add(" for (%s%s walker: walkers) {", genClassNameWalker, withArg ? "" : ""); + box.add(" walker.postprocess%s(obj%s);", cls.getName(), withArg ? ", arg" : ""); box.add(" }"); box.add("}"); box.dedent(); -- GitLab From d83f2801bd63503e0a2f41f121e567c1f11c1682 Mon Sep 17 00:00:00 2001 From: Dennis Hendriks Date: Sat, 11 Jun 2022 08:16:04 +0200 Subject: [PATCH 22/23] #370 Adapt CIF checks to use extra-argument (composite) walkers. --- .../escet/cif/common/checkers/CifCheck.java | 32 +--- .../common/checkers/CifCheckViolations.java | 58 +++++++ .../escet/cif/common/checkers/CifChecker.java | 27 +-- .../checkers/CifPreconditionChecker.java | 7 +- .../cif/common/checkers/NoChannelsCheck.java | 4 +- .../checkers/NoContinuousVariablesCheck.java | 4 +- .../NoDiscVarsWithMultiInitValuesCheck.java | 6 +- .../checkers/NoIfUpdatesOnEdgesCheck.java | 6 +- .../checkers/NoInitPredsInCompsCheck.java | 4 +- .../checkers/NoInputVariablesCheck.java | 4 +- .../checkers/NoKindlessAutomataCheck.java | 4 +- .../NoKindlessStateEvtExclInvsCheck.java | 10 +- .../checkers/NoMultiAssignOnEdgesCheck.java | 6 +- .../NoPartialVarAssignOnEdgesCheck.java | 6 +- .../checkers/NoSpecificBinaryExprsCheck.java | 141 ++++++++-------- .../common/checkers/NoSpecificExprsCheck.java | 157 +++++++++--------- .../common/checkers/NoSpecificTypesCheck.java | 67 ++++---- .../checkers/NoSpecificUnaryExprsCheck.java | 36 ++-- .../checkers/NoStateInvsInLocsCheck.java | 6 +- .../escet/cif/common/checkers/NoTauCheck.java | 13 +- .../common/checkers/NoUrgentEdgesCheck.java | 6 +- .../checkers/NoUrgentLocationsCheck.java | 6 +- .../checkers/NoUserDefinedFunctionsCheck.java | 4 +- .../checkers/OnlyAutsWithOneInitLocCheck.java | 14 +- .../OnlyEventsWithControllabilityCheck.java | 18 +- .../OnlyReqStateInvsInCompsCheck.java | 4 +- .../checkers/OnlySimpleAssignmentsCheck.java | 20 +-- .../OnlyStaticEvalMarkerPredsInLocsCheck.java | 10 +- .../OnlyVarValueMarkerPredsInCompsCheck.java | 18 +- 29 files changed, 346 insertions(+), 352 deletions(-) create mode 100644 cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifCheckViolations.java diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifCheck.java index 42ea0262c..18ad34bb3 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifCheck.java @@ -13,10 +13,7 @@ package org.eclipse.escet.cif.common.checkers; -import java.util.Set; - -import org.eclipse.escet.cif.metamodel.java.CifWalker; -import org.eclipse.escet.common.position.metamodel.position.PositionObject; +import org.eclipse.escet.cif.metamodel.java.CifWithArgWalker; /** * CIF check. Checks whether a given CIF specification satisfies a certain condition. @@ -24,29 +21,6 @@ import org.eclipse.escet.common.position.metamodel.position.PositionObject; * @implSpec Override only the relevant {@code preprocess*} and {@code postprocess*} methods. The {@code *crawl*} and * {@code walk*} methods should not be overridden, as they are ignored by {@link CifChecker}. */ -public abstract class CifCheck extends CifWalker { - /** The violations collected so far. */ - private Set violations; - - /** - * Sets the set in which to collect violations. - * - * @param violations The set. - */ - public void setViolations(Set violations) { - this.violations = violations; - } - - /** - * Add a violation. - * - * @param cifObject The named CIF object for which the violation is reported, or {@code null} to report it for the - * CIF specification. - * @param message The message describing the violation. E.g., {@code "event is a channel"}, - * {@code "automaton is a kindless automaton, lacking a supervisory kind"} or - * {@code "specification has no automata"}. - */ - protected void addViolation(PositionObject cifObject, String message) { - violations.add(new CifCheckViolation(cifObject, message)); - } +public abstract class CifCheck extends CifWithArgWalker { + // Nothing to do here. } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifCheckViolations.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifCheckViolations.java new file mode 100644 index 000000000..765f72490 --- /dev/null +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifCheckViolations.java @@ -0,0 +1,58 @@ +////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2022 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available +// under the terms of the MIT License which is available at +// https://opensource.org/licenses/MIT +// +// SPDX-License-Identifier: MIT +////////////////////////////////////////////////////////////////////////////// + +package org.eclipse.escet.cif.common.checkers; + +import static org.eclipse.escet.common.java.Sets.set; + +import java.util.Set; +import java.util.stream.Stream; + +import org.eclipse.escet.common.position.metamodel.position.PositionObject; + +/** CIF check condition violations. */ +public class CifCheckViolations { + /** The violations collected so far. */ + private final Set violations = set(); + + /** + * Returns whether any violations were collected so far. + * + * @return {@code true} if violations were collected, {@code false} otherwise. + */ + public boolean hasViolations() { + return !violations.isEmpty(); + } + + /** + * Returns the violations collected so far. + * + * @return The violations. + */ + public Stream getViolations() { + return violations.stream(); + } + + /** + * Add a violation. + * + * @param cifObject The named CIF object for which the violation is reported, or {@code null} to report it for the + * CIF specification. + * @param message The message describing the violation. E.g., {@code "event is a channel"}, + * {@code "automaton is a kindless automaton, lacking a supervisory kind"} or + * {@code "specification has no automata"}. + */ + public void add(PositionObject cifObject, String message) { + violations.add(new CifCheckViolation(cifObject, message)); + } +} diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifChecker.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifChecker.java index 2f48f80d8..bde8a0165 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifChecker.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifChecker.java @@ -13,26 +13,20 @@ package org.eclipse.escet.cif.common.checkers; -import static org.eclipse.escet.common.java.Sets.set; - import java.util.List; -import java.util.Set; import org.eclipse.escet.cif.metamodel.cif.Specification; -import org.eclipse.escet.cif.metamodel.java.CompositeCifWalker; +import org.eclipse.escet.cif.metamodel.java.CompositeCifWithArgWalker; /** CIF checker. Checks whether a given CIF specification satisfies certain {@link CifCheck conditions}. */ -public class CifChecker extends CompositeCifWalker { - /** The conditions to check. */ - private final CifCheck[] conditions; - +public class CifChecker extends CompositeCifWithArgWalker { /** * Constructor for the {@link CifChecker} class. * * @param conditions The conditions to check. */ public CifChecker(List conditions) { - this(conditions.toArray(i -> new CifCheck[i])); + super(conditions.toArray(i -> new CifCheck[i])); } /** @@ -42,7 +36,6 @@ public class CifChecker extends CompositeCifWalker { */ public CifChecker(CifCheck[] conditions) { super(conditions); - this.conditions = conditions; } /** @@ -51,17 +44,9 @@ public class CifChecker extends CompositeCifWalker { * @param spec The CIF specification to check. * @return The violations. */ - public Set check(Specification spec) { - // Initialize. - Set violations = set(); - for (CifCheck condition: conditions) { - condition.setViolations(violations); - } - - // Check specification for condition violations. - walkSpecification(spec); - - // Return the violations. + public CifCheckViolations check(Specification spec) { + CifCheckViolations violations = new CifCheckViolations(); + walkSpecification(spec, violations); return violations; } } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifPreconditionChecker.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifPreconditionChecker.java index 70eca5ae5..5056ba3bd 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifPreconditionChecker.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/CifPreconditionChecker.java @@ -15,7 +15,6 @@ package org.eclipse.escet.cif.common.checkers; import java.util.Collections; import java.util.List; -import java.util.Set; import java.util.stream.Collectors; import org.eclipse.escet.cif.metamodel.cif.Specification; @@ -55,11 +54,11 @@ public class CifPreconditionChecker extends CifChecker { */ public void reportPreconditionViolations(Specification spec, String toolName) { // Check specification. - Set violations = check(spec); + CifCheckViolations violations = check(spec); // Report unsupported specification, if there are any precondition violations. - if (!violations.isEmpty()) { - List messages = violations.stream().map(v -> "Unsupported " + v.toString()) + if (violations.hasViolations()) { + List messages = violations.getViolations().map(v -> "Unsupported " + v.toString()) .collect(Collectors.toList()); Collections.sort(messages, Strings.SORTER); String msg = toolName + " failed due to unsatisfied preconditions:\n - " + String.join("\n - ", messages); diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoChannelsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoChannelsCheck.java index 0a02a8b5c..37bd93d1a 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoChannelsCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoChannelsCheck.java @@ -18,9 +18,9 @@ import org.eclipse.escet.cif.metamodel.cif.declarations.Event; /** CIF check that does not allow channels. */ public class NoChannelsCheck extends CifCheck { @Override - protected void preprocessEvent(Event event) { + protected void preprocessEvent(Event event, CifCheckViolations violations) { if (event.getType() != null) { - addViolation(event, "event is a channel (has a data type)"); + violations.add(event, "event is a channel (has a data type)"); } } } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoContinuousVariablesCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoContinuousVariablesCheck.java index 7dbe9ffdf..19d3f9713 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoContinuousVariablesCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoContinuousVariablesCheck.java @@ -18,7 +18,7 @@ import org.eclipse.escet.cif.metamodel.cif.declarations.ContVariable; /** CIF check that does not allow continuous variables. */ public class NoContinuousVariablesCheck extends CifCheck { @Override - protected void preprocessContVariable(ContVariable var) { - addViolation(var, "variable is a continuous variable"); + protected void preprocessContVariable(ContVariable var, CifCheckViolations violations) { + violations.add(var, "variable is a continuous variable"); } } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoDiscVarsWithMultiInitValuesCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoDiscVarsWithMultiInitValuesCheck.java index 63ef98288..7dd1f18c1 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoDiscVarsWithMultiInitValuesCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoDiscVarsWithMultiInitValuesCheck.java @@ -22,7 +22,7 @@ import org.eclipse.escet.cif.metamodel.cif.declarations.DiscVariable; /** CIF check that does not allow discrete variables with multiple potential initial values. */ public class NoDiscVarsWithMultiInitValuesCheck extends CifCheck { @Override - protected void preprocessDiscVariable(DiscVariable var) { + protected void preprocessDiscVariable(DiscVariable var, CifCheckViolations violations) { // Ignore discrete variables that represent function parameters or local variables of functions. EObject parent = var.eContainer(); if (!(parent instanceof ComplexComponent)) { @@ -37,9 +37,9 @@ public class NoDiscVarsWithMultiInitValuesCheck extends CifCheck { // Check number of potential initial values. int count = var.getValue().getValues().size(); if (count == 0) { // 0 means 'any' initial value. - addViolation(var, "discrete variable has multiple potential initial values (any value in its domain)"); + violations.add(var, "discrete variable has multiple potential initial values (any value in its domain)"); } else if (count > 1) { - addViolation(var, fmt("discrete variable has multiple (%d) potential initial values", count)); + violations.add(var, fmt("discrete variable has multiple (%d) potential initial values", count)); } } } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoIfUpdatesOnEdgesCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoIfUpdatesOnEdgesCheck.java index 5bc6a464b..b2175cb38 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoIfUpdatesOnEdgesCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoIfUpdatesOnEdgesCheck.java @@ -26,7 +26,7 @@ import org.eclipse.escet.common.java.Assert; */ public class NoIfUpdatesOnEdgesCheck extends CifCheck { @Override - protected void preprocessIfUpdate(IfUpdate update) { + protected void preprocessIfUpdate(IfUpdate update, CifCheckViolations violations) { // Get location. EObject ancestor = update; while (!(ancestor instanceof Location)) { @@ -37,9 +37,9 @@ public class NoIfUpdatesOnEdgesCheck extends CifCheck { // Report violation. if (loc.getName() != null) { - addViolation(loc, "location has an edge with an 'if' update"); + violations.add(loc, "location has an edge with an 'if' update"); } else { - addViolation((Automaton)loc.eContainer(), "automaton has an edge with an 'if' update"); + violations.add((Automaton)loc.eContainer(), "automaton has an edge with an 'if' update"); } } } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoInitPredsInCompsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoInitPredsInCompsCheck.java index f5bd91c67..36599fc51 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoInitPredsInCompsCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoInitPredsInCompsCheck.java @@ -21,9 +21,9 @@ import org.eclipse.escet.cif.metamodel.cif.ComplexComponent; */ public class NoInitPredsInCompsCheck extends CifCheck { @Override - protected void preprocessComplexComponent(ComplexComponent comp) { + protected void preprocessComplexComponent(ComplexComponent comp, CifCheckViolations violations) { if (!comp.getInitials().isEmpty()) { - addViolation(comp, "component contains an initialization predicate"); + violations.add(comp, "component contains an initialization predicate"); } } } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoInputVariablesCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoInputVariablesCheck.java index e20806be8..093a8d2cd 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoInputVariablesCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoInputVariablesCheck.java @@ -18,7 +18,7 @@ import org.eclipse.escet.cif.metamodel.cif.declarations.InputVariable; /** CIF check that does not allow input variables. */ public class NoInputVariablesCheck extends CifCheck { @Override - protected void preprocessInputVariable(InputVariable var) { - addViolation(var, "variable is an input variable"); + protected void preprocessInputVariable(InputVariable var, CifCheckViolations violations) { + violations.add(var, "variable is an input variable"); } } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoKindlessAutomataCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoKindlessAutomataCheck.java index 9de417766..d44288825 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoKindlessAutomataCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoKindlessAutomataCheck.java @@ -19,9 +19,9 @@ import org.eclipse.escet.cif.metamodel.cif.automata.Automaton; /** CIF check that does not allow kindless automata (without a supervisory kind). */ public class NoKindlessAutomataCheck extends CifCheck { @Override - protected void preprocessAutomaton(Automaton aut) { + protected void preprocessAutomaton(Automaton aut, CifCheckViolations violations) { if (aut.getKind() == SupKind.NONE) { - addViolation(aut, "automaton is a kindless automaton, lacking a supervisory kind"); + violations.add(aut, "automaton is a kindless automaton, lacking a supervisory kind"); } } } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoKindlessStateEvtExclInvsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoKindlessStateEvtExclInvsCheck.java index 5ca70de60..1fa502d1b 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoKindlessStateEvtExclInvsCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoKindlessStateEvtExclInvsCheck.java @@ -23,12 +23,12 @@ import org.eclipse.escet.cif.metamodel.cif.automata.Location; /** CIF check that does not allow kindless state/event exclusion invariants (without a supervisory kind). */ public class NoKindlessStateEvtExclInvsCheck extends CifCheck { @Override - protected void preprocessComplexComponent(ComplexComponent comp) { + protected void preprocessComplexComponent(ComplexComponent comp, CifCheckViolations violations) { for (Invariant inv: comp.getInvariants()) { if (inv.getInvKind() == InvKind.EVENT_NEEDS || inv.getInvKind() == InvKind.EVENT_DISABLES) { SupKind supKind = inv.getSupKind(); if (supKind == SupKind.NONE) { - addViolation(comp, + violations.add(comp, "component has a kindless state/event exclusion invariant, lacking a supervisory kind"); } } @@ -36,16 +36,16 @@ public class NoKindlessStateEvtExclInvsCheck extends CifCheck { } @Override - protected void preprocessLocation(Location loc) { + protected void preprocessLocation(Location loc, CifCheckViolations violations) { for (Invariant inv: loc.getInvariants()) { if (inv.getInvKind() == InvKind.EVENT_NEEDS || inv.getInvKind() == InvKind.EVENT_DISABLES) { SupKind supKind = inv.getSupKind(); if (supKind == SupKind.NONE) { if (loc.getName() != null) { - addViolation(loc, + violations.add(loc, "location has a kindless state/event exclusion invariant, lacking a supervisory kind"); } else { - addViolation((Automaton)loc.eContainer(), + violations.add((Automaton)loc.eContainer(), "automaton has a location with a kindless state/event exclusion invariant, " + "lacking a supervisory kind"); } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoMultiAssignOnEdgesCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoMultiAssignOnEdgesCheck.java index c69f149d4..792990b92 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoMultiAssignOnEdgesCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoMultiAssignOnEdgesCheck.java @@ -28,7 +28,7 @@ import org.eclipse.escet.common.java.Assert; */ public class NoMultiAssignOnEdgesCheck extends CifCheck { @Override - protected void preprocessAssignment(Assignment asgn) { + protected void preprocessAssignment(Assignment asgn, CifCheckViolations violations) { if (asgn.getAddressable() instanceof TupleExpression) { // Get location. EObject ancestor = asgn; @@ -40,9 +40,9 @@ public class NoMultiAssignOnEdgesCheck extends CifCheck { // Report violation. if (loc.getName() != null) { - addViolation(loc, "location has an edge with a multi-assignment"); + violations.add(loc, "location has an edge with a multi-assignment"); } else { - addViolation((Automaton)loc.eContainer(), "automaton has an edge with a multi-assignment"); + violations.add((Automaton)loc.eContainer(), "automaton has an edge with a multi-assignment"); } } } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoPartialVarAssignOnEdgesCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoPartialVarAssignOnEdgesCheck.java index 7818f7619..d54a81bd5 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoPartialVarAssignOnEdgesCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoPartialVarAssignOnEdgesCheck.java @@ -27,7 +27,7 @@ import org.eclipse.escet.common.java.Assert; */ public class NoPartialVarAssignOnEdgesCheck extends CifCheck { @Override - protected void preprocessAssignment(Assignment asgn) { + protected void preprocessAssignment(Assignment asgn, CifCheckViolations violations) { if (asgn.getAddressable() instanceof ProjectionExpression) { // Get location. EObject ancestor = asgn; @@ -39,9 +39,9 @@ public class NoPartialVarAssignOnEdgesCheck extends CifCheck { // Report violation. if (loc.getName() != null) { - addViolation(loc, "location has an edge with a partial variable assignment"); + violations.add(loc, "location has an edge with a partial variable assignment"); } else { - addViolation((Automaton)loc.eContainer(), "automaton has an edge with a partial variable assignment"); + violations.add((Automaton)loc.eContainer(), "automaton has an edge with a partial variable assignment"); } } } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificBinaryExprsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificBinaryExprsCheck.java index 89ae1bf97..4a8321dbf 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificBinaryExprsCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificBinaryExprsCheck.java @@ -47,359 +47,359 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { } @Override - protected void preprocessBinaryExpression(BinaryExpression binExpr) { + protected void preprocessBinaryExpression(BinaryExpression binExpr, CifCheckViolations violations) { BinaryOperator op = binExpr.getOperator(); CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); switch (op) { case ADDITION: if (disalloweds.contains(NoSpecificBinaryOp.ADDITION)) { - addExprViolationOperator(binExpr); + addExprViolationOperator(binExpr, violations); } else { if (disalloweds.contains(NoSpecificBinaryOp.ADDITION_INTS)) { if (ltype instanceof IntType || rtype instanceof IntType) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } } else { if (disalloweds.contains(NoSpecificBinaryOp.ADDITION_INTS_RANGED) && ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype)))) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } if (disalloweds.contains(NoSpecificBinaryOp.ADDITION_INTS_RANGELESS) && ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype)))) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } } if (disalloweds.contains(NoSpecificBinaryOp.ADDITION_REALS) && (ltype instanceof RealType || rtype instanceof RealType)) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } if (disalloweds.contains(NoSpecificBinaryOp.ADDITION_LISTS) && (ltype instanceof ListType || rtype instanceof ListType)) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } if (disalloweds.contains(NoSpecificBinaryOp.ADDITION_STRINGS) && (ltype instanceof StringType || rtype instanceof StringType)) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } if (disalloweds.contains(NoSpecificBinaryOp.ADDITION_DICTS) && (ltype instanceof DictType || rtype instanceof DictType)) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } } break; case BI_CONDITIONAL: if (disalloweds.contains(NoSpecificBinaryOp.BI_CONDITIONAL)) { - addExprViolationOperator(binExpr); + addExprViolationOperator(binExpr, violations); } break; case CONJUNCTION: if (disalloweds.contains(NoSpecificBinaryOp.CONJUNCTION)) { - addExprViolationOperator(binExpr); + addExprViolationOperator(binExpr, violations); } else if (disalloweds.contains(NoSpecificBinaryOp.CONJUNCTION_SETS) && (ltype instanceof SetType || rtype instanceof SetType)) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } break; case DISJUNCTION: if (disalloweds.contains(NoSpecificBinaryOp.DISJUNCTION)) { - addExprViolationOperator(binExpr); + addExprViolationOperator(binExpr, violations); } else if (disalloweds.contains(NoSpecificBinaryOp.DISJUNCTION_SETS) && (ltype instanceof SetType || rtype instanceof SetType)) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } break; case DIVISION: if (disalloweds.contains(NoSpecificBinaryOp.DIVISION)) { - addExprViolationOperator(binExpr); + addExprViolationOperator(binExpr, violations); } break; case ELEMENT_OF: if (disalloweds.contains(NoSpecificBinaryOp.ELEMENT_OF)) { - addExprViolationOperator(binExpr); + addExprViolationOperator(binExpr, violations); } else { if (disalloweds.contains(NoSpecificBinaryOp.ELEMENT_OF_LISTS) && (ltype instanceof ListType || rtype instanceof ListType)) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } if (disalloweds.contains(NoSpecificBinaryOp.ELEMENT_OF_SETS) && (ltype instanceof SetType || rtype instanceof SetType)) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } if (disalloweds.contains(NoSpecificBinaryOp.ELEMENT_OF_DICTS) && (ltype instanceof DictType || rtype instanceof DictType)) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } } break; case EQUAL: if (disalloweds.contains(NoSpecificBinaryOp.EQUAL)) { - addExprViolationOperator(binExpr); + addExprViolationOperator(binExpr, violations); } break; case GREATER_EQUAL: if (disalloweds.contains(NoSpecificBinaryOp.GREATER_EQUAL)) { - addExprViolationOperator(binExpr); + addExprViolationOperator(binExpr, violations); } else { if (disalloweds.contains(NoSpecificBinaryOp.GREATER_EQUAL_INTS)) { if (ltype instanceof IntType || rtype instanceof IntType) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } } else { if (disalloweds.contains(NoSpecificBinaryOp.GREATER_EQUAL_INTS_RANGED) && ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype)))) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } if (disalloweds.contains(NoSpecificBinaryOp.GREATER_EQUAL_INTS_RANGELESS) && ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype)))) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } } if (disalloweds.contains(NoSpecificBinaryOp.GREATER_EQUAL_REALS) && (ltype instanceof RealType || rtype instanceof RealType)) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } } break; case GREATER_THAN: if (disalloweds.contains(NoSpecificBinaryOp.GREATER_THAN)) { - addExprViolationOperator(binExpr); + addExprViolationOperator(binExpr, violations); } else { if (disalloweds.contains(NoSpecificBinaryOp.GREATER_THAN_INTS)) { if (ltype instanceof IntType || rtype instanceof IntType) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } } else { if (disalloweds.contains(NoSpecificBinaryOp.GREATER_THAN_INTS_RANGED) && ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype)))) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } if (disalloweds.contains(NoSpecificBinaryOp.GREATER_THAN_INTS_RANGELESS) && ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype)))) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } } if (disalloweds.contains(NoSpecificBinaryOp.GREATER_THAN_REALS) && (ltype instanceof RealType || rtype instanceof RealType)) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } } break; case IMPLICATION: if (disalloweds.contains(NoSpecificBinaryOp.IMPLICATION)) { - addExprViolationOperator(binExpr); + addExprViolationOperator(binExpr, violations); } break; case INTEGER_DIVISION: if (disalloweds.contains(NoSpecificBinaryOp.INTEGER_DIVISION)) { - addExprViolationOperator(binExpr); + addExprViolationOperator(binExpr, violations); } else { if (disalloweds.contains(NoSpecificBinaryOp.INTEGER_DIVISION_INTS)) { if (ltype instanceof IntType || rtype instanceof IntType) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } } else { if (disalloweds.contains(NoSpecificBinaryOp.INTEGER_DIVISION_INTS_RANGED) && ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype)))) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } if (disalloweds.contains(NoSpecificBinaryOp.INTEGER_DIVISION_INTS_RANGELESS) && ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype)))) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } } } break; case LESS_EQUAL: if (disalloweds.contains(NoSpecificBinaryOp.LESS_EQUAL)) { - addExprViolationOperator(binExpr); + addExprViolationOperator(binExpr, violations); } else { if (disalloweds.contains(NoSpecificBinaryOp.LESS_EQUAL_INTS)) { if (ltype instanceof IntType || rtype instanceof IntType) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } } else { if (disalloweds.contains(NoSpecificBinaryOp.LESS_EQUAL_INTS_RANGED) && ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype)))) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } if (disalloweds.contains(NoSpecificBinaryOp.LESS_EQUAL_INTS_RANGELESS) && ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype)))) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } } if (disalloweds.contains(NoSpecificBinaryOp.LESS_EQUAL_REALS) && (ltype instanceof RealType || rtype instanceof RealType)) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } } break; case LESS_THAN: if (disalloweds.contains(NoSpecificBinaryOp.LESS_THAN)) { - addExprViolationOperator(binExpr); + addExprViolationOperator(binExpr, violations); } else { if (disalloweds.contains(NoSpecificBinaryOp.LESS_THAN_INTS)) { if (ltype instanceof IntType || rtype instanceof IntType) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } } else { if (disalloweds.contains(NoSpecificBinaryOp.LESS_THAN_INTS_RANGED) && ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype)))) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } if (disalloweds.contains(NoSpecificBinaryOp.LESS_THAN_INTS_RANGELESS) && ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype)))) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } } if (disalloweds.contains(NoSpecificBinaryOp.LESS_THAN_REALS) && (ltype instanceof RealType || rtype instanceof RealType)) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } } break; case MODULUS: if (disalloweds.contains(NoSpecificBinaryOp.MODULUS)) { - addExprViolationOperator(binExpr); + addExprViolationOperator(binExpr, violations); } else { if (disalloweds.contains(NoSpecificBinaryOp.MODULUS_INTS)) { if (ltype instanceof IntType || rtype instanceof IntType) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } } else { if (disalloweds.contains(NoSpecificBinaryOp.MODULUS_INTS_RANGED) && ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype)))) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } if (disalloweds.contains(NoSpecificBinaryOp.MODULUS_INTS_RANGELESS) && ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype)))) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } } } break; case MULTIPLICATION: if (disalloweds.contains(NoSpecificBinaryOp.MULTIPLICATION)) { - addExprViolationOperator(binExpr); + addExprViolationOperator(binExpr, violations); } else { if (disalloweds.contains(NoSpecificBinaryOp.MULTIPLICATION_INTS)) { if (ltype instanceof IntType || rtype instanceof IntType) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } } else { if (disalloweds.contains(NoSpecificBinaryOp.MULTIPLICATION_INTS_RANGED) && ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype)))) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } if (disalloweds.contains(NoSpecificBinaryOp.MULTIPLICATION_INTS_RANGELESS) && ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype)))) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } } if (disalloweds.contains(NoSpecificBinaryOp.MULTIPLICATION_REALS) && (ltype instanceof RealType || rtype instanceof RealType)) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } } break; case SUBSET: if (disalloweds.contains(NoSpecificBinaryOp.SUBSET)) { - addExprViolationOperator(binExpr); + addExprViolationOperator(binExpr, violations); } break; case SUBTRACTION: if (disalloweds.contains(NoSpecificBinaryOp.SUBTRACTION)) { - addExprViolationOperator(binExpr); + addExprViolationOperator(binExpr, violations); } else { if (disalloweds.contains(NoSpecificBinaryOp.SUBTRACTION_INTS)) { if (ltype instanceof IntType || rtype instanceof IntType) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } } else { if (disalloweds.contains(NoSpecificBinaryOp.SUBTRACTION_INTS_RANGED) && ((ltype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && !CifTypeUtils.isRangeless((IntType)rtype)))) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } if (disalloweds.contains(NoSpecificBinaryOp.SUBTRACTION_INTS_RANGELESS) && ((ltype instanceof IntType && CifTypeUtils.isRangeless((IntType)ltype)) || (rtype instanceof IntType && CifTypeUtils.isRangeless((IntType)rtype)))) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } } if (disalloweds.contains(NoSpecificBinaryOp.SUBTRACTION_REALS) && (ltype instanceof RealType || rtype instanceof RealType)) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } if (disalloweds.contains(NoSpecificBinaryOp.SUBTRACTION_LISTS) && (ltype instanceof ListType || rtype instanceof ListType)) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } if (disalloweds.contains(NoSpecificBinaryOp.SUBTRACTION_SETS) && (ltype instanceof SetType || rtype instanceof SetType)) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } if (disalloweds.contains(NoSpecificBinaryOp.SUBTRACTION_DICTS) && (ltype instanceof DictType || rtype instanceof DictType)) { - addExprViolationOperand(binExpr); + addExprViolationOperand(binExpr, violations); } } break; case UNEQUAL: if (disalloweds.contains(NoSpecificBinaryOp.UNEQUAL)) { - addExprViolationOperator(binExpr); + addExprViolationOperator(binExpr, violations); } break; default: @@ -411,22 +411,23 @@ public class NoSpecificBinaryExprsCheck extends CifCheck { * Add a violation for the operator of the given binary expression. * * @param binExpr The binary expression. + * @param violations The violations collected so far. Is modified in-place. */ - private void addExprViolationOperator(BinaryExpression binExpr) { - super.addViolation(getNamedSelfOrAncestor(binExpr), - fmt("uses binary operator \"%s\" in binary expression \"%s\"", operatorToStr(binExpr.getOperator()), - exprToStr(binExpr))); + private void addExprViolationOperator(BinaryExpression binExpr, CifCheckViolations violations) { + violations.add(getNamedSelfOrAncestor(binExpr), fmt("uses binary operator \"%s\" in binary expression \"%s\"", + operatorToStr(binExpr.getOperator()), exprToStr(binExpr))); } /** * Add a violation for an operand of the the given binary expression. * * @param binExpr The binary expression. + * @param violations The violations collected so far. Is modified in-place. */ - private void addExprViolationOperand(BinaryExpression binExpr) { + private void addExprViolationOperand(BinaryExpression binExpr, CifCheckViolations violations) { CifType ltype = CifTypeUtils.normalizeType(binExpr.getLeft().getType()); CifType rtype = CifTypeUtils.normalizeType(binExpr.getRight().getType()); - super.addViolation(getNamedSelfOrAncestor(binExpr), + violations.add(getNamedSelfOrAncestor(binExpr), fmt("uses binary operator \"%s\" on operands of types \"%s\" and \"%s\" in binary expression \"%s\"", operatorToStr(binExpr.getOperator()), typeToStr(ltype), typeToStr(rtype), exprToStr(binExpr))); } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificExprsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificExprsCheck.java index be7ddcf1a..c5d70163f 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificExprsCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificExprsCheck.java @@ -64,7 +64,6 @@ import org.eclipse.escet.cif.metamodel.cif.types.IntType; import org.eclipse.escet.cif.metamodel.cif.types.ListType; import org.eclipse.escet.cif.metamodel.cif.types.StringType; import org.eclipse.escet.cif.metamodel.cif.types.TupleType; -import org.eclipse.escet.common.position.metamodel.position.PositionObject; /** CIF check that does not allow certain expressions. */ public class NoSpecificExprsCheck extends CifCheck { @@ -81,54 +80,56 @@ public class NoSpecificExprsCheck extends CifCheck { } @Override - protected void preprocessAlgVariableExpression(AlgVariableExpression algRef) { + protected void preprocessAlgVariableExpression(AlgVariableExpression algRef, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificExpr.ALG_VAR_REFS)) { - addExprViolation(algRef, "algebraic variable reference"); + addExprViolation(algRef, "algebraic variable reference", violations); } } @Override - protected void preprocessFunctionExpression(FunctionExpression userDefFuncRef) { + protected void preprocessFunctionExpression(FunctionExpression userDefFuncRef, CifCheckViolations violations) { if ((disalloweds.contains(NoSpecificExpr.FUNC_REFS) || disalloweds.contains(NoSpecificExpr.FUNC_REFS_USER_DEF) || disalloweds.contains(NoSpecificExpr.FUNC_REFS_USER_DEF_INT)) && userDefFuncRef.getFunction() instanceof InternalFunction) { - addExprViolation(userDefFuncRef, "internal user-defined function reference"); + addExprViolation(userDefFuncRef, "internal user-defined function reference", violations); } if ((disalloweds.contains(NoSpecificExpr.FUNC_REFS) || disalloweds.contains(NoSpecificExpr.FUNC_REFS_USER_DEF) || disalloweds.contains(NoSpecificExpr.FUNC_REFS_USER_DEF_EXT)) && userDefFuncRef.getFunction() instanceof ExternalFunction) { - addExprViolation(userDefFuncRef, "external user-defined function reference"); + addExprViolation(userDefFuncRef, "external user-defined function reference", violations); } } @Override - protected void preprocessStdLibFunctionExpression(StdLibFunctionExpression stdLibRef) { + protected void preprocessStdLibFunctionExpression(StdLibFunctionExpression stdLibRef, + CifCheckViolations violations) + { if (disalloweds.contains(NoSpecificExpr.FUNC_REFS) || disalloweds.contains(NoSpecificExpr.FUNC_REFS_STD_LIB)) { - addExprViolation(stdLibRef, "standard library function reference"); + addExprViolation(stdLibRef, "standard library function reference", violations); } } @Override - protected void preprocessBinaryExpression(BinaryExpression binExpr) { + protected void preprocessBinaryExpression(BinaryExpression binExpr, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificExpr.BINARY_EXPRS)) { - addExprViolation(binExpr, "binary expression"); + addExprViolation(binExpr, "binary expression", violations); } } @Override - protected void preprocessBoolExpression(BoolExpression boolLit) { + protected void preprocessBoolExpression(BoolExpression boolLit, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificExpr.BOOL_LITS)) { - addExprViolation(boolLit, "boolean literal"); + addExprViolation(boolLit, "boolean literal", violations); } } @Override - protected void preprocessCastExpression(CastExpression castExpr) { + protected void preprocessCastExpression(CastExpression castExpr, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificExpr.CAST_EXPRS)) { - addExprViolation(castExpr, "cast expression"); + addExprViolation(castExpr, "cast expression", violations); } else if (disalloweds.contains(NoSpecificExpr.CAST_EXPRS_NON_EQUAL_TYPE)) { CifType ctype = castExpr.getChild().getType(); CifType rtype = castExpr.getType(); @@ -136,59 +137,59 @@ public class NoSpecificExprsCheck extends CifCheck { // Ignore casting to the child type. return; } - addExprViolation(castExpr, "type-changing cast expression"); + addExprViolation(castExpr, "type-changing cast expression", violations); } } @Override - protected void preprocessComponentExpression(ComponentExpression compRef) { + protected void preprocessComponentExpression(ComponentExpression compRef, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificExpr.COMP_REFS) || disalloweds.contains(NoSpecificExpr.COMP_REFS_EXPLICIT)) { - addExprViolation(compRef, "component reference"); + addExprViolation(compRef, "component reference", violations); } } @Override - protected void preprocessCompParamExpression(CompParamExpression compParamRef) { + protected void preprocessCompParamExpression(CompParamExpression compParamRef, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificExpr.COMP_PARAM_REFS)) { - addExprViolation(compParamRef, "component parameter reference"); + addExprViolation(compParamRef, "component parameter reference", violations); } } @Override - protected void preprocessConstantExpression(ConstantExpression constRef) { + protected void preprocessConstantExpression(ConstantExpression constRef, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificExpr.CONST_REFS)) { - addExprViolation(constRef, "constant reference"); + addExprViolation(constRef, "constant reference", violations); } } @Override - protected void preprocessContVariableExpression(ContVariableExpression contRef) { + protected void preprocessContVariableExpression(ContVariableExpression contRef, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificExpr.CONT_VAR_REFS)) { - addExprViolation(contRef, "continuous variable reference"); + addExprViolation(contRef, "continuous variable reference", violations); } } @Override - protected void preprocessDictExpression(DictExpression dictLit) { + protected void preprocessDictExpression(DictExpression dictLit, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificExpr.DICT_LITS)) { - addExprViolation(dictLit, "dictionary literal"); + addExprViolation(dictLit, "dictionary literal", violations); } } @Override - protected void preprocessDiscVariableExpression(DiscVariableExpression discRef) { + protected void preprocessDiscVariableExpression(DiscVariableExpression discRef, CifCheckViolations violations) { EObject parent = discRef.getVariable().eContainer(); if (parent instanceof ComplexComponent) { if (disalloweds.contains(NoSpecificExpr.DISC_VAR_REFS)) { - addExprViolation(discRef, "discrete variable reference"); + addExprViolation(discRef, "discrete variable reference", violations); } } else if (parent instanceof FunctionParameter) { if (disalloweds.contains(NoSpecificExpr.USER_DEF_FUNC_PARAM_REFS)) { - addExprViolation(discRef, "user-defined function parameter reference"); + addExprViolation(discRef, "user-defined function parameter reference", violations); } } else if (parent instanceof InternalFunction) { if (disalloweds.contains(NoSpecificExpr.INT_USER_DEF_FUNC_LOCAL_VAR_REFS)) { - addExprViolation(discRef, "internal user-defined function local variable reference"); + addExprViolation(discRef, "internal user-defined function local variable reference", violations); } } else { throw new RuntimeException("Unexpected disc var parent: " + parent); @@ -196,101 +197,101 @@ public class NoSpecificExprsCheck extends CifCheck { } @Override - protected void preprocessEnumLiteralExpression(EnumLiteralExpression enumLitRef) { + protected void preprocessEnumLiteralExpression(EnumLiteralExpression enumLitRef, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificExpr.ENUM_LIT_REFS)) { - addExprViolation(enumLitRef, "enumeration literal reference"); + addExprViolation(enumLitRef, "enumeration literal reference", violations); } } @Override - protected void preprocessFieldExpression(FieldExpression fieldRef) { + protected void preprocessFieldExpression(FieldExpression fieldRef, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificExpr.TUPLE_FIELD_REFS)) { - addExprViolation(fieldRef, "tuple field reference"); + addExprViolation(fieldRef, "tuple field reference", violations); } } @Override - protected void preprocessFunctionCallExpression(FunctionCallExpression funcCall) { + protected void preprocessFunctionCallExpression(FunctionCallExpression funcCall, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificExpr.FUNC_CALLS)) { - addExprViolation(funcCall, "function call"); + addExprViolation(funcCall, "function call", violations); } } @Override - protected void preprocessIfExpression(IfExpression ifExpr) { + protected void preprocessIfExpression(IfExpression ifExpr, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificExpr.IF_EXPRS)) { - addExprViolation(ifExpr, "conditional expression"); + addExprViolation(ifExpr, "conditional expression", violations); } } @Override - protected void preprocessInputVariableExpression(InputVariableExpression inputRef) { + protected void preprocessInputVariableExpression(InputVariableExpression inputRef, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificExpr.INPUT_VAR_REFS)) { - addExprViolation(inputRef, "input variable reference"); + addExprViolation(inputRef, "input variable reference", violations); } } @Override - protected void preprocessIntExpression(IntExpression intLit) { + protected void preprocessIntExpression(IntExpression intLit, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificExpr.INT_LITS)) { - addExprViolation(intLit, "integer number literal"); + addExprViolation(intLit, "integer number literal", violations); } } @Override - protected void preprocessListExpression(ListExpression listLit) { + protected void preprocessListExpression(ListExpression listLit, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificExpr.LIST_LITS)) { - addExprViolation(listLit, "list literal"); + addExprViolation(listLit, "list literal", violations); } } @Override - protected void preprocessLocationExpression(LocationExpression locRef) { + protected void preprocessLocationExpression(LocationExpression locRef, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificExpr.LOC_REFS)) { - addExprViolation(locRef, "location reference"); + addExprViolation(locRef, "location reference", violations); } } @Override - protected void preprocessProjectionExpression(ProjectionExpression projExpr) { + protected void preprocessProjectionExpression(ProjectionExpression projExpr, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificExpr.PROJECTION_EXPRS)) { - addExprViolation(projExpr, "projection expression"); + addExprViolation(projExpr, "projection expression", violations); } else { if (disalloweds.contains(NoSpecificExpr.PROJECTION_EXPRS_LISTS)) { CifType ctype = CifTypeUtils.normalizeType(projExpr.getChild().getType()); if (ctype instanceof ListType) { - addExprViolation(projExpr, "list projection expression"); + addExprViolation(projExpr, "list projection expression", violations); } } if (disalloweds.contains(NoSpecificExpr.PROJECTION_EXPRS_DICTS)) { CifType ctype = CifTypeUtils.normalizeType(projExpr.getChild().getType()); if (ctype instanceof DictType) { - addExprViolation(projExpr, "dictionary projection expression"); + addExprViolation(projExpr, "dictionary projection expression", violations); } } if (disalloweds.contains(NoSpecificExpr.PROJECTION_EXPRS_STRINGS)) { CifType ctype = CifTypeUtils.normalizeType(projExpr.getChild().getType()); if (ctype instanceof StringType) { - addExprViolation(projExpr, "string projection expression"); + addExprViolation(projExpr, "string projection expression", violations); } } if (disalloweds.contains(NoSpecificExpr.PROJECTION_EXPRS_TUPLES)) { CifType ctype = CifTypeUtils.normalizeType(projExpr.getChild().getType()); if (ctype instanceof TupleType) { - addExprViolation(projExpr, "tuple projection expression"); + addExprViolation(projExpr, "tuple projection expression", violations); } } else { if (disalloweds.contains(NoSpecificExpr.PROJECTION_EXPRS_TUPLES_INDEX)) { CifType ctype = CifTypeUtils.normalizeType(projExpr.getChild().getType()); CifType itype = CifTypeUtils.normalizeType(projExpr.getIndex().getType()); if (ctype instanceof TupleType && itype instanceof IntType) { - addExprViolation(projExpr, "tuple index-projection expression"); + addExprViolation(projExpr, "tuple index-projection expression", violations); } } if (disalloweds.contains(NoSpecificExpr.PROJECTION_EXPRS_TUPLES_FIELD)) { CifType ctype = CifTypeUtils.normalizeType(projExpr.getChild().getType()); if (ctype instanceof TupleType && projExpr.getIndex() instanceof FieldExpression) { - addExprViolation(projExpr, "tuple field-projection expression"); + addExprViolation(projExpr, "tuple field-projection expression", violations); } } } @@ -298,88 +299,84 @@ public class NoSpecificExprsCheck extends CifCheck { } @Override - protected void preprocessRealExpression(RealExpression realLit) { + protected void preprocessRealExpression(RealExpression realLit, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificExpr.REAL_LITS)) { - addExprViolation(realLit, "real number literal"); + addExprViolation(realLit, "real number literal", violations); } } @Override - protected void preprocessReceivedExpression(ReceivedExpression receivedExpr) { + protected void preprocessReceivedExpression(ReceivedExpression receivedExpr, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificExpr.RECEIVE_EXPRS)) { - addExprViolation(receivedExpr, "received value expression"); + addExprViolation(receivedExpr, "received value expression", violations); } } @Override - protected void preprocessSelfExpression(SelfExpression selfRef) { + protected void preprocessSelfExpression(SelfExpression selfRef, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificExpr.COMP_REFS) || disalloweds.contains(NoSpecificExpr.COMP_REFS_SELF)) { - addExprViolation(selfRef, "component reference"); + addExprViolation(selfRef, "component reference", violations); } } @Override - protected void preprocessSetExpression(SetExpression setLit) { + protected void preprocessSetExpression(SetExpression setLit, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificExpr.SET_LITS)) { - addExprViolation(setLit, "set literal"); + addExprViolation(setLit, "set literal", violations); } } @Override - protected void preprocessSliceExpression(SliceExpression sliceExpr) { + protected void preprocessSliceExpression(SliceExpression sliceExpr, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificExpr.SLICE_EXPRS)) { - addExprViolation(sliceExpr, "slice expression"); + addExprViolation(sliceExpr, "slice expression", violations); } } @Override - protected void preprocessStringExpression(StringExpression stringLit) { + protected void preprocessStringExpression(StringExpression stringLit, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificExpr.STRING_LITS)) { - addExprViolation(stringLit, "string literal"); + addExprViolation(stringLit, "string literal", violations); } } @Override - protected void preprocessSwitchExpression(SwitchExpression switchExpr) { + protected void preprocessSwitchExpression(SwitchExpression switchExpr, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificExpr.SWITCH_EXPRS)) { - addExprViolation(switchExpr, "switch expression"); + addExprViolation(switchExpr, "switch expression", violations); } } @Override - protected void preprocessTimeExpression(TimeExpression timeRef) { + protected void preprocessTimeExpression(TimeExpression timeRef, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificExpr.TIME_VAR_REFS)) { - addExprViolation(timeRef, "time variable reference"); + addExprViolation(timeRef, "time variable reference", violations); } } @Override - protected void preprocessTupleExpression(TupleExpression tupleLit) { + protected void preprocessTupleExpression(TupleExpression tupleLit, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificExpr.TUPLE_LITS)) { - addExprViolation(tupleLit, "tuple literal"); + addExprViolation(tupleLit, "tuple literal", violations); } } @Override - protected void preprocessUnaryExpression(UnaryExpression unExpr) { + protected void preprocessUnaryExpression(UnaryExpression unExpr, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificExpr.UNARY_EXPRS)) { - addExprViolation(unExpr, "unary expression"); + addExprViolation(unExpr, "unary expression", violations); } } - @Override - protected void addViolation(PositionObject exprObj, String message) { - throw new UnsupportedOperationException(); // Use addExprViolation. - } - /** * Add a violation for the given expression. * * @param expr The expression. * @param description The description of the expression. + * @param violations The violations collected so far. Is modified in-place. */ - private void addExprViolation(Expression expr, String description) { - super.addViolation(getNamedSelfOrAncestor(expr), fmt("uses %s \"%s\"", description, exprToStr(expr))); + private void addExprViolation(Expression expr, String description, CifCheckViolations violations) { + violations.add(getNamedSelfOrAncestor(expr), fmt("uses %s \"%s\"", description, exprToStr(expr))); } /** The expression to disallow. */ diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificTypesCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificTypesCheck.java index 276327870..38f65d375 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificTypesCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificTypesCheck.java @@ -34,7 +34,6 @@ import org.eclipse.escet.cif.metamodel.cif.types.SetType; import org.eclipse.escet.cif.metamodel.cif.types.StringType; import org.eclipse.escet.cif.metamodel.cif.types.TupleType; import org.eclipse.escet.cif.metamodel.cif.types.VoidType; -import org.eclipse.escet.common.position.metamodel.position.PositionObject; /** CIF check that does not allow certain types. */ public class NoSpecificTypesCheck extends CifCheck { @@ -51,113 +50,109 @@ public class NoSpecificTypesCheck extends CifCheck { } @Override - protected void preprocessComponentDefType(ComponentDefType compDefType) { + protected void preprocessComponentDefType(ComponentDefType compDefType, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificType.COMP_DEF_TYPES)) { - addTypeViolation(compDefType, "component definition type"); + addTypeViolation(compDefType, "component definition type", violations); } } @Override - protected void preprocessComponentType(ComponentType compType) { + protected void preprocessComponentType(ComponentType compType, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificType.COMP_TYPES)) { - addTypeViolation(compType, "component type"); + addTypeViolation(compType, "component type", violations); } } @Override - protected void preprocessDictType(DictType dictType) { + protected void preprocessDictType(DictType dictType, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificType.DICT_TYPES)) { - addTypeViolation(dictType, "dictionary type"); + addTypeViolation(dictType, "dictionary type", violations); } } @Override - protected void preprocessDistType(DistType distType) { + protected void preprocessDistType(DistType distType, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificType.DIST_TYPES)) { - addTypeViolation(distType, "distribution type"); + addTypeViolation(distType, "distribution type", violations); } } @Override - protected void preprocessEnumType(EnumType enumType) { + protected void preprocessEnumType(EnumType enumType, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificType.ENUM_TYPES)) { - addTypeViolation(enumType, "enumeration type"); + addTypeViolation(enumType, "enumeration type", violations); } } @Override - protected void preprocessFuncType(FuncType funcType) { + protected void preprocessFuncType(FuncType funcType, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificType.FUNC_TYPES)) { - addTypeViolation(funcType, "function type"); + addTypeViolation(funcType, "function type", violations); } } @Override - protected void preprocessIntType(IntType intType) { + protected void preprocessIntType(IntType intType, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificType.INT_TYPES)) { - addTypeViolation(intType, "integer type"); + addTypeViolation(intType, "integer type", violations); } else if (disalloweds.contains(NoSpecificType.INT_TYPES_RANGELESS) && CifTypeUtils.isRangeless(intType)) { - addTypeViolation(intType, "rangeless integer type"); + addTypeViolation(intType, "rangeless integer type", violations); } } @Override - protected void preprocessListType(ListType listType) { + protected void preprocessListType(ListType listType, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificType.LIST_TYPES)) { - addTypeViolation(listType, "list type"); + addTypeViolation(listType, "list type", violations); } else if (disalloweds.contains(NoSpecificType.LIST_TYPES_NON_ARRAY) && !CifTypeUtils.isArrayType(listType)) { - addTypeViolation(listType, "non-array list type"); + addTypeViolation(listType, "non-array list type", violations); } } @Override - protected void preprocessRealType(RealType realType) { + protected void preprocessRealType(RealType realType, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificType.REAL_TYPES)) { - addTypeViolation(realType, "real type"); + addTypeViolation(realType, "real type", violations); } } @Override - protected void preprocessSetType(SetType setType) { + protected void preprocessSetType(SetType setType, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificType.SET_TYPES)) { - addTypeViolation(setType, "set type"); + addTypeViolation(setType, "set type", violations); } } @Override - protected void preprocessStringType(StringType stringType) { + protected void preprocessStringType(StringType stringType, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificType.STRING_TYPES)) { - addTypeViolation(stringType, "string type"); + addTypeViolation(stringType, "string type", violations); } } @Override - protected void preprocessTupleType(TupleType tupleType) { + protected void preprocessTupleType(TupleType tupleType, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificType.TUPLE_TYPES)) { - addTypeViolation(tupleType, "tuple type"); + addTypeViolation(tupleType, "tuple type", violations); } } @Override - protected void preprocessVoidType(VoidType voidType) { + protected void preprocessVoidType(VoidType voidType, CifCheckViolations violations) { if (disalloweds.contains(NoSpecificType.VOID_TYPES)) { - addTypeViolation(voidType, "void type"); + addTypeViolation(voidType, "void type", violations); } } - @Override - protected void addViolation(PositionObject typeObj, String message) { - throw new UnsupportedOperationException(); // Use addTypeViolation. - } - /** * Add a violation for the given type. * * @param type The type. * @param description The description of the type. + * @param violations The violations collected so far. Is modified in-place. */ - private void addTypeViolation(CifType type, String description) { - super.addViolation(getNamedSelfOrAncestor(type), fmt("uses %s \"%s\"", description, typeToStr(type))); + private void addTypeViolation(CifType type, String description, CifCheckViolations violations) { + violations.add(getNamedSelfOrAncestor(type), fmt("uses %s \"%s\"", description, typeToStr(type))); } /** The type, or sub-type, to disallow. */ diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificUnaryExprsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificUnaryExprsCheck.java index 512fe0ce2..b036c6361 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificUnaryExprsCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoSpecificUnaryExprsCheck.java @@ -43,68 +43,68 @@ public class NoSpecificUnaryExprsCheck extends CifCheck { } @Override - protected void preprocessUnaryExpression(UnaryExpression unExpr) { + protected void preprocessUnaryExpression(UnaryExpression unExpr, CifCheckViolations violations) { UnaryOperator op = unExpr.getOperator(); CifType ctype = CifTypeUtils.normalizeType(unExpr.getChild().getType()); switch (op) { case INVERSE: if (disalloweds.contains(NoSpecificUnaryOp.INVERSE)) { - addExprViolationOperator(unExpr); + addExprViolationOperator(unExpr, violations); } break; case NEGATE: if (disalloweds.contains(NoSpecificUnaryOp.NEGATE)) { - addExprViolationOperator(unExpr); + addExprViolationOperator(unExpr, violations); } else { if (disalloweds.contains(NoSpecificUnaryOp.NEGATE_INTS)) { if (ctype instanceof IntType) { - addExprViolationOperand(unExpr); + addExprViolationOperand(unExpr, violations); } } else { if (disalloweds.contains(NoSpecificUnaryOp.NEGATE_INTS_RANGED) && ctype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ctype)) { - addExprViolationOperand(unExpr); + addExprViolationOperand(unExpr, violations); } if (disalloweds.contains(NoSpecificUnaryOp.NEGATE_INTS_RANGELESS) && ctype instanceof IntType && CifTypeUtils.isRangeless((IntType)ctype)) { - addExprViolationOperand(unExpr); + addExprViolationOperand(unExpr, violations); } } if (disalloweds.contains(NoSpecificUnaryOp.NEGATE_REALS) && ctype instanceof RealType) { - addExprViolationOperand(unExpr); + addExprViolationOperand(unExpr, violations); } } break; case PLUS: if (disalloweds.contains(NoSpecificUnaryOp.PLUS)) { - addExprViolationOperator(unExpr); + addExprViolationOperator(unExpr, violations); } else { if (disalloweds.contains(NoSpecificUnaryOp.PLUS_INTS)) { if (ctype instanceof IntType) { - addExprViolationOperand(unExpr); + addExprViolationOperand(unExpr, violations); } } else { if (disalloweds.contains(NoSpecificUnaryOp.PLUS_INTS_RANGED) && ctype instanceof IntType && !CifTypeUtils.isRangeless((IntType)ctype)) { - addExprViolationOperand(unExpr); + addExprViolationOperand(unExpr, violations); } if (disalloweds.contains(NoSpecificUnaryOp.PLUS_INTS_RANGELESS) && ctype instanceof IntType && CifTypeUtils.isRangeless((IntType)ctype)) { - addExprViolationOperand(unExpr); + addExprViolationOperand(unExpr, violations); } } if (disalloweds.contains(NoSpecificUnaryOp.PLUS_REALS) && ctype instanceof RealType) { - addExprViolationOperand(unExpr); + addExprViolationOperand(unExpr, violations); } } break; case SAMPLE: if (disalloweds.contains(NoSpecificUnaryOp.SAMPLE)) { - addExprViolationOperator(unExpr); + addExprViolationOperator(unExpr, violations); } break; default: @@ -116,9 +116,10 @@ public class NoSpecificUnaryExprsCheck extends CifCheck { * Add a violation for the operator of the given unary expression. * * @param unExpr The unary expression. + * @param violations The violations collected so far. Is modified in-place. */ - private void addExprViolationOperator(UnaryExpression unExpr) { - super.addViolation(getNamedSelfOrAncestor(unExpr), fmt("uses unary operator \"%s\" in unary expression \"%s\"", + private void addExprViolationOperator(UnaryExpression unExpr, CifCheckViolations violations) { + violations.add(getNamedSelfOrAncestor(unExpr), fmt("uses unary operator \"%s\" in unary expression \"%s\"", operatorToStr(unExpr.getOperator()), exprToStr(unExpr))); } @@ -126,10 +127,11 @@ public class NoSpecificUnaryExprsCheck extends CifCheck { * Add a violation for an operand of the the given unary expression. * * @param unExpr The unary expression. + * @param violations The violations collected so far. Is modified in-place. */ - private void addExprViolationOperand(UnaryExpression unExpr) { + private void addExprViolationOperand(UnaryExpression unExpr, CifCheckViolations violations) { CifType ctype = CifTypeUtils.normalizeType(unExpr.getChild().getType()); - super.addViolation(getNamedSelfOrAncestor(unExpr), + violations.add(getNamedSelfOrAncestor(unExpr), fmt("uses unary operator \"%s\" on an operand of type \"%s\" in unary expression \"%s\"", operatorToStr(unExpr.getOperator()), typeToStr(ctype), exprToStr(unExpr))); } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoStateInvsInLocsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoStateInvsInLocsCheck.java index bf99d6d30..4d52ecb13 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoStateInvsInLocsCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoStateInvsInLocsCheck.java @@ -23,7 +23,7 @@ import org.eclipse.escet.cif.metamodel.cif.automata.Location; /** CIF check that does not allow state invariants in locations. */ public class NoStateInvsInLocsCheck extends CifCheck { @Override - protected void preprocessLocation(Location loc) { + protected void preprocessLocation(Location loc, CifCheckViolations violations) { // Skip location parameters. EObject parent = loc.eContainer(); if (parent instanceof LocationParameter) { @@ -34,9 +34,9 @@ public class NoStateInvsInLocsCheck extends CifCheck { for (Invariant inv: loc.getInvariants()) { if (inv.getInvKind() == InvKind.STATE) { if (loc.getName() != null) { - addViolation(loc, "location has a state invariant"); + violations.add(loc, "location has a state invariant"); } else { - addViolation((Automaton)loc.eContainer(), "automaton has a location with a state invariant"); + violations.add((Automaton)loc.eContainer(), "automaton has a location with a state invariant"); } } } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoTauCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoTauCheck.java index 66e23d381..3a65da4cc 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoTauCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoTauCheck.java @@ -27,27 +27,28 @@ import org.eclipse.escet.cif.metamodel.cif.expressions.TauExpression; */ public class NoTauCheck extends CifCheck { @Override - protected void preprocessTauExpression(TauExpression tauExpr) { + protected void preprocessTauExpression(TauExpression tauExpr, CifCheckViolations violations) { // Explicit tau. EdgeEvent edgeEvent = (EdgeEvent)tauExpr.eContainer(); Edge edge = (Edge)edgeEvent.eContainer(); Location loc = CifEdgeUtils.getSource(edge); if (loc.getName() != null) { - addViolation(loc, "location has an edge with explicitly event \"tau\" on it"); + violations.add(loc, "location has an edge with explicitly event \"tau\" on it"); } else { - addViolation((Automaton)loc.eContainer(), "automaton has an edge with explicitly event \"tau\" on it"); + violations.add((Automaton)loc.eContainer(), "automaton has an edge with explicitly event \"tau\" on it"); } } @Override - protected void preprocessEdge(Edge edge) { + protected void preprocessEdge(Edge edge, CifCheckViolations violations) { // Implicit tau. if (edge.getEvents().isEmpty()) { Location loc = CifEdgeUtils.getSource(edge); if (loc.getName() != null) { - addViolation(loc, "location has an edge with implicitly event \"tau\" on it"); + violations.add(loc, "location has an edge with implicitly event \"tau\" on it"); } else { - addViolation((Automaton)loc.eContainer(), "automaton has an edge with implicitly event \"tau\" on it"); + violations.add((Automaton)loc.eContainer(), + "automaton has an edge with implicitly event \"tau\" on it"); } } } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoUrgentEdgesCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoUrgentEdgesCheck.java index 6941a3481..7151d5bb1 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoUrgentEdgesCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoUrgentEdgesCheck.java @@ -20,13 +20,13 @@ import org.eclipse.escet.cif.metamodel.cif.automata.Location; /** CIF check that does not allow urgent edges. */ public class NoUrgentEdgesCheck extends CifCheck { @Override - protected void preprocessEdge(Edge edge) { + protected void preprocessEdge(Edge edge, CifCheckViolations violations) { if (edge.isUrgent()) { Location loc = (Location)edge.eContainer(); if (loc.getName() != null) { - addViolation(loc, "location has an urgent edge"); + violations.add(loc, "location has an urgent edge"); } else { - addViolation((Automaton)loc.eContainer(), "automaton has an urgent edge"); + violations.add((Automaton)loc.eContainer(), "automaton has an urgent edge"); } } } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoUrgentLocationsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoUrgentLocationsCheck.java index 788fb4fcc..7695b5548 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoUrgentLocationsCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoUrgentLocationsCheck.java @@ -21,7 +21,7 @@ import org.eclipse.escet.cif.metamodel.cif.automata.Location; /** CIF check that does not allow urgent locations. */ public class NoUrgentLocationsCheck extends CifCheck { @Override - protected void preprocessLocation(Location loc) { + protected void preprocessLocation(Location loc, CifCheckViolations violations) { // Skip location parameters. EObject parent = loc.eContainer(); if (parent instanceof LocationParameter) { @@ -31,9 +31,9 @@ public class NoUrgentLocationsCheck extends CifCheck { // Check for violation. if (loc.isUrgent()) { if (loc.getName() != null) { - addViolation(loc, "location is urgent"); + violations.add(loc, "location is urgent"); } else { - addViolation((Automaton)loc.eContainer(), "automaton has an urgent location"); + violations.add((Automaton)loc.eContainer(), "automaton has an urgent location"); } } } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoUserDefinedFunctionsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoUserDefinedFunctionsCheck.java index b3b2d0258..6082f1a14 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoUserDefinedFunctionsCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/NoUserDefinedFunctionsCheck.java @@ -18,7 +18,7 @@ import org.eclipse.escet.cif.metamodel.cif.functions.Function; /** CIF check that does not allow user-defined functions. */ public class NoUserDefinedFunctionsCheck extends CifCheck { @Override - protected void preprocessFunction(Function func) { - addViolation(func, "function is a user-defined function"); + protected void preprocessFunction(Function func, CifCheckViolations violations) { + violations.add(func, "function is a user-defined function"); } } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyAutsWithOneInitLocCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyAutsWithOneInitLocCheck.java index 4cb9bbbf0..ee6e57f40 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyAutsWithOneInitLocCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyAutsWithOneInitLocCheck.java @@ -35,23 +35,23 @@ public class OnlyAutsWithOneInitLocCheck extends CifCheck { private int initLocCount; @Override - protected void preprocessAutomaton(Automaton aut) { + protected void preprocessAutomaton(Automaton aut, CifCheckViolations violations) { // Reset initial locations counter. initLocCount = 0; } @Override - protected void postprocessAutomaton(Automaton aut) { + protected void postprocessAutomaton(Automaton aut, CifCheckViolations violations) { // There must be exactly one initial location. if (initLocCount == 0) { - addViolation(aut, "automaton has no initial location"); + violations.add(aut, "automaton has no initial location"); } else if (initLocCount > 1) { - addViolation(aut, fmt("automata has multiple (%d) initial locations", initLocCount)); + violations.add(aut, fmt("automata has multiple (%d) initial locations", initLocCount)); } // Skip if check is disabled (negative value). } @Override - protected void preprocessLocation(Location loc) { + protected void preprocessLocation(Location loc, CifCheckViolations violations) { // Skip location parameters. EObject parent = loc.eContainer(); if (parent instanceof LocationParameter) { @@ -73,9 +73,9 @@ public class OnlyAutsWithOneInitLocCheck extends CifCheck { } if (errMsg != null) { if (loc.getName() != null) { - addViolation(loc, "failed to determine whether this is an initial location, " + errMsg); + violations.add(loc, "failed to determine whether this is an initial location, " + errMsg); } else { - addViolation((Automaton)loc.eContainer(), + violations.add((Automaton)loc.eContainer(), "failed to determine whether the automaton's location is an initial location, " + errMsg); } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyEventsWithControllabilityCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyEventsWithControllabilityCheck.java index f77121b0c..100df9af9 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyEventsWithControllabilityCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyEventsWithControllabilityCheck.java @@ -28,38 +28,38 @@ import org.eclipse.escet.cif.metamodel.cif.expressions.TauExpression; */ public class OnlyEventsWithControllabilityCheck extends CifCheck { @Override - protected void preprocessEvent(Event event) { + protected void preprocessEvent(Event event, CifCheckViolations violations) { if (event.getControllable() == null) { - addViolation(event, "event is not declared as controllable or uncontrollable"); + violations.add(event, "event is not declared as controllable or uncontrollable"); } } @Override - protected void preprocessTauExpression(TauExpression tauExpr) { + protected void preprocessTauExpression(TauExpression tauExpr, CifCheckViolations violations) { // Explicit tau. EdgeEvent edgeEvent = (EdgeEvent)tauExpr.eContainer(); Edge edge = (Edge)edgeEvent.eContainer(); Location loc = CifEdgeUtils.getSource(edge); if (loc.getName() != null) { - addViolation(loc, "location has an edge with explicitly event \"tau\" on it, " + violations.add(loc, "location has an edge with explicitly event \"tau\" on it, " + "which is not controllable or uncontrollable"); } else { - addViolation((Automaton)loc.eContainer(), "automaton has an edge with explicitly event \"tau\" on it, " + violations.add((Automaton)loc.eContainer(), "automaton has an edge with explicitly event \"tau\" on it, " + "which is not controllable or uncontrollable"); } } @Override - protected void preprocessEdge(Edge edge) { + protected void preprocessEdge(Edge edge, CifCheckViolations violations) { // Implicit tau. if (edge.getEvents().isEmpty()) { Location loc = CifEdgeUtils.getSource(edge); if (loc.getName() != null) { - addViolation(loc, "location has an edge with implicitly event \"tau\" on it, " + violations.add(loc, "location has an edge with implicitly event \"tau\" on it, " + "which is not controllable or uncontrollable"); } else { - addViolation((Automaton)loc.eContainer(), "automaton has an edge with implicitly event \"tau\" on it, " - + "which is not controllable or uncontrollable"); + violations.add((Automaton)loc.eContainer(), "automaton has an edge with implicitly event \"tau\" on " + + "it, which is not controllable or uncontrollable"); } } } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyReqStateInvsInCompsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyReqStateInvsInCompsCheck.java index 55f3d6ed5..a6a775a1a 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyReqStateInvsInCompsCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyReqStateInvsInCompsCheck.java @@ -24,13 +24,13 @@ import org.eclipse.escet.cif.metamodel.cif.SupKind; /** CIF check that allows state invariants in components only if they are requirement invariants. */ public class OnlyReqStateInvsInCompsCheck extends CifCheck { @Override - protected void preprocessComplexComponent(ComplexComponent comp) { + protected void preprocessComplexComponent(ComplexComponent comp, CifCheckViolations violations) { for (Invariant inv: comp.getInvariants()) { if (inv.getInvKind() == InvKind.STATE) { SupKind supKind = inv.getSupKind(); if (supKind != SupKind.REQUIREMENT) { String kindTxt = (supKind == SupKind.NONE) ? "kindless" : CifTextUtils.kindToStr(supKind); - addViolation(comp, fmt("component has a %s state invariant", kindTxt)); + violations.add(comp, fmt("component has a %s state invariant", kindTxt)); } } } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlySimpleAssignmentsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlySimpleAssignmentsCheck.java index 7f7ca4f0a..9eb11db15 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlySimpleAssignmentsCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlySimpleAssignmentsCheck.java @@ -13,8 +13,6 @@ package org.eclipse.escet.cif.common.checkers; -import java.util.Set; - import org.eclipse.escet.cif.metamodel.cif.automata.Assignment; import org.eclipse.escet.cif.metamodel.cif.automata.IfUpdate; @@ -36,21 +34,13 @@ public class OnlySimpleAssignmentsCheck extends CifCheck { private NoPartialVarAssignOnEdgesCheck noPartial = new NoPartialVarAssignOnEdgesCheck(); @Override - public void setViolations(Set violations) { - super.setViolations(violations); - noIf.setViolations(violations); - noMulti.setViolations(violations); - noPartial.setViolations(violations); - } - - @Override - protected void preprocessIfUpdate(IfUpdate update) { - noIf.preprocessIfUpdate(update); + protected void preprocessIfUpdate(IfUpdate update, CifCheckViolations violations) { + noIf.preprocessIfUpdate(update, violations); } @Override - protected void preprocessAssignment(Assignment asgn) { - noMulti.preprocessAssignment(asgn); - noPartial.preprocessAssignment(asgn); + protected void preprocessAssignment(Assignment asgn, CifCheckViolations violations) { + noMulti.preprocessAssignment(asgn, violations); + noPartial.preprocessAssignment(asgn, violations); } } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyStaticEvalMarkerPredsInLocsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyStaticEvalMarkerPredsInLocsCheck.java index b526c5256..39bd2155e 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyStaticEvalMarkerPredsInLocsCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyStaticEvalMarkerPredsInLocsCheck.java @@ -25,7 +25,7 @@ import org.eclipse.escet.common.app.framework.exceptions.UnsupportedException; /** CIF check that allows marker predicates in locations only if they can be evaluated statically. */ public class OnlyStaticEvalMarkerPredsInLocsCheck extends CifCheck { @Override - protected void preprocessLocation(Location loc) { + protected void preprocessLocation(Location loc, CifCheckViolations violations) { // Skip location parameters. EObject parent = loc.eContainer(); if (parent instanceof LocationParameter) { @@ -38,17 +38,17 @@ public class OnlyStaticEvalMarkerPredsInLocsCheck extends CifCheck { evalPreds(loc.getMarkeds(), false, true); } catch (UnsupportedException e) { if (loc.getName() != null) { - addViolation(loc, "location has a marker predicate that can not be evaluated statically"); + violations.add(loc, "location has a marker predicate that can not be evaluated statically"); } else { - addViolation((Automaton)loc.eContainer(), + violations.add((Automaton)loc.eContainer(), "automaton has a location with a marker predicate that can not be evaluated statically"); } } catch (CifEvalException e) { if (loc.getName() != null) { - addViolation(loc, + violations.add(loc, "static evaluation of a marker predicate in the location resulted in an evaluation error"); } else { - addViolation((Automaton)loc.eContainer(), "static evaluation of a marker predicate in the " + violations.add((Automaton)loc.eContainer(), "static evaluation of a marker predicate in the " + "location of the automaton resulted in an evaluation error"); } } diff --git a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyVarValueMarkerPredsInCompsCheck.java b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyVarValueMarkerPredsInCompsCheck.java index 9f3cd7820..022012ad1 100644 --- a/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyVarValueMarkerPredsInCompsCheck.java +++ b/cif/org.eclipse.escet.cif.common/src/org/eclipse/escet/cif/common/checkers/OnlyVarValueMarkerPredsInCompsCheck.java @@ -16,7 +16,6 @@ package org.eclipse.escet.cif.common.checkers; import static org.eclipse.escet.common.java.Maps.map; import java.util.Map; -import java.util.Set; import org.eclipse.escet.cif.metamodel.cif.ComplexComponent; import org.eclipse.escet.cif.metamodel.cif.declarations.DiscVariable; @@ -31,27 +30,20 @@ import org.eclipse.escet.cif.metamodel.cif.expressions.Expression; */ public class OnlyVarValueMarkerPredsInCompsCheck extends CifCheck { /** Mapping from discrete variables to their marked values. Used to detect duplicates. */ - private Map markeds; + private Map markeds = map(); @Override - public void setViolations(Set violations) { - // Initialization. - super.setViolations(violations); - markeds = map(); - } - - @Override - protected void preprocessComplexComponent(ComplexComponent comp) { + protected void preprocessComplexComponent(ComplexComponent comp, CifCheckViolations violations) { for (Expression marked: comp.getMarkeds()) { // The only supported form is 'discrete_variable = marked_value'. if (!(marked instanceof BinaryExpression)) { - addViolation(comp, "component has a marker predicate that is not of the form " + violations.add(comp, "component has a marker predicate that is not of the for