Clingo
Loading...
Searching...
No Matches
Core Functionality

Core types and functions used throughout all modules and version information. More...

Classes

struct  clingo_weighted_literal
 A literal with an associated weight. More...
 
struct  clingo_string
 Struct to capture strings that are not null-terminated. More...
 
struct  clingo_logger
 The clingo logger. More...
 

Macros

#define CLINGO_VERSION_MAJOR   6
 Major version number.
 
#define CLINGO_VERSION_MINOR   0
 Minor version number.
 
#define CLINGO_VERSION_REVISION   0
 Revision number.
 
#define CLINGO_VERSION   "6.0.0"
 String representation of version.
 
#define CLINGO_EXECUTABLE   "clingo"
 The name of the clingo executable.
 

Typedefs

typedef int32_t clingo_literal_t
 Signed integer type used for aspif and solver literals.
 
typedef uint32_t clingo_atom_t
 Unsigned integer type used for aspif atoms.
 
typedef uint32_t clingo_id_t
 Unsigned integer type used in various places.
 
typedef int32_t clingo_weight_t
 Signed integer type for weights in sum aggregates and minimize constraints.
 
typedef struct clingo_weighted_literal clingo_weighted_literal_t
 A literal with an associated weight.
 
typedef struct clingo_string clingo_string_t
 Struct to capture strings that are not null-terminated.
 
typedef int clingo_result_t
 Corresponding type to clingo_result_e.
 
typedef int clingo_message_t
 Corresponding type to clingo_message_e.
 
typedef int clingo_log_level_t
 Corresponding type to clingo_log_level_e.
 
typedef struct clingo_logger clingo_logger_t
 The clingo logger.
 
typedef struct clingo_lib clingo_lib_t
 A library object storing global information.
 
typedef uint32_t clingo_lib_flags_t
 Bitset of clingo_lib_flags_e.
 
typedef struct clingo_string_builder clingo_string_builder_t
 A builder for strings.
 
typedef struct clingo_position clingo_position_t
 Represents a cursor position in source code.
 
typedef struct clingo_location clingo_location_t
 Represents a source code location marking its beginning and end.
 

Enumerations

enum  clingo_result_e {
  clingo_result_success = 0 , clingo_result_runtime = 1 , clingo_result_logic = 2 , clingo_result_bad_alloc = 3 ,
  clingo_result_invalid = 4 , clingo_result_range = 5
}
 Enumeration of error codes. More...
 
enum  clingo_message_e {
  clingo_message_trace = 0 , clingo_message_debug = 1 , clingo_message_info = 2 , clingo_message_operation_undefined = 3 ,
  clingo_message_atom_undefined = 4 , clingo_message_file_included = 5 , clingo_message_global_variable = 6 , clingo_message_warn = 7 ,
  clingo_message_error = 8
}
 Enumeration of message codes. More...
 
enum  clingo_log_level_e {
  clingo_log_level_trace = clingo_message_trace , clingo_log_level_debug = clingo_message_debug , clingo_log_level_info = clingo_message_info , clingo_log_level_warn = clingo_message_warn ,
  clingo_log_level_error = clingo_message_error
}
 Enumeration of log levels. More...
 
enum  clingo_lib_flags_e { clingo_lib_flags_slotted = 1 , clingo_lib_flags_shared = 2 , clingo_lib_flags_fast_release = 4 }
 Flags to create library objects. More...
 

Functions

CLINGO_VISIBILITY_DEFAULT bool clingo_set_error (clingo_result_t code, char const *message, size_t size)
 Set an error in the current thread.
 
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 void clingo_clear_error (void)
 Clear the current error.
 
CLINGO_VISIBILITY_DEFAULT void clingo_version (int *major, int *minor, int *revision)
 Obtain the clingo version.
 
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 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_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.
 
CLINGO_VISIBILITY_DEFAULT void clingo_lib_acquire (clingo_lib_t *lib)
 Increment the reference count of the given library.
 
CLINGO_VISIBILITY_DEFAULT void clingo_lib_release (clingo_lib_t *lib)
 Release a library object created with clingo_lib_new().
 
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_string_builder_new (clingo_string_builder_t **bld)
 Create a new string builder.
 
CLINGO_VISIBILITY_DEFAULT bool clingo_string_builder_copy (clingo_string_builder_t const *src, clingo_string_builder_t **dst)
 Copy the string builder.
 
