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

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
48 changes: 47 additions & 1 deletion chapters/inheritance.tex
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,11 @@ \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
The latter is described in the example below.
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 +438,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 +461,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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where I typed a comment before but it disappeared. Trying again. I don't find that "only conceptual" explains enough what is going on. Can we formulate it more concretely? From the example it looks like there is still some merging going on. Is it correct then to say that if a redeclaration is also replaceable but does not include its own constranedby-clause, a constrainedby-clause is created using the class specified in the previous constrainedby-clause and the modification added to it? This topic is one of those where I forget the all the minute details if I haven't looked at it in more than a week.

\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