Skip to content

Commit

Permalink
Clarify encapsulated. (modelica#3282)
Browse files Browse the repository at this point in the history
* Clarify encapsulated.
Change grammar for two reasons:
* It is type-specifier not IDENT
* For encapsulated we really need the leading "." which is part of type-specifier.
Closes modelica#3270
* Clarify composite name lookup (related to encapsulated).
* Clearer on global name lookup.
* Consistent use of terminology.
* Update chapters/classes.tex
Co-authored-by: Henrik Tidefelt <henrikt@wolfram.com>
  • Loading branch information
HansOlsson committed Feb 9, 2023
1 parent 104367d commit 8532b2d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
11 changes: 5 additions & 6 deletions chapters/classes.tex
Expand Up @@ -644,20 +644,18 @@ \subsection{Short Class Definitions}\label{short-class-definitions}

A class definition of the form
\begin{lstlisting}[language=modelica]
class IDENT1 = IDENT2 class-modification;
class IDENT1 = type-specifier class-modification;
\end{lstlisting}

is identical, except that IDENT2 may be replaceable and for the lexical
is identical, except that \lstinline!type-specifier! (the base-class) may be replaceable and for the lexical
scope of modifiers, where the short class definition does not introduce
an additional lexical scope for modifiers, to the longer form

\begin{lstlisting}[language=modelica]
class IDENT1
extends IDENT2 class-modification;
extends type-specifier class-modification;
end IDENT1;
\end{lstlisting}

An exception to the above is that if the short class definition is declared as \lstinline!encapsulated!, then the modifiers follow the rules for encapsulated classes and cannot be looked up in the enclosing scope.
An exception to the above is that if the short class definition is declared as \lstinline!encapsulated!, then the type-specifier and modifiers follow the rules for encapsulated classes and cannot be looked up in the enclosing scope.

\begin{example}
Demonstrating the difference in scopes:
Expand All @@ -682,6 +680,7 @@ \subsection{Short Class Definitions}\label{short-class-definitions}
$\ldots$
end A;
\end{lstlisting}
The type-specifiers \lstinline!.Resistor! rely on global name lookup (see \ref{composite-name-lookup}), due to the encapsulated restriction.
\end{example}

A short class definition of the form
Expand Down
4 changes: 2 additions & 2 deletions chapters/scoping.tex
Expand Up @@ -96,7 +96,7 @@ \subsection{Composite Name Lookup}\label{composite-name-lookup}
All identifiers of the rest of the name (e.g., \lstinline!B! and \lstinline!B.C!) must be classes.
That is, the composite name is comprised of one or more component names (optionally with indexing), followed by one or more class names.
\item
If the identifier denotes a class, that class is temporarily flattened (as if instantiating a component without modifiers of this class, see \cref{modification-environment}) and using the enclosing classes of the denoted class.
If the identifier denotes a class, that class is temporarily flattened (as if instantiating a component without modifiers of this class, see \cref{modification-environment} and using the enclosing classes of the denoted class).
The rest of the name (e.g., \lstinline!B! or \lstinline!B.C!) is looked up among the declared named elements of the temporary flattened class.
The lookup will only find the element (assuming it exists) in the following cases:
\begin{itemize}
Expand Down Expand Up @@ -146,7 +146,7 @@ \subsection{Global Name Lookup}\label{global-name-lookup}
\item
If the name is simple then the class \lstinline!A! is the result of lookup.
\item
If the name is a composite name then the class \lstinline!A! is temporarily flattened with an empty environment (i.e., no modifiers, see \cref{modification-environment}) and using the enclosing classes of the denoted class.
If the name is a composite name then the class \lstinline!A! is temporarily flattened with an empty environment (i.e., no modifiers, see \cref{modification-environment} and using the enclosing classes of the denoted class).
The rest of the name (e.g., \lstinline!B! or \lstinline!B.C!) is looked up among the declared named elements of the temporary flattened class.
If the class does not satisfy the requirements for a package, the lookup is restricted to encapsulated elements only.
The class we look inside shall not be partial.
Expand Down

0 comments on commit 8532b2d

Please sign in to comment.