Added spec:commit task to commit changes to spec/ruby sources.
[rbx.git] / shotgun / lib / grammar_node.h
blob87a136461a09199b732df9de8f07d1f800df58c4
1 /**********************************************************************
3 node.h -
5 $Author: nobu $
6 $Date: 2004/10/02 11:34:29 $
7 created at: Fri May 28 15:14:02 JST 1993
9 Copyright (C) 1993-2003 Yukihiro Matsumoto
11 **********************************************************************/
13 #ifndef RBS_GRAMMAR_NODE_H
14 #define RBS_GRAMMAR_NODE_H
16 #if defined(__cplusplus)
17 extern "C" {
18 #endif
20 #include "bstrlib.h"
21 #include "shotgun/lib/node_types.h"
23 typedef struct RNode {
24 unsigned long flags;
25 char *nd_file;
26 union {
27 struct RNode *node;
28 ID id;
29 OBJECT value;
30 ID *tbl;
31 bstring string;
32 } u1;
33 union {
34 struct RNode *node;
35 ID id;
36 long argc;
37 OBJECT value;
38 } u2;
39 union {
40 struct RNode *node;
41 ID id;
42 long state;
43 long cnt;
44 OBJECT value;
45 bstring string;
46 } u3;
47 } NODE;
49 #define RNODE(obj) ((NODE*)(obj))
51 #define FL_USHIFT 11
52 #define FL_UMASK (0xff<<FL_USHIFT)
54 #define nd_type(n) ((int)(((RNODE(n))->flags>>FL_USHIFT)&0xff))
55 #define nd_set_type(n,t) \
56 RNODE(n)->flags=((RNODE(n)->flags&~FL_UMASK)|(((t)<<FL_USHIFT)&FL_UMASK))
58 #define NODE_LSHIFT (FL_USHIFT+8)
59 #define NODE_LMASK (((long)1<<(sizeof(NODE*)*CHAR_BIT-NODE_LSHIFT))-1)
60 #define nd_line(n) ((unsigned int)(((RNODE(n))->flags>>NODE_LSHIFT)&NODE_LMASK))
61 #define nd_set_line(n,l) \
62 RNODE(n)->flags=((RNODE(n)->flags&~(-1<<NODE_LSHIFT))|(((l)&NODE_LMASK)<<NODE_LSHIFT))
64 #define nd_head u1.node
65 #define nd_alen u2.argc
66 #define nd_next u3.node
68 #define nd_cond u1.node
69 #define nd_body u2.node
70 #define nd_else u3.node
72 #define nd_orig u3.string
74 #define nd_resq u2.node
75 #define nd_ensr u3.node
77 #define nd_1st u1.node
78 #define nd_2nd u2.node
80 #define nd_stts u1.node
82 #define nd_entry u3.entry
83 #define nd_vid u1.id
84 #define nd_cflag u2.id
85 #define nd_cval u3.value
87 #define nd_cnt u3.cnt
88 #define nd_tbl u1.tbl
90 #define nd_var u1.node
91 #define nd_ibdy u2.node
92 #define nd_iter u3.node
94 #define nd_value u2.node
95 #define nd_aid u3.id
97 #define nd_str u1.string
98 #define nd_lit u1.value
100 #define nd_frml u1.node
101 #define nd_rest u2.argc
102 #define nd_opt u1.node
104 #define nd_recv u1.node
105 #define nd_mid u2.id
106 #define nd_args u3.node
108 #define nd_noex u1.id
109 #define nd_defn u3.node
111 #define nd_old u1.id
112 #define nd_new u2.id
114 #define nd_cfnc u1.cfunc
115 #define nd_argc u2.argc
117 #define nd_cpath u1.node
118 #define nd_super u3.node
120 #define nd_modl u1.id
121 #define nd_clss u1.value
123 #define nd_beg u1.node
124 #define nd_end u2.node
125 #define nd_state u3.state
126 #define nd_rval u2.value
128 #define nd_nth u2.argc
130 #define nd_tag u1.id
131 #define nd_tval u2.value
133 #define NEW_NODE(t,a0,a1,a2) syd_node_newnode(parse_state, (t),(OBJECT)(a0),(OBJECT)(a1),(OBJECT)(a2))
135 #define NEW_METHOD(n,x) NEW_NODE(NODE_METHOD,x,n,0)
136 #define NEW_FBODY(n,i,o) NEW_NODE(NODE_FBODY,n,i,o)
137 #define NEW_DEFN(i,a,d,p) NEW_NODE(NODE_DEFN,p,i,NEW_RFUNC(a,d))
138 #define NEW_DEFS(r,i,a,d) NEW_NODE(NODE_DEFS,r,i,NEW_RFUNC(a,d))
139 #define NEW_CFUNC(f,c) NEW_NODE(NODE_CFUNC,f,c,0)
140 #define NEW_IFUNC(f,c) NEW_NODE(NODE_IFUNC,f,c,0)
141 #define NEW_RFUNC(b1,b2) NEW_SCOPE(block_append(vps, b1,b2))
142 #define NEW_SCOPE(b) NEW_NODE(NODE_SCOPE,syd_local_tbl(vps),0,(b))
143 #define NEW_BLOCK(a) NEW_NODE(NODE_BLOCK,a,0,0)
144 #define NEW_IF(c,t,e) NEW_NODE(NODE_IF,c,t,e)
145 #define NEW_UNLESS(c,t,e) NEW_IF(c,e,t)
146 #define NEW_CASE(h,b) NEW_NODE(NODE_CASE,h,b,0)
147 #define NEW_WHEN(c,t,e) NEW_NODE(NODE_WHEN,c,t,e)
148 #define NEW_OPT_N(b) NEW_NODE(NODE_OPT_N,0,b,0)
149 #define NEW_WHILE(c,b,n) NEW_NODE(NODE_WHILE,c,b,n)
150 #define NEW_UNTIL(c,b,n) NEW_NODE(NODE_UNTIL,c,b,n)
151 #define NEW_FOR(v,i,b) NEW_NODE(NODE_FOR,v,b,i)
152 #define NEW_ITER(v,i,b) NEW_NODE(NODE_ITER,v,b,i)
153 #define NEW_BREAK(s) NEW_NODE(NODE_BREAK,s,0,0)
154 #define NEW_NEXT(s) NEW_NODE(NODE_NEXT,s,0,0)
155 #define NEW_REDO() NEW_NODE(NODE_REDO,0,0,0)
156 #define NEW_RETRY() NEW_NODE(NODE_RETRY,0,0,0)
157 #define NEW_BEGIN(b) NEW_NODE(NODE_BEGIN,0,b,0)
158 #define NEW_RESCUE(b,res,e) NEW_NODE(NODE_RESCUE,b,res,e)
159 #define NEW_RESBODY(a,ex,n) NEW_NODE(NODE_RESBODY,n,ex,a)
160 #define NEW_ENSURE(b,en) NEW_NODE(NODE_ENSURE,b,0,en)
161 #define NEW_RETURN(s) NEW_NODE(NODE_RETURN,s,0,0)
162 #define NEW_YIELD(a,s) NEW_NODE(NODE_YIELD,a,0,s)
163 #define NEW_LIST(a) NEW_ARRAY(a)
164 #define NEW_ARRAY(a) NEW_NODE(NODE_ARRAY,a,1,0)
165 #define NEW_ZARRAY() NEW_NODE(NODE_ZARRAY,0,0,0)
166 #define NEW_HASH(a) NEW_NODE(NODE_HASH,a,0,0)
167 #define NEW_POSITIONAL(a) NEW_NODE(NODE_HASH,a,1,0)
168 #define NEW_NOT(a) NEW_NODE(NODE_NOT,0,a,0)
169 #define NEW_MASGN(l,r) NEW_NODE(NODE_MASGN,l,0,r)
170 #define NEW_GASGN(v,val) NEW_NODE(NODE_GASGN,v,val,0)
171 #define NEW_LASGN(v,val) NEW_NODE(NODE_LASGN,v,val,local_cnt(v))
172 #define NEW_DASGN(v,val) NEW_NODE(NODE_DASGN,v,val,0)
173 #define NEW_DASGN_CURR(v,val) NEW_NODE(NODE_DASGN_CURR,v,val,0)
174 #define NEW_IASGN(v,val) NEW_NODE(NODE_IASGN,v,val,0)
175 #define NEW_CDECL(v,val,path) NEW_NODE(NODE_CDECL,v,val,path)
176 #define NEW_CVASGN(v,val) NEW_NODE(NODE_CVASGN,v,val,0)
177 #define NEW_CVDECL(v,val) NEW_NODE(NODE_CVDECL,v,val,0)
178 #define NEW_OP_ASGN1(p,id,a) NEW_NODE(NODE_OP_ASGN1,p,id,a)
179 #define NEW_OP_ASGN2(r,i,o,val) NEW_NODE(NODE_OP_ASGN2,r,val,NEW_OP_ASGN22(i,o))
180 #define NEW_OP_ASGN22(i,o) NEW_NODE(NODE_OP_ASGN2,i,o,rb_id_attrset(i))
181 #define NEW_OP_ASGN_OR(i,val) NEW_NODE(NODE_OP_ASGN_OR,i,val,0)
182 #define NEW_OP_ASGN_AND(i,val) NEW_NODE(NODE_OP_ASGN_AND,i,val,0)
183 #define NEW_GVAR(v) NEW_NODE(NODE_GVAR,v,0,0)
184 #define NEW_LVAR(v) NEW_NODE(NODE_LVAR,v,0,local_cnt(v))
185 #define NEW_DVAR(v) NEW_NODE(NODE_DVAR,v,0,0)
186 #define NEW_IVAR(v) NEW_NODE(NODE_IVAR,v,0,0)
187 #define NEW_CONST(v) NEW_NODE(NODE_CONST,v,0,0)
188 #define NEW_CVAR(v) NEW_NODE(NODE_CVAR,v,0,0)
189 #define NEW_NTH_REF(n) NEW_NODE(NODE_NTH_REF,0,n,local_cnt('~'))
190 #define NEW_BACK_REF(n) NEW_NODE(NODE_BACK_REF,0,n,local_cnt('~'))
191 #define NEW_MATCH(c) NEW_NODE(NODE_MATCH,c,0,0)
192 #define NEW_MATCH2(n1,n2) NEW_NODE(NODE_MATCH2,n1,n2,0)
193 #define NEW_MATCH3(r,n2) NEW_NODE(NODE_MATCH3,r,n2,0)
194 #define NEW_LIT(l) NEW_NODE(NODE_LIT,l,0,0)
195 #define NEW_STR(s) NEW_NODE(NODE_STR,s,0,0)
196 #define NEW_DSTR(s) NEW_NODE(NODE_DSTR,s,1,0)
197 #define NEW_XSTR(s) NEW_NODE(NODE_XSTR,s,0,0)
198 #define NEW_DXSTR(s) NEW_NODE(NODE_DXSTR,s,0,0)
199 #define NEW_DSYM(s) NEW_NODE(NODE_DSYM,s,0,0)
200 #define NEW_EVSTR(n) NEW_NODE(NODE_EVSTR,0,(n),0)
201 #define NEW_CALL(r,m,a) NEW_NODE(NODE_CALL,r,m,a)
202 #define NEW_FCALL(m,a) NEW_NODE(NODE_FCALL,0,m,a)
203 #define NEW_VCALL(m) NEW_NODE(NODE_VCALL,0,m,0)
204 #define NEW_SUPER(a) NEW_NODE(NODE_SUPER,0,0,a)
205 #define NEW_ZSUPER() NEW_NODE(NODE_ZSUPER,0,0,0)
206 #define NEW_ARGS(f,o,r) NEW_NODE(NODE_ARGS,o,r,f)
207 #define NEW_ARGSCAT(a,b) NEW_NODE(NODE_ARGSCAT,a,b,0)
208 #define NEW_ARGSPUSH(a,b) NEW_NODE(NODE_ARGSPUSH,a,b,0)
209 #define NEW_SPLAT(a) NEW_NODE(NODE_SPLAT,a,0,0)
210 #define NEW_TO_ARY(a) NEW_NODE(NODE_TO_ARY,a,0,0)
211 #define NEW_SVALUE(a) NEW_NODE(NODE_SVALUE,a,0,0)
212 #define NEW_BLOCK_ARG(v) NEW_NODE(NODE_BLOCK_ARG,v,0,local_cnt(v))
213 #define NEW_BLOCK_PASS(b) NEW_NODE(NODE_BLOCK_PASS,0,b,0)
214 #define NEW_ALIAS(n,o) NEW_NODE(NODE_ALIAS,o,n,0)
215 #define NEW_VALIAS(n,o) NEW_NODE(NODE_VALIAS,o,n,0)
216 #define NEW_UNDEF(i) NEW_NODE(NODE_UNDEF,0,i,0)
217 #define NEW_CLASS(n,b,s) NEW_NODE(NODE_CLASS,n,NEW_SCOPE(b),(s))
218 #define NEW_SCLASS(r,b) NEW_NODE(NODE_SCLASS,r,NEW_SCOPE(b),0)
219 #define NEW_MODULE(n,b) NEW_NODE(NODE_MODULE,n,NEW_SCOPE(b),0)
220 #define NEW_COLON2(c,i) NEW_NODE(NODE_COLON2,c,i,0)
221 #define NEW_COLON3(i) NEW_NODE(NODE_COLON3,0,i,0)
222 #define NEW_CREF(c) (NEW_NODE(NODE_CREF,0,0,c))
223 #define NEW_DOT2(b,e) NEW_NODE(NODE_DOT2,b,e,0)
224 #define NEW_DOT3(b,e) NEW_NODE(NODE_DOT3,b,e,0)
225 #define NEW_ATTRSET(a) NEW_NODE(NODE_ATTRSET,a,0,0)
226 #define NEW_SELF() NEW_NODE(NODE_SELF,0,0,0)
227 #define NEW_NIL() NEW_NODE(NODE_NIL,0,0,0)
228 #define NEW_TRUE() NEW_NODE(NODE_TRUE,0,0,0)
229 #define NEW_FALSE() NEW_NODE(NODE_FALSE,0,0,0)
230 #define NEW_DEFINED(e) NEW_NODE(NODE_DEFINED,e,0,0)
231 #define NEW_NEWLINE(n) NEW_NODE(NODE_NEWLINE,0,0,n)
232 #define NEW_PREEXE(b) NEW_SCOPE(b)
233 #define NEW_POSTEXE() NEW_NODE(NODE_POSTEXE,0,0,0)
234 #define NEW_DMETHOD(b) NEW_NODE(NODE_DMETHOD,0,0,b)
235 #define NEW_BMETHOD(b) NEW_NODE(NODE_BMETHOD,0,0,b)
236 #define NEW_ATTRASGN(r,m,a) NEW_NODE(NODE_ATTRASGN,r,m,a)
238 #define NEW_FIXNUM(l) NEW_NODE(NODE_FIXNUM,0,0,l)
239 #define NEW_NUMBER(l) NEW_NODE(NODE_NUMBER,l,0,0)
240 #define NEW_HEXNUM(l) NEW_NODE(NODE_HEXNUM,l,0,0)
241 #define NEW_OCTNUM(l) NEW_NODE(NODE_OCTNUM,l,0,0)
242 #define NEW_BINNUM(l) NEW_NODE(NODE_BINNUM,l,0,0)
243 #define NEW_FLOAT(l) NEW_NODE(NODE_FLOAT,l,0,0)
244 #define NEW_NEGATE(l) NEW_NODE(NODE_NEGATE,l,0,0)
245 #define NEW_REGEX(l,o) NEW_NODE(NODE_REGEX,l,0,o)
246 #define NEW_FILE() NEW_NODE(NODE_FILE,0,0,0)
247 #define NOEX_PUBLIC 0
248 #define NOEX_NOSUPER 1
249 #define NOEX_PRIVATE 2
250 #define NOEX_PROTECTED 4
251 #define NOEX_MASK 6
253 #define NOEX_UNDEF NOEX_NOSUPER
255 #if defined(__cplusplus)
256 } /* extern "C" { */
257 #endif
259 #endif