datadog-ruby_core_source 3.5.5 → 3.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +0 -2
  3. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/ccan/build_assert/build_assert.h +40 -0
  4. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/ccan/check_type/check_type.h +63 -0
  5. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/ccan/container_of/container_of.h +142 -0
  6. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/ccan/list/list.h +791 -0
  7. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/ccan/str/str.h +17 -0
  8. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/constant.h +53 -0
  9. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/debug_counter.h +428 -0
  10. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/hrtime.h +237 -0
  11. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/id.h +365 -0
  12. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/id_table.h +74 -0
  13. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/internal/array.h +158 -0
  14. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/internal/basic_operators.h +67 -0
  15. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/internal/bits.h +647 -0
  16. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/internal/box.h +103 -0
  17. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/internal/class.h +797 -0
  18. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/internal/compilers.h +104 -0
  19. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/internal/coverage.h +51 -0
  20. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/internal/gc.h +411 -0
  21. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/internal/imemo.h +302 -0
  22. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/internal/sanitizers.h +346 -0
  23. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/internal/serial.h +23 -0
  24. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/internal/set_table.h +77 -0
  25. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/internal/static_assert.h +16 -0
  26. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/internal/time.h +34 -0
  27. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/internal/variable.h +81 -0
  28. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/internal/vm.h +144 -0
  29. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/internal/warnings.h +16 -0
  30. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/internal.h +106 -0
  31. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/iseq.h +439 -0
  32. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/method.h +279 -0
  33. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/node.h +122 -0
  34. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/parser_st.h +161 -0
  35. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/parser_value.h +116 -0
  36. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/arena.h +37 -0
  37. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/ast.h +10371 -0
  38. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/buffer.h +52 -0
  39. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/comments.h +43 -0
  40. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/compiler/align.h +36 -0
  41. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/compiler/exported.h +24 -0
  42. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/compiler/filesystem.h +32 -0
  43. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/compiler/nodiscard.h +22 -0
  44. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/compiler/nonnull.h +18 -0
  45. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/constant_pool.h +81 -0
  46. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/diagnostic.h +93 -0
  47. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/errors_format.h +53 -0
  48. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/excludes.h +29 -0
  49. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/integer.h +41 -0
  50. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/json.h +32 -0
  51. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/line_offset_list.h +61 -0
  52. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/magic_comments.h +35 -0
  53. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/node.h +94 -0
  54. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/options.h +335 -0
  55. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/parser.h +348 -0
  56. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/prettyprint.h +31 -0
  57. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/prism.h +131 -0
  58. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/serialize.h +115 -0
  59. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/source.h +155 -0
  60. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/stream.h +28 -0
  61. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/string_query.h +63 -0
  62. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/stringy.h +72 -0
  63. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/version.h +38 -0
  64. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism_compile.h +204 -0
  65. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/ractor_core.h +421 -0
  66. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/ruby_assert.h +14 -0
  67. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/ruby_atomic.h +115 -0
  68. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/rubyparser.h +1389 -0
  69. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/shape.h +733 -0
  70. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/thread_none.h +25 -0
  71. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/thread_pthread.h +63 -0
  72. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/thread_sched.h +271 -0
  73. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/vm_core.h +2509 -0
  74. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/vm_debug.h +124 -0
  75. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/vm_opts.h +65 -0
  76. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/vm_sync.h +160 -0
  77. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/zjit.h +221 -0
  78. data/lib/datadog/ruby_core_source/version.rb +1 -1
  79. metadata +77 -2
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @file buffer.h
3
+ *
4
+ * A wrapper around a contiguous block of allocated memory.
5
+ */
6
+ #ifndef PRISM_BUFFER_H
7
+ #define PRISM_BUFFER_H
8
+
9
+ #include "prism/compiler/exported.h"
10
+ #include "prism/compiler/nodiscard.h"
11
+ #include "prism/compiler/nonnull.h"
12
+
13
+ #include <stddef.h>
14
+
15
+ /**
16
+ * A wrapper around a contiguous block of allocated memory.
17
+ */
18
+ typedef struct pm_buffer_t pm_buffer_t;
19
+
20
+ /**
21
+ * Allocate and initialize a new buffer. If the buffer cannot be allocated, this
22
+ * function will abort the process.
23
+ *
24
+ * @returns A pointer to the initialized buffer. The caller is responsible for
25
+ * freeing the buffer with pm_buffer_free.
26
+ */
27
+ PRISM_NODISCARD PRISM_EXPORTED_FUNCTION pm_buffer_t * pm_buffer_new(void);
28
+
29
+ /**
30
+ * Free both the memory held by the buffer and the buffer itself.
31
+ *
32
+ * @param buffer The buffer to free.
33
+ */
34
+ PRISM_EXPORTED_FUNCTION void pm_buffer_free(pm_buffer_t *buffer) PRISM_NONNULL(1);
35
+
36
+ /**
37
+ * Return the value of the buffer.
38
+ *
39
+ * @param buffer The buffer to get the value of.
40
+ * @returns The value of the buffer.
41
+ */
42
+ PRISM_EXPORTED_FUNCTION char * pm_buffer_value(const pm_buffer_t *buffer) PRISM_NONNULL(1);
43
+
44
+ /**
45
+ * Return the length of the buffer.
46
+ *
47
+ * @param buffer The buffer to get the length of.
48
+ * @returns The length of the buffer.
49
+ */
50
+ PRISM_EXPORTED_FUNCTION size_t pm_buffer_length(const pm_buffer_t *buffer) PRISM_NONNULL(1);
51
+
52
+ #endif
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @file comments.h
3
+ *
4
+ * Types and functions related to comments found during parsing.
5
+ */
6
+ #ifndef PRISM_COMMENTS_H
7
+ #define PRISM_COMMENTS_H
8
+
9
+ #include "prism/compiler/exported.h"
10
+ #include "prism/compiler/nodiscard.h"
11
+ #include "prism/compiler/nonnull.h"
12
+
13
+ #include "prism/ast.h"
14
+
15
+ #include <stddef.h>
16
+
17
+ /** This is the type of a comment that we've found while parsing. */
18
+ typedef enum {
19
+ PM_COMMENT_INLINE,
20
+ PM_COMMENT_EMBDOC
21
+ } pm_comment_type_t;
22
+
23
+ /** An opaque pointer to a comment found while parsing. */
24
+ typedef struct pm_comment_t pm_comment_t;
25
+
26
+ /**
27
+ * Returns the location associated with the given comment.
28
+ *
29
+ * @param comment the comment whose location we want to get
30
+ * @returns the location associated with the given comment
31
+ */
32
+ PRISM_EXPORTED_FUNCTION pm_location_t pm_comment_location(const pm_comment_t *comment) PRISM_NONNULL(1);
33
+
34
+ /**
35
+ * Returns the type associated with the given comment.
36
+ *
37
+ * @param comment the comment whose type we want to get
38
+ * @returns the type associated with the given comment. This can either be
39
+ * PM_COMMENT_INLINE or PM_COMMENT_EMBDOC.
40
+ */
41
+ PRISM_EXPORTED_FUNCTION pm_comment_type_t pm_comment_type(const pm_comment_t *comment) PRISM_NONNULL(1);
42
+
43
+ #endif
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @file compiler/align.h
3
+ */
4
+ #ifndef PRISM_COMPILER_ALIGN_H
5
+ #define PRISM_COMPILER_ALIGN_H
6
+
7
+ /**
8
+ * Compiler-agnostic macros for specifying alignment of types and variables.
9
+ */
10
+ #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L /* C11 or later */
11
+ /** Specify alignment for a type or variable. */
12
+ #define PRISM_ALIGNAS _Alignas
13
+
14
+ /** Get the alignment requirement of a type. */
15
+ #define PRISM_ALIGNOF _Alignof
16
+ #elif defined(__GNUC__) || defined(__clang__)
17
+ /** Specify alignment for a type or variable. */
18
+ #define PRISM_ALIGNAS(size) __attribute__((aligned(size)))
19
+
20
+ /** Get the alignment requirement of a type. */
21
+ #define PRISM_ALIGNOF(type) __alignof__(type)
22
+ #elif defined(_MSC_VER)
23
+ /** Specify alignment for a type or variable. */
24
+ #define PRISM_ALIGNAS(size) __declspec(align(size))
25
+
26
+ /** Get the alignment requirement of a type. */
27
+ #define PRISM_ALIGNOF(type) __alignof(type)
28
+ #else
29
+ /** Void because this platform does not support specifying alignment. */
30
+ #define PRISM_ALIGNAS(size)
31
+
32
+ /** Fallback to sizeof as alignment requirement of a type. */
33
+ #define PRISM_ALIGNOF(type) sizeof(type)
34
+ #endif
35
+
36
+ #endif
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @file compiler/exported.h
3
+ */
4
+ #ifndef PRISM_COMPILER_EXPORTED_H
5
+ #define PRISM_COMPILER_EXPORTED_H
6
+
7
+ /**
8
+ * By default, we compile with -fvisibility=hidden. When this is enabled, we
9
+ * need to mark certain functions as being publically-visible. This macro does
10
+ * that in a compiler-agnostic way.
11
+ */
12
+ #ifndef PRISM_EXPORTED_FUNCTION
13
+ # ifdef PRISM_EXPORT_SYMBOLS
14
+ # ifdef _WIN32
15
+ # define PRISM_EXPORTED_FUNCTION __declspec(dllexport) extern
16
+ # else
17
+ # define PRISM_EXPORTED_FUNCTION __attribute__((__visibility__("default"))) extern
18
+ # endif
19
+ # else
20
+ # define PRISM_EXPORTED_FUNCTION
21
+ # endif
22
+ #endif
23
+
24
+ #endif
@@ -0,0 +1,32 @@
1
+ /**
2
+ * @file compiler/filesystem.h
3
+ *
4
+ * Platform detection for mmap and filesystem support.
5
+ */
6
+ #ifndef PRISM_COMPILER_FILESYSTEM_H
7
+ #define PRISM_COMPILER_FILESYSTEM_H
8
+
9
+ /**
10
+ * In general, libc for embedded systems does not support memory-mapped files.
11
+ * If the target platform is POSIX or Windows, we can map a file in memory and
12
+ * read it in a more efficient manner.
13
+ */
14
+ #ifdef _WIN32
15
+ # define PRISM_HAS_MMAP
16
+ #else
17
+ # include <unistd.h>
18
+ # ifdef _POSIX_MAPPED_FILES
19
+ # define PRISM_HAS_MMAP
20
+ # endif
21
+ #endif
22
+
23
+ /**
24
+ * If PRISM_HAS_NO_FILESYSTEM is defined, then we want to exclude all filesystem
25
+ * related code from the library. All filesystem related code should be guarded
26
+ * by PRISM_HAS_FILESYSTEM.
27
+ */
28
+ #ifndef PRISM_HAS_NO_FILESYSTEM
29
+ # define PRISM_HAS_FILESYSTEM
30
+ #endif
31
+
32
+ #endif
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @file compiler/nodiscard.h
3
+ */
4
+ #ifndef PRISM_COMPILER_NODISCARD_H
5
+ #define PRISM_COMPILER_NODISCARD_H
6
+
7
+ /**
8
+ * Mark the return value of a function as important so that the compiler warns
9
+ * if a caller ignores it. This is useful for functions that return error codes
10
+ * or allocated resources that must be freed.
11
+ */
12
+ #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
13
+ # define PRISM_NODISCARD [[nodiscard]]
14
+ #elif defined(__GNUC__) || defined(__clang__)
15
+ # define PRISM_NODISCARD __attribute__((__warn_unused_result__))
16
+ #elif defined(_MSC_VER)
17
+ # define PRISM_NODISCARD _Check_return_
18
+ #else
19
+ # define PRISM_NODISCARD
20
+ #endif
21
+
22
+ #endif
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @file compiler/nonnull.h
3
+ */
4
+ #ifndef PRISM_COMPILER_NONNULL_H
5
+ #define PRISM_COMPILER_NONNULL_H
6
+
7
+ /**
8
+ * Mark the parameters of a function as non-null. This allows the compiler to
9
+ * warn if a caller passes NULL for a parameter that should never be NULL. The
10
+ * arguments are the 1-based indices of the parameters.
11
+ */
12
+ #if defined(__GNUC__) || defined(__clang__)
13
+ # define PRISM_NONNULL(...) __attribute__((__nonnull__(__VA_ARGS__)))
14
+ #else
15
+ # define PRISM_NONNULL(...)
16
+ #endif
17
+
18
+ #endif
@@ -0,0 +1,81 @@
1
+ /**
2
+ * @file constant_pool.h
3
+ *
4
+ * A data structure that stores a set of strings.
5
+ *
6
+ * Each string is assigned a unique id, which can be used to compare strings for
7
+ * equality. This comparison ends up being much faster than strcmp, since it
8
+ * only requires a single integer comparison.
9
+ */
10
+ #ifndef PRISM_CONSTANT_POOL_H
11
+ #define PRISM_CONSTANT_POOL_H
12
+
13
+ #include "prism/compiler/exported.h"
14
+ #include "prism/compiler/nodiscard.h"
15
+ #include "prism/compiler/nonnull.h"
16
+
17
+ #include "prism/arena.h"
18
+
19
+ #include <stddef.h>
20
+ #include <stdint.h>
21
+
22
+ /**
23
+ * A constant id is a unique identifier for a constant in the constant pool.
24
+ */
25
+ typedef uint32_t pm_constant_id_t;
26
+
27
+ /**
28
+ * A list of constant IDs. Usually used to represent a set of locals.
29
+ */
30
+ typedef struct {
31
+ /** The number of constant ids in the list. */
32
+ size_t size;
33
+
34
+ /** The number of constant ids that have been allocated in the list. */
35
+ size_t capacity;
36
+
37
+ /** The constant ids in the list. */
38
+ pm_constant_id_t *ids;
39
+ } pm_constant_id_list_t;
40
+
41
+ /** A constant in the pool which effectively stores a string. */
42
+ typedef struct pm_constant_t pm_constant_t;
43
+
44
+ /**
45
+ * The overall constant pool, which stores constants found while parsing.
46
+ */
47
+ typedef struct pm_constant_pool_t pm_constant_pool_t;
48
+
49
+ /**
50
+ * Return a raw pointer to the start of a constant.
51
+ *
52
+ * @param constant The constant to get the start of.
53
+ * @returns A raw pointer to the start of the constant.
54
+ */
55
+ PRISM_EXPORTED_FUNCTION const uint8_t * pm_constant_start(const pm_constant_t *constant) PRISM_NONNULL(1);
56
+
57
+ /**
58
+ * Return the length of a constant.
59
+ *
60
+ * @param constant The constant to get the length of.
61
+ * @returns The length of the constant.
62
+ */
63
+ PRISM_EXPORTED_FUNCTION size_t pm_constant_length(const pm_constant_t *constant) PRISM_NONNULL(1);
64
+
65
+ /**
66
+ * Initialize a list of constant ids.
67
+ *
68
+ * @param list The list to initialize.
69
+ */
70
+ PRISM_EXPORTED_FUNCTION void pm_constant_id_list_init(pm_constant_id_list_t *list) PRISM_NONNULL(1);
71
+
72
+ /**
73
+ * Append a constant id to a list of constant ids.
74
+ *
75
+ * @param arena The arena to use for allocations.
76
+ * @param list The list to append to.
77
+ * @param id The constant id to append.
78
+ */
79
+ PRISM_EXPORTED_FUNCTION void pm_constant_id_list_append(pm_arena_t *arena, pm_constant_id_list_t *list, pm_constant_id_t id) PRISM_NONNULL(1, 2);
80
+
81
+ #endif
@@ -0,0 +1,93 @@
1
+ /**
2
+ * @file diagnostic.h
3
+ *
4
+ * A list of diagnostics generated during parsing.
5
+ */
6
+ #ifndef PRISM_DIAGNOSTIC_H
7
+ #define PRISM_DIAGNOSTIC_H
8
+
9
+ #include "prism/compiler/exported.h"
10
+ #include "prism/compiler/nodiscard.h"
11
+ #include "prism/compiler/nonnull.h"
12
+
13
+ #include "prism/ast.h"
14
+
15
+ /**
16
+ * An opaque pointer to a diagnostic generated during parsing.
17
+ */
18
+ typedef struct pm_diagnostic_t pm_diagnostic_t;
19
+
20
+ /**
21
+ * The levels of errors generated during parsing.
22
+ */
23
+ typedef enum {
24
+ /** For errors that should raise a syntax error. */
25
+ PM_ERROR_LEVEL_SYNTAX = 0,
26
+
27
+ /** For errors that should raise an argument error. */
28
+ PM_ERROR_LEVEL_ARGUMENT = 1,
29
+
30
+ /** For errors that should raise a load error. */
31
+ PM_ERROR_LEVEL_LOAD = 2
32
+ } pm_error_level_t;
33
+
34
+ /**
35
+ * The levels of warnings generated during parsing.
36
+ */
37
+ typedef enum {
38
+ /** For warnings which should be emitted if $VERBOSE != nil. */
39
+ PM_WARNING_LEVEL_DEFAULT = 0,
40
+
41
+ /** For warnings which should be emitted if $VERBOSE == true. */
42
+ PM_WARNING_LEVEL_VERBOSE = 1
43
+ } pm_warning_level_t;
44
+
45
+ /**
46
+ * Get the type of the given diagnostic.
47
+ *
48
+ * @param diagnostic The diagnostic to get the type of.
49
+ * @returns The type of the given diagnostic. Note that this is a string
50
+ * representation of an internal ID, and is not meant to be relied upon as a
51
+ * stable identifier for the diagnostic. We do not guarantee that these will
52
+ * not change in the future. This is meant to be used for debugging and
53
+ * error reporting purposes, and not for programmatic checks.
54
+ */
55
+ PRISM_EXPORTED_FUNCTION const char * pm_diagnostic_type(const pm_diagnostic_t *diagnostic) PRISM_NONNULL(1);
56
+
57
+ /**
58
+ * Get the location of the given diagnostic.
59
+ *
60
+ * @param diagnostic The diagnostic to get the location of.
61
+ * @returns The location of the given diagnostic.
62
+ */
63
+ PRISM_EXPORTED_FUNCTION pm_location_t pm_diagnostic_location(const pm_diagnostic_t *diagnostic) PRISM_NONNULL(1);
64
+
65
+ /**
66
+ * Get the message of the given diagnostic.
67
+ *
68
+ * @param diagnostic The diagnostic to get the message of.
69
+ * @returns The message of the given diagnostic.
70
+ */
71
+ PRISM_EXPORTED_FUNCTION const char * pm_diagnostic_message(const pm_diagnostic_t *diagnostic) PRISM_NONNULL(1);
72
+
73
+ /**
74
+ * Get the error level associated with the given diagnostic.
75
+ *
76
+ * @param diagnostic The diagnostic to get the error level of.
77
+ * @returns The error level of the given diagnostic. If the diagnostic was a
78
+ * warning, or is in any way not an error, then the return value is
79
+ * undefined and should not be relied upon.
80
+ */
81
+ PRISM_EXPORTED_FUNCTION pm_error_level_t pm_diagnostic_error_level(const pm_diagnostic_t *diagnostic) PRISM_NONNULL(1);
82
+
83
+ /**
84
+ * Get the warning level associated with the given diagnostic.
85
+ *
86
+ * @param diagnostic The diagnostic to get the warning level of.
87
+ * @returns The warning level of the given diagnostic. If the diagnostic was an
88
+ * error, or is in any way not a warning, then the return value is
89
+ * undefined and should not be relied upon.
90
+ */
91
+ PRISM_EXPORTED_FUNCTION pm_warning_level_t pm_diagnostic_warning_level(const pm_diagnostic_t *diagnostic) PRISM_NONNULL(1);
92
+
93
+ #endif
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @file errors_format.h
3
+ *
4
+ * A function for formatting the errors in a parser into a buffer.
5
+ */
6
+ #ifndef PRISM_ERRORS_FORMAT_H
7
+ #define PRISM_ERRORS_FORMAT_H
8
+
9
+ #include "prism/compiler/exported.h"
10
+ #include "prism/compiler/nodiscard.h"
11
+ #include "prism/compiler/nonnull.h"
12
+
13
+ #include "prism/buffer.h"
14
+ #include "prism/diagnostic.h"
15
+ #include "prism/parser.h"
16
+
17
+ /** The type of formatting to use when formatting errors. */
18
+ typedef enum {
19
+ /** Format errors in a plain format with no colors or styles. Typically
20
+ * used when outputting to a file or when the output is not a terminal.
21
+ */
22
+ PM_ERRORS_FORMAT_PLAIN = 1,
23
+
24
+ /** Format errors in a style format with bold only. Typically used when
25
+ * outputting to a terminal where you do not want colors.
26
+ */
27
+ PM_ERRORS_FORMAT_STYLE = 2,
28
+
29
+ /** Format errors in a color format with bold and colors. The default case
30
+ * when outputting on the terminal.
31
+ */
32
+ PM_ERRORS_FORMAT_COLOR = 3
33
+ } pm_errors_format_type_t;
34
+
35
+ /**
36
+ * Format the errors in a parser into a buffer. After return, the buffer will
37
+ * contain the formatted errors and any relevant source snippets if available
38
+ * and possible.
39
+ *
40
+ * @param parser The parser containing the errors to format. Note that the
41
+ * parser does not need to be fully initialized, but it will need to have
42
+ * start, end, start_line, encoding, line_offsets, filepath, and error_list
43
+ * initialized.
44
+ * @param buffer The buffer to format the errors into.
45
+ * @param format_type The type of formatting to use when formatting the errors.
46
+ * @returns The error level of the error with the highest precedence that was
47
+ * formatted. In practice this means it will be the argument or load error
48
+ * level if any were found, otherwise it will be the syntax error level.
49
+ * Callers should raise appropriate error types based on the returned level.
50
+ */
51
+ PRISM_EXPORTED_FUNCTION pm_error_level_t pm_errors_format(const pm_parser_t *parser, pm_buffer_t *buffer, pm_errors_format_type_t format_type) PRISM_NONNULL(1, 2);
52
+
53
+ #endif
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @file excludes.h
3
+ *
4
+ * A header file that defines macros to exclude certain features of the prism
5
+ * library. This is useful for reducing the size of the library when certain
6
+ * features are not needed.
7
+ */
8
+ #ifndef PRISM_EXCLUDES_H
9
+ #define PRISM_EXCLUDES_H
10
+
11
+ /**
12
+ * If PRISM_BUILD_MINIMAL is defined, then we're going to define every possible
13
+ * switch that will turn off certain features of prism.
14
+ */
15
+ #ifdef PRISM_BUILD_MINIMAL
16
+ /** Exclude the serialization API. */
17
+ #define PRISM_EXCLUDE_SERIALIZATION
18
+
19
+ /** Exclude the JSON serialization API. */
20
+ #define PRISM_EXCLUDE_JSON
21
+
22
+ /** Exclude the prettyprint API. */
23
+ #define PRISM_EXCLUDE_PRETTYPRINT
24
+
25
+ /** Exclude the full set of encodings, using the minimal only. */
26
+ #define PRISM_ENCODING_EXCLUDE_FULL
27
+ #endif
28
+
29
+ #endif
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @file integer.h
3
+ *
4
+ * This module provides functions for working with arbitrary-sized integers.
5
+ */
6
+ #ifndef PRISM_INTEGER_H
7
+ #define PRISM_INTEGER_H
8
+
9
+ #include <stdbool.h>
10
+ #include <stddef.h>
11
+ #include <stdint.h>
12
+
13
+ /**
14
+ * A structure represents an arbitrary-sized integer.
15
+ */
16
+ typedef struct {
17
+ /**
18
+ * The number of allocated values. length is set to 0 if the integer fits
19
+ * into uint32_t.
20
+ */
21
+ size_t length;
22
+
23
+ /**
24
+ * List of 32-bit integers. Set to NULL if the integer fits into uint32_t.
25
+ */
26
+ uint32_t *values;
27
+
28
+ /**
29
+ * Embedded value for small integer. This value is set to 0 if the value
30
+ * does not fit into uint32_t.
31
+ */
32
+ uint32_t value;
33
+
34
+ /**
35
+ * Whether or not the integer is negative. It is stored this way so that a
36
+ * zeroed pm_integer_t is always positive zero.
37
+ */
38
+ bool negative;
39
+ } pm_integer_t;
40
+
41
+ #endif
@@ -0,0 +1,32 @@
1
+ /**
2
+ * @file json.h
3
+ */
4
+ #ifndef PRISM_JSON_H
5
+ #define PRISM_JSON_H
6
+
7
+ #include "prism/excludes.h"
8
+
9
+ /* We optionally support dumping to JSON. For systems that don't want or need
10
+ * this functionality, it can be turned off with the PRISM_EXCLUDE_JSON define.
11
+ */
12
+ #ifndef PRISM_EXCLUDE_JSON
13
+
14
+ #include "prism/compiler/exported.h"
15
+ #include "prism/compiler/nonnull.h"
16
+
17
+ #include "prism/ast.h"
18
+ #include "prism/buffer.h"
19
+ #include "prism/parser.h"
20
+
21
+ /**
22
+ * Dump JSON to the given buffer.
23
+ *
24
+ * @param buffer The buffer to serialize to.
25
+ * @param parser The parser that parsed the node.
26
+ * @param node The node to serialize.
27
+ */
28
+ PRISM_EXPORTED_FUNCTION void pm_dump_json(pm_buffer_t *buffer, const pm_parser_t *parser, const pm_node_t *node) PRISM_NONNULL(1, 2, 3);
29
+
30
+ #endif
31
+
32
+ #endif
@@ -0,0 +1,61 @@
1
+ /**
2
+ * @file line_offset_list.h
3
+ *
4
+ * A list of byte offsets of newlines in a string.
5
+ *
6
+ * When compiling the syntax tree, it's necessary to know the line and column
7
+ * of many nodes. This is necessary to support things like error messages,
8
+ * tracepoints, etc.
9
+ *
10
+ * It's possible that we could store the start line, start column, end line, and
11
+ * end column on every node in addition to the offsets that we already store,
12
+ * but that would be quite a lot of memory overhead.
13
+ */
14
+ #ifndef PRISM_LINE_OFFSET_LIST_H
15
+ #define PRISM_LINE_OFFSET_LIST_H
16
+
17
+ #include "prism/compiler/exported.h"
18
+ #include "prism/compiler/nonnull.h"
19
+
20
+ #include <stddef.h>
21
+ #include <stdint.h>
22
+
23
+ /**
24
+ * A list of offsets of the start of lines in a string. The offsets are assumed
25
+ * to be sorted/inserted in ascending order.
26
+ */
27
+ typedef struct {
28
+ /** The number of offsets in the list. */
29
+ size_t size;
30
+
31
+ /** The capacity of the list that has been allocated. */
32
+ size_t capacity;
33
+
34
+ /** The list of offsets. */
35
+ uint32_t *offsets;
36
+ } pm_line_offset_list_t;
37
+
38
+ /**
39
+ * A line and column in a string.
40
+ */
41
+ typedef struct {
42
+ /** The line number. */
43
+ int32_t line;
44
+
45
+ /** The column in bytes. */
46
+ uint32_t column;
47
+ } pm_line_column_t;
48
+
49
+ /**
50
+ * Returns the line and column of the given offset. If the offset is not in the
51
+ * list, the line and column of the closest offset less than the given offset
52
+ * are returned.
53
+ *
54
+ * @param list The list to search.
55
+ * @param cursor The offset to search for.
56
+ * @param start_line The line to start counting from.
57
+ * @returns The line and column of the given offset.
58
+ */
59
+ PRISM_EXPORTED_FUNCTION pm_line_column_t pm_line_offset_list_line_column(const pm_line_offset_list_t *list, uint32_t cursor, int32_t start_line) PRISM_NONNULL(1);
60
+
61
+ #endif
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @file magic_comments.h
3
+ *
4
+ * Types and functions related to magic comments found during parsing.
5
+ */
6
+ #ifndef PRISM_MAGIC_COMMENTS_H
7
+ #define PRISM_MAGIC_COMMENTS_H
8
+
9
+ #include "prism/compiler/exported.h"
10
+ #include "prism/compiler/nonnull.h"
11
+
12
+ #include "prism/ast.h"
13
+
14
+ #include <stddef.h>
15
+
16
+ /** An opaque pointer to a magic comment found while parsing. */
17
+ typedef struct pm_magic_comment_t pm_magic_comment_t;
18
+
19
+ /**
20
+ * Returns the location of the key associated with the given magic comment.
21
+ *
22
+ * @param magic_comment the magic comment whose key location we want to get
23
+ * @returns the location of the key associated with the given magic comment
24
+ */
25
+ PRISM_EXPORTED_FUNCTION pm_location_t pm_magic_comment_key(const pm_magic_comment_t *magic_comment) PRISM_NONNULL(1);
26
+
27
+ /**
28
+ * Returns the location of the value associated with the given magic comment.
29
+ *
30
+ * @param magic_comment the magic comment whose value location we want to get
31
+ * @returns the location of the value associated with the given magic comment
32
+ */
33
+ PRISM_EXPORTED_FUNCTION pm_location_t pm_magic_comment_value(const pm_magic_comment_t *magic_comment) PRISM_NONNULL(1);
34
+
35
+ #endif