Clingo C API
C API for clingo providing high level functions to control grounding and solving.
Classes | Typedefs | Enumerations | Variables
Abstract Syntax Trees Version 2

Detailed Description

Functions and data structures to work with program ASTs.

Classes

struct  clingo_ast_attribute_names
 Struct to map attributes to their string representation. More...
 
struct  clingo_ast_argument
 Struct to define an argument that consists of a name and a type. More...
 
struct  clingo_ast_constructor
 A lists of required attributes to construct an AST. More...
 
struct  clingo_ast_constructors
 Struct to map AST types to lists of required attributes to construct ASTs. More...
 

Typedefs

typedef int clingo_ast_theory_sequence_type_t
 Corresponding type to clingo_ast_theory_sequence_type_e.
 
typedef int clingo_ast_comparison_operator_t
 Corresponding type to clingo_ast_comparison_operator_e.
 
typedef int clingo_ast_sign_t
 Corresponding type to clingo_ast_sign_t.
 
typedef int clingo_ast_unary_operator_t
 Corresponding type to clingo_ast_unary_operator_e.
 
typedef int clingo_ast_binary_operator_t
 Corresponding type to clingo_ast_binary_operator_e.
 
typedef int clingo_ast_aggregate_function_t
 Corresponding type to clingo_ast_aggregate_function_e.
 
typedef int clingo_ast_theory_operator_type_t
 Corresponding type to clingo_ast_theory_operator_type_e.
 
typedef int clingo_ast_theory_atom_definition_type_t
 Corresponding type to clingo_ast_theory_atom_definition_type_e.
 
typedef int clingo_ast_type_t
 Corresponding type to clingo_ast_type_e.
 
typedef int clingo_ast_attribute_type_t
 Corresponding type to clingo_ast_attribute_type.
 
typedef int clingo_ast_attribute_t
 Corresponding type to clingo_ast_attribute_e.
 
typedef struct clingo_ast_attribute_names clingo_ast_attribute_names_t
 Struct to map attributes to their string representation.
 
typedef struct clingo_ast_argument clingo_ast_argument_t
 Struct to define an argument that consists of a name and a type.
 
typedef struct clingo_ast_constructor clingo_ast_constructor_t
 A lists of required attributes to construct an AST.
 
typedef struct clingo_ast_constructors clingo_ast_constructors_t
 Struct to map AST types to lists of required attributes to construct ASTs.
 
typedef struct clingo_ast clingo_ast_t
 This struct provides a view to nodes in the AST.
 
typedef struct clingo_program_builder clingo_program_builder_t
 Object to build non-ground programs.
 

Enumerations

enum  clingo_ast_theory_sequence_type_e { clingo_ast_theory_sequence_type_tuple, clingo_ast_theory_sequence_type_list, clingo_ast_theory_sequence_type_set }
 Enumeration of theory sequence types. More...
 
enum  clingo_ast_comparison_operator_e {
  clingo_ast_comparison_operator_greater_than = 0, clingo_ast_comparison_operator_less_than = 1, clingo_ast_comparison_operator_less_equal = 2, clingo_ast_comparison_operator_greater_equal = 3,
  clingo_ast_comparison_operator_not_equal = 4, clingo_ast_comparison_operator_equal = 5
}
 Enumeration of comparison relations. More...
 
enum  clingo_ast_sign_e { clingo_ast_sign_no_sign = 0, clingo_ast_sign_negation = 1, clingo_ast_sign_double_negation = 2 }
 Enumeration of signs. More...
 
enum  clingo_ast_unary_operator_e { clingo_ast_unary_operator_minus = 0, clingo_ast_unary_operator_negation = 1, clingo_ast_unary_operator_absolute = 2 }
 Enumeration of unary operators. More...
 
enum  clingo_ast_binary_operator_e {
  clingo_ast_binary_operator_xor = 0, clingo_ast_binary_operator_or = 1, clingo_ast_binary_operator_and = 2, clingo_ast_binary_operator_plus = 3,
  clingo_ast_binary_operator_minus = 4, clingo_ast_binary_operator_multiplication = 5, clingo_ast_binary_operator_division = 6, clingo_ast_binary_operator_modulo = 7,
  clingo_ast_binary_operator_power = 8
}
 Enumeration of binary operators. More...
 
enum  clingo_ast_aggregate_function_e {
  clingo_ast_aggregate_function_count = 0, clingo_ast_aggregate_function_sum = 1, clingo_ast_aggregate_function_sump = 2, clingo_ast_aggregate_function_min = 3,
  clingo_ast_aggregate_function_max = 4
}
 Enumeration of aggregate functions. More...
 
enum  clingo_ast_theory_operator_type_e { clingo_ast_theory_operator_type_unary = 0, clingo_ast_theory_operator_type_binary_left = 1, clingo_ast_theory_operator_type_binary_right = 2 }
 Enumeration of theory operators. More...
 
