(file) Return to parser.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Compiler

  1 martin 1.22 //%LICENSE////////////////////////////////////////////////////////////////
  2 martin 1.23 //
  3 martin 1.22 // Licensed to The Open Group (TOG) under one or more contributor license
  4             // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
  5             // this work for additional information regarding copyright ownership.
  6             // Each contributor licenses this file to you under the OpenPegasus Open
  7             // Source License; you may not use this file except in compliance with the
  8             // License.
  9 martin 1.23 //
 10 martin 1.22 // Permission is hereby granted, free of charge, to any person obtaining a
 11             // copy of this software and associated documentation files (the "Software"),
 12             // to deal in the Software without restriction, including without limitation
 13             // the rights to use, copy, modify, merge, publish, distribute, sublicense,
 14             // and/or sell copies of the Software, and to permit persons to whom the
 15             // Software is furnished to do so, subject to the following conditions:
 16 martin 1.23 //
 17 martin 1.22 // The above copyright notice and this permission notice shall be included
 18             // in all copies or substantial portions of the Software.
 19 martin 1.23 //
 20 martin 1.22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 21 martin 1.23 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 22 martin 1.22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 23             // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 24             // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 25             // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 26             // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27 martin 1.23 //
 28 martin 1.22 //////////////////////////////////////////////////////////////////////////
 29 mike   1.8  //
 30             //%/////////////////////////////////////////////////////////////////////////////
 31             
 32             
 33             //
 34             // Header for a class to generate CIMValue objects from String values
 35             //
 36             //
 37             //
 38             // This is a generic parser class from which controllers for particular
 39             // yacc parsers can be derived.  It keeps enough state information that
 40             // you should be able to get by without a reentrant parser.  You should
 41             // compile both parser and lexer with a C++ compiler, although there
 42             // is no need to generate a C++ lexer.
 43             //
 44             // The include file and compile-from-String techniques used here are
 45             // supported only by bison and flex.
 46             //
 47             
 48             #ifndef _PARSER_H_
 49             #define _PARSER_H_
 50 mike   1.8  
 51 marek  1.15 #include <Pegasus/Common/Config.h>
 52 mike   1.8  #include <cstdio>
 53             #include <Pegasus/Common/String.h>
 54             #include <Pegasus/Common/Stack.h>
 55 kumpf  1.13 #include <Pegasus/Compiler/Linkage.h>
 56 jim.wunderlich 1.19 #include <Pegasus/Common/FileSystem.h>
 57                     
 58 mike           1.8  
 59 karl           1.23.8.1 
 60 mike           1.8      PEGASUS_USING_STD;
 61                         PEGASUS_USING_PEGASUS;
 62                         
 63 jim.wunderlich 1.19     // #define  DEBUG_INCLUDE // enables include file processing debug printout
 64                         
 65 karl           1.23.8.1 // Define symbol for Empty Array.  Actually signal that this is not an
 66                         // array.
 67                         #define CIMMOF_EMPTY_ARRAY -1
 68                         
 69                         //// Enum to type the string values from nonNullConstantValue.
 70                         //// Used primarily to seperate Boolean and String types but test within
 71                         //// valueFactory to compare types with parsed types.
 72                         ////
 73                         namespace strValTypeNS
 74                         {
 75                             enum strValTypeEnum
 76                             {
 77                                 NULL_VALUE = 0,
 78                                 INTEGER_VALUE,
 79                                 REAL_VALUE,
 80                                 STRING_VALUE,
 81                                 BOOLEAN_VALUE,
 82                                 CHAR_VALUE
 83                             } ;
 84                         };
 85                         
 86 karl           1.23.8.1 // Display char def for the names (Used in exception generation)
 87                         const char * strValTypeEnumToString(strValTypeNS::strValTypeEnum x);
 88                         
 89                         //// Define a struct to contain the string value and type for
 90                         //// initializer values in the parser. This is used only by the grammar
 91                         //// today.
 92 karl           1.21     typedef struct typedInitializerValue
 93                         {
 94 karl           1.23.8.1     enum InitValueType
 95                             {
 96                                 CONSTANT_VALUE = 1,
 97                                 ARRAY_VALUE,
 98                                 REFERENCE_VALUE,
 99                                 NULL_VALUE
100                             } ;
101                         
102                             InitValueType type;
103 kumpf          1.9          const String *value;
104 karl           1.23.8.1     int nonNullParserType;
105                             void set(InitValueType t, String* v)
106                             {
107                                 type = t;
108                                 value = v;
109                             }
110                             void setNull()
111                             {
112                                 type = NULL_VALUE;
113                                 value = new String(String::EMPTY);
114                                 nonNullParserType = strValTypeNS::NULL_VALUE;
115                             }
116 karl           1.21     } TYPED_INITIALIZER_VALUE;
117 kumpf          1.9      
118 karl           1.21     struct bufstate
119                         {
120                             void *buffer_state; // the YY_BUFFER_STATE of the stacked context
121                             String filename;    // the name of the file open in the stacked context
122                             int    lineno;      // the line number of the file
123                             String filenamePath; //the path of the file open in the stacked context
124 mike           1.8      };
125                         
126 karl           1.21     class PEGASUS_COMPILER_LINKAGE  parser
127                         {
128                             private:
129                                 unsigned int _buffer_size;   // the value of the YY_BUFFER_SIZE macro
130                                 Stack<bufstate*> _include_stack;  // a stack of YY_BUFFER_STATEs
131                                 String _current_filename; // name of the file being parsed
132                                 unsigned int _lineno;     // current line number in the file
133                                 String _current_filenamePath; // path of the file being parsed
134                             protected:
135                                 void push_statebuff(bufstate *statebuff)
136                                 {
137                                     _include_stack.push(statebuff);
138                                 }
139                                 bufstate *pop_statebuff();
140                             public:
141                         
142                                 // Constructor, destructor
143                                 parser() : _buffer_size(16384), _lineno(0) {;}
144                                 virtual ~parser() {;}
145                         
146                                 virtual int parse() = 0;    // call the parser main yy_parse()
147 karl           1.21             virtual int wrap();         // handle the end of the current stream
148                         
149                                 // start parsing this file
150                                 int setInputBufferFromName(const String &filename);
151                                 virtual int setInputBuffer(const FILE *f,
152                                         Boolean closeCurrent) = 0;  // start parsing this handle
153                                 //  int setInputBuffer(const char *buf);   // start parsing this String
154                                 virtual int setInputBuffer(void *buffstate,
155                                         Boolean closeCurrent) = 0; // start parsing this buffer
156                         
157                                 // given a file stream, treat it as an include file
158                                 virtual int enterInlineInclude(const FILE *f) = 0;
159                                 virtual int wrapCurrentBuffer() = 0;
160                         
161                                 unsigned int get_buffer_size() { return _buffer_size; }
162                                 void set_buffer_size(unsigned int siz) { _buffer_size = siz; }
163                         
164                                 // We keep track of the filename associated with the current input
165                                 // buffer so we can report on it.
166                                 void set_current_filename(const String &filename)
167                                 {
168 karl           1.21                 _current_filename = filename;
169 jim.wunderlich 1.19     
170                         #ifdef DEBUG_INCLUDE
171 karl           1.21                 cout << "cimmof parser - setting path = "
172                                         << get_current_filenamePath() << endl; // DEBUG
173 jim.wunderlich 1.19     #endif // DEBUG_INCLUDE
174                         
175 karl           1.21                 String includePathTemp = FileSystem::extractFilePath(filename);
176 jim.wunderlich 1.19     
177 karl           1.21                 // ************************************************************
178                                     // if the filename path consisted of just the file name
179                                     // becasue it is in the current directory then extractFilePath
180                                     // returns just the filename rather than "dot". The following
181                                     // test is to prevent adding file names to the include path.
182                                     // ****************************************************************
183                                     if (includePathTemp == filename)
184                                     {
185                                         includePathTemp = ".";
186                                     }
187                         
188                                     set_current_filenamePath(includePathTemp);
189 jim.wunderlich 1.19     
190                         #ifdef DEBUG_INCLUDE
191 karl           1.21                 cout << "cimmof parser set filename = " << filename
192                                         << " include path = " << get_current_filenamePath()
193                                         << endl; // DEBUG
194 jim.wunderlich 1.19     #endif //  DEBUG_INCLUDE
195 karl           1.21             }
196 jim.wunderlich 1.19     
197 karl           1.21             const String &get_current_filename() const { return _current_filename; }
198 jim.wunderlich 1.19     
199 karl           1.21             // We keep track of the filename path associated with the current input
200                                 // buffer so we can use it to search for include files in that
201                                 // same directory
202                                 void set_current_filenamePath(const String &filenamePath)
203                                 { _current_filenamePath = filenamePath; }
204                         
205                                 const String &get_current_filenamePath() const
206                                 {
207                                     return _current_filenamePath;
208                                 }
209                         
210                                 // Ditto the line number
211                                 void set_lineno(int n) { _lineno = n; }
212                                 void increment_lineno() { ++_lineno; }
213                                 unsigned int get_lineno() const { return _lineno; }
214 mike           1.8      
215 karl           1.21             // This is the main entry point for parser error logging
216                                 virtual void log_parse_error(char *token, const char *errmsg) const;
217 mike           1.8      };
218                         #endif

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2