File: TaQLNode.cc

package info (click to toggle)
casacore 3.8.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 51,912 kB
  • sloc: cpp: 471,569; fortran: 16,372; ansic: 7,416; yacc: 4,714; lex: 2,346; sh: 1,865; python: 629; perl: 531; sed: 499; csh: 201; makefile: 32
file content (311 lines) | stat: -rw-r--r-- 8,048 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
//# TaQLNode.cc: Representation of entities in the TaQL parse tree
//# Copyright (C) 2005
//# Associated Universities, Inc. Washington DC, USA.
//#
//# This library is free software; you can redistribute it and/or modify it
//# under the terms of the GNU Library General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or (at your
//# option) any later version.
//#
//# This library is distributed in the hope that it will be useful, but WITHOUT
//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
//# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
//# License for more details.
//#
//# You should have received a copy of the GNU Library General Public License
//# along with this library; if not, write to the Free Software Foundation,
//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
//#
//# Correspondence concerning AIPS++ should be addressed as follows:
//#        Internet email: casa-feedback@nrao.edu.
//#        Postal address: AIPS++ Project Office
//#                        National Radio Astronomy Observatory
//#                        520 Edgemont Road
//#                        Charlottesville, VA 22903-2475 USA

//# Includes
#include <casacore/tables/TaQL/TaQLNode.h>
#include <casacore/tables/TaQL/TaQLNodeDer.h>
#include <casacore/tables/TaQL/TableGram.h>
#include <casacore/casa/IO/AipsIO.h>
#include <casacore/tables/Tables/TableError.h>

