From 8532b2d9bcc92d8491bbd86f33774a3dfd5d269a Mon Sep 17 00:00:00 2001 From: Hans Olsson Date: Thu, 9 Feb 2023 11:30:58 +0100 Subject: [PATCH] Clarify encapsulated. (#3282) * 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 #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 --- chapters/classes.tex | 11 +++++------ chapters/scoping.tex | 4 ++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/chapters/classes.tex b/chapters/classes.tex index ab89615ef..2973e490a 100644 --- a/chapters/classes.tex +++ b/chapters/classes.tex @@ -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: @@ -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 diff --git a/chapters/scoping.tex b/chapters/scoping.tex index ea9fa26af..0af8f3c24 100644 --- a/chapters/scoping.tex +++ b/chapters/scoping.tex @@ -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} @@ -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.