Clingo
Loading...
Searching...
No Matches
core.h
1#ifndef CLINGO_CORE_H
2#define CLINGO_CORE_H
3
4#include <stdbool.h>
5#include <stddef.h>
6#include <stdint.h>
7
8#if defined CLINGO_NO_VISIBILITY
9#define CLINGO_VISIBILITY_DEFAULT
10#define CLINGO_VISIBILITY_PRIVATE
11#elif defined __EMSCRIPTEN__
12#include <emscripten.h>
13#define CLINGO_VISIBILITY_DEFAULT EMSCRIPTEN_KEEPALIVE
14#define CLINGO_VISIBILITY_PRIVATE
15#elif defined _WIN32 || defined __CYGWIN__
16#ifdef CLINGO_BUILD_LIBRARY
17#define CLINGO_VISIBILITY_DEFAULT __declspec(dllexport)
18#else
19#define CLINGO_VISIBILITY_DEFAULT __declspec(dllimport)
20#endif
21#define CLINGO_VISIBILITY_PRIVATE
22#elif __GNUC__ >= 4
23#define CLINGO_VISIBILITY_DEFAULT __attribute__((visibility("default")))
24#define CLINGO_VISIBILITY_PRIVATE __attribute__((visibility("hidden")))
25#else
26#define CLINGO_VISIBILITY_DEFAULT
27#define CLINGO_VISIBILITY_PRIVATE
28#endif
29
30#if defined __GNUC__
31#define CLINGO_DEPRECATED __attribute__((deprecated))
32#elif defined _MSC_VER
33#define CLINGO_DEPRECATED __declspec(deprecated)
34#else
36#define CLINGO_DEPRECATED
37#endif
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
54
60
62#define CLINGO_VERSION_MAJOR 6
64#define CLINGO_VERSION_MINOR 0
66#define CLINGO_VERSION_REVISION 0
68#define CLINGO_VERSION "6.0.0"
70#define CLINGO_EXECUTABLE "clingo"
71
73typedef int32_t clingo_literal_t;
75typedef uint32_t clingo_atom_t;
77typedef uint32_t clingo_id_t;
79typedef int32_t clingo_weight_t;
86typedef struct clingo_string {
87 char const *data;
88 size_t size;
90
106typedef int clingo_result_t;
107
114CLINGO_VISIBILITY_DEFAULT bool clingo_set_error(clingo_result_t code, char const *message, size_t size);
115
120CLINGO_VISIBILITY_DEFAULT void clingo_get_error(clingo_result_t *code, clingo_string_t *message);
121
123CLINGO_VISIBILITY_DEFAULT void clingo_clear_error(void);
124
139
150
152typedef struct clingo_logger {
161 void (*log)(clingo_message_t code, char const *message, size_t size, void *data);
167 void (*free)(void *data);
169
171typedef struct clingo_lib clingo_lib_t;
172
180typedef uint32_t clingo_lib_flags_t;
181
187CLINGO_VISIBILITY_DEFAULT void clingo_version(int *major, int *minor, int *revision);
188
195CLINGO_VISIBILITY_DEFAULT void clingo_result_string(clingo_result_t code, clingo_string_t *value);
196
203CLINGO_VISIBILITY_DEFAULT void clingo_message_string(clingo_message_t code, clingo_string_t *value);
204
218CLINGO_VISIBILITY_DEFAULT bool clingo_lib_new(clingo_lib_flags_t flags, clingo_log_level_t level,
219 clingo_logger_t const *logger, void *data, size_t limit,
220 clingo_lib_t **lib);
221
225CLINGO_VISIBILITY_DEFAULT void clingo_lib_acquire(clingo_lib_t *lib);
226
240CLINGO_VISIBILITY_DEFAULT void clingo_lib_release(clingo_lib_t *lib);
241
248CLINGO_VISIBILITY_DEFAULT void clingo_lib_report(clingo_lib_t *lib, clingo_message_t code, char const *message,
249 size_t size);
250
252typedef struct clingo_string_builder clingo_string_builder_t;
253
258CLINGO_VISIBILITY_DEFAULT bool clingo_string_builder_new(clingo_string_builder_t **bld);
264CLINGO_VISIBILITY_DEFAULT bool clingo_string_builder_copy(clingo_string_builder_t const *src,
269CLINGO_VISIBILITY_DEFAULT void clingo_string_builder_free(clingo_string_builder_t const *bld);
270
276CLINGO_VISIBILITY_DEFAULT bool clingo_string_builder_string(clingo_string_builder_t const *bld, clingo_string_t *value);
280CLINGO_VISIBILITY_DEFAULT void clingo_string_builder_clear(clingo_string_builder_t *bld);
281
286typedef struct clingo_position clingo_position_t;
287
297CLINGO_VISIBILITY_DEFAULT bool clingo_position_new(clingo_lib_t *lib, char const *file, size_t size, size_t line,
298 size_t column, clingo_position_t const **pos);
304CLINGO_VISIBILITY_DEFAULT bool clingo_position_copy(clingo_position_t const *src, clingo_position_t const **dst);
308CLINGO_VISIBILITY_DEFAULT void clingo_position_free(clingo_position_t const *pos);
309
314CLINGO_VISIBILITY_DEFAULT void clingo_position_file(clingo_position_t const *pos, clingo_string_t *value);
319CLINGO_VISIBILITY_DEFAULT size_t clingo_position_line(clingo_position_t const *pos);
324CLINGO_VISIBILITY_DEFAULT size_t clingo_position_column(clingo_position_t const *pos);
329CLINGO_VISIBILITY_DEFAULT size_t clingo_position_hash(clingo_position_t const *pos);
337CLINGO_VISIBILITY_DEFAULT bool clingo_position_equal(clingo_position_t const *a, clingo_position_t const *b);
345CLINGO_VISIBILITY_DEFAULT int clingo_position_compare(clingo_position_t const *a, clingo_position_t const *b);
351CLINGO_VISIBILITY_DEFAULT bool clingo_position_to_string(clingo_position_t const *pos, clingo_string_builder_t *str);
352
354typedef struct clingo_location clingo_location_t;
355
362CLINGO_VISIBILITY_DEFAULT bool clingo_location_new(clingo_position_t const *begin, clingo_position_t const *end,
363 clingo_location_t const **loc);
369CLINGO_VISIBILITY_DEFAULT bool clingo_location_copy(clingo_location_t const *src, clingo_location_t const **dst);
373CLINGO_VISIBILITY_DEFAULT void clingo_location_free(clingo_location_t const *loc);
374
381CLINGO_VISIBILITY_DEFAULT clingo_position_t const *clingo_location_begin(clingo_location_t const *loc);
388CLINGO_VISIBILITY_DEFAULT clingo_position_t const *clingo_location_end(clingo_location_t const *loc);
393CLINGO_VISIBILITY_DEFAULT size_t clingo_location_hash(clingo_location_t const *loc);
401CLINGO_VISIBILITY_DEFAULT bool clingo_location_equal(clingo_location_t const *a, clingo_location_t const *b);
409CLINGO_VISIBILITY_DEFAULT int clingo_location_compare(clingo_location_t const *a, clingo_location_t const *b);
415CLINGO_VISIBILITY_DEFAULT bool clingo_location_to_string(clingo_location_t const *loc, clingo_string_builder_t *str);
416
418
419#ifdef __cplusplus
420}
421#endif
422
423#endif
CLINGO_VISIBILITY_DEFAULT void clingo_position_file(clingo_position_t const *pos, clingo_string_t *value)
Get the file name of the position.
CLINGO_VISIBILITY_DEFAULT clingo_position_t const * clingo_location_end(clingo_location_t const *loc)
Get the end of the location.
CLINGO_VISIBILITY_DEFAULT void clingo_lib_release(clingo_lib_t *lib)
Release a library object created with clingo_lib_new().
CLINGO_VISIBILITY_DEFAULT int clingo_position_compare(clingo_position_t const *a, clingo_position_t const *b)
Compare two positions.
CLINGO_VISIBILITY_DEFAULT bool clingo_position_new(clingo_lib_t *lib, char const *file, size_t size, size_t line, size_t column, clingo_position_t const **pos)
Create a new source position object.
struct clingo_string clingo_string_t
Struct to capture strings that are not null-terminated.
CLINGO_VISIBILITY_DEFAULT void clingo_string_builder_free(clingo_string_builder_t const *bld)
Free the string builder.
CLINGO_VISIBILITY_DEFAULT void clingo_version(int *major, int *minor, int *revision)
Obtain the clingo version.
CLINGO_VISIBILITY_DEFAULT bool clingo_set_error(clingo_result_t code, char const *message, size_t size)
Set an error in the current thread.
struct clingo_weighted_literal clingo_weighted_literal_t
A literal with an associated weight.
CLINGO_VISIBILITY_DEFAULT void clingo_lib_report(clingo_lib_t *lib, clingo_message_t code, char const *message, size_t size)
Report a message via the libraries logger.
CLINGO_VISIBILITY_DEFAULT bool clingo_location_new(clingo_position_t const *begin, clingo_position_t const *end, clingo_location_t const **loc)
Create a new source location object.
CLINGO_VISIBILITY_DEFAULT bool clingo_position_to_string(clingo_position_t const *pos, clingo_string_builder_t *str)
Convert the given position into a string.
CLINGO_VISIBILITY_DEFAULT size_t clingo_position_column(clingo_position_t const *pos)
Get the column number of the position.
CLINGO_VISIBILITY_DEFAULT void clingo_string_builder_clear(clingo_string_builder_t *bld)
Clear the string in the builder.
CLINGO_VISIBILITY_DEFAULT bool clingo_lib_new(clingo_lib_flags_t flags, clingo_log_level_t level, clingo_logger_t const *logger, void *data, size_t limit, clingo_lib_t **lib)
Create a library object.
int clingo_log_level_t
Corresponding type to clingo_log_level_e.
Definition core.h:149
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
CLINGO_VISIBILITY_DEFAULT void clingo_get_error(clingo_result_t *code, clingo_string_t *message)
Get the error set in the current thread.
CLINGO_VISIBILITY_DEFAULT bool clingo_string_builder_copy(clingo_string_builder_t const *src, clingo_string_builder_t **dst)
Copy the string builder.
uint32_t clingo_atom_t
Unsigned integer type used for aspif atoms.
Definition core.h:75
CLINGO_VISIBILITY_DEFAULT int clingo_location_compare(clingo_location_t const *a, clingo_location_t const *b)
Compare two locations.
struct clingo_string_builder clingo_string_builder_t
A builder for strings.
Definition core.h:252
CLINGO_VISIBILITY_DEFAULT void clingo_clear_error(void)
Clear the current error.
CLINGO_VISIBILITY_DEFAULT bool clingo_string_builder_string(clingo_string_builder_t const *bld, clingo_string_t *value)
Get the (zero-terminated) string in the builder.
CLINGO_VISIBILITY_DEFAULT void clingo_result_string(clingo_result_t code, clingo_string_t *value)
Convert the given result code into a string.
CLINGO_VISIBILITY_DEFAULT size_t clingo_position_line(clingo_position_t const *pos)
Get the line number of the position.
CLINGO_VISIBILITY_DEFAULT bool clingo_position_equal(clingo_position_t const *a, clingo_position_t const *b)
Check if two positions are equal.
CLINGO_VISIBILITY_DEFAULT bool clingo_location_to_string(clingo_location_t const *loc, clingo_string_builder_t *str)
Convert the given location into a string.
clingo_message_e
Enumeration of message codes.
Definition core.h:126
struct clingo_logger clingo_logger_t
The clingo logger.
clingo_log_level_e
Enumeration of log levels.
Definition core.h:141
CLINGO_VISIBILITY_DEFAULT size_t clingo_position_hash(clingo_position_t const *pos)
Compute a hash of the position.
int32_t clingo_literal_t
Signed integer type used for aspif and solver literals.
Definition core.h:73
CLINGO_VISIBILITY_DEFAULT clingo_position_t const * clingo_location_begin(clingo_location_t const *loc)
Get the beginning of the location.
CLINGO_VISIBILITY_DEFAULT void clingo_position_free(clingo_position_t const *pos)
Free the given position.
clingo_result_e
Enumeration of error codes.
Definition core.h:97
int clingo_message_t
Corresponding type to clingo_message_e.
Definition core.h:138
uint32_t clingo_id_t
Unsigned integer type used in various places.
Definition core.h:77
int clingo_result_t
Corresponding type to clingo_result_e.
Definition core.h:106
uint32_t clingo_lib_flags_t
Bitset of clingo_lib_flags_e.
Definition core.h:180
CLINGO_VISIBILITY_DEFAULT void clingo_location_free(clingo_location_t const *loc)
Free the given location.
struct clingo_position clingo_position_t
Represents a cursor position in source code.
Definition core.h:286
clingo_lib_flags_e
Flags to create library objects.
Definition core.h:174
CLINGO_VISIBILITY_DEFAULT bool clingo_string_builder_new(clingo_string_builder_t **bld)
Create a new string builder.
CLINGO_VISIBILITY_DEFAULT bool clingo_position_copy(clingo_position_t const *src, clingo_position_t const **dst)
Copy the given position.
CLINGO_VISIBILITY_DEFAULT bool clingo_location_equal(clingo_location_t const *a, clingo_location_t const *b)
Check if two locations are equal.
int32_t clingo_weight_t
Signed integer type for weights in sum aggregates and minimize constraints.
Definition core.h:79
CLINGO_VISIBILITY_DEFAULT void clingo_message_string(clingo_message_t code, clingo_string_t *value)
Convert the giving message code into a string.
CLINGO_VISIBILITY_DEFAULT bool clingo_location_copy(clingo_location_t const *src, clingo_location_t const **dst)
Copy the given location.
CLINGO_VISIBILITY_DEFAULT size_t clingo_location_hash(clingo_location_t const *loc)
Compute a hash of the location.
CLINGO_VISIBILITY_DEFAULT void clingo_lib_acquire(clingo_lib_t *lib)
Increment the reference count of the given library.
@ clingo_message_file_included
same file included multiple times
Definition core.h:132
@ clingo_message_error
to report multiple errors; a corresponding runtime error is raised later
Definition core.h:135
@ clingo_message_info
an info message
Definition core.h:129
@ clingo_message_atom_undefined
undefined atom in program
Definition core.h:131
@ clingo_message_global_variable
global variable in tuple of aggregate element
Definition core.h:133
@ clingo_message_operation_undefined
undefined operation in program
Definition core.h:130
@ clingo_message_trace
a trace message
Definition core.h:127
@ clingo_message_debug
a debug message
Definition core.h:128
@ clingo_message_warn
a warning message
Definition core.h:134
@ clingo_log_level_warn
the warning level
Definition core.h:145
@ clingo_log_level_debug
the debug level
Definition core.h:143
@ clingo_log_level_info
the info level
Definition core.h:144
@ clingo_log_level_error
the error level (least verbose)
Definition core.h:146
@ clingo_log_level_trace
the trace level (most verbose)
Definition core.h:142
@ clingo_result_range
result out of range
Definition core.h:103
@ clingo_result_runtime
errors only detectable at runtime like invalid input
Definition core.h:99
@ clingo_result_success
successful API calls
Definition core.h:98
@ clingo_result_invalid
invalid arguments passed to function
Definition core.h:102
@ clingo_result_bad_alloc
memory could not be allocated
Definition core.h:101
@ clingo_result_logic
wrong usage of the clingo API
Definition core.h:100
@ clingo_lib_flags_shared
create symbols in a thread-safe manner
Definition core.h:176
@ clingo_lib_flags_slotted
use custom allocator for storing symbols
Definition core.h:175
@ clingo_lib_flags_fast_release
whether to enable fast release of libraries
Definition core.h:177
The clingo logger.
Definition core.h:152
void(* free)(void *data)
Free the logger.
Definition core.h:167
void(* log)(clingo_message_t code, char const *message, size_t size, void *data)
Callback to intercept messages.
Definition core.h:161
Struct to capture strings that are not null-terminated.
Definition core.h:86
size_t size
the length of the string
Definition core.h:88
char const * data
pointer to the beginning of the string
Definition core.h:87
A literal with an associated weight.
Definition core.h:81
clingo_weight_t weight
the weight
Definition core.h:83
clingo_literal_t literal
the literal
Definition core.h:82