Skip to content

Commit

Permalink
Add class restriction to getModelInstance (#9124)
Browse files Browse the repository at this point in the history
  • Loading branch information
perost committed Jun 20, 2022
1 parent 0047718 commit d60a541
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions OMCompiler/Compiler/Script/NFApi.mo
Expand Up @@ -83,6 +83,7 @@ import NFPrefixes.{Variability};
import NFSections.Sections;
import Package = NFPackage;
import Prefixes = NFPrefixes;
import Restriction = NFRestriction;
import Scalarize = NFScalarize;
import SimplifyExp = NFSimplifyExp;
import SimplifyModel = NFSimplifyModel;
Expand Down Expand Up @@ -930,6 +931,8 @@ algorithm
cmt := SCodeUtil.getElementComment(InstNode.definition(node));

json := JSON.addPair("name", dumpJSONNodePath(node), json);
json := JSON.addPair("restriction",
JSON.makeString(Restriction.toString(InstNode.restriction(node))), json);

if not listEmpty(exts) then
json := JSON.addPair("extends", dumpJSONExtends(exts), json);
Expand Down
4 changes: 4 additions & 0 deletions doc/instanceAPI/getModelInstance.schema.json
Expand Up @@ -8,6 +8,10 @@
"description": "The name of the class",
"type": "string"
},
"restriction": {
"description": "The kind of class",
"type": "string"
},
"extends": {
"description": "The extends clauses in the class instance",
"type": "array",
Expand Down
Expand Up @@ -19,6 +19,7 @@ getModelInstance(M, prettyPrint=true);
// true
// "{
// \"name\": \"M\",
// \"restriction\": \"model\",
// \"annotation\": {
// \"Icon\": {
// \"graphics\": [
Expand Down
Expand Up @@ -19,6 +19,7 @@ getModelInstance(M, prettyPrint=true);
// true
// "{
// \"name\": \"M\",
// \"restriction\": \"model\",
// \"annotation\": {
// \"Icon\": {
// \"graphics\": [
Expand Down
Expand Up @@ -19,6 +19,7 @@ getModelInstance(M, prettyPrint = true);
// true
// "{
// \"name\": \"M\",
// \"restriction\": \"model\",
// \"components\": [
// {
// \"name\": \"pi\",
Expand Down
Expand Up @@ -34,9 +34,11 @@ getModelInstance(M, prettyPrint = true);
// true
// "{
// \"name\": \"M\",
// \"restriction\": \"model\",
// \"extends\": [
// {
// \"name\": \"A\",
// \"restriction\": \"model\",
// \"components\": [
// {
// \"name\": \"w\",
Expand Down Expand Up @@ -106,6 +108,7 @@ getModelInstance(M, prettyPrint = true);
// \"name\": \"c\",
// \"type\": {
// \"name\": \"C\",
// \"restriction\": \"connector\",
// \"components\": [
// {
// \"name\": \"e\",
Expand Down
Expand Up @@ -17,6 +17,7 @@ getModelInstance(M, prettyPrint=true);
// true
// "{
// \"name\": \"M\",
// \"restriction\": \"model\",
// \"comment\": \"A class\"
// }"
// endResult
Expand Up @@ -31,14 +31,17 @@ getModelInstance(M, prettyPrint = true);
// true
// "{
// \"name\": \"M\",
// \"restriction\": \"model\",
// \"extends\": [
// {
// \"name\": \"A\",
// \"restriction\": \"model\",
// \"components\": [
// {
// \"name\": \"c1\",
// \"type\": {
// \"name\": \"C\",
// \"restriction\": \"connector\",
// \"components\": [
// {
// \"name\": \"e\",
Expand Down Expand Up @@ -67,6 +70,7 @@ getModelInstance(M, prettyPrint = true);
// \"name\": \"c2\",
// \"type\": {
// \"name\": \"C\",
// \"restriction\": \"connector\",
// \"components\": [
// {
// \"name\": \"e\",
Expand Down Expand Up @@ -99,6 +103,7 @@ getModelInstance(M, prettyPrint = true);
// \"name\": \"c3\",
// \"type\": {
// \"name\": \"C\",
// \"restriction\": \"connector\",
// \"components\": [
// {
// \"name\": \"e\",
Expand Down
Expand Up @@ -22,9 +22,11 @@ getModelInstance(B, prettyPrint = true);
// true
// "{
// \"name\": \"B\",
// \"restriction\": \"model\",
// \"extends\": [
// {
// \"name\": \"A\",
// \"restriction\": \"model\",
// \"components\": [
// {
// \"name\": \"x\",
Expand Down
2 changes: 2 additions & 0 deletions testsuite/openmodelica/instance-API/GetModelInstanceExp1.mos
Expand Up @@ -23,6 +23,7 @@ getModelInstance(M, prettyPrint = true);
// true
// "{
// \"name\": \"M\",
// \"restriction\": \"model\",
// \"components\": [
// {
// \"name\": \"x\",
Expand All @@ -39,6 +40,7 @@ getModelInstance(M, prettyPrint = true);
// \"name\": \"a\",
// \"type\": {
// \"name\": \"A\",
// \"restriction\": \"model\",
// \"components\": [
// {
// \"name\": \"x\",
Expand Down
Expand Up @@ -23,9 +23,11 @@ getModelInstance(M, prettyPrint=true);
// true
// "{
// \"name\": \"M\",
// \"restriction\": \"model\",
// \"extends\": [
// {
// \"name\": \"A\",
// \"restriction\": \"model\",
// \"components\": [
// {
// \"name\": \"x\",
Expand Down
Expand Up @@ -23,6 +23,7 @@ getModelInstance(M, prettyPrint = true);
// true
// "{
// \"name\": \"M\",
// \"restriction\": \"model\",
// \"components\": [
// {
// \"name\": \"x\",
Expand All @@ -39,6 +40,7 @@ getModelInstance(M, prettyPrint = true);
// \"name\": \"m\",
// \"type\": {
// \"name\": \"M\",
// \"restriction\": \"model\",
// \"components\": [
// {
// \"name\": \"x\",
Expand Down
1 change: 1 addition & 0 deletions testsuite/openmodelica/instance-API/test.mos
Expand Up @@ -17,6 +17,7 @@ getModelInstance(M, prettyPrint=true);
// true
// "{
// \"name\": \"M\",
// \"restriction\": \"model\",
// \"annotation\": {
// \"kind\": \"call\",
// \"name\": \"fn\",
Expand Down

0 comments on commit d60a541

Please sign in to comment.