enum  clingo_ast_theory_atom_definition_type_e { clingo_ast_theory_atom_definition_type_head = 0, clingo_ast_theory_atom_definition_type_body = 1, clingo_ast_theory_atom_definition_type_any = 2, clingo_ast_theory_atom_definition_type_directive = 3 }
 Enumeration of the theory atom types. More...
 
enum  clingo_ast_type_e {
  clingo_ast_type_id, clingo_ast_type_variable, clingo_ast_type_symbolic_term, clingo_ast_type_unary_operation,
  clingo_ast_type_binary_operation, clingo_ast_type_interval, clingo_ast_type_function, clingo_ast_type_pool,
  clingo_ast_type_csp_product, clingo_ast_type_csp_sum, clingo_ast_type_csp_guard, clingo_ast_type_boolean_constant,
  clingo_ast_type_symbolic_atom, clingo_ast_type_comparison, clingo_ast_type_csp_literal, clingo_ast_type_aggregate_guard,
  clingo_ast_type_conditional_literal, clingo_ast_type_aggregate, clingo_ast_type_body_aggregate_element, clingo_ast_type_body_aggregate,
  clingo_ast_type_head_aggregate_element, clingo_ast_type_head_aggregate, clingo_ast_type_disjunction, clingo_ast_type_disjoint_element,
  clingo_ast_type_disjoint, clingo_ast_type_theory_sequence, clingo_ast_type_theory_function, clingo_ast_type_theory_unparsed_term_element,
  clingo_ast_type_theory_unparsed_term, clingo_ast_type_theory_guard, clingo_ast_type_theory_atom_element, clingo_ast_type_theory_atom,
  clingo_ast_type_literal, 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_rule, clingo_ast_type_definition, clingo_ast_type_show_signature,
  clingo_ast_type_show_term, clingo_ast_type_minimize, clingo_ast_type_script, clingo_ast_type_program,
  clingo_ast_type_external, clingo_ast_type_edge, clingo_ast_type_heuristic, clingo_ast_type_project_atom,
  clingo_ast_type_project_signature, clingo_ast_type_defined, clingo_ast_type_theory_definition
}
 Enumeration of AST types.
 
enum  clingo_ast_attribute_type_e {
  clingo_ast_attribute_type_number = 0, clingo_ast_attribute_type_symbol = 1, clingo_ast_attribute_type_location = 2, clingo_ast_attribute_type_string = 3,
  clingo_ast_attribute_type_ast = 4, clingo_ast_attribute_type_optional_ast = 5, clingo_ast_attribute_type_string_array = 6, clingo_ast_attribute_type_ast_array = 7
}
 Enumeration of attributes types used by the AST. More...
 
enum  clingo_ast_attribute_e {
  clingo_ast_attribute_argument, clingo_ast_attribute_arguments, clingo_ast_attribute_arity, clingo_ast_attribute_atom,
  clingo_ast_attribute_atoms, clingo_ast_attribute_atom_type, clingo_ast_attribute_bias, clingo_ast_attribute_body,
  clingo_ast_attribute_code, clingo_ast_attribute_coefficient, clingo_ast_attribute_comparison, clingo_ast_attribute_condition,
  clingo_ast_attribute_csp, clingo_ast_attribute_elements, clingo_ast_attribute_external, clingo_ast_attribute_external_type,
  clingo_ast_attribute_function, clingo_ast_attribute_guard, clingo_ast_attribute_guards, clingo_ast_attribute_head,
  clingo_ast_attribute_is_default, clingo_ast_attribute_left, clingo_ast_attribute_left_guard, clingo_ast_attribute_literal,
  clingo_ast_attribute_location, clingo_ast_attribute_modifier, clingo_ast_attribute_name, clingo_ast_attribute_node_u,
  clingo_ast_attribute_node_v, clingo_ast_attribute_operator_name, clingo_ast_attribute_operator_type, clingo_ast_attribute_operators,
  clingo_ast_attribute_parameters, clingo_ast_attribute_positive, clingo_ast_attribute_priority, clingo_ast_attribute_right,
  clingo_ast_attribute_right_guard, clingo_ast_attribute_sequence_type, clingo_ast_attribute_sign, clingo_ast_attribute_symbol,
  clingo_ast_attribute_term, clingo_ast_attribute_terms, clingo_ast_attribute_value, clingo_ast_attribute_variable,
  clingo_ast_attribute_weight
}
 Enumeration of attributes used by the AST.
 

Variables

CLINGO_VISIBILITY_DEFAULT clingo_ast_attribute_names_t g_clingo_ast_attribute_names
 A map from attributes to their string representation.
 
CLINGO_VISIBILITY_DEFAULT clingo_ast_constructors_t g_clingo_ast_constructors
 A map from AST types to their constructors. More...
 

Functions to construct ASTs

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_build (clingo_ast_type_t type, clingo_ast_t **ast,...)
 Construct an AST of the given type. More...
 

