rego-cpp 1.0.0
A C++ implementation of the Rego language and runtime
Loading...
Searching...
No Matches
rego_c.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
5
6#ifndef _REGO_C_H_
7#define _REGO_C_H_
8
9#include "version.h"
10
11#include <stdint.h>
12
14typedef void regoInterpreter;
15
17typedef void regoNode;
18
20typedef void regoOutput;
21
23typedef void regoBundle;
24
26typedef void regoInput;
27
29typedef uint_least8_t regoBoolean;
30
32typedef uint_least32_t regoEnum;
33
35typedef uint_least32_t regoSize;
36
38typedef int_least64_t regoInt;
39
41typedef uint_least32_t regoType;
42
44// error codes
45#define REGO_OK 0
46#define REGO_ERROR 1
47#define REGO_ERROR_BUFFER_TOO_SMALL 2
48#define REGO_ERROR_INVALID_LOG_LEVEL 3
49// #define REGO_ERROR_MANUAL_TZDATA_NOT_SUPPORTED 4 deprecated
50#define REGO_ERROR_INPUT_NULL 5
51#define REGO_ERROR_INPUT_MISSING_ARGUMENTS 6
52#define REGO_ERROR_INPUT_OBJECT_ITEM 7
53
54// term node types
55#define REGO_NODE_BINDING 1000
56#define REGO_NODE_VAR 1001
57#define REGO_NODE_TERM 1002
58#define REGO_NODE_SCALAR 1003
59#define REGO_NODE_ARRAY 1004
60#define REGO_NODE_SET 1005
61#define REGO_NODE_OBJECT 1006
62#define REGO_NODE_OBJECT_ITEM 1007
63#define REGO_NODE_INT 1008
64#define REGO_NODE_FLOAT 1009
65#define REGO_NODE_STRING 1010
66#define REGO_NODE_TRUE 1011
67#define REGO_NODE_FALSE 1012
68#define REGO_NODE_NULL 1013
69#define REGO_NODE_UNDEFINED 1014
70#define REGO_NODE_TERMS 1015
71#define REGO_NODE_BINDINGS 1016
72#define REGO_NODE_RESULTS 1017
73#define REGO_NODE_RESULT 1018
74
75#define REGO_NODE_ERROR 1800
76#define REGO_NODE_ERROR_MESSAGE 1801
77#define REGO_NODE_ERROR_AST 1802
78#define REGO_NODE_ERROR_CODE 1803
79#define REGO_NODE_ERROR_SEQ 1804
80
81#define REGO_NODE_INTERNAL 1999
82
83// log levels
84#define REGO_LOG_LEVEL_NONE 0
85#define REGO_LOG_LEVEL_ERROR 1
86#define REGO_LOG_LEVEL_OUTPUT 2
87#define REGO_LOG_LEVEL_WARN 3
88#define REGO_LOG_LEVEL_INFO 4
89#define REGO_LOG_LEVEL_DEBUG 5
90#define REGO_LOG_LEVEL_TRACE 6
91#define REGO_LOG_LEVEL_UNSUPPORTED 7
92
93#define REGO_BUILD_INFO \
94 (REGOCPP_VERSION " (" REGOCPP_BUILD_NAME ", " REGOCPP_BUILD_DATE \
95 ") " REGOCPP_BUILD_TOOLCHAIN " on " REGOCPP_PLATFORM)
96
98
99#if defined(REGO_SHARED) && defined(WIN32)
101#define REGO_API(x) __declspec(dllexport) x __cdecl
102#else
105#define REGO_API(x) x
106#endif
107
108#ifdef __cplusplus
109extern "C"
110{
111#endif
113 // ----- Interpreter functions ------ //
115
123
133
141
150 REGO_API(regoEnum) regoVersion(char* buffer, regoSize size);
151
163
176
188
195
201
206
216
226 regoAddModule(regoInterpreter* rego, const char* name, const char* contents);
227
239
250 regoAddDataJSON(regoInterpreter* rego, const char* contents);
251
264
275 regoSetInputTerm(regoInterpreter* rego, const char* contents);
276
286
296 REGO_API(void)
298
301 // /@return Whether debug mode is enabled.
303
315
325 REGO_API(void)
327
332
343 regoQuery(regoInterpreter* rego, const char* query_expr);
344
352 REGO_API(void)
354
359
367
375
387 regoError(regoInterpreter* rego, char* buffer, regoSize size);
388
398 regoSetQuery(regoInterpreter* rego, const char* query_expr);
399
409 regoAddEntrypoint(regoInterpreter* rego, const char* entrypoint);
410
421
431
442
454 regoBundleSave(regoInterpreter* rego, const char* dir, regoBundle* bundle);
455
467 regoInterpreter* rego, const char* path, regoBundle* bundle);
468
481
497 regoInterpreter* rego, regoBundle* bundle, const char* endpoint);
498
500 // -------- Output functions -------- //
502
511
517
525
531
539
549 regoOutput* output, regoSize index, const char* name);
550
558 REGO_API(regoNode*) regoOutputBinding(regoOutput* output, const char* name);
559
568
579 regoOutputJSON(regoOutput* output, char* buffer, regoSize size);
580
585
587 // --------- Node functions --------- //
589
590 // clang-format off
591
628
629 // clang-format on
630
639
651 regoNodeTypeName(regoNode* node, char* buffer, regoSize size);
652
661
670 REGO_API(regoEnum) regoNodeValue(regoNode* node, char* buffer, regoSize size);
671
676
682
691
700 REGO_API(regoEnum) regoNodeJSON(regoNode* node, char* buffer, regoSize size);
701
703 // --------- Input functions --------- //
705
706 // clang-format off
707
755
756 // clang-format on
757
763
769
774 REGO_API(regoEnum) regoInputString(regoInput* input, const char* value);
775
781
786
796
805
813
823
833
839
844
849
851 // --------- Bundle functions --------- //
853
863
871
877
878#ifdef __cplusplus
879}
880#endif
881
882#endif
Definition rego.hh:18
void regoSetStrictBuiltInErrors(regoInterpreter *rego, regoBoolean enabled)
Sets whether the built-ins should throw errors.
regoEnum regoAddEntrypoint(regoInterpreter *rego, const char *entrypoint)
Adds an entrypoint to the interpreter.
regoNode * regoOutputExpressionsAtIndex(regoOutput *output, regoSize index)
Returns a node containing a list of terms resulting from the query at the specified index.
regoEnum regoVersion(char *buffer, regoSize size)
Populate a buffer with a string representing the semantic version of the library.
regoSize regoBuildInfoSize(void)
Returns the number of bytes needed to store a 0-terminated string representing the build info.
regoEnum regoInputSet(regoInput *input, regoSize count)
Uses the top 'count' values on the stack to create a set and pushes it back onto the stack.
regoEnum regoError(regoInterpreter *rego, char *buffer, regoSize size)
Populate a buffer with the most recent error message.
regoEnum regoInputValidate(regoInput *input)
Validates the input object.
regoSize regoErrorSize(regoInterpreter *rego)
Returns the number of bytes needed to store a 0-terminated string representing the most recent error ...
regoEnum regoInputNull(regoInput *input)
Adds a null value to the input object.
regoOutput * regoBundleQuery(regoInterpreter *rego, regoBundle *bundle)
Performs a query against the specified bundle.
void regoInterpreter
Opaque interpreter type.
Definition rego_c.h:14
void regoFreeBundle(regoBundle *bundle)
Frees a Rego bundle.
regoEnum regoInputInt(regoInput *input, regoInt value)
Adds an integer value to the input object.
regoEnum regoBundleSaveBinary(regoInterpreter *rego, const char *path, regoBundle *bundle)
Saves a compiled Rego bundle to the specified binary file.
void regoInput
Opaque input type.
Definition rego_c.h:26
uint_least32_t regoSize
Size type.
Definition rego_c.h:35
regoBundle * regoBuild(regoInterpreter *rego)
Builds a compiled Rego bundle.
regoBoolean regoGetDebugEnabled(regoInterpreter *rego)
Gets the debug mode of the interpreter.
void regoFreeOutput(regoOutput *output)
Frees a Rego output.
regoSize regoVersionSize(void)
Returns the number of bytes needed to store a 0-terminated string representing version.
regoBoolean regoIsAvailableBuiltIn(regoInterpreter *rego, const char *name)
Returns whether the specified name corresponds to an available built-in in the interpreter.
void regoFree(regoInterpreter *rego)
Frees a Rego interpreter.
regoEnum regoNodeValue(regoNode *node, char *buffer, regoSize size)
Populate a buffer with the node value.
regoEnum regoNodeTypeName(regoNode *node, char *buffer, regoSize size)
Returns the name of the node type as a human-readable string.
void regoOutput
Opaque output type.
Definition rego_c.h:20
void regoSetDebugEnabled(regoInterpreter *rego, regoBoolean enabled)
Sets the debug mode of the interpreter.
regoOutput * regoQuery(regoInterpreter *rego, const char *query_expr)
Performs a query against the current base and virtual documents.
regoEnum regoSetLogLevel(regoInterpreter *rego, regoEnum level)
Sets the level of logging on the interpreter.
regoEnum regoSetDefaultLogLevel(regoEnum level)
Sets the default level of logging.
regoEnum regoAddModuleFile(regoInterpreter *rego, const char *path)
Adds a module (e.g. virtual document) from the file at the specified path.
regoSize regoNodeValueSize(regoNode *node)
Returns the number of bytes needed to store a 0-terminated string representing the text value of the ...
regoNode * regoOutputBinding(regoOutput *output, const char *name)
Returns the bound value for a given variable name at the first index.
regoSize regoNodeJSONSize(regoNode *node)
Returns the number of bytes needed to store a 0-terminated string representing the JSON representatio...
regoSize regoOutputJSONSize(regoOutput *output)
Returns the number of bytes needed to store a 0-terminated string representing the output as a human-...
regoNode * regoOutputBindingAtIndex(regoOutput *output, regoSize index, const char *name)
Returns the bound value for a given variable name.
void regoFreeInput(regoInput *input)
Frees a Rego Input object.
regoEnum regoInputFloat(regoInput *input, double value)
Adds a floating point value to the input object.
regoEnum regoInputObjectItem(regoInput *input)
Uses the top two values on the stack to create an object item and pushes it back onto the stack.
regoNode * regoBundleNode(regoBundle *bundle)
Returns a node containing the base document of the bundle.
regoEnum regoSetInputTerm(regoInterpreter *rego, const char *contents)
Sets the current input document from the specified string.
regoEnum regoNodeJSON(regoNode *node, char *buffer, regoSize size)
Populate a buffer with the JSON representation of the node.
regoType regoNodeType(regoNode *node)
Returns an enumeration value indicating the node's type.
regoBoolean regoOutputOk(regoOutput *output)
Returns whether the output is ok.
void regoNode
Opaque node type.
Definition rego_c.h:17
regoEnum regoSetInputJSONFile(regoInterpreter *rego, const char *path)
Sets the current input document from the file at the specified path.
uint_least8_t regoBoolean
Boolean type.
Definition rego_c.h:29
regoInterpreter * regoNew(void)
Allocates and initializes a new Rego interpreter.
regoEnum regoInputBoolean(regoInput *input, regoBoolean value)
Adds a boolean value to the input object.
regoBoolean regoGetStrictBuiltInErrors(regoInterpreter *rego)
Gets whether strict built-in errors are enabled.
regoInput * regoNewInput()
Allocates and initializes a new Rego Input object.
void regoSetWellFormedChecksEnabled(regoInterpreter *rego, regoBoolean enabled)
Sets whether to perform well-formedness checks after each compiler pass.
uint_least32_t regoType
Node Type type.
Definition rego_c.h:41
regoNode * regoInputNode(regoInput *input)
Returns the top of the Input stack.
regoOutput * regoBundleQueryEntrypoint(regoInterpreter *rego, regoBundle *bundle, const char *endpoint)
Performs a query against the specified bundle at the specified entrypoint.
regoEnum regoSetDebugPath(regoInterpreter *rego, const char *path)
Sets the path to the debug directory.
regoEnum regoInputString(regoInput *input, const char *value)
Adds a string value to the input object.
regoBoolean regoBundleOk(regoBundle *bundle)
Returns whether the bundle is ok.
regoNode * regoOutputExpressions(regoOutput *output)
Returns a node containing a list of terms resulting from the query at the default index.
regoBundle * regoBundleLoad(regoInterpreter *rego, const char *dir)
Loads a compiled Rego bundle from the specified directory.
regoEnum regoOutputJSON(regoOutput *output, char *buffer, regoSize size)
Populate a buffer with the output represented as a human-readable string.
regoEnum regoAddDataJSONFile(regoInterpreter *rego, const char *path)
Adds a base document from the file at the specified path.
regoEnum regoInputArray(regoInput *input, regoSize count)
Uses the top 'count' values on the stack to create an array and pushes it back onto the stack.
regoNode * regoOutputNode(regoOutput *output)
Returns the node containing the output of the query.
int_least64_t regoInt
Integer type.
Definition rego_c.h:38
regoEnum regoInputObject(regoInput *input, regoSize count)
Uses the top 'count' values on the stack to create an object and pushes it back onto the stack.
regoEnum regoAddModule(regoInterpreter *rego, const char *name, const char *contents)
Adds a module (e.g. virtual document) from the specified string.
#define REGO_API(x)
Macro for exporting functions from a shared library on other platforms.
Definition rego_c.h:105
regoBoolean regoGetWellFormedChecksEnabled(regoInterpreter *rego)
Gets whether well-formedness checks are enabled.
regoSize regoInputSize(regoInput *input)
Returns the number of items on the Input stack.
regoEnum regoGetLogLevel(regoInterpreter *rego)
Gets the level of logging on the interpreter.
regoBundle * regoBundleLoadBinary(regoInterpreter *rego, const char *path)
Loads a compiled Rego bundle from the specified binary file.
regoEnum regoBuildInfo(char *buffer, regoSize size)
Populate a buffer with a string of the form "VERSION (BUILD_NAME,BUILD_DATE) BUILD_TOOLCHAIN on PLATF...
regoEnum regoAddDataJSON(regoInterpreter *rego, const char *contents)
Adds a base document from the specified string.
regoEnum regoLogLevelFromString(const char *level)
Gets a log level constant value from a string (case-invariant).
void regoBundle
Opaque bundle type.
Definition rego_c.h:23
regoEnum regoSetQuery(regoInterpreter *rego, const char *query_expr)
Sets the query for the interpreter.
uint_least32_t regoEnum
Enum type.
Definition rego_c.h:32
regoEnum regoNodeTypeNameSize(regoNode *node)
Returns the number of bytes needed to store a 0-terminated string representing the name of the node t...
regoEnum regoSetInput(regoInterpreter *rego, regoInput *input)
Sets the current input document from the specified Input object.
regoEnum regoBundleSave(regoInterpreter *rego, const char *dir, regoBundle *bundle)
Saves a compiled Rego bundle to the specified directory.
regoSize regoOutputSize(regoOutput *output)
Returns the number of results in the output.
regoSize regoNodeSize(regoNode *node)
Returns the number of children of the node.
regoNode * regoNodeGet(regoNode *node, regoSize index)
Returns the child node at the specified index.