Changeset 35a0fde5 in OpenModelica


Ignore:
Timestamp:
2023-03-28T15:58:19+02:00 (13 months ago)
Author:
Per Östlund <perost86@…>
Parents:
92b6780
git-author:
Per Östlund <perost86@…> (03/28/23 15:08:15)
git-committer:
Per Östlund <perost86@…> (03/28/23 15:58:19)
Message:

Fix derived modifiers in getModelInstance

  • Dump the modifier of a short class definition on the extends element instead of on the class itself, so that short and long class definitions are dumped in the same way.

Fixes #9519

Files:
1 added
8 edited

Legend:

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

    r00c7cfda r35a0fde5  
    836836  function getDerivedNode
    837837    input InstNode node;
     838    input Boolean recursive = true;
    838839    output InstNode derived;
    839840  algorithm
    840841    derived := match node
    841       case CLASS_NODE(nodeType = InstNodeType.BASE_CLASS(parent = derived))
    842         then getDerivedNode(derived);
     842      case CLASS_NODE() then getDerivedNode2(node, node.nodeType, recursive);
    843843      else node;
    844844    end match;
    845845  end getDerivedNode;
     846
     847  function getDerivedNode2
     848    input InstNode node;
     849    input InstNodeType ty;
     850    input Boolean recursive;
     851    output InstNode derived;
     852  algorithm
     853    derived := match ty
     854      case InstNodeType.BASE_CLASS() then if recursive then getDerivedNode(ty.parent) else ty.parent;
     855      case InstNodeType.DERIVED_CLASS() then getDerivedNode2(node, ty.ty, recursive);
     856      else node;
     857    end match;
     858  end getDerivedNode2;
    846859
    847860  function updateClass
  • OMCompiler/Compiler/Script/NFApi.mo

    rb37d4a5e r35a0fde5  
    10891089  json := JSON.addPair("restriction",
    10901090    JSON.makeString(Restriction.toString(InstNode.restriction(node))), json);
    1091   json := dumpJSONSCodeMod(SCodeUtil.elementMod(def), scope, json);
    10921091
    10931092  json := JSON.addPairNotNull("prefixes", dumpJSONClassPrefixes(def, node), json);
     
    12251224  InstNode node;
    12261225  SCode.Element cls_def, ext_def;
     1226  SCode.Mod mod;
    12271227algorithm
    12281228  InstanceTree.CLASS(node = node) := ext;
     
    12311231
    12321232  json := JSON.addPair("$kind", JSON.makeString("extends"), json);
    1233   json := dumpJSONSCodeMod(SCodeUtil.elementMod(ext_def), node, json);
     1233  json := dumpJSONSCodeMod(getExtendsModifier(ext_def, node), node, json);
    12341234  json := dumpJSONCommentOpt(SCodeUtil.getElementComment(ext_def), node, json);
    12351235
     
    12401240  end if;
    12411241end dumpJSONExtends;
     1242
     1243function getExtendsModifier
     1244  input SCode.Element definition;
     1245  input InstNode node;
     1246  output SCode.Mod mod;
     1247algorithm
     1248  mod := match definition
     1249    case SCode.EXTENDS() then definition.modifications;
     1250    case SCode.CLASS() then SCodeUtil.elementMod(InstNode.definition(InstNode.getDerivedNode(node, recursive = false)));
     1251    else SCode.NOMOD();
     1252  end match;
     1253end getExtendsModifier;
    12421254
    12431255function dumpJSONReplaceableClass
  • doc/instanceAPI/getModelInstance.schema.json

    r3347ee4 r35a0fde5  
    2020      "description": "The class prefixes",
    2121      "$ref": "#/definitions/classPrefixes"
    22     },
    23     "modifiers": {
    24       "description": "Modifier from the SCode",
    25       "type": "#/definitions/scodeModifier"
    2622    },
    2723    "comment": {
  • testsuite/openmodelica/instance-API/GetModelInstanceAttributes1.mos

    rfbe0da1f r35a0fde5  
    4040//         \"name\": \"Angle\",
    4141//         \"restriction\": \"type\",
    42 //         \"modifiers\": {
    43 //           \"quantity\": {
    44 //             \"final\": true,
    45 //             \"$value\": \"\\\"Angle\\\"\"
    46 //           }
    47 //         },
    4842//         \"elements\": [
    4943//           {
    5044//             \"$kind\": \"extends\",
     45//             \"modifiers\": {
     46//               \"quantity\": {
     47//                 \"final\": true,
     48//                 \"$value\": \"\\\"Angle\\\"\"
     49//               }
     50//             },
    5151//             \"baseClass\": \"Real\"
    5252//           }
  • testsuite/openmodelica/instance-API/GetModelInstanceDerived1.mos

    r7ce7c53 r35a0fde5  
    5555//         \"name\": \"RealInput2\",
    5656//         \"restriction\": \"type\",
    57 //         \"modifiers\": {
    58 //           \"start\": \"1.0\"
    59 //         },
    6057//         \"elements\": [
    6158//           {
    6259//             \"$kind\": \"extends\",
     60//             \"modifiers\": {
     61//               \"start\": \"1.0\"
     62//             },
    6363//             \"baseClass\": {
    6464//               \"name\": \"RealInput\",
  • testsuite/openmodelica/instance-API/GetModelInstanceDerived2.mos

    r7ce7c53 r35a0fde5  
    4040//   \"name\": \"RealInput2\",
    4141//   \"restriction\": \"type\",
    42 //   \"modifiers\": {
    43 //     \"start\": \"1.0\"
    44 //   },
    4542//   \"elements\": [
    4643//     {
    4744//       \"$kind\": \"extends\",
     45//       \"modifiers\": {
     46//         \"start\": \"1.0\"
     47//       },
    4848//       \"baseClass\": {
    4949//         \"name\": \"RealInput\",
  • testsuite/openmodelica/instance-API/GetModelInstanceExtends3.mos

    rfbe0da1f r35a0fde5  
    88loadString("
    99  type MyReal
    10     extends Real;
     10    extends Real(start = 1.0);
    1111  end MyReal;
    1212
    1313  model M
    14     MyReal x;
     14    MyReal x(unit = \"m\");
    1515  end M;
    1616");
     
    3535//           {
    3636//             \"$kind\": \"extends\",
     37//             \"modifiers\": {
     38//               \"start\": \"1.0\"
     39//             },
    3740//             \"baseClass\": \"Real\"
    3841//           }
     
    4548//           \"columnEnd\": 13
    4649//         }
     50//       },
     51//       \"modifiers\": {
     52//         \"unit\": \"\\\"m\\\"\"
    4753//       }
    4854//     }
  • testsuite/openmodelica/instance-API/Makefile

    rb37d4a5e r35a0fde5  
    2424GetModelInstanceDerived1.mos \
    2525GetModelInstanceDerived2.mos \
     26GetModelInstanceDerived3.mos \
    2627GetModelInstanceDuplicate1.mos \
    2728GetModelInstanceEnum1.mos \
Note: See TracChangeset for help on using the changeset viewer.