CLINGO_VISIBILITY_DEFAULT void clingo_string_builder_free (clingo_string_builder_t const *bld)
 Free the string builder.
 
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_string_builder_clear (clingo_string_builder_t *bld)
 Clear the string in the builder.
 
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.
 
CLINGO_VISIBILITY_DEFAULT bool clingo_position_copy (clingo_position_t const *src, clingo_position_t const **dst)
 Copy the given position.
 
CLINGO_VISIBILITY_DEFAULT void clingo_position_free (clingo_position_t const *pos)
 Free the given position.
 
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 size_t clingo_position_line (clingo_position_t const *pos)
 Get the line number of the position.
 
CLINGO_VISIBILITY_DEFAULT size_t clingo_position_column (clingo_position_t const *pos)
 Get the column number of the position.
 
CLINGO_VISIBILITY_DEFAULT size_t clingo_position_hash (clingo_position_t const *pos)
 Compute a hash 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 int clingo_position_compare (clingo_position_t const *a, clingo_position_t const *b)
 Compare two positions.
 
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 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_location_copy (clingo_location_t const *src, clingo_location_t const **dst)
 Copy the given location.
 
CLINGO_VISIBILITY_DEFAULT void clingo_location_free (clingo_location_t const *loc)
 Free the given location.
 
CLINGO_VISIBILITY_DEFAULT clingo_position_t const * clingo_location_begin (clingo_location_t const *loc)
 Get the beginning of the location.
 
CLINGO_VISIBILITY_DEFAULT clingo_position_t const * clingo_location_end (clingo_location_t const *loc)
 Get the end of the location.
 
CLINGO_VISIBILITY_DEFAULT size_t clingo_location_hash (clingo_location_t const *loc)
 Compute a hash of the location.
 
CLINGO_VISIBILITY_DEFAULT bool clingo_location_equal (clingo_location_t const *a, clingo_location_t const *b)
 Check if two locations are equal.
 
CLINGO_VISIBILITY_DEFAULT int clingo_location_compare (clingo_location_t const *a, clingo_location_t const *b)
 Compare two locations.
 
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.
 

Detailed Description

Core types and functions used throughout all modules and version information.

For an example, see version.c.

Typedef Documentation

◆ clingo_position_t

typedef struct clingo_position clingo_position_t

Represents a cursor position in source code.

Note
Not all positions refer to physical files. By convention, such locations use a name put in angular brackets as filename.

Enumeration Type Documentation

◆ clingo_lib_flags_e

Flags to create library objects.

Enumerator
clingo_lib_flags_slotted 

use custom allocator for storing symbols

clingo_lib_flags_shared 

create symbols in a thread-safe manner

clingo_lib_flags_fast_release 

whether to enable fast release of libraries

◆ clingo_log_level_e

Enumeration of log levels.

Enumerator
clingo_log_level_trace 

the trace level (most verbose)

clingo_log_level_debug 

the debug level

clingo_log_level_info 

the info level

clingo_log_level_warn 

the warning level

clingo_log_level_error 

the error level (least verbose)

◆ clingo_message_e

Enumeration of message codes.

Enumerator
clingo_message_trace 

a trace message

clingo_message_debug 

a debug message

clingo_message_info 

an info message

clingo_message_operation_undefined 

undefined operation in program

clingo_message_atom_undefined 

undefined atom in program

clingo_message_file_included 

same file included multiple times

clingo_message_global_variable 

global variable in tuple of aggregate element

clingo_message_warn 

a warning message

clingo_message_error 

to report multiple errors; a corresponding runtime error is raised later

◆ clingo_result_e

Enumeration of error codes.

Note
Errors can only be recovered from if explicitly mentioned; most functions do not provide strong exception guarantees. This means that in case of errors associated objects cannot be used further. If such an object has a free function, this function can and should still be called.
Enumerator
clingo_result_success 

successful API calls

clingo_result_runtime 

errors only detectable at runtime like invalid input

clingo_result_logic 

wrong usage of the clingo API

clingo_result_bad_alloc 

memory could not be allocated

clingo_result_invalid 

invalid arguments passed to function

clingo_result_range 

result out of range

Function Documentation

◆ clingo_get_error()

CLINGO_VISIBILITY_DEFAULT void clingo_get_error ( clingo_result_t code,
clingo_string_t message 
)

Get the error set in the current thread.

Parameters
[out]codethe error code
[out]messagethe error message

◆ clingo_lib_acquire()

