Skip to content

Commit 3305f5b

Browse files
authored
Move some annotation API calls to the typed API (#13051)
- Move `getNthComponentAnnotation`, `getComponentAnnotations`, and `getElementAnnotations` to the typed API. - Change `getNthComponentAnnotation` to use the same implementation as `getElementAnnotation` instead of keeping the oddly specific behaviour of only returning the annotations if the first one is a `Placement` annotation.
1 parent fce2b39 commit 3305f5b

File tree

15 files changed

+411
-595
lines changed

15 files changed

+411
-595
lines changed

OMCompiler/Compiler/FrontEnd/ModelicaBuiltin.mo

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3508,6 +3508,18 @@ annotation(
35083508
preferredView="text");
35093509
end getComponentCount;
35103510

3511+
function getNthComponentAnnotation
3512+
input TypeName className;
3513+
input Integer n;
3514+
output Expression result;
3515+
external "builtin";
3516+
annotation(
3517+
Documentation(info="<html>
3518+
<p>Returns the annotation for the n:th component in the given class.</p>
3519+
</html>"),
3520+
preferredView="text");
3521+
end getNthComponentAnnotation;
3522+
35113523
function getElementAnnotation
35123524
input TypeName elementName;
35133525
output String annotationString;
@@ -3554,6 +3566,28 @@ annotation(
35543566
preferredView="text");
35553567
end getInstantiatedParametersAndValues;
35563568

3569+
function getComponentAnnotations
3570+
input TypeName className;
3571+
output Expression result;
3572+
external "builtin";
3573+
annotation(
3574+
Documentation(info="<html>
3575+
<p>Returns the annotations of the components in the given class.</p>
3576+
</html>"),
3577+
preferredView="text");
3578+
end getComponentAnnotations;
3579+
3580+
function getElementAnnotations
3581+
input TypeName className;
3582+
output Expression result;
3583+
external "builtin";
3584+
annotation(
3585+
Documentation(info="<html>
3586+
<p>Returns the annotations of the components and short class definitions in the given class.</p>
3587+
</html>"),
3588+
preferredView="text");
3589+
end getElementAnnotations;
3590+
35573591
function removeExtendsModifiers
35583592
input TypeName className;
35593593
input TypeName baseClassName;

OMCompiler/Compiler/FrontEnd/ValuesUtil.mo

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,6 +1694,10 @@ algorithm
16941694
end matchcontinue;
16951695
end makeArray;
16961696

1697+
function makeEmptyArray
1698+
output Values.Value outValue = Values.Value.ARRAY({}, {0});
1699+
end makeEmptyArray;
1700+
16971701
public function makeStringArray
16981702
"Creates a Values.ARRAY from a list of Strings."
16991703
input list<String> inReals;
@@ -2401,5 +2405,16 @@ algorithm
24012405
end match;
24022406
end fixZeroSizeArray;
24032407

2408+
public function arraySize
2409+
input Values.Value value;
2410+
output Integer size;
2411+
algorithm
2412+
size := match value
2413+
case Values.Value.ARRAY() then listHead(value.dimLst);
2414+
case Values.Value.META_ARRAY() then listLength(value.valueLst);
2415+
else 0;
2416+
end match;
2417+
end arraySize;
2418+
24042419
annotation(__OpenModelica_Interface="frontend");
24052420
end ValuesUtil;

OMCompiler/Compiler/NFFrontEnd/NFModelicaBuiltin.mo

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3762,6 +3762,18 @@ annotation(
37623762
preferredView="text");
37633763
end getComponentCount;
37643764

3765+
function getNthComponentAnnotation
3766+
input TypeName className;
3767+
input Integer n;
3768+
output Expression result;
3769+
external "builtin";
3770+
annotation(
3771+
Documentation(info="<html>
3772+
<p>Returns the annotation for the n:th component in the given class.</p>
3773+
</html>"),
3774+
preferredView="text");
3775+
end getNthComponentAnnotation;
3776+
37653777
function getElementAnnotation
37663778
input TypeName elementName;
37673779
output String annotationString;
@@ -3808,6 +3820,28 @@ annotation(
38083820
preferredView="text");
38093821
end getInstantiatedParametersAndValues;
38103822

3823+
function getComponentAnnotations
3824+
input TypeName className;
3825+
output Expression result;
3826+
external "builtin";
3827+
annotation(
3828+
Documentation(info="<html>
3829+
<p>Returns the annotations of the components in the given class.</p>
3830+
</html>"),
3831+
preferredView="text");
3832+
end getComponentAnnotations;
3833+
3834+
function getElementAnnotations
3835+
input TypeName className;
3836+
output Expression result;
3837+
external "builtin";
3838+
annotation(
3839+
Documentation(info="<html>
3840+
<p>Returns the annotations of the components and short class definitions in the given class.</p>
3841+
</html>"),
3842+
preferredView="text");
3843+
end getElementAnnotations;
3844+
38113845
function removeExtendsModifiers
38123846
input TypeName className;
38133847
input TypeName baseClassName;

OMCompiler/Compiler/Script/CevalScriptBackend.mo

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2113,8 +2113,8 @@ algorithm
21132113
equation
21142114
absynClass = InteractiveUtil.getPathedClassInProgram(classpath, SymbolTable.getAbsyn());
21152115
genv = Interactive.getClassEnv(SymbolTable.getAbsyn(), classpath);
2116-
valsLst = list(getComponentInfo(c, genv, isProtected=false) for c in Interactive.getPublicComponentsInClass(absynClass));
2117-
valsLst = listAppend(list(getComponentInfo(c, genv, isProtected=true) for c in Interactive.getProtectedComponentsInClass(absynClass)), valsLst);
2116+
valsLst = list(getComponentInfo(c, genv, isProtected=false) for c in InteractiveUtil.getPublicComponentsInClass(absynClass));
2117+
valsLst = listAppend(list(getComponentInfo(c, genv, isProtected=true) for c in InteractiveUtil.getProtectedComponentsInClass(absynClass)), valsLst);
21182118
then ValuesUtil.makeArray(List.flatten(valsLst));
21192119

21202120
case ("getComponentsTest",{Values.CODE(Absyn.C_TYPENAME(_))})
@@ -3198,6 +3198,16 @@ algorithm
31983198

31993199
case ("getElements", {Values.CODE(Absyn.C_TYPENAME(classpath)), Values.BOOL(b)})
32003200
then Interactive.getElements(classpath, b, SymbolTable.getAbsyn());
3201+
3202+
case ("getComponentAnnotations", {Values.CODE(Absyn.C_TYPENAME(classpath))})
3203+
then Interactive.getComponentAnnotations(classpath, SymbolTable.getAbsyn());
3204+
3205+
case ("getElementAnnotations", {Values.CODE(Absyn.C_TYPENAME(classpath))})
3206+
then Interactive.getElementAnnotations(classpath, SymbolTable.getAbsyn());
3207+
3208+
case ("getNthComponentAnnotation", {Values.CODE(Absyn.C_TYPENAME(classpath)), Values.INTEGER(n)})
3209+
then Interactive.getNthComponentAnnotation(classpath, n, SymbolTable.getAbsyn());
3210+
32013211
end matchcontinue;
32023212
end cevalInteractiveFunctions4;
32033213

0 commit comments

Comments
 (0)