Skip to content

CIF code generator may crash when dealing with ranged integers

The CIF code generator crashes on the following CIF specification:

type Item = int[0..10];

controllable event c_decr;

plant Test:
  disc Item item = 0;

  location:
    initial;
    marked;
    edge c_decr when item > 0 do item := item - 1;
end

The crash report says:

[Exception]
java.lang.ClassCastException: class org.eclipse.escet.cif.metamodel.cif.types.impl.TypeRefImpl cannot be cast to class org.eclipse.escet.cif.metamodel.cif.types.IntType (org.eclipse.escet.cif.metamodel.cif.types.impl.TypeRefImpl and org.eclipse.escet.cif.metamodel.cif.types.IntType are in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @2e34df9b)
  at org.eclipse.escet.cif.codegen.javascript.typeinfos.JavaScriptIntTypeInfo.checkRange(JavaScriptIntTypeInfo.java:233)
  at org.eclipse.escet.cif.codegen.javascript.JavaScriptCodeGen.performAssign(JavaScriptCodeGen.java:874)
  at org.eclipse.escet.cif.codegen.CodeContext.performAssign(CodeContext.java:232)
  at org.eclipse.escet.cif.codegen.updates.tree.AssignmentUpdate.genCode(AssignmentUpdate.java:140)
  at org.eclipse.escet.cif.codegen.updates.tree.SequenceUpdate.genCode(SequenceUpdate.java:218)
  at org.eclipse.escet.cif.codegen.updates.tree.UpdateData.generateAssignment(UpdateData.java:107)
  at org.eclipse.escet.cif.codegen.CodeGen.addUpdates(CodeGen.java:1133)
  at org.eclipse.escet.cif.codegen.javascript.JavaScriptCodeGen.addEdges(JavaScriptCodeGen.java:820)
  at org.eclipse.escet.cif.codegen.javascript.JavaScriptCodeGen.addEdges(JavaScriptCodeGen.java:700)
  at org.eclipse.escet.cif.codegen.CodeGen.generateCode(CodeGen.java:1035)
  at org.eclipse.escet.cif.codegen.CodeGen.generate(CodeGen.java:485)
  at org.eclipse.escet.cif.codegen.CodeGenApp.runInternal(CodeGenApp.java:104)
  at org.eclipse.escet.common.app.framework.Application.runApplication(Application.java:315)
  at org.eclipse.escet.common.app.framework.Application.run(Application.java:180)
  at org.eclipse.escet.common.eclipse.ui.BaseFileCommandHandler.run(BaseFileCommandHandler.java:261)
  at org.eclipse.escet.common.eclipse.ui.BaseFileCommandHandler$1.run(BaseFileCommandHandler.java:102)
  at java.base/java.lang.Thread.run(Thread.java:840)

[Application]
Application name    = CIF code generator
Application version = 5.0.0.qualifier
Application class   = org.eclipse.escet.cif.codegen.CodeGenApp

[Options]
Command line arguments = "test.cif", "--option-dialog=yes"
Dialog arguments       = "test.cif", "--code-prefix=", "--devmode=no", "--java-package=", "--output-dir=.", "--output-mode=normal", "--output-variables=*", "--simulink-sample-offset=0.0", "--simulink-sample-time=continuous", "--target-language=html"
Final arguments        = "--devmode=no", "--option-dialog=no", "--output-mode=normal", "--gui=auto", "--output-variables=*", "--simulink-sample-time=continuous", "--simulink-sample-offset=0.0", "--java-package=", "test.cif", "--output-dir=.", "--target-language=html", "--code-prefix="

The same problem occurs when another target language is specified using --target-language. So this isn't specific to HTML generation.

The problem seems to be in handling the type declaration Item. If I apply a CIF-to-CIF transformation to eliminate type declarations, the crash no longer occurs.