Functions to manage life time of ASTs

CLINGO_VISIBILITY_DEFAULT void clingo_ast_acquire (clingo_ast_t *ast)
 Increment the reference count of an AST node. More...
 
CLINGO_VISIBILITY_DEFAULT void clingo_ast_release (clingo_ast_t *ast)
 Decrement the reference count of an AST node. More...
 

Functions to copy ASTs

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_copy (clingo_ast_t *ast, clingo_ast_t **copy)
 Deep copy an AST node. More...
 
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_deep_copy (clingo_ast_t *ast, clingo_ast_t **copy)
 Create a shallow copy of an AST node. More...
 

Functions to compare ASTs

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_less_than (clingo_ast_t *a, clingo_ast_t *b)
 Less than compare two AST nodes. More...
 
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_equal (clingo_ast_t *a, clingo_ast_t *b)
 Equality compare two AST nodes. More...
 
CLINGO_VISIBILITY_DEFAULT size_t clingo_ast_hash (clingo_ast_t *ast)
 Compute a hash for an AST node. More...
 

Functions to get convert ASTs to strings

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_to_string_size (clingo_ast_t *ast, size_t *size)
 Get the size of the string representation of an AST node. More...
 
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_to_string (clingo_ast_t *ast, char *string, size_t size)
 Get the string representation of an AST node. More...
 

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. More...
 
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_has_attribute (clingo_ast_t *ast, clingo_ast_attribute_t attribute, bool *has_attribute)
 Check if an AST has the given attribute. More...
 
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_type (clingo_ast_t *ast, clingo_ast_attribute_t attribute, clingo_ast_attribute_type_t *type)
 Get the type of the given AST. More...
 

Functions to get/set numeric attributes of ASTs

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_get_number (clingo_ast_t *ast, clingo_ast_attribute_t attribute, int *value)
 Get the value of an attribute of type "clingo_ast_attribute_type_number". More...
 
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_set_number (clingo_ast_t *ast, clingo_ast_attribute_t attribute, int value)
 Set the value of an attribute of type "clingo_ast_attribute_type_number". More...
 

Functions to get/set symbolic attributes of ASTs

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 an attribute of type "clingo_ast_attribute_type_symbol". More...
 
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_set_symbol (clingo_ast_t *ast, clingo_ast_attribute_t attribute, clingo_symbol_t value)
 Set the value of an attribute of type "clingo_ast_attribute_type_symbol". More...
 

Functions to get/set location attributes of ASTs

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_get_location (clingo_ast_t *ast, clingo_ast_attribute_t attribute, clingo_location_t *value)
 Get the value of an attribute of type "clingo_ast_attribute_type_location". More...
 
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_set_location (clingo_ast_t *ast, clingo_ast_attribute_t attribute, clingo_location_t const *value)
 Set the value of an attribute of type "clingo_ast_attribute_type_location". More...
 

Functions to get/set string attributes of ASTs

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_get_string (clingo_ast_t *ast, clingo_ast_attribute_t attribute, char const **value)
 Get the value of an attribute of type "clingo_ast_attribute_type_string". More...
 
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_set_string (clingo_ast_t *ast, clingo_ast_attribute_t attribute, char const *value)
 Set the value of an attribute of type "clingo_ast_attribute_type_string". More...
 

Functions to get/set AST attributes of ASTs

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 attribute of type "clingo_ast_attribute_type_ast". More...
 
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_set_ast (clingo_ast_t *ast, clingo_ast_attribute_t attribute, clingo_ast_t *value)
 Set the value of an attribute of type "clingo_ast_attribute_type_ast". More...
 

Functions to get/set optional AST attributes of ASTs

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_get_optional_ast (clingo_ast_t *ast, clingo_ast_attribute_t attribute, clingo_ast_t **value)
 Get the value of an attribute of type "clingo_ast_attribute_type_optional_ast". More...
 
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_set_optional_ast (clingo_ast_t *ast, clingo_ast_attribute_t attribute, clingo_ast_t *value)
 Set the value of an attribute of type "clingo_ast_attribute_type_optional_ast". More...
 

Functions to get/set string array attributes of ASTs

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_get_string_at (clingo_ast_t *ast, clingo_ast_attribute_t attribute, size_t index, char const **value)
 Get the value of an attribute of type "clingo_ast_attribute_type_string_array" at the given index. More...
 
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_set_string_at (clingo_ast_t *ast, clingo_ast_attribute_t attribute, size_t index, char const *value)
 Set the value of an attribute of type "clingo_ast_attribute_type_string_array" at the given index. More...
 
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_delete_string_at (clingo_ast_t *ast, clingo_ast_attribute_t attribute, size_t index)
 Remove an element from an attribute of type "clingo_ast_attribute_type_string_array" at the given index. More...
 
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_size_string_array (clingo_ast_t *ast, clingo_ast_attribute_t attribute, size_t *size)
 Get the size of an attribute of type "clingo_ast_attribute_type_string_array". More...
 
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_insert_string_at (clingo_ast_t *ast, clingo_ast_attribute_t attribute, size_t index, char const *value)
 Insert a value into an attribute of type "clingo_ast_attribute_type_string_array" at the given index. More...
 

