(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                     PEGASUS_USING_STD;
 60                     PEGASUS_USING_PEGASUS;
 61                     
 62 kumpf          1.9  #define CIMMOF_CONSTANT_VALUE  1
 63                     #define CIMMOF_ARRAY_VALUE     2
 64                     #define CIMMOF_REFERENCE_VALUE 3
 65                     #define CIMMOF_NULL_VALUE      4
 66                     
 67 jim.wunderlich 1.19 // #define  DEBUG_INCLUDE // enables include file processing debug printout
 68                     
 69 karl           1.21 typedef struct typedInitializerValue
 70                     {
 71 kumpf          1.9      Uint16 type;
 72                         const String *value;
 73 karl           1.21 } TYPED_INITIALIZER_VALUE;
 74 kumpf          1.9  
 75 karl           1.21 struct bufstate
 76                     {
 77                         void *buffer_state; // the YY_BUFFER_STATE of the stacked context
 78                         String filename;    // the name of the file open in the stacked context
 79                         int    lineno;      // the line number of the file
 80                         String filenamePath; //the path of the file open in the stacked context
 81 mike           1.8  };
 82                     
 83 karl           1.21 class PEGASUS_COMPILER_LINKAGE  parser
 84                     {
 85                         private:
 86                             unsigned int _buffer_size;   // the value of the YY_BUFFER_SIZE macro
 87                             Stack<bufstate*> _include_stack;  // a stack of YY_BUFFER_STATEs
 88                             String _current_filename; // name of the file being parsed
 89                             unsigned int _lineno;     // current line number in the file
 90                             String _current_filenamePath; // path of the file being parsed
 91                         protected:
 92                             void push_statebuff(bufstate *statebuff)
 93                             {
 94                                 _include_stack.push(statebuff);
 95                             }
 96                             bufstate *pop_statebuff();
 97                         public:
 98                     
 99                             // Constructor, destructor
100                             parser() : _buffer_size(16384), _lineno(0) {;}
101                             virtual ~parser() {;}
102                     
103                             virtual int parse() = 0;    // call the parser main yy_parse()
104 karl           1.21         virtual int wrap();         // handle the end of the current stream
105                     
106                             // start parsing this file
107                             int setInputBufferFromName(const String &filename);
108                             virtual int setInputBuffer(const FILE *f,
109                                     Boolean closeCurrent) = 0;  // start parsing this handle
110                             //  int setInputBuffer(const char *buf);   // start parsing this String
111                             virtual int setInputBuffer(void *buffstate,
112                                     Boolean closeCurrent) = 0; // start parsing this buffer
113                     
114                             // given a file stream, treat it as an include file
115                             virtual int enterInlineInclude(const FILE *f) = 0;
116                             virtual int wrapCurrentBuffer() = 0;
117                     
118                             unsigned int get_buffer_size() { return _buffer_size; }
119                             void set_buffer_size(unsigned int siz) { _buffer_size = siz; }
120                     
121                             // We keep track of the filename associated with the current input
122                             // buffer so we can report on it.
123                             void set_current_filename(const String &filename)
124                             {
125 karl           1.21             _current_filename = filename;
126 jim.wunderlich 1.19 
127                     #ifdef DEBUG_INCLUDE
128 karl           1.21             cout << "cimmof parser - setting path = "
129                                     << get_current_filenamePath() << endl; // DEBUG
130 jim.wunderlich 1.19 #endif // DEBUG_INCLUDE
131                     
132 karl           1.21             String includePathTemp = FileSystem::extractFilePath(filename);
133 jim.wunderlich 1.19 
134 karl           1.21             // ************************************************************
135                                 // if the filename path consisted of just the file name
136                                 // becasue it is in the current directory then extractFilePath
137                                 // returns just the filename rather than "dot". The following
138                                 // test is to prevent adding file names to the include path.
139                                 // ****************************************************************
140                                 if (includePathTemp == filename)
141                                 {
142                                     includePathTemp = ".";
143                                 }
144                     
145                                 set_current_filenamePath(includePathTemp);
146 jim.wunderlich 1.19 
147                     #ifdef DEBUG_INCLUDE
148 karl           1.21             cout << "cimmof parser set filename = " << filename
149                                     << " include path = " << get_current_filenamePath()
150                                     << endl; // DEBUG
151 jim.wunderlich 1.19 #endif //  DEBUG_INCLUDE
152 karl           1.21         }
153 jim.wunderlich 1.19 
154 karl           1.21         const String &get_current_filename() const { return _current_filename; }
155 jim.wunderlich 1.19 
156 karl           1.21         // We keep track of the filename path associated with the current input
157                             // buffer so we can use it to search for include files in that
158                             // same directory
159                             void set_current_filenamePath(const String &filenamePath)
160                             { _current_filenamePath = filenamePath; }
161                     
162                             const String &get_current_filenamePath() const
163                             {
164                                 return _current_filenamePath;
165                             }
166                     
167                             // Ditto the line number
168                             void set_lineno(int n) { _lineno = n; }
169                             void increment_lineno() { ++_lineno; }
170                             unsigned int get_lineno() const { return _lineno; }
171 mike           1.8  
172 karl           1.21         // This is the main entry point for parser error logging
173                             virtual void log_parse_error(char *token, const char *errmsg) const;
174 mike           1.8  };
175                     #endif

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2