Clingo
Loading...
Searching...
No Matches
ast.h
1#ifndef CLINGO_AST_H
2#define CLINGO_AST_H
3
4#include <clingo/core.h>
5#include <clingo/symbol.h>
6
7#ifdef __cplusplus
8extern "C" {
9#endif
10
11typedef struct clingo_control clingo_control_t;
12
24
29
32 // terms
33 clingo_ast_type_format_field_literal,
34 clingo_ast_type_format_field_expression,
35 clingo_ast_type_projection,
36 clingo_ast_type_term_variable,
37 clingo_ast_type_term_symbolic,
38 clingo_ast_type_term_format_string,
39 clingo_ast_type_term_absolute,
40 clingo_ast_type_term_unary_operation,
41 clingo_ast_type_term_binary_operation,
42 clingo_ast_type_term_tuple,
43 clingo_ast_type_term_function,
44 clingo_ast_type_argument_tuple,
45 // theory terms
46 clingo_ast_type_unparsed_element,
47 clingo_ast_type_theory_term_variable,
48 clingo_ast_type_theory_term_symbolic,
49 clingo_ast_type_theory_term_tuple,
50 clingo_ast_type_theory_term_function,
51 clingo_ast_type_theory_term_unparsed,
52 // literals
53 clingo_ast_type_left_guard,
54 clingo_ast_type_right_guard,
55 clingo_ast_type_literal_boolean,
56 clingo_ast_type_literal_comparison,
57 clingo_ast_type_literal_symbolic,
58 // set aggregates and theory atoms
59 clingo_ast_type_set_aggregate_element,
60 clingo_ast_type_theory_atom_element,
61 clingo_ast_type_theory_right_guard,
62 // body literals
63 clingo_ast_type_body_simple_literal,
64 clingo_ast_type_body_aggregate_element,
65 clingo_ast_type_body_aggregate,
66 clingo_ast_type_body_set_aggregate,
67 clingo_ast_type_body_theory_atom,
68 clingo_ast_type_body_conditional_literal,
69 // head literals
70 clingo_ast_type_head_simple_literal,
71 clingo_ast_type_head_aggregate_element,
72 clingo_ast_type_head_aggregate,
73 clingo_ast_type_head_set_aggregate,
74 clingo_ast_type_head_theory_atom,
75 clingo_ast_type_head_conditional_literal,
76 clingo_ast_type_head_disjunction,
77 // theory definition
78 clingo_ast_type_theory_operator_definition,
79 clingo_ast_type_theory_term_definition,
80 clingo_ast_type_theory_guard_definition,
81 clingo_ast_type_theory_atom_definition,
82 // elements
83 clingo_ast_type_optimize_tuple,
84 clingo_ast_type_optimize_element,
85 clingo_ast_type_edge,
86 clingo_ast_type_program_part,
87 // statements
88 clingo_ast_type_statement_rule,
89 clingo_ast_type_statement_theory,
90 clingo_ast_type_statement_optimize,
91 clingo_ast_type_statement_weak_constraint,
92 clingo_ast_type_statement_show,
93 clingo_ast_type_statement_show_nothing,
94 clingo_ast_type_statement_show_signature,
95 clingo_ast_type_statement_project,
96 clingo_ast_type_statement_project_signature,
97 clingo_ast_type_statement_defined,
98 clingo_ast_type_statement_external,
99 clingo_ast_type_statement_edge,
100 clingo_ast_type_statement_heuristic,
101 clingo_ast_type_statement_script,
102 clingo_ast_type_statement_program,
103 clingo_ast_type_statement_include,
104 clingo_ast_type_statement_const,
105 clingo_ast_type_statement_parts,
106 clingo_ast_type_statement_comment
107};
110
113 clingo_ast_attribute_anonymous,
114 clingo_ast_attribute_arguments,
115 clingo_ast_attribute_arity,
116 clingo_ast_attribute_atom,
117 clingo_ast_attribute_atoms,
118 clingo_ast_attribute_atom_type,
119 clingo_ast_attribute_body,
120 clingo_ast_attribute_comment_type,
121 clingo_ast_attribute_condition,
122 clingo_ast_attribute_precedence,
123 clingo_ast_attribute_elements,
124 clingo_ast_attribute_external,
125 clingo_ast_attribute_external_type,
126 clingo_ast_attribute_function,
127 clingo_ast_attribute_guard,
128 clingo_ast_attribute_head,
129 clingo_ast_attribute_include_type,
130 clingo_ast_attribute_left,
131 clingo_ast_attribute_literal,
132 clingo_ast_attribute_location,
133 clingo_ast_attribute_modifier,
134 clingo_ast_attribute_name,
135 clingo_ast_attribute_operators,
136 clingo_ast_attribute_operator_type,
137 clingo_ast_attribute_optimize_type,
138 clingo_ast_attribute_pool,
139 clingo_ast_attribute_priority,
140 clingo_ast_attribute_relation,
141 clingo_ast_attribute_right,
142 clingo_ast_attribute_script_type,
143 clingo_ast_attribute_sign,
144 clingo_ast_attribute_symbol,
145 clingo_ast_attribute_term,
146 clingo_ast_attribute_terms,
147 clingo_ast_attribute_theory_operator,
148 clingo_ast_attribute_tuple,
149 clingo_ast_attribute_tuple_type,
150 clingo_ast_attribute_u,
151 clingo_ast_attribute_v,
152 clingo_ast_attribute_value,
153 clingo_ast_attribute_weight,
154};
155
158
160typedef struct clingo_ast clingo_ast_t;
161
164
171CLINGO_VISIBILITY_DEFAULT bool clingo_ast_construct(clingo_lib_t *lib, clingo_ast_type_t type, clingo_ast_t **ast, ...);
172
178CLINGO_VISIBILITY_DEFAULT bool clingo_ast_copy(clingo_ast_t *ast, clingo_ast_t **copy);
179
182 clingo_ast_parse_type_term,
183 clingo_ast_parse_type_theory_term,
184 clingo_ast_parse_type_literal,
185 clingo_ast_parse_type_body_literal,
186 clingo_ast_parse_type_head_literal,
187 clingo_ast_parse_type_statement,
188};
191
202CLINGO_VISIBILITY_DEFAULT bool clingo_ast_parse_expression(clingo_lib_t *lib, clingo_ast_parse_type_t type,
203 char const *string, size_t size, clingo_ast_t **ast);
204
208CLINGO_VISIBILITY_DEFAULT void clingo_ast_free(clingo_ast_t *ast);
209
216CLINGO_VISIBILITY_DEFAULT void clingo_ast_array_free(clingo_ast_t **ast, size_t size);
217
219
222
228CLINGO_VISIBILITY_DEFAULT bool clingo_ast_to_string(clingo_ast_t *ast, clingo_string_builder_t *builder);
229
231
234
240CLINGO_VISIBILITY_DEFAULT int clingo_ast_compare(clingo_ast_t *a, clingo_ast_t *b);
241
247CLINGO_VISIBILITY_DEFAULT bool clingo_ast_equal(clingo_ast_t *a, clingo_ast_t *b);
248
253CLINGO_VISIBILITY_DEFAULT size_t clingo_ast_hash(clingo_ast_t *ast);
254
256
259
265CLINGO_VISIBILITY_DEFAULT bool clingo_ast_get_type(clingo_ast_t *ast, clingo_ast_type_t *type);
266
273CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_get_number(clingo_ast_t *ast, clingo_ast_attribute_t attribute,
274 int *value);
275
282CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_get_symbol(clingo_ast_t *ast, clingo_ast_attribute_t attribute,
283 clingo_symbol_t *value);
284
291CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_get_location(clingo_ast_t *ast, clingo_ast_attribute_t attribute,
292 clingo_location_t const **value);
293
300CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_get_string(clingo_ast_t *ast, clingo_ast_attribute_t attribute,
301 clingo_string_t *value);
302
312CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_get_string_array(clingo_ast_t *ast,
313 clingo_ast_attribute_t attribute,
314 clingo_string_t const **value, size_t *size);
315
325CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_get_symbol_array(clingo_ast_t *ast,
326 clingo_ast_attribute_t attribute,
327 clingo_symbol_t const **value, size_t *size);
328
339CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_get_ast(clingo_ast_t *ast, clingo_ast_attribute_t attribute,
340 clingo_ast_t **value);
341
351CLINGO_VISIBILITY_DEFAULT bool clingo_ast_attribute_get_ast_array(clingo_ast_t *ast, clingo_ast_attribute_t attribute,
352 clingo_ast_t ***value, size_t *size);
353
357CLINGO_VISIBILITY_DEFAULT char const *clingo_ast_type_info_yaml(void);
358
360
363
369typedef bool (*clingo_ast_callback_t)(clingo_ast_t *ast, void *data);
370
380CLINGO_VISIBILITY_DEFAULT bool clingo_ast_parse_string(clingo_lib_t *lib, char const *program, size_t size,
381 clingo_control_t *control, clingo_ast_callback_t callback,
382 void *data);
383
393CLINGO_VISIBILITY_DEFAULT bool clingo_ast_parse_files(clingo_lib_t *lib, clingo_string_t const *files, size_t size,
394 clingo_control_t *control, clingo_ast_callback_t callback,
395 void *data);
396
398
407
409typedef struct clingo_ast_rewrite_context clingo_ast_rewrite_context_t;
410
416CLINGO_VISIBILITY_DEFAULT bool clingo_ast_rewrite_context_create(clingo_lib_t *lib,
418
422CLINGO_VISIBILITY_DEFAULT void clingo_ast_rewrite_context_free(clingo_ast_rewrite_context_t *context);
423
433 char const *param, size_t size);
434
439
448 clingo_ast_t const *theory);
449
455 bool value);
456
462
469
474CLINGO_VISIBILITY_DEFAULT clingo_projection_mode_t
476
482
492CLINGO_VISIBILITY_DEFAULT bool clingo_ast_rewrite(clingo_ast_rewrite_context_t *context, clingo_ast_t *statement,
493 clingo_ast_t ***result, size_t *result_size);
494
496typedef struct clingo_program clingo_program_t;
497
500
506CLINGO_VISIBILITY_DEFAULT bool clingo_program_new(clingo_lib_t *lib, clingo_program_t **program);
510CLINGO_VISIBILITY_DEFAULT void clingo_program_free(clingo_program_t *program);
516CLINGO_VISIBILITY_DEFAULT bool clingo_program_add(clingo_program_t *program, clingo_ast_t *statement);
517
519
528CLINGO_VISIBILITY_DEFAULT bool clingo_control_join(clingo_control_t *control, clingo_program_t const *program);
529
531
532#ifdef __cplusplus
533}
534#endif
535
536#endif
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 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.
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 void clingo_program_free(clingo_program_t *program)
Destroy the given program object.
struct clingo_ast clingo_ast_t
This struct provides a view to nodes in the AST.
Definition ast.h:160
struct clingo_program clingo_program_t
Object to store.
Definition ast.h:496
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 clingo_lib_t * clingo_ast_rewrite_context_get_lib(clingo_ast_rewrite_context_t *context)
Get the library object used to create the context.
int clingo_ast_type_t
Corresponding type to clingo_ast_type_e.
Definition ast.h:109
CLINGO_VISIBILITY_DEFAULT bool clingo_program_new(clingo_lib_t *lib, clingo_program_t **program)
Create an empty non-ground program.
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 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 void clingo_ast_free(clingo_ast_t *ast)
Free an AST node.
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.
int clingo_ast_attribute_t
Corresponding type to clingo_ast_attribute_e.
Definition ast.h:157
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.
int clingo_ast_parse_type_t
Corresponding type to clingo_ast_parse_type_e.
Definition ast.h:190
struct clingo_ast_rewrite_context clingo_ast_rewrite_context_t
Context object to rewrite statements.
Definition ast.h:409
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_program_add(clingo_program_t *program, clingo_ast_t *statement)
Adds a statement to the program.
clingo_ast_type_e
Enumeration of AST types.
Definition ast.h:31
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_equal(clingo_ast_t *a, clingo_ast_t *b)
Equality compare two AST nodes.
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.
int clingo_projection_mode_t
Corresponding type to clingo_projection_mode_e.
Definition ast.h:406
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_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 void clingo_ast_rewrite_context_clear_params(clingo_ast_rewrite_context_t *context)
Remove all previously added parameters.
clingo_projection_mode_e
The available projection modes.
Definition ast.h:400
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 bool clingo_ast_get_type(clingo_ast_t *ast, clingo_ast_type_t *type)
Get the type of an AST node.
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 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 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 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_ast_parse_type_e
Enumeration of expressions that can be parsed.
Definition ast.h:181
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_theory(clingo_ast_rewrite_context_t *context, clingo_ast_t const *theory)
Add a theory definition to the rewrite context.
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.
bool(* clingo_ast_callback_t)(clingo_ast_t *ast, void *data)
A callback to intercept ast's.
Definition ast.h:369
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.
CLINGO_VISIBILITY_DEFAULT bool clingo_ast_copy(clingo_ast_t *ast, clingo_ast_t **copy)
Copy the given AST node.
clingo_ast_attribute_e
Enumeration of attributes used by the AST.
Definition ast.h:112
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 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_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_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 size_t clingo_ast_hash(clingo_ast_t *ast)
Compute a hash for an AST node.
CLINGO_VISIBILITY_DEFAULT void clingo_ast_array_free(clingo_ast_t **ast, size_t size)
Free an AST array.
@ clingo_projection_mode_disabled
Disable projection.
Definition ast.h:401
@ clingo_projection_mode_pure
Project pure variables.
Definition ast.h:403
@ clingo_projection_mode_anonymous
Only project anonymous variables.
Definition ast.h:402
struct clingo_lib clingo_lib_t
A library object storing global information.
Definition core.h:171
struct clingo_location clingo_location_t
Represents a source code location marking its beginning and end.
Definition core.h:354
struct clingo_string_builder clingo_string_builder_t
A builder for strings.
Definition core.h:252
uint64_t clingo_symbol_t
Type to represent a symbol.
Definition symbol.h:51
Struct to capture strings that are not null-terminated.
Definition core.h:86