Functions to get/set AST array attributes of ASTs

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_get_ast_at (clingo_ast_t *ast, clingo_ast_attribute_t attribute, size_t index, clingo_ast_t **value)
 Get the value of an attribute of type "clingo_ast_attribute_type_ast_array" at the given index. More...
 
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_set_ast_at (clingo_ast_t *ast, clingo_ast_attribute_t attribute, size_t index, clingo_ast_t *value)
 Set the value of an attribute of type "clingo_ast_attribute_type_ast_array" at the given index. More...
 
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_delete_ast_at (clingo_ast_t *ast, clingo_ast_attribute_t attribute, size_t index)
 Remove an element from an attribute of type "clingo_ast_attribute_type_ast_array" at the given index. More...
 
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_size_ast_array (clingo_ast_t *ast, clingo_ast_attribute_t attribute, size_t *size)
 Get the size of an attribute of type "clingo_ast_attribute_type_ast_array". More...
 
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_insert_ast_at (clingo_ast_t *ast, clingo_ast_attribute_t attribute, size_t index, clingo_ast_t *value)
 Insert a value into an attribute of type "clingo_ast_attribute_type_ast_array" at the given index. More...
 

Functions to construct ASTs from strings

typedef bool(* clingo_ast_callback_t) (clingo_ast_t *ast, void *data)
 Callback function to intercept AST nodes. More...
 
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_parse_string (char const *program, clingo_ast_callback_t callback, void *callback_data, clingo_logger_t logger, void *logger_data, unsigned message_limit)
 Parse the given program and return an abstract syntax tree for each statement via a callback. More...
 
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_parse_files (char const *const *files, size_t size, clingo_ast_callback_t callback, void *callback_data, clingo_logger_t logger, void *logger_data, unsigned message_limit)
 Parse the programs in the given list of files and return an abstract syntax tree for each statement via a callback. More...
 

Functions to add ASTs to logic programs

CLINGO_VISIBILITY_DEFAULT bool clingo_program_builder_begin (clingo_program_builder_t *builder)
 Begin building a program. More...
 
CLINGO_VISIBILITY_DEFAULT bool clingo_program_builder_end (clingo_program_builder_t *builder)
 End building a program. More...
 
CLINGO_VISIBILITY_DEFAULT bool clingo_program_builder_add (clingo_program_builder_t *builder, clingo_ast_t *ast)
 Adds a statement to the program. More...
 

Functions to unpool ASts

enum  clingo_ast_unpool_type_e { clingo_ast_unpool_type_condition = 1, clingo_ast_unpool_type_other = 2, clingo_ast_unpool_type_all = 3 }
 Enum to configure unpooling. More...
 
typedef int clingo_ast_unpool_type_bitset_t
 Corresponding type to clingo_ast_unpool_type_e.
 
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_unpool (clingo_ast_t *ast, clingo_ast_unpool_type_bitset_t unpool_type, clingo_ast_callback_t callback, void *callback_data)
 Unpool the given AST. More...
 

Typedef Documentation

◆ clingo_ast_callback_t

typedef bool(* clingo_ast_callback_t) (clingo_ast_t *ast, void *data)

Callback function to intercept AST nodes.

Parameters
[in]astthe AST
[in]dataa user data pointer
Returns
whether the call was successful
Examples:
ast.c.

Enumeration Type Documentation

◆ clingo_ast_aggregate_function_e

Enumeration of aggregate functions.

Enumerator
clingo_ast_aggregate_function_count 

Operator "^".

clingo_ast_aggregate_function_sum 

Operator "?".

clingo_ast_aggregate_function_sump 

Operator "&".

clingo_ast_aggregate_function_min 

Operator "+".

clingo_ast_aggregate_function_max 

Operator "-".

◆ clingo_ast_attribute_type_e

Enumeration of attributes types used by the AST.

Enumerator
clingo_ast_attribute_type_number 

For an attribute of type "int".

clingo_ast_attribute_type_symbol 

For an attribute of type "clingo_ast_symbol_t".

clingo_ast_attribute_type_location 

For an attribute of type "clingo_location_t".

clingo_ast_attribute_type_string 

For an attribute of type "char const *".

clingo_ast_attribute_type_ast 

For an attribute of type "clingo_ast_t *".

clingo_ast_attribute_type_optional_ast 

For an attribute of type "clingo_ast_t *" that can be NULL.

clingo_ast_attribute_type_string_array 

For an attribute of type "char const **".

clingo_ast_attribute_type_ast_array 

For an attribute of type "clingo_ast_t **".

◆ clingo_ast_binary_operator_e

Enumeration of binary operators.

