1 karl 1.14 //%2006////////////////////////////////////////////////////////////////////////
|
2 chuck 1.2 //
|
3 karl 1.7 // 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 chuck 1.2 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.7 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
9 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 karl 1.14 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 chuck 1.2 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // 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 // 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 karl 1.14 //
|
21 chuck 1.2 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 // 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 // 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 // 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 david.dillard 1.9 // Author: Humberto Rivero (hurivero@us.ibm.com)
|
33 chuck 1.2 //
|
34 david.dillard 1.5 // Modified By: David Dillard, VERITAS Software Corp.
35 // (david.dillard@veritas.com)
|
36 joyce.j 1.8 // Josephine Eskaline Joyce (jojustin@in.ibm.com) for PEP#101
|
37 chuck 1.2 //
38 //%/////////////////////////////////////////////////////////////////////////////
39
|
40 david.dillard 1.12 #include "CQLParser.h"
41 #include "CQLParserState.h"
|
42 chuck 1.2 #include <Pegasus/Common/InternalException.h>
|
43 mike 1.15 #include <Pegasus/Common/Mutex.h>
|
44 chuck 1.2 #include <Pegasus/Query/QueryCommon/QueryException.h>
45 #include <Pegasus/Common/Tracer.h>
46 #include <Pegasus/Common/PegasusVersion.h>
47
48 PEGASUS_USING_STD;
49
50 extern int CQL_parse();
51 extern void CQL_restart (FILE *input_file);
|
52 humberto 1.6 extern void CQL_Bison_Cleanup();
|
53 chuck 1.2
54 PEGASUS_NAMESPACE_BEGIN
55
|
56 humberto 1.4 CQLParserState* CQL_globalParserState = 0;
|
57 humberto 1.3 static Mutex CQL_mutex;
|
58 chuck 1.2
59 void CQLParser::parse(
60 const char* text,
61 CQLSelectStatement& statement)
62 {
63 PEG_METHOD_ENTER(TRC_CQL,"CQLParser::parse");
|
64 david.dillard 1.9
|
65 kumpf 1.10 AutoMutex mtx(CQL_mutex);
|
66 david.dillard 1.9
|
67 chuck 1.2 if (!text)
68 {
69 PEG_METHOD_EXIT();
|
70 kumpf 1.10 throw NullPointer();
|
71 chuck 1.2 }
72
73 statement.clear();
74 CQL_restart (0);
75
|
76 humberto 1.4 CQL_globalParserState = new CQLParserState;
77 CQL_globalParserState->error = false;
78 CQL_globalParserState->text = text;
79 CQL_globalParserState->textSize = strlen(text) + 1;
80 CQL_globalParserState->offset = 0;
81 CQL_globalParserState->currentTokenPos = 0;
82 CQL_globalParserState->tokenCount = 0;
83 CQL_globalParserState->currentRule = String::EMPTY;
84 CQL_globalParserState->statement = &statement;
|
85 chuck 1.2
|
86 kumpf 1.10 try
87 {
88 CQL_parse();
89 }
|
90 chuck 1.11 catch(...)
|
91 kumpf 1.10 {
92 CQL_Bison_Cleanup();
|
93 chuck 1.11 PEG_METHOD_EXIT();
|
94 kumpf 1.10 throw;
95 }
|
96 chuck 1.2
|
97 humberto 1.4 if (CQL_globalParserState->error)
|
98 chuck 1.2 {
|
99 kumpf 1.10 String errorMessage = CQL_globalParserState->errorMessage;
100 cleanup();
101 Uint32 position = CQL_globalParserState->currentTokenPos;
102 Uint32 token = CQL_globalParserState->tokenCount;
103 String rule = CQL_globalParserState->currentRule;
104 delete CQL_globalParserState;
|
105 chuck 1.2 PEG_METHOD_EXIT();
|
106 kumpf 1.10 throw CQLSyntaxErrorException(errorMessage,token,position,rule);
|
107 chuck 1.2 }
108
109 cleanup();
|
110 humberto 1.4 delete CQL_globalParserState;
|
111 chuck 1.2 PEG_METHOD_EXIT();
112 }
113
114 void CQLParser::parse(
|
115 mike 1.13 const Buffer& text,
|
116 chuck 1.2 CQLSelectStatement& statement)
117 {
118 PEG_METHOD_ENTER(TRC_CQL,"CQLParser::parse");
119
120 if (text.size() == 0 || text[text.size() - 1] != '\0')
121 {
122 PEG_METHOD_EXIT();
|
123 kumpf 1.10 throw MissingNullTerminator();
|
124 chuck 1.2 }
125
126 parse(text.getData(), statement);
127 PEG_METHOD_EXIT();
128 }
129
130 void CQLParser::parse(
131 const String& text,
132 CQLSelectStatement& statement)
133 {
134 PEG_METHOD_ENTER(TRC_CQL,"CQLParser::parse");
135
136 parse(text.getCString(), statement);
137
138 PEG_METHOD_EXIT();
139 }
140
141 void CQLParser::cleanup()
142 {
143 PEG_METHOD_ENTER(TRC_CQL,"CQLParser::cleanup");
144
145 chuck 1.2
|
146 humberto 1.4 Array<char*>& arr = CQL_globalParserState->outstandingStrings;
|
147 chuck 1.2
148 for (Uint32 i = 0, n = arr.size(); i < n; i++)
|
149 kumpf 1.10 delete [] arr[i];
|
150 chuck 1.2
151 arr.clear();
152
153 PEG_METHOD_EXIT();
154 }
155
156 PEGASUS_NAMESPACE_END
157
158 PEGASUS_USING_PEGASUS;
159
160 int CQL_error(const char* errorMessage)
161 {
162 PEG_METHOD_ENTER(TRC_CQL,"CQL_error");
|
163 humberto 1.4 CQL_globalParserState->error = true;
164 CQL_globalParserState->errorMessage = errorMessage;
|
165 chuck 1.2
166 //
167 // flex does not automatically flush the input buffer in case of error
168 //
169 CQL_restart (0);
170
171 PEG_METHOD_EXIT();
172 return -1;
173 }
174
175 int CQLInput(char* buffer, int& numRead, int numRequested)
176 {
177 PEG_METHOD_ENTER(TRC_CQL,"CQLInput");
178 //
179 // Be sure to account for the null terminator (the size of the text will
180 // be one or more; this is fixed checked beforehand by CQLParser::parse()).
181 //
|
182 david.dillard 1.9 int remaining =
|
183 kumpf 1.10 CQL_globalParserState->textSize - CQL_globalParserState->offset - 1;
|
184 chuck 1.2
185 if (remaining == 0)
186 {
|
187 kumpf 1.10 numRead = 0;
|
188 chuck 1.2 PEG_METHOD_EXIT();
|
189 kumpf 1.10 return 0;
|
190 chuck 1.2 }
191
192 if (remaining < numRequested)
|
193 kumpf 1.10 numRequested = remaining;
|
194 chuck 1.2
|
195 david.dillard 1.9 memcpy(buffer,
|
196 kumpf 1.10 CQL_globalParserState->text + CQL_globalParserState->offset,
197 numRequested);
|
198 chuck 1.2
|
199 humberto 1.4 CQL_globalParserState->offset += numRequested;
|
200 chuck 1.2 numRead = numRequested;
201
202
203 PEG_METHOD_EXIT();
204 return numRead;
205 }
|