forked from ianh/owl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstruct-actions.h
61 lines (54 loc) · 1.95 KB
/
construct-actions.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef CONSTRUCT_ACTIONS_H
#define CONSTRUCT_ACTIONS_H
// These are the parse tree construction actions in order. See 3-combine.c and
// x-construct-parse-tree.h for how these are used.
// We use #defines here instead of an enum so the values can be substituted into
// the generated parser.
#define ACTION_NONE 0
#define ACTION_BEGIN_SLOT 1
#define ACTION_BEGIN_EXPRESSION_SLOT 2
#define ACTION_SET_SLOT_CHOICE 3
#define ACTION_TOKEN_SLOT 4
#define ACTION_BEGIN_OPERAND 5
#define ACTION_BEGIN_OPERATOR 6
#define ACTION_END_SLOT 8
#define ACTION_END_EXPRESSION_SLOT 9
#define ACTION_END_OPERAND 10
#define ACTION_END_OPERATOR 11
#define CONSTRUCT_ACTION(type, slot_or_choice) \
(((type) << 12) | ((slot_or_choice) & 0xfff))
// No action has both a slot and a choice, so we can use the same bits for both.
#define CONSTRUCT_ACTION_GET_TYPE(action) (((action) >> 12) & 0xf)
#define CONSTRUCT_ACTION_GET_SLOT(action) ((action) & 0xfff)
#define CONSTRUCT_ACTION_GET_CHOICE(action) ((action) & 0xfff)
#define CONSTRUCT_IS_END_ACTION(action) (CONSTRUCT_ACTION_GET_TYPE(action) & 8)
static inline const char *action_name(unsigned action)
{
switch (CONSTRUCT_ACTION_GET_TYPE(action)) {
case ACTION_NONE:
return "ACTION_NONE";
case ACTION_END_SLOT:
return "ACTION_END_SLOT";
case ACTION_END_EXPRESSION_SLOT:
return "ACTION_END_EXPRESSION_SLOT";
case ACTION_BEGIN_SLOT:
return "ACTION_BEGIN_SLOT";
case ACTION_BEGIN_EXPRESSION_SLOT:
return "ACTION_BEGIN_EXPRESSION_SLOT";
case ACTION_SET_SLOT_CHOICE:
return "ACTION_SET_SLOT_CHOICE";
case ACTION_TOKEN_SLOT:
return "ACTION_TOKEN_SLOT";
case ACTION_END_OPERAND:
return "ACTION_END_OPERAND";
case ACTION_END_OPERATOR:
return "ACTION_END_OPERATOR";
case ACTION_BEGIN_OPERAND:
return "ACTION_BEGIN_OPERAND";
case ACTION_BEGIN_OPERATOR:
return "ACTION_BEGIN_OPERATOR";
default:
return "?";
}
}
#endif