View Source Unifex.CodeGenerator.Utils (Unifex v1.2.0)

Utilities for code generation.

Summary

Functions

Traverses Elixir specification AST and creates C data types serialization with serializers.

Replaces special characters such as: ., -> and array brackets e.g. var_name[i] with underscores.

Sigil used for templating generated code.

Functions

Link to this function

generate_enums_definitions(config, generator, ctx)

View Source
@spec generate_enums_definitions(
  config :: Enumerable.t(),
  generator :: (term(), map() -> Unifex.CodeGenerator.code_t()),
  ctx :: map()
) :: Unifex.CodeGenerator.code_t()
Link to this function

generate_functions(config, generator, ctx)

View Source
@spec generate_functions(
  config :: Enumerable.t(),
  generator :: (term(), map() -> Unifex.CodeGenerator.code_t()),
  ctx :: map()
) :: Unifex.CodeGenerator.code_t()
Link to this function

generate_functions_declarations(config, generator, ctx)

View Source
@spec generate_functions_declarations(
  config :: Enumerable.t(),
  generator :: (term(), map() -> Unifex.CodeGenerator.code_t()),
  ctx :: map()
) :: Unifex.CodeGenerator.code_t()
Link to this function

generate_maybe_unused_args_statements(args)

View Source
@spec generate_maybe_unused_args_statements(args :: [String.t()]) :: [String.t()]
Link to this function

generate_serialization(atom, serializers)

View Source
@spec generate_serialization(
  ast :: Macro.t(),
  serializers :: %{
    arg_serializer:
      (type :: Unifex.CodeGenerator.BaseType.t(), name :: atom() -> output),
    tuple_serializer: ([output] -> output)
  }
) ::
  {output,
   label: atom(),
   arg: {name :: atom(), type :: Unifex.CodeGenerator.BaseType.t()}}
when output: term()

Traverses Elixir specification AST and creates C data types serialization with serializers.

Link to this function

generate_structs_definitions(config, generator, ctx)

View Source
@spec generate_structs_definitions(
  config :: Enumerable.t(),
  generator :: (term(), map() -> Unifex.CodeGenerator.code_t()),
  ctx :: map()
) :: Unifex.CodeGenerator.code_t()
Link to this function

sanitize_var_name(var_name)

View Source
@spec sanitize_var_name(String.t()) :: String.t()

Replaces special characters such as: ., -> and array brackets e.g. var_name[i] with underscores.

In case of arrays var_name[i] results in var_name_i.

@spec sigil_g(String.t(), []) :: String.t()

Sigil used for templating generated code.