Enumerator
clingo_ast_binary_operator_xor 

Operator "^".

clingo_ast_binary_operator_or 

Operator "?".

clingo_ast_binary_operator_and 

Operator "&".

clingo_ast_binary_operator_plus 

Operator "+".

clingo_ast_binary_operator_minus 

Operator "-".

clingo_ast_binary_operator_multiplication 

Operator "*".

clingo_ast_binary_operator_division 

Operator "/".

clingo_ast_binary_operator_modulo 

Operator "\".

clingo_ast_binary_operator_power 

Operator "**".

◆ clingo_ast_comparison_operator_e

Enumeration of comparison relations.

Enumerator
clingo_ast_comparison_operator_greater_than 

Operator ">".

clingo_ast_comparison_operator_less_than 

Operator "<".

clingo_ast_comparison_operator_less_equal 

Operator "<=".

clingo_ast_comparison_operator_greater_equal 

Operator ">=".

clingo_ast_comparison_operator_not_equal 

Operator "!=".

clingo_ast_comparison_operator_equal 

Operator "==".

◆ clingo_ast_sign_e

Enumeration of signs.

Enumerator
clingo_ast_sign_no_sign 

For positive literals.

clingo_ast_sign_negation 

For negative literals (prefix "not").

clingo_ast_sign_double_negation 

For double negated literals (prefix "not not").

◆ clingo_ast_theory_atom_definition_type_e

Enumeration of the theory atom types.

Enumerator
clingo_ast_theory_atom_definition_type_head 

For theory atoms that can appear in the head.

clingo_ast_theory_atom_definition_type_body 

For theory atoms that can appear in the body.

clingo_ast_theory_atom_definition_type_any 

For theory atoms that can appear in both head and body.

clingo_ast_theory_atom_definition_type_directive 

For theory atoms that must not have a body.

◆ clingo_ast_theory_operator_type_e

Enumeration of theory operators.

Enumerator
clingo_ast_theory_operator_type_unary 

An unary theory operator.

clingo_ast_theory_operator_type_binary_left 

A left associative binary operator.

clingo_ast_theory_operator_type_binary_right 

A right associative binary operator.

◆ clingo_ast_theory_sequence_type_e

Enumeration of theory sequence types.

Enumerator
clingo_ast_theory_sequence_type_tuple 

Theory tuples "(t1,...,tn)".

clingo_ast_theory_sequence_type_list 

Theory lists "[t1,...,tn]".

clingo_ast_theory_sequence_type_set 

Theory sets "{t1,...,tn}".

◆ clingo_ast_unary_operator_e

Enumeration of unary operators.

Enumerator
clingo_ast_unary_operator_minus 

Operator "-".

clingo_ast_unary_operator_negation 

Operator "~".

clingo_ast_unary_operator_absolute 

Operator "|.|".

◆ clingo_ast_unpool_type_e

Enum to configure unpooling.

Enumerator
clingo_ast_unpool_type_condition 

To only unpool conditions of conditional literals.

clingo_ast_unpool_type_other 

To unpool everything except conditions of conditional literals.

clingo_ast_unpool_type_all 

To unpool everything.

Function Documentation

◆ clingo_ast_acquire()

CLINGO_VISIBILITY_DEFAULT void clingo_ast_acquire ( clingo_ast_t ast)

Increment the reference count of an AST node.

Note
All functions that return AST nodes already increment the reference count. The reference count of callback arguments is not incremented.
Parameters
[in]astthe target AST

◆ clingo_ast_attribute_delete_ast_at()

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_delete_ast_at ( clingo_ast_t ast,
clingo_ast_attribute_t  attribute,
size_t  index 
)

Remove an element from an attribute of type "clingo_ast_attribute_type_ast_array" at the given index.

Parameters
[in]astthe target AST
[in]attributethe target attribute
[in]indexthe target index
Returns
whether the call was successful; might set one of the following error codes:

◆ clingo_ast_attribute_delete_string_at()

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_delete_string_at ( clingo_ast_t ast,
clingo_ast_attribute_t  attribute,
size_t  index 
)

Remove an element from an attribute of type "clingo_ast_attribute_type_string_array" at the given index.

Parameters
[in]astthe target AST
[in]attributethe target attribute
[in]indexthe target index
Returns
whether the call was successful; might set one of the following error codes:

◆ clingo_ast_attribute_get_ast()

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 attribute of type "clingo_ast_attribute_type_ast".

Parameters
[in]astthe target AST
[in]attributethe target attribute
[out]valuethe resulting value
Returns
whether the call was successful; might set one of the following error codes:

◆ clingo_ast_attribute_get_ast_at()

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_get_ast_at ( clingo_ast_t ast,
clingo_ast_attribute_t  attribute,
size_t  index,
clingo_ast_t **  value 
)

Get the value of an attribute of type "clingo_ast_attribute_type_ast_array" at the given index.

