Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / ace / Svc_Conf.y
blob039cbab5e377338260542f0e2d2a81c1f6c4ef4b
1 %{
2 #include "ace/Svc_Conf.h"
4 #if (ACE_USES_CLASSIC_SVC_CONF == 1)
6 #include "ace/Module.h"
7 #include "ace/Stream.h"
8 #include "ace/Service_Types.h"
9 #include "ace/ace_wchar.h"
11 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
13 // Prototypes.
15 static ACE_Module_Type *
16 ace_get_module (ACE_Service_Type const * sr,
17 ACE_TCHAR const * svc_name,
18 int & ace_yyerrno);
20 #define YYDEBUG_LEXER_TEXT (yytext[yyleng] = '\0', yytext)
22 // Force the pretty debugging code to compile.
23 // #define YYDEBUG 1
25 // Bison 2.3 template contains switch statement with a "default:", but
26 // without a "case:" label. Suppressing a compiler warning for Visual
27 // C++.
28 #if defined (_MSC_VER)
29 # pragma warning ( disable : 4065 )
30 #endif
32 // Normalize the message literal's type to match yyerror() prototype
33 #define YY_ ACE_TEXT
35 // Prevent yacc(1) from declaring a trivial YYSTYPE just because
36 // YYSTYPE is not a macro definition. On the other hand we want
37 // YYSTYPE_IS_DECLARED to be as localized as possible to avoid
38 // poluting the global namespace - there may be other yacc(1) parsers
39 // that want to play nice with ACE
40 #define YYSTYPE_IS_DECLARED
42 ACE_END_VERSIONED_NAMESPACE_DECL
46 %token ACE_DYNAMIC ACE_STATIC ACE_SUSPEND ACE_RESUME ACE_REMOVE ACE_USTREAM
47 %token ACE_MODULE_T ACE_STREAM_T ACE_SVC_OBJ_T ACE_ACTIVE ACE_INACTIVE
48 %token ACE_PATHNAME ACE_IDENT ACE_STRING
50 %start svc_config_entries
52 %type <ident_> ACE_IDENT ACE_STRING ACE_PATHNAME pathname parameters_opt
53 %type <type_> type status
54 %type <parse_node_> dynamic static suspend resume remove module_list stream
55 %type <parse_node_> stream_modules module svc_config_entry
56 %type <static_node_> stream_ops
57 %type <svc_record_> svc_location
58 %type <location_node_> svc_initializer
60 // Generate a pure (reentrant) parser -- GNU Bison only
61 %pure_parser
65 svc_config_entries
66 : svc_config_entries svc_config_entry
68 if ($2 != 0)
70 $2->apply (ACE_SVC_CONF_PARAM->config, ACE_SVC_CONF_PARAM->yyerrno);
71 delete $2;
73 ACE_SVC_CONF_PARAM->obstack.release ();
75 | svc_config_entries error
77 ACE_SVC_CONF_PARAM->obstack.release ();
79 | /* EMPTY */
82 svc_config_entry
83 : dynamic
84 | static
85 | suspend
86 | resume
87 | remove
88 | stream
91 dynamic
92 : ACE_DYNAMIC svc_location parameters_opt
94 if ($2 != 0)
95 $$ = new ACE_Dynamic_Node ($2, $3);
96 else
97 $$ = 0;
101 static
102 : ACE_STATIC ACE_IDENT parameters_opt
104 $$ = new ACE_Static_Node ($2, $3);
108 suspend
109 : ACE_SUSPEND ACE_IDENT
111 $$ = new ACE_Suspend_Node ($2);
115 resume
116 : ACE_RESUME ACE_IDENT
118 $$ = new ACE_Resume_Node ($2);
122 remove
123 : ACE_REMOVE ACE_IDENT
125 $$ = new ACE_Remove_Node ($2);
129 stream
130 : ACE_USTREAM stream_ops stream_modules
132 $$ = new ACE_Stream_Node ($2, $3);
134 | ACE_USTREAM ACE_IDENT { $<static_node_>$ = new ACE_Static_Node ($2); } stream_modules
136 $$ = new ACE_Dummy_Node ($<static_node_>3, $4);
140 stream_ops
141 : dynamic
144 | static
149 stream_modules
150 : '{'
152 // Initialize left context...
153 $<static_node_>$ = $<static_node_>0;
155 module_list '}'
157 ACE_UNUSED_ARG ($2);
158 $$ = $3;
160 | /* EMPTY */ { $$ = 0; }
163 module_list
164 : module_list module
166 if ($2 != 0)
168 $2->link ($1);
169 $$ = $2;
172 | /* EMPTY */ { $$ = 0; }
175 module
176 : dynamic
179 | static
181 ACE_Static_Node *sn = $<static_node_>-1;
182 ACE_Module_Type *mt = ace_get_module (sn->record (ACE_SVC_CONF_PARAM->config),
183 $<static_node_>1->name (),
184 ACE_SVC_CONF_PARAM->yyerrno);
186 if (((ACE_Stream_Type *) sn->record (ACE_SVC_CONF_PARAM->config)->type ())->push (mt) == -1)
188 ACE_ERROR ((LM_ERROR,
189 ACE_TEXT ("Problem with static\n")));
190 ACE_SVC_CONF_PARAM->yyerrno++;
193 | suspend
195 ACE_Static_Node *sn = $<static_node_>-1;
196 ACE_Module_Type *mt = ace_get_module (sn->record (ACE_SVC_CONF_PARAM->config),
197 sn->name (),
198 ACE_SVC_CONF_PARAM->yyerrno);
199 if (mt != 0)
200 mt->suspend ();
202 | resume
204 ACE_Static_Node *sn = $<static_node_>-1;
205 ACE_Module_Type *mt = ace_get_module (sn->record (ACE_SVC_CONF_PARAM->config),
206 $<static_node_>1->name (),
207 ACE_SVC_CONF_PARAM->yyerrno);
208 if (mt != 0)
209 mt->resume ();
211 | remove
213 ACE_Static_Node *stream = $<static_node_>-1;
214 ACE_Static_Node *module = $<static_node_>1;
215 ACE_Module_Type *mt = ace_get_module (stream->record (ACE_SVC_CONF_PARAM->config),
216 module->name (),
217 ACE_SVC_CONF_PARAM->yyerrno);
219 ACE_Stream_Type *st =
220 dynamic_cast<ACE_Stream_Type *> (const_cast<ACE_Service_Type_Impl *> (stream->record (ACE_SVC_CONF_PARAM->config)->type ()));
221 if (!st || (mt != 0 && st->remove (mt) == -1))
223 ACE_ERROR ((LM_ERROR,
224 ACE_TEXT ("cannot remove Module_Type %s from STREAM_Type %s\n"),
225 module->name (),
226 stream->name ()));
227 ACE_SVC_CONF_PARAM->yyerrno++;
232 svc_location
233 : ACE_IDENT type svc_initializer status
235 $$ = new ACE_Service_Type_Factory ($1, $2, $3, $4);
239 status
240 : ACE_ACTIVE
242 $$ = 1;
244 | ACE_INACTIVE
246 $$ = 0;
248 | /* EMPTY */
250 $$ = 1;
254 svc_initializer
255 : pathname ':' ACE_IDENT
257 $$ = new ACE_Object_Node ($1, $3);
259 | pathname ':' ACE_IDENT '(' ')'
261 $$ = new ACE_Function_Node ($1, $3);
263 | ':' ACE_IDENT '(' ')'
265 $$ = new ACE_Static_Function_Node ($2);
269 type
270 : ACE_MODULE_T '*'
272 $$ = ACE_MODULE_T;
274 | ACE_SVC_OBJ_T '*'
276 $$ = ACE_SVC_OBJ_T;
278 | ACE_STREAM_T '*'
280 $$ = ACE_STREAM_T;
284 parameters_opt
285 : ACE_STRING
286 | /* EMPTY */ { $$ = 0; }
289 pathname
290 : ACE_PATHNAME
291 | ACE_IDENT
292 | ACE_STRING
297 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
299 // Prints the error string to standard output. Cleans up the error
300 // messages.
302 void
303 yyerror (int yyerrno, int yylineno, ACE_TCHAR const * s)
305 #if defined (ACE_NLOGGING)
306 ACE_UNUSED_ARG (yyerrno);
307 ACE_UNUSED_ARG (yylineno);
308 ACE_UNUSED_ARG (s);
309 #endif /* ACE_NLOGGING */
311 ACE_ERROR ((LM_ERROR,
312 ACE_TEXT ("ACE (%P|%t) [error %d] on line %d: %C\n"),
313 yyerrno,
314 yylineno,
315 s));
318 void
319 yyerror (ACE_TCHAR const * s)
321 yyerror (-1, -1, s);
324 // Note that SRC_REC represents left context, which is the STREAM *
325 // record.
327 static ACE_Module_Type *
328 ace_get_module (ACE_Service_Type const * sr,
329 ACE_TCHAR const * svc_name,
330 int & yyerrno)
332 ACE_Stream_Type const * const st =
333 (sr == 0
335 : dynamic_cast<ACE_Stream_Type const *> (sr->type ()));
336 ACE_Module_Type const * const mt = (st == 0 ? 0 : st->find (svc_name));
338 if (sr == 0 || st == 0 || mt == 0)
340 ACE_ERROR ((LM_ERROR,
341 ACE_TEXT ("cannot locate Module_Type %s ")
342 ACE_TEXT ("in STREAM_Type %s\n"),
343 svc_name,
344 (sr ? sr->name () : ACE_TEXT ("(nil)"))));
345 ++yyerrno;
348 return const_cast<ACE_Module_Type *> (mt);
351 #if defined (SVC_CONF_Y_DEBUGGING)
352 // Main driver program.
355 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
357 ACE_Svc_Conf_Param param (0, stdin);
359 // Try to reopen any filename argument to use YYIN.
360 if (argc > 1 && (yyin = freopen (argv[1], "r", stdin)) == 0)
361 (void) ACE_OS::fprintf (stderr, ACE_TEXT ("usage: %s [file]\n"), argv[0]), ACE_OS::exit (1);
363 return ::yyparse (&param);
365 #endif /* SVC_CONF_Y_DEBUGGING */
367 ACE_END_VERSIONED_NAMESPACE_DECL
369 #endif /* ACE_USES_CLASSIC_SVC_CONF == 1 */