Clingo
Loading...
Searching...
No Matches
core.h
1#ifndef CLINGO_CORE_H
2#define CLINGO_CORE_H
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8#include <stdbool.h>
9#include <stddef.h>
10#include <stdint.h>
11
12#if defined _WIN32 || defined __CYGWIN__
13#define CLINGO_WIN
14#endif
15#ifdef CLINGO_NO_VISIBILITY
16#define CLINGO_VISIBILITY_DEFAULT
17#define CLINGO_VISIBILITY_PRIVATE
18#else
19#ifdef CLINGO_WIN
20#ifdef CLINGO_BUILD_LIBRARY
21#define CLINGO_VISIBILITY_DEFAULT __declspec(dllexport)
22#else
23#define CLINGO_VISIBILITY_DEFAULT __declspec(dllimport)
24#endif
25#define CLINGO_VISIBILITY_PRIVATE
26#else
27#if __GNUC__ >= 4
28#define CLINGO_VISIBILITY_DEFAULT __attribute__((visibility("default")))
29#define CLINGO_VISIBILITY_PRIVATE __attribute__((visibility("hidden")))
30#else
32#define CLINGO_VISIBILITY_DEFAULT
34#define CLINGO_VISIBILITY_PRIVATE
35#endif
36#endif
37#endif
38
39#if defined __GNUC__
40#define CLINGO_DEPRECATED __attribute__((deprecated))
41#elif defined _MSC_VER
42#define CLINGO_DEPRECATED __declspec(deprecated)
43#else
45#define CLINGO_DEPRECATED
46#endif
47
59
65
67#define CLINGO_VERSION_MAJOR 6
69#define CLINGO_VERSION_MINOR 0
71#define CLINGO_VERSION_REVISION 0
73#define CLINGO_VERSION "6.0.0"
75#define CLINGO_EXECUTABLE "clingo"
76
78typedef int32_t clingo_literal_t;
80typedef uint32_t clingo_atom_t;
82typedef uint32_t clingo_id_t;
84typedef int32_t clingo_weight_t;
91typedef struct clingo_string {
92 char const *data;
93 size_t size;
95
111typedef int clingo_result_t;
112
119CLINGO_VISIBILITY_DEFAULT bool clingo_set_error(clingo_result_t code, char const *message, size_t size);
120
125CLINGO_VISIBILITY_DEFAULT void clingo_get_error(clingo_result_t *code, clingo_string_t *message);
126
128CLINGO_VISIBILITY_DEFAULT void clingo_clear_error(void);
129
144
155
157typedef struct clingo_logger {
166 void (*log)(clingo_message_t code, char const *message, size_t size, void *data);
172 void (*free)(void *data);
174
176typedef struct clingo_lib clingo_lib_t;
177
185typedef uint32_t clingo_lib_flags_t;
186
192CLINGO_VISIBILITY_DEFAULT void clingo_version(int *major, int *minor, int *revision);
193
200CLINGO_VISIBILITY_DEFAULT void clingo_result_string(clingo_result_t code, clingo_string_t *value);
201
208CLINGO_VISIBILITY_DEFAULT void clingo_message_string(clingo_message_t code, clingo_string_t *value);
209
223CLINGO_VISIBILITY_DEFAULT bool clingo_lib_new(clingo_lib_flags_t flags, clingo_log_level_t level,
224 clingo_logger_t const *logger, void *data, size_t limit,
225 clingo_lib_t **lib);
226
230CLINGO_VISIBILITY_DEFAULT void clingo_lib_acquire(clingo_lib_t *lib);
231
245CLINGO_VISIBILITY_DEFAULT void clingo_lib_release(clingo_lib_t *lib);
246
253CLINGO_VISIBILITY_DEFAULT void clingo_lib_report(clingo_lib_t *lib, clingo_message_t code, char const *message,
254 size_t size);
255
257typedef struct clingo_string_builder clingo_string_builder_t;
258
263CLINGO_VISIBILITY_DEFAULT bool clingo_string_builder_new(clingo_string_builder_t **bld);
269CLINGO_VISIBILITY_DEFAULT bool clingo_string_builder_copy(clingo_string_builder_t const *src,
274CLINGO_VISIBILITY_DEFAULT void clingo_string_builder_free(clingo_string_builder_t const *bld);
275
281CLINGO_VISIBILITY_DEFAULT bool clingo_string_builder_string(clingo_string_builder_t const *bld, clingo_string_t *value);
285CLINGO_VISIBILITY_DEFAULT void clingo_string_builder_clear(clingo_string_builder_t *bld);
286
291typedef struct clingo_position clingo_position_t;
292
302CLINGO_VISIBILITY_DEFAULT bool clingo_position_new(clingo_lib_t *lib, char const *file, size_t size, size_t line,
303 size_t column, clingo_position_t const **pos);
309CLINGO_VISIBILITY_DEFAULT bool clingo_position_copy(clingo_position_t const *src, clingo_position_t const **dst);
313CLINGO_VISIBILITY_DEFAULT void clingo_position_free(clingo_position_t const *pos);
314
319CLINGO_VISIBILITY_DEFAULT void clingo_position_file(clingo_position_t const *pos, clingo_string_t *value);
324CLINGO_VISIBILITY_DEFAULT size_t clingo_position_line(clingo_position_t const *pos);
329CLINGO_VISIBILITY_DEFAULT size_t clingo_position_column(clingo_position_t const *pos);
334CLINGO_VISIBILITY_DEFAULT size_t clingo_position_hash(clingo_position_t const *pos);
342CLINGO_VISIBILITY_DEFAULT bool clingo_position_equal(clingo_position_t const *a, clingo_position_t const *b);
350CLINGO_VISIBILITY_DEFAULT int clingo_position_compare(clingo_position_t const *a, clingo_position_t const *b);
356CLINGO_VISIBILITY_DEFAULT bool clingo_position_to_string(clingo_position_t const *pos, clingo_string_builder_t *str);
357
359typedef struct clingo_location clingo_location_t;
360
367CLINGO_VISIBILITY_DEFAULT bool clingo_location_new(clingo_position_t const *begin, clingo_position_t const *end,
368 clingo_location_t const **loc);
374CLINGO_VISIBILITY_DEFAULT bool clingo_location_copy(clingo_location_t const *src, clingo_location_t const **dst);
378CLINGO_VISIBILITY_DEFAULT void clingo_location_free(clingo_location_t const *loc);
379
386CLINGO_VISIBILITY_DEFAULT clingo_position_t const *clingo_location_begin(clingo_location_t const *loc);
393CLINGO_VISIBILITY_DEFAULT clingo_position_t const *clingo_location_end(clingo_location_t const *loc);
398CLINGO_VISIBILITY_DEFAULT size_t clingo_location_hash(clingo_location_t const *loc);
406CLINGO_VISIBILITY_DEFAULT bool clingo_location_equal(clingo_location_t const *a, clingo_location_t const *b);
414CLINGO_VISIBILITY_DEFAULT int clingo_location_compare(clingo_location_t const *a, clingo_location_t const *b);
420CLINGO_VISIBILITY_DEFAULT bool clingo_location_to_string(clingo_location_t const *loc, clingo_string_builder_t *str);
421
423
424#ifdef __cplusplus
425}
426#endif
427
428#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:154
struct clingo_lib clingo_lib_t
A library object storing global information.
Definition core.h:176
struct clingo_location clingo_location_t
Represents a source code location marking its beginning and end.
Definition core.h:359
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:80
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:257
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:131
struct clingo_logger clingo_logger_t
The clingo logger.
clingo_log_level_e
Enumeration of log levels.
Definition core.h:146
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:78
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:102
int clingo_message_t
Corresponding type to clingo_message_e.
Definition core.h:143
uint32_t clingo_id_t
Unsigned integer type used in various places.
Definition core.h:82
int clingo_result_t
Corresponding type to clingo_result_e.
Definition core.h:111
uint32_t clingo_lib_flags_t
Bitset of clingo_lib_flags_e.
Definition core.h:185
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:291
clingo_lib_flags_e
Flags to create library objects.
Definition core.h:179
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:84
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:137
@ clingo_message_error
to report multiple errors; a corresponding runtime error is raised later
Definition core.h:140
@ clingo_message_info
an info message
Definition core.h:134
@ clingo_message_atom_undefined
undefined atom in program
Definition core.h:136
@ clingo_message_global_variable
global variable in tuple of aggregate element
Definition core.h:138
@ clingo_message_operation_undefined
undefined operation in program
Definition core.h:135
@ clingo_message_trace
a trace message
Definition core.h:132
@ clingo_message_debug
a debug message
Definition core.h:133
@ clingo_message_warn
a warning message
Definition core.h:139
@ clingo_log_level_warn
the warning level
Definition core.h:150
@ clingo_log_level_debug
the debug level
Definition core.h:148
@ clingo_log_level_info
the info level
Definition core.h:149
@ clingo_log_level_error
the error level (least verbose)
Definition core.h:151
@ clingo_log_level_trace
the trace level (most verbose)
Definition core.h:147
@ clingo_result_range
result out of range
Definition core.h:108
@ clingo_result_runtime
errors only detectable at runtime like invalid input
Definition core.h:104
@ clingo_result_success
successful API calls
Definition core.h:103
@ clingo_result_invalid
invalid arguments passed to function
Definition core.h:107
@ clingo_result_bad_alloc
memory could not be allocated
Definition core.h:106
@ clingo_result_logic
wrong usage of the clingo API
Definition core.h:105
@ clingo_lib_flags_shared
create symbols in a thread-safe manner
Definition core.h:181
@ clingo_lib_flags_slotted
use custom allocator for storing symbols
Definition core.h:180
@ clingo_lib_flags_fast_release
whether to enable fast release of libraries
Definition core.h:182
The clingo logger.
Definition core.h:157
void(* free)(void *data)
Free the logger.
Definition core.h:172
void(* log)(clingo_message_t code, char const *message, size_t size, void *data)
Callback to intercept messages.
Definition core.h:166
Struct to capture strings that are not null-terminated.
Definition core.h:91
size_t size
the length of the string
Definition core.h:93
char const * data
pointer to the beginning of the string
Definition core.h:92
A literal with an associated weight.
Definition core.h:86
clingo_weight_t weight
the weight
Definition core.h:88
clingo_literal_t literal
the literal
Definition core.h:87