1 mike 1.8 //%/////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to
7 // deal in the Software without restriction, including without limitation the
8 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 // sell copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
13 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
14 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
15 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
16 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
18 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
19 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 //
21 //==============================================================================
22 mike 1.8 //
23 // Author: Bob Blair (bblair@bmc.com)
24 //
25 // Modified By:
26 //
27 //%/////////////////////////////////////////////////////////////////////////////
28
29
30 //
31 //
32 // This header describes the cimmofParser class.
33 // It is a singleton, and can only be accessed via the pointer
34 // returned by its static Intance() method.
35 // //
36 // The instance of this
37 // class hold enough state information that there should be no need for
38 // the underlying YACC parser to be written reentrant.
39 //
40 // The YACCer (and LExer) communicate with the instance of this class
41 // via the ointer returned by the Instance() method.
42 //
43 mike 1.8 // This specialization contains a reference to the containing program's
44 // mofComplerCmdLine object, which holds the command line arguments
45 // including the list of directories to search to find included mof files
46 //
47
48 #ifndef _CIMMOFPARSER_H_
49 #define _CIMMOFPARSER_H_
50
51
52 #include "parser.h"
53 #include "mofCompilerOptions.h"
54 #include "cimmofRepository.h"
55 #include <Pegasus/Common/Config.h>
56 #include <Pegasus/Common/Exception.h>
57 #include "memobjs.h"
58 #include "objname.h"
59
60 extern int cimmof_parse(); // the yacc parser entry point
61
62 PEGASUS_USING_STD;
63 PEGASUS_USING_PEGASUS;
64 mike 1.8
65 class cimmofRepository;
66
67 // This class extends class parser (see parser.h)
68 class PEGASUS_COMPILER_LINKAGE cimmofParser : public parser {
69 private:
70 // This is meant to be a singleton, so we hide the constructor
71 // and the destructor
72 static cimmofParser *_instance;
73 cimmofParser();
74 ~cimmofParser();
75 void elog(const String &msg) const; // handle logging of warnings
76 void wlog(const String &msg) const; // handle logging of warnings
77 void trace(const String &head, const String &tail) const;
78 //either throw us out or retry depending on user preference
79 void maybeThrowParseError(const String &msg) const;
80 void maybeThrowLexerError(const String &msg) const;
81
82 // Here are the members added by this specialization
83 const mofCompilerOptions *_cmdline;
84 String _includefile; // temp storage for included file to be entered
85 mike 1.8 cimmofRepository *_repository; // the repository object to use
86 String _defaultNamespacePath; // The path we'll use if none is given
87 String _currentNamespacePath; // a namespace set from a #pragma
88 public:
89 // Provide a way for the singleton to be constructed, or a
90 // pointer to be returned:
91 static cimmofParser *Instance();
92
93 //------------------------------------------------------------------
94 // Methods for manipulating the members added in this specialization
95 //------------------------------------------------------------------
96 // compiler options. This may be set from command line data,
97 // or by an embedding application
98 void setCompilerOptions(const mofCompilerOptions *co);
99 const mofCompilerOptions *getCompilerOptions() const;
100 // for all, or nearly all, operations, a repository object is needed
101 Boolean setRepository(void);
102 const cimmofRepository *getRepository() const;
103 // Set a default root namespace path to pass to the repository
104 void setDefaultNamespacePath(const String &path); // default value
105 void setCurrentNamespacePath(const String &path); // current override
106 mike 1.8 const String &getDefaultNamespacePath() const;
107 const String &getCurrentNamespacePath() const;
108 // Get the effective namespace path -- the override, if there is one.
109 const String &getNamespacePath() const;
110 //------------------------------------------------------------------
111 // Methods that implement or override base class methods
112 //------------------------------------------------------------------
113 // establish an input buffer given an input file stream
114 int setInputBuffer(const FILE *f);
115 // establish an input buffer given an existing context (YY_BUFFERSTATE)
116 int setInputBuffer(void *buffstate);
117 // Dig into an include file given its name
118 int enterInlineInclude(const String &filename);
119 // Dig into an include file given an input file stream
120 int enterInlineInclude(const FILE *f);
121 // Handle end-of-file
122 int wrapCurrentBuffer();
123 // Parse an input file
124 int parse();
125 // Log a parser error
126 void log_parse_error(char *token, char *errmsg) const;
127 mike 1.8
128 //------------------------------------------------------------------
129 // Do various representation transformations.
130 // These are in this class simply because there wasn't another
131 // conventient place for them. They could just as well be static
132 // methods of some convenience class.
133 //------------------------------------------------------------------
134 // Octal character input to decimal character output
135 char *oct_to_dec(const String &octrep) const;
136 // Hex character input to decimal character output
137 char *hex_to_dec(const String &hexrep) const;
138 // Binary character input to decimal character output
139 char *binary_to_dec(const String &binrep) const;
140
141 //------------------------------------------------------------------
142 // Handle the processing of CIM-specific constructs
143 //------------------------------------------------------------------
144 // This is called after a completed #pragma production is formed
145 void processPragma(const String &pragmaName, const String &pragmaString);
146 // This is called when a completed class declaration production is formed
147 int addClass(CIMClass *classdecl);
148 mike 1.8 // This is called when a new class declaration heading is discovered
149 CIMClass *newClassDecl(const String &name, const String &superclass);
150 // Called when a completed instanace declaration production is formed
151 int addInstance(CIMInstance *instance);
152 // Called when a new qualifier declaration heading is discovered
153 CIMQualifierDecl *newQualifierDecl(const String &name, const CIMValue *value,
154 Uint32 scope, Uint32 flavor);
155 // Called when a completed qualifier declaration production is formed
156 int addQualifier(CIMQualifierDecl *qualifier);
157 // Called when a new qualifier declaration heading is discovered
158 CIMQualifier *newQualifier(const String &name, const CIMValue &val,
159 Uint32 flav);
160 // Called when a new instance declaration heading is discovered
161 CIMInstance *newInstance(const String &name);
162 // Called when a new property is discovered
163 CIMProperty *newProperty(const String &name, const CIMValue &val,
164 const String &referencedObj = String::EMPTY) const;
165 // Called when a property production inside a class is complete
166 int applyProperty(CIMClass &c, CIMProperty &p);
167 // Called when a property production inside an instance is complete
168 int applyProperty(CIMInstance &instance, CIMProperty &p);
169 mike 1.8 // Called when a new method is discovered
170 CIMMethod *newMethod(const String &name, const CIMType type);
171 // Called when a method production inside a class is complete
172 int applyMethod(CIMClass &c, CIMMethod &m);
173 // Called when a method parameter is discovered
174 CIMParameter *newParameter(const String &name, const CIMType type,
175 Boolean isArray=false, Uint32 array=0,
176 const String &objName=String::EMPTY);
177 // Called when a method parameter production is complete
178 int applyParameter(CIMMethod &method, CIMParameter &parm);
179 // Called when a qualifier value production is complete
180 CIMValue *QualifierValue(const String &qualifierName, const String &valstr);
181 // Called to retrieve the value object for an existing parameter
182 CIMProperty *PropertyFromInstance(CIMInstance &instance,
183 const String &propertyName) const;
184 CIMValue *ValueFromProperty(const CIMProperty &prop) const;
185 CIMValue *PropertyValueFromInstance(CIMInstance &instance,
186 const String &propertyName) const;
187 // Called when a class alias is found
188 void addClassAlias(const String &alias, const CIMClass *cd,
189 Boolean isInstance);
190 mike 1.8 // Called when an instance alias is found
191 void addInstanceAlias(const String &alias, const CIMInstance *cd,
192 Boolean isInstance);
193 // Called when a reference declaration is found
194 CIMReference *newReference(const objectName &oname);
195 // Make a clone of a property object, inserting a new value object
196 CIMProperty *copyPropertyWithNewValue(const CIMProperty &p,
197 const CIMValue &v) const;
198 };
199
200 // Exceptions
201
202 class PEGASUS_COMPILER_LINKAGE ParseError : public Exception {
203 public:
204 static const char MSG[];
205 ParseError(const String &msg) : Exception(MSG + msg) {}
206 };
207
208 class PEGASUS_COMPILER_LINKAGE LexerError : public Exception {
209 public:
210 static const char MSG[];
211 mike 1.8 LexerError(const String &lexerr) : Exception(MSG + lexerr) {}
212 };
213
214 #endif
215
216
217
|