Changeset c62eaf3 in OpenModelica


Ignore:
Timestamp:
2022-05-19T12:30:41+02:00 (2 years ago)
Author:
Per Östlund <perost86@…>
Parents:
e6238a1
git-author:
Per Östlund <perost86@…> (05/19/22 12:28:47)
git-committer:
Per Östlund <perost86@…> (05/19/22 12:30:41)
Message:

Dump components recursively in instance API

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • OMCompiler/Compiler/Script/NFApi.mo

    rdfa5c6bb rc62eaf3  
    843843  record COMPONENT
    844844    InstNode node;
     845    InstanceTree cls;
    845846  end COMPONENT;
    846847
     
    850851    list<InstanceTree> components;
    851852  end CLASS;
     853
     854  record EMPTY
     855  end EMPTY;
    852856end InstanceTree;
    853857
     
    880884  output InstanceTree tree;
    881885protected
     886  Class cls;
    882887  ClassTree cls_tree;
    883888  list<InstanceTree> exts, components;
    884889  array<InstNode> ext_nodes;
    885890algorithm
    886   cls_tree := Class.classTree(InstNode.getClass(node));
     891  cls := InstNode.getClass(node);
     892
     893  if Class.isBuiltin(cls) then
     894    tree := InstanceTree.EMPTY();
     895    return;
     896  end if;
     897
     898  cls_tree := Class.classTree(cls);
    887899
    888900  tree := match cls_tree
     
    906918  input Mutable<InstNode> compNode;
    907919  output InstanceTree tree;
    908 algorithm
    909   tree := InstanceTree.COMPONENT(Mutable.access(compNode));
     920protected
     921  InstNode node;
     922  InstanceTree cls;
     923algorithm
     924  node := Mutable.access(compNode);
     925  cls := buildInstanceTree(InstNode.classScope(node));
     926  tree := InstanceTree.COMPONENT(node, cls);
    910927end buildInstanceTreeComponent;
    911928
     
    919936  Sections sections;
    920937  Option<SCode.Comment> cmt;
     938  JSON j;
    921939algorithm
    922940  InstanceTree.CLASS(node = node, exts = exts, components = comps) := tree;
     
    937955  if root then
    938956    sections := Class.getSections(InstNode.getClass(node));
    939     json := JSON.addPair("connections", dumpJSONConnections(sections), json);
    940     json := JSON.addPair("replaceable", dumpJSONReplaceableElements(node), json);
     957    j := dumpJSONConnections(sections);
     958    if not JSON.isNull(j) then
     959      json := JSON.addPair("connections", j, json);
     960    end if;
     961
     962    j := dumpJSONReplaceableElements(node);
     963    if not JSON.isNull(j) then
     964      json := JSON.addPair("replaceable", j, json);
     965    end if;
    941966  end if;
    942967end dumpJSONInstanceTree;
     
    9831008  SCode.Comment cmt;
    9841009  SCode.Annotation ann;
    985 algorithm
    986   InstanceTree.COMPONENT(node = node) := component;
     1010  InstanceTree cls;
     1011algorithm
     1012  InstanceTree.COMPONENT(node = node, cls = cls) := component;
    9871013  node := InstNode.resolveOuter(node);
    9881014  comp := InstNode.component(node);
     
    9921018    case (Component.TYPED_COMPONENT(), SCode.Element.COMPONENT())
    9931019      algorithm
    994         json := JSON.addPair("type", dumpJSONTypeName(comp.ty), json);
     1020        json := JSON.addPair("type", dumpJSONComponentType(cls, comp.ty), json);
    9951021
    9961022        if Type.isArray(comp.ty) then
     
    10281054  end match;
    10291055end dumpJSONComponent;
     1056
     1057function dumpJSONComponentType
     1058  input InstanceTree cls;
     1059  input Type ty;
     1060  output JSON json;
     1061algorithm
     1062  json := match cls
     1063    case InstanceTree.CLASS() then dumpJSONInstanceTree(cls);
     1064    else dumpJSONTypeName(ty);
     1065  end match;
     1066end dumpJSONComponentType;
    10301067
    10311068function dumpJSONTypeName
     
    11641201function dumpJSONConnections
    11651202  input Sections sections;
    1166   output JSON json = JSON.emptyArray();
     1203  output JSON json = JSON.makeNull();
    11671204algorithm
    11681205  () := match sections
     
    11961233function dumpJSONReplaceableElements
    11971234  input InstNode clsNode;
    1198   output JSON json = JSON.emptyArray();
     1235  output JSON json = JSON.makeNull();
    11991236protected
    12001237  ClassTree cls_tree;
  • testsuite/openmodelica/instance-API/GetModelInstanceAnnotation1.mos

    rdfa5c6bb rc62eaf3  
    3535//       }
    3636//     }
    37 //   },
    38 //   \"connections\": [
    39 //
    40 //   ],
    41 //   \"replaceable\": [
    42 //
    43 //   ]
     37//   }
    4438// }"
    4539// endResult
  • testsuite/openmodelica/instance-API/GetModelInstanceAttributes1.mos

    r4cb8721 rc62eaf3  
    5454//       }
    5555//     }
    56 //   },
    57 //   \"connections\": [
    58 //
    59 //   ],
    60 //   \"replaceable\": [
    61 //
    62 //   ]
     56//   }
    6357// }"
    6458// endResult
  • testsuite/openmodelica/instance-API/GetModelInstanceComment1.mos

    raa8243e0 rc62eaf3  
    1818// "{
    1919//   \"name\": \"M\",
    20 //   \"comment\": \"A class\",
    21 //   \"connections\": [
    22 //
    23 //   ],
    24 //   \"replaceable\": [
    25 //
    26 //   ]
     20//   \"comment\": \"A class\"
    2721// }"
    2822// endResult
  • testsuite/openmodelica/instance-API/GetModelInstanceConnection1.mos

    rdfa5c6bb rc62eaf3  
    3737//       \"components\": {
    3838//         \"c2\": {
    39 //           \"type\": \"C\",
     39//           \"type\": {
     40//             \"name\": \"C\",
     41//             \"components\": {
     42//               \"f\": {
     43//                 \"type\": \"Real\",
     44//                 \"modifier\": \"\",
     45//                 \"prefixes\": {
     46//                   \"public\": true,
     47//                   \"final\": false,
     48//                   \"inner\": false,
     49//                   \"outer\": false,
     50//                   \"replaceable\": false,
     51//                   \"redeclare\": false,
     52//                   \"connector\": \"flow\",
     53//                   \"variability\": \"\",
     54//                   \"direction\": \"\"
     55//                 }
     56//               },
     57//               \"e\": {
     58//                 \"type\": \"Real\",
     59//                 \"modifier\": \"\",
     60//                 \"prefixes\": {
     61//                   \"public\": true,
     62//                   \"final\": false,
     63//                   \"inner\": false,
     64//                   \"outer\": false,
     65//                   \"replaceable\": false,
     66//                   \"redeclare\": false,
     67//                   \"connector\": \"\",
     68//                   \"variability\": \"\",
     69//                   \"direction\": \"\"
     70//                 }
     71//               }
     72//             }
     73//           },
    4074//           \"modifier\": \"\",
    4175//           \"prefixes\": {
     
    5286//         },
    5387//         \"c1\": {
    54 //           \"type\": \"C\",
     88//           \"type\": {
     89//             \"name\": \"C\",
     90//             \"components\": {
     91//               \"f\": {
     92//                 \"type\": \"Real\",
     93//                 \"modifier\": \"\",
     94//                 \"prefixes\": {
     95//                   \"public\": true,
     96//                   \"final\": false,
     97//                   \"inner\": false,
     98//                   \"outer\": false,
     99//                   \"replaceable\": false,
     100//                   \"redeclare\": false,
     101//                   \"connector\": \"flow\",
     102//                   \"variability\": \"\",
     103//                   \"direction\": \"\"
     104//                 }
     105//               },
     106//               \"e\": {
     107//                 \"type\": \"Real\",
     108//                 \"modifier\": \"\",
     109//                 \"prefixes\": {
     110//                   \"public\": true,
     111//                   \"final\": false,
     112//                   \"inner\": false,
     113//                   \"outer\": false,
     114//                   \"replaceable\": false,
     115//                   \"redeclare\": false,
     116//                   \"connector\": \"\",
     117//                   \"variability\": \"\",
     118//                   \"direction\": \"\"
     119//                 }
     120//               }
     121//             }
     122//           },
    55123//           \"modifier\": \"\",
    56124//           \"prefixes\": {
     
    71139//   \"components\": {
    72140//     \"c3\": {
    73 //       \"type\": \"C\",
     141//       \"type\": {
     142//         \"name\": \"C\",
     143//         \"components\": {
     144//           \"f\": {
     145//             \"type\": \"Real\",
     146//             \"modifier\": \"\",
     147//             \"prefixes\": {
     148//               \"public\": true,
     149//               \"final\": false,
     150//               \"inner\": false,
     151//               \"outer\": false,
     152//               \"replaceable\": false,
     153//               \"redeclare\": false,
     154//               \"connector\": \"flow\",
     155//               \"variability\": \"\",
     156//               \"direction\": \"\"
     157//             }
     158//           },
     159//           \"e\": {
     160//             \"type\": \"Real\",
     161//             \"modifier\": \"\",
     162//             \"prefixes\": {
     163//               \"public\": true,
     164//               \"final\": false,
     165//               \"inner\": false,
     166//               \"outer\": false,
     167//               \"replaceable\": false,
     168//               \"redeclare\": false,
     169//               \"connector\": \"\",
     170//               \"variability\": \"\",
     171//               \"direction\": \"\"
     172//             }
     173//           }
     174//         }
     175//       },
    74176//       \"modifier\": \"\",
    75177//       \"prefixes\": {
     
    104206//       \"rhs\": \"c2\"
    105207//     }
    106 //   ],
    107 //   \"replaceable\": [
    108 //
    109208//   ]
    110209// }"
  • testsuite/openmodelica/instance-API/GetModelInstanceDuplicate1.mos

    r4cb8721 rc62eaf3  
    6161//       }
    6262//     }
    63 //   },
    64 //   \"connections\": [
    65 //
    66 //   ],
    67 //   \"replaceable\": [
    68 //
    69 //   ]
     63//   }
    7064// }"
    7165// endResult
  • testsuite/openmodelica/instance-API/GetModelInstanceReplaceable1.mos

    r4cb8721 rc62eaf3  
    2626//   \"components\": {
    2727//     \"m\": {
    28 //       \"type\": \"M\",
     28//       \"type\": {
     29//         \"name\": \"M\",
     30//         \"components\": {
     31//           \"x\": {
     32//             \"type\": \"Real\",
     33//             \"modifier\": \"\",
     34//             \"prefixes\": {
     35//               \"public\": true,
     36//               \"final\": false,
     37//               \"inner\": false,
     38//               \"outer\": false,
     39//               \"replaceable\": false,
     40//               \"redeclare\": false,
     41//               \"connector\": \"\",
     42//               \"variability\": \"\",
     43//               \"direction\": \"\"
     44//             }
     45//           }
     46//         }
     47//       },
    2948//       \"modifier\": \"\",
    3049//       \"prefixes\": {
     
    5978//     }
    6079//   },
    61 //   \"connections\": [
    62 //
    63 //   ],
    6480//   \"replaceable\": [
    6581//     {
Note: See TracChangeset for help on using the changeset viewer.