14 #ifndef PRISM_EXCLUDE_SERIALIZATION
18 static inline uint32_t
19 pm_ptrdifft_to_u32(ptrdiff_t value) {
20 assert(value >= 0 && ((
unsigned long) value) < UINT32_MAX);
21 return (uint32_t) value;
24 static inline uint32_t
25 pm_sizet_to_u32(
size_t value) {
26 assert(value < UINT32_MAX);
27 return (uint32_t) value;
32 assert(location->
start);
33 assert(location->
end);
34 assert(location->
start <= location->
end);
42 switch (string->
type) {
43 case PM_STRING_SHARED: {
50 case PM_STRING_CONSTANT: {
58 case PM_STRING_MAPPED:
59 assert(
false &&
"Cannot serialize mapped strings.");
68 if (integer->
values == NULL) {
73 for (
size_t i = 0; i < integer->
length; i++) {
83 size_t offset = buffer->
length;
86 pm_serialize_location(parser, &node->
location, buffer);
118 pm_serialize_location(parser, &((
pm_and_node_t *)node)->operator_loc, buffer);
125 for (uint32_t index = 0; index < arguments_size; index++) {
132 uint32_t elements_size = pm_sizet_to_u32(((
pm_array_node_t *)node)->elements.size);
134 for (uint32_t index = 0; index < elements_size; index++) {
141 pm_serialize_location(parser, &((
pm_array_node_t *)node)->opening_loc, buffer);
147 pm_serialize_location(parser, &((
pm_array_node_t *)node)->closing_loc, buffer);
160 for (uint32_t index = 0; index < requireds_size; index++) {
170 for (uint32_t index = 0; index < posts_size; index++) {
195 pm_serialize_location(parser, &((
pm_assoc_node_t *)node)->operator_loc, buffer);
220 pm_serialize_location(parser, &((
pm_begin_node_t *)node)->begin_keyword_loc, buffer);
246 pm_serialize_location(parser, &((
pm_begin_node_t *)node)->end_keyword_loc, buffer);
267 uint32_t locals_size = pm_sizet_to_u32(((
pm_block_node_t *)node)->locals.size);
269 for (uint32_t index = 0; index < locals_size; index++) {
282 pm_serialize_location(parser, &((
pm_block_node_t *)node)->opening_loc, buffer);
283 pm_serialize_location(parser, &((
pm_block_node_t *)node)->closing_loc, buffer);
307 for (uint32_t index = 0; index < locals_size; index++) {
331 pm_serialize_location(parser, &((
pm_break_node_t *)node)->keyword_loc, buffer);
370 pm_serialize_location(parser, &((
pm_call_node_t *)node)->call_operator_loc, buffer);
377 pm_serialize_location(parser, &((
pm_call_node_t *)node)->message_loc, buffer);
383 pm_serialize_location(parser, &((
pm_call_node_t *)node)->opening_loc, buffer);
394 pm_serialize_location(parser, &((
pm_call_node_t *)node)->closing_loc, buffer);
478 for (uint32_t index = 0; index < conditions_size; index++) {
497 uint32_t conditions_size = pm_sizet_to_u32(((
pm_case_node_t *)node)->conditions.size);
499 for (uint32_t index = 0; index < conditions_size; index++) {
507 pm_serialize_location(parser, &((
pm_case_node_t *)node)->case_keyword_loc, buffer);
508 pm_serialize_location(parser, &((
pm_case_node_t *)node)->end_keyword_loc, buffer);
513 uint32_t locals_size = pm_sizet_to_u32(((
pm_class_node_t *)node)->locals.size);
515 for (uint32_t index = 0; index < locals_size; index++) {
518 pm_serialize_location(parser, &((
pm_class_node_t *)node)->class_keyword_loc, buffer);
520 if (((
pm_class_node_t *)node)->inheritance_operator_loc.start == NULL) {
524 pm_serialize_location(parser, &((
pm_class_node_t *)node)->inheritance_operator_loc, buffer);
536 pm_serialize_location(parser, &((
pm_class_node_t *)node)->end_keyword_loc, buffer);
682 size_t length_offset = buffer->
length;
686 pm_serialize_location(parser, &((
pm_def_node_t *)node)->name_loc, buffer);
702 uint32_t locals_size = pm_sizet_to_u32(((
pm_def_node_t *)node)->locals.size);
704 for (uint32_t index = 0; index < locals_size; index++) {
707 pm_serialize_location(parser, &((
pm_def_node_t *)node)->def_keyword_loc, buffer);
712 pm_serialize_location(parser, &((
pm_def_node_t *)node)->operator_loc, buffer);
718 pm_serialize_location(parser, &((
pm_def_node_t *)node)->lparen_loc, buffer);
724 pm_serialize_location(parser, &((
pm_def_node_t *)node)->rparen_loc, buffer);
730 pm_serialize_location(parser, &((
pm_def_node_t *)node)->equal_loc, buffer);
732 if (((
pm_def_node_t *)node)->end_keyword_loc.start == NULL) {
736 pm_serialize_location(parser, &((
pm_def_node_t *)node)->end_keyword_loc, buffer);
739 uint32_t length = pm_sizet_to_u32(buffer->
length - offset -
sizeof(uint32_t));
740 memcpy(buffer->
value + length_offset, &length,
sizeof(uint32_t));
758 pm_serialize_location(parser, &((
pm_defined_node_t *)node)->keyword_loc, buffer);
763 pm_serialize_location(parser, &((
pm_else_node_t *)node)->else_keyword_loc, buffer);
773 pm_serialize_location(parser, &((
pm_else_node_t *)node)->end_keyword_loc, buffer);
796 pm_serialize_location(parser, &((
pm_ensure_node_t *)node)->ensure_keyword_loc, buffer);
802 pm_serialize_location(parser, &((
pm_ensure_node_t *)node)->end_keyword_loc, buffer);
819 for (uint32_t index = 0; index < requireds_size; index++) {
866 pm_serialize_location(parser, &((
pm_for_node_t *)node)->for_keyword_loc, buffer);
867 pm_serialize_location(parser, &((
pm_for_node_t *)node)->in_keyword_loc, buffer);
872 pm_serialize_location(parser, &((
pm_for_node_t *)node)->do_keyword_loc, buffer);
874 pm_serialize_location(parser, &((
pm_for_node_t *)node)->end_keyword_loc, buffer);
939 pm_serialize_location(parser, &((
pm_hash_node_t *)node)->opening_loc, buffer);
940 uint32_t elements_size = pm_sizet_to_u32(((
pm_hash_node_t *)node)->elements.size);
942 for (uint32_t index = 0; index < elements_size; index++) {
945 pm_serialize_location(parser, &((
pm_hash_node_t *)node)->closing_loc, buffer);
957 for (uint32_t index = 0; index < elements_size; index++) {
981 if (((
pm_if_node_t *)node)->if_keyword_loc.start == NULL) {
985 pm_serialize_location(parser, &((
pm_if_node_t *)node)->if_keyword_loc, buffer);
988 if (((
pm_if_node_t *)node)->then_keyword_loc.start == NULL) {
992 pm_serialize_location(parser, &((
pm_if_node_t *)node)->then_keyword_loc, buffer);
1004 if (((
pm_if_node_t *)node)->end_keyword_loc.start == NULL) {
1008 pm_serialize_location(parser, &((
pm_if_node_t *)node)->end_keyword_loc, buffer);
1034 pm_serialize_location(parser, &((
pm_in_node_t *)node)->in_loc, buffer);
1039 pm_serialize_location(parser, &((
pm_in_node_t *)node)->then_loc, buffer);
1201 for (uint32_t index = 0; index < parts_size; index++) {
1212 for (uint32_t index = 0; index < parts_size; index++) {
1228 for (uint32_t index = 0; index < parts_size; index++) {
1249 for (uint32_t index = 0; index < parts_size; index++) {
1265 for (uint32_t index = 0; index < parts_size; index++) {
1283 for (uint32_t index = 0; index < elements_size; index++) {
1302 uint32_t locals_size = pm_sizet_to_u32(((
pm_lambda_node_t *)node)->locals.size);
1304 for (uint32_t index = 0; index < locals_size; index++) {
1307 pm_serialize_location(parser, &((
pm_lambda_node_t *)node)->operator_loc, buffer);
1308 pm_serialize_location(parser, &((
pm_lambda_node_t *)node)->opening_loc, buffer);
1309 pm_serialize_location(parser, &((
pm_lambda_node_t *)node)->closing_loc, buffer);
1398 for (uint32_t index = 0; index < targets_size; index++) {
1409 uint32_t locals_size = pm_sizet_to_u32(((
pm_module_node_t *)node)->locals.size);
1411 for (uint32_t index = 0; index < locals_size; index++) {
1414 pm_serialize_location(parser, &((
pm_module_node_t *)node)->module_keyword_loc, buffer);
1421 pm_serialize_location(parser, &((
pm_module_node_t *)node)->end_keyword_loc, buffer);
1429 for (uint32_t index = 0; index < lefts_size; index++) {
1439 for (uint32_t index = 0; index < rights_size; index++) {
1460 for (uint32_t index = 0; index < lefts_size; index++) {
1470 for (uint32_t index = 0; index < rights_size; index++) {
1496 pm_serialize_location(parser, &((
pm_next_node_t *)node)->keyword_loc, buffer);
1538 pm_serialize_location(parser, &((
pm_or_node_t *)node)->operator_loc, buffer);
1545 for (uint32_t index = 0; index < requireds_size; index++) {
1550 for (uint32_t index = 0; index < optionals_size; index++) {
1560 for (uint32_t index = 0; index < posts_size; index++) {
1565 for (uint32_t index = 0; index < keywords_size; index++) {
1631 uint32_t locals_size = pm_sizet_to_u32(((
pm_program_node_t *)node)->locals.size);
1633 for (uint32_t index = 0; index < locals_size; index++) {
1651 pm_serialize_location(parser, &((
pm_range_node_t *)node)->operator_loc, buffer);
1692 pm_serialize_location(parser, &((
pm_rescue_node_t *)node)->keyword_loc, buffer);
1693 uint32_t exceptions_size = pm_sizet_to_u32(((
pm_rescue_node_t *)node)->exceptions.size);
1695 for (uint32_t index = 0; index < exceptions_size; index++) {
1702 pm_serialize_location(parser, &((
pm_rescue_node_t *)node)->operator_loc, buffer);
1739 pm_serialize_location(parser, &((
pm_return_node_t *)node)->keyword_loc, buffer);
1760 for (uint32_t index = 0; index < locals_size; index++) {
1789 pm_serialize_location(parser, &((
pm_splat_node_t *)node)->operator_loc, buffer);
1801 for (uint32_t index = 0; index < body_size; index++) {
1812 pm_serialize_location(parser, &((
pm_string_node_t *)node)->opening_loc, buffer);
1814 pm_serialize_location(parser, &((
pm_string_node_t *)node)->content_loc, buffer);
1819 pm_serialize_location(parser, &((
pm_string_node_t *)node)->closing_loc, buffer);
1821 pm_serialize_string(parser, &((
pm_string_node_t *)node)->unescaped, buffer);
1826 pm_serialize_location(parser, &((
pm_super_node_t *)node)->keyword_loc, buffer);
1831 pm_serialize_location(parser, &((
pm_super_node_t *)node)->lparen_loc, buffer);
1842 pm_serialize_location(parser, &((
pm_super_node_t *)node)->rparen_loc, buffer);
1857 pm_serialize_location(parser, &((
pm_symbol_node_t *)node)->opening_loc, buffer);
1863 pm_serialize_location(parser, &((
pm_symbol_node_t *)node)->value_loc, buffer);
1869 pm_serialize_location(parser, &((
pm_symbol_node_t *)node)->closing_loc, buffer);
1871 pm_serialize_string(parser, &((
pm_symbol_node_t *)node)->unescaped, buffer);
1880 uint32_t names_size = pm_sizet_to_u32(((
pm_undef_node_t *)node)->names.size);
1882 for (uint32_t index = 0; index < names_size; index++) {
1885 pm_serialize_location(parser, &((
pm_undef_node_t *)node)->keyword_loc, buffer);
1890 pm_serialize_location(parser, &((
pm_unless_node_t *)node)->keyword_loc, buffer);
1896 pm_serialize_location(parser, &((
pm_unless_node_t *)node)->then_keyword_loc, buffer);
1912 pm_serialize_location(parser, &((
pm_unless_node_t *)node)->end_keyword_loc, buffer);
1918 pm_serialize_location(parser, &((
pm_until_node_t *)node)->keyword_loc, buffer);
1923 pm_serialize_location(parser, &((
pm_until_node_t *)node)->closing_loc, buffer);
1935 pm_serialize_location(parser, &((
pm_when_node_t *)node)->keyword_loc, buffer);
1936 uint32_t conditions_size = pm_sizet_to_u32(((
pm_when_node_t *)node)->conditions.size);
1938 for (uint32_t index = 0; index < conditions_size; index++) {
1945 pm_serialize_location(parser, &((
pm_when_node_t *)node)->then_keyword_loc, buffer);
1956 pm_serialize_location(parser, &((
pm_while_node_t *)node)->keyword_loc, buffer);
1961 pm_serialize_location(parser, &((
pm_while_node_t *)node)->closing_loc, buffer);
1981 pm_serialize_location(parser, &((
pm_yield_node_t *)node)->keyword_loc, buffer);
1986 pm_serialize_location(parser, &((
pm_yield_node_t *)node)->lparen_loc, buffer);
1997 pm_serialize_location(parser, &((
pm_yield_node_t *)node)->rparen_loc, buffer);
2006 uint32_t size = pm_sizet_to_u32(list->
size);
2009 for (uint32_t i = 0; i < size; i++) {
2010 uint32_t offset = pm_sizet_to_u32(list->
offsets[i]);
2021 pm_serialize_location(parser, &comment->
location, buffer);
2033 pm_serialize_comment(parser, comment, buffer);
2064 pm_serialize_location(parser, &parser->
data_loc, buffer);
2074 size_t message_length = strlen(diagnostic->
message);
2079 pm_serialize_location(parser, &diagnostic->
location, buffer);
2090 pm_serialize_diagnostic(parser, diagnostic, buffer);
2099 size_t encoding_length = strlen(encoding->
name);
2108 pm_serialize_newline_list(&parser->
newline_list, buffer);
2111 pm_serialize_data_loc(parser, buffer);
2112 pm_serialize_diagnostic_list(parser, &parser->
error_list, buffer);
2113 pm_serialize_diagnostic_list(parser, &parser->
warning_list, buffer);
2116 #line 275 "prism/templates/src/serialize.c.erb"
2122 pm_serialize_metadata(parser, buffer);
2126 size_t offset = buffer->
length;
2133 pm_serialize_node(parser, node, buffer);
2137 uint32_t length = pm_sizet_to_u32(buffer->
length);
2138 memcpy(buffer->
value + offset, &length,
sizeof(uint32_t));
2149 if (bucket->
id != 0) {
2151 size_t buffer_offset = offset + ((((size_t)bucket->
id) - 1) * 8);
2159 uint32_t content_offset = pm_sizet_to_u32(buffer->
length);
2160 uint32_t owned_mask = (uint32_t) (1 << 31);
2162 assert(content_offset < owned_mask);
2163 content_offset |= owned_mask;
2165 memcpy(buffer->
value + buffer_offset, &content_offset, 4);
2170 uint32_t source_offset = pm_ptrdifft_to_u32(constant->
start - parser->
start);
2171 memcpy(buffer->
value + buffer_offset, &source_offset, 4);
2175 uint32_t constant_length = pm_sizet_to_u32(constant->
length);
2176 memcpy(buffer->
value + buffer_offset + 4, &constant_length, 4);
2203 .
data = (
void *) buffer,
2204 .callback = serialize_token,
2213 pm_serialize_metadata(&parser, buffer);
2233 .
data = (
void *) buffer,
2234 .callback = serialize_token,
@ PM_DEFINED_NODE
DefinedNode.
@ PM_PRE_EXECUTION_NODE
PreExecutionNode.
@ PM_RETRY_NODE
RetryNode.
@ PM_CONSTANT_PATH_WRITE_NODE
ConstantPathWriteNode.
@ PM_INDEX_AND_WRITE_NODE
IndexAndWriteNode.
@ PM_SOURCE_LINE_NODE
SourceLineNode.
@ PM_UNLESS_NODE
UnlessNode.
@ PM_EMBEDDED_VARIABLE_NODE
EmbeddedVariableNode.
@ PM_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE
GlobalVariableOperatorWriteNode.
@ PM_GLOBAL_VARIABLE_READ_NODE
GlobalVariableReadNode.
@ PM_RATIONAL_NODE
RationalNode.
@ PM_YIELD_NODE
YieldNode.
@ PM_LOCAL_VARIABLE_AND_WRITE_NODE
LocalVariableAndWriteNode.
@ PM_CONSTANT_AND_WRITE_NODE
ConstantAndWriteNode.
@ PM_CLASS_NODE
ClassNode.
@ PM_FIND_PATTERN_NODE
FindPatternNode.
@ PM_CALL_OPERATOR_WRITE_NODE
CallOperatorWriteNode.
@ PM_MATCH_WRITE_NODE
MatchWriteNode.
@ PM_ARRAY_NODE
ArrayNode.
@ PM_CONSTANT_PATH_TARGET_NODE
ConstantPathTargetNode.
@ PM_PROGRAM_NODE
ProgramNode.
@ PM_MULTI_WRITE_NODE
MultiWriteNode.
@ PM_IMPLICIT_NODE
ImplicitNode.
@ PM_ARGUMENTS_NODE
ArgumentsNode.
@ PM_FORWARDING_SUPER_NODE
ForwardingSuperNode.
@ PM_WHILE_NODE
WhileNode.
@ PM_INTERPOLATED_STRING_NODE
InterpolatedStringNode.
@ PM_FALSE_NODE
FalseNode.
@ PM_FORWARDING_PARAMETER_NODE
ForwardingParameterNode.
@ PM_BLOCK_LOCAL_VARIABLE_NODE
BlockLocalVariableNode.
@ PM_UNTIL_NODE
UntilNode.
@ PM_MATCH_PREDICATE_NODE
MatchPredicateNode.
@ PM_X_STRING_NODE
XStringNode.
@ PM_LOCAL_VARIABLE_OPERATOR_WRITE_NODE
LocalVariableOperatorWriteNode.
@ PM_LOCAL_VARIABLE_OR_WRITE_NODE
LocalVariableOrWriteNode.
@ PM_INSTANCE_VARIABLE_AND_WRITE_NODE
InstanceVariableAndWriteNode.
@ PM_GLOBAL_VARIABLE_TARGET_NODE
GlobalVariableTargetNode.
@ PM_CONSTANT_TARGET_NODE
ConstantTargetNode.
@ PM_IT_LOCAL_VARIABLE_READ_NODE
ItLocalVariableReadNode.
@ PM_CONSTANT_PATH_AND_WRITE_NODE
ConstantPathAndWriteNode.
@ PM_BLOCK_PARAMETER_NODE
BlockParameterNode.
@ PM_CAPTURE_PATTERN_NODE
CapturePatternNode.
@ PM_SOURCE_FILE_NODE
SourceFileNode.
@ PM_NO_KEYWORDS_PARAMETER_NODE
NoKeywordsParameterNode.
@ PM_CONSTANT_PATH_OPERATOR_WRITE_NODE
ConstantPathOperatorWriteNode.
@ PM_MULTI_TARGET_NODE
MultiTargetNode.
@ PM_SPLAT_NODE
SplatNode.
@ PM_LAMBDA_NODE
LambdaNode.
@ PM_CLASS_VARIABLE_READ_NODE
ClassVariableReadNode.
@ PM_REQUIRED_KEYWORD_PARAMETER_NODE
RequiredKeywordParameterNode.
@ PM_CALL_TARGET_NODE
CallTargetNode.
@ PM_INTERPOLATED_MATCH_LAST_LINE_NODE
InterpolatedMatchLastLineNode.
@ PM_NUMBERED_PARAMETERS_NODE
NumberedParametersNode.
@ PM_SYMBOL_NODE
SymbolNode.
@ PM_RESCUE_MODIFIER_NODE
RescueModifierNode.
@ PM_ALIAS_METHOD_NODE
AliasMethodNode.
@ PM_MATCH_REQUIRED_NODE
MatchRequiredNode.
@ PM_FORWARDING_ARGUMENTS_NODE
ForwardingArgumentsNode.
@ PM_BACK_REFERENCE_READ_NODE
BackReferenceReadNode.
@ PM_SCOPE_NODE
A special kind of node used for compilation.
@ PM_BLOCK_ARGUMENT_NODE
BlockArgumentNode.
@ PM_MISSING_NODE
MissingNode.
@ PM_IMPLICIT_REST_NODE
ImplicitRestNode.
@ PM_ASSOC_SPLAT_NODE
AssocSplatNode.
@ PM_CLASS_VARIABLE_AND_WRITE_NODE
ClassVariableAndWriteNode.
@ PM_RANGE_NODE
RangeNode.
@ PM_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE
InstanceVariableOperatorWriteNode.
@ PM_LOCAL_VARIABLE_READ_NODE
LocalVariableReadNode.
@ PM_SHAREABLE_CONSTANT_NODE
ShareableConstantNode.
@ PM_INSTANCE_VARIABLE_OR_WRITE_NODE
InstanceVariableOrWriteNode.
@ PM_REGULAR_EXPRESSION_NODE
RegularExpressionNode.
@ PM_CLASS_VARIABLE_OR_WRITE_NODE
ClassVariableOrWriteNode.
@ PM_BLOCK_PARAMETERS_NODE
BlockParametersNode.
@ PM_CONSTANT_WRITE_NODE
ConstantWriteNode.
@ PM_HASH_PATTERN_NODE
HashPatternNode.
@ PM_INDEX_OPERATOR_WRITE_NODE
IndexOperatorWriteNode.
@ PM_UNDEF_NODE
UndefNode.
@ PM_ALTERNATION_PATTERN_NODE
AlternationPatternNode.
@ PM_ENSURE_NODE
EnsureNode.
@ PM_LOCAL_VARIABLE_WRITE_NODE
LocalVariableWriteNode.
@ PM_SINGLETON_CLASS_NODE
SingletonClassNode.
@ PM_KEYWORD_HASH_NODE
KeywordHashNode.
@ PM_PARENTHESES_NODE
ParenthesesNode.
@ PM_CLASS_VARIABLE_WRITE_NODE
ClassVariableWriteNode.
@ PM_POST_EXECUTION_NODE
PostExecutionNode.
@ PM_CONSTANT_OPERATOR_WRITE_NODE
ConstantOperatorWriteNode.
@ PM_RETURN_NODE
ReturnNode.
@ PM_MODULE_NODE
ModuleNode.
@ PM_ARRAY_PATTERN_NODE
ArrayPatternNode.
@ PM_SUPER_NODE
SuperNode.
@ PM_MATCH_LAST_LINE_NODE
MatchLastLineNode.
@ PM_CONSTANT_PATH_NODE
ConstantPathNode.
@ PM_INTERPOLATED_SYMBOL_NODE
InterpolatedSymbolNode.
@ PM_CALL_AND_WRITE_NODE
CallAndWriteNode.
@ PM_OPTIONAL_KEYWORD_PARAMETER_NODE
OptionalKeywordParameterNode.
@ PM_CLASS_VARIABLE_TARGET_NODE
ClassVariableTargetNode.
@ PM_CASE_MATCH_NODE
CaseMatchNode.
@ PM_BREAK_NODE
BreakNode.
@ PM_CALL_OR_WRITE_NODE
CallOrWriteNode.
@ PM_IMAGINARY_NODE
ImaginaryNode.
@ PM_CONSTANT_READ_NODE
ConstantReadNode.
@ PM_GLOBAL_VARIABLE_WRITE_NODE
GlobalVariableWriteNode.
@ PM_SOURCE_ENCODING_NODE
SourceEncodingNode.
@ PM_BEGIN_NODE
BeginNode.
@ PM_INTERPOLATED_X_STRING_NODE
InterpolatedXStringNode.
@ PM_INSTANCE_VARIABLE_READ_NODE
InstanceVariableReadNode.
@ PM_FLIP_FLOP_NODE
FlipFlopNode.
@ PM_PINNED_VARIABLE_NODE
PinnedVariableNode.
@ PM_REQUIRED_PARAMETER_NODE
RequiredParameterNode.
@ PM_INSTANCE_VARIABLE_WRITE_NODE
InstanceVariableWriteNode.
@ PM_INSTANCE_VARIABLE_TARGET_NODE
InstanceVariableTargetNode.
@ PM_GLOBAL_VARIABLE_AND_WRITE_NODE
GlobalVariableAndWriteNode.
@ PM_RESCUE_NODE
RescueNode.
@ PM_FLOAT_NODE
FloatNode.
@ PM_ASSOC_NODE
AssocNode.
@ PM_IT_PARAMETERS_NODE
ItParametersNode.
@ PM_INTEGER_NODE
IntegerNode.
@ PM_LOCAL_VARIABLE_TARGET_NODE
LocalVariableTargetNode.
@ PM_STRING_NODE
StringNode.
@ PM_INDEX_OR_WRITE_NODE
IndexOrWriteNode.
@ PM_ALIAS_GLOBAL_VARIABLE_NODE
AliasGlobalVariableNode.
@ PM_PARAMETERS_NODE
ParametersNode.
@ PM_NUMBERED_REFERENCE_READ_NODE
NumberedReferenceReadNode.
@ PM_CONSTANT_PATH_OR_WRITE_NODE
ConstantPathOrWriteNode.
@ PM_GLOBAL_VARIABLE_OR_WRITE_NODE
GlobalVariableOrWriteNode.
@ PM_CONSTANT_OR_WRITE_NODE
ConstantOrWriteNode.
@ PM_STATEMENTS_NODE
StatementsNode.
@ PM_OPTIONAL_PARAMETER_NODE
OptionalParameterNode.
@ PM_PINNED_EXPRESSION_NODE
PinnedExpressionNode.
@ PM_BLOCK_NODE
BlockNode.
@ PM_CLASS_VARIABLE_OPERATOR_WRITE_NODE
ClassVariableOperatorWriteNode.
@ PM_REST_PARAMETER_NODE
RestParameterNode.
@ PM_EMBEDDED_STATEMENTS_NODE
EmbeddedStatementsNode.
@ PM_INTERPOLATED_REGULAR_EXPRESSION_NODE
InterpolatedRegularExpressionNode.
@ PM_INDEX_TARGET_NODE
IndexTargetNode.
@ PM_KEYWORD_REST_PARAMETER_NODE
KeywordRestParameterNode.
#define PM_NODE_TYPE(node)
Cast the type to an enum to allow the compiler to provide exhaustiveness checking.
PRISM_EXPORTED_FUNCTION void pm_options_free(pm_options_t *options)
Free the internal memory associated with the options.
void pm_options_read(pm_options_t *options, const char *data)
Deserialize an options struct from the given binary string.
void void pm_buffer_append_string(pm_buffer_t *buffer, const char *value, size_t length)
Append a string to the buffer.
void pm_buffer_append_zeroes(pm_buffer_t *buffer, size_t length)
Append the given amount of space as zeroes to the buffer.
void pm_buffer_append_varuint(pm_buffer_t *buffer, uint32_t value)
Append a 32-bit unsigned integer to the buffer as a variable-length integer.
void pm_buffer_append_byte(pm_buffer_t *buffer, uint8_t value)
Append a single byte to the buffer.
void pm_buffer_append_varsint(pm_buffer_t *buffer, int32_t value)
Append a 32-bit signed integer to the buffer as a variable-length integer.
void pm_buffer_append_bytes(pm_buffer_t *buffer, const uint8_t *value, size_t length)
Append a list of bytes to the buffer.
void pm_buffer_append_double(pm_buffer_t *buffer, double value)
Append a double to the buffer.
static const pm_constant_pool_bucket_type_t PM_CONSTANT_POOL_BUCKET_OWNED
An owned constant is one for which memory has been allocated.
static const pm_constant_pool_bucket_type_t PM_CONSTANT_POOL_BUCKET_CONSTANT
A constant constant is known at compile time.
PRISM_EXPORTED_FUNCTION size_t pm_list_size(pm_list_t *list)
Returns the size of the list.
PRISM_EXPORTED_FUNCTION size_t pm_string_length(const pm_string_t *string)
Returns the length associated with the string.
PRISM_EXPORTED_FUNCTION const uint8_t * pm_string_source(const pm_string_t *string)
Returns the start pointer associated with the string.
#define PRISM_EXPORTED_FUNCTION
By default, we compile with -fvisibility=hidden.
PRISM_EXPORTED_FUNCTION void pm_node_destroy(pm_parser_t *parser, struct pm_node *node)
Deallocate a node and all of its children.
The main header file for the prism parser.
PRISM_EXPORTED_FUNCTION void pm_serialize_lex(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data)
Lex the given source and serialize to the given buffer.
PRISM_EXPORTED_FUNCTION void pm_parser_free(pm_parser_t *parser)
Free any memory associated with the given parser.
void pm_serialize_content(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer)
Serialize the encoding, metadata, nodes, and constant pool.
PRISM_EXPORTED_FUNCTION void pm_serialize_parse_lex(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data)
Parse and serialize both the AST and the tokens represented by the given source to the given buffer.
PRISM_EXPORTED_FUNCTION void pm_serialize(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer)
Serialize the AST represented by the given node to the given buffer.
PRISM_EXPORTED_FUNCTION pm_node_t * pm_parse(pm_parser_t *parser)
Initiate the parser with the given parser.
void pm_serialize_encoding(const pm_encoding_t *encoding, pm_buffer_t *buffer)
Serialize the name of the encoding to the buffer.
PRISM_EXPORTED_FUNCTION void pm_parser_init(pm_parser_t *parser, const uint8_t *source, size_t size, const pm_options_t *options)
Initialize a parser with the given start and end pointers.
void pm_serialize_comment_list(pm_parser_t *parser, pm_list_t *list, pm_buffer_t *buffer)
Serialize the given list of comments to the given buffer.
A pm_buffer_t is a simple memory buffer that stores data in a contiguous block of memory.
size_t length
The length of the buffer in bytes.
char * value
A pointer to the start of the buffer.
ClassVariableAndWriteNode.
ClassVariableOperatorWriteNode.
ClassVariableOrWriteNode.
ConstantOperatorWriteNode.
ConstantPathAndWriteNode.
ConstantPathOperatorWriteNode.
A bucket in the hash map.
unsigned int id
The incremental ID used for indexing back into the pool.
pm_constant_pool_bucket_type_t type
The type of the bucket, which determines how to free it.
uint32_t capacity
The number of buckets that have been allocated in the hash map.
pm_constant_pool_bucket_t * buckets
The buckets in the hash map.
uint32_t size
The number of buckets in the hash map.
pm_constant_t * constants
The constants that are stored in the buckets.
A constant in the pool which effectively stores a string.
size_t length
The length of the string.
const uint8_t * start
A pointer to the start of the string.
This struct represents a diagnostic generated during parsing.
pm_location_t location
The location of the diagnostic in the source.
const char * message
The message associated with the diagnostic.
pm_list_node_t node
The embedded base node.
pm_diagnostic_id_t diag_id
The ID of the diagnostic.
uint8_t level
The level of the diagnostic, see pm_error_level_t and pm_warning_level_t for possible values.
This struct defines the functions necessary to implement the encoding interface so we can determine h...
const char * name
The name of the encoding.
GlobalVariableAndWriteNode.
GlobalVariableOperatorWriteNode.
GlobalVariableOrWriteNode.
GlobalVariableTargetNode.
InstanceVariableAndWriteNode.
InstanceVariableOperatorWriteNode.
InstanceVariableOrWriteNode.
InstanceVariableReadNode.
InstanceVariableTargetNode.
InstanceVariableWriteNode.
A structure represents an arbitrary-sized integer.
size_t length
The number of allocated values.
uint32_t value
Embedded value for small integer.
uint32_t * values
List of 32-bit integers.
bool negative
Whether or not the integer is negative.
InterpolatedMatchLastLineNode.
InterpolatedRegularExpressionNode.
KeywordRestParameterNode.
When you are lexing through a file, the lexer needs all of the information that the parser additional...
void * data
This opaque pointer is used to provide whatever information the user deemed necessary to the callback...
struct pm_list_node * next
A pointer to the next node in the list.
This represents the overall linked list.
pm_list_node_t * head
A pointer to the head of the list.
LocalVariableAndWriteNode.
LocalVariableOperatorWriteNode.
LocalVariableOrWriteNode.
This represents a range of bytes in the source string to which a node or token corresponds.
const uint8_t * start
A pointer to the start location of the range in the source.
const uint8_t * end
A pointer to the end location of the range in the source.
A list of offsets of newlines in a string.
size_t * offsets
The list of offsets.
size_t size
The number of offsets in the list.
This is the base structure that represents a node in the syntax tree.
uint32_t node_id
The unique identifier for this node, which is deterministic based on the source.
pm_node_flags_t flags
This represents any flags on the node.
pm_location_t location
This is the location of the node in the source.
NumberedReferenceReadNode.
OptionalKeywordParameterNode.
The options that can be passed to the parser.
This struct represents the overall parser.
pm_lex_state_t lex_state
The current state of the lexer.
const pm_encoding_t * encoding
The encoding functions for the current file is attached to the parser as it's parsing so that it can ...
pm_constant_pool_t constant_pool
This constant pool keeps all of the constants defined throughout the file so that we can reference th...
pm_list_t magic_comment_list
The list of magic comments that have been found while parsing.
pm_lex_callback_t * lex_callback
This is an optional callback that can be attached to the parser that will be called whenever a new to...
pm_location_t data_loc
An optional location that represents the location of the END marker and the rest of the content of th...
const uint8_t * start
The pointer to the start of the source.
pm_list_t error_list
The list of errors that have been found while parsing.
pm_list_t warning_list
The list of warnings that have been found while parsing.
int32_t start_line
The line number at the start of the parse.
pm_list_t comment_list
The list of comments that have been found while parsing.
pm_newline_list_t newline_list
This is the list of newline offsets in the source file.
RequiredKeywordParameterNode.
A generic string type that can have various ownership semantics.
enum pm_string_t::@94 type
The type of the string.
This struct represents a token in the Ruby source.