Type System Code Generator (cyclus.gentypesystem)

Generates Cyclus Type System bindings.

Module history:

  • 2016-10-12: scopatz: This file used to be called genapi.py in cymetric.
class cyclus.gentypesystem.Indenter(s)

Handles indentations.

class cyclus.gentypesystem.TypeSystem(table, cycver, rawver=None, cpp_typesystem='cpp_typesystem')

A type system for cyclus code generation.

classname(t)

Returns a version of the type name suitable for use in a class name.

convert_to_cpp(x, t)

Converts a Python variable to C++.

Parameters:

x : str

variable name

t : str

variable type

Returns:

decl : str

Declarations needed for conversion, may be many lines.

body : str

Actual conversion implementation, may be many lines.

rtn : str

Return expression.

convert_to_py(x, t)

Converts a C++ variable to python.

Parameters:

x : str

variable name

t : str

variable type

Returns:

decl : str

Declarations needed for conversion, may be many lines.

body : str

Actual conversion implementation, may be many lines.

rtn : str

Return expression.

cython_cpp_name(t)

Returns the C++ name of the type, eg INT -> cpp_typesystem.INT.

cython_type(t)

Returns the Cython spelling of the type.

funcname(t)

Returns a version of the type name suitable for use in a function name.

hold_any_to_py(x, t)

Returns an expression for converting a hold_any object to Python.

new_py_inst(t)

Returns the new instance for the type.

nptype(n)

Returns the numpy type for a normal form element.

py_to_any(a, val, t)

Returns an expression for assigning a Python object (val) to an any object (a).

var_to_cpp(x, t)

Returns an expression for converting a Python object to C++.

var_to_py(x, t)

Returns an expression for converting an object to Python.

cyclus.gentypesystem.code_gen(ts, ns)

Generates code given a type system and a namespace.

cyclus.gentypesystem.cpp_typesystem(ts, ns)

Creates the Cython header that wraps the Cyclus type system.

cyclus.gentypesystem.main(argv=None)

Entry point into the code generation. Accepts list of command line arguments.

cyclus.gentypesystem.parse_args(argv)

Parses typesystem arguments for code generation.

cyclus.gentypesystem.parse_template(s, open_brace='<', close_brace='>', separator=', ')

Takes a string – which may represent a template specialization – and returns the corresponding type. Mostly cribbed from xdress.

cyclus.gentypesystem.safe_output(cmd, shell=False, *args, **kwargs)

Checks that a command successfully runs with/without shell=True. Returns the output.

cyclus.gentypesystem.setup(ns)

Ensure that we are ready to perform code generation. Returns typesystem.

cyclus.gentypesystem.split_template_args(s, open_brace='<', close_brace='>', separator=', ')

Takes a string with template specialization and returns a list of the argument values as strings. Mostly cribbed from xdress.

cyclus.gentypesystem.typesystem_pxd(ts, ns)

Creates the Cython wrapper header for the Cyclus type system.

cyclus.gentypesystem.typesystem_pyx(ts, ns)

Creates the Cython wrapper for the Cyclus type system.