Skip to content

Commit

Permalink
Reorder sections in package-chapter as discussed.
Browse files Browse the repository at this point in the history
  • Loading branch information
HansOlsson committed Sep 9, 2020
1 parent 69de9dc commit 9acfd09
Showing 1 changed file with 63 additions and 63 deletions.
126 changes: 63 additions & 63 deletions chapters/packages.tex
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,70 @@ \subsection{Summary of Rules for Import Clauses}\label{summary-of-rules-for-impo
\item
Multiple qualified import-clauses may not have the same import name.
\end{itemize}
\section{The Modelica Library Path -- MODELICAPATH}\label{the-modelica-library-path-modelicapath}

The top-level scope implicitly contains a number of classes stored
externally. If a top-level name is not found at global scope, a Modelica
translator shall look up additional classes in an ordered list of
library roots, called \lstinline!MODELICAPATH!.

\begin{nonnormative}
The implementation of \lstinline!MODELICAPATH! is tool dependent. In order that a user can work in parallel with different Modelica tools, it is advisable to not
have this list as environment variable, but as a setting in the respective tool. Since \lstinline!MODELICAPATH! is tool dependent, it is not specified in which way
the list of library roots is stored. Typically, on a Windows system \lstinline!MODELICAPATH! is a string with path names separated by `\filename{;}' whereas on a Linux system
it is a string with path names separated by a `\filename{:}'.
\end{nonnormative}

In addition a tool may define an internal list of libraries, since it is
in general not advisable for a program installation to modify global
environment variables. The version information for a library (as defined
in \cref{annotations-for-version-handling}) may also be used during this search to search for a
specific version of the library (e.g.\ if Modelica library version 2.2 is
needed and the first directory in \lstinline!MODELICAPATH! contain Modelica library
version 2.1, whereas the second directory contains Modelica version 2.2,
then Modelica library version 2.2 is loaded from the second directory.).

\begin{nonnormative}
The first part of the path \lstinline!A.B.C! (i.e., \lstinline!A!) is located by searching the ordered list of roots in \lstinline!MODELICAPATH!. If no root contains
\lstinline!A! the lookup fails. If \lstinline!A! has been found in one of the roots, the rest of the path is located in \lstinline!A!; if that fails, the entire lookup
fails without searching for \lstinline!A! in any of the remaining roots in \lstinline!MODELICAPATH!.
\end{nonnormative}

\subsection{Example of Searching MODELICAPATH}\label{example-of-searching-modelicapath}

If during lookup a top-level name is not found in the unnamed top-level
scope, the search continues in the package hierarchies stored in these
directories.

\begin{example}
\Cref{fig:roots} below shows an example \lstinline!MODELICAPATH! = \filename{"C:\textbackslash{}library;C:\textbackslash{}lib1;C:\textbackslash{}lib2"}, with three
directories containing the roots of the package hierarchies \lstinline!Modelica!, \lstinline!MyLib!, and \lstinline!ComplexNumbers!. The first two are represented as
the subdirectories \filename{C:\textbackslash{}library\textbackslash{}Modelica} and \filename{C:\textbackslash{}lib1\textbackslash{}MyLib}, whereas the third is stored
as the file \filename{C:\textbackslash{}lib2\textbackslash{}ComplexNumbers.mo}.

\begin{figure}[H]
\caption{%
Roots of package hierarchies, e.g., \lstinline!Modelica!, \lstinline!MyLib!, and \lstinline!ComplexNumbers! in
\lstinline!MODELICAPATH! = \filename{"C:\textbackslash{}library;C:\textbackslash{}lib1;C:\textbackslash{}lib2"}.
}
\label{fig:roots}
\includegraphics[width=6in,height=2in]{modelicapath}
\end{figure}

Assume that we want to access the package \lstinline!MyLib.Pack2! in \cref{fig:roots} above, e.g.\ through an \lstinline!import!-clause \lstinline!import MyLib.Pack2;!.
During lookup we first try to find a package \lstinline!MyLib! corresponding to the first part of the import name. It is not found in the top-level scope since it has not
previously been loaded into the environment.

Since the name was not found in the top-level scope the search continues in the directories in the \lstinline!MODELICAPATH! in the specified order. For the search to succeed,
there must be a subdirectory \filename{MyLib} or a file \filename{MyLib.mo} in one of the directories mentioned in the \lstinline!MODELICAPATH!. If there is no such
subdirectory or file, the lookup fails. If \filename{MyLib} is found in one of the directories, the rest of the name, in this case \lstinline!Pack2!, is located in
\filename{MyLib}. If that fails, the entire lookup fails without continuing the search in possibly remaining directories.

In this example the name matches the subdirectory named \filename{MyLib} in the second directory \filename{C:\textbackslash{}lib1} mentioned in the \lstinline!MODELICAPATH!.
This subdirectory must have a file \filename{package.mo} containing a definition of the package \lstinline!MyLib!, according to the Modelica rules on how to map a package
hierarchy to the file system. The subpackage \lstinline!Pack2! is stored in its own subdirectory or file in the subdirectory \filename{MyLib}. In this case the search
succeeds and the package \lstinline!MyLib.Pack2! is loaded into the environment.
\end{example}
\section{Mapping Package/Class Structures to a Hierarchical File System}\label{mapping-package-class-structures-to-a-hierarchical-file-system}

Packages/classes may be represented in the hierarchical structure of the
Expand Down Expand Up @@ -280,67 +343,4 @@ \section{External resources}\label{external-resources}
resource than \filename{modelica://Modelica/C.jpg}.
\end{example}

\section{The Modelica Library Path -- MODELICAPATH}\label{the-modelica-library-path-modelicapath}

The top-level scope implicitly contains a number of classes stored
externally. If a top-level name is not found at global scope, a Modelica
translator shall look up additional classes in an ordered list of
library roots, called \lstinline!MODELICAPATH!.

\begin{nonnormative}
The implementation of \lstinline!MODELICAPATH! is tool dependent. In order that a user can work in parallel with different Modelica tools, it is advisable to not
have this list as environment variable, but as a setting in the respective tool. Since \lstinline!MODELICAPATH! is tool dependent, it is not specified in which way
the list of library roots is stored. Typically, on a Windows system \lstinline!MODELICAPATH! is a string with path names separated by `\filename{;}' whereas on a Linux system
it is a string with path names separated by a `\filename{:}'.
\end{nonnormative}

In addition a tool may define an internal list of libraries, since it is
in general not advisable for a program installation to modify global
environment variables. The version information for a library (as defined
in \cref{annotations-for-version-handling}) may also be used during this search to search for a
specific version of the library (e.g.\ if Modelica library version 2.2 is
needed and the first directory in \lstinline!MODELICAPATH! contain Modelica library
version 2.1, whereas the second directory contains Modelica version 2.2,
then Modelica library version 2.2 is loaded from the second directory.).

\begin{nonnormative}
The first part of the path \lstinline!A.B.C! (i.e., \lstinline!A!) is located by searching the ordered list of roots in \lstinline!MODELICAPATH!. If no root contains
\lstinline!A! the lookup fails. If \lstinline!A! has been found in one of the roots, the rest of the path is located in \lstinline!A!; if that fails, the entire lookup
fails without searching for \lstinline!A! in any of the remaining roots in \lstinline!MODELICAPATH!.
\end{nonnormative}

\subsection{Example of Searching MODELICAPATH}\label{example-of-searching-modelicapath}

If during lookup a top-level name is not found in the unnamed top-level
scope, the search continues in the package hierarchies stored in these
directories.

\begin{example}
\Cref{fig:roots} below shows an example \lstinline!MODELICAPATH! = \filename{"C:\textbackslash{}library;C:\textbackslash{}lib1;C:\textbackslash{}lib2"}, with three
directories containing the roots of the package hierarchies \lstinline!Modelica!, \lstinline!MyLib!, and \lstinline!ComplexNumbers!. The first two are represented as
the subdirectories \filename{C:\textbackslash{}library\textbackslash{}Modelica} and \filename{C:\textbackslash{}lib1\textbackslash{}MyLib}, whereas the third is stored
as the file \filename{C:\textbackslash{}lib2\textbackslash{}ComplexNumbers.mo}.

\begin{figure}[H]
\caption{%
Roots of package hierarchies, e.g., \lstinline!Modelica!, \lstinline!MyLib!, and \lstinline!ComplexNumbers! in
\lstinline!MODELICAPATH! = \filename{"C:\textbackslash{}library;C:\textbackslash{}lib1;C:\textbackslash{}lib2"}.
}
\label{fig:roots}
\includegraphics[width=6in,height=2in]{modelicapath}
\end{figure}

Assume that we want to access the package \lstinline!MyLib.Pack2! in \cref{fig:roots} above, e.g.\ through an \lstinline!import!-clause \lstinline!import MyLib.Pack2;!.
During lookup we first try to find a package \lstinline!MyLib! corresponding to the first part of the import name. It is not found in the top-level scope since it has not
previously been loaded into the environment.

Since the name was not found in the top-level scope the search continues in the directories in the \lstinline!MODELICAPATH! in the specified order. For the search to succeed,
there must be a subdirectory \filename{MyLib} or a file \filename{MyLib.mo} in one of the directories mentioned in the \lstinline!MODELICAPATH!. If there is no such
subdirectory or file, the lookup fails. If \filename{MyLib} is found in one of the directories, the rest of the name, in this case \lstinline!Pack2!, is located in
\filename{MyLib}. If that fails, the entire lookup fails without continuing the search in possibly remaining directories.

In this example the name matches the subdirectory named \filename{MyLib} in the second directory \filename{C:\textbackslash{}lib1} mentioned in the \lstinline!MODELICAPATH!.
This subdirectory must have a file \filename{package.mo} containing a definition of the package \lstinline!MyLib!, according to the Modelica rules on how to map a package
hierarchy to the file system. The subpackage \lstinline!Pack2! is stored in its own subdirectory or file in the subdirectory \filename{MyLib}. In this case the search
succeeds and the package \lstinline!MyLib.Pack2! is loaded into the environment.
\end{example}

0 comments on commit 9acfd09

Please sign in to comment.