Skip to content

Commit 3b7c4e6

Browse files
committed
🎨 subtree.h
1 parent 8df0b8d commit 3b7c4e6

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

lib/src/subtree.h

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,65 +40,74 @@ typedef struct {
4040
//
4141
// This representation is used for small leaf nodes that are not
4242
// errors, and were not created by an external scanner.
43+
//
4344
// The idea behind the layout of this struct is that the `is_inline`
4445
// bit will fall exactly into the same location as the least significant
4546
// bit of the pointer in `Subtree` or `MutableSubtree`, respectively.
4647
// Because of alignment, for any valid pointer this will be 0, giving
4748
// us the opportunity to make use of this bit to signify whether to use
4849
// the pointer or the inline struct.
49-
typedef struct {
50-
#define SUBTREE_3_BYTES \
51-
uint8_t symbol; \
52-
uint16_t parse_state;
50+
typedef struct SubtreeInlineData SubtreeInlineData;
5351

54-
#define SUBTREE_BITS \
55-
bool visible : 1; \
56-
bool named : 1; \
57-
bool extra : 1; \
52+
#define SUBTREE_BITS \
53+
bool visible : 1; \
54+
bool named : 1; \
55+
bool extra : 1; \
5856
bool has_changes : 1; \
59-
bool is_missing : 1; \
57+
bool is_missing : 1; \
6058
bool is_keyword : 1;
6159

62-
#define SUBTREE_SIZE \
63-
uint8_t padding_columns; \
64-
uint8_t padding_rows : 4; \
60+
#define SUBTREE_SIZE \
61+
uint8_t padding_columns; \
62+
uint8_t padding_rows : 4; \
6563
uint8_t lookahead_bytes : 4; \
66-
uint8_t padding_bytes; \
64+
uint8_t padding_bytes; \
6765
uint8_t size_bytes;
6866

6967
#if TS_BIG_ENDIAN
7068
#if TS_PTR_SIZE == 32
69+
70+
struct SubtreeInlineData {
7171
uint16_t parse_state;
7272
uint8_t symbol;
7373
SUBTREE_BITS
7474
bool unused : 1;
7575
bool is_inline : 1;
7676
SUBTREE_SIZE
77+
};
78+
7779
#else
80+
81+
struct SubtreeInlineData {
7882
SUBTREE_SIZE
7983
uint16_t parse_state;
8084
uint8_t symbol;
8185
SUBTREE_BITS
8286
bool unused : 1;
8387
bool is_inline : 1;
88+
};
89+
8490
#endif
8591
#else
92+
93+
struct SubtreeInlineData {
8694
bool is_inline : 1;
8795
SUBTREE_BITS
8896
uint8_t symbol;
8997
uint16_t parse_state;
9098
SUBTREE_SIZE
99+
};
100+
91101
#endif
92102

93103
#undef SUBTREE_BITS
94104
#undef SUBTREE_SIZE
95-
} SubtreeInlineData;
96105

97106
// A heap-allocated representation of a subtree.
98107
//
99108
// This representation is used for parent nodes, external tokens,
100109
// errors, and other leaf nodes whose data is too large to fit into
101-
// the inlinen representation.
110+
// the inline representation.
102111
typedef struct {
103112
volatile uint32_t ref_count;
104113
Length padding;

0 commit comments

Comments
 (0)