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

  1 karl  1.18 //%2005////////////////////////////////////////////////////////////////////////
  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 mike  1.8  //
 12            // Permission is hereby granted, free of charge, to any person obtaining a copy
 13 kumpf 1.12 // of this software and associated documentation files (the "Software"), to
 14            // deal in the Software without restriction, including without limitation the
 15            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 16 mike  1.8  // sell copies of the Software, and to permit persons to whom the Software is
 17            // furnished to do so, subject to the following conditions:
 18            // 
 19 kumpf 1.12 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 20 mike  1.8  // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 21            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 22 kumpf 1.12 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 23            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 24            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 25 mike  1.8  // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 26            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27            //
 28            //==============================================================================
 29            //
 30            // Author: Bob Blair (bblair@bmc.com)
 31            //
 32            // Modified By:
 33            //
 34            //%/////////////////////////////////////////////////////////////////////////////
 35            
 36            
 37            //
 38            // Header for a class to generate CIMValue objects from String values
 39            //
 40            //
 41            //
 42            // This is a generic parser class from which controllers for particular
 43            // yacc parsers can be derived.  It keeps enough state information that
 44            // you should be able to get by without a reentrant parser.  You should
 45            // compile both parser and lexer with a C++ compiler, although there
 46 mike  1.8  // is no need to generate a C++ lexer.
 47            //
 48            // The include file and compile-from-String techniques used here are
 49            // supported only by bison and flex.
 50            //
 51            
 52            #ifndef _PARSER_H_
 53            #define _PARSER_H_
 54            
 55 marek 1.15 #include <Pegasus/Common/Config.h>
 56 mike  1.8  #include <cstdio>
 57            #include <Pegasus/Common/String.h>
 58            #include <Pegasus/Common/Stack.h>
 59 kumpf 1.13 #include <Pegasus/Compiler/Linkage.h>
 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            typedef struct typedInitializerValue {
 70                Uint16 type;
 71                const String *value;
 72                } TYPED_INITIALIZER_VALUE;
 73            
 74 mike  1.8  struct bufstate {
 75            	void *buffer_state; // the YY_BUFFER_STATE of the stacked context
 76            	String filename;    // the name of the file open in the stacked context
 77            	int    lineno;      // the line number of the file
 78            };
 79            
 80            class PEGASUS_COMPILER_LINKAGE  parser {
 81             private:
 82              unsigned int _buffer_size;   // the value of the YY_BUFFER_SIZE macro
 83              Stack<bufstate*> _include_stack;  // a stack of YY_BUFFER_STATEs
 84              String _current_filename; // name of the file being parsed
 85              unsigned int _lineno;     // current line number in the file 
 86             protected:
 87              void push_statebuff(bufstate *statebuff) { _include_stack.push(statebuff); }
 88              bufstate *pop_statebuff();
 89             public:
 90            
 91              // Constructor, destructor
 92              parser() : _buffer_size(16384), _lineno(0) {;}
 93              virtual ~parser() {;}
 94            
 95 mike  1.8    virtual int parse() = 0;    // call the parser main yy_parse()
 96              virtual int wrap();         // handle the end of the current stream
 97            
 98              int setInputBufferFromName(const String &filename); // start parsing this file
 99 kumpf 1.14   virtual int setInputBuffer(const FILE *f, 
100                                   Boolean closeCurrent) = 0;  // start parsing this handle
101 mike  1.8    //  int setInputBuffer(const char *buf);   // start parsing this String
102 kumpf 1.14   virtual int setInputBuffer(void *buffstate,
103                                   Boolean closeCurrent) = 0; // start parsing this buffer
104 mike  1.8  
105              // given a file stream, treat it as an include file
106              virtual int enterInlineInclude(const FILE *f) = 0;
107              virtual int wrapCurrentBuffer() = 0;
108            
109              unsigned int get_buffer_size() { return _buffer_size; }
110              void set_buffer_size(unsigned int siz) { _buffer_size = siz; }
111            
112              // We keep track of the filename associated with the current input
113              // buffer so we can report on it.
114              void set_current_filename(const String &filename)
115              	{ _current_filename = filename; }
116              const String &get_current_filename() const { return _current_filename; }
117            
118              // Ditto the line number
119              void set_lineno(int n) { _lineno = n; }
120              void increment_lineno() { ++_lineno; }
121              unsigned int get_lineno() const { return _lineno; }
122            
123              // This is the main entry point for parser error logging
124 kumpf 1.10   virtual void log_parse_error(char *token, const char *errmsg) const;
125 mike  1.8  };
126            #endif

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2