1 karl 1.20 //%2006////////////////////////////////////////////////////////////////////////
|
2 mike 1.8 //
|
3 karl 1.17 // 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 karl 1.16 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.17 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
|
9 karl 1.18 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 karl 1.20 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 mike 1.8 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
15 kumpf 1.12 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
18 mike 1.8 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
|
20 karl 1.21 //
|
21 kumpf 1.12 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
22 mike 1.8 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
24 kumpf 1.12 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
27 mike 1.8 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 //==============================================================================
31 //
32 //%/////////////////////////////////////////////////////////////////////////////
33
34
35 //
36 // Header for a class to generate CIMValue objects from String values
37 //
38 //
39 //
40 // This is a generic parser class from which controllers for particular
41 // yacc parsers can be derived. It keeps enough state information that
42 // you should be able to get by without a reentrant parser. You should
43 // compile both parser and lexer with a C++ compiler, although there
44 // is no need to generate a C++ lexer.
45 //
46 // The include file and compile-from-String techniques used here are
47 // supported only by bison and flex.
48 mike 1.8 //
49
50 #ifndef _PARSER_H_
51 #define _PARSER_H_
52
|
53 marek 1.15 #include <Pegasus/Common/Config.h>
|
54 mike 1.8 #include <cstdio>
55 #include <Pegasus/Common/String.h>
56 #include <Pegasus/Common/Stack.h>
|
57 kumpf 1.13 #include <Pegasus/Compiler/Linkage.h>
|
58 jim.wunderlich 1.19 #include <Pegasus/Common/FileSystem.h>
59
|
60 mike 1.8
61 PEGASUS_USING_STD;
62 PEGASUS_USING_PEGASUS;
63
|
64 kumpf 1.9 #define CIMMOF_CONSTANT_VALUE 1
65 #define CIMMOF_ARRAY_VALUE 2
66 #define CIMMOF_REFERENCE_VALUE 3
67 #define CIMMOF_NULL_VALUE 4
68
|
69 jim.wunderlich 1.19 // #define DEBUG_INCLUDE // enables include file processing debug printout
70
|
71 karl 1.21 typedef struct typedInitializerValue
72 {
|
73 kumpf 1.9 Uint16 type;
74 const String *value;
|
75 karl 1.21 } TYPED_INITIALIZER_VALUE;
|
76 kumpf 1.9
|
77 karl 1.21 struct bufstate
78 {
79 void *buffer_state; // the YY_BUFFER_STATE of the stacked context
80 String filename; // the name of the file open in the stacked context
81 int lineno; // the line number of the file
82 String filenamePath; //the path of the file open in the stacked context
|
83 mike 1.8 };
84
|
85 karl 1.21 class PEGASUS_COMPILER_LINKAGE parser
86 {
87 private:
88 unsigned int _buffer_size; // the value of the YY_BUFFER_SIZE macro
89 Stack<bufstate*> _include_stack; // a stack of YY_BUFFER_STATEs
90 String _current_filename; // name of the file being parsed
91 unsigned int _lineno; // current line number in the file
92 String _current_filenamePath; // path of the file being parsed
93 protected:
94 void push_statebuff(bufstate *statebuff)
95 {
96 _include_stack.push(statebuff);
97 }
98 bufstate *pop_statebuff();
99 public:
100
101 // Constructor, destructor
102 parser() : _buffer_size(16384), _lineno(0) {;}
103 virtual ~parser() {;}
104
105 virtual int parse() = 0; // call the parser main yy_parse()
106 karl 1.21 virtual int wrap(); // handle the end of the current stream
107
108 // start parsing this file
109 int setInputBufferFromName(const String &filename);
110 virtual int setInputBuffer(const FILE *f,
111 Boolean closeCurrent) = 0; // start parsing this handle
112 // int setInputBuffer(const char *buf); // start parsing this String
113 virtual int setInputBuffer(void *buffstate,
114 Boolean closeCurrent) = 0; // start parsing this buffer
115
116 // given a file stream, treat it as an include file
117 virtual int enterInlineInclude(const FILE *f) = 0;
118 virtual int wrapCurrentBuffer() = 0;
119
120 unsigned int get_buffer_size() { return _buffer_size; }
121 void set_buffer_size(unsigned int siz) { _buffer_size = siz; }
122
123 // We keep track of the filename associated with the current input
124 // buffer so we can report on it.
125 void set_current_filename(const String &filename)
126 {
127 karl 1.21 _current_filename = filename;
|
128 jim.wunderlich 1.19
129 #ifdef DEBUG_INCLUDE
|
130 karl 1.21 cout << "cimmof parser - setting path = "
131 << get_current_filenamePath() << endl; // DEBUG
|
132 jim.wunderlich 1.19 #endif // DEBUG_INCLUDE
133
|
134 karl 1.21 String includePathTemp = FileSystem::extractFilePath(filename);
|
135 jim.wunderlich 1.19
|
136 karl 1.21 // ************************************************************
137 // if the filename path consisted of just the file name
138 // becasue it is in the current directory then extractFilePath
139 // returns just the filename rather than "dot". The following
140 // test is to prevent adding file names to the include path.
141 // ****************************************************************
142 if (includePathTemp == filename)
143 {
144 includePathTemp = ".";
145 }
146
147 set_current_filenamePath(includePathTemp);
|
148 jim.wunderlich 1.19
149 #ifdef DEBUG_INCLUDE
|
150 karl 1.21 cout << "cimmof parser set filename = " << filename
151 << " include path = " << get_current_filenamePath()
152 << endl; // DEBUG
|
153 jim.wunderlich 1.19 #endif // DEBUG_INCLUDE
|
154 karl 1.21 }
|
155 jim.wunderlich 1.19
|
156 karl 1.21 const String &get_current_filename() const { return _current_filename; }
|
157 jim.wunderlich 1.19
|
158 karl 1.21 // We keep track of the filename path associated with the current input
159 // buffer so we can use it to search for include files in that
160 // same directory
161 void set_current_filenamePath(const String &filenamePath)
162 { _current_filenamePath = filenamePath; }
163
164 const String &get_current_filenamePath() const
165 {
166 return _current_filenamePath;
167 }
168
169 // Ditto the line number
170 void set_lineno(int n) { _lineno = n; }
171 void increment_lineno() { ++_lineno; }
172 unsigned int get_lineno() const { return _lineno; }
|
173 mike 1.8
|
174 karl 1.21 // This is the main entry point for parser error logging
175 virtual void log_parse_error(char *token, const char *errmsg) const;
|
176 mike 1.8 };
177 #endif
|