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

  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            // 
 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            // Author: Bob Blair (bblair@bmc.com)
 33            //
 34            // Modified By:
 35 jim.wunderlich 1.19 //              Jim Wunderlich (Jim_Wunderlich@prodigy.net)
 36 mike           1.8  //
 37                     //%/////////////////////////////////////////////////////////////////////////////
 38                     
 39                     
 40                     //
 41                     // Header for a class to generate CIMValue objects from String values
 42                     //
 43                     //
 44                     //
 45                     // This is a generic parser class from which controllers for particular
 46                     // yacc parsers can be derived.  It keeps enough state information that
 47                     // you should be able to get by without a reentrant parser.  You should
 48                     // compile both parser and lexer with a C++ compiler, although there
 49                     // is no need to generate a C++ lexer.
 50                     //
 51                     // The include file and compile-from-String techniques used here are
 52                     // supported only by bison and flex.
 53                     //
 54                     
 55                     #ifndef _PARSER_H_
 56                     #define _PARSER_H_
 57 mike           1.8  
 58 marek          1.15 #include <Pegasus/Common/Config.h>
 59 mike           1.8  #include <cstdio>
 60                     #include <Pegasus/Common/String.h>
 61                     #include <Pegasus/Common/Stack.h>
 62 kumpf          1.13 #include <Pegasus/Compiler/Linkage.h>
 63 jim.wunderlich 1.19 #include <Pegasus/Common/FileSystem.h>
 64                     
 65 mike           1.8  
 66                     PEGASUS_USING_STD;
 67                     PEGASUS_USING_PEGASUS;
 68                     
 69 kumpf          1.9  #define CIMMOF_CONSTANT_VALUE  1
 70                     #define CIMMOF_ARRAY_VALUE     2
 71                     #define CIMMOF_REFERENCE_VALUE 3
 72                     #define CIMMOF_NULL_VALUE      4
 73                     
 74 jim.wunderlich 1.19 // #define  DEBUG_INCLUDE // enables include file processing debug printout
 75                     
 76 kumpf          1.9  typedef struct typedInitializerValue {
 77                         Uint16 type;
 78                         const String *value;
 79                         } TYPED_INITIALIZER_VALUE;
 80                     
 81 mike           1.8  struct bufstate {
 82                     	void *buffer_state; // the YY_BUFFER_STATE of the stacked context
 83                     	String filename;    // the name of the file open in the stacked context
 84                     	int    lineno;      // the line number of the file
 85 jim.wunderlich 1.19 	String filenamePath; //the path of the file open in the stacked context
 86 mike           1.8  };
 87                     
 88                     class PEGASUS_COMPILER_LINKAGE  parser {
 89                      private:
 90                       unsigned int _buffer_size;   // the value of the YY_BUFFER_SIZE macro
 91                       Stack<bufstate*> _include_stack;  // a stack of YY_BUFFER_STATEs
 92                       String _current_filename; // name of the file being parsed
 93                       unsigned int _lineno;     // current line number in the file 
 94 jim.wunderlich 1.19   String _current_filenamePath; // path of the file being parsed
 95 mike           1.8   protected:
 96                       void push_statebuff(bufstate *statebuff) { _include_stack.push(statebuff); }
 97                       bufstate *pop_statebuff();
 98                      public:
 99                     
100                       // Constructor, destructor
101                       parser() : _buffer_size(16384), _lineno(0) {;}
102                       virtual ~parser() {;}
103                     
104                       virtual int parse() = 0;    // call the parser main yy_parse()
105                       virtual int wrap();         // handle the end of the current stream
106                     
107                       int setInputBufferFromName(const String &filename); // start parsing this file
108 kumpf          1.14   virtual int setInputBuffer(const FILE *f, 
109                                            Boolean closeCurrent) = 0;  // start parsing this handle
110 mike           1.8    //  int setInputBuffer(const char *buf);   // start parsing this String
111 kumpf          1.14   virtual int setInputBuffer(void *buffstate,
112                                            Boolean closeCurrent) = 0; // start parsing this buffer
113 mike           1.8  
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 jim.wunderlich 1.19   	{ 
125                     	  _current_filename = filename;
126                     
127                     #ifdef DEBUG_INCLUDE
128                     	  cout << "cimmof parser - setting path = " << get_current_filenamePath() << endl; // DEBUG
129                     #endif // DEBUG_INCLUDE
130                     
131                     	  String includePathTemp = FileSystem::extractFilePath(filename);
132                     	  
133                     	  // ************************************************************
134                     	  // if the filename path consisted of just the file name 
135                     	  // becasue it is in the current directory then extractFilePath
136                     	  // returns just the filename rather than "dot". The following 
137                     	  // test is to prevent adding file names to the include path.
138                     	  // ****************************************************************
139                     	  if (includePathTemp == filename)
140                     	    {
141                     	      includePathTemp = ".";
142                     	    }
143                     
144                     	    set_current_filenamePath(includePathTemp);	  
145 jim.wunderlich 1.19 
146                     #ifdef DEBUG_INCLUDE
147                     	    cout << "cimmof parser set filename = " << filename 
148                                      << " include path = " << get_current_filenamePath()
149                     		 << endl; // DEBUG
150                     #endif //  DEBUG_INCLUDE
151                     	}
152                     
153 mike           1.8    const String &get_current_filename() const { return _current_filename; }
154                     
155 jim.wunderlich 1.19   // We keep track of the filename path associated with the current input
156                       // buffer so we can use it to search for include files in that same directory
157                       void set_current_filenamePath(const String &filenamePath)
158                       	{ _current_filenamePath = filenamePath; }
159                     
160                       const String &get_current_filenamePath() const { return _current_filenamePath; }
161                     
162 mike           1.8    // Ditto the line number
163                       void set_lineno(int n) { _lineno = n; }
164                       void increment_lineno() { ++_lineno; }
165                       unsigned int get_lineno() const { return _lineno; }
166                     
167                       // This is the main entry point for parser error logging
168 kumpf          1.10   virtual void log_parse_error(char *token, const char *errmsg) const;
169 mike           1.8  };
170                     #endif

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2