Parameters
[in]astthe target AST
[in]attributethe target attribute
[in]indexthe target index
[out]valuethe resulting value
Returns
whether the call was successful; might set one of the following error codes:

◆ clingo_ast_attribute_get_location()

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_get_location ( clingo_ast_t ast,
clingo_ast_attribute_t  attribute,
clingo_location_t value 
)

Get the value of an attribute of type "clingo_ast_attribute_type_location".

Parameters
[in]astthe target AST
[in]attributethe target attribute
[out]valuethe resulting value
Returns
whether the call was successful; might set one of the following error codes:

◆ clingo_ast_attribute_get_number()

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_get_number ( clingo_ast_t ast,
clingo_ast_attribute_t  attribute,
int *  value 
)

Get the value of an attribute of type "clingo_ast_attribute_type_number".

Parameters
[in]astthe target AST
[in]attributethe target attribute
[out]valuethe resulting value
Returns
whether the call was successful; might set one of the following error codes:

◆ clingo_ast_attribute_get_optional_ast()

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_get_optional_ast ( clingo_ast_t ast,
clingo_ast_attribute_t  attribute,
clingo_ast_t **  value 
)

Get the value of an attribute of type "clingo_ast_attribute_type_optional_ast".

Note
The value might be "NULL".
Parameters
[in]astthe target AST
[in]attributethe target attribute
[out]valuethe resulting value
Returns
whether the call was successful; might set one of the following error codes:

◆ clingo_ast_attribute_get_string()

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_get_string ( clingo_ast_t ast,
clingo_ast_attribute_t  attribute,
char const **  value 
)

Get the value of an attribute of type "clingo_ast_attribute_type_string".

Parameters
[in]astthe target AST
[in]attributethe target attribute
[out]valuethe resulting value
Returns
whether the call was successful; might set one of the following error codes:

◆ clingo_ast_attribute_get_string_at()

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_get_string_at ( clingo_ast_t ast,
clingo_ast_attribute_t  attribute,
size_t  index,
char const **  value 
)

Get the value of an attribute of type "clingo_ast_attribute_type_string_array" at the given index.

Parameters
[in]astthe target AST
[in]attributethe target attribute
[in]indexthe target index
[out]valuethe resulting value
Returns
whether the call was successful; might set one of the following error codes:

◆ clingo_ast_attribute_get_symbol()

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 an attribute of type "clingo_ast_attribute_type_symbol".

Parameters
[in]astthe target AST
[in]attributethe target attribute
[out]valuethe resulting value
Returns
whether the call was successful; might set one of the following error codes:

◆ clingo_ast_attribute_insert_ast_at()

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_insert_ast_at ( clingo_ast_t ast,
clingo_ast_attribute_t  attribute,
size_t  index,
clingo_ast_t value 
)

Insert a value into an attribute of type "clingo_ast_attribute_type_ast_array" at the given index.

Parameters
[in]astthe target AST
[in]attributethe target attribute
[in]indexthe target index
[in]valuethe value
Returns
whether the call was successful; might set one of the following error codes:
Examples:
ast.c.

◆ clingo_ast_attribute_insert_string_at()

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_insert_string_at ( clingo_ast_t ast,
clingo_ast_attribute_t  attribute,
size_t  index,
char const *  value 
)

Insert a value into an attribute of type "clingo_ast_attribute_type_string_array" at the given index.

Parameters
[in]astthe target AST
[in]attributethe target attribute
[in]indexthe target index
[in]valuethe value
Returns
whether the call was successful; might set one of the following error codes:

◆ clingo_ast_attribute_set_ast()

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_set_ast ( clingo_ast_t ast,
clingo_ast_attribute_t  attribute,
clingo_ast_t value 
)

Set the value of an attribute of type "clingo_ast_attribute_type_ast".

Parameters
[in]astthe target AST
[in]attributethe target attribute
[in]valuethe value
Returns
whether the call was successful; might set one of the following error codes:

◆ clingo_ast_attribute_set_ast_at()

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_set_ast_at ( clingo_ast_t ast,
clingo_ast_attribute_t  attribute,
size_t  index,
clingo_ast_t value 
)

Set the value of an attribute of type "clingo_ast_attribute_type_ast_array" at the given index.

Parameters
[in]astthe target AST
[in]attributethe target attribute
[in]indexthe target index
[in]valuethe value
Returns
whether the call was successful; might set one of the following error codes:

◆ clingo_ast_attribute_set_location()

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_set_location ( clingo_ast_t ast,
clingo_ast_attribute_t  attribute,
clingo_location_t const *  value 
)

Set the value of an attribute of type "clingo_ast_attribute_type_location".

Parameters
[in]astthe target AST
[in]attributethe target attribute
[in]valuethe value
Returns
whether the call was successful; might set one of the following error codes:

◆ clingo_ast_attribute_set_number()

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_set_number ( clingo_ast_t ast,
clingo_ast_attribute_t  attribute,
int  value 
)