namespace casacore { //# NAMESPACE CASACORE - BEGIN


// Initialize the static getting the result from the parser.
TaQLNode TaQLNode::theirNode;
std::vector<TaQLNode*> TaQLNode::theirNodesCreated;
// Initialize the TaQL style.
TaQLStyle TaQLNode::theirStyle;
std::mutex TaQLNode::theirMutex;


TaQLNode TaQLNode::parse (const String& command)
{
  // Add a newline if not present.
  String str(command);
  if (str.length() == 0  ||  str[str.length()-1] != '\n') {
    str += '\n';
  }
  std::lock_guard<std::mutex> lock(theirMutex);
  // Reset to default TaQL style and no timings.
  theirStyle.reset();
  try {
    tableGramParseCommand (str);
  } catch (const TableGramError& x) {
    // Keep erroneous position and token in new exception
    clearNodesCreated();
    throw TableParseError (str + "  " + x.what(), x.pos(), x.token());
  } catch (const std::exception& x) {
    // Parse error, so delete all nodes and rethrow.
    clearNodesCreated();
    throw TableParseError (str + "  " + x.what());
  }
  TaQLNode node = theirNode;
  clearNodesCreated();
  return node;
}

void TaQLNode::clearNodesCreated()
{
  for (uInt i=0; i<theirNodesCreated.size(); ++i) {
    delete theirNodesCreated[i];
  }
  theirNodesCreated.resize (0);
  theirNode = TaQLNode();
}

void TaQLNode::save (AipsIO& aio) const
{
  aio.putstart ("TaQLNode", 1);
  saveNode (aio);
  aio.putend();
}

void TaQLNode::saveNode (AipsIO& aio) const
{
  if (itsRep) {
    aio << nodeType();
    itsRep->save (aio);
  } else {
    aio << TaQLNode_Null;
  }
}

TaQLNode TaQLNode::restore (AipsIO& aio)
{
  aio.getstart ("TaQLNode");
  TaQLNode node = restoreNode (aio);
  aio.getend();
  return node;
}

TaQLNode TaQLNode::restoreNode (AipsIO& aio)
{
  char nodeType;
  aio >> nodeType;
  switch (nodeType) {
  case TaQLNode_Null:
    return 0;
  case TaQLNode_Const:
    return TaQLConstNodeRep::restore (aio);
  case TaQLNode_Unary:
    return TaQLUnaryNodeRep::restore (aio);
  case TaQLNode_Binary:
    return TaQLBinaryNodeRep::restore (aio);
  case TaQLNode_Multi:
    return TaQLMultiNodeRep::restore (aio);
  case TaQLNode_Func:
    return TaQLFuncNodeRep::restore (aio);
  case TaQLNode_Range:
    return TaQLRangeNodeRep::restore (aio);
  case TaQLNode_Index:
    return TaQLIndexNodeRep::restore (aio);
  case TaQLNode_KeyCol:
    return TaQLKeyColNodeRep::restore (aio);
  case TaQLNode_Table:
    return TaQLTableNodeRep::restore (aio);
  case TaQLNode_Col:
    return TaQLColNodeRep::restore (aio);
  case TaQLNode_Columns:
    return TaQLColumnsNodeRep::restore (aio);
  case TaQLNode_Join:
    return TaQLJoinNodeRep::restore (aio);
  case TaQLNode_SortKey:
    return TaQLSortKeyNodeRep::restore (aio);
  case TaQLNode_Sort:
    return TaQLSortNodeRep::restore (aio);
  case TaQLNode_LimitOff:
    return TaQLLimitOffNodeRep::restore (aio);
  case TaQLNode_Giving:
    return TaQLGivingNodeRep::restore (aio);
  case TaQLNode_UpdExpr:
    return TaQLUpdExprNodeRep::restore (aio);
  case TaQLNode_Select:
    return TaQLSelectNodeRep::restore (aio);
  case TaQLNode_Update:
    return TaQLUpdateNodeRep::restore (aio);
  case TaQLNode_Insert:
    return TaQLInsertNodeRep::restore (aio);
  case TaQLNode_Delete:
    return TaQLDeleteNodeRep::restore (aio);
  case TaQLNode_Calc:
    return TaQLCalcNodeRep::restore (aio);
  case TaQLNode_CreTab:
    return TaQLCreTabNodeRep::restore (aio);
  case TaQLNode_ColSpec:
    return TaQLColSpecNodeRep::restore (aio);
  case TaQLNode_RecFld:
    return TaQLRecFldNodeRep::restore (aio);
  case TaQLNode_Unit:
    return TaQLUnitNodeRep::restore (aio);
  case TaQLNode_Regex:
    return TaQLRegexNodeRep::restore (aio);
  case TaQLNode_Count:
    return TaQLCountNodeRep::restore (aio);
  case TaQLNode_Groupby:
    return TaQLGroupNodeRep::restore (aio);
  case TaQLNode_AltTab:
    return TaQLAltTabNodeRep::restore (aio);
  case TaQLNode_AddCol:
    return TaQLAddColNodeRep::restore (aio);
  case TaQLNode_SetKey:
    return TaQLSetKeyNodeRep::restore (aio);
  case TaQLNode_RenDrop:
    return TaQLRenDropNodeRep::restore (aio);
  case TaQLNode_AddRow:
    return TaQLAddRowNodeRep::restore (aio);
  case TaQLNode_ConcTab:
    return TaQLConcTabNodeRep::restore (aio);
  case TaQLNode_Show:
    return TaQLShowNodeRep::restore (aio);
  case TaQLNode_CopyCol:
    return TaQLCopyColNodeRep::restore (aio);
  case TaQLNode_DropTab:
    return TaQLDropTabNodeRep::restore (aio);
  default:
    throw AipsError ("TaQLNode::restoreNode - unknown node type");
  }
}

TaQLMultiNode TaQLNode::restoreMultiNode (AipsIO& aio)
{
  char nodeType;
  aio >> nodeType;
  switch (nodeType) {
  case TaQLNode_Null:
    return 0;
  case TaQLNode_Multi:
    return TaQLMultiNodeRep::restore (aio);
  default:
    throw AipsError ("TaQLNode::restoreMultiNode - unknown node type");
  }
}


TaQLConstNode::TaQLConstNode (TaQLConstNodeRep* rep)
  : TaQLNode(rep),
    itsNRep(rep)
{}

void TaQLConstNode::setIsTableName()
{
  itsNRep->setIsTableName();
}

const String& TaQLConstNode::getString() const
{
  return itsNRep->getString();
}


TaQLRegexNode::TaQLRegexNode (TaQLRegexNodeRep* rep)
  : TaQLNode(rep),
    itsNRep(rep)
{}

const String& TaQLRegexNode::getString() const
{
  return itsNRep->itsValue;
}

Bool TaQLRegexNode::caseInsensitive() const
{
  return itsNRep->itsCaseInsensitive;
}

Bool TaQLRegexNode::negate() const
{
  return itsNRep->itsNegate;
}


TaQLMultiNode::TaQLMultiNode()
  : TaQLNode(0),
    itsNRep (0)
{}

TaQLMultiNode::TaQLMultiNode (Bool isSetOrArray)
  : TaQLNode(new TaQLMultiNodeRep(isSetOrArray))
{
  itsNRep = (TaQLMultiNodeRep*)(TaQLNode::itsRep.get());
}

TaQLMultiNode::TaQLMultiNode (TaQLMultiNodeRep* rep)
  : TaQLNode(rep),
    itsNRep (rep)
{}

void TaQLMultiNode::add (const TaQLNode& node)
{
  itsNRep->add (node);
}

void TaQLMultiNode::add (TaQLNodeRep* noderep)
{
  itsNRep->add (TaQLNode(noderep));
}

void TaQLMultiNode::setIsSetOrArray()
{
  itsNRep->setIsSetOrArray();
}

void TaQLMultiNode::setPPFix (const String& prefix, const String& postfix)
{
  itsNRep->setPPFix (prefix, postfix);
}

void TaQLMultiNode::setSeparator (const String& sep)
{
  itsNRep->setSeparator (sep);
}
void TaQLMultiNode::setSeparator (uInt incr, const String& sep)
{
  itsNRep->setSeparator (incr, sep);
}


TaQLQueryNode::TaQLQueryNode (TaQLQueryNodeRep* rep)
  : TaQLNode(rep),
    itsNRep (rep)
{}

void TaQLQueryNode::setBrackets()
{
  itsNRep->setBrackets();
}

void TaQLQueryNode::setNoExecute()
{
  itsNRep->setNoExecute();
}

void TaQLQueryNode::setFromExecute()
{
  itsNRep->setFromExecute();
}


} //# NAMESPACE CASACORE - END