# ffcx.formatting

Compiler stage 5: Code formatting.

This module implements the formatting of UFC code from a given dictionary of generated C++ code for the body of each UFC function.

It relies on templates for UFC code available as part of the module ufcx_utils.

Functions

`format_code`(code) | Format given code in UFC format.
`write_code`(code_h, code_c, prefix, output_dir) | Write code to files.

class ffcx.formatting.CodeBlocks(file_pre: list[tuple[str, str]], integrals: list[tuple[str, str]], forms: list[tuple[str, str]], expressions: list[tuple[str, str]], file_post: list[tuple[str, str]])

  Bases: `NamedTuple`

  Storage of code blocks of the form (declaration, implementation).

  Blocks for integrals, forms and expressions, and start and end of file output

  Create new instance of CodeBlocks(file_pre, integrals, forms, expressions, file_post)

  expressions: list[tuple[str, str]]

    Alias for field number 3

  file_post: list[tuple[str, str]]

    Alias for field number 4

  file_pre: list[tuple[str, str]]

    Alias for field number 0

  forms: list[tuple[str, str]]

    Alias for field number 2

  integrals: list[tuple[str, str]]

    Alias for field number 1

ffcx.formatting.format_code(code: CodeBlocks) → tuple[str, str]

  Format given code in UFC format. Returns two strings with header and source file contents.

ffcx.formatting.write_code(code_h: str, code_c: str, prefix: str, output_dir: str) → None

  Write code to files.