Set the value of an attribute of type "clingo_ast_attribute_type_number".

Parameters
[in]astthe target AST
[in]attributethe target attribute
[in]valuethe value
Returns
whether the call was successful; might set one of the following error codes:

◆ clingo_ast_attribute_set_optional_ast()

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_set_optional_ast ( clingo_ast_t ast,
clingo_ast_attribute_t  attribute,
clingo_ast_t value 
)

Set the value of an attribute of type "clingo_ast_attribute_type_optional_ast".

Note
The value might be "NULL".
Parameters
[in]astthe target AST
[in]attributethe target attribute
[in]valuethe value
Returns
whether the call was successful; might set one of the following error codes:

◆ clingo_ast_attribute_set_string()

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_set_string ( clingo_ast_t ast,
clingo_ast_attribute_t  attribute,
char const *  value 
)

Set the value of an attribute of type "clingo_ast_attribute_type_string".

Parameters
[in]astthe target AST
[in]attributethe target attribute
[in]valuethe value
Returns
whether the call was successful; might set one of the following error codes:

◆ clingo_ast_attribute_set_string_at()

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_set_string_at ( clingo_ast_t ast,
clingo_ast_attribute_t  attribute,
size_t  index,
char const *  value 
)

Set the value of an attribute of type "clingo_ast_attribute_type_string_array" at the given index.

Parameters
[in]astthe target AST
[in]attributethe target attribute
[in]indexthe target index
[in]valuethe value
Returns
whether the call was successful; might set one of the following error codes:

◆ clingo_ast_attribute_set_symbol()

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_set_symbol ( clingo_ast_t ast,
clingo_ast_attribute_t  attribute,
clingo_symbol_t  value 
)

Set the value of an attribute of type "clingo_ast_attribute_type_symbol".

Parameters
[in]astthe target AST
[in]attributethe target attribute
[in]valuethe value
Returns
whether the call was successful; might set one of the following error codes:

◆ clingo_ast_attribute_size_ast_array()

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_size_ast_array ( clingo_ast_t ast,
clingo_ast_attribute_t  attribute,
size_t *  size 
)

Get the size of an attribute of type "clingo_ast_attribute_type_ast_array".

Parameters
[in]astthe target AST
[in]attributethe target attribute
[out]sizethe resulting size
Returns
whether the call was successful; might set one of the following error codes:
Examples:
ast.c.

◆ clingo_ast_attribute_size_string_array()

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_size_string_array ( clingo_ast_t ast,
clingo_ast_attribute_t  attribute,
size_t *  size 
)

Get the size of an attribute of type "clingo_ast_attribute_type_string_array".

Parameters
[in]astthe target AST
[in]attributethe target attribute
[out]sizethe resulting size
Returns
whether the call was successful; might set one of the following error codes:

◆ clingo_ast_attribute_type()

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_type ( clingo_ast_t ast,
clingo_ast_attribute_t  attribute,
clingo_ast_attribute_type_t type 
)

Get the type of the given AST.

Parameters
[in]astthe target AST
[in]attributethe target attribute
[out]typethe resulting type
Returns
whether the call was successful; might set one of the following error codes:

◆ clingo_ast_build()

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_build ( clingo_ast_type_t  type,
clingo_ast_t **  ast,
  ... 
)

Construct an AST of the given type.

Note
The arguments corresponding to the given type can be inspected using "g_clingo_ast_constructors.constructors[type]".
Parameters
[in]typethe type of AST to construct
[out]astthe resulting AST
Returns
whether the call was successful; might set one of the following error codes:
Examples:
ast.c.

◆ clingo_ast_copy()

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_copy ( clingo_ast_t ast,
clingo_ast_t **  copy 
)

Deep copy an AST node.

Parameters
[in]astthe AST to copy
[out]copythe resulting AST
Returns
whether the call was successful; might set one of the following error codes:

◆ clingo_ast_deep_copy()

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_deep_copy ( clingo_ast_t ast,
clingo_ast_t **  copy 
)

Create a shallow copy of an AST node.

Parameters
[in]astthe AST to copy
[out]copythe resulting AST
Returns
whether the call was successful; might set one of the following error codes:

◆ clingo_ast_equal()

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_equal ( clingo_ast_t a,
clingo_ast_t b 
)

Equality compare two AST nodes.

Parameters
[in]athe left-hand-side AST
[in]bthe right-hand-side AST
Returns
the result of the comparison

◆ clingo_ast_get_type()

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_get_type ( clingo_ast_t ast,
clingo_ast_type_t type 
)

Get the type of an AST node.

Parameters
[in]astthe target AST
[out]typethe resulting type
Returns
whether the call was successful; might set one of the following error codes:
Examples:
ast.c.

◆ clingo_ast_has_attribute()

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_has_attribute ( clingo_ast_t ast,
clingo_ast_attribute_t  attribute,
bool *  has_attribute 
)

Check if an AST has the given attribute.

