c339efc3f46ab87208e3c2acc79f3153eb45e3ba
[tpot/pegasus/.git] / src / Pegasus / Compiler / cimmof.y
1 //%2005////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
7 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
9 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining a copy
13 // of this software and associated documentation files (the "Software"), to
14 // deal in the Software without restriction, including without limitation the
15 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
16 // sell copies of the Software, and to permit persons to whom the Software is
17 // furnished to do so, subject to the following conditions:
18 // 
19 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
20 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
21 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
22 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
23 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
25 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28 //==============================================================================
29 %{
30   /* Flex grammar created from CIM Specification Version 2.2 Appendix A */
31
32   /*
33      Note the following implementation details:
34
35        1. The MOF specification has a production of type assocDeclaration,
36        but an association is just a type of classDeclaration with a few
37        special rules.  At least for the first pass, I'm treating an
38        associationDeclaration as a classDeclaration and applying its
39        syntactical rules outside of the grammar definition.
40
41        2. Same with the indicationDeclaration.  It appears to be a normal
42        classDeclaration with the INDICATION qualifier and no special
43        syntactical rules.
44
45        3. The Parser uses String objects throughout to represent
46        character data.  However, the tokenizer underneath is probably
47        working with 8-bit chars.  If we later use an extended character
48        compatible tokenizer, I anticipate NO CHANGE to this parser.
49
50        4. Besides the tokenizer, this parser uses 2 sets of outside
51        services:
52           1)Class valueFactory.  This has a couple of static methods
53           that assist in creating CIMValue objects from Strings.
54           2)Class cimmofParser.  This has a wide variety of methods
55           that fall into these catagories:
56             a) Interfaces to the Repository.  You call cimmofParser::
57             methods to query and store compiled CIM elements.
58             b) Error handling.
59             c) Data format conversions.
60             d) Tokenizer manipulation
61             e) Pragma handling
62             f) Alias Handling
63   */
64
65
66 #define YYSTACKSIZE 2000
67
68 #include <cstdlib>
69 #if !defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) && !defined(__OS400__) && !defined(PEGASUS_OS_VMS)
70 #if defined(PEGASUS_PLATFORM_DARWIN_PPC_GNU)
71 #include <sys/malloc.h>
72 #else
73 #include <malloc.h>
74 #endif
75 #endif
76 #include <cstdio>
77 #include <cstring>
78 #include <Pegasus/Common/String.h>
79 #include <Pegasus/Common/CIMName.h>
80 #include "cimmofParser.h"
81 #include "valueFactory.h"
82 #include "memobjs.h"
83 #include "qualifierList.h"
84 #include "objname.h"
85
86 //include any useful debugging stuff here
87
88 /* Debugging the parser.  Debugging is provided through
89    1. debug functions in Bison that are controlled by a compile time
90       flag (YYDEBUG) and a runtime flag (yydebug) which is redefined
91       to cimmof_debug.
92    2. Debug functions defined through YACCTRACE, a macro defined
93       in cimmofparser.h and turned on and off manually.
94    All debugging must be turned on manually at this point by
95    setting the YYDEBUG compile flag and also setting YACCTRACE.
96    ATTN: TODO: automate the debug information flags.
97 */
98 // Enable this define to compie Bison/Yacc tracing
99 // ATTN: p3 03092003 ks Enabling this flag currently causes a compile error
100
101 #define YYDEBUG 1
102 //static int cimmof_debug;
103
104 //extern cimmofParser g_cimmofParser;
105
106 extern int   cimmof_lex(void);
107 extern int   cimmof_error(...);
108 extern char *cimmof_text;
109 extern void  cimmof_yy_less(int n);
110 extern int   cimmof_leng;
111
112
113 /* ------------------------------------------------------------------- */
114 /* These globals provide continuity between various pieces of a        */
115 /* declaration.  They are usually interpreted as "these modifiers were */
116 /* encountered and need to be applied to the finished object".  For    */
117 /* example, qualifiers are accumulated in g_qualifierList[] as they    */
118 /* encountered, then applied to the production they qualify when it    */
119 /* is completed.                                                       */
120 /* ------------------------------------------------------------------- */
121   CIMFlavor g_flavor = CIMFlavor (CIMFlavor::NONE);
122   CIMScope g_scope = CIMScope ();
123   //ATTN: BB 2001 BB P1 - Fixed size qualifier list max 20. Make larger or var
124   qualifierList g_qualifierList(20);
125   CIMMethod *g_currentMethod = 0;
126   CIMClass *g_currentClass = 0;
127   CIMInstance *g_currentInstance = 0;
128   String g_currentAliasRef; // Alias reference
129   String g_currentAliasDecl; // Alias declaration
130   CIMName g_referenceClassName = CIMName();
131   Array<CIMKeyBinding> g_KeyBindingArray; // it gets created empty
132   TYPED_INITIALIZER_VALUE g_typedInitializerValue; 
133
134 /* ------------------------------------------------------------------- */
135 /* Pragmas, except for the Include pragma, are not handled yet    */
136 /* I don't understand them, so it may be a while before they are       */ 
137 /* ------------------------------------------------------------------- */
138   struct pragma {
139     String name;
140     String value;
141   };
142
143 /* ---------------------------------------------------------------- */
144 /* Use our general wrap manager to handle end-of-file               */
145 /* ---------------------------------------------------------------- */
146 extern "C" {
147 int
148 cimmof_wrap() {
149   return cimmofParser::Instance()->wrapCurrentBuffer();
150 }
151 }
152
153 /* ---------------------------------------------------------------- */
154 /* Pass errors to our general log manager.                          */
155 /* ---------------------------------------------------------------- */
156 void
157 cimmof_error(const char *msg) {
158   cimmofParser::Instance()->log_parse_error(cimmof_text, msg);
159   // printf("Error: %s\n", msg);
160 }
161
162 static void MOF_error(const char * str, const char * S);
163 static void MOF_trace(const char* str);
164 static void MOF_trace2(const char * str, const char * S);
165
166 %}
167
168 %union {
169   //char                     *strval;
170   CIMClass                 *mofclass;
171   CIMFlavor                *flavor;
172   CIMInstance              *instance;
173   CIMKeyBinding            *keybinding;
174   CIMMethod                *method;
175   CIMName                  *cimnameval;
176   CIMObjectPath            *reference;
177   CIMProperty              *property;
178   CIMQualifier             *qualifier;
179   CIMQualifierDecl         *mofqualifier;
180   CIMScope                 *scope;
181   CIMType                   datatype;
182   CIMValue                 *value;
183   int                       ival;
184   modelPath                *modelpath;
185   String                   *strptr;
186   String                   *strval;
187   struct pragma            *pragma;
188   TYPED_INITIALIZER_VALUE  *typedinitializer;
189 }
190
191
192
193 %token TOK_ALIAS_IDENTIFIER
194 %token TOK_ANY
195 %token TOK_AS
196 %token TOK_ASSOCIATION
197 %token TOK_BINARY_VALUE
198 %token TOK_CHAR_VALUE
199 %token TOK_CLASS
200 %token TOK_COLON
201 %token TOK_COMMA
202 %token TOK_DISABLEOVERRIDE
203 %token TOK_DQUOTE
204 %token TOK_DT_BOOL
205 %token TOK_DT_CHAR16
206 %token TOK_DT_CHAR8
207 %token TOK_DT_DATETIME
208 %token TOK_DT_REAL32
209 %token TOK_DT_REAL64
210 %token TOK_DT_SINT16
211 %token TOK_DT_SINT32
212 %token TOK_DT_SINT64
213 %token TOK_DT_SINT8
214 %token TOK_DT_STR
215 %token TOK_DT_UINT16
216 %token TOK_DT_UINT32
217 %token TOK_DT_UINT64
218 %token TOK_DT_UINT8
219 %token TOK_ENABLEOVERRIDE
220 %token TOK_END_OF_FILE
221 %token TOK_EQUAL
222 %token TOK_FALSE
223 %token TOK_FLAVOR
224 %token TOK_HEX_VALUE
225 %token TOK_INCLUDE
226 %token TOK_INDICATION
227 %token TOK_INSTANCE
228 %token TOK_LEFTCURLYBRACE
229 %token TOK_LEFTPAREN
230 %token TOK_LEFTSQUAREBRACKET
231 %token TOK_METHOD
232 %token TOK_NULL_VALUE
233 %token TOK_OCTAL_VALUE
234 %token TOK_OF
235 %token TOK_PARAMETER
236 %token TOK_PERIOD
237 %token TOK_POSITIVE_DECIMAL_VALUE
238 %token TOK_PRAGMA
239 %token TOK_PROPERTY
240 %token TOK_QUALIFIER
241 %token TOK_REAL_VALUE
242 %token TOK_REF
243 %token TOK_REFERENCE
244 %token TOK_RESTRICTED
245 %token TOK_RIGHTCURLYBRACE
246 %token TOK_RIGHTPAREN
247 %token TOK_RIGHTSQUAREBRACKET
248 %token TOK_SCHEMA
249 %token TOK_SCOPE
250 %token TOK_SEMICOLON
251 %token TOK_SIGNED_DECIMAL_VALUE
252 %token TOK_SIMPLE_IDENTIFIER
253 %token TOK_STRING_VALUE
254 %token TOK_TOSUBCLASS
255 %token TOK_TRANSLATABLE
256 %token TOK_TRUE
257 %token TOK_UNEXPECTED_CHAR
258
259
260 %type <cimnameval>       propertyName parameterName methodName className
261 %type <cimnameval>       superClass
262 %type <datatype>         dataType intDataType realDataType parameterType objectRef
263 %type <flavor>           flavor defaultFlavor 
264 %type <instance>         instanceHead instanceDeclaration 
265 %type <ival>             array
266 %type <ival>             booleanValue keyValuePairList
267 %type <keybinding>       keyValuePair
268 %type <method>           methodHead methodDeclaration
269 %type <modelpath>        modelPath
270 %type <mofclass>         classHead classDeclaration
271 %type <mofqualifier>     qualifierDeclaration
272 %type <pragma>           compilerDirectivePragma
273 %type <property>         propertyBody propertyDeclaration referenceDeclaration
274 %type <qualifier>        qualifier
275 %type <scope>            scope metaElements metaElement
276 %type <strval>           arrayInitializer constantValues 
277 %type <strval>           fileName referencedObject referenceName referencePath 
278 %type <strval>           integerValue TOK_REAL_VALUE TOK_CHAR_VALUE 
279 %type <strval>           namespaceHandle namespaceHandleRef
280 %type <strval>           nonNullConstantValue
281 %type <strval>           pragmaName pragmaVal keyValuePairName qualifierName
282 %type <strval>           referenceInitializer objectHandle
283 %type <strval>           aliasInitializer
284 %type <strval>           aliasIdentifier
285 %type <strval>           stringValue stringValues initializer constantValue
286 %type <strval>           TOK_ALIAS_IDENTIFIER  alias 
287 %type <strval>           TOK_POSITIVE_DECIMAL_VALUE TOK_OCTAL_VALUE TOK_HEX_VALUE 
288 %type <strval>           TOK_SIGNED_DECIMAL_VALUE TOK_BINARY_VALUE
289 %type <strval>           TOK_SIMPLE_IDENTIFIER TOK_STRING_VALUE
290 %type <strval>           TOK_UNEXPECTED_CHAR
291 %type <typedinitializer> typedInitializer typedDefaultValue 
292 %type <typedinitializer> typedQualifierParameter
293 %type <value>            qualifierValue
294
295
296
297
298
299 %%
300
301
302
303
304 /*
305 **------------------------------------------------------------------------------
306 **
307 **   Production rules section
308 **
309 **------------------------------------------------------------------------------
310 */
311 mofSpec: mofProductions ;
312
313
314 mofProductions: mofProduction mofProductions
315               | /* empty */ ;
316
317
318 // ATTN: P1 KS Apr 2002 Limit in (none) Directive handling. See FIXME below.
319 mofProduction: compilerDirective { /* FIXME: Where do we put directives? */ }
320              | qualifierDeclaration 
321                  { cimmofParser::Instance()->addQualifier($1); delete $1; }
322              | classDeclaration 
323                  { cimmofParser::Instance()->addClass($1); }
324              | instanceDeclaration 
325                  { cimmofParser::Instance()->addInstance($1); } ;
326
327
328
329
330 /*
331 **------------------------------------------------------------------------------
332 **
333 **   class Declaration productions and processing
334 **
335 **------------------------------------------------------------------------------
336 */
337 classDeclaration: classHead  classBody
338 {
339     YACCTRACE("classDeclaration");
340     if (g_currentAliasDecl != String::EMPTY)
341     cimmofParser::Instance()->addClassAlias(g_currentAliasDecl, $$, false);
342 } ;
343
344
345 classHead: qualifierList TOK_CLASS className alias superClass
346 {
347     // create new instance of class with className and superclassName
348     // put returned class object on stack
349     YACCTRACE("classHead:");
350     $$ = cimmofParser::Instance()->newClassDecl(*$3, *$5);
351     
352     // put list of qualifiers into class
353     applyQualifierList(&g_qualifierList, $$);
354     
355     g_currentAliasRef = *$4;
356     if (g_currentClass)
357         delete g_currentClass;
358     g_currentClass = $$;
359     delete $3;
360     delete $4;
361     delete $5;
362 } ;
363
364
365 className: TOK_SIMPLE_IDENTIFIER {} ;
366
367
368 superClass: TOK_COLON className { $$ = new CIMName(*$2); }
369           | /* empty */ { $$ = new CIMName(); } ;
370
371
372 classBody: TOK_LEFTCURLYBRACE classFeatures TOK_RIGHTCURLYBRACE TOK_SEMICOLON
373          | TOK_LEFTCURLYBRACE TOK_RIGHTCURLYBRACE TOK_SEMICOLON ;
374
375
376 classFeatures: classFeature
377              | classFeatures classFeature ;
378
379
380 classFeature: propertyDeclaration  {
381   YACCTRACE("classFeature:applyProperty");
382   cimmofParser::Instance()->applyProperty(*g_currentClass, *$1); delete $1; } 
383             | methodDeclaration {
384   YACCTRACE("classFeature:applyMethod");
385   cimmofParser::Instance()->applyMethod(*g_currentClass, *$1); }
386             | referenceDeclaration {
387   YACCTRACE("classFeature:applyProperty");
388   cimmofParser::Instance()->applyProperty(*g_currentClass, *$1); delete $1; }; 
389
390
391
392
393
394
395 /*
396 **------------------------------------------------------------------------------
397 **
398 ** method Declaration productions and processing.
399 **
400 **------------------------------------------------------------------------------
401 */
402
403 methodDeclaration: qualifierList methodHead methodBody methodEnd 
404 {
405   YACCTRACE("methodDeclaration");
406   $$ = $2;
407 } ;
408
409
410
411 // methodHead processes the datatype and methodName and puts qualifierList.
412 // BUG 366. qualifier list was originally placed on in methoddeclaration
413 // which meant it might be overwritten by parameter qualifier lists.
414 methodHead: dataType methodName 
415 {
416     YACCTRACE("methodHead");
417     if (g_currentMethod)
418     delete g_currentMethod;
419
420   // create new method instance with pointer to method name and datatype
421   g_currentMethod = cimmofParser::Instance()->newMethod(*$2, $1) ;
422   
423   // put new method on stack
424   $$ = g_currentMethod;
425
426   // apply the method qualifier list.
427   applyQualifierList(&g_qualifierList, $$);
428
429   delete $2;
430 } ;
431
432
433 methodBody: TOK_LEFTPAREN parameters TOK_RIGHTPAREN ;
434
435
436 methodEnd: TOK_SEMICOLON ;
437
438
439 methodName: TOK_SIMPLE_IDENTIFIER { $$ = new CIMName(*$1); } ;
440
441
442 //
443 //  Productions for method parameters
444 //
445 parameters : parameter
446            | parameters TOK_COMMA parameter
447            | /* empty */ ;
448
449
450 parameter: qualifierList parameterType parameterName array 
451
452   // ATTN: P2 2002 Question Need to create default value including type?
453   
454   YACCTRACE("parameter:");
455   CIMParameter *p = 0;
456   cimmofParser *cp = cimmofParser::Instance();
457
458   // Create new parameter with name, type, isArray, array, referenceClassName
459   if ($4 == -1) {
460     p = cp->newParameter(*$3, $2, false, 0, g_referenceClassName);
461   } else {
462     p = cp->newParameter(*$3, $2, true, $4, g_referenceClassName);
463   }
464
465   g_referenceClassName = CIMName();
466
467   YACCTRACE("parameter:applyQualifierList");
468   applyQualifierList(&g_qualifierList, p);
469
470   cp->applyParameter(*g_currentMethod, *p);
471   delete p;
472   delete $3;
473 } ;
474
475
476 parameterType: dataType { $$ = $1; }
477              | objectRef { $$ = CIMTYPE_REFERENCE; } ;
478
479
480
481
482
483
484 /*
485 **------------------------------------------------------------------------------
486 **
487 **   property Declaration productions and processing
488 **
489 **------------------------------------------------------------------------------
490 */
491
492 propertyDeclaration: qualifierList propertyBody propertyEnd 
493 {
494     // set body to stack and apply qualifier list
495     // ATTN: the apply qualifer only works here because
496     // there are not lower level qualifiers.  We do productions
497     // that might have lower level qualifiers differently by
498     // setting up a xxxHead production where qualifiers are 
499     // applied.
500     YACCTRACE("propertyDeclaration:");
501     $$ = $2;
502     applyQualifierList(&g_qualifierList, $$);
503 } ;
504
505
506 propertyBody: dataType propertyName array typedDefaultValue
507 {
508   CIMValue *v = valueFactory::createValue($1, $3, 
509                       ($4->type == CIMMOF_NULL_VALUE), $4->value);
510   if ($3 == -1) {
511     $$ = cimmofParser::Instance()->newProperty(*$2, *v, false, 0);
512 } else {                                           
513     $$ = cimmofParser::Instance()->newProperty(*$2, *v, true, $3);
514   }
515
516   delete $2;
517   delete $4->value;
518   delete v;
519 } ;
520
521
522 propertyEnd: TOK_SEMICOLON ;
523
524
525
526
527
528
529 /*
530 **------------------------------------------------------------------------------
531 **
532 **    reference Declaration productions and processing
533 **
534 **------------------------------------------------------------------------------
535 */
536
537 referenceDeclaration: qualifierList referencedObject TOK_REF referenceName
538                       referencePath TOK_SEMICOLON 
539 {
540   String s(*$2);
541   if (!String::equal(*$5, String::EMPTY))
542     s.append("." + *$5);
543   CIMValue *v = valueFactory::createValue(CIMTYPE_REFERENCE, -1, true, &s);
544   //KS add the isArray and arraysize parameters. 8 mar 2002
545   $$ = cimmofParser::Instance()->newProperty(*$4, *v, false,0, *$2);
546   applyQualifierList(&g_qualifierList, $$);
547   delete $2;
548   delete $4;
549   delete $5; 
550   delete v;
551 } ;
552
553
554 referencedObject: TOK_SIMPLE_IDENTIFIER { $$ = $1; } ;
555
556
557 referenceName: TOK_SIMPLE_IDENTIFIER { $$ = $1; };
558
559
560 referencePath: TOK_EQUAL stringValue { $$ = $2; }
561                | /* empty */ { $$ = new String(String::EMPTY); } ;
562
563
564 objectRef: className TOK_REF {  
565                           g_referenceClassName = *$1; } ;
566
567
568 parameterName: TOK_SIMPLE_IDENTIFIER { $$ = new CIMName(*$1); } ;
569
570
571 propertyName: TOK_SIMPLE_IDENTIFIER { $$ = new CIMName(*$1); } ;
572
573
574 array: TOK_LEFTSQUAREBRACKET TOK_POSITIVE_DECIMAL_VALUE  
575          TOK_RIGHTSQUAREBRACKET
576                  { $$ = valueFactory::Stoi(*$2);
577                    delete $2;
578                  }
579      | TOK_LEFTSQUAREBRACKET TOK_RIGHTSQUAREBRACKET { $$ = 0; } 
580      | /* empty */ { $$ = -1; } ;
581
582
583 typedDefaultValue: TOK_EQUAL typedInitializer { $$ = $2; }  
584             | {   /* empty */
585                   g_typedInitializerValue.type = CIMMOF_NULL_VALUE;
586                   g_typedInitializerValue.value = new String(String::EMPTY); 
587                   $$ = &g_typedInitializerValue;
588               };
589
590
591 initializer: constantValue { $$ = $1; }
592            | arrayInitializer { $$ = $1; }
593            | referenceInitializer { $$ = $1; } ;
594
595
596 // The typedInitializer element is syntactially identical to 
597 // the initializer element. However, the typedInitializer element 
598 // returns, in addition to the value, the type of the value.
599 typedInitializer: nonNullConstantValue 
600            { 
601            g_typedInitializerValue.type = CIMMOF_CONSTANT_VALUE;
602            g_typedInitializerValue.value =  $1; 
603            $$ = &g_typedInitializerValue;
604            }
605          | TOK_NULL_VALUE
606            {
607            g_typedInitializerValue.type = CIMMOF_NULL_VALUE;
608            g_typedInitializerValue.value = new String(String::EMPTY); 
609            $$ = &g_typedInitializerValue;
610            }
611          | arrayInitializer
612            { 
613            g_typedInitializerValue.type = CIMMOF_ARRAY_VALUE;
614            g_typedInitializerValue.value =  $1; 
615            $$ = &g_typedInitializerValue;
616            }
617          | referenceInitializer
618            { 
619            g_typedInitializerValue.type = CIMMOF_REFERENCE_VALUE;
620            g_typedInitializerValue.value =  $1; 
621            $$ = &g_typedInitializerValue;
622            };
623
624
625 // BUG 497 - Commmas embedded in strings in arrays change the
626 // strings.  Aded function stringWComma to escape commas.
627 constantValues: constantValue { 
628             *$$ = valueFactory::stringWComma(String(*$1)); }
629          | constantValues TOK_COMMA constantValue 
630               {
631                 YACCTRACE("constantValues:1, Value= " << *$3);
632                 (*$$).append(","); 
633                 //(*$$).append(*$3);
634                 (*$$).append(valueFactory::stringWComma(String(*$3)));
635                 delete $3;
636               } ;
637
638
639 // The nonNullConstantValue has been added to allow NULL 
640 // to be distinguished from the EMPTY STRING.
641
642 constantValue: nonNullConstantValue {$$ = $1;}
643              | TOK_NULL_VALUE { $$ = new String(String::EMPTY); } ;
644
645
646 nonNullConstantValue: integerValue { $$ = $1; }
647              | TOK_REAL_VALUE { $$ = $1; }
648              | TOK_CHAR_VALUE { $$ =  $1; }
649              | stringValues { }
650              | booleanValue { $$ = new String($1 ? "T" : "F"); };
651
652
653 integerValue: TOK_POSITIVE_DECIMAL_VALUE
654             | TOK_SIGNED_DECIMAL_VALUE
655             | TOK_OCTAL_VALUE {
656                    $$ = new String(cimmofParser::Instance()->oct_to_dec(*$1));
657                    delete $1; }
658             | TOK_HEX_VALUE {
659                    $$ = new String(cimmofParser::Instance()->hex_to_dec(*$1));
660                    delete $1; }
661             | TOK_BINARY_VALUE {
662                  $$ = new String(cimmofParser::Instance()->binary_to_dec(*$1));
663                    delete $1; };
664
665
666 booleanValue: TOK_FALSE { $$ = 0; }
667             | TOK_TRUE  { $$ = 1; } ;
668
669
670 stringValues: stringValue { $$ = $1; }
671             | stringValues stringValue 
672               { 
673                 (*$$).append(*$2);  delete $2;
674               } ;
675
676
677 stringValue: TOK_STRING_VALUE 
678
679    //String oldrep = *$1;
680    //String s(oldrep), s1(String::EMPTY);
681    // Handle quoted quote
682    //int len = s.size();
683    //if (s[len] == '\n') {
684        //error: new line inside a string constant unless it is quoted
685        //if (s[len - 2] == '\\') {
686            //if (len > 3)
687                 //s1 = s.subString(1, len-3);
688        //} else {
689            //cimmof_error("New line in string constant");
690            //}
691        //cimmofParser::Instance()->increment_lineno();
692    //} else { // Can only be a quotation mark
693        //if (s[len - 2] == '\\') {  // if it is quoted
694            //if (len > 3) s1 = s.subString(1, len-3);
695            //s1.append('\"');
696            //cimmof_yy_less(len-1);
697        //} else { // This is the normal case:  real quotes on both end
698            //s1 = s.subString(1, len - 2) ;
699            //}
700        //}
701    //delete $1;
702    $$ = //new String(s1);
703         new String(*$1);
704    delete $1;
705 } ;
706
707
708 arrayInitializer: 
709        TOK_LEFTCURLYBRACE constantValues TOK_RIGHTCURLYBRACE 
710            { $$ = $2; } 
711      | TOK_LEFTCURLYBRACE  TOK_RIGHTCURLYBRACE 
712            { $$ = new String(String::EMPTY); };
713
714
715 referenceInitializer: objectHandle {}
716                   | aliasInitializer {  } ;
717
718
719 objectHandle: TOK_DQUOTE namespaceHandleRef modelPath TOK_DQUOTE
720
721   // The objectName string is decomposed for syntactical purposes 
722   // and reassembled here for later parsing in creation of an objname instance 
723   String *s = new String(*$2);
724   if (!String::equal(*s, String::EMPTY) && $3)
725     (*s).append(":");
726   if ($3) {
727     (*s).append($3->Stringrep());
728   }
729   $$ = s;
730   delete $2;
731   delete $3;
732   MOF_trace2 ("objectHandle done $$ = ", $$->getCString());
733 } ;
734
735
736 aliasInitializer : aliasIdentifier {
737   
738   CIMObjectPath AOP;
739
740   MOF_trace2("aliasInitializer $$ = ", $$->getCString());
741   MOF_trace2("aliasInitializer $1 = ", $1->getCString());
742
743   g_currentAliasRef = *$$;
744
745   MOF_trace2("aliasInitializer g_currentAliasRef = ", g_currentAliasRef.getCString());
746   if (cimmofParser::Instance()->getInstanceAlias(g_currentAliasRef, AOP) == 0)
747     {
748       yyerror("aliasInitializer - 'aliasIdentifier' NOT FOUND");
749       YYABORT;
750     }
751
752   String *s = new String(AOP.toString());
753
754   $$ = s;
755   
756   delete $1;
757
758   MOF_trace2 ("aliasInitializer done $$ = ", $$->getCString());
759   
760 };
761
762
763 namespaceHandleRef: namespaceHandle TOK_COLON
764                     { }
765                   | /* empty */ { $$ = new String(String::EMPTY); };
766
767
768 namespaceHandle: stringValue {};
769
770
771 modelPath: className TOK_PERIOD keyValuePairList {
772              modelPath *m = new modelPath((*$1).getString(), g_KeyBindingArray);
773              g_KeyBindingArray.clear(); 
774              delete $1;} ;
775
776
777 keyValuePairList: keyValuePair { $$ = 0; }
778                 | keyValuePairList TOK_COMMA keyValuePair { $$ = 0; } ;
779
780
781 keyValuePair: keyValuePairName TOK_EQUAL initializer 
782               {
783                 CIMKeyBinding *kb = new CIMKeyBinding(*$1, *$3,
784                                modelPath::KeyBindingTypeOf(*$3));
785                 g_KeyBindingArray.append(*kb);
786                 delete kb;
787                 delete $1;
788                 delete $3; } ;
789
790
791 keyValuePairName: TOK_SIMPLE_IDENTIFIER ;
792
793
794 alias: TOK_AS aliasIdentifier {
795               $$ = $2;
796               g_currentAliasDecl = *$2;
797               MOF_trace2("aliasIdentifier $$ = ", $$->getCString());
798               MOF_trace2("aliasIdentifier g_currentAliasDecl = ", g_currentAliasDecl.getCString());
799
800               } 
801               | /* empty */ { 
802               $$ = new String(String::EMPTY);
803               g_currentAliasDecl = String::EMPTY}
804               ;
805
806
807 aliasIdentifier: TOK_ALIAS_IDENTIFIER ;
808
809
810 /*
811 **------------------------------------------------------------------------------
812 **
813 **   Instance Declaration productions and processing
814 **
815 **-----------------------------------------------------------------------------
816 */
817
818 instanceDeclaration: instanceHead instanceBody
819
820   $$ = g_currentInstance; 
821   if (g_currentAliasDecl != String::EMPTY)
822     {
823       MOF_trace2("instanceDeclaration g_currentAliasDecl = ", g_currentAliasDecl.getCString());
824       // MOF_trace2 ("instanceDeclaration instance = ", ((CIMObject *)$$)->toString().getCString());
825       if (cimmofParser::Instance()->addInstanceAlias(g_currentAliasDecl, $$, true) == 0)
826         {
827           // Error alias already exist
828           MOF_error("ERROR: alias ALREADY EXISTS: aliasIdentifier = ",
829                     g_currentAliasDecl.getCString());
830           yyerror("instanceDeclaration - 'aliasIdentifier' ALREADY EXISTS");
831           YYABORT;
832         }
833     }
834 };
835
836
837
838 instanceHead: qualifierList TOK_INSTANCE TOK_OF className alias 
839 {
840   if (g_currentInstance)
841     delete g_currentInstance;
842   g_currentAliasDecl = *$5;
843   g_currentInstance = cimmofParser::Instance()->newInstance(*$4);
844   // apply the qualifierlist to the current instance
845   $$ = g_currentInstance;
846   applyQualifierList(&g_qualifierList, $$);
847   delete $4;
848   delete $5;
849   if (g_currentAliasDecl != String::EMPTY)
850     MOF_trace2("instanceHead g_currentAliasDecl = ", g_currentAliasDecl.getCString());
851 } ;
852
853
854
855 instanceBody: TOK_LEFTCURLYBRACE valueInitializers TOK_RIGHTCURLYBRACE
856               TOK_SEMICOLON ;
857
858
859
860 valueInitializers: valueInitializer
861                  | valueInitializers valueInitializer ;
862
863
864
865 // ATTN-DE-P1-20020427: Processing NULL Initializer values is incomplete.
866 // Currently only the arrayInitializer element has been modified to 
867 // return CIMMOF_NULL_VALUE
868 valueInitializer: qualifierList TOK_SIMPLE_IDENTIFIER TOK_EQUAL
869                   typedInitializer TOK_SEMICOLON 
870 {
871   cimmofParser *cp = cimmofParser::Instance();
872   // ATTN: P1 InstanceUpdate function 2001 BB  Instance update needs work here and CIMOM 
873   // a property.  It must be fixed in the Common code first.
874   // What we have to do here is create a CIMProperty  and initialize it with
875   // the value provided.  The name of the property is $2 and it belongs
876   // to the class whose name is in g_currentInstance->getClassName().
877   // The steps are
878   //   2. Get  property declaration's value object
879   CIMProperty *oldprop = cp->PropertyFromInstance(*g_currentInstance,
880                                                         *$2);
881   CIMValue *oldv = cp->ValueFromProperty(*oldprop);
882
883   //   3. create the new Value object of the same type
884
885   // We want createValue to interpret a value as an array if is enclosed 
886   // in {}s (e.g., { 2 } or {2, 3, 5}) or it is NULL and the property is 
887   // defined as an array. createValue is responsible for the actual
888   // validation.
889
890   CIMValue *v = valueFactory::createValue(oldv->getType(),
891                  (($4->type == CIMMOF_ARRAY_VALUE) |
892                   (($4->type == CIMMOF_NULL_VALUE) & oldprop->isArray()))?0:-1,
893                  ($4->type == CIMMOF_NULL_VALUE),
894                  $4->value);
895
896
897   //   4. create a clone property with the new value
898   CIMProperty *newprop = cp->copyPropertyWithNewValue(*oldprop, *v);
899
900   //   5. apply the qualifiers; 
901   applyQualifierList(&g_qualifierList, newprop);
902
903   //   6. and apply the CIMProperty to g_currentInstance.
904   cp->applyProperty(*g_currentInstance, *newprop);
905   delete $2;
906   delete $4->value;
907   delete oldprop;
908   delete oldv;
909   delete v;
910   delete newprop;
911 };
912
913
914
915
916
917 /*
918 **------------------------------------------------------------------------------
919 **
920 ** Compiler directive productions and processing
921 **
922 **------------------------------------------------------------------------------
923 */
924
925 compilerDirective: compilerDirectiveInclude
926 {
927     //printf("compilerDirectiveInclude "); 
928 }
929                  | compilerDirectivePragma
930 {
931     //printf("compilerDirectivePragma ");
932 } ;
933
934
935 compilerDirectiveInclude: TOK_PRAGMA TOK_INCLUDE TOK_LEFTPAREN fileName
936                           TOK_RIGHTPAREN 
937 {
938   cimmofParser::Instance()->enterInlineInclude(*$4); delete $4;
939 };
940
941
942 fileName: stringValue { $$ = $1; } ;
943
944
945 compilerDirectivePragma: TOK_PRAGMA pragmaName
946                    TOK_LEFTPAREN pragmaVal TOK_RIGHTPAREN 
947                    { cimmofParser::Instance()->processPragma(*$2, *$4); 
948                    delete $2;
949                    delete $4;
950                    };
951
952
953
954
955 /*
956 **------------------------------------------------------------------------------
957 **
958 **  qualifier Declaration productions and processing
959 **
960 **------------------------------------------------------------------------------
961 */
962
963 qualifierDeclaration: TOK_QUALIFIER qualifierName qualifierValue scope
964                        defaultFlavor TOK_SEMICOLON 
965 {
966 //    CIMQualifierDecl *qd = new CIMQualifierDecl($2, $3, $4, $5);
967         $$ = cimmofParser::Instance()->newQualifierDecl(*$2, $3, *$4, *$5);
968         delete $2;
969         delete $3;  // CIMValue object created in qualifierValue production
970 } ;
971
972
973 qualifierValue: TOK_COLON dataType array typedDefaultValue
974 {
975     $$ = valueFactory::createValue($2, $3, 
976                 $4->type == CIMMOF_NULL_VALUE, $4->value);
977     delete $4->value;
978 } ;
979
980
981 scope: scope_begin metaElements TOK_RIGHTPAREN { $$ = $2; } ;
982
983
984 scope_begin: TOK_COMMA TOK_SCOPE TOK_LEFTPAREN { 
985     g_scope = CIMScope (CIMScope::NONE); } ;
986
987
988 metaElements: metaElement { $$ = $1; }
989             | metaElements TOK_COMMA metaElement
990                           { $$->addScope(*$3); } ;
991 // ATTN:  2001 P3 defer There is not CIMScope::SCHEMA. Spec Limit KS
992
993
994 metaElement: TOK_CLASS       { $$ = new CIMScope(CIMScope::CLASS);        }
995 //           | TOK_SCHEMA      { $$ = new CIMScope(CIMScope::SCHEMA);       }
996            | TOK_SCHEMA        { $$ = new CIMScope(CIMScope::CLASS); }
997            | TOK_ASSOCIATION { $$ = new CIMScope(CIMScope::ASSOCIATION);  }
998            | TOK_INDICATION  { $$ = new CIMScope(CIMScope::INDICATION);   }
999 //           | TOK_QUALIFIER   { $$ = new CIMScope(CIMScope::QUALIFIER); }
1000            | TOK_PROPERTY    { $$ = new CIMScope(CIMScope::PROPERTY);     }
1001            | TOK_REFERENCE   { $$ = new CIMScope(CIMScope::REFERENCE);    }
1002            | TOK_METHOD      { $$ = new CIMScope(CIMScope::METHOD);       }
1003            | TOK_PARAMETER   { $$ = new CIMScope(CIMScope::PARAMETER);    }
1004            | TOK_ANY         { $$ = new CIMScope(CIMScope::ANY);          } ;
1005
1006
1007 // Correction KS 4 march 2002 - Set the default if empty
1008 defaultFlavor: TOK_COMMA flavorHead explicitFlavors TOK_RIGHTPAREN
1009   { $$ = &g_flavor; }
1010            | /* empty */ { $$ = new CIMFlavor (CIMFlavor::NONE); } ;
1011
1012
1013 // Correction KS 4 March 2002 - set the defaults (was zero)
1014 // Set the flavors for the defaults required: via DEFAULTS
1015
1016 flavorHead: TOK_FLAVOR TOK_LEFTPAREN {g_flavor = CIMFlavor (CIMFlavor::NONE);};
1017
1018
1019 explicitFlavors: explicitFlavor
1020                | explicitFlavors TOK_COMMA explicitFlavor ;
1021
1022
1023 // ATTN:KS-26/03/02 P2 This accumulates the flavor definitions.  However, it allows multiple instances
1024 // of any keyword.  Note also that each entity simply sets a bit so that you may
1025 // set disable and enable and we will not know which overrides the other.
1026 // We need to create the function to insure that you cannot enable then disable or
1027 // accept the latter and override the former.
1028
1029 // The compiler simply provides the flavors defined in the MOF and does not make any
1030 // assumptions about defaults, etc.  That is a problem for resolution of the flavors.
1031
1032 explicitFlavor: TOK_ENABLEOVERRIDE  
1033                     { g_flavor.addFlavor (CIMFlavor::ENABLEOVERRIDE); }
1034   | TOK_DISABLEOVERRIDE { g_flavor.addFlavor (CIMFlavor::DISABLEOVERRIDE); }
1035   | TOK_RESTRICTED      { g_flavor.addFlavor (CIMFlavor::RESTRICTED); }
1036   | TOK_TOSUBCLASS      { g_flavor.addFlavor (CIMFlavor::TOSUBELEMENTS); }
1037   | TOK_TRANSLATABLE    { g_flavor.addFlavor (CIMFlavor::TRANSLATABLE); };
1038
1039
1040 flavor: overrideFlavors { $$ = &g_flavor; }
1041       | /* empty */ { $$ = new CIMFlavor (CIMFlavor::NONE); };
1042
1043
1044 overrideFlavors: explicitFlavor
1045                | overrideFlavors explicitFlavor ;
1046
1047
1048
1049 dataType: intDataType     { $$ = $1; }
1050         | realDataType    { $$ = $1; }
1051         | TOK_DT_STR      { $$ = CIMTYPE_STRING;   }
1052         | TOK_DT_BOOL     { $$ = CIMTYPE_BOOLEAN;  }
1053         | TOK_DT_DATETIME { $$ = CIMTYPE_DATETIME; } ;
1054
1055
1056 intDataType: TOK_DT_UINT8  { $$ = CIMTYPE_UINT8;  }
1057            | TOK_DT_SINT8  { $$ = CIMTYPE_SINT8;  }
1058            | TOK_DT_UINT16 { $$ = CIMTYPE_UINT16; }
1059            | TOK_DT_SINT16 { $$ = CIMTYPE_SINT16; }
1060            | TOK_DT_UINT32 { $$ = CIMTYPE_UINT32; }
1061            | TOK_DT_SINT32 { $$ = CIMTYPE_SINT32; }
1062            | TOK_DT_UINT64 { $$ = CIMTYPE_UINT64; }
1063            | TOK_DT_SINT64 { $$ = CIMTYPE_SINT64; }
1064            | TOK_DT_CHAR16 { $$ = CIMTYPE_CHAR16; } ;
1065
1066
1067 realDataType: TOK_DT_REAL32 { $$ =CIMTYPE_REAL32; }
1068             | TOK_DT_REAL64 { $$ =CIMTYPE_REAL64; };
1069
1070
1071
1072
1073 /*
1074 **------------------------------------------------------------------------------
1075 **
1076 **   Qualifier list and qualifier processing
1077 **
1078 **------------------------------------------------------------------------------
1079 */
1080 qualifierList: qualifierListBegin qualifiers TOK_RIGHTSQUAREBRACKET 
1081              | /* empty */ { 
1082                  //yydebug = 1; stderr = stdout;
1083                  };
1084
1085
1086
1087 qualifierListBegin: TOK_LEFTSQUAREBRACKET { 
1088
1089     //yydebug = 1; stderr = stdout;
1090     YACCTRACE("qualifierListbegin");
1091     g_qualifierList.init(); } ;
1092
1093
1094
1095 qualifiers: qualifier { }
1096           | qualifiers TOK_COMMA qualifier { } ;
1097
1098
1099
1100 qualifier: qualifierName typedQualifierParameter flavor
1101 {
1102   cimmofParser *p = cimmofParser::Instance();
1103   // The qualifier value can't be set until we know the contents of the
1104   // QualifierDeclaration.  That's what QualifierValue() does.
1105   CIMValue *v = p->QualifierValue(*$1, 
1106                   ($2->type == CIMMOF_NULL_VALUE), *$2->value); 
1107   $$ = p->newQualifier(*$1, *v, g_flavor);
1108   g_qualifierList.add($$);
1109   delete $1;
1110   delete $2->value;
1111   delete v;
1112  } ;
1113
1114
1115
1116 qualifierName: TOK_SIMPLE_IDENTIFIER { 
1117     g_flavor = CIMFlavor (CIMFlavor::NONE); }
1118              | metaElement { 
1119                         $$ = new String((*$1).toString ());
1120                         g_flavor = CIMFlavor (CIMFlavor::NONE); } ;
1121
1122
1123
1124 typedQualifierParameter: TOK_LEFTPAREN nonNullConstantValue TOK_RIGHTPAREN 
1125                     {
1126                     g_typedInitializerValue.type = CIMMOF_CONSTANT_VALUE;
1127                     g_typedInitializerValue.value =  $2;
1128                     $$ = &g_typedInitializerValue;
1129                     }
1130                   | TOK_LEFTPAREN TOK_NULL_VALUE TOK_RIGHTPAREN
1131                     {
1132                     g_typedInitializerValue.type = CIMMOF_NULL_VALUE;
1133                     g_typedInitializerValue.value = new String(String::EMPTY);
1134                     $$ = &g_typedInitializerValue;
1135                     }
1136                   | arrayInitializer
1137                     {
1138                     g_typedInitializerValue.type = CIMMOF_ARRAY_VALUE;
1139                     g_typedInitializerValue.value =  $1;
1140                     $$ = &g_typedInitializerValue;
1141                     }
1142                   | {   /* empty */
1143                     g_typedInitializerValue.type = CIMMOF_NULL_VALUE;
1144                     g_typedInitializerValue.value = new String(String::EMPTY);
1145                     $$ = &g_typedInitializerValue;
1146                     };
1147
1148
1149 pragmaName: TOK_SIMPLE_IDENTIFIER { $$ = $1; } ;
1150
1151
1152 pragmaVal:  TOK_STRING_VALUE { $$ = $1; } ;
1153
1154 %%
1155
1156 /*
1157 **==============================================================================
1158 **
1159 ** MOF_error():
1160 **
1161 **==============================================================================
1162 */
1163 static void MOF_error(const char * str, const char * S)
1164 {
1165   printf("%s %s\n", str, S);
1166 }
1167
1168 /*
1169 **==============================================================================
1170 **
1171 ** MOF_trace():
1172 **
1173 **==============================================================================
1174 */
1175 // #define DEBUG_cimmof 1
1176
1177 static void MOF_trace(const char* str)
1178 {
1179 #ifdef DEBUG_cimmof
1180     printf("MOF_trace(): %s \n", str);
1181 #endif // DEBUG_cimmof
1182 }
1183
1184 static void MOF_trace2(const char * str, const char * S)
1185 {
1186 #ifdef DEBUG_cimmof
1187   printf("MOF_trace2(): %s %s\n", str, S);
1188 #endif // DEBUG_cimmof
1189 }