# CodeGenerator class

(Shortest import: `from brian2.codegen.generators import CodeGenerator)`

class brian2.codegen.generators.base.CodeGenerator(variables, variable_indices, owner, iterate_all, codeobj_class, name, template_name, override_conditional_write=None, allows_scalar_write=False)

  Bases: `object`

  Base class for all languages.

  See definition of methods below.

  TODO: more details here

  Methods

  `array_read_write`(statements) | Helper function, gives the set of ArrayVariables that are read from and written to in the series of statements.
  `arrays_helper`(statements) | Combines the two helper functions `array_read_write` and `get_conditional_write_vars`, and updates the `read` set.
  `determine_keywords`() | A dictionary of values that is made available to the templated.
  `get_array_name`(var[, access_data]) | Get a globally unique name for a `ArrayVariable`.
  `get_conditional_write_vars`() | Helper function, returns a dict of mappings `(varname, condition_var_name)` indicating that when `varname` is written to, it should only be when `condition_var_name` is `True`.
  `has_repeated_indices`(statements) | Whether any of the statements potentially uses repeated indices (e.g. pre- or postsynaptic indices).
  `translate`(code, dtype) | Translates an abstract code block into the target language.
  `translate_expression`(expr) | Translate the given expression string into a string in the target language, returns a string.
  `translate_one_statement_sequence`(statements) |
  `translate_statement`(statement) | Translate a single line `Statement` into the target language, returns a string.
  `translate_statement_sequence`(...) | Translate a sequence of `Statement` into the target language, taking care to declare variables, etc.

  Details

  array_read_write(statements)

    Helper function, gives the set of ArrayVariables that are read from and written to in the series of statements. Returns the pair read, write of sets of variable names.

  arrays_helper(statements)

    Combines the two helper functions `array_read_write` and `get_conditional_write_vars`, and updates the `read` set.

  determine_keywords()

    A dictionary of values that is made available to the templated. This is used for example by the `CPPCodeGenerator` to set up all the supporting code

  static get_array_name(var, access_data=True)

    Get a globally unique name for a `ArrayVariable`.

    Parameters:

      var : `ArrayVariable`

      > The variable for which a name should be found.

      access_data : bool, optional

      > For `DynamicArrayVariable` objects, specifying `True` here means the name for the underlying data is returned. If specifying `False`, the name of object itself is returned (e.g. to allow resizing).

      Returns :

      ——- :

      name : str

      > A uniqe name for `var`.

  get_conditional_write_vars()

    Helper function, returns a dict of mappings `(varname, condition_var_name)` indicating that when `varname` is written to, it should only be when `condition_var_name` is `True`.

  has_repeated_indices(statements)

    Whether any of the statements potentially uses repeated indices (e.g. pre- or postsynaptic indices).

  translate(code, dtype)

    Translates an abstract code block into the target language.

  translate_expression(expr)

    Translate the given expression string into a string in the target language, returns a string.

  translate_one_statement_sequence(statements, scalar=False)
  translate_statement(statement)

    Translate a single line `Statement` into the target language, returns a string.

  translate_statement_sequence(scalar_statements, vector_statements)

    Translate a sequence of `Statement` into the target language, taking care to declare variables, etc. if necessary.

    Returns a tuple `(scalar_code, vector_code, kwds)` where `scalar_code` is a list of the lines of code executed before the inner loop, `vector_code` is a list of the lines of code in the inner loop, and `kwds` is a dictionary of values that is made available to the template.