forked from hpcc-systems/HPCC-Platform
/
hqlexpr.hpp
1817 lines (1638 loc) · 84.3 KB
/
hqlexpr.hpp
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_INCL
#define HQLEXPR_INCL
#ifdef _DEBUG
#define ENABLE_ENUM_TYPE
#endif
#ifndef _DEBUG
// #define USE_TBB
#endif
//#define USE_SELSEQ_UID
//#define ENSURE_SELSEQ_UID
//Currently nearly all functional attributes are expanded when the call is parsed.
//This is potentially inefficient, and makes it hard to dynamically control whether functions are expanded in line or generated out of line.
//Expansion in place probably occupies 50% of the parse time processing, but parsing is typically 20% of over-all time - significant but not disastrous.
//There may be situations (syntax check, gather dependencies) where the savings are significant enough to allow it to work for parse - even if it doesn't work for generation.
//
//The following constant changes that functionality so expansion is delayed until before code generation.
//It nearly works - but there are still some examples which have problems - primarily libraries, old parameter syntax, enums and other issues.
//There may also problems with queryRecord() which needs to really be replaced with recordof(x), especially if "templates" are delayed expanded.
//To work properly it may require many of the transformations in hqlgram2.cpp to be moved to after the expansion. (E.g., BUILD)
//#define DELAY_CALL_EXPANSION
#ifdef DELAY_CALL_EXPANSION
#define DEFAULT_EXPAND_CALL false
#else
#define DEFAULT_EXPAND_CALL true
#endif
#define GATHER_HIDDEN_SELECTORS
#define XPATH_CONTENTS_TEXT "<>"
//This should be defined, but HOLe does not cope with variable length stored strings. Need to wait until HOLe is integrated into thor.
//#define STORED_CAN_CHANGE_LENGTH
#include "hql.hpp"
#include "jhash.hpp"
#include "jprop.hpp"
#include "jptree.hpp"
#include "defvalue.hpp"
interface IXmlScope;
interface IHqlScope;
interface IHqlSimpleScope;
interface IHqlDataset;
interface IHqlExpression;
extern HQL_API ISourcePath * createSourcePath(const char * name);
extern HQL_API ISourcePath * createSourcePath(unsigned len, const char * name);
class HqlGramCtx; // opaque, but still not very nice
class HQL_API HqlExprArray : public IArrayOf<IHqlExpression>
{
public:
void swapWith(HqlExprArray & other);
bool containsBody(IHqlExpression & expr);
};
class HQL_API UniqueSequenceCounter
{
public:
inline UniqueSequenceCounter() { value = 0; }
inline unique_id_t next()
{
SpinBlock block(lock);
return ++value;
}
protected:
unique_id_t value;
SpinLock lock;
};
typedef ICopyArrayOf<IHqlExpression> HqlExprCopyArray;
typedef class MapXToMyClass<_ATOM, _ATOM, _ATOM> KeywordMap;
typedef ICopyArrayOf<IAtom> AtomArray;
const unsigned UnadornedParameterIndex = (unsigned)-1;
#define CHOOSEN_ALL_LIMIT I64C(0x7FFFFFFFFFFFFFFF)
// Allow of the following are private, and should only be accessed by the associated helper functions.
//NB: If this is changed, remember to look at whether no_select an noinherit need modifying.
enum
{
// House keeping information on a per node basis
HEF____unused0____ = 0x00000001,
HEFobserved = 0x00000002,
HEFgatheredNew = 0x00000004,
HEFhasunadorned = 0x00000008,
HEFhousekeeping = (HEFhasunadorned|HEFobserved|HEFgatheredNew),
// generally applicable start from the top down
HEFunbound = 0x00000010,
HEFinternalVirtual = 0x00000020,
HEFcontainsDatasetAliasLocally= 0x00000040,
HEF____unused2____ = 0x00000080,
HEF____unused3____ = 0x00000100,
HEFfunctionOfGroupAggregate = 0x00000200,
HEFvolatile = 0x00000400, // value changes each time called - e.g., random()
HEFaction = 0x00000800, // an action, or something that can have a side-effect
HEFtransformSkips = 0x00001000,
HEFthrowscalar = 0x00002000, // scalar/action that can throw an exception
HEFthrowds = 0x00004000, // dataset that can throw an exception
HEFoldthrows = 0x00008000, // old throws flag, which I should remove asap
// code generator specific start from the bottom up.
//NB: update the select
HEFcontainsThisNode = 0x00010000,
HEFonFailDependent = 0x00020000,
HEFcontainsActiveDataset = 0x00040000,
HEFcontainsActiveNonSelector= 0x00080000,
HEFcontainsDataset = 0x00100000,
HEFtranslated = 0x00200000,
HEFgraphDependent = 0x00400000,
HEFcontainsNlpText = 0x00800000,
HEFcontainsXmlText = 0x01000000,
HEFtransformDependent = 0x02000000, // depends in some way on the containing transform
// self, fail and counter. Latter should be treated like a dataset I suspect., could have separate flags for others.
HEFcontainsSkip = 0x04000000,
HEFcontainsCounter = 0x08000000,
HEFassertkeyed = 0x10000000,
HEFcontextDependentException= 0x20000000, // A context dependent item that doesn't fit into any other category - for use as a last resort!
HEFcontainsAlias = 0x40000000,
HEFcontainsAliasLocally = 0x80000000,
//Combinations used for processing elsewhere:
//Don't ever inherit the following...
HEFalwaysInherit = HEFunbound|HEFinternalVirtual,
HEFassigninheritFlags = ~(HEFhousekeeping|HEFalwaysInherit), // An assign inherits all but this list from the rhs value
// HEFcontextDependent = (HEFgraphDependent|HEFcontainsNlpText|HEFcontainsXmlText|HEFcontainsSkip|HEFcontainsCounter|HEFtransformDependent|HEFtranslated|HEFonFailDependent|HEFcontextDependentException|HEFthrowscalar|HEFthrowds),
HEFcontextDependent = (HEFgraphDependent|HEFcontainsNlpText|HEFcontainsXmlText|HEFcontainsSkip|HEFcontainsCounter|HEFtransformDependent|HEFtranslated|HEFonFailDependent|HEFcontextDependentException|HEFoldthrows),
HEFretainedByActiveSelect = (HEFhousekeeping|HEFalwaysInherit),
HEFintersectionFlags = (0),
HEFunionFlags = (HEFunbound|HEFfunctionOfGroupAggregate|HEFvolatile|HEFaction|HEFthrowscalar|HEFthrowds|HEFoldthrows|//HEFtransformSkips|
HEFonFailDependent|HEFcontainsActiveDataset|HEFcontainsActiveNonSelector|HEFcontainsDataset|
HEFtranslated|HEFgraphDependent|HEFcontainsNlpText|HEFcontainsXmlText|HEFtransformDependent|
HEFcontainsSkip|HEFcontainsCounter|HEFassertkeyed|HEFcontextDependentException|HEFcontainsAlias|HEFcontainsAliasLocally|
HEFinternalVirtual|HEFcontainsThisNode|HEFcontainsDatasetAliasLocally),
HEFcontextDependentNoThrow = (HEFcontextDependent & ~(HEFthrowscalar|HEFthrowds|HEFoldthrows)),
HEFcontextDependentDataset = (HEFcontextDependent & ~(HEFthrowscalar)),
HEFimpure = (HEFvolatile|HEFaction|HEFthrowds|HEFthrowscalar|HEFcontainsSkip|HEFtransformSkips),
};
//NB: increase the member variable if it grows
enum
{
HEF2workflow = 0x00000001,
HEF2mustHoist = 0x00000002,
HEF2assertstepped = 0x00000004,
HEF2containsNonGlobalAlias = 0x00000008,
//no longer used = 0x00000010,
HEF2containsNewDataset = 0x00000020,
HEF2constant = 0x00000040,
HEF2____unused1____ = 0x00000080,
HEF2globalAction = 0x00000100, // Can only be evaluated globally
HEF2containsCall = 0x00000200,
HEF2containsDelayedCall = 0x00000400,
//NB: infoFlags2 is currently 2 bytes
HEF2alwaysInherit = (HEF2workflow|HEF2containsCall|HEF2containsDelayedCall),
HEF2intersectionFlags = (HEF2constant),
HEF2unionFlags = (HEF2alwaysInherit)|(HEF2mustHoist|HEF2assertstepped|HEF2containsNonGlobalAlias|HEF2containsNewDataset|HEF2globalAction),
HEF2assigninheritFlags = ~(HEF2alwaysInherit), // An assign inherits all but this list from the rhs value
};
//Removed spaces so it is easier to translate from a number to a node when debugging.
enum _node_operator {
no_none,
no_scope,
no_list,
no_mul,
no_div,
no_modulus,
no_negate,
no_add,
no_sub,
no_eq,
no_ne,
no_lt,
no_le,
no_gt,
no_ge,
no_not,
no_notnot,
no_and,
no_or,
no_xor,
no_concat,
no_notin,
no_in,
no_notbetween,
no_between,
no_comma,
no_count,
no_countgroup,
no_unused82,
no_exists,
no_within,
no_notwithin,
no_param,
no_constant,
no_field,
no_map,
no_if,
no_max,
no_min,
no_sum,
no_ave,
no_maxgroup,
no_mingroup,
no_sumgroup,
no_avegroup,
no_exp,
no_power,
no_round,
no_roundup,
no_range,
no_rangeto,
no_rangefrom,
no_substring,
no_transform,
no_rollup,
no_iterate,
no_hqlproject,
no_assign,
no_assignall,
no_asstring,
no_group,
no_cogroup,
no_cosort,
no_truncate,
no_ln,
no_log10,
no_sin,
no_cos,
no_tan,
no_asin,
no_acos,
no_atan,
no_atan2,
no_sinh,
no_cosh,
no_tanh,
no_sqrt,
no_evaluate,
no_choose,
no_which,
no_rejected,
no_mapto,
no_record,
no_service,
no_index,
no_all,
no_left,
no_right,
no_outofline,
no_cast,
no_implicitcast,
no_once,
no_csv,
no_sql,
no_thor,
no_flat,
no_pipe,
no_mix,
no_selectnth,
no_stored,
no_failure,
no_success,
no_recovery,
no_external,
no_funcdef,
no_externalcall,
no_wait,
no_event,
no_persist,
no_buildindex,
no_output,
no_omitted,
no_when,
no_setconditioncode,
no_priority,
no_intformat,
no_realformat,
no_abs,
no_nofold,
no_table,
no_keyindex,
no_temptable,
no_usertable,
no_choosen,
no_filter,
no_fetch,
no_join,
no_joined,
no_sort,
no_sorted,
no_sortlist,
no_dedup,
no_enth,
no_sample,
no_selectfields,
no_persist_check,
no_create_initializer,
no_owned_ds,
no_complex,
no_assign_addfiles,
no_debug_option_value,
no_hash,
no_hash32,
no_hash64,
no_crc,
no_return_stmt,
no_update,
no_shuffle,
no_unused18,
no_alias,
no_unused19,
no_unused20,
no_unused21,
no_unused22,
no_unused23,
no_unused24,
no_dataset_from_transform,
no_unused2,
no_unknown,
no_unused3,
no_unused4,
no_unused5,
no_any,
no_unused27,
no_unused26,
no_unused25,
no_unused28,
no_unused29,
no_unused30,
no_unused31,
no_unused32,
no_unused33,
no_unused34,
no_unused35,
no_unused36,
no_unused37,
no_unused38,
no_is_null,
no_dataset_alias,
no_unused40,
no_unused41,
no_unused52,
no_trim,
no_position,
no_charlen,
no_unused42,
no_unused43,
no_unused44,
no_unused45,
no_unused46,
no_unused47,
no_unused48,
no_unused49,
no_unused50,
no_nullptr,
no_sizeof,
no_offsetof,
no_current_date,
no_current_time,
no_current_timestamp,
no_variable,
no_libraryselect,
no_case,
no_band,
no_bor,
no_bxor,
no_bnot,
no_postinc,
no_postdec,
no_preinc,
no_predec,
no_pselect,
no_address,
no_deref,
no_order,
no_hint,
no_attr,
no_self,
no_rank,
no_ranked,
no_mergedscope,
no_ordered, // internal, used in processing of rank/ranked
no_typetransfer,
no_decimalstack,
no_type,
no_apply,
no_ifblock,
no_translated, // contents below this have already been translated
no_addfiles,
no_distribute,
no_macro,
no_cloned,
no_cachealias,
no_lshift,
no_rshift,
no_colon,
no_setworkflow_cond,
no_recovering,
no_unused15,
no_random,
no_select,
no_normalize,
no_counter,
no_distributed,
no_grouped,
no_denormalize,
no_transformebcdic,
no_transformascii,
no_childdataset,
no_envsymbol,
no_null,
no_quoted, // similar to no_variable, but not a simple variable
no_bound_func, // used in caching
no_bound_type,
no_metaactivity,
no_fail,
no_filepos,
no_aggregate,
no_distribution,
no_newusertable, // replacements for no_usertable that have a separate newtransform.
no_newaggregate, // otherwise it becomes impossible to transform the trees.
no_newtransform, // same as transform, but no LEFT. in assignments. Allows easy reference to hole child tables.
no_fromunicode,
no_tounicode,
no_keyunicode,
no_loadxml, // used for error report
no_isomitted,
no_fieldmap, // dataset with a map
no_template_context, // dataset func
no_ensureresult, // (value, seq, [name])
no_getresult, // (seq, [name])
no_setresult, // (value, seq, [name])
no_is_valid,
no_alias_project, // add aliases to projected values
no_alias_scope, // define aliases for context of child expressions.
no_global, // force expression to be evaluated at global scope
no_eventname,
no_sequential,
no_parallel,
no_writespill,
no_readspill,
no_nolink,
no_workflow,
no_workflow_action,
no_commonspill,
no_choosesets,
no_regex_find,
no_regex_replace,
no_workunit_dataset,
no_failcode,
no_failmessage,
no_independent,
no_keyed,
no_compound,
no_checkpoint,
no_split, // only used in graph resourcing.
no_spill, // passthrough activity that also spills to disk.
no_subgraph,
no_dependenton,
no_setmeta,
no_throughaggregate,
no_joincount,
no_merge_nomatch,
no_countcompare,
no_limit,
no_evaluate_stmt,
no_notify,
no_parse,
no_newparse, // parse where record is expanded to (record,newtransform)
no_skip,
no_matched,
no_matchtext,
no_matchlength,
no_matchposition,
no_pat_select, // parameter to MATCHED
no_pat_const, // literal string
no_pat_pattern, // pattern
no_pat_follow, // following tokens
no_pat_first, // first in buffer
no_pat_last, // last in buffer
no_pat_repeat, // x{n[,m]}, no second parameter means unlimited.
no_pat_instance, // instance of a named symbol
no_pat_anychar, // .
no_pat_token, // make a token from a pattern
no_pat_imptoken, // An implicit token (to help regeneration)
no_pat_set, // created from [a-z0-9] etc.
no_pat_checkin, // Does the pattern exist in the arguments?
no_pat_x_before_y, // look ahead assertion
no_pat_x_after_y, // look behind assertion
no_xml,
no_compound_fetch,
no_pat_index,
no_pat_beginpattern, // marks the start of a global/child pattern.
no_pat_endpattern, // marks the end of a global/child pattern.
no_pat_checklength, // has symbol x got length y?
no_topn,
no_outputscalar,
no_matchunicode,
no_pat_validate,
no_unused83,
no_existsgroup,
no_pat_use,
no_unused13,
no_penalty,
no_rowdiff,
no_wuid,
no_featuretype,
no_pat_guard,
no_xmltext,
no_xmlunicode,
no_newxmlparse,
no_xmlparse,
no_xmldecode,
no_xmlencode,
no_pat_featureparam,
no_pat_featureactual,
no_pat_featuredef,
no_evalonce,
no_unused14,
no_merge,
no_keyeddistribute,
no_distributer,
no_impure,
no_attr_link, // a link to another expression - parameters should be mapped by transformations.
no_attr_expr, // an attribute with parameters that should be transformed (not just mapped)
no_addsets,
no_rowvalue,
no_newkeyindex,
no_pat_case,
no_pat_nocase,
no_activetable, // used in the type information to represent the active table
no_preload,
no_createset,
no_assertkeyed,
no_assertwild,
no_recordlist,
no_hashmd5,
no_soapcall,
no_soapcall_ds, // as above, but has a dataset parameter
no_newsoapcall,
no_newsoapcall_ds,
no_soapaction_ds,
no_newsoapaction_ds,
no_temprow,
no_activerow, // no_activerow(dataset) - used to disambiguate rows that are in scope.
no_catch,
no_unused80,
no_reference,
no_callback, // only used by code generator to backpatch the source
no_keyedlimit,
no_keydiff,
no_keypatch,
no_returnresult,
no_id2blob,
no_blob2id,
no_anon,
no_projectrow,
no_cppbody,
no_sortpartition,
no_define,
no_globalscope,
no_forcelocal,
no_typedef,
no_matchattr,
no_pat_production,
no_guard,
no_datasetfromrow,
no_createrow,
no_selfref, // reference to self inside record - not lhs of a transform. Because inside a record it can't have a type, since type isn't know at that point.
no_unicodeorder,
no_assertconstant,
no_compound_selectnew,
no_nothor,
no_newrow, // only used when changing selector on an expression
no_clustersize,
no_call,
no_compound_diskread, //NB: All these compound activities occur in the same order for each source.
no_compound_disknormalize,
no_compound_diskaggregate,
no_compound_diskcount,
no_compound_diskgroupaggregate,
no_compound_indexread,
no_compound_indexnormalize,
no_compound_indexaggregate,
no_compound_indexcount,
no_compound_indexgroupaggregate,
no_compound_childread,
no_compound_childnormalize,
no_compound_childaggregate,
no_compound_childcount,
no_compound_childgroupaggregate,
no_compound_inline,
no_getgraphresult,
no_setgraphresult,
no_assert,
no_assert_ds,
no_namedactual,
no_combine,
no_rows,
no_rollupgroup,
no_regroup,
no_combinegroup,
no_inlinetable,
no_transformlist,
no_variance,
no_covariance,
no_correlation,
no_vargroup,
no_covargroup,
no_corrgroup,
no_denormalizegroup,
no_xmlproject,
no_spillgraphresult,
no_enum,
no_pat_or,
no_loop,
no_loopbody,
no_cluster,
no_forcenolocal,
no_allnodes,
no_unused6,
no_matchrow,
no_sequence,
no_selfjoin,
no_remotescope,
no_privatescope,
no_virtualscope,
no_concretescope,
no_purevirtual,
no_internalvirtual,
no_delayedselect,
no_pure,
no_libraryscope,
no_libraryscopeinstance,
no_libraryinput,
no_pseudods,
no_process,
no_matchutf8,
no_thisnode,
no_graphloop,
no_rowset,
no_loopcounter,
no_getgraphloopresult,
no_setgraphloopresult,
no_rowsetindex,
no_rowsetrange,
no_assertstepped,
no_assertsorted,
no_assertgrouped,
no_assertdistributed,
no_mergejoin,
no_datasetlist,
no_nwayjoin,
no_nwaymerge,
no_stepped,
no_existslist,
no_countlist,
no_maxlist,
no_minlist,
no_sumlist,
no_getgraphloopresultset,
no_forwardscope,
no_pat_before_y, // look ahead assertion
no_pat_after_y, // look behind assertion
no_extractresult,
no_attrname, // used to save names, but not an "attribute" so names don't clash
no_nonempty,
no_processing, // currently expanding this as a definition.
no_filtergroup,
no_rangecommon,
no_section,
no_nobody,
no_deserialize,
no_serialize,
no_eclcrc,
no_top,
no_uncommoned_comma,
no_nameof,
no_catchds,
no_file_logicalname,
no_toxml,
no_sectioninput,
no_forcegraph,
no_eventextra,
no_unused81,
no_related,
no_executewhen,
no_definesideeffect,
no_callsideeffect,
no_fromxml,
no_actionlist, // Similar to no_sequential, but does not require independence
no_preservemeta,
no_normalizegroup,
no_indirect,
no_selectindirect,
no_nohoist, //purely for debugging/test generation
no_merge_pending,
no_httpcall,
no_getenv,
no_last_op,
//These never get created as IHqlExpressions....
no_pat_compound,
no_pat_begintoken,
no_pat_endtoken,
no_pat_begincheck,
no_pat_endcheckin,
no_pat_endchecklength,
no_pat_beginseparator,
no_pat_endseparator,
no_pat_separator,
no_pat_beginvalidate,
no_pat_endvalidate,
no_pat_dfa,
no_pat_singlechar,
no_pat_beginrecursive,
no_pat_endrecursive,
no_pat_utf8single,
no_pat_utf8lead,
no_pat_utf8follow,
no_last_pseudoop
};
enum
{
compound_readdelta = 0,
compound_normalizedelta,
compound_aggregatedelta,
compound_countdelta,
compound_groupaggregatedelta,
compound_maxdelta
};
enum annotate_kind
{
annotate_none,
annotate_symbol,
annotate_meta,
annotate_warning,
annotate_javadoc,
annotate_location,
annotate_parsemeta,
annotate_max
};
#ifdef ENABLE_ENUM_TYPE
typedef enum _node_operator node_operator;
#else
typedef unsigned short node_operator;
#endif
interface HQL_API IECLError: public IException
{
public:
virtual const char* getFilename() = 0;
virtual int getLine() = 0;
virtual int getColumn() = 0;
virtual int getPosition() = 0;
virtual StringBuffer& toString(StringBuffer&) = 0;
virtual bool isError() = 0;
};
interface HQL_API IErrorReceiver : public IInterface
{
virtual void reportError(int errNo, const char *msg, const char *filename, int lineno, int column, int pos) = 0;
virtual void report(IECLError* err) = 0;
virtual void reportWarning(int warnNo, const char *msg, const char *filename, int lineno, int column, int pos) = 0;
virtual size32_t errCount() = 0;
virtual size32_t warnCount() = 0;
};
typedef IArrayOf<IECLError> IECLErrorArray;
interface IHqlSimpleScope : public IInterface
{
virtual IHqlExpression *lookupSymbol(_ATOM name) = 0;
};
interface IHqlAlienTypeInfo : public IInterface
{
virtual ITypeInfo * getLogicalType() = 0;
virtual ITypeInfo * getPhysicalType() = 0;
virtual ITypeInfo * queryLogicalType() = 0;
virtual ITypeInfo * queryPhysicalType() = 0;
virtual int getLogicalTypeSize() = 0;
virtual int getPhysicalTypeSize() = 0;
virtual unsigned getMaxSize() = 0;
virtual IHqlExpression * queryLoadFunction() = 0;
virtual IHqlExpression * queryLengthFunction() = 0;
virtual IHqlExpression * queryStoreFunction() = 0;
virtual IHqlExpression * queryFunction(_ATOM name) = 0;
};
interface IFileContents : public IInterface
{
public:
virtual IFile * queryFile() = 0;
virtual ISourcePath * querySourcePath() = 0;
virtual const char * getText() = 0;
virtual size32_t length() = 0;
};
//This class ensures that the pointer to the owner is cleared before both links are released, which allows
//you to safely have an unlinked owner pointer in a child while this class instance exists.
template <class OWNER, class CHILD>
class SafeOwnerReference : public CInterface
{
public:
inline SafeOwnerReference(OWNER * _owner, CHILD * _child) : owner(_owner), child(_child) {}
inline ~SafeOwnerReference() { child->clearOwner(); }
protected:
Linked<OWNER> owner;
Linked<CHILD> child;
};
interface IHasUnlinkedOwnerReference : public IInterface
{
virtual void clearOwner() = 0;
};
typedef SafeOwnerReference<IHqlScope, IHasUnlinkedOwnerReference> ForwardScopeItem;
class HQL_API HqlParseContext
{
public:
class MetaOptions
{
public:
MetaOptions() { _clear(*this); }
bool includePublicDefinitions; // include details of SHARED and EXPORTED symbols
bool includePrivateDefinitions; // include details of local symbols/parameters etc.
bool onlyGatherRoot; // only gather information for the main definition processed.
bool includeInternalUses; // gather use of internal symbols
bool includeExternalUses; // gather use of external symbols
bool includeImports; // gather imports
bool includeLocations; // include information about source locations
bool includeJavadoc;
};
HqlParseContext(IEclRepository * _eclRepository, IPropertyTree * _archive)
: archive(_archive), eclRepository(_eclRepository)
{
expandCallsWhenBound = DEFAULT_EXPAND_CALL;
ignoreUnknownImport = false;
_clear(metaState);
}
void addForwardReference(IHqlScope * owner, IHasUnlinkedOwnerReference * child);
void noteBeginAttribute(IHqlScope * scope, IFileContents * contents, _ATOM name);
void noteBeginModule(IHqlScope * scope, IFileContents * contents);
void noteBeginQuery(IHqlScope * scope, IFileContents * contents);
void noteEndAttribute();
void noteEndModule();
void noteEndQuery();
void noteFinishedParse(IHqlScope * scope);
void notePrivateSymbols(IHqlScope * scope);
IPropertyTree * queryEnsureArchiveModule(const char * name, IHqlScope * scope);
void setGatherMeta(const MetaOptions & options);
inline IPropertyTree * getMetaTree() { return LINK(metaTree); }
inline IPropertyTree * queryArchive() const { return archive; }
inline IEclRepository * queryRepository() const { return eclRepository; }
public:
Linked<IPropertyTree> archive;
Linked<IEclRepository> eclRepository;
Owned<IPropertyTree> nestedDependTree;
Owned<IPropertyTree> globalDependTree;
Owned<IPropertyTree> metaTree;
HqlExprArray defaultFunctionCache;
CIArrayOf<ForwardScopeItem> forwardLinks;
bool expandCallsWhenBound;
bool ignoreUnknownImport;
private:
bool checkBeginMeta();
bool checkEndMeta();
void finishMeta();
MetaOptions metaOptions;
struct {
bool gatherNow;
PointerArrayOf<IPropertyTree> nesting;
} metaState;
};
class HqlDummyParseContext : public HqlParseContext
{
public:
HqlDummyParseContext() : HqlParseContext(NULL, NULL) {}
};
class HqlLookupContext
{
public:
explicit HqlLookupContext(const HqlLookupContext & other) : parseCtx(other.parseCtx)
{
errs.set(other.errs);
functionCache = other.functionCache;
curAttrTree.set(other.curAttrTree);
}
HqlLookupContext(HqlParseContext & _parseCtx, IErrorReceiver * _errs)
: parseCtx(_parseCtx), errs(_errs)
{
functionCache = &parseCtx.defaultFunctionCache;
}
void createDependencyEntry(IHqlScope * scope, _ATOM name);
void noteBeginAttribute(IHqlScope * scope, IFileContents * contents, _ATOM name);
void noteBeginModule(IHqlScope * scope, IFileContents * contents);
void noteBeginQuery(IHqlScope * scope, IFileContents * contents);
inline void noteEndAttribute() { parseCtx.noteEndAttribute(); }
inline void noteEndModule() { parseCtx.noteEndAttribute(); }
inline void noteEndQuery() { parseCtx.noteEndQuery(); }
inline void noteFinishedParse(IHqlScope * scope) { parseCtx.noteFinishedParse(scope); }
void noteExternalLookup(IHqlScope * parentScope, IHqlExpression * expr);
inline void notePrivateSymbols(IHqlScope * scope) { parseCtx.notePrivateSymbols(scope); }
inline IEclRepository * queryRepository() const { return parseCtx.eclRepository; }
inline bool queryExpandCallsWhenBound() const { return parseCtx.expandCallsWhenBound; }
inline HqlParseContext & queryParseContext() const { return parseCtx; }
inline unsigned numErrors() const { return errs ? errs->errCount() : 0; }
protected:
inline IPropertyTree * queryArchive() const { return parseCtx.archive; }
inline IPropertyTree * queryNestedDependTree() const { return parseCtx.nestedDependTree; }
private:
HqlParseContext & parseCtx;
public:
Linked<IErrorReceiver> errs;
HqlExprArray * functionCache;
Owned<IPropertyTree> curAttrTree;
HqlExprCopyArray dependents;
};
class HqlDummyLookupContext : public HqlLookupContext
{
public:
//Potentially problematic - dummyCtx not created at the point the constructor is called.
HqlDummyLookupContext(IErrorReceiver * _errs) : HqlLookupContext(dummyCtx, _errs) {}
private:
HqlDummyParseContext dummyCtx;
};
enum
{
LSFpublic = 0x0000,
LSFsharedOK = 0x0001,
LSFignoreBase = 0x0002,
LSFrequired = 0x0004,
LSFimport = 0x0008,
};
inline unsigned makeLookupFlags(bool sharedOK, bool ignoreBase, bool required)