Revert "Fix redefinition of `clock_gettime` and `clock_getres`"
[ruby.git] / prism / static_literals.h
blobbd29761899c29c1d5d6998601ee9286b9bb63e4d
1 /**
2 * @file static_literals.h
4 * A set of static literal nodes that can be checked for duplicates.
5 */
6 #ifndef PRISM_STATIC_LITERALS_H
7 #define PRISM_STATIC_LITERALS_H
9 #include "prism/defines.h"
10 #include "prism/ast.h"
11 #include "prism/util/pm_newline_list.h"
13 #include <assert.h>
14 #include <stdbool.h>
16 /**
17 * An internal hash table for a set of nodes.
19 typedef struct {
20 /** The array of nodes in the hash table. */
21 pm_node_t **nodes;
23 /** The size of the hash table. */
24 uint32_t size;
26 /** The space that has been allocated in the hash table. */
27 uint32_t capacity;
28 } pm_node_hash_t;
30 /**
31 * Certain sets of nodes (hash keys and when clauses) check for duplicate nodes
32 * to alert the user of potential issues. To do this, we keep a set of the nodes
33 * that have been seen so far, and compare whenever we find a new node.
35 * We bucket the nodes based on their type to minimize the number of comparisons
36 * that need to be performed.
38 typedef struct {
39 /**
40 * This is the set of IntegerNode and SourceLineNode instances.
42 pm_node_hash_t integer_nodes;
44 /**
45 * This is the set of FloatNode instances.
47 pm_node_hash_t float_nodes;
49 /**
50 * This is the set of RationalNode and ImaginaryNode instances.
52 pm_node_hash_t number_nodes;
54 /**
55 * This is the set of StringNode and SourceFileNode instances.
57 pm_node_hash_t string_nodes;
59 /**
60 * This is the set of RegularExpressionNode instances.
62 pm_node_hash_t regexp_nodes;
64 /**
65 * This is the set of SymbolNode instances.
67 pm_node_hash_t symbol_nodes;
69 /**
70 * A pointer to the last TrueNode instance that was inserted, or NULL.
72 pm_node_t *true_node;
74 /**
75 * A pointer to the last FalseNode instance that was inserted, or NULL.
77 pm_node_t *false_node;
79 /**
80 * A pointer to the last NilNode instance that was inserted, or NULL.
82 pm_node_t *nil_node;
84 /**
85 * A pointer to the last SourceEncodingNode instance that was inserted, or
86 * NULL.
88 pm_node_t *source_encoding_node;
89 } pm_static_literals_t;
91 /**
92 * Add a node to the set of static literals.
94 * @param newline_list The list of newline offsets to use to calculate lines.
95 * @param start_line The line number that the parser starts on.
96 * @param literals The set of static literals to add the node to.
97 * @param node The node to add to the set.
98 * @param replace Whether to replace the previous node if one already exists.
99 * @return A pointer to the node that is being overwritten, if there is one.
101 pm_node_t * pm_static_literals_add(const pm_newline_list_t *newline_list, int32_t start_line, pm_static_literals_t *literals, pm_node_t *node, bool replace);
104 * Free the internal memory associated with the given static literals set.
106 * @param literals The set of static literals to free.
108 void pm_static_literals_free(pm_static_literals_t *literals);
111 * Create a string-based representation of the given static literal.
113 * @param buffer The buffer to write the string to.
114 * @param newline_list The list of newline offsets to use to calculate lines.
115 * @param start_line The line number that the parser starts on.
116 * @param encoding_name The name of the encoding of the source being parsed.
117 * @param node The node to create a string representation of.
119 void pm_static_literal_inspect(pm_buffer_t *buffer, const pm_newline_list_t *newline_list, int32_t start_line, const char *encoding_name, const pm_node_t *node);
121 #endif