Skip to content

Base Modelica class-definition not allowing class class-prefix. #3919

@AnHeuermann

Description

@AnHeuermann

Issue

In the current version of the Base Modelica grammar the class-prefix class is not allowed. How to deal with External Objects from Modelica?
Where should constructor and destructor classes life?
The two constructor and desctructor functions aren't allowed to be called directly (at least in Modelica). How would a Base Modelica parser/ compiler deduce that a function is indeed a constructor/desctructor for an external object and be able to verify that?

Example

When flattening Modelica.Blocks.Examples.ShowLogicalSources (from MSL 4.1) into Base Modelica the external object for the table needs to be lowered to Base Modelica. Currently we at OpenModelica don't know what to do with the ExternalObject class, see OpenModelica/OpenModelica#15238.

The Base Modelica from OpenModelica: Modelica.Blocks.Examples.ShowLogicalSources.bmo

//! base 0.1.0
package 'ShowLogicalSources'
  /* ... */
  class 'Modelica.Blocks.Types.ExternalCombiTimeTable'
  extends ExternalObject;

    function constructor "Initialize 1-dim. table where first column is time"
      input String 'tableName';
      input String 'fileName';
      input Real 'table'[:, :];
      input Real 'startTime';
      input Integer 'columns'[:];
      input 'Modelica.Blocks.Types.Smoothness' 'smoothness';
      input 'Modelica.Blocks.Types.Extrapolation' 'extrapolation';
      input Real 'shiftTime' = 0.0;
      input 'Modelica.Blocks.Types.TimeEvents' 'timeEvents' = 'Modelica.Blocks.Types.TimeEvents'.'Always';
      input Boolean 'verboseRead' = true;
      input String 'delimiter' = ",";
      input Integer 'nHeaderLines' = 0;
      output 'Modelica.Blocks.Types.ExternalCombiTimeTable' 'externalCombiTimeTable';
    external "C" 'externalCombiTimeTable' = ModelicaStandardTables_CombiTimeTable_init3('fileName', 'tableName', 'table', size('table', 1), size('table', 2), 'startTime', 'columns', size('columns', 1), 'smoothness', 'extrapolation', 'shiftTime', 'timeEvents', 'verboseRead', 'delimiter', 'nHeaderLines') annotation(Library = {"ModelicaStandardTables", "ModelicaIO", "ModelicaMatIO", "zlib"}, LibraryDirectory = "modelica://Modelica/Resources/Library");
    end constructor;

    function destructor "Terminate 1-dim. table where first column is time"
      input 'Modelica.Blocks.Types.ExternalCombiTimeTable' 'externalCombiTimeTable';
    external "C" ModelicaStandardTables_CombiTimeTable_close('externalCombiTimeTable') annotation(Library = {"ModelicaStandardTables", "ModelicaIO", "ModelicaMatIO", "zlib"}, LibraryDirectory = "modelica://Modelica/Resources/Library");
    end destructor;

end 'Modelica.Blocks.Types.ExternalCombiTimeTable';

  model 'ShowLogicalSources' "Demonstrates the usage of logical sources together with their diagram animation"
    /* ... */
  parameter 'Modelica.Blocks.Types.ExternalCombiTimeTable' 'table.combiTimeTable.tableID' = 'Modelica.Blocks.Types.ExternalCombiTimeTable'("NoName", "NoName", {{2.0, 0.0}, {2.0, 1.0}, {4.0, 0.0}, {6.0, 1.0}, {8.0, 0.0}}, -1e60, {2}, 'Modelica.Blocks.Types.Smoothness'.'ConstantSegments', 'Modelica.Blocks.Types.Extrapolation'.'HoldLastPoint', 0.0, 'Modelica.Blocks.Types.TimeEvents'.'Always', false, ",", 0) "External table object";
    /* ... */
  end 'ShowLogicalSources';
end 'ShowLogicalSources';

Metadata

Metadata

Assignees

No one assigned

    Labels

    MCP0031Base Modelica and MLS modularization (MCP-0031)

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions