Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi modification #3545

Merged
merged 16 commits into from
Sep 20, 2024
47 changes: 46 additions & 1 deletion chapters/inheritance.tex
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,10 @@ \subsection{Merging of Modifications}\label{merging-of-modifications}

\subsection{Single Modification}\label{single-modification}

Two arguments of a modification shall not modify the same element, attribute, or description-string. When using qualified names the different qualified names starting with the same identifier are merged into one modifier. If a modifier with a qualified name has the \lstinline!each! or \lstinline!final! prefix, that prefix is only seen as applied to the final part of the name.
Two arguments of a modification shall not modify the same element, attribute, or description-string.
When using qualified names the different qualified names starting with the same identifier are merged into one modifier.
This merged modifier can be described as a purely syntactic rewriting to an equivalent modifier, except in the case of replaceable redeclarations without a constraining type.
HansOlsson marked this conversation as resolved.
Show resolved Hide resolved
If a modifier with a qualified name has the \lstinline!each! or \lstinline!final! prefix, that prefix is only seen as applied to the final part of the name.

\begin{example}
\begin{lstlisting}[language=modelica]
Expand All @@ -434,6 +437,11 @@ \subsection{Single Modification}\label{single-modification}
// Ok, different attributes designated (unit, displayUnit and value)
// identical to:
C4 b(x(final unit = "V", displayUnit = "mV") = 5.0));

C4 c(final x, final x.unit = "V", x.displayUnit = "mV");
// OK, different attributes and "final x" in itself is OK,
// identical to (the final on unit is redundant):
C4 d(final x(final unit = "V", displayUnit = "mV"));
end C3;
\end{lstlisting}

Expand All @@ -452,6 +460,43 @@ \subsection{Single Modification}\label{single-modification}
m1(r = 1.6, r "x")
m1(r = R(), r(y(min = 2)))
\end{lstlisting}

Modifiers can be merged for non-replaceable redeclarations, or replaceable redeclarations with a constraining type.
\begin{lstlisting}[language=modelica]
model Test
model A
replaceable Real x = 1;
end A;

A a(redeclare Real x, x.start = 2);
// Identical to A a(redeclare Real x(start=2));
A a(redeclare replaceable Real x constrainedby Real, x.start = 2);
// Identical to A a(redeclare Real x constrainedby Real(start=2));
end Test;
\end{lstlisting}

For replaceable redeclarations without a constraining type the merging is only conceptual.
HansOlsson marked this conversation as resolved.
Show resolved Hide resolved
\begin{lstlisting}[language=modelica]
model Test
partial model Base
parameter Real p;
end Base;

model Implementation
extends Base;
parameter Real q;
end Implementation;

model A
replaceable Base b constrainedby Base(p=1);
end A;

A a(redeclare replaceable Implementation b, b.q=1);
// This is treated the same as
// A a(redeclare replaceable Implementation b constrainedby Base(q=1));
// This is no longer a syntactic rewrite as it relies on the constrainedby class
end Test;
\end{lstlisting}
\end{example}

\subsection{Modifiers for Array Elements}\label{modifiers-for-array-elements}
Expand Down