Clingo
|
Functions and data structures to work with program ASTs. More...
Typedefs | |
typedef int | clingo_ast_type_t |
Corresponding type to clingo_ast_type_e. | |
typedef int | clingo_ast_attribute_t |
Corresponding type to clingo_ast_attribute_e. | |
typedef struct clingo_ast | clingo_ast_t |
This struct provides a view to nodes in the AST. | |
typedef int | clingo_projection_mode_t |
Corresponding type to clingo_projection_mode_e. | |
typedef struct clingo_ast_rewrite_context | clingo_ast_rewrite_context_t |
Context object to rewrite statements. | |
typedef struct clingo_program | clingo_program_t |
Object to store. | |
Enumerations | |
enum | clingo_ast_type_e { clingo_ast_type_projection , clingo_ast_type_term_variable , clingo_ast_type_term_symbolic , clingo_ast_type_term_absolute , clingo_ast_type_term_unary_operation , clingo_ast_type_term_binary_operation , clingo_ast_type_term_tuple , clingo_ast_type_term_function , clingo_ast_type_argument_tuple , clingo_ast_type_unparsed_element , clingo_ast_type_theory_term_variable , clingo_ast_type_theory_term_symbolic , clingo_ast_type_theory_term_tuple , clingo_ast_type_theory_term_function , clingo_ast_type_theory_term_unparsed , clingo_ast_type_left_guard , clingo_ast_type_right_guard , clingo_ast_type_literal_boolean , clingo_ast_type_literal_comparison , clingo_ast_type_literal_symbolic , clingo_ast_type_set_aggregate_element , clingo_ast_type_theory_atom_element , clingo_ast_type_theory_right_guard , clingo_ast_type_body_simple_literal , clingo_ast_type_body_aggregate_element , clingo_ast_type_body_aggregate , clingo_ast_type_body_set_aggregate , clingo_ast_type_body_theory_atom , clingo_ast_type_body_conditional_literal , clingo_ast_type_head_simple_literal , clingo_ast_type_head_aggregate_element , clingo_ast_type_head_aggregate , clingo_ast_type_head_set_aggregate , clingo_ast_type_head_theory_atom , clingo_ast_type_head_conditional_literal , clingo_ast_type_head_disjunction , clingo_ast_type_theory_operator_definition , clingo_ast_type_theory_term_definition , clingo_ast_type_theory_guard_definition , clingo_ast_type_theory_atom_definition , clingo_ast_type_optimize_tuple , clingo_ast_type_optimize_element , clingo_ast_type_edge , clingo_ast_type_program_part , clingo_ast_type_statement_rule , clingo_ast_type_statement_theory , clingo_ast_type_statement_optimize , clingo_ast_type_statement_weak_constraint , clingo_ast_type_statement_show , clingo_ast_type_statement_show_nothing , clingo_ast_type_statement_show_signature , clingo_ast_type_statement_project , clingo_ast_type_statement_project_signature , clingo_ast_type_statement_defined , clingo_ast_type_statement_external , clingo_ast_type_statement_edge , clingo_ast_type_statement_heuristic , clingo_ast_type_statement_script , clingo_ast_type_statement_program , clingo_ast_type_statement_include , clingo_ast_type_statement_const , clingo_ast_type_statement_parts , clingo_ast_type_statement_comment } |
Enumeration of AST types. | |
enum | clingo_ast_attribute_e { clingo_ast_attribute_anonymous , clingo_ast_attribute_arguments , clingo_ast_attribute_arity , clingo_ast_attribute_atom , clingo_ast_attribute_atoms , clingo_ast_attribute_atom_type , clingo_ast_attribute_body , clingo_ast_attribute_comment_type , clingo_ast_attribute_condition , clingo_ast_attribute_precedence , clingo_ast_attribute_elements , clingo_ast_attribute_external , clingo_ast_attribute_external_type , clingo_ast_attribute_function , clingo_ast_attribute_guard , clingo_ast_attribute_head , clingo_ast_attribute_include_type , clingo_ast_attribute_left , clingo_ast_attribute_literal , clingo_ast_attribute_location , clingo_ast_attribute_modifier , clingo_ast_attribute_name , clingo_ast_attribute_operators , clingo_ast_attribute_operator_type , clingo_ast_attribute_optimize_type , clingo_ast_attribute_pool , clingo_ast_attribute_priority , clingo_ast_attribute_relation , clingo_ast_attribute_right , clingo_ast_attribute_script_type , clingo_ast_attribute_sign , clingo_ast_attribute_symbol , clingo_ast_attribute_term , clingo_ast_attribute_terms , clingo_ast_attribute_theory_operator , clingo_ast_attribute_tuple , clingo_ast_attribute_tuple_type , clingo_ast_attribute_u , clingo_ast_attribute_v , clingo_ast_attribute_value , clingo_ast_attribute_weight } |
Enumeration of attributes used by the AST. | |
enum | clingo_projection_mode_e { clingo_projection_mode_disabled = 0 , clingo_projection_mode_anonymous = 1 , clingo_projection_mode_pure = 2 } |
The available projection modes. More... | |
Functions | |
CLINGO_VISIBILITY_DEFAULT bool | clingo_ast_rewrite_context_create (clingo_lib_t *lib, clingo_ast_rewrite_context_t **context) |
Create a new rewrite context. | |
CLINGO_VISIBILITY_DEFAULT void | clingo_ast_rewrite_context_free (clingo_ast_rewrite_context_t *context) |
Free the given rewrite context. | |
CLINGO_VISIBILITY_DEFAULT bool | clingo_ast_rewrite_context_add_param (clingo_ast_rewrite_context_t *context, char const *param, size_t size) |
Protect the given parameter from simplifications. | |
CLINGO_VISIBILITY_DEFAULT void | clingo_ast_rewrite_context_clear_params (clingo_ast_rewrite_context_t *context) |
Remove all previously added parameters. | |
CLINGO_VISIBILITY_DEFAULT bool | clingo_ast_rewrite_context_add_theory (clingo_ast_rewrite_context_t *context, clingo_ast_t const *theory) |
Add a theory definition to the rewrite context. | |
CLINGO_VISIBILITY_DEFAULT void | clingo_ast_rewrite_context_set_project_anonymous (clingo_ast_rewrite_context_t *context, bool value) |
Configure whether anonymous variables in negative literals are projected. | |
CLINGO_VISIBILITY_DEFAULT bool | clingo_ast_rewrite_context_get_project_anonymous (clingo_ast_rewrite_context_t *context) |
Return whether anonymous variables in negative literals are projected. | |
CLINGO_VISIBILITY_DEFAULT void | clingo_ast_rewrite_context_set_project_mode (clingo_ast_rewrite_context_t *context, clingo_projection_mode_t value) |
Configure the projection mode. | |
CLINGO_VISIBILITY_DEFAULT clingo_projection_mode_t | clingo_ast_rewrite_context_get_project_mode (clingo_ast_rewrite_context_t *context) |
Get the configured projection mode. | |
CLINGO_VISIBILITY_DEFAULT clingo_lib_t * | clingo_ast_rewrite_context_get_lib (clingo_ast_rewrite_context_t *context) |
Get the library object used to create the context. | |
CLINGO_VISIBILITY_DEFAULT bool | clingo_ast_rewrite (clingo_ast_rewrite_context_t *context, clingo_ast_t *statement, clingo_ast_t ***result, size_t *result_size) |
Rewrite the given statement. | |
CLINGO_VISIBILITY_DEFAULT bool | clingo_control_join (clingo_control_t *control, clingo_program_t const *program) |
Extend the control objects's program with the given one. | |
Functions to create/free ASTs | |
enum | clingo_ast_parse_type_e { clingo_ast_parse_type_term , clingo_ast_parse_type_theory_term , clingo_ast_parse_type_literal , clingo_ast_parse_type_body_literal , clingo_ast_parse_type_head_literal , clingo_ast_parse_type_statement } |
Enumeration of expressions that can be parsed. | |
typedef int | clingo_ast_parse_type_t |
Corresponding type to clingo_ast_parse_type_e. | |
CLINGO_VISIBILITY_DEFAULT bool | clingo_ast_construct (clingo_lib_t *lib, clingo_ast_type_t type, clingo_ast_t **ast,...) |
Construct an AST of the given type. | |
CLINGO_VISIBILITY_DEFAULT bool | clingo_ast_copy (clingo_ast_t *ast, clingo_ast_t **copy) |
Copy the given AST node. | |
CLINGO_VISIBILITY_DEFAULT bool | clingo_ast_parse_expression (clingo_lib_t *lib, clingo_ast_parse_type_t type, char const *string, size_t size, clingo_ast_t **ast) |
Parse a single expression given as string. | |
CLINGO_VISIBILITY_DEFAULT void | clingo_ast_free (clingo_ast_t *ast) |
Free an AST node. | |
CLINGO_VISIBILITY_DEFAULT void | clingo_ast_array_free (clingo_ast_t **ast, size_t size) |
Free an AST array. | |
Functions to scan ASTs | |
typedef bool(* | clingo_ast_callback_t) (clingo_ast_t *ast, void *data) |
A callback to intercept ast's. | |
CLINGO_VISIBILITY_DEFAULT bool | clingo_ast_parse_string (clingo_lib_t *lib, char const *program, size_t size, clingo_control_t *control, clingo_ast_callback_t callback, void *data) |
Parse a program from a string. | |
CLINGO_VISIBILITY_DEFAULT bool | clingo_ast_parse_files (clingo_lib_t *lib, clingo_string_t const *files, size_t size, clingo_control_t *control, clingo_ast_callback_t callback, void *data) |
Parse a program from the given files. | |
Functions to convert ASTs to strings | |
CLINGO_VISIBILITY_DEFAULT bool | clingo_ast_to_string (clingo_ast_t *ast, clingo_string_builder_t *builder) |
Get the string representation of an AST node. | |
Functions to compare ASTs | |
CLINGO_VISIBILITY_DEFAULT int | clingo_ast_compare (clingo_ast_t *a, clingo_ast_t *b) |
Less than compare two AST nodes. | |
CLINGO_VISIBILITY_DEFAULT bool | clingo_ast_equal (clingo_ast_t *a, clingo_ast_t *b) |
Equality compare two AST nodes. | |
CLINGO_VISIBILITY_DEFAULT size_t | clingo_ast_hash (clingo_ast_t *ast) |
Compute a hash for an AST node. | |
Functions to inspect ASTs | |
CLINGO_VISIBILITY_DEFAULT bool | clingo_ast_get_type (clingo_ast_t *ast, clingo_ast_type_t *type) |
Get the type of an AST node. | |
CLINGO_VISIBILITY_DEFAULT bool | clingo_ast_attribute_get_number (clingo_ast_t *ast, clingo_ast_attribute_t attribute, int *value) |
Get the value of numeric attribute. | |
CLINGO_VISIBILITY_DEFAULT bool | clingo_ast_attribute_get_symbol (clingo_ast_t *ast, clingo_ast_attribute_t attribute, clingo_symbol_t *value) |
Get the value of a symbol attribute. | |
CLINGO_VISIBILITY_DEFAULT bool | clingo_ast_attribute_get_location (clingo_ast_t *ast, clingo_ast_attribute_t attribute, clingo_location_t const **value) |
Get the value of a location attribute. | |
CLINGO_VISIBILITY_DEFAULT bool | clingo_ast_attribute_get_string (clingo_ast_t *ast, clingo_ast_attribute_t attribute, clingo_string_t *value) |
Get the value of a string attribute. | |
CLINGO_VISIBILITY_DEFAULT bool | clingo_ast_attribute_get_string_array (clingo_ast_t *ast, clingo_ast_attribute_t attribute, clingo_string_t const **value, size_t *size) |
Get the value of a string array attribute. | |
CLINGO_VISIBILITY_DEFAULT bool | clingo_ast_attribute_get_symbol_array (clingo_ast_t *ast, clingo_ast_attribute_t attribute, clingo_symbol_t const **value, size_t *size) |
Get the value of a symbol array attribute. | |
CLINGO_VISIBILITY_DEFAULT bool | clingo_ast_attribute_get_ast (clingo_ast_t *ast, clingo_ast_attribute_t attribute, clingo_ast_t **value) |
Get the value of an ast attribute. | |
CLINGO_VISIBILITY_DEFAULT bool | clingo_ast_attribute_get_ast_array (clingo_ast_t *ast, clingo_ast_attribute_t attribute, clingo_ast_t ***value, size_t *size) |
Get the value of an ast array attribute. | |
CLINGO_VISIBILITY_DEFAULT char const * | clingo_ast_type_info_yaml (void) |
Get a description of the AST structure in form of a YAML document. | |
Functions to add ASTs to logic programs | |
CLINGO_VISIBILITY_DEFAULT bool | clingo_program_new (clingo_lib_t *lib, clingo_program_t **program) |
Create an empty non-ground program. | |
CLINGO_VISIBILITY_DEFAULT void | clingo_program_free (clingo_program_t *program) |
Destroy the given program object. | |
CLINGO_VISIBILITY_DEFAULT bool | clingo_program_add (clingo_program_t *program, clingo_ast_t *statement) |
Adds a statement to the program. | |
Functions and data structures to work with program ASTs.
typedef bool(* clingo_ast_callback_t) (clingo_ast_t *ast, void *data) |
A callback to intercept ast's.
[in] | ast | the paresd ast |
[in] | data | the user data of the callback |
CLINGO_VISIBILITY_DEFAULT void clingo_ast_array_free | ( | clingo_ast_t ** | ast, |
size_t | size | ||
) |
Free an AST array.
This also frees the individual ast's in the array using clingo_ast_free.
[in] | ast | the target AST array |
[in] | size | the size of the AST array |
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_get_ast | ( | clingo_ast_t * | ast, |
clingo_ast_attribute_t | attribute, | ||
clingo_ast_t ** | value | ||
) |
Get the value of an ast attribute.
The value will be set to NULL if an optional AST does not have a value.
[in] | ast | the target AST |
[in] | attribute | the target attribute |
[out] | value | the resulting value |
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_get_ast_array | ( | clingo_ast_t * | ast, |
clingo_ast_attribute_t | attribute, | ||
clingo_ast_t *** | value, | ||
size_t * | size | ||
) |
Get the value of an ast array attribute.
[in] | ast | the target AST |
[in] | attribute | the target attribute |
[out] | value | the resulting value |
[out] | size | the size of the array |
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_get_location | ( | clingo_ast_t * | ast, |
clingo_ast_attribute_t | attribute, | ||
clingo_location_t const ** | value | ||
) |
Get the value of a location attribute.
[in] | ast | the target AST |
[in] | attribute | the target attribute |
[out] | value | the resulting value |
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_get_number | ( | clingo_ast_t * | ast, |
clingo_ast_attribute_t | attribute, | ||
int * | value | ||
) |
Get the value of numeric attribute.
[in] | ast | the target AST |
[in] | attribute | the target attribute |
[out] | value | the resulting value |
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_get_string | ( | clingo_ast_t * | ast, |
clingo_ast_attribute_t | attribute, | ||
clingo_string_t * | value | ||
) |
Get the value of a string attribute.
[in] | ast | the target AST |
[in] | attribute | the target attribute |
[out] | value | the resulting value |
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_get_string_array | ( | clingo_ast_t * | ast, |
clingo_ast_attribute_t | attribute, | ||
clingo_string_t const ** | value, | ||
size_t * | size | ||
) |
Get the value of a string array attribute.
[in] | ast | the target AST |
[in] | attribute | the target attribute |
[out] | value | the resulting value |
[out] | size | the size of the array |
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_get_symbol | ( | clingo_ast_t * | ast, |
clingo_ast_attribute_t | attribute, | ||
clingo_symbol_t * | value | ||
) |
Get the value of a symbol attribute.
[in] | ast | the target AST |
[in] | attribute | the target attribute |
[out] | value | the resulting value |
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_get_symbol_array | ( | clingo_ast_t * | ast, |
clingo_ast_attribute_t | attribute, | ||
clingo_symbol_t const ** | value, | ||
size_t * | size | ||
) |
Get the value of a symbol array attribute.
[in] | ast | the target AST |
[in] | attribute | the target attribute |
[out] | value | the resulting value |
[out] | size | the size of the array |
CLINGO_VISIBILITY_DEFAULT int clingo_ast_compare | ( | clingo_ast_t * | a, |
clingo_ast_t * | b | ||
) |
Less than compare two AST nodes.
[in] | a | the left-hand-side AST |
[in] | b | the right-hand-side AST |
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_construct | ( | clingo_lib_t * | lib, |
clingo_ast_type_t | type, | ||
clingo_ast_t ** | ast, | ||
... | |||
) |
Construct an AST of the given type.
[in] | lib | the library object to store symbols |
[in] | type | the type of AST to construct |
[out] | ast | the resulting AST |
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_copy | ( | clingo_ast_t * | ast, |
clingo_ast_t ** | copy | ||
) |
Copy the given AST node.
[in] | ast | the AST to copy |
[out] | copy | the resulting AST |
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_equal | ( | clingo_ast_t * | a, |
clingo_ast_t * | b | ||
) |
Equality compare two AST nodes.
[in] | a | the left-hand-side AST |
[in] | b | the right-hand-side AST |
CLINGO_VISIBILITY_DEFAULT void clingo_ast_free | ( | clingo_ast_t * | ast | ) |
Free an AST node.
[in] | ast | the target AST |
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_get_type | ( | clingo_ast_t * | ast, |
clingo_ast_type_t * | type | ||
) |
Get the type of an AST node.
[in] | ast | the target AST |
[out] | type | the resulting type |
CLINGO_VISIBILITY_DEFAULT size_t clingo_ast_hash | ( | clingo_ast_t * | ast | ) |
Compute a hash for an AST node.
[in] | ast | the target AST |
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_parse_expression | ( | clingo_lib_t * | lib, |
clingo_ast_parse_type_t | type, | ||
char const * | string, | ||
size_t | size, | ||
clingo_ast_t ** | ast | ||
) |
Parse a single expression given as string.
[in] | lib | the library object to store symbols |
[in] | type | the expression type to parse |
[in] | string | the expression to parse |
[in] | size | the size of the string |
[in] | ast | the resulting ast |
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_parse_files | ( | clingo_lib_t * | lib, |
clingo_string_t const * | files, | ||
size_t | size, | ||
clingo_control_t * | control, | ||
clingo_ast_callback_t | callback, | ||
void * | data | ||
) |
Parse a program from the given files.
[in] | lib | the library object to store symbols |
[in] | files | the file paths to read from |
[in] | size | the number of file paths |
[in] | control | optional control object to handle aspif |
[in] | callback | the callback for the ast nodes |
[in] | data | the user data of the callback |
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_parse_string | ( | clingo_lib_t * | lib, |
char const * | program, | ||
size_t | size, | ||
clingo_control_t * | control, | ||
clingo_ast_callback_t | callback, | ||
void * | data | ||
) |
Parse a program from a string.
[in] | lib | the library object to store symbols |
[in] | program | the string to read from |
[in] | size | the size of the string |
[in] | control | optional control object to handle aspif |
[in] | callback | the callback for the ast nodes |
[in] | data | the user data of the callback |
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_rewrite | ( | clingo_ast_rewrite_context_t * | context, |
clingo_ast_t * | statement, | ||
clingo_ast_t *** | result, | ||
size_t * | result_size | ||
) |
Rewrite the given statement.
[in] | context | the context object |
[in] | statement | the statement object |
[out] | result | the resulting rewritten statements |
[out] | result_size | the number of resulting statements |
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_rewrite_context_add_param | ( | clingo_ast_rewrite_context_t * | context, |
char const * | param, | ||
size_t | size | ||
) |
Protect the given parameter from simplifications.
Parameters from const and program statements should be protected.
[in] | context | the context object |
[in] | param | the parameter to protect |
[in] | size | the size of the string |
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_rewrite_context_add_theory | ( | clingo_ast_rewrite_context_t * | context, |
clingo_ast_t const * | theory | ||
) |
Add a theory definition to the rewrite context.
Added definitions are used to rewrite theory atoms.
[in] | context | the context object |
[in] | theory | the theory definition |
CLINGO_VISIBILITY_DEFAULT void clingo_ast_rewrite_context_clear_params | ( | clingo_ast_rewrite_context_t * | context | ) |
Remove all previously added parameters.
[in] | context | the context object |
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_rewrite_context_create | ( | clingo_lib_t * | lib, |
clingo_ast_rewrite_context_t ** | context | ||
) |
Create a new rewrite context.
[in] | lib | the library object to store symbols |
[out] | context | the resulting context object |
CLINGO_VISIBILITY_DEFAULT void clingo_ast_rewrite_context_free | ( | clingo_ast_rewrite_context_t * | context | ) |
Free the given rewrite context.
[in] | context | the context to free |
CLINGO_VISIBILITY_DEFAULT clingo_lib_t * clingo_ast_rewrite_context_get_lib | ( | clingo_ast_rewrite_context_t * | context | ) |
Get the library object used to create the context.
[in] | context | the context object |
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_rewrite_context_get_project_anonymous | ( | clingo_ast_rewrite_context_t * | context | ) |
Return whether anonymous variables in negative literals are projected.
[in] | context | the context object |
CLINGO_VISIBILITY_DEFAULT clingo_projection_mode_t clingo_ast_rewrite_context_get_project_mode | ( | clingo_ast_rewrite_context_t * | context | ) |
Get the configured projection mode.
[in] | context | the context object |
CLINGO_VISIBILITY_DEFAULT void clingo_ast_rewrite_context_set_project_anonymous | ( | clingo_ast_rewrite_context_t * | context, |
bool | value | ||
) |
Configure whether anonymous variables in negative literals are projected.
[in] | context | the context object |
[in] | value | whether to enable projection |
CLINGO_VISIBILITY_DEFAULT void clingo_ast_rewrite_context_set_project_mode | ( | clingo_ast_rewrite_context_t * | context, |
clingo_projection_mode_t | value | ||
) |
Configure the projection mode.
[in] | context | the context object |
[in] | value | the projection mode |
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_to_string | ( | clingo_ast_t * | ast, |
clingo_string_builder_t * | builder | ||
) |
Get the string representation of an AST node.
[in] | ast | the target AST |
[in] | builder | the string builder |
CLINGO_VISIBILITY_DEFAULT char const * clingo_ast_type_info_yaml | ( | void | ) |
Get a description of the AST structure in form of a YAML document.
CLINGO_VISIBILITY_DEFAULT bool clingo_control_join | ( | clingo_control_t * | control, |
clingo_program_t const * | program | ||
) |
Extend the control objects's program with the given one.
After extending the logic program, the corresponding program parts are typically grounded with clingo_control_ground.
[in] | control | the target |
[in] | program | the program to add |
CLINGO_VISIBILITY_DEFAULT bool clingo_program_add | ( | clingo_program_t * | program, |
clingo_ast_t * | statement | ||
) |
Adds a statement to the program.
[in] | program | the target program |
[in] | statement | the statement to add |
CLINGO_VISIBILITY_DEFAULT void clingo_program_free | ( | clingo_program_t * | program | ) |
Destroy the given program object.
[in] | program | the program object |
CLINGO_VISIBILITY_DEFAULT bool clingo_program_new | ( | clingo_lib_t * | lib, |
clingo_program_t ** | program | ||
) |
Create an empty non-ground program.
[in] | lib | the library object |
[out] | program | the program builder object |