Parameters
[in]astthe target AST
[in]attributethe attribute to check
[out]has_attributethe result
Returns
whether the call was successful; might set one of the following error codes:

◆ clingo_ast_hash()

CLINGO_VISIBILITY_DEFAULT size_t clingo_ast_hash ( clingo_ast_t ast)

Compute a hash for an AST node.

Parameters
[in]astthe target AST
Returns
the resulting hash code

◆ clingo_ast_less_than()

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_less_than ( clingo_ast_t a,
clingo_ast_t b 
)

Less than compare two AST nodes.

Parameters
[in]athe left-hand-side AST
[in]bthe right-hand-side AST
Returns
the result of the comparison

◆ clingo_ast_parse_files()

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_parse_files ( char const *const *  files,
size_t  size,
clingo_ast_callback_t  callback,
void *  callback_data,
clingo_logger_t  logger,
void *  logger_data,
unsigned  message_limit 
)

Parse the programs in the given list of files and return an abstract syntax tree for each statement via a callback.

The function follows clingo's handling of files on the command line. Filename "-" is treated as "STDIN" and if an empty list is given, then the parser will read from "STDIN".

Parameters
[in]filesthe beginning of the file name array
[in]sizethe number of file names
[in]callbackthe callback reporting statements
[in]callback_datauser data for the callback
[in]loggercallback to report messages during parsing
[in]logger_datauser data for the logger
[in]message_limitthe maximum number of times the logger is called
Returns
whether the call was successful; might set one of the following error codes:

◆ clingo_ast_parse_string()

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_parse_string ( char const *  program,
clingo_ast_callback_t  callback,
void *  callback_data,
clingo_logger_t  logger,
void *  logger_data,
unsigned  message_limit 
)

Parse the given program and return an abstract syntax tree for each statement via a callback.

Parameters
[in]programthe program in gringo syntax
[in]callbackthe callback reporting statements
[in]callback_datauser data for the callback
[in]loggercallback to report messages during parsing
[in]logger_datauser data for the logger
[in]message_limitthe maximum number of times the logger is called
Returns
whether the call was successful; might set one of the following error codes:
Examples:
ast.c.

◆ clingo_ast_release()

CLINGO_VISIBILITY_DEFAULT void clingo_ast_release ( clingo_ast_t ast)

Decrement the reference count of an AST node.

Note
The node is deleted if the reference count reaches zero.
Parameters
[in]astthe target AST
Examples:
ast.c.

◆ clingo_ast_to_string()

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_to_string ( clingo_ast_t ast,
char *  string,
size_t  size 
)

Get the string representation of an AST node.

Parameters
[in]astthe target AST
[out]stringthe string representation
[out]sizethe size of the string representation
Returns
whether the call was successful; might set one of the following error codes:

◆ clingo_ast_to_string_size()

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_to_string_size ( clingo_ast_t ast,
size_t *  size 
)

Get the size of the string representation of an AST node.

Parameters
[in]astthe target AST
[out]sizethe size of the string representation
Returns
whether the call was successful; might set one of the following error codes:

◆ clingo_ast_unpool()

CLINGO_VISIBILITY_DEFAULT bool clingo_ast_unpool ( clingo_ast_t ast,
clingo_ast_unpool_type_bitset_t  unpool_type,
clingo_ast_callback_t  callback,
void *  callback_data 
)

Unpool the given AST.

Parameters
[in]astthe target AST
[in]unpool_typewhat to unpool
[in]callbackthe callback to report ASTs
[in]callback_datauser data for the callback
Returns
whether the call was successful; might set one of the following error codes:

◆ clingo_program_builder_add()

CLINGO_VISIBILITY_DEFAULT bool clingo_program_builder_add ( clingo_program_builder_t builder,
clingo_ast_t ast 
)

Adds a statement to the program.

Attention
clingo_program_builder_begin() must be called before adding statements and clingo_program_builder_end() must be called after all statements have been added.
Parameters
[in]builderthe target program builder
[in]astthe AST node to add
Returns
whether the call was successful; might set one of the following error codes:
Examples:
ast.c.

◆ clingo_program_builder_begin()

CLINGO_VISIBILITY_DEFAULT bool clingo_program_builder_begin ( clingo_program_builder_t builder)

Begin building a program.

Parameters
[in]builderthe target program builder
Returns
whether the call was successful
Examples:
ast.c.

◆ clingo_program_builder_end()

CLINGO_VISIBILITY_DEFAULT bool clingo_program_builder_end ( clingo_program_builder_t builder)

End building a program.

Parameters
[in]builderthe target program builder
Returns
whether the call was successful
Examples:
ast.c.

Variable Documentation

◆ g_clingo_ast_constructors

CLINGO_VISIBILITY_DEFAULT clingo_ast_constructors_t g_clingo_ast_constructors

A map from AST types to their constructors.

Note
The idea of this variable is to provide enough information to auto-generate code for language bindings.