1 karl 1.16 //%2003////////////////////////////////////////////////////////////////////////
|
2 mike 1.8 //
|
3 karl 1.16 // 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 // IBM Corp.; EMC Corporation, The Open Group.
|
7 mike 1.8 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
9 kumpf 1.12 // of this software and associated documentation files (the "Software"), to
10 // deal in the Software without restriction, including without limitation the
11 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
12 mike 1.8 // sell copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
|
15 kumpf 1.12 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
16 mike 1.8 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
17 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
18 kumpf 1.12 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
19 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
21 mike 1.8 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 //
24 //==============================================================================
25 //
26 // Author: Bob Blair (bblair@bmc.com)
27 //
28 // Modified By:
29 //
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 mike 1.8 // 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
|
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 mike 1.8
57 PEGASUS_USING_STD;
58 PEGASUS_USING_PEGASUS;
59
|
60 kumpf 1.9 #define CIMMOF_CONSTANT_VALUE 1
61 #define CIMMOF_ARRAY_VALUE 2
62 #define CIMMOF_REFERENCE_VALUE 3
63 #define CIMMOF_NULL_VALUE 4
64
65 typedef struct typedInitializerValue {
66 Uint16 type;
67 const String *value;
68 } TYPED_INITIALIZER_VALUE;
69
|
70 mike 1.8 struct bufstate {
71 void *buffer_state; // the YY_BUFFER_STATE of the stacked context
72 String filename; // the name of the file open in the stacked context
73 int lineno; // the line number of the file
74 };
75
76 class PEGASUS_COMPILER_LINKAGE parser {
77 private:
78 unsigned int _buffer_size; // the value of the YY_BUFFER_SIZE macro
79 Stack<bufstate*> _include_stack; // a stack of YY_BUFFER_STATEs
80 String _current_filename; // name of the file being parsed
81 unsigned int _lineno; // current line number in the file
82 protected:
83 void push_statebuff(bufstate *statebuff) { _include_stack.push(statebuff); }
84 bufstate *pop_statebuff();
85 public:
86
87 // Constructor, destructor
88 parser() : _buffer_size(16384), _lineno(0) {;}
89 virtual ~parser() {;}
90
91 mike 1.8 virtual int parse() = 0; // call the parser main yy_parse()
92 virtual int wrap(); // handle the end of the current stream
93
94 int setInputBufferFromName(const String &filename); // start parsing this file
|
95 kumpf 1.14 virtual int setInputBuffer(const FILE *f,
96 Boolean closeCurrent) = 0; // start parsing this handle
|
97 mike 1.8 // int setInputBuffer(const char *buf); // start parsing this String
|
98 kumpf 1.14 virtual int setInputBuffer(void *buffstate,
99 Boolean closeCurrent) = 0; // start parsing this buffer
|
100 mike 1.8
101 // given a file stream, treat it as an include file
102 virtual int enterInlineInclude(const FILE *f) = 0;
103 virtual int wrapCurrentBuffer() = 0;
104
105 unsigned int get_buffer_size() { return _buffer_size; }
106 void set_buffer_size(unsigned int siz) { _buffer_size = siz; }
107
108 // We keep track of the filename associated with the current input
109 // buffer so we can report on it.
110 void set_current_filename(const String &filename)
111 { _current_filename = filename; }
112 const String &get_current_filename() const { return _current_filename; }
113
114 // Ditto the line number
115 void set_lineno(int n) { _lineno = n; }
116 void increment_lineno() { ++_lineno; }
117 unsigned int get_lineno() const { return _lineno; }
118
119 // This is the main entry point for parser error logging
|
120 kumpf 1.10 virtual void log_parse_error(char *token, const char *errmsg) const;
|
121 mike 1.8 };
122 #endif
|