forked from hpcc-systems/HPCC-Platform
/
hqlexpr.ipp
1535 lines (1260 loc) · 58.2 KB
/
hqlexpr.ipp
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*##############################################################################
Copyright (C) 2011 HPCC Systems.
All rights reserved. This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
############################################################################## */
#ifndef HQLEXPR_IPP_INCL
#define HQLEXPR_IPP_INCL
#define NUM_PARALLEL_TRANSFORMS 1
//I'm not sure if the following is needed or not - I'm slight concerned that remote scopes (e.g.,, plugins)
//may be accessed in parallel fro mmultiple threads, causing potential conflicts
#define THREAD_SAFE_SYMBOLS
#include "jexcept.hpp"
#include "javahash.hpp"
#include "defvalue.hpp"
#include "hqlexpr.hpp"
#ifdef USE_TBB
#include "tbb/scalable_allocator.h"
#endif
typedef byte transformdepth_t;
#define TRANSFORM_DEPTH_MASK 0x7f
#define TRANSFORM_DEPTH_NOLINK 0x80
#define TRANSFORM_DEPTH(depth) (depth & TRANSFORM_DEPTH_MASK)
//following are only stored in the save array
#define TRANSFORM_DEPTH_SAVE_MATCH_EXPR 0x100
#define RELEASE_TRANSFORM_EXTRA(depth, extra) { if (!(depth & TRANSFORM_DEPTH_NOLINK)) ::Release(extra); }
class CHqlExprMeta;
class HQL_API CHqlExpression : implements IHqlExpression, public CInterface
{
public:
friend HQL_API IHqlExpression *createOpenValue(node_operator op, ITypeInfo *type);
friend class CHqlExprMeta;
#ifdef USE_TBB
void *operator new(size32_t size) { return scalable_malloc(size); }
void operator delete(void *ptr) { return scalable_free(ptr); }
#endif
protected:
unsigned hashcode; // CInterface is 4 byte aligned in 64bits
ITypeInfo *type;
IInterface * transformExtra[NUM_PARALLEL_TRANSFORMS];
OwnedHqlExpr locationIndependent;
unsigned cachedCRC;
unsigned infoFlags;
node_operator op; // 2 bytes
unsigned short infoFlags2;
transformdepth_t transformDepth[NUM_PARALLEL_TRANSFORMS]; // 1 byte
HqlExprArray operands;
HqlExprArray attributes;
HqlExprCopyArray inScopeTables; // may need to rename, since use has changed.
HqlExprCopyArray newScopeTables;
protected:
//protected virtual members not in public interface
virtual void sethash();
protected:
inline bool constant() const { return (infoFlags2 & HEF2constant) != 0; }
inline bool functionOfGroupAggregate() const { return (infoFlags & HEFfunctionOfGroupAggregate) != 0; }
inline bool fullyBound() const { return (infoFlags & HEFunbound) == 0; }
inline bool pure() const { return (infoFlags & HEFimpure) == 0; }
bool isAggregate();
IHqlExpression * commonUpExpression();
void onAppendOperand(IHqlExpression & child, unsigned whichOperand);
inline void doAppendOperand(IHqlExpression & child)
{
unsigned which = operands.ordinality();
operands.append(child);
onAppendOperand(child, which);
}
IHqlExpression * queryExistingAttribute(_ATOM propName) const;
void initFlagsBeforeOperands();
void updateFlagsAfterOperands();
IHqlExpression * calcNormalizedSelector() const;
void mergeGathered(CopyArray &, CopyArray &);
IHqlExpression *fixScope(IHqlDataset *table);
CHqlExpression(node_operator op, ITypeInfo *type, ...);
CHqlExpression(node_operator op, ITypeInfo *type, HqlExprArray & ownedOperands);
virtual unsigned getCachedEclCRC();
void setInitialHash(unsigned typeHash);
void cacheChildrenTablesUsed(unsigned from, unsigned to);
void cacheInheritChildTablesUsed(IHqlExpression * ds, HqlExprCopyArray & childInScopeTables);
void cachePotentialTablesUsed();
void cacheTablesProcessChildScope();
void cacheTablesUsed();
void cacheTableUseage(IHqlExpression * expr);
void addAttributeOwn(IHqlExpression * attr);
public:
virtual void Link(void) const;
virtual bool Release(void) const;
static CHqlExpression *makeExpression(node_operator op, ITypeInfo *type, HqlExprArray &operands);
static CHqlExpression *makeExpression(node_operator op, ITypeInfo *type, ...);
virtual ~CHqlExpression();
virtual bool isExprClosed() const { return hashcode!=0; }
virtual bool isFullyBound() const { return fullyBound(); };
virtual _ATOM queryName() const { return NULL; }
virtual node_operator getOperator() const { return op; }
virtual IHqlDataset *queryDataset() { return NULL; };
virtual IHqlScope *queryScope();
virtual IHqlSimpleScope *querySimpleScope();
virtual IHqlExpression *queryProperty(_ATOM propName) const;
virtual IHqlExpression *queryAttribute(_ATOM propName);
virtual IHqlExpression *queryFunctionDefinition() const { return NULL; };
virtual IHqlExpression *queryExternalDefinition() const { return NULL; };
virtual unsigned getInfoFlags() const { return infoFlags; }
virtual unsigned getInfoFlags2() const { return infoFlags2; }
virtual bool isBoolean();
virtual bool isConstant();
virtual bool isDataset();
virtual bool isDatarow();
virtual bool isScope();
virtual bool isMacro();
virtual bool isType();
virtual bool isList();
virtual bool isField();
virtual bool isGroupAggregateFunction() { return functionOfGroupAggregate(); }
virtual bool isRecord();
virtual bool isAction();
virtual bool isTransform();
virtual bool isFunction();
virtual annotate_kind getAnnotationKind() const { return annotate_none; }
virtual IHqlAnnotation * queryAnnotation() { return NULL; }
virtual bool isPure() { return pure(); }
virtual bool isAttribute() const { return false; }
virtual IHqlExpression *queryNormalizedSelector(bool skipIndex) { return this; }
virtual int getStartLine() const { throwUnexpected(); }
virtual int getStartColumn() const { throwUnexpected(); }
virtual IPropertyTree * getDocumentation() const { return NULL; }
virtual ITypeInfo *queryType() const;
virtual ITypeInfo *getType();
virtual IHqlExpression *queryBody(bool singleLevel = false) { return this; }
virtual IValue *queryValue() const { return NULL; }
virtual IInterface *queryUnknownExtra() { return NULL; }
virtual unsigned __int64 querySequenceExtra() { return 0; }
virtual StringBuffer &toString(StringBuffer &ret);
virtual IHqlExpression *queryChild(unsigned idx) const;
virtual unsigned numChildren() const ;
virtual bool isIndependentOfScope();
virtual void gatherTablesUsed(HqlExprCopyArray * newScope, HqlExprCopyArray * inScope);
virtual ITypeInfo *queryRecordType();
virtual IHqlExpression *queryRecord();
virtual IHqlExpression *clone(HqlExprArray &newkids);
virtual IHqlExpression * cloneAnnotation(IHqlExpression * body) { return LINK(body); }
virtual IHqlExpression * cloneAllAnnotations(IHqlExpression * body) { return LINK(body); }
virtual void unwindList(HqlExprArray &dst, node_operator);
virtual _ATOM queryFullModuleName() const { return NULL; }
virtual ISourcePath * querySourcePath() const { return NULL; }
virtual IInterface * queryTransformExtra();
virtual void setTransformExtra(IInterface * x);
virtual void setTransformExtraOwned(IInterface * x);
virtual void setTransformExtraUnlinked(IInterface * x);
virtual IHqlExpression *closeExpr(); // MORE - should be in expressionBuilder interface!
virtual IHqlExpression *addOperand(IHqlExpression *); // MORE - should be in expressionBuilder interface!
virtual StringBuffer& getTextBuf(StringBuffer& buf) { assertex(false); return buf; }
virtual IFileContents * queryDefinitionText() const { return NULL; }
virtual bool isExported() const { return false; }
virtual IHqlExpression * queryAnnotationParameter(unsigned i) const { return NULL; }
virtual void addObserver(IObserver & observer);
virtual void removeObserver(IObserver & observer);
virtual unsigned getHash() const;
virtual bool equals(const IHqlExpression & other) const;
virtual void beforeDispose(); // called before item is freed so whole object still valid
virtual unsigned getSymbolFlags() const;
void setLocationIndependent(IHqlExpression * value);
inline IHqlExpression * queryLocationIndependent()
{
if (!(infoFlags & HEFhasunadorned))
return NULL;
if (locationIndependent)
return locationIndependent;
return this;
}
public:
inline void doSetTransformExtra(IInterface * x, unsigned depthMask);
inline void resetTransformExtra(IInterface * _extra, unsigned depth);
};
class CHqlNamedExpression : public CHqlExpression
{
friend HQL_API IHqlExpression *createOpenNamedValue(node_operator op, ITypeInfo *type, _ATOM name);
friend HQL_API IHqlExpression *createNamedValue(node_operator op, ITypeInfo *type, _ATOM name, HqlExprArray & args);
protected:
_ATOM name;
protected:
CHqlNamedExpression(node_operator _op, ITypeInfo *_type, _ATOM _name, ...);
CHqlNamedExpression(node_operator _op, ITypeInfo *_type, _ATOM _name, HqlExprArray & _ownedOperands);
virtual void sethash();
virtual bool equals(const IHqlExpression & other) const;
public:
virtual IHqlExpression *clone(HqlExprArray &newkids);
virtual _ATOM queryName() const { return name; }
};
class CHqlSelectExpression : public CHqlExpression
{
public:
CHqlSelectExpression(IHqlExpression * left, IHqlExpression * right, IHqlExpression * attr);
CHqlSelectExpression(HqlExprArray & ownedOperands);
virtual IHqlExpression *clone(HqlExprArray &newkids);
virtual IHqlExpression *queryNormalizedSelector(bool skipIndex);
protected:
HqlExprAttr normalized;
};
class CFileContents : public CInterface, implements IFileContents
{
private:
Linked<IFile> file;
StringAttr fileContents;
Linked<ISourcePath> sourcePath;
bool delayedRead;
public:
CFileContents(IFile * _file, ISourcePath * _sourcePath);
CFileContents(const char *query, ISourcePath * _sourcePath);
CFileContents(unsigned len, const char *query, ISourcePath * _sourcePath);
IMPLEMENT_IINTERFACE;
virtual IFile * queryFile() { return file; }
virtual ISourcePath * querySourcePath() { return sourcePath; }
virtual const char *getText()
{
ensureLoaded();
return fileContents.sget();
}
virtual size32_t length()
{
ensureLoaded();
return fileContents.length();
}
private:
bool preloadFromFile();
void ensureLoaded();
void ensureUtf8(MemoryBuffer & contents);
};
class HQL_API CHqlAnnotation: public CHqlExpression
{
protected:
IHqlExpression *body;
protected:
virtual void sethash();
public:
CHqlAnnotation(IHqlExpression * _body);
~CHqlAnnotation();
//Following methods are implemented in CHqlExpression
// virtual node_operator getOperator() const;
// virtual IInterface* queryTransformExtra();
// virtual void setTransformExtra(IInterface *);
// virtual void setTransformExtraOwned(IInterface *);
// virtual void setTransformExtraUnlinked(IInterface *);
// virtual IHqlExpression *closeExpr();
// virtual bool isExprClosed() const;
// virtual void addObserver(IObserver & observer);
// virtual void removeObserver(IObserver & observer);
// virtual unsigned getHash() const;
// virtual ITypeInfo *queryType() const;
// virtual ITypeInfo *getType();
// virtual void unwindList(HqlExprArray &dst, node_operator);
// virtual bool isAggregate();
// virtual IHqlDataset *queryDeepestTable();
//Using methods in CHqlExpression should realy be inline in IHqlExpression, all based on type
// virtual bool isBoolean();
// virtual bool isDataset();
// virtual bool isDatarow();
// virtual bool isRecord();
// virtual bool isAction();
// virtual bool isTransform();
// virtual bool isList();
// virtual bool isFunction();
// virtual ITypeInfo *queryRecordType();
// virtual IHqlExpression *queryRecord();
// virtual bool isField();
//Following are redirected to body
virtual _ATOM queryName() const;
virtual bool isScope();
virtual bool isType();
virtual bool isConstant();
virtual bool isMacro();
virtual bool isGroupAggregateFunction();
virtual annotate_kind getAnnotationKind() const = 0;
virtual bool isPure();
virtual bool isAttribute() const;
virtual unsigned getInfoFlags() const;
virtual unsigned getInfoFlags2() const;
virtual int getStartLine() const;
virtual int getStartColumn() const;
virtual IPropertyTree * getDocumentation() const;
virtual StringBuffer &toString(StringBuffer &ret);
virtual IHqlExpression *queryChild(unsigned idx) const;
virtual unsigned numChildren() const;
virtual bool isIndependentOfScope();
virtual void gatherTablesUsed(HqlExprCopyArray * newScope, HqlExprCopyArray * inScope);
virtual IValue *queryValue() const;
virtual IInterface *queryUnknownExtra();
virtual unsigned __int64 querySequenceExtra();
virtual IHqlDataset *queryDataset();
virtual IHqlScope *queryScope();
virtual IHqlSimpleScope *querySimpleScope();
virtual IHqlExpression *queryFunctionDefinition() const;
virtual IHqlExpression *queryExternalDefinition() const;
virtual IHqlExpression *queryNormalizedSelector(bool skipIndex=false);
virtual IHqlExpression *queryProperty(_ATOM propName) const;
virtual IHqlExpression *queryAttribute(_ATOM propName);
virtual IHqlExpression * clone(HqlExprArray &);
virtual IHqlExpression * cloneAnnotation(IHqlExpression * body) = 0;
virtual IHqlExpression * cloneAllAnnotations(IHqlExpression * body);
virtual _ATOM queryFullModuleName() const;
virtual bool isFullyBound() const;
virtual IHqlExpression *addOperand(IHqlExpression *);
virtual StringBuffer& getTextBuf(StringBuffer& buf);
virtual IFileContents * queryDefinitionText() const;
virtual bool isExported() const;
virtual unsigned getSymbolFlags() const;
virtual unsigned getCachedEclCRC();
//Actually implemented by this class
virtual bool equals(const IHqlExpression & other) const;
virtual IHqlExpression *queryBody(bool singleLevel = false);
virtual IHqlExpression * queryAnnotationParameter(unsigned i) const;
};
class HQL_API CHqlSymbolAnnotation : public CHqlAnnotation, public IHqlNamedAnnotation
{
public:
IMPLEMENT_IINTERFACE_USING(CHqlAnnotation)
virtual _ATOM queryName() const { return name; }
virtual _ATOM queryFullModuleName() const { return module; }
virtual IHqlExpression *queryFunctionDefinition() const;
virtual unsigned getSymbolFlags() const;
virtual annotate_kind getAnnotationKind() const { return annotate_symbol; }
virtual IHqlAnnotation * queryAnnotation() { return this; }
virtual IHqlExpression * cloneAnnotation(IHqlExpression * body);
virtual bool equals(const IHqlExpression & other) const;
//interface IHqlNamedAnnotation
virtual IHqlExpression * queryExpression();
virtual bool isExported() const { return (symbolFlags&ob_exported)!=0; };
virtual bool isShared() const { return (symbolFlags&ob_shared)!=0; };
virtual bool isPublic() const { return (symbolFlags&(ob_shared|ob_exported))!=0; };
virtual void setRepositoryFlags(unsigned _flags) { symbolFlags |= (_flags & ob_registryflags); }
protected:
CHqlSymbolAnnotation(_ATOM _name, _ATOM _module, IHqlExpression *_expr, IHqlExpression *_funcdef, unsigned _obFlags);
~CHqlSymbolAnnotation();
virtual void sethash();
protected:
_ATOM name;
_ATOM module;
IHqlExpression *funcdef;
unsigned symbolFlags;
};
class HQL_API CHqlSimpleSymbol : public CHqlSymbolAnnotation
{
public:
static IHqlExpression * makeSymbol(_ATOM _name, _ATOM _module, IHqlExpression *_expr, IHqlExpression *_funcdef, unsigned _obFlags);
//interface IHqlNamedAnnotation
virtual IFileContents * getBodyContents() { return NULL; }
virtual IHqlExpression * cloneSymbol(_ATOM optname, IHqlExpression * optnewbody, IHqlExpression * optnewfuncdef, HqlExprArray * optargs);
virtual int getStartLine() const { return 0; }
virtual int getStartColumn() const { return 0; }
virtual int getStartPos() const { return 0; }
virtual int getBodyPos() const { return 0; }
virtual int getEndPos() const { return 0; }
protected:
CHqlSimpleSymbol(_ATOM _name, _ATOM _module, IHqlExpression *_expr, IHqlExpression *_funcdef, unsigned _obFlags);
};
class HQL_API CHqlNamedSymbol: public CHqlSymbolAnnotation
{
public:
static CHqlNamedSymbol *makeSymbol(_ATOM _name, _ATOM _module, IHqlExpression *_expr, bool _exported, bool _shared, unsigned _flags);
static CHqlNamedSymbol *makeSymbol(_ATOM _name, _ATOM _module, IHqlExpression *_expr, IHqlExpression *_funcdef, bool _exported, bool _shared, unsigned _flags, IFileContents *_text, int lineno, int column, int _startpos, int _bodypos, int _endpos);
virtual ISourcePath * querySourcePath() const;
virtual StringBuffer& getTextBuf(StringBuffer& buf) { return buf.append(text->length(),text->getText()); }
virtual IFileContents * queryDefinitionText() const;
virtual int getStartLine() const { return startLine; }
virtual int getStartColumn() const { return startColumn; }
virtual int getStartPos() const { return startpos; }
virtual int getBodyPos() const { return bodypos; }
virtual int getEndPos() const
{
if ((endpos == 0) && text)
return text->length();
return endpos;
}
//interface IHqlNamedAnnotation
virtual IFileContents * getBodyContents();
virtual IHqlExpression * cloneSymbol(_ATOM optname, IHqlExpression * optnewbody, IHqlExpression * optnewfuncdef, HqlExprArray * optargs);
protected:
CHqlNamedSymbol(_ATOM _name, _ATOM _module, IHqlExpression *_expr, bool _exported, bool _shared, unsigned _obFlags);
CHqlNamedSymbol(_ATOM _name, _ATOM _module, IHqlExpression *_expr, IHqlExpression *_funcdef, bool _exported, bool _shared, unsigned _flags, IFileContents *_text, int _startLine, int _startColumn, int _startpos, int _bodypos, int _endpos);
protected:
Linked<IFileContents> text;
int startpos;
int bodypos;
int endpos;
int startLine;
unsigned short startColumn;
};
class HQL_API CHqlAnnotationWithOperands: public CHqlAnnotation
{
public:
virtual bool equals(const IHqlExpression & other) const;
protected:
CHqlAnnotationWithOperands(IHqlExpression * _expr, HqlExprArray & _args);
virtual void sethash();
};
class HQL_API CHqlMetaAnnotation: public CHqlAnnotationWithOperands
{
public:
static IHqlExpression * createAnnotation(IHqlExpression * _ownedBody, HqlExprArray & _args);
virtual annotate_kind getAnnotationKind() const { return annotate_meta; }
virtual IHqlExpression * cloneAnnotation(IHqlExpression * body);
protected:
CHqlMetaAnnotation(IHqlExpression * _expr, HqlExprArray & _args);
};
class HQL_API CHqlParseMetaAnnotation: public CHqlAnnotationWithOperands
{
public:
static IHqlExpression * createAnnotation(IHqlExpression * _ownedBody, HqlExprArray & _args);
virtual annotate_kind getAnnotationKind() const { return annotate_parsemeta; }
virtual IHqlExpression * cloneAnnotation(IHqlExpression * body);
protected:
CHqlParseMetaAnnotation(IHqlExpression * _expr, HqlExprArray & _args);
};
class HQL_API CHqlLocationAnnotation: public CHqlAnnotation
{
public:
static IHqlExpression * createLocationAnnotation(IHqlExpression * _ownedBody, ISourcePath * _sourcePath, int _lineno, int _column);
virtual annotate_kind getAnnotationKind() const { return annotate_location; }
virtual IHqlExpression * cloneAnnotation(IHqlExpression * body);
virtual bool equals(const IHqlExpression & other) const;
virtual ISourcePath * querySourcePath() const { return sourcePath; }
virtual int getStartLine() const { return lineno; }
virtual int getStartColumn() const { return column; }
protected:
CHqlLocationAnnotation(IHqlExpression * _expr, ISourcePath * _sourcePath, int _lineno, int _column);
virtual void sethash();
protected:
Linked<ISourcePath> sourcePath;
int lineno;
int column;
};
class HQL_API CHqlAnnotationExtraBase: public CHqlAnnotation
{
public:
virtual bool equals(const IHqlExpression & other) const;
protected:
CHqlAnnotationExtraBase(IHqlExpression * _expr, IInterface * _ownedExtra);
virtual void sethash();
protected:
Owned<IInterface> extra;
};
class HQL_API CHqlWarningAnnotation: public CHqlAnnotationExtraBase
{
public:
static IHqlExpression * createWarningAnnotation(IHqlExpression * _ownedBody, IECLError * _ownedWarning);
virtual annotate_kind getAnnotationKind() const { return annotate_warning; }
virtual IHqlExpression * cloneAnnotation(IHqlExpression * body);
inline IECLError * queryWarning() const { return static_cast<IECLError *>(extra.get()); }
protected:
CHqlWarningAnnotation(IHqlExpression * _expr, IECLError * _ownedWarning);
};
class HQL_API CHqlJavadocAnnotation: public CHqlAnnotationExtraBase
{
public:
static IHqlExpression * createJavadocAnnotation(IHqlExpression * _ownedBody, IPropertyTree * _ownedWarning);
virtual annotate_kind getAnnotationKind() const { return annotate_javadoc; }
virtual IHqlExpression * cloneAnnotation(IHqlExpression * body);
virtual IPropertyTree * getDocumentation() const { return LINK(queryDocumentation()); }
inline IPropertyTree * queryDocumentation() const { return static_cast<IPropertyTree *>(extra.get()); }
protected:
CHqlJavadocAnnotation(IHqlExpression * _expr, IPropertyTree * _ownedJavadoc);
};
class CHqlField: public CHqlExpression
{
private:
_ATOM name;
virtual void sethash();
virtual bool equals(const IHqlExpression & other) const;
void onCreateField();
public:
CHqlField(_ATOM, ITypeInfo *type, IHqlExpression *defaultValue);
CHqlField(_ATOM _name, ITypeInfo *_type, HqlExprArray &_ownedOperands);
// CHqlField(_ATOM _name, ITypeInfo *_type, IHqlExpression *_defValue, IHqlExpression *_attrs);
virtual StringBuffer &toString(StringBuffer &ret);
// virtual StringBuffer &toSQL(StringBuffer &, bool paren, IHqlDataset *scope, bool useAliases, node_operator op = no_none);
virtual IHqlExpression *clone(HqlExprArray &newkids);
virtual StringBuffer &printAliases(StringBuffer &s, unsigned, bool &) { return s; }
virtual _ATOM queryName() const { return name; }
};
class CHqlRow: public CHqlExpression
{
CHqlRow(node_operator op, ITypeInfo * type, HqlExprArray & _operands);
HqlExprAttr normalized;
public:
static CHqlRow *makeRow(node_operator op, ITypeInfo * type, HqlExprArray & _operands);
virtual IHqlExpression *clone(HqlExprArray &newkids);
virtual IHqlSimpleScope *querySimpleScope();
virtual IHqlDataset *queryDataset();
virtual _ATOM queryName() const;
virtual IHqlExpression *queryNormalizedSelector(bool skipIndex);
};
class CHqlExternal: public CHqlExpression
{
_ATOM name;
CHqlExternal(_ATOM name, ITypeInfo *, HqlExprArray &_ownedOperands);
virtual bool equals(const IHqlExpression & other) const;
public:
static CHqlExternal *makeExternalReference(_ATOM name, ITypeInfo *, HqlExprArray &_ownedOperands);
virtual _ATOM queryName() const { return name; }
};
class CHqlExternalCall: public CHqlExpression
{
protected:
OwnedHqlExpr funcdef;
CHqlExternalCall(IHqlExpression * _funcdef, ITypeInfo * type, HqlExprArray &parms);
virtual _ATOM queryName() const { return funcdef->queryName(); }
virtual void sethash();
virtual bool equals(const IHqlExpression & other) const;
virtual IHqlExpression *clone(HqlExprArray &newkids);
virtual IHqlExpression *queryExternalDefinition() const;
public:
static IHqlExpression *makeExternalCall(IHqlExpression * _funcdef, ITypeInfo * type, HqlExprArray &operands);
};
class CHqlExternalDatasetCall: public CHqlExternalCall, implements IHqlDataset
{
friend class CHqlExternalCall;
CHqlExternalDatasetCall(IHqlExpression * _funcdef, ITypeInfo * type, HqlExprArray &_ownedOperands) : CHqlExternalCall(_funcdef, type, _ownedOperands) {}
IMPLEMENT_IINTERFACE_USING(CHqlExternalCall)
virtual IHqlExpression *clone(HqlExprArray &newkids);
virtual IHqlDataset *queryDataset() { return this; }
//interface IHqlDataset
virtual IHqlDataset* queryTable() { return this; }
virtual IHqlSimpleScope *querySimpleScope() { return queryRecord()->querySimpleScope(); }
virtual IHqlDataset * queryRootTable() { return this; }
virtual IHqlExpression * queryContainer() { return NULL; }
virtual bool isAggregate() { return false; }
};
#ifdef THREAD_SAFE_SYMBOLS
class SymbolTable
{
public:
inline void setValue(_ATOM name, IHqlExpression * value)
{
CriticalBlock block(cs);
map.setValue(name, value);
}
inline bool contain(_ATOM name) const
{
CriticalBlock block(cs);
IHqlExpression * ret = map.getValue(name);
return (ret != NULL);
}
inline IHqlExpression * getLinkedValue(_ATOM name) const
{
CriticalBlock block(cs);
IHqlExpression * ret = map.getValue(name);
if (ret)
ret->Link();
return ret;
}
inline IHqlExpression * mapToValue(IMapping * mapping) const {
return map.mapToValue(mapping);
}
inline void kill()
{
CriticalBlock block(cs);
map.kill();
}
inline void remove(_ATOM name)
{
CriticalBlock block(cs);
map.remove(name);
}
inline HashTable & lock()
{
cs.enter();
return map;
}
inline void unlock()
{
cs.leave();
}
inline unsigned count() const
{
CriticalBlock block(cs);
return map.count();
}
protected:
MapXToMyClass<_ATOM, _ATOM, IHqlExpression> map;
mutable CriticalSection cs;
};
class SymbolTableIterator : public HashIterator
{
public:
SymbolTableIterator(SymbolTable & _table) : HashIterator(_table.lock()), table(_table)
{
}
~SymbolTableIterator()
{
table.unlock();
}
protected:
SymbolTable & table;
};
#else
class SymbolTable : public MapXToMyClass<_ATOM, _ATOM, IHqlExpression>
{
public:
inline IHqlExpression * getLinkedValue(_ATOM name) const
{
IHqlExpression * ret = getValue(name);
if (ret)
ret->Link();
return ret;
}
};
typedef HashIterator SymbolTableIterator;
#endif
inline IHqlExpression * lookupSymbol(SymbolTable & symbols, _ATOM searchName, bool sharedOK)
{
OwnedHqlExpr ret = symbols.getLinkedValue(searchName);
if (!ret)
return NULL;
if (!(ret->isExported() || sharedOK))
return NULL;
return ret.getClear();
}
typedef class MapXToMyClassViaBase<_ATOM, _ATOM, CHqlField, IHqlExpression> FieldTable;
typedef class MapXToMyClassViaBase<_ATOM, _ATOM, IFileContents, IFileContents> FileContentsTable;
class CHqlDelayedCall: public CHqlExpression
{
OwnedHqlExpr param;
protected:
CHqlDelayedCall(IHqlExpression * _param, ITypeInfo * type, HqlExprArray &parms);
virtual _ATOM queryName() const { return param->queryName(); }
virtual void sethash();
virtual bool equals(const IHqlExpression & other) const;
virtual IHqlExpression *clone(HqlExprArray &newkids);
virtual IHqlExpression *queryFunctionDefinition() const { return param; };
public:
static IHqlExpression *makeDelayedCall(IHqlExpression * _param, HqlExprArray &operands);
};
class CHqlDelayedDatasetCall: public CHqlDelayedCall, implements IHqlDataset
{
friend class CHqlDelayedCall;
CHqlDelayedDatasetCall(IHqlExpression * _param, ITypeInfo * type, HqlExprArray &parms) : CHqlDelayedCall(_param, type, parms) {}
IMPLEMENT_IINTERFACE_USING(CHqlDelayedCall)
virtual IHqlDataset *queryDataset() { return this; }
//interface IHqlDataset
virtual IHqlDataset* queryTable() { return this; }
virtual IHqlSimpleScope *querySimpleScope() { return queryRecord()->querySimpleScope(); }
virtual IHqlDataset * queryRootTable() { return this; }
virtual IHqlExpression * queryContainer() { return NULL; }
virtual bool isAggregate() { return false; }
};
class CHqlDelayedScopeCall: public CHqlDelayedCall, implements IHqlScope
{
public:
friend class CHqlDelayedCall;
CHqlDelayedScopeCall(IHqlExpression * _param, ITypeInfo * type, HqlExprArray &parms);
IMPLEMENT_IINTERFACE_USING(CHqlDelayedCall)
virtual void defineSymbol(_ATOM name, _ATOM moduleName, IHqlExpression *value, bool isExported, bool isShared, unsigned flags, IFileContents *fc, int lineno, int column, int _startpos, int _bodypos, int _endpos) { throwUnexpected(); }
virtual void defineSymbol(_ATOM name, _ATOM moduleName, IHqlExpression *value, bool isExported, bool isShared, unsigned flags) { throwUnexpected(); }
virtual void defineSymbol(IHqlExpression * expr) { throwUnexpected(); }
virtual void removeSymbol(_ATOM name) { throwUnexpected(); }
virtual IHqlExpression *lookupSymbol(_ATOM searchName, unsigned lookupFlags, HqlLookupContext & ctx);
virtual void getSymbols(HqlExprArray& exprs) const;
virtual _ATOM queryName() const;
virtual const char * queryFullName() const { throwUnexpected(); }
virtual ISourcePath * querySourcePath() const { throwUnexpected(); }
virtual bool hasBaseClass(IHqlExpression * searchBase);
virtual void ensureSymbolsDefined(HqlLookupContext & ctx) { }
virtual bool isImplicit() const { return false; }
virtual bool isPlugin() const { return false; }
virtual int getPropInt(_ATOM a, int def) const { return def; }
virtual bool getProp(_ATOM a, StringBuffer &ret) const { return false; }
virtual IHqlScope * clone(HqlExprArray & children, HqlExprArray & symbols) { throwUnexpected(); }
virtual IHqlScope * queryConcreteScope() { return this; }
virtual IHqlScope * queryResolvedScope(HqlLookupContext * context) { return this; }
virtual IHqlExpression * queryExpression() { return this; }
virtual IHqlScope * queryScope() { return this; }
protected:
IHqlScope * typeScope;
};
//This is abstract. Either CHqlRemoteScope or CHqlLocalScope should be used......
class HQL_API CHqlScope : public CHqlExpression, implements IHqlScope, implements ITypeInfo
{
protected:
Owned<IFileContents> text;
_ATOM name;
StringAttr fullName; //Fully qualified name of this nested module E.g.: PARENT.CHILD.GRANDCHILD
SymbolTable symbols;
IHqlDataset *lookupDataset(_ATOM name);
virtual bool equals(const IHqlExpression & other) const;
public:
CHqlScope(node_operator _op, _ATOM _name, const char * _fullName);
CHqlScope(node_operator _op);
CHqlScope(IHqlScope* scope);
~CHqlScope();
IMPLEMENT_IINTERFACE_USING(CHqlExpression)
IHqlScope * cloneAndClose(HqlExprArray & children, HqlExprArray & symbols);
//interface IHqlExpression
virtual IHqlScope *queryScope() { return this; };
virtual IHqlExpression *clone(HqlExprArray &newkids);
virtual void sethash();
//interface IHqlScope
virtual IHqlExpression * queryExpression() { return this; }
virtual void defineSymbol(_ATOM name, _ATOM moduleName, IHqlExpression *value, bool isPublic, bool isShared, unsigned symbolFlags, IFileContents *, int lineno, int column, int _startpos, int _bodypos, int _endpos);
virtual void defineSymbol(_ATOM name, _ATOM moduleName, IHqlExpression *value, bool exported, bool shared, unsigned symbolFlags);
virtual void defineSymbol(IHqlExpression * expr);
virtual void removeSymbol(_ATOM name);
virtual IHqlExpression *lookupSymbol(_ATOM searchName, unsigned lookupFlags, HqlLookupContext & ctx);
virtual _ATOM queryName() const {return name;}
virtual const char * queryFullName() const { return fullName; }
virtual ISourcePath * querySourcePath() const { return text ? text->querySourcePath() : NULL; }
virtual void ensureSymbolsDefined(HqlLookupContext & ctx) { }
virtual bool isImplicit() const { return false; }
virtual bool isPlugin() const { return false; }
virtual int getPropInt(_ATOM, int) const;
virtual bool getProp(_ATOM, StringBuffer &) const;
virtual void getSymbols(HqlExprArray& exprs) const;
virtual IHqlScope * clone(HqlExprArray & children, HqlExprArray & symbols) { throwUnexpected(); }
virtual bool hasBaseClass(IHqlExpression * searchBase);
virtual IHqlScope * queryConcreteScope() { return this; }
virtual IHqlScope * queryResolvedScope(HqlLookupContext * context) { return this; }
virtual IFileContents * queryDefinitionText() const { return text; }
//ITypeInfo
virtual type_t getTypeCode() const { return type_scope; }
virtual size32_t getSize() { return 0; }
virtual unsigned getAlignment() { return 1; }
virtual unsigned getPrecision() { return 0; }
virtual unsigned getBitSize() { return 0; }
virtual unsigned getStringLen() { return 0; }
virtual unsigned getDigits() { return 0; }
virtual IValue * castFrom(bool isSignedValue, __int64 value) { return NULL; }
virtual IValue * castFrom(double value) { return NULL; }
virtual IValue * castFrom(size32_t len, const char * text) { return NULL; }
virtual IValue * castFrom(size32_t len, const UChar * text) { return NULL; }
virtual StringBuffer &getECLType(StringBuffer & out) { return out.append("MODULE"); }
virtual StringBuffer &getDescriptiveType(StringBuffer & out) { return out.append("MODULE"); }
virtual const char *queryTypeName() { return name->str(); }
virtual unsigned getCardinality() { return 0; }
virtual bool isInteger() { return false; }
virtual bool isReference() { return false; }
virtual bool isScalar() { return false; }
virtual bool isSigned() { return false; }
virtual bool isSwappedEndian() { return false; }
virtual ICharsetInfo * queryCharset() { return NULL; }
virtual ICollationInfo * queryCollation() { return NULL; }
virtual _ATOM queryLocale() { return NULL; }
// virtual _ATOM queryName() const { return name; }
virtual ITypeInfo * queryChildType() { return NULL; }
virtual IInterface * queryDistributeInfo() { return NULL; }
virtual IInterface * queryGroupInfo() { return NULL; }
virtual IInterface * queryGlobalSortInfo() { return NULL; }
virtual IInterface * queryLocalUngroupedSortInfo() { return NULL; }
virtual IInterface * queryGroupSortInfo() { return NULL; }
virtual ITypeInfo * queryPromotedType() { return this; }
virtual ITypeInfo * queryTypeBase() { return this; }
virtual typemod_t queryModifier() { return typemod_none; }
virtual IInterface * queryModifierExtra() { return NULL; }
virtual StringBuffer & appendStringFromMem(StringBuffer & out, const void * data) {assertex(!"tbd"); return out; }
virtual unsigned getCrc();
virtual bool assignableFrom(ITypeInfo * source);
virtual void serialize(MemoryBuffer &) { UNIMPLEMENTED; }
virtual void deserialize(MemoryBuffer &) { UNIMPLEMENTED; }
protected:
void throwRecursiveError(_ATOM name);
};
class HQL_API CHqlRemoteScope : public CHqlScope, implements IHqlRemoteScope
{
protected:
IEclRepositoryCallback * ownerRepository;
IProperties* props;
Owned<IHqlScope> resolved;
Linked<IEclSource> eclSource;
CriticalSection generalCS;
bool loadedAllSymbols;
protected:
void preloadSymbols(HqlLookupContext & ctx, bool forceAll);
void doParseScopeText(HqlLookupContext & ctx);
virtual bool equals(const IHqlExpression & other) const;
virtual void repositoryLoadModule(HqlLookupContext & ctx, bool forceAll);
virtual IHqlExpression * repositoryLoadSymbol(_ATOM attrName);
public:
CHqlRemoteScope(_ATOM _name, const char * _fullName, IEclRepositoryCallback *_repository, IProperties* _props, IFileContents * _text, bool _lazy, IEclSource * _eclSource);
~CHqlRemoteScope();
IMPLEMENT_IINTERFACE_USING(CHqlScope)
virtual IHqlScope * queryScope() { return this; } // remove ambiguous call
//interface IHqlExpression
virtual IHqlExpression *clone(HqlExprArray &newkids);
virtual void sethash();
//interface IHqlScope
virtual IHqlExpression *lookupSymbol(_ATOM searchName, unsigned lookupFlags, HqlLookupContext & ctx);
virtual void ensureSymbolsDefined(HqlLookupContext & ctx);
virtual void defineSymbol(IHqlExpression * expr);
using CHqlScope::defineSymbol;
virtual IFileContents * queryDefinitionText() const;
virtual void getSymbols(HqlExprArray& exprs) const;
virtual bool isImplicit() const;
virtual bool isPlugin() const;
virtual int getPropInt(_ATOM, int) const;
virtual bool getProp(_ATOM, StringBuffer &) const;
virtual void setProp(_ATOM, const char *);
virtual void setProp(_ATOM, int);
virtual IEclSource * queryEclSource() const { return eclSource; }
};
class HQL_API CHqlLocalScope : public CHqlScope
{
protected:
virtual bool equals(const IHqlExpression & other) const;
public:
CHqlLocalScope(node_operator _op, _ATOM _name, const char * _fullName);
CHqlLocalScope(IHqlScope* scope);
//interface IHqlExpression
virtual IHqlExpression *clone(HqlExprArray &newkids);
virtual void sethash();
//interface IHqlScope
virtual IHqlScope * clone(HqlExprArray & children, HqlExprArray & symbols);
};
class HQL_API CHqlVirtualScope : public CHqlScope
{
protected:
Owned<IHqlScope> concrete;
bool isAbstract;