CLINGO_VISIBILITY_DEFAULT void clingo_lib_acquire ( clingo_lib_t lib)

Increment the reference count of the given library.

Parameters
[in]libthe target

◆ clingo_lib_new()

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.

A library has to be freed using clingo_lib_free().

If the logger is NULL, the default logger printing messages to stderr is used.

Parameters
[in]flagsconstruction flags
[in]levelthe log level for the message logger
[in]loggercallback functions for warnings and info messages
[in]datauser data for the logger callback
[in]limitthe message limit
[out]libthe resulting library object
Returns
wether the call was successful
Examples
control.c, and symbol.c.

◆ clingo_lib_release()

CLINGO_VISIBILITY_DEFAULT void clingo_lib_release ( clingo_lib_t lib)

Release a library object created with clingo_lib_new().

If fast release has been disabled, the garbage collector is run to ensure that all symbols are freed. If there are still referenced symbols, the library is not deleted but put in a list for later cleanup. Further calls to this function trigger further cleanups (the lib parameter can be set to NULL to just run the cleanup).

The flag is mainly intended for language bindings, where cleanup of all symbols cannot be guaranteed due to unpredictable garbage collection. Objects using the library can still be freed after this call.

Parameters
[in]libthe target
Examples
control.c, and symbol.c.

◆ clingo_lib_report()

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.

Parameters
[in]libthe library
[in]codeassociated code
[in]messagethe message
[in]sizethe size of the message

◆ clingo_location_begin()

CLINGO_VISIBILITY_DEFAULT clingo_position_t const * clingo_location_begin ( clingo_location_t const *  loc)

Get the beginning of the location.

The lifetime of the position is tied to that of the location.

Parameters
[in]locthe location
Returns
the beginning position

◆ clingo_location_compare()

CLINGO_VISIBILITY_DEFAULT int clingo_location_compare ( clingo_location_t const *  a,
clingo_location_t const *  b 
)

Compare two locations.

Only locations associated with the same library may be compared.

Parameters
[in]athe first location
[in]bthe second location
Returns
the comparator

◆ clingo_location_copy()

CLINGO_VISIBILITY_DEFAULT bool clingo_location_copy ( clingo_location_t const *  src,
clingo_location_t const **  dst 
)

Copy the given location.

Parameters
[in]srcthe location to copy
[out]dstthe resulting location
Returns
wether the call was successful

◆ clingo_location_end()

CLINGO_VISIBILITY_DEFAULT clingo_position_t const * clingo_location_end ( clingo_location_t const *  loc)

Get the end of the location.

The lifetime of the position is tied to that of the location.

Parameters
[in]locthe location
Returns
the end position

◆ clingo_location_equal()

CLINGO_VISIBILITY_DEFAULT bool clingo_location_equal ( clingo_location_t const *  a,
clingo_location_t const *  b 
)

Check if two locations are equal.

Only locations associated with the same library may be compared.

Parameters
[in]athe first location
[in]bthe second location
Returns
whether the location are equal

◆ clingo_location_free()

CLINGO_VISIBILITY_DEFAULT void clingo_location_free ( clingo_location_t const *  loc)

Free the given location.

Parameters
[in]locthe location to free

◆ clingo_location_hash()

CLINGO_VISIBILITY_DEFAULT size_t clingo_location_hash ( clingo_location_t const *  loc)

Compute a hash of the location.

Parameters
[in]locthe location
Returns
the resulting hash

◆ clingo_location_new()

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.

Parameters
[in]beginthe position marking the beginning
[in]endthe position marking the end
[out]locthe resulting location
Returns
wether the call was successful

◆ clingo_location_to_string()

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.

Parameters
[in]locthe location
[in]strthe string builder
Returns
wether the call was successful

◆ clingo_message_string()

CLINGO_VISIBILITY_DEFAULT void clingo_message_string ( clingo_message_t  code,
clingo_string_t value 
)

Convert the giving message code into a string.

The function returns string literals that do not have to be cleaned up.

Parameters
[in]codethe message code
[out]valuethe string

◆ clingo_position_column()

CLINGO_VISIBILITY_DEFAULT size_t clingo_position_column ( clingo_position_t const *  pos)

Get the column number of the position.

Parameters
[in]posthe position
Returns
the column number

◆ clingo_position_compare()

CLINGO_VISIBILITY_DEFAULT int clingo_position_compare ( clingo_position_t const *  a,
clingo_position_t const *  b 
)

Compare two positions.

Only positions associated with the same library may be compared.

Parameters
[in]athe first position
[in]bthe second position
Returns
the comparator

◆ clingo_position_copy()

CLINGO_VISIBILITY_DEFAULT bool clingo_position_copy ( clingo_position_t const *  src,
clingo_position_t const **  dst 
)

Copy the given position.

Parameters
[in]srcthe position to copy
[out]dstthe resulting position
Returns
wether the call was successful

◆ clingo_position_equal()

CLINGO_VISIBILITY_DEFAULT bool clingo_position_equal ( clingo_position_t const *  a,
clingo_position_t const *  b 
)

Check if two positions are equal.

Only positions associated with the same library may be compared.

Parameters
[in]athe first position
[in]bthe second position
Returns
whether the positions are equal

◆ clingo_position_file()

CLINGO_VISIBILITY_DEFAULT void clingo_position_file ( clingo_position_t const *  pos,
clingo_string_t value 
)

Get the file name of the position.

Parameters
[in]posthe position
[out]valuethe file name

◆ clingo_position_free()

CLINGO_VISIBILITY_DEFAULT void clingo_position_free ( clingo_position_t const *  pos)

Free the given position.

Parameters
[in]posthe position to free

◆ clingo_position_hash()

CLINGO_VISIBILITY_DEFAULT size_t clingo_position_hash ( clingo_position_t const *  pos)

Compute a hash of the position.

Parameters
[in]posthe position
Returns
the resulting hash

◆ clingo_position_line()

CLINGO_VISIBILITY_DEFAULT size_t clingo_position_line ( clingo_position_t const *  pos)

Get the line number of the position.

Parameters
[in]posthe position
Returns
the line number

◆ clingo_position_new()

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.

Parameters
[in]libthe library storing strings
[in]filethe file of the position
[in]sizethe size of the file string
[in]linethe line number of the position
[in]columnthe column number of the position
[out]posthe resulting position
Returns
wether the call was successful

◆ clingo_position_to_string()

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.

Parameters
[in]posthe position
[in]strthe string builder
Returns
wether the call was successful

◆ clingo_result_string()

CLINGO_VISIBILITY_DEFAULT void clingo_result_string ( clingo_result_t  code,
clingo_string_t value 
)

Convert the given result code into a string.

The function returns string literals that do not have to be cleaned up.

Parameters
[in]codethe result code
[out]valuethe string
Examples
symbol.c.

◆ clingo_set_error()

CLINGO_VISIBILITY_DEFAULT bool clingo_set_error ( clingo_result_t  code,
char const *  message,
size_t  size 
)

Set an error in the current thread.

Parameters
[in]codethe error code
[in]messagethe error message
[in]sizethe size of the error message
Returns
returns false

◆ clingo_string_builder_clear()

CLINGO_VISIBILITY_DEFAULT void clingo_string_builder_clear ( clingo_string_builder_t bld)

Clear the string in the builder.

Parameters
[in]bldthe builder
Examples
control.c, and symbol.c.

◆ clingo_string_builder_copy()

CLINGO_VISIBILITY_DEFAULT bool clingo_string_builder_copy ( clingo_string_builder_t const *  src,
clingo_string_builder_t **  dst 
)

Copy the string builder.

Parameters
[in]srcthe builder to copy
[out]dstthe resulting builder
Returns
wether the call was successful

◆ clingo_string_builder_free()

CLINGO_VISIBILITY_DEFAULT void clingo_string_builder_free ( clingo_string_builder_t const *  bld)

Free the string builder.

Parameters
[in]bldthe builder
Examples
control.c, and symbol.c.

◆ clingo_string_builder_new()

CLINGO_VISIBILITY_DEFAULT bool clingo_string_builder_new ( clingo_string_builder_t **  bld)

Create a new string builder.

Parameters
[out]bldthe resulting builder
Returns
wether the call was successful
Examples
control.c, and symbol.c.

◆ clingo_string_builder_string()

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.

Parameters
[in]bldthe builder
[out]valuethe resulting string
Returns
wether the call was successful
Examples
control.c, and symbol.c.

◆ clingo_version()

CLINGO_VISIBILITY_DEFAULT void clingo_version ( int *  major,
int *  minor,
int *  revision 
)

Obtain the clingo version.

Parameters
[out]majormajor version number
[out]minorminor version number
[out]revisionrevision number
Examples
version.c.