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
  
62
  
63
  
64
  
65
  
66
  
67
  
68
  
69
  
70
  
71
  
72
  
73
  
74
  
75
  
76
  
77
  
78
  
79
  
80
  
81
  
82
  
83
  
84
  
85
  
86
  
87
  
88
  
89
  
90
  
91
  
92
  
93
  
94
  
95
  
96
  
97
  
98
  
99
  
100
  
101
  
102
  
103
  
104
  
105
  
106
  
107
  
108
  
109
  
110
  
111
  
112
  
113
  
114
  
115
  
116
  
117
  
118
  
119
  
120
  
121
  
122
  
123
  
124
  
125
  
126
  
127
  
128
  
129
  
130
  
131
  
132
  
133
  
134
  
135
  
136
  
137
  
138
  
139
  
140
  
141
  
142
  
143
  
144
  
145
  
146
  
147
  
148
  
149
  
150
  
151
  
152
  
153
  
154
  
155
  
156
  
157
  
158
  
159
  
160
  
161
  
162
  
163
  
164
  
165
  
166
  
167
  
168
  
169
  
170
  
171
  
172
  
173
  
174
  
175
  
176
  
177
  
178
  
179
  
180
  
181
  
182
  
183
  
184
  
185
  
186
  
187
  
188
  
189
  
190
  
191
  
192
  
193
  
194
  
195
  
196
  
197
  
198
  
199
  
200
  
201
  
202
  
203
  
204
  
205
  
206
  
207
  
208
  
209
  
210
  
211
  
212
  
213
  
214
  
215
  
216
  
217
  
218
  
219
  
220
  
221
  
222
  
#include "global.h" 
#include "stralloc.h" 
#include "global.h" 
RCSID("$Id: parser.c,v 1.3 1999/06/12 13:42:42 mirar Exp $"); 
#include "pike_macros.h" 
#include "interpret.h" 
#include "program.h" 
#include "object.h" 
#include "operators.h" 
 
#include "parser.h" 
 
#define PARSER_INITER 
 
/*#define DEBUG*/ 
 
#define PARSER_CLASS(name,init,exit,prog) \ 
    void init(void); void exit(void); struct program *prog; 
#define PARSER_SUBMODULE(name,init,exit)  \ 
    void init(void); void exit(void);  
#define PARSER_SUBMODMAG(name,init,exit) \ 
    void init(void); void exit(void); 
#define PARSER_FUNCTION(name,func,def0,def1) \ 
    void func(INT32 args); 
#include "initstuff.h" 
 
static struct  
{ 
   char *name; 
   void (*init)(void); 
   void (*exit)(void); 
   struct program **dest; 
} initclass[]= 
{ 
#undef PARSER_CLASS 
#undef PARSER_SUBMODULE 
#undef PARSER_FUNCTION 
#undef PARSER_SUBMODMAG 
#define PARSER_SUBMODMAG(a,b,c)  
#define PARSER_FUNCTION(a,b,c,d) 
#define PARSER_CLASS(name,init,exit,prog) { name,init,exit,&prog }, 
#define PARSER_SUBMODULE(a,b,c) 
#include "initstuff.h" 
}; 
 
static struct  
{ 
   char *name; 
   void (*init)(void); 
   void (*exit)(void); 
} initsubmodule[]= 
{ 
#undef PARSER_CLASS 
#undef PARSER_SUBMODULE 
#define PARSER_CLASS(name,init,exit,prog)  
#define PARSER_SUBMODULE(name,init,exit) { name,init,exit }, 
#include "initstuff.h" 
}; 
 
static struct  
{ 
   char *name; 
   void (*init)(void); 
   void (*exit)(void); 
   struct pike_string *ps; 
   struct object *o; 
} submagic[]= 
{ 
#undef PARSER_SUBMODULE 
#undef PARSER_SUBMODMAG 
#define PARSER_SUBMODULE(a,b,c) 
#define PARSER_SUBMODMAG(name,init,exit) { name,init,exit,NULL,NULL }, 
#include "initstuff.h" 
}; 
 
#ifdef PIKE_DEBUG 
#define PARSER_CHECK_STACK(X)       do { if (save_sp != sp) { fatal("%s:%d: %d droppings on stack! previous init: %s\n", __FILE__, __LINE__, sp - save_sp,X); } } while(0) 
#else 
#define PARSER_CHECK_STACK(X) 
#endif /* PIKE_DEBUG */ 
 
 
static void parser_magic_index(INT32 args) 
{ 
   struct svalue tmp; 
   int i; 
 
   if (args!=1)  
      error("Parser.`[]: Too few or too many arguments\n"); 
   if (sp[-1].type!=T_STRING) 
      error("Parser.`[]: Illegal type of argument\n"); 
 
   for (i=0; i<(int)NELEM(submagic); i++) 
      if (sp[-1].u.string==submagic[i].ps) 
      { 
#ifdef PIKE_DEBUG 
   struct svalue *save_sp; 
#endif 
       pop_stack(); 
 
#ifdef PIKE_DEBUG 
       save_sp = sp; 
#endif 
 
         if (!submagic[i].o) 
         { 
            struct program *p; 
            start_new_program(); 
            (submagic[i].init)(); 
            PARSER_CHECK_STACK(submagic[i].name); 
            p=end_program(); 
            submagic[i].o=clone_object(p,0); 
            free_program(p); 
         } 
          
         ref_push_object(submagic[i].o); 
         return; 
      } 
 
   stack_dup(); 
   ref_push_object(fp->current_object); 
   stack_swap(); 
   f_arrow(2); 
 
   if (sp[-1].type==T_INT) 
   { 
      pop_stack(); 
      stack_dup(); 
      push_text("_Parser_"); 
      stack_swap(); 
      f_add(2); 
      push_int(0); 
      SAFE_APPLY_MASTER("resolv",2); 
   } 
   if (sp[-1].type==T_INT) 
   { 
      pop_stack(); 
      stack_dup(); 
      push_text("_Parser"); 
      push_int(0); 
      SAFE_APPLY_MASTER("resolv",2); 
      stack_swap(); 
      f_index(2); 
   } 
   stack_swap(); 
   pop_stack(); 
} 
 
void pike_module_init(void) 
{ 
#ifdef PIKE_DEBUG 
   struct svalue *save_sp = sp; 
#endif 
 
   int i; 
   for (i=0; i<(int)NELEM(initclass); i++) 
   { 
      start_new_program(); 
 
#ifdef DEBUG 
      fprintf(stderr,"Parser: initiating class \"Parser.%s\"...\n", 
              initclass[i].name); 
#endif 
 
      (initclass[i].init)(); 
      PARSER_CHECK_STACK(initclass[i].name); 
      initclass[i].dest[0]=end_program(); 
      add_program_constant(initclass[i].name,initclass[i].dest[0],0); 
   } 
 
   for (i=0; i<(int)NELEM(initsubmodule); i++) 
   { 
      struct program *p; 
      struct pike_string *s; 
 
#ifdef DEBUG 
      fprintf(stderr,"Parser: initiating submodule \"Parser.%s\"...\n", 
              initsubmodule[i].name); 
#endif 
       
      start_new_program(); 
      (initsubmodule[i].init)(); 
      PARSER_CHECK_STACK(initsubmodule[i].name); 
      p=end_program(); 
      push_object(clone_object(p,0)); 
      s=make_shared_string(initsubmodule[i].name); 
      add_constant(s,sp-1,0); 
      free_string(s); 
      free_program(p); 
      pop_stack(); 
   } 
 
   for (i=0; i<(int)NELEM(submagic); i++) 
      submagic[i].ps=make_shared_string(submagic[i].name); 
 
#undef PARSER_FUNCTION 
#define PARSER_FUNCTION(name,func,def0,def1) ADD_FUNCTION(name,func,def0,def1); 
#include "initstuff.h" 
 
   ADD_FUNCTION("`[]",parser_magic_index, 
                tFunc(tString,tMixed),0); 
} 
 
void pike_module_exit(void)  
{ 
   int i; 
   for (i=0; i<(int)NELEM(initclass); i++) 
   { 
      (initclass[i].exit)(); 
      free_program(initclass[i].dest[0]); 
   } 
   for (i=0; i<(int)NELEM(initsubmodule); i++) 
      (initsubmodule[i].exit)(); 
   for (i=0; i<(int)NELEM(submagic); i++) 
      if (submagic[i].o) 
      { 
         (submagic[i].exit)(); 
         free_object(submagic[i].o); 
      } 
}