'import'

import

Information

This information is part of the Modelica Standard Library maintained by the Modelica Association.

Import classes

Examples

class Lookup
  import SI = Modelica.SIunits; // #1
  import Modelica.Math.*; // #2 (Try to avoid wildcard imports,
                          //     consider using #1 or #3  instead!)
  import Modelica.Mechanics.Rotational; // #3

  SI.Torque torque; // due to #1 (Modelica.SIunits.Torque)
  Rotational.Components.Inertia inertia; // due to #3 (Modelica.Mechanics.Rotational.Components.Inertia)
equation
  torque = sin(time); // due to #2 (Modelica.Math.sin)
  ...
end Lookup;

Syntax

class_definition :
   [ encapsulated ]
   [ partial ]
   ( class | model | record | block | connector | type |
     package | function )
   IDENT class_specifier

class_specifier :
   string_comment composition end IDENT
   | "=" base_prefix name [ array_subscripts ] [ class_modification ] comment
   | "=" enumeration "(" ( [enum_list] | ":" ) ")" comment

composition  :
   element_list
   { public element_list |
     protected element_list |
     equation_clause |
     algorithm_clause
   }
   [ external [ language_specification ]
              [ external_function_call ] [ annotation ";" ]
              [ annotation  ";" ] ]

element_list :
   { element ";" | annotation  ";" }

element :
   import_clause |
   extends_clause |
   [ final ]
   [ inner | outer ]
   ( ( class_definition | component_clause) |
     replaceable ( class_definition | component_clause)
        [constraining_clause comment])

import_clause :
   import ( IDENT "=" name | name ["." "*"] ) comment

Description

Using import statements extends the static name lookup to additional import names. The generated import names are:

  • C for import A.B.C;
  • D for import D = A.B.C;
  • C and all other classes in B for import A.B.*;
Note

Especially the last wildcard import statement should be avoided since it might lead to name-lookup conflicts.