2 * @file static_literals.h
4 * A set of static literal nodes that can be checked for duplicates.
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"
17 * An internal hash table for a set of nodes.
20 /** The array of nodes in the hash table. */
23 /** The size of the hash table. */
26 /** The space that has been allocated in the hash table. */
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.
40 * This is the set of IntegerNode and SourceLineNode instances.
42 pm_node_hash_t integer_nodes
;
45 * This is the set of FloatNode instances.
47 pm_node_hash_t float_nodes
;
50 * This is the set of RationalNode and ImaginaryNode instances.
52 pm_node_hash_t number_nodes
;
55 * This is the set of StringNode and SourceFileNode instances.
57 pm_node_hash_t string_nodes
;
60 * This is the set of RegularExpressionNode instances.
62 pm_node_hash_t regexp_nodes
;
65 * This is the set of SymbolNode instances.
67 pm_node_hash_t symbol_nodes
;
70 * A pointer to the last TrueNode instance that was inserted, or NULL.
75 * A pointer to the last FalseNode instance that was inserted, or NULL.
77 pm_node_t
*false_node
;
80 * A pointer to the last NilNode instance that was inserted, or NULL.
85 * A pointer to the last SourceEncodingNode instance that was inserted, or
88 pm_node_t
*source_encoding_node
;
89 } pm_static_literals_t
;
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
);