# loki.types.symbol_table module

Representation of symbol tables and scopes in Loki’s internal representation (IR)

class SymbolAttributes(dtype, **kwargs)

  Bases: `object`

  Representation of a symbol’s attributes, such as data type and declared properties

  It has a fixed `DataType` associated with it, available as property `SymbolAttributes.dtype`.

  Any other properties can be attached on-the-fly, thus allowing to store arbitrary metadata for a symbol, e.g., declaration attributes such as `POINTER`, `ALLOCATABLE`, or the shape of an array, or structural information, e.g., whether a variable is a loop index, argument, etc.

  There is no need to check for the presence of attributes, undefined attributes can be queried and default to None.

  Parameters:

    - dtype (`DataType`) – The data type associated with the symbol

    - **kwargs (optional) – Any attributes that should be stored as properties

  clone(**kwargs)

    Clone the `SymbolAttributes`, optionally overwriting any attributes

    Attributes that should be removed should simply be given as None.

  compare(other, ignore=None)

    Compare `SymbolAttributes` objects while ignoring a set of select attributes.

    Parameters:

      - other (`SymbolAttributes`) – The object to compare with

      - ignore (iterable, optional) – Names of attributes to ignore while comparing.

    Return type:

      bool

class SymbolTable(*args, case_sensitive=False, **kwargs)

  Bases: `dict`

  Lookup table for symbol types that maps symbol names to `SymbolAttributes`

  It is used to store types for declared variables, defined types or imported symbols within their respective scope. If its associated scope is nested into an enclosing scope, it allows to perform recursive look-ups in parent scopes.

  The interface of this table behaves like a `dict`.

  Parameters:

    - parent (`SymbolTable`, optional) – The symbol table of the parent scope for recursive look-ups.

    - case_sensitive (bool, optional) – Respect the case of symbol names in lookups (default: False).

  property parent

    The symbol table of the parent scope

    Return type:

      `SymbolTable` or None

  property case_sensitive

    Indicate if the `SymbolTable` is case-sensitive when looking up names

    Return type:

      bool

  format_lookup_name(name)

    Format a variable name for look-up (e.g., convert to lower case if case-insensitive)

    Parameters:

      name (str) – the name to look up

    Returns:

      the name used for look-ups

    Return type:

      str

  lookup(name, recursive=True)

    Look-up a symbol in the symbol table and return the type or None if not found.

    Parameters:

      - name (str) – Name of the type or symbol

      - recursive (bool, optional) – If no entry by that name is found, try to find it in the table of the parent scope

    Return type:

      `SymbolAttributes` or None

  get(key, default=None)

    Get a symbol’s entry without recursive lookup

    Parameters:

      - key (str) – Name of the type or symbol

      - default (optional) – Return this value if `key` is not found in the table

  setdefault(key, default=None)

    Insert a default value for a key into the table if it does not exist

    Parameters:

      - key (str) – Name of the type or symbol

      - default (optional) – The default value to store for the key. Defaults to `SymbolAttributes(BasicType.DEFERRED)`.

  update(other)

    Update this symbol table with entries from `other`

  clone(**kwargs)

    Create a copy of the symbol table with the option to override individual parameters

    Parameters:

      **kwargs – Any parameters from the constructor of `SymbolTable`

    Returns:

      The clone symbol table with copies of all `SymbolAttributes`

    Return type:

      `SymbolTable`