Changeset c8e35cd in OpenModelica


Ignore:
Timestamp:
2024-05-23T12:53:11+02:00 (3 weeks ago)
Author:
GitHub <noreply@…>
Branches:
master
Children:
8cc47a0c, f191ed8
Parents:
d5dbbd9b
git-author:
Per Östlund <per.ostlund@…> (05/23/24 12:53:11)
git-committer:
GitHub <noreply@…> (05/23/24 12:53:11)
Message:

Improve Base Modelica export (#12460)

  • Add version header.
  • Add experiment annotation.

Fixes #12457 and #12458

Files:
16 edited

Legend:

Unmodified
Added
Removed
  • OMCompiler/Compiler/NFFrontEnd/NFEquation.mo

    r901e52a8 rc8e35cd  
    15271527    end match;
    15281528
    1529     s := FlatModelicaUtil.appendElementSourceComment(source(eq), s);
     1529    s := FlatModelicaUtil.appendElementSourceComment(source(eq), NFFlatModelicaUtil.ElementType.EQUATION, s);
    15301530  end toFlatStream;
    15311531
  • OMCompiler/Compiler/NFFrontEnd/NFFlatModel.mo

    r018ac8eb rc8e35cd  
    234234    String name = className(flatModel);
    235235  algorithm
     236    s := IOStream.append(s, "//! base 0.1.0\n");
    236237    s := IOStream.append(s, "package '" + name + "'\n");
    237238    flat_model.variables := reconstructRecordInstances(flat_model.variables);
     
    282283    end for;
    283284
    284     s := FlatModelicaUtil.appendElementSourceCommentAnnotation(flat_model.source, "    ", ";\n", s);
     285    s := FlatModelicaUtil.appendElementSourceCommentAnnotation(flat_model.source,
     286      NFFlatModelicaUtil.ElementType.ROOT_CLASS, "    ", ";\n", s);
    285287    s := IOStream.append(s, "  end '" + name + "';\n");
    286288    s := IOStream.append(s, "end '" + name + "';\n");
  • OMCompiler/Compiler/NFFrontEnd/NFFlatModelicaUtil.mo

    rb3681ace rc8e35cd  
    4343  import Util;
    4444
     45  // Used to indicate what type of element an annotation comes from, to allow
     46  // filtering out specific annotations for dumping.
     47  type ElementType = enumeration(
     48    ROOT_CLASS,
     49    CLASS,
     50    FUNCTION,
     51    COMPONENT,
     52    EQUATION,
     53    ALGORITHM,
     54    OTHER
     55  );
     56
    4557  function appendElementSourceCommentString
    4658    input DAE.ElementSource source;
     
    5264  function appendElementSourceCommentAnnotation
    5365    input DAE.ElementSource source;
     66    input ElementType elementType;
    5467    input String indent;
    5568    input String ending;
    5669    input output IOStream.IOStream s;
    5770  algorithm
    58     s := appendCommentAnnotation(ElementSource.getOptComment(source), indent, ending, s);
     71    s := appendCommentAnnotation(ElementSource.getOptComment(source), elementType, indent, ending, s);
    5972  end appendElementSourceCommentAnnotation;
    6073
    6174  function appendElementSourceComment
    6275    input DAE.ElementSource source;
    63     input output IOStream.IOStream s;
    64   algorithm
    65     s := appendComment(ElementSource.getOptComment(source), s);
     76    input ElementType elementType;
     77    input output IOStream.IOStream s;
     78  algorithm
     79    s := appendComment(ElementSource.getOptComment(source), elementType, s);
    6680  end appendElementSourceComment;
    6781
    6882  function appendComment
    6983    input Option<SCode.Comment> comment;
     84    input ElementType elementType;
    7085    input output IOStream.IOStream s;
    7186  algorithm
    7287    s := appendCommentString(comment, s);
    73     s := appendCommentAnnotation(comment, " ", "", s);
     88    s := appendCommentAnnotation(comment, elementType, " ", "", s);
    7489  end appendComment;
    7590
     
    95110  function appendCommentAnnotation
    96111    input Option<SCode.Comment> comment;
     112    input ElementType elementType;
    97113    input String indent;
    98114    input String ending;
     
    105121          SOME(SCode.Annotation.ANNOTATION(modification = mod))))
    106122        algorithm
    107           mod := DAEDump.filterStructuralMods(mod);
     123          mod := match elementType
     124            case ElementType.ROOT_CLASS then filterRootClassAnnotations(mod);
     125            else DAEDump.filterStructuralMods(mod);
     126          end match;
    108127
    109128          if not SCodeUtil.isEmptyMod(mod) then
     
    120139  end appendCommentAnnotation;
    121140
     141  function filterRootClassAnnotations
     142    input output SCode.Mod mod;
     143  protected
     144    function filter
     145      input SCode.SubMod smod;
     146      output Boolean keep;
     147    algorithm
     148      keep := match smod.ident
     149        case "experiment" then true;
     150        else false;
     151      end match;
     152    end filter;
     153  algorithm
     154    mod := SCodeUtil.filterSubMods(mod, filter);
     155  end filterRootClassAnnotations;
     156
    122157  function appendAnnotationMod
    123158    input SCode.Mod mod;
  • OMCompiler/Compiler/NFFrontEnd/NFFunction.mo

    rd9f2966 rc8e35cd  
    881881      s := IOStream.append(s, ", ");
    882882      s := IOStream.append(s, stringDelimitList(getDerivedInputNames(fn), ", "));
    883       s := FlatModelicaUtil.appendComment(SCodeUtil.getElementComment(InstNode.definition(fn.node)), s);
     883      s := FlatModelicaUtil.appendComment(SCodeUtil.getElementComment(InstNode.definition(fn.node)),
     884        NFFlatModelicaUtil.ElementType.FUNCTION, s);
    884885      s := IOStream.append(s, ")");
    885886    else
     
    931932      if not SCodeUtil.emptyModOrEquality(annMod) then
    932933        cmt := SCode.COMMENT(SOME(SCode.ANNOTATION(annMod)), NONE());
    933         s := FlatModelicaUtil.appendCommentAnnotation(SOME(cmt), indent + "  ", ";\n", s);
     934        s := FlatModelicaUtil.appendCommentAnnotation(SOME(cmt),
     935          NFFlatModelicaUtil.ElementType.FUNCTION, indent + "  ", ";\n", s);
    934936      end if;
    935937
  • OMCompiler/Compiler/NFFrontEnd/NFStatement.mo

    rb727a78 rc8e35cd  
    10311031    end match;
    10321032
    1033     s := FlatModelicaUtil.appendElementSourceComment(source(stmt), s);
     1033    s := FlatModelicaUtil.appendElementSourceComment(source(stmt), NFFlatModelicaUtil.ElementType.ALGORITHM, s);
    10341034  end toFlatStream;
    10351035
  • OMCompiler/Compiler/NFFrontEnd/NFVariable.mo

    r018ac8eb rc8e35cd  
    583583
    584584    s := toFlatStreamBinding(var.binding, printBindingType, s);
    585     s := FlatModelicaUtil.appendComment(var.comment, s);
     585    s := FlatModelicaUtil.appendComment(var.comment, NFFlatModelicaUtil.ElementType.COMPONENT, s);
    586586  end toFlatStream;
    587587
  • testsuite/flattening/modelica/scodeinst/CombineSubscripts3.mo

    rd3aac72 rc8e35cd  
    2121
    2222// Result:
     23// //! base 0.1.0
    2324// package 'CombineSubscripts3'
    2425//   model 'CombineSubscripts3'
  • testsuite/openmodelica/basemodelica/ArrayBinding1.mo

    rc3d1dae rc8e35cd  
    1313
    1414// Result:
     15// //! base 0.1.0
    1516// package 'ArrayBinding1'
    1617//   model 'ArrayBinding1'
  • testsuite/openmodelica/basemodelica/Comments.mo

    r77614c7 rc8e35cd  
    1111  x + y = 0 "Some equation" annotation(__A = true);
    1212  x - y = 1 "Some other equation";
    13   annotation(version = "1.0.0");
     13  annotation(version = "1.0.0", experiment(StopTime = 1.0));
    1414end Comments;
    1515
    1616// Result:
     17// //! base 0.1.0
    1718// package 'Comments'
    1819//   model 'Comments' "Model to test comments in Flat Modelica output"
     
    2223//     'x' + 'y' = 0.0 "Some equation";
    2324//     'x' - 'y' = 1.0 "Some other equation";
     25//     annotation(experiment(StopTime = 1.0));
    2426//   end 'Comments';
    2527// end 'Comments';
  • testsuite/openmodelica/basemodelica/Expression1.mo

    r46a181d rc8e35cd  
    2020
    2121// Result:
     22// //! base 0.1.0
    2223// package 'Expression1'
    2324//   function 'f'
  • testsuite/openmodelica/basemodelica/InStreamNominalThreshold.mo

    rd9f2966 rc8e35cd  
    3636
    3737// Result:
     38// //! base 0.1.0
    3839// package 'InStreamNominalThreshold'
    3940//   function '$OMC$PositiveMax'
  • testsuite/openmodelica/basemodelica/Record1.mo

    rd5dbbd9b rc8e35cd  
    1818
    1919// Result:
     20// //! base 0.1.0
    2021// package 'Record1'
    2122//   record 'R'
  • testsuite/openmodelica/basemodelica/Record2.mo

    rd5dbbd9b rc8e35cd  
    2121
    2222// Result:
     23// //! base 0.1.0
    2324// package 'Record2'
    2425//   record 'R'
  • testsuite/openmodelica/basemodelica/SD.mo

    r77614c7 rc8e35cd  
    4343
    4444// Result:
     45// //! base 0.1.0
    4546// package 'SD'
    4647//   model 'SD'
  • testsuite/openmodelica/basemodelica/SimpleCoolingCycle.mo

    r46a181d rc8e35cd  
    5555
    5656// Result:
     57// //! base 0.1.0
    5758// package 'SimpleCoolingCycle'
    5859//   function 'SimpleCoolingCycle.heatExchange_CounterFlowNTU.MediumA.specificHeatCapacityCp'
  • testsuite/openmodelica/basemodelica/Tables.mos

    r46a181d rc8e35cd  
    2828// true
    2929// true
    30 // "[openmodelica/basemodelica/Tables.mo:32:3-46:43:writable] Warning: Pure function ''Test33'.'Modelica.Utilities.Strings.isEmpty'' contains a call to impure function ''Test33'.'Modelica.Utilities.Strings.Advanced.skipWhiteSpace''.
     30// "[openmodelica/basemodelica/Tables.mo:33:3-47:43:writable] Warning: Pure function ''Test33'.'Modelica.Utilities.Strings.isEmpty'' contains a call to impure function ''Test33'.'Modelica.Utilities.Strings.Advanced.skipWhiteSpace''.
    3131// "
    3232// "Tables_res.mat"
Note: See TracChangeset for help on using the changeset viewer.