hqlexpr.hpp 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785
  1. /*##############################################################################
  2. Copyright (C) 2011 HPCC Systems.
  3. All rights reserved. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ############################################################################## */
  14. #ifndef HQLEXPR_INCL
  15. #define HQLEXPR_INCL
  16. #ifdef _DEBUG
  17. #define ENABLE_ENUM_TYPE
  18. #endif
  19. #ifndef _DEBUG
  20. // #define USE_TBB
  21. #endif
  22. //#define USE_SELSEQ_UID
  23. //#define ENSURE_SELSEQ_UID
  24. //Currently nearly all functional attributes are expanded when the call is parsed.
  25. //This is potentially inefficient, and makes it hard to dynamically control whether functions are expanded in line or generated out of line.
  26. //Expansion in place probably occupies 50% of the parse time processing, but parsing is typically 20% of over-all time - significant but not disastrous.
  27. //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.
  28. //
  29. //The following constant changes that functionality so expansion is delayed until before code generation.
  30. //It nearly works - but there are still some examples which have problems - primarily libraries, old parameter syntax, enums and other issues.
  31. //There may also problems with queryRecord() which needs to really be replaced with recordof(x), especially if "templates" are delayed expanded.
  32. //To work properly it may require many of the transformations in hqlgram2.cpp to be moved to after the expansion. (E.g., BUILD)
  33. //#define DELAY_CALL_EXPANSION
  34. #ifdef DELAY_CALL_EXPANSION
  35. #define DEFAULT_EXPAND_CALL false
  36. #else
  37. #define DEFAULT_EXPAND_CALL true
  38. #endif
  39. #define GATHER_HIDDEN_SELECTORS
  40. #define XPATH_CONTENTS_TEXT "<>"
  41. //This should be defined, but HOLe does not cope with variable length stored strings. Need to wait until HOLe is integrated into thor.
  42. //#define STORED_CAN_CHANGE_LENGTH
  43. #include "hql.hpp"
  44. #include "jhash.hpp"
  45. #include "jprop.hpp"
  46. #include "jptree.hpp"
  47. #include "defvalue.hpp"
  48. interface IXmlScope;
  49. interface IHqlScope;
  50. interface IHqlSimpleScope;
  51. interface IHqlDataset;
  52. interface IHqlExpression;
  53. extern HQL_API ISourcePath * createSourcePath(const char * name);
  54. extern HQL_API ISourcePath * createSourcePath(unsigned len, const char * name);
  55. class HqlGramCtx; // opaque, but still not very nice
  56. class HQL_API HqlExprArray : public IArrayOf<IHqlExpression>
  57. {
  58. public:
  59. void swapWith(HqlExprArray & other);
  60. bool containsBody(IHqlExpression & expr);
  61. };
  62. class HQL_API UniqueSequenceCounter
  63. {
  64. public:
  65. inline UniqueSequenceCounter() { value = 0; }
  66. inline unique_id_t next()
  67. {
  68. SpinBlock block(lock);
  69. return ++value;
  70. }
  71. protected:
  72. unique_id_t value;
  73. SpinLock lock;
  74. };
  75. typedef ICopyArrayOf<IHqlExpression> HqlExprCopyArray;
  76. typedef class MapXToMyClass<_ATOM, _ATOM, _ATOM> KeywordMap;
  77. typedef ICopyArrayOf<IAtom> AtomArray;
  78. const unsigned UnadornedParameterIndex = (unsigned)-1;
  79. #define CHOOSEN_ALL_LIMIT I64C(0x7FFFFFFFFFFFFFFF)
  80. // Allow of the following are private, and should only be accessed by the associated helper functions.
  81. //NB: If this is changed, remember to look at whether no_select an noinherit need modifying.
  82. enum
  83. {
  84. // House keeping information on a per node basis
  85. HEF____unused0____ = 0x00000001,
  86. HEFobserved = 0x00000002,
  87. HEFgatheredNew = 0x00000004,
  88. HEFhasunadorned = 0x00000008,
  89. HEFhousekeeping = (HEFhasunadorned|HEFobserved|HEFgatheredNew),
  90. // generally applicable start from the top down
  91. HEFunbound = 0x00000010,
  92. HEFinternalVirtual = 0x00000020,
  93. HEFcontainsDatasetAliasLocally= 0x00000040,
  94. HEF____unused2____ = 0x00000080,
  95. HEF____unused3____ = 0x00000100,
  96. HEFfunctionOfGroupAggregate = 0x00000200,
  97. HEFvolatile = 0x00000400, // value changes each time called - e.g., random()
  98. HEFaction = 0x00000800, // an action, or something that can have a side-effect
  99. HEFtransformSkips = 0x00001000,
  100. HEFthrowscalar = 0x00002000, // scalar/action that can throw an exception
  101. HEFthrowds = 0x00004000, // dataset that can throw an exception
  102. HEFoldthrows = 0x00008000, // old throws flag, which I should remove asap
  103. // code generator specific start from the bottom up.
  104. //NB: update the select
  105. HEFcontainsThisNode = 0x00010000,
  106. HEFonFailDependent = 0x00020000,
  107. HEFcontainsActiveDataset = 0x00040000,
  108. HEFcontainsActiveNonSelector= 0x00080000,
  109. HEFcontainsDataset = 0x00100000,
  110. HEFtranslated = 0x00200000,
  111. HEFgraphDependent = 0x00400000,
  112. HEFcontainsNlpText = 0x00800000,
  113. HEFcontainsXmlText = 0x01000000,
  114. HEFtransformDependent = 0x02000000, // depends in some way on the containing transform
  115. // self, fail and counter. Latter should be treated like a dataset I suspect., could have separate flags for others.
  116. HEFcontainsSkip = 0x04000000,
  117. HEFcontainsCounter = 0x08000000,
  118. HEFassertkeyed = 0x10000000,
  119. HEFcontextDependentException= 0x20000000, // A context dependent item that doesn't fit into any other category - for use as a last resort!
  120. HEFcontainsAlias = 0x40000000,
  121. HEFcontainsAliasLocally = 0x80000000,
  122. //Combinations used for processing elsewhere:
  123. //Don't ever inherit the following...
  124. HEFalwaysInherit = HEFunbound|HEFinternalVirtual,
  125. HEFassigninheritFlags = ~(HEFhousekeeping|HEFalwaysInherit), // An assign inherits all but this list from the rhs value
  126. // HEFcontextDependent = (HEFgraphDependent|HEFcontainsNlpText|HEFcontainsXmlText|HEFcontainsSkip|HEFcontainsCounter|HEFtransformDependent|HEFtranslated|HEFonFailDependent|HEFcontextDependentException|HEFthrowscalar|HEFthrowds),
  127. HEFcontextDependent = (HEFgraphDependent|HEFcontainsNlpText|HEFcontainsXmlText|HEFcontainsSkip|HEFcontainsCounter|HEFtransformDependent|HEFtranslated|HEFonFailDependent|HEFcontextDependentException|HEFoldthrows),
  128. HEFretainedByActiveSelect = (HEFhousekeeping|HEFalwaysInherit),
  129. HEFintersectionFlags = (0),
  130. HEFunionFlags = (HEFunbound|HEFfunctionOfGroupAggregate|HEFvolatile|HEFaction|HEFthrowscalar|HEFthrowds|HEFoldthrows|//HEFtransformSkips|
  131. HEFonFailDependent|HEFcontainsActiveDataset|HEFcontainsActiveNonSelector|HEFcontainsDataset|
  132. HEFtranslated|HEFgraphDependent|HEFcontainsNlpText|HEFcontainsXmlText|HEFtransformDependent|
  133. HEFcontainsSkip|HEFcontainsCounter|HEFassertkeyed|HEFcontextDependentException|HEFcontainsAlias|HEFcontainsAliasLocally|
  134. HEFinternalVirtual|HEFcontainsThisNode|HEFcontainsDatasetAliasLocally),
  135. HEFcontextDependentNoThrow = (HEFcontextDependent & ~(HEFthrowscalar|HEFthrowds|HEFoldthrows)),
  136. HEFcontextDependentDataset = (HEFcontextDependent & ~(HEFthrowscalar)),
  137. HEFimpure = (HEFvolatile|HEFaction|HEFthrowds|HEFthrowscalar|HEFcontainsSkip|HEFtransformSkips),
  138. };
  139. //NB: increase the member variable if it grows
  140. enum
  141. {
  142. HEF2workflow = 0x00000001,
  143. HEF2mustHoist = 0x00000002,
  144. HEF2assertstepped = 0x00000004,
  145. HEF2containsNonGlobalAlias = 0x00000008,
  146. //no longer used = 0x00000010,
  147. HEF2containsNewDataset = 0x00000020,
  148. HEF2constant = 0x00000040,
  149. HEF2____unused1____ = 0x00000080,
  150. HEF2globalAction = 0x00000100, // Can only be evaluated globally
  151. HEF2containsCall = 0x00000200,
  152. HEF2containsDelayedCall = 0x00000400,
  153. //NB: infoFlags2 is currently 2 bytes
  154. HEF2alwaysInherit = (HEF2workflow|HEF2containsCall|HEF2containsDelayedCall),
  155. HEF2intersectionFlags = (HEF2constant),
  156. HEF2unionFlags = (HEF2alwaysInherit)|(HEF2mustHoist|HEF2assertstepped|HEF2containsNonGlobalAlias|HEF2containsNewDataset|HEF2globalAction),
  157. HEF2assigninheritFlags = ~(HEF2alwaysInherit), // An assign inherits all but this list from the rhs value
  158. };
  159. //Removed spaces so it is easier to translate from a number to a node when debugging.
  160. enum _node_operator {
  161. no_none,
  162. no_scope,
  163. no_list,
  164. no_mul,
  165. no_div,
  166. no_modulus,
  167. no_negate,
  168. no_add,
  169. no_sub,
  170. no_eq,
  171. no_ne,
  172. no_lt,
  173. no_le,
  174. no_gt,
  175. no_ge,
  176. no_not,
  177. no_notnot,
  178. no_and,
  179. no_or,
  180. no_xor,
  181. no_concat,
  182. no_notin,
  183. no_in,
  184. no_notbetween,
  185. no_between,
  186. no_comma,
  187. no_count,
  188. no_countgroup,
  189. no_unused82,
  190. no_exists,
  191. no_within,
  192. no_notwithin,
  193. no_param,
  194. no_constant,
  195. no_field,
  196. no_map,
  197. no_if,
  198. no_max,
  199. no_min,
  200. no_sum,
  201. no_ave,
  202. no_maxgroup,
  203. no_mingroup,
  204. no_sumgroup,
  205. no_avegroup,
  206. no_exp,
  207. no_power,
  208. no_round,
  209. no_roundup,
  210. no_range,
  211. no_rangeto,
  212. no_rangefrom,
  213. no_substring,
  214. no_transform,
  215. no_rollup,
  216. no_iterate,
  217. no_hqlproject,
  218. no_assign,
  219. no_assignall,
  220. no_asstring,
  221. no_group,
  222. no_cogroup,
  223. no_cosort,
  224. no_truncate,
  225. no_ln,
  226. no_log10,
  227. no_sin,
  228. no_cos,
  229. no_tan,
  230. no_asin,
  231. no_acos,
  232. no_atan,
  233. no_atan2,
  234. no_sinh,
  235. no_cosh,
  236. no_tanh,
  237. no_sqrt,
  238. no_evaluate,
  239. no_choose,
  240. no_which,
  241. no_rejected,
  242. no_mapto,
  243. no_record,
  244. no_service,
  245. no_index,
  246. no_all,
  247. no_left,
  248. no_right,
  249. no_outofline,
  250. no_cast,
  251. no_implicitcast,
  252. no_once,
  253. no_csv,
  254. no_sql,
  255. no_thor,
  256. no_flat,
  257. no_pipe,
  258. no_mix,
  259. no_selectnth,
  260. no_stored,
  261. no_failure,
  262. no_success,
  263. no_recovery,
  264. no_external,
  265. no_funcdef,
  266. no_externalcall,
  267. no_wait,
  268. no_event,
  269. no_persist,
  270. no_buildindex,
  271. no_output,
  272. no_omitted,
  273. no_when,
  274. no_setconditioncode,
  275. no_priority,
  276. no_intformat,
  277. no_realformat,
  278. no_abs,
  279. no_nofold,
  280. no_table,
  281. no_keyindex,
  282. no_temptable,
  283. no_usertable,
  284. no_choosen,
  285. no_filter,
  286. no_fetch,
  287. no_join,
  288. no_joined,
  289. no_sort,
  290. no_sorted,
  291. no_sortlist,
  292. no_dedup,
  293. no_enth,
  294. no_sample,
  295. no_selectfields,
  296. no_persist_check,
  297. no_create_initializer,
  298. no_owned_ds,
  299. no_complex,
  300. no_assign_addfiles,
  301. no_debug_option_value,
  302. no_hash,
  303. no_hash32,
  304. no_hash64,
  305. no_crc,
  306. no_return_stmt,
  307. no_update,
  308. no_shuffle,
  309. no_unused18,
  310. no_alias,
  311. no_unused19,
  312. no_unused20,
  313. no_unused21,
  314. no_unused22,
  315. no_unused23,
  316. no_unused24,
  317. no_dataset_from_transform,
  318. no_unused2,
  319. no_unknown,
  320. no_unused3,
  321. no_unused4,
  322. no_unused5,
  323. no_any,
  324. no_unused27,
  325. no_unused26,
  326. no_unused25,
  327. no_unused28,
  328. no_unused29,
  329. no_unused30,
  330. no_unused31,
  331. no_unused32,
  332. no_unused33,
  333. no_unused34,
  334. no_unused35,
  335. no_unused36,
  336. no_unused37,
  337. no_unused38,
  338. no_is_null,
  339. no_dataset_alias,
  340. no_unused40,
  341. no_unused41,
  342. no_unused52,
  343. no_trim,
  344. no_position,
  345. no_charlen,
  346. no_unused42,
  347. no_unused43,
  348. no_unused44,
  349. no_unused45,
  350. no_unused46,
  351. no_unused47,
  352. no_unused48,
  353. no_unused49,
  354. no_unused50,
  355. no_nullptr,
  356. no_sizeof,
  357. no_offsetof,
  358. no_current_date,
  359. no_current_time,
  360. no_current_timestamp,
  361. no_variable,
  362. no_libraryselect,
  363. no_case,
  364. no_band,
  365. no_bor,
  366. no_bxor,
  367. no_bnot,
  368. no_postinc,
  369. no_postdec,
  370. no_preinc,
  371. no_predec,
  372. no_pselect,
  373. no_address,
  374. no_deref,
  375. no_order,
  376. no_hint,
  377. no_attr,
  378. no_self,
  379. no_rank,
  380. no_ranked,
  381. no_mergedscope,
  382. no_ordered, // internal, used in processing of rank/ranked
  383. no_typetransfer,
  384. no_decimalstack,
  385. no_type,
  386. no_apply,
  387. no_ifblock,
  388. no_translated, // contents below this have already been translated
  389. no_addfiles,
  390. no_distribute,
  391. no_macro,
  392. no_cloned,
  393. no_cachealias,
  394. no_lshift,
  395. no_rshift,
  396. no_colon,
  397. no_setworkflow_cond,
  398. no_recovering,
  399. no_unused15,
  400. no_random,
  401. no_select,
  402. no_normalize,
  403. no_counter,
  404. no_distributed,
  405. no_grouped,
  406. no_denormalize,
  407. no_transformebcdic,
  408. no_transformascii,
  409. no_childdataset,
  410. no_envsymbol,
  411. no_null,
  412. no_quoted, // similar to no_variable, but not a simple variable
  413. no_bound_func, // used in caching
  414. no_bound_type,
  415. no_metaactivity,
  416. no_fail,
  417. no_filepos,
  418. no_aggregate,
  419. no_distribution,
  420. no_newusertable, // replacements for no_usertable that have a separate newtransform.
  421. no_newaggregate, // otherwise it becomes impossible to transform the trees.
  422. no_newtransform, // same as transform, but no LEFT. in assignments. Allows easy reference to hole child tables.
  423. no_fromunicode,
  424. no_tounicode,
  425. no_keyunicode,
  426. no_loadxml, // used for error report
  427. no_isomitted,
  428. no_fieldmap, // dataset with a map
  429. no_template_context, // dataset func
  430. no_ensureresult, // (value, seq, [name])
  431. no_getresult, // (seq, [name])
  432. no_setresult, // (value, seq, [name])
  433. no_is_valid,
  434. no_alias_project, // add aliases to projected values
  435. no_alias_scope, // define aliases for context of child expressions.
  436. no_global, // force expression to be evaluated at global scope
  437. no_eventname,
  438. no_sequential,
  439. no_parallel,
  440. no_writespill,
  441. no_readspill,
  442. no_nolink,
  443. no_workflow,
  444. no_workflow_action,
  445. no_commonspill,
  446. no_choosesets,
  447. no_regex_find,
  448. no_regex_replace,
  449. no_workunit_dataset,
  450. no_failcode,
  451. no_failmessage,
  452. no_independent,
  453. no_keyed,
  454. no_compound,
  455. no_checkpoint,
  456. no_split, // only used in graph resourcing.
  457. no_spill, // passthrough activity that also spills to disk.
  458. no_subgraph,
  459. no_dependenton,
  460. no_setmeta,
  461. no_throughaggregate,
  462. no_joincount,
  463. no_merge_nomatch,
  464. no_countcompare,
  465. no_limit,
  466. no_evaluate_stmt,
  467. no_notify,
  468. no_parse,
  469. no_newparse, // parse where record is expanded to (record,newtransform)
  470. no_skip,
  471. no_matched,
  472. no_matchtext,
  473. no_matchlength,
  474. no_matchposition,
  475. no_pat_select, // parameter to MATCHED
  476. no_pat_const, // literal string
  477. no_pat_pattern, // pattern
  478. no_pat_follow, // following tokens
  479. no_pat_first, // first in buffer
  480. no_pat_last, // last in buffer
  481. no_pat_repeat, // x{n[,m]}, no second parameter means unlimited.
  482. no_pat_instance, // instance of a named symbol
  483. no_pat_anychar, // .
  484. no_pat_token, // make a token from a pattern
  485. no_pat_imptoken, // An implicit token (to help regeneration)
  486. no_pat_set, // created from [a-z0-9] etc.
  487. no_pat_checkin, // Does the pattern exist in the arguments?
  488. no_pat_x_before_y, // look ahead assertion
  489. no_pat_x_after_y, // look behind assertion
  490. no_xml,
  491. no_compound_fetch,
  492. no_pat_index,
  493. no_pat_beginpattern, // marks the start of a global/child pattern.
  494. no_pat_endpattern, // marks the end of a global/child pattern.
  495. no_pat_checklength, // has symbol x got length y?
  496. no_topn,
  497. no_outputscalar,
  498. no_matchunicode,
  499. no_pat_validate,
  500. no_unused83,
  501. no_existsgroup,
  502. no_pat_use,
  503. no_unused13,
  504. no_penalty,
  505. no_rowdiff,
  506. no_wuid,
  507. no_featuretype,
  508. no_pat_guard,
  509. no_xmltext,
  510. no_xmlunicode,
  511. no_newxmlparse,
  512. no_xmlparse,
  513. no_xmldecode,
  514. no_xmlencode,
  515. no_pat_featureparam,
  516. no_pat_featureactual,
  517. no_pat_featuredef,
  518. no_evalonce,
  519. no_unused14,
  520. no_merge,
  521. no_keyeddistribute,
  522. no_distributer,
  523. no_impure,
  524. no_attr_link, // a link to another expression - parameters should be mapped by transformations.
  525. no_attr_expr, // an attribute with parameters that should be transformed (not just mapped)
  526. no_addsets,
  527. no_rowvalue,
  528. no_newkeyindex,
  529. no_pat_case,
  530. no_pat_nocase,
  531. no_activetable, // used in the type information to represent the active table
  532. no_preload,
  533. no_createset,
  534. no_assertkeyed,
  535. no_assertwild,
  536. no_recordlist,
  537. no_hashmd5,
  538. no_soapcall,
  539. no_soapcall_ds, // as above, but has a dataset parameter
  540. no_newsoapcall,
  541. no_newsoapcall_ds,
  542. no_soapaction_ds,
  543. no_newsoapaction_ds,
  544. no_temprow,
  545. no_activerow, // no_activerow(dataset) - used to disambiguate rows that are in scope.
  546. no_catch,
  547. no_unused80,
  548. no_reference,
  549. no_callback, // only used by code generator to backpatch the source
  550. no_keyedlimit,
  551. no_keydiff,
  552. no_keypatch,
  553. no_returnresult,
  554. no_id2blob,
  555. no_blob2id,
  556. no_anon,
  557. no_projectrow,
  558. no_cppbody,
  559. no_sortpartition,
  560. no_define,
  561. no_globalscope,
  562. no_forcelocal,
  563. no_typedef,
  564. no_matchattr,
  565. no_pat_production,
  566. no_guard,
  567. no_datasetfromrow,
  568. no_createrow,
  569. 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.
  570. no_unicodeorder,
  571. no_assertconstant,
  572. no_compound_selectnew,
  573. no_nothor,
  574. no_newrow, // only used when changing selector on an expression
  575. no_clustersize,
  576. no_call,
  577. no_compound_diskread, //NB: All these compound activities occur in the same order for each source.
  578. no_compound_disknormalize,
  579. no_compound_diskaggregate,
  580. no_compound_diskcount,
  581. no_compound_diskgroupaggregate,
  582. no_compound_indexread,
  583. no_compound_indexnormalize,
  584. no_compound_indexaggregate,
  585. no_compound_indexcount,
  586. no_compound_indexgroupaggregate,
  587. no_compound_childread,
  588. no_compound_childnormalize,
  589. no_compound_childaggregate,
  590. no_compound_childcount,
  591. no_compound_childgroupaggregate,
  592. no_compound_inline,
  593. no_getgraphresult,
  594. no_setgraphresult,
  595. no_assert,
  596. no_assert_ds,
  597. no_namedactual,
  598. no_combine,
  599. no_rows,
  600. no_rollupgroup,
  601. no_regroup,
  602. no_combinegroup,
  603. no_inlinetable,
  604. no_transformlist,
  605. no_variance,
  606. no_covariance,
  607. no_correlation,
  608. no_vargroup,
  609. no_covargroup,
  610. no_corrgroup,
  611. no_denormalizegroup,
  612. no_xmlproject,
  613. no_spillgraphresult,
  614. no_enum,
  615. no_pat_or,
  616. no_loop,
  617. no_loopbody,
  618. no_cluster,
  619. no_forcenolocal,
  620. no_allnodes,
  621. no_unused6,
  622. no_matchrow,
  623. no_sequence,
  624. no_selfjoin,
  625. no_remotescope,
  626. no_privatescope,
  627. no_virtualscope,
  628. no_concretescope,
  629. no_purevirtual,
  630. no_internalvirtual,
  631. no_delayedselect,
  632. no_pure,
  633. no_libraryscope,
  634. no_libraryscopeinstance,
  635. no_libraryinput,
  636. no_pseudods,
  637. no_process,
  638. no_matchutf8,
  639. no_thisnode,
  640. no_graphloop,
  641. no_rowset,
  642. no_loopcounter,
  643. no_getgraphloopresult,
  644. no_setgraphloopresult,
  645. no_rowsetindex,
  646. no_rowsetrange,
  647. no_assertstepped,
  648. no_assertsorted,
  649. no_assertgrouped,
  650. no_assertdistributed,
  651. no_mergejoin,
  652. no_datasetlist,
  653. no_nwayjoin,
  654. no_nwaymerge,
  655. no_stepped,
  656. no_existslist,
  657. no_countlist,
  658. no_maxlist,
  659. no_minlist,
  660. no_sumlist,
  661. no_getgraphloopresultset,
  662. no_forwardscope,
  663. no_pat_before_y, // look ahead assertion
  664. no_pat_after_y, // look behind assertion
  665. no_extractresult,
  666. no_attrname, // used to save names, but not an "attribute" so names don't clash
  667. no_nonempty,
  668. no_processing, // currently expanding this as a definition.
  669. no_filtergroup,
  670. no_rangecommon,
  671. no_section,
  672. no_nobody,
  673. no_deserialize,
  674. no_serialize,
  675. no_eclcrc,
  676. no_top,
  677. no_uncommoned_comma,
  678. no_nameof,
  679. no_catchds,
  680. no_file_logicalname,
  681. no_toxml,
  682. no_sectioninput,
  683. no_forcegraph,
  684. no_eventextra,
  685. no_unused81,
  686. no_related,
  687. no_executewhen,
  688. no_definesideeffect,
  689. no_callsideeffect,
  690. no_fromxml,
  691. no_actionlist, // Similar to no_sequential, but does not require independence
  692. no_preservemeta,
  693. no_normalizegroup,
  694. no_indirect,
  695. no_selectindirect,
  696. no_nohoist, //purely for debugging/test generation
  697. no_merge_pending,
  698. no_httpcall,
  699. no_getenv,
  700. no_last_op,
  701. //These never get created as IHqlExpressions....
  702. no_pat_compound,
  703. no_pat_begintoken,
  704. no_pat_endtoken,
  705. no_pat_begincheck,
  706. no_pat_endcheckin,
  707. no_pat_endchecklength,
  708. no_pat_beginseparator,
  709. no_pat_endseparator,
  710. no_pat_separator,
  711. no_pat_beginvalidate,
  712. no_pat_endvalidate,
  713. no_pat_dfa,
  714. no_pat_singlechar,
  715. no_pat_beginrecursive,
  716. no_pat_endrecursive,
  717. no_pat_utf8single,
  718. no_pat_utf8lead,
  719. no_pat_utf8follow,
  720. no_last_pseudoop
  721. };
  722. enum
  723. {
  724. compound_readdelta = 0,
  725. compound_normalizedelta,
  726. compound_aggregatedelta,
  727. compound_countdelta,
  728. compound_groupaggregatedelta,
  729. compound_maxdelta
  730. };
  731. enum annotate_kind
  732. {
  733. annotate_none,
  734. annotate_symbol,
  735. annotate_meta,
  736. annotate_warning,
  737. annotate_javadoc,
  738. annotate_location,
  739. annotate_parsemeta,
  740. annotate_max
  741. };
  742. #ifdef ENABLE_ENUM_TYPE
  743. typedef enum _node_operator node_operator;
  744. #else
  745. typedef unsigned short node_operator;
  746. #endif
  747. interface HQL_API IECLError: public IException
  748. {
  749. public:
  750. virtual const char* getFilename() = 0;
  751. virtual int getLine() = 0;
  752. virtual int getColumn() = 0;
  753. virtual int getPosition() = 0;
  754. virtual StringBuffer& toString(StringBuffer&) = 0;
  755. virtual bool isError() = 0;
  756. };
  757. interface HQL_API IErrorReceiver : public IInterface
  758. {
  759. virtual void reportError(int errNo, const char *msg, const char *filename, int lineno, int column, int pos) = 0;
  760. virtual void report(IECLError* err) = 0;
  761. virtual void reportWarning(int warnNo, const char *msg, const char *filename, int lineno, int column, int pos) = 0;
  762. virtual size32_t errCount() = 0;
  763. virtual size32_t warnCount() = 0;
  764. };
  765. typedef IArrayOf<IECLError> IECLErrorArray;
  766. interface IHqlSimpleScope : public IInterface
  767. {
  768. virtual IHqlExpression *lookupSymbol(_ATOM name) = 0;
  769. };
  770. interface IHqlAlienTypeInfo : public IInterface
  771. {
  772. virtual ITypeInfo * getLogicalType() = 0;
  773. virtual ITypeInfo * getPhysicalType() = 0;
  774. virtual ITypeInfo * queryLogicalType() = 0;
  775. virtual ITypeInfo * queryPhysicalType() = 0;
  776. virtual int getLogicalTypeSize() = 0;
  777. virtual int getPhysicalTypeSize() = 0;
  778. virtual unsigned getMaxSize() = 0;
  779. virtual IHqlExpression * queryLoadFunction() = 0;
  780. virtual IHqlExpression * queryLengthFunction() = 0;
  781. virtual IHqlExpression * queryStoreFunction() = 0;
  782. virtual IHqlExpression * queryFunction(_ATOM name) = 0;
  783. };
  784. interface IFileContents : public IInterface
  785. {
  786. public:
  787. virtual IFile * queryFile() = 0;
  788. virtual ISourcePath * querySourcePath() = 0;
  789. virtual const char * getText() = 0;
  790. virtual size32_t length() = 0;
  791. };
  792. //This class ensures that the pointer to the owner is cleared before both links are released, which allows
  793. //you to safely have an unlinked owner pointer in a child while this class instance exists.
  794. template <class OWNER, class CHILD>
  795. class SafeOwnerReference : public CInterface
  796. {
  797. public:
  798. inline SafeOwnerReference(OWNER * _owner, CHILD * _child) : owner(_owner), child(_child) {}
  799. inline ~SafeOwnerReference() { child->clearOwner(); }
  800. protected:
  801. Linked<OWNER> owner;
  802. Linked<CHILD> child;
  803. };
  804. interface IHasUnlinkedOwnerReference : public IInterface
  805. {
  806. virtual void clearOwner() = 0;
  807. };
  808. typedef SafeOwnerReference<IHqlScope, IHasUnlinkedOwnerReference> ForwardScopeItem;
  809. class HQL_API HqlParseContext
  810. {
  811. public:
  812. class MetaOptions
  813. {
  814. public:
  815. MetaOptions() { _clear(*this); }
  816. bool includePublicDefinitions; // include details of SHARED and EXPORTED symbols
  817. bool includePrivateDefinitions; // include details of local symbols/parameters etc.
  818. bool onlyGatherRoot; // only gather information for the main definition processed.
  819. bool includeInternalUses; // gather use of internal symbols
  820. bool includeExternalUses; // gather use of external symbols
  821. bool includeImports; // gather imports
  822. bool includeLocations; // include information about source locations
  823. bool includeJavadoc;
  824. };
  825. HqlParseContext(IEclRepository * _eclRepository, IPropertyTree * _archive)
  826. : archive(_archive), eclRepository(_eclRepository)
  827. {
  828. expandCallsWhenBound = DEFAULT_EXPAND_CALL;
  829. ignoreUnknownImport = false;
  830. _clear(metaState);
  831. }
  832. void addForwardReference(IHqlScope * owner, IHasUnlinkedOwnerReference * child);
  833. void noteBeginAttribute(IHqlScope * scope, IFileContents * contents, _ATOM name);
  834. void noteBeginModule(IHqlScope * scope, IFileContents * contents);
  835. void noteBeginQuery(IHqlScope * scope, IFileContents * contents);
  836. void noteEndAttribute();
  837. void noteEndModule();
  838. void noteEndQuery();
  839. void noteFinishedParse(IHqlScope * scope);
  840. void notePrivateSymbols(IHqlScope * scope);
  841. IPropertyTree * queryEnsureArchiveModule(const char * name, IHqlScope * scope);
  842. void setGatherMeta(const MetaOptions & options);
  843. inline IPropertyTree * getMetaTree() { return LINK(metaTree); }
  844. inline IPropertyTree * queryArchive() const { return archive; }
  845. inline IEclRepository * queryRepository() const { return eclRepository; }
  846. public:
  847. Linked<IPropertyTree> archive;
  848. Linked<IEclRepository> eclRepository;
  849. Owned<IPropertyTree> nestedDependTree;
  850. Owned<IPropertyTree> globalDependTree;
  851. Owned<IPropertyTree> metaTree;
  852. HqlExprArray defaultFunctionCache;
  853. CIArrayOf<ForwardScopeItem> forwardLinks;
  854. bool expandCallsWhenBound;
  855. bool ignoreUnknownImport;
  856. private:
  857. bool checkBeginMeta();
  858. bool checkEndMeta();
  859. void finishMeta();
  860. MetaOptions metaOptions;
  861. struct {
  862. bool gatherNow;
  863. PointerArrayOf<IPropertyTree> nesting;
  864. } metaState;
  865. };
  866. class HqlDummyParseContext : public HqlParseContext
  867. {
  868. public:
  869. HqlDummyParseContext() : HqlParseContext(NULL, NULL) {}
  870. };
  871. class HqlLookupContext
  872. {
  873. public:
  874. explicit HqlLookupContext(const HqlLookupContext & other) : parseCtx(other.parseCtx)
  875. {
  876. errs.set(other.errs);
  877. functionCache = other.functionCache;
  878. curAttrTree.set(other.curAttrTree);
  879. }
  880. HqlLookupContext(HqlParseContext & _parseCtx, IErrorReceiver * _errs)
  881. : parseCtx(_parseCtx), errs(_errs)
  882. {
  883. functionCache = &parseCtx.defaultFunctionCache;
  884. }
  885. void createDependencyEntry(IHqlScope * scope, _ATOM name);
  886. void noteBeginAttribute(IHqlScope * scope, IFileContents * contents, _ATOM name);
  887. void noteBeginModule(IHqlScope * scope, IFileContents * contents);
  888. void noteBeginQuery(IHqlScope * scope, IFileContents * contents);
  889. inline void noteEndAttribute() { parseCtx.noteEndAttribute(); }
  890. inline void noteEndModule() { parseCtx.noteEndAttribute(); }
  891. inline void noteEndQuery() { parseCtx.noteEndQuery(); }
  892. inline void noteFinishedParse(IHqlScope * scope) { parseCtx.noteFinishedParse(scope); }
  893. void noteExternalLookup(IHqlScope * parentScope, IHqlExpression * expr);
  894. inline void notePrivateSymbols(IHqlScope * scope) { parseCtx.notePrivateSymbols(scope); }
  895. inline IEclRepository * queryRepository() const { return parseCtx.eclRepository; }
  896. inline bool queryExpandCallsWhenBound() const { return parseCtx.expandCallsWhenBound; }
  897. inline HqlParseContext & queryParseContext() const { return parseCtx; }
  898. inline unsigned numErrors() const { return errs ? errs->errCount() : 0; }
  899. protected:
  900. inline IPropertyTree * queryArchive() const { return parseCtx.archive; }
  901. inline IPropertyTree * queryNestedDependTree() const { return parseCtx.nestedDependTree; }
  902. private:
  903. HqlParseContext & parseCtx;
  904. public:
  905. Linked<IErrorReceiver> errs;
  906. HqlExprArray * functionCache;
  907. Owned<IPropertyTree> curAttrTree;
  908. HqlExprCopyArray dependents;
  909. };
  910. class HqlDummyLookupContext : public HqlLookupContext
  911. {
  912. public:
  913. //Potentially problematic - dummyCtx not created at the point the constructor is called.
  914. HqlDummyLookupContext(IErrorReceiver * _errs) : HqlLookupContext(dummyCtx, _errs) {}
  915. private:
  916. HqlDummyParseContext dummyCtx;
  917. };
  918. enum
  919. {
  920. LSFpublic = 0x0000,
  921. LSFsharedOK = 0x0001,
  922. LSFignoreBase = 0x0002,
  923. LSFrequired = 0x0004,
  924. LSFimport = 0x0008,
  925. };
  926. inline unsigned makeLookupFlags(bool sharedOK, bool ignoreBase, bool required)
  927. {
  928. return (sharedOK ? LSFsharedOK : 0) |
  929. (ignoreBase ? LSFignoreBase : 0) |
  930. (required ? LSFrequired : 0);
  931. }
  932. //MORE: This should be split into a constant and creator interfaces
  933. interface IHqlScope : public IInterface
  934. {
  935. virtual IHqlExpression * queryExpression() = 0;
  936. virtual IHqlExpression *lookupSymbol(_ATOM searchName, unsigned lookupFlags, HqlLookupContext & ctx) = 0;
  937. virtual void getSymbols(HqlExprArray& exprs) const= 0;
  938. virtual _ATOM queryName() const = 0;
  939. virtual const char * queryFullName() const = 0;
  940. virtual ISourcePath * querySourcePath() const = 0;
  941. virtual bool hasBaseClass(IHqlExpression * searchBase) = 0;
  942. virtual IHqlScope * clone(HqlExprArray & children, HqlExprArray & symbols) = 0;
  943. virtual IHqlScope * queryConcreteScope() = 0;
  944. virtual IHqlScope * queryResolvedScope(HqlLookupContext * context) = 0;
  945. virtual void ensureSymbolsDefined(HqlLookupContext & ctx) = 0;
  946. virtual bool isImplicit() const = 0;
  947. virtual bool isPlugin() const = 0;
  948. virtual int getPropInt(_ATOM, int) const = 0;
  949. virtual bool getProp(_ATOM, StringBuffer &) const = 0;
  950. //IHqlCreateScope
  951. 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) = 0;
  952. virtual void defineSymbol(_ATOM name, _ATOM moduleName, IHqlExpression *value, bool isExported, bool isShared, unsigned flags) = 0;
  953. virtual void defineSymbol(IHqlExpression * expr) = 0; // use with great care, expr must be a named symbol.
  954. virtual void removeSymbol(_ATOM name) = 0; // use with great care
  955. };
  956. interface IEclSource;
  957. interface IHqlRemoteScope : public IInterface
  958. {
  959. virtual IHqlScope * queryScope() = 0;
  960. virtual void setProp(_ATOM, const char *) = 0;
  961. virtual void setProp(_ATOM, int) = 0;
  962. virtual IEclSource * queryEclSource() const = 0;
  963. };
  964. interface IHqlDataset : public IInterface
  965. {
  966. virtual IHqlDataset* queryTable() = 0;
  967. virtual IHqlDataset * queryRootTable() = 0; // get DATASET definition.
  968. virtual IHqlExpression * queryContainer() = 0; // this shouldn't really be used - won't extent to more arbitrary relation trees.
  969. };
  970. extern HQL_API int getPrecedence(node_operator op);
  971. struct BindParameterContext;
  972. interface IHqlAnnotation;
  973. interface IHqlExpression : public IInterface
  974. {
  975. virtual _ATOM queryName() const = 0;
  976. virtual node_operator getOperator() const = 0;
  977. virtual bool isBoolean() = 0;
  978. virtual bool isDataset() = 0;
  979. virtual bool isDatarow() = 0;
  980. virtual bool isScope() = 0;
  981. virtual bool isType() = 0;
  982. virtual bool isAction() = 0;
  983. virtual bool isConstant() = 0;
  984. virtual bool isTransform() = 0;
  985. virtual bool isList() = 0;
  986. virtual bool isField() = 0;
  987. virtual bool isMacro() = 0;
  988. virtual bool isRecord() = 0;
  989. virtual bool isFunction() = 0;
  990. virtual bool isAggregate() = 0;
  991. virtual bool isGroupAggregateFunction() = 0;
  992. virtual bool isPure() = 0;
  993. virtual bool isAttribute() const = 0;
  994. virtual annotate_kind getAnnotationKind() const = 0;
  995. virtual IHqlAnnotation * queryAnnotation() = 0;
  996. virtual unsigned getInfoFlags() const = 0;
  997. virtual unsigned getInfoFlags2() const = 0;
  998. virtual ISourcePath * querySourcePath() const = 0;
  999. virtual _ATOM queryFullModuleName() const = 0; // only defined for a named symbol
  1000. virtual int getStartLine() const = 0;
  1001. virtual int getStartColumn() const = 0;
  1002. virtual IPropertyTree * getDocumentation() const = 0;
  1003. virtual ITypeInfo *queryType() const = 0;
  1004. virtual ITypeInfo *getType() = 0;
  1005. virtual StringBuffer &toString(StringBuffer &ret) = 0;
  1006. virtual IHqlExpression *queryChild(unsigned idx) const = 0;
  1007. virtual IHqlExpression *queryBody(bool singleLevel = false) = 0;
  1008. virtual unsigned numChildren() const = 0;
  1009. virtual bool isIndependentOfScope() = 0;
  1010. virtual void gatherTablesUsed(HqlExprCopyArray * newScope, HqlExprCopyArray * inScope) = 0;
  1011. virtual IValue *queryValue() const = 0;
  1012. virtual IInterface *queryUnknownExtra() = 0;
  1013. virtual unsigned __int64 querySequenceExtra() = 0; // sequence, but also overloaded with parameter number
  1014. virtual IHqlDataset *queryDataset() = 0;
  1015. virtual IHqlScope *queryScope() = 0;
  1016. virtual IHqlSimpleScope *querySimpleScope() = 0;
  1017. virtual IHqlExpression *queryFunctionDefinition() const = 0;
  1018. virtual IHqlExpression *queryExternalDefinition() const = 0;
  1019. virtual IHqlExpression *queryNormalizedSelector(bool skipIndex=false) = 0;
  1020. virtual IHqlExpression *queryProperty(_ATOM propName) const = 0;
  1021. virtual IHqlExpression *queryAttribute(_ATOM propName) = 0;
  1022. virtual ITypeInfo *queryRecordType() = 0;
  1023. virtual IHqlExpression *queryRecord() = 0;
  1024. virtual IHqlExpression *clone(HqlExprArray &) = 0;
  1025. virtual IHqlExpression * cloneAnnotation(IHqlExpression * body) = 0;
  1026. virtual IHqlExpression * cloneAllAnnotations(IHqlExpression * body) = 0;
  1027. virtual void unwindList(HqlExprArray &dst, node_operator) = 0;
  1028. virtual IInterface* queryTransformExtra() = 0;
  1029. virtual void setTransformExtra(IInterface *) = 0;
  1030. virtual void setTransformExtraOwned(IInterface *) = 0; // same as above, but argument is already linked
  1031. virtual void setTransformExtraUnlinked(IInterface *) = 0; // same as above, but argument isn't linked
  1032. virtual bool isFullyBound() const = 0;
  1033. virtual IHqlExpression *closeExpr() = 0; // MORE - should be in expressionBuilder interface!
  1034. virtual bool isExprClosed() const = 0; // aid to error recovery
  1035. virtual IHqlExpression *addOperand(IHqlExpression *) = 0; // MORE - should be in expressionBuilder interface!
  1036. virtual StringBuffer& getTextBuf(StringBuffer& buf) = 0;
  1037. virtual IFileContents * queryDefinitionText() const = 0;
  1038. virtual unsigned getSymbolFlags() const = 0; // only valid for a named symbol
  1039. virtual bool isExported() const = 0;
  1040. virtual unsigned getCachedEclCRC() = 0; // do not call directly - use getExpressionCRC()
  1041. virtual IHqlExpression * queryAnnotationParameter(unsigned i) const = 0;
  1042. // The following are added to allow efficient storage/retreival in a hashtable.
  1043. virtual void addObserver(IObserver & observer) = 0;
  1044. virtual void removeObserver(IObserver & observer) = 0;
  1045. virtual unsigned getHash() const = 0;
  1046. virtual bool equals(const IHqlExpression & other) const = 0;
  1047. // The following inline functions are purely derived from the functions in this interface
  1048. inline int getPrecedence() const { return ::getPrecedence(getOperator()); }
  1049. inline bool isAnnotation() const { return getAnnotationKind() != annotate_none; }
  1050. inline bool isNamedSymbol() const { return getAnnotationKind() == annotate_symbol; }
  1051. inline bool isFunctionDefinition() const { return getOperator() == no_funcdef; }
  1052. inline bool hasProperty(_ATOM propName) const { return queryProperty(propName) != NULL; }
  1053. inline bool hasText() const
  1054. {
  1055. IFileContents * contents = queryDefinitionText();
  1056. return contents && contents->length() != 0;
  1057. }
  1058. inline IHqlExpression * queryCallParameter(unsigned i) { return queryChild(i); }
  1059. inline IHqlExpression * queryDefinition() { return queryBody()->queryFunctionDefinition(); }
  1060. inline unsigned numCallParameters() { return numChildren(); }
  1061. };
  1062. interface IHqlAnnotation : public IInterface
  1063. {
  1064. virtual annotate_kind getAnnotationKind() const = 0;
  1065. virtual IHqlExpression * queryExpression() = 0;
  1066. };
  1067. interface IHqlNamedAnnotation : public IHqlAnnotation
  1068. {
  1069. virtual IFileContents * getBodyContents() = 0;
  1070. virtual IHqlExpression * cloneSymbol(_ATOM optname, IHqlExpression * optnewbody, IHqlExpression * optnewfuncdef, HqlExprArray * optargs) = 0;
  1071. virtual bool isExported() const = 0;
  1072. virtual bool isShared() const = 0;
  1073. virtual bool isPublic() const = 0;
  1074. virtual int getStartLine() const = 0;
  1075. virtual int getStartColumn() const = 0;
  1076. virtual void setRepositoryFlags(unsigned _flags) = 0; // To preserve flags like ob_locked, ob_sandbox, etc.
  1077. virtual int getStartPos() const = 0;
  1078. virtual int getBodyPos() const = 0;
  1079. virtual int getEndPos() const = 0;
  1080. };
  1081. typedef Linked<IHqlExpression> HqlExprAttr;
  1082. typedef Shared<IHqlExpression> SharedHqlExpr;
  1083. typedef Linked<IHqlExpression> LinkedHqlExpr;
  1084. typedef Owned<IHqlExpression> OwnedHqlExpr;
  1085. struct OwnedHqlExprItem : public CInterface
  1086. {
  1087. OwnedHqlExpr value;
  1088. };
  1089. extern HQL_API const char *getOpString(node_operator op);
  1090. extern HQL_API IHqlExpression *createValue(node_operator op);
  1091. extern HQL_API IHqlExpression *createValue(node_operator op, IHqlExpression *p1, IHqlExpression *p2);
  1092. extern HQL_API IHqlExpression *createOpenValue(node_operator op, ITypeInfo *type);
  1093. extern HQL_API IHqlExpression *createOpenNamedValue(node_operator op, ITypeInfo *type, _ATOM name);
  1094. extern HQL_API IHqlExpression *createNamedValue(node_operator op, ITypeInfo *type, _ATOM name, HqlExprArray & args);
  1095. extern HQL_API IHqlExpression *createValue(node_operator op, ITypeInfo * type);
  1096. extern HQL_API IHqlExpression *createValue(node_operator op, ITypeInfo * type, IHqlExpression *p1);
  1097. extern HQL_API IHqlExpression *createValue(node_operator op, ITypeInfo * type, IHqlExpression *p1, IHqlExpression *p2);
  1098. extern HQL_API IHqlExpression *createValue(node_operator op, ITypeInfo * type, IHqlExpression *p1, IHqlExpression *p2, IHqlExpression *p3);
  1099. extern HQL_API IHqlExpression *createValue(node_operator op, ITypeInfo * type, IHqlExpression *p1, IHqlExpression *p2, IHqlExpression *p3, IHqlExpression *p4);
  1100. extern HQL_API IHqlExpression *createValueF(node_operator op, ITypeInfo * type, ...);
  1101. extern HQL_API IHqlExpression *createValue(node_operator op, ITypeInfo * type, unsigned num, IHqlExpression * * args);
  1102. extern HQL_API IHqlExpression *createValue(node_operator op, ITypeInfo * type, HqlExprArray & args); //NB: This deletes the array that is passed
  1103. extern HQL_API IHqlExpression *createValueSafe(node_operator op, ITypeInfo * type, const HqlExprArray & args);
  1104. extern HQL_API IHqlExpression *createValueSafe(node_operator op, ITypeInfo * type, const HqlExprArray & args, unsigned from, unsigned max);
  1105. extern HQL_API IHqlExpression *createValueFromList(node_operator op, ITypeInfo * type, ...);
  1106. extern HQL_API IHqlExpression *createValueFromCommaList(node_operator op, ITypeInfo * type, IHqlExpression * argsExpr);
  1107. //These all consume their arguments
  1108. extern HQL_API IHqlExpression *createWrapper(node_operator op, IHqlExpression * expr);
  1109. extern HQL_API IHqlExpression *createWrapper(node_operator op, IHqlExpression * e, IHqlExpression * arg);
  1110. extern HQL_API IHqlExpression *createWrapper(node_operator op, HqlExprArray & args);
  1111. extern HQL_API IHqlExpression *createWrapper(node_operator op, ITypeInfo * type, HqlExprArray & args);
  1112. //This doesn't consume its argument!
  1113. extern HQL_API IHqlExpression *createWrappedExpr(IHqlExpression * expr, node_operator op, HqlExprArray & args);
  1114. extern HQL_API IHqlExpression *createAlienType(_ATOM, IHqlScope *);
  1115. extern HQL_API IHqlExpression *createAlienType(_ATOM name, IHqlScope * scope, HqlExprArray &newkids, IHqlExpression * funcdef=NULL);
  1116. extern HQL_API IHqlExpression *createEnumType(ITypeInfo * _type, IHqlScope *_scope);
  1117. extern HQL_API IHqlExpression *createBoolExpr(node_operator op, IHqlExpression *p1);
  1118. extern HQL_API IHqlExpression *createBoolExpr(node_operator op, IHqlExpression *p1, IHqlExpression *p2);
  1119. extern HQL_API IHqlExpression *createBoolExpr(node_operator op, IHqlExpression *p1, IHqlExpression *p2, IHqlExpression *p3);
  1120. extern HQL_API IHqlExpression *createBoolExpr(node_operator op, IHqlExpression *p1, IHqlExpression *p2, IHqlExpression *p3, IHqlExpression *p4);
  1121. extern HQL_API IHqlExpression *createList(node_operator op, ITypeInfo *type, IHqlExpression *p1);
  1122. extern HQL_API IHqlExpression *createBinaryList(node_operator op, HqlExprArray & args);
  1123. extern HQL_API IHqlExpression *createLeftBinaryList(node_operator op, HqlExprArray & args);
  1124. extern HQL_API IHqlExpression *createField(_ATOM name, ITypeInfo *type, IHqlExpression *defaultValue, IHqlExpression *attrs=NULL);
  1125. extern HQL_API IHqlExpression *createField(IAtom *name, ITypeInfo *type, HqlExprArray & args);
  1126. extern HQL_API IHqlExpression *createConstant(bool constant);
  1127. extern HQL_API IHqlExpression *createConstant(__int64 constant);
  1128. extern HQL_API IHqlExpression *createConstant(const char *constant);
  1129. extern HQL_API IHqlExpression *createConstant(double constant);
  1130. extern HQL_API IHqlExpression *createConstant(IValue * constant);
  1131. extern HQL_API IHqlExpression *createConstant(__int64 constant, ITypeInfo * ownedType);
  1132. extern HQL_API IHqlExpression *createDataset(node_operator op, IHqlExpression *dataset);
  1133. extern HQL_API IHqlExpression *createDataset(node_operator op, IHqlExpression *dataset, IHqlExpression *elist);
  1134. extern HQL_API IHqlExpression *createDataset(node_operator op, HqlExprArray & parms); // inScope should only be set internally.
  1135. extern HQL_API IHqlExpression *createDatasetF(node_operator op, ...);
  1136. extern HQL_API IHqlExpression *createNewDataset(IHqlExpression *name, IHqlExpression *recorddef, IHqlExpression *mode, IHqlExpression *parent, IHqlExpression *joinCondition, IHqlExpression * options = NULL);
  1137. extern HQL_API IHqlExpression *createRow(node_operator op, IHqlExpression *Dataset, IHqlExpression *element = NULL);
  1138. extern HQL_API IHqlExpression *createRow(node_operator op, HqlExprArray & args);
  1139. extern HQL_API IHqlExpression *createRowF(node_operator op, ...);
  1140. extern HQL_API IHqlExpression *createRecord();
  1141. extern HQL_API IHqlExpression *createRecord(const HqlExprArray & fields);
  1142. extern HQL_API IHqlExpression *createExternalReference(_ATOM name, ITypeInfo *_type, IHqlExpression *props);
  1143. extern HQL_API IHqlExpression *createExternalReference(_ATOM name, ITypeInfo *_type, HqlExprArray & attributes);
  1144. HQL_API IHqlExpression * createExternalFuncdefFromInternal(IHqlExpression * funcdef);
  1145. extern HQL_API IHqlExpression *createBoundFunction(IErrorReceiver * errors, IHqlExpression *func, HqlExprArray & ownedActuals, HqlExprArray * functionCache, bool forceExpansion);
  1146. extern HQL_API IHqlExpression *createReboundFunction(IHqlExpression *func, HqlExprArray & ownedActuals);
  1147. extern HQL_API IHqlExpression *createTranslatedExternalCall(IErrorReceiver * errors, IHqlExpression *func, HqlExprArray &actuals);
  1148. extern HQL_API IHqlExpression *createParameter(_ATOM name, unsigned idx, ITypeInfo *type, HqlExprArray & args);
  1149. extern HQL_API IHqlExpression *createDatasetFromRow(IHqlExpression * ownedRow);
  1150. extern HQL_API IHqlExpression * createTypedValue(node_operator op, ITypeInfo * type, HqlExprArray & args);
  1151. extern HQL_API IHqlExpression * createTypeTransfer(IHqlExpression * expr, ITypeInfo * newType); //arguments must be linked
  1152. extern HQL_API IHqlExpression * expandOutOfLineFunctionCall(IHqlExpression * expr);
  1153. extern HQL_API void expandDelayedFunctionCalls(IErrorReceiver * errors, HqlExprArray & exprs);
  1154. extern HQL_API IHqlExpression *createQuoted(const char * name, ITypeInfo *type);
  1155. extern HQL_API IHqlExpression *createVariable(const char * name, ITypeInfo *type);
  1156. extern HQL_API IHqlExpression * createSymbol(_ATOM name, IHqlExpression *expr, unsigned exportFlags);
  1157. extern HQL_API IHqlExpression * createSymbol(_ATOM _name, _ATOM _module, IHqlExpression *_expr, bool _exported, bool _shared, unsigned _flags);
  1158. extern HQL_API IHqlExpression * createSymbol(_ATOM _name, _ATOM moduleName, IHqlExpression *expr, IHqlExpression * funcdef,
  1159. bool exported, bool shared, unsigned symbolFlags,
  1160. IFileContents *fc, int lineno, int column, int _startpos, int _bodypos, int _endpos);
  1161. extern HQL_API IHqlExpression *createAttribute(_ATOM name, IHqlExpression * value = NULL, IHqlExpression * value2 = NULL, IHqlExpression * value3 = NULL);
  1162. extern HQL_API IHqlExpression *createAttribute(_ATOM name, HqlExprArray & args);
  1163. extern HQL_API IHqlExpression *createExprAttribute(_ATOM name, IHqlExpression * value = NULL, IHqlExpression * value2 = NULL, IHqlExpression * value3 = NULL);
  1164. extern HQL_API IHqlExpression *createExprAttribute(_ATOM name, HqlExprArray & args);
  1165. extern HQL_API IHqlExpression *createLinkAttribute(_ATOM name, IHqlExpression * value = NULL, IHqlExpression * value2 = NULL, IHqlExpression * value3 = NULL);
  1166. extern HQL_API IHqlExpression *createLinkAttribute(_ATOM name, HqlExprArray & args);
  1167. extern HQL_API IHqlExpression *createUnknown(node_operator op, ITypeInfo * type, _ATOM name, IInterface * value);
  1168. extern HQL_API IHqlExpression *createSequence(node_operator op, ITypeInfo * type, _ATOM name, unsigned __int64 value);
  1169. extern HQL_API IHqlExpression *createCompareExpr(node_operator op, IHqlExpression * l, IHqlExpression * r);
  1170. extern HQL_API IHqlExpression * createAliasOwn(IHqlExpression * expr, IHqlExpression * attr);
  1171. inline IHqlExpression * createAlias(IHqlExpression * expr, IHqlExpression * attr) { return createAliasOwn(LINK(expr), LINK(attr)); }
  1172. extern HQL_API IHqlExpression * createLocationAnnotation(IHqlExpression * _ownedBody, const ECLlocation & _location);
  1173. extern HQL_API IHqlExpression * createLocationAnnotation(IHqlExpression * ownedBody, ISourcePath * sourcePath, int lineno, int column);
  1174. extern HQL_API IHqlExpression * createMetaAnnotation(IHqlExpression * _ownedBody, HqlExprArray & _args);
  1175. extern HQL_API IHqlExpression * createParseMetaAnnotation(IHqlExpression * _ownedBody, HqlExprArray & _args);
  1176. extern HQL_API IHqlExpression * createWarningAnnotation(IHqlExpression * _ownedBody, IECLError * _ownedWarning);
  1177. extern HQL_API IHqlExpression * createJavadocAnnotation(IHqlExpression * _ownedBody, IPropertyTree * _doc);
  1178. extern HQL_API IHqlExpression * createCompound(IHqlExpression * expr1, IHqlExpression * expr2);
  1179. extern HQL_API IHqlExpression * createCompound(const HqlExprArray & actions);
  1180. extern HQL_API IHqlExpression * createCompound(node_operator op, const HqlExprArray & actions);
  1181. extern HQL_API IHqlExpression * createActionList(const HqlExprArray & actions);
  1182. extern HQL_API IHqlExpression * createActionList(const HqlExprArray & actions, unsigned from, unsigned to);
  1183. extern HQL_API IHqlExpression * createComma(IHqlExpression * expr1, IHqlExpression * expr2);
  1184. extern HQL_API IHqlExpression * createComma(IHqlExpression * expr1, IHqlExpression * expr2, IHqlExpression * expr3);
  1185. extern HQL_API IHqlExpression * createComma(IHqlExpression * expr1, IHqlExpression * expr2, IHqlExpression * expr3, IHqlExpression * expr4);
  1186. extern HQL_API IHqlExpression * createComma(const HqlExprArray & exprs);
  1187. extern HQL_API IHqlExpression * createBalanced(node_operator op, ITypeInfo * type, const HqlExprArray & exprs);
  1188. extern HQL_API IHqlExpression * createBalanced(node_operator op, ITypeInfo * type, const HqlExprArray & exprs, unsigned first, unsigned last);
  1189. extern HQL_API IHqlExpression * createUnbalanced(node_operator op, ITypeInfo * type, const HqlExprArray & exprs);
  1190. extern HQL_API IHqlExpression * createAssign(IHqlExpression * expr1, IHqlExpression * expr2);
  1191. extern HQL_API void ensureActions(HqlExprArray & actions);
  1192. extern HQL_API void ensureActions(HqlExprArray & actions, unsigned first, unsigned last);
  1193. extern HQL_API IHqlExpression * extendConditionOwn(node_operator op, IHqlExpression * l, IHqlExpression * r);
  1194. inline IHqlExpression * extendCondition(node_operator op, IHqlExpression * l, IHqlExpression * r)
  1195. {
  1196. return extendConditionOwn(op, LINK(l), LINK(r));
  1197. }
  1198. IHqlExpression * attachWorkflowOwn(HqlExprArray & meta, IHqlExpression * value, IHqlExpression * workflow, const HqlExprCopyArray * allActiveParameters);
  1199. extern HQL_API IHqlExpression * createNullExpr(ITypeInfo * type);
  1200. extern HQL_API IHqlExpression * createNullExpr(IHqlExpression * expr);
  1201. extern HQL_API IValue * createNullValue(ITypeInfo * type);
  1202. extern HQL_API IHqlExpression * createNullScope();
  1203. extern HQL_API IHqlExpression * createPureVirtual(ITypeInfo * type);
  1204. extern HQL_API IHqlExpression * cloneOrLink(IHqlExpression * expr, HqlExprArray & children);
  1205. extern HQL_API IHqlExpression * createConstantOne();
  1206. extern HQL_API IHqlExpression * createLocalAttribute();
  1207. extern HQL_API bool isNullExpr(IHqlExpression * expr, ITypeInfo * type);
  1208. inline bool isNull(IHqlExpression * expr) { return expr->getOperator() == no_null; }
  1209. inline bool isFail(IHqlExpression * expr) { return expr->getOperator() == no_fail; }
  1210. extern HQL_API IHqlExpression * createDelayedReference(node_operator op, IHqlExpression * moduleMarker, IHqlExpression * attr, bool ignoreBase);
  1211. extern HQL_API IHqlExpression * createLibraryInstance(IHqlExpression * scopeFunction, HqlExprArray &operands);
  1212. extern HQL_API IHqlExpression* createValue(node_operator op, ITypeInfo *type, HqlExprArray& operands);
  1213. extern HQL_API IHqlExpression* createValue(node_operator op, HqlExprArray& operands);
  1214. extern HQL_API IHqlExpression *createValue(node_operator op, IHqlExpression *p1);
  1215. extern HQL_API IHqlExpression* createConstant(int ival);
  1216. extern HQL_API IHqlExpression* createBoolExpr(node_operator op, HqlExprArray& operands);
  1217. extern HQL_API IHqlExpression* createSelectExpr(IHqlExpression * lhs, IHqlExpression * rhs, bool isNew);
  1218. inline IHqlExpression* createSelectExpr(IHqlExpression * lhs, IHqlExpression * rhs) { return createSelectExpr(lhs, rhs, false); }
  1219. inline IHqlExpression* createNewSelectExpr(IHqlExpression * lhs, IHqlExpression * rhs) { return createSelectExpr(lhs, rhs, true); }
  1220. extern HQL_API IHqlExpression* createSelectExpr(HqlExprArray & args);
  1221. inline IHqlExpression* createAction(node_operator op, HqlExprArray& operands) { return createValue(op, makeVoidType(), operands); }
  1222. // Helper functions for retreiving meta information about a node.
  1223. extern HQL_API bool definesColumnList(IHqlExpression * dataset);
  1224. extern HQL_API unsigned getNumChildTables(IHqlExpression * dataset);
  1225. extern HQL_API bool isAggregateDataset(IHqlExpression * expr);
  1226. extern HQL_API bool isAggregatedDataset(IHqlExpression * expr);
  1227. extern HQL_API bool datasetHasGroupBy(IHqlExpression * expr);
  1228. extern HQL_API IHqlExpression *queryDatasetGroupBy(IHqlExpression * expr);
  1229. extern HQL_API bool hasSingleRow(IHqlExpression * expr);
  1230. extern HQL_API bool hasFewRows(IHqlExpression * expr);
  1231. extern HQL_API node_operator queryHasRows(IHqlExpression * expr);
  1232. extern HQL_API void queryRemoveRows(HqlExprCopyArray & tables, IHqlExpression * expr, IHqlExpression * left, IHqlExpression * right);
  1233. extern HQL_API bool isPureActivity(IHqlExpression * expr);
  1234. extern HQL_API bool isPureActivityIgnoringSkip(IHqlExpression * expr);
  1235. extern HQL_API bool isPureInlineDataset(IHqlExpression * expr);
  1236. extern HQL_API bool transformHasSkipAttr(IHqlExpression * transform);
  1237. extern HQL_API IHqlExpression * queryNewColumnProvider(IHqlExpression * expr); // what is the transform/newtransform/record?
  1238. extern HQL_API unsigned queryTransformIndex(IHqlExpression * expr);
  1239. extern HQL_API bool isKnownTransform(IHqlExpression * transform);
  1240. extern HQL_API bool hasUnknownTransform(IHqlExpression * expr);
  1241. // Some Helper functions for processing the tree
  1242. extern HQL_API IHqlExpression * ensureExprType(IHqlExpression * expr, ITypeInfo * type);
  1243. extern HQL_API IHqlExpression * ensureExprType(IHqlExpression * expr, ITypeInfo * type, node_operator castOp);
  1244. extern HQL_API IHqlExpression * normalizeListCasts(IHqlExpression * expr);
  1245. extern HQL_API IHqlExpression * simplifyFixedLengthList(IHqlExpression * expr);
  1246. extern HQL_API IHqlExpression * getCastExpr(IHqlExpression * expr, ITypeInfo * type);
  1247. extern HQL_API void parseModule(IHqlScope *scope, IFileContents * contents, HqlLookupContext & ctx, IXmlScope *xmlScope, bool loadImplicit);
  1248. extern HQL_API IHqlExpression *parseQuery(IHqlScope *scope, IFileContents * contents,
  1249. HqlLookupContext & ctx, IXmlScope *xmlScope, bool loadImplicit);
  1250. extern HQL_API IHqlExpression *parseQuery(const char *in, IErrorReceiver * errs);
  1251. extern HQL_API IPropertyTree * gatherAttributeDependencies(IEclRepository * dataServer, const char * items = NULL);
  1252. extern HQL_API IHqlScope *createService();
  1253. extern HQL_API IHqlScope *createDatabase(IHqlExpression * name);
  1254. extern HQL_API IHqlScope *createScope();
  1255. extern HQL_API IHqlScope *createConcreteScope();
  1256. extern HQL_API IHqlScope *createForwardScope(IHqlScope * parentScope, HqlGramCtx * parentCtx, HqlParseContext & parseCtx);
  1257. extern HQL_API IHqlScope *createLibraryScope();
  1258. extern HQL_API IHqlScope *createVirtualScope();
  1259. extern HQL_API IHqlScope* createVirtualScope(_ATOM name, const char * fullName);
  1260. extern HQL_API IHqlScope *createScope(node_operator op);
  1261. extern HQL_API IHqlScope *createScope(IHqlScope * scope);
  1262. extern HQL_API IHqlScope *createPrivateScope();
  1263. extern HQL_API IHqlScope *createPrivateScope(IHqlScope * scope);
  1264. extern HQL_API IHqlRemoteScope *createRemoteScope(_ATOM name, const char * fullName, IEclRepositoryCallback *ds, IProperties* props, IFileContents * _text, bool lazy, IEclSource * eclSource);
  1265. extern HQL_API IHqlExpression * populateScopeAndClose(IHqlScope * scope, const HqlExprArray & children, const HqlExprArray & symbols);
  1266. extern HQL_API IHqlScope* createContextScope();
  1267. extern HQL_API IHqlExpression* createTemplateFunctionContext(IHqlExpression* body, IHqlScope* helperScope);
  1268. extern HQL_API IHqlExpression* createFieldMap(IHqlExpression*, IHqlExpression*);
  1269. extern HQL_API IHqlExpression * createNullDataset(IHqlExpression * ds);
  1270. extern HQL_API IHqlExpression * ensureDataset(IHqlExpression * expr);
  1271. extern HQL_API node_operator getInverseOp(node_operator op);
  1272. extern HQL_API node_operator getReverseOp(node_operator op);
  1273. extern HQL_API bool isKeyedJoin(IHqlExpression * expr);
  1274. extern HQL_API bool isSelfJoin(IHqlExpression * expr);
  1275. extern HQL_API bool isInnerJoin(IHqlExpression * expr);
  1276. extern HQL_API bool isFullJoin(IHqlExpression * expr);
  1277. extern HQL_API bool isLeftJoin(IHqlExpression * expr);
  1278. extern HQL_API bool isRightJoin(IHqlExpression * expr);
  1279. extern HQL_API bool isSimpleInnerJoin(IHqlExpression * expr);
  1280. extern HQL_API _ATOM queryJoinKind(IHqlExpression * expr);
  1281. inline bool isSpecificJoin(IHqlExpression * expr, _ATOM leftRightKind) { return queryJoinKind(expr) == leftRightKind; }
  1282. extern HQL_API bool isLimitedJoin(IHqlExpression * expr);
  1283. extern HQL_API bool isGroupedActivity(IHqlExpression * expr);
  1284. extern HQL_API bool isLocalActivity(IHqlExpression * expr);
  1285. extern HQL_API bool localChangesActivity(IHqlExpression * expr);
  1286. extern HQL_API bool localChangesActivityData(IHqlExpression * expr);
  1287. extern HQL_API bool localChangesActivityAction(IHqlExpression * expr);
  1288. extern HQL_API bool isInImplictScope(IHqlExpression * scope, IHqlExpression * dataset);
  1289. extern HQL_API bool isLimitedDataset(IHqlExpression * expr, bool onFailOnly=false);
  1290. extern HQL_API IHqlExpression * queryJoinRhs(IHqlExpression * expr);
  1291. extern HQL_API void lockTransformMutex();
  1292. extern HQL_API void unlockTransformMutex();
  1293. extern HQL_API void PrintLogExprTree(IHqlExpression *expr, const char *caption = NULL, bool full = false);
  1294. extern HQL_API IHqlExpression *doInstantEclTransformations(IHqlExpression *qquery, unsigned limit);
  1295. //extern HQL_API void loadImplicitScopes(IEclRepository &dataServer, HqlScopeArray &defualtScopes, int suppress, _ATOM suppressName);
  1296. extern HQL_API unsigned getExpressionCRC(IHqlExpression * expr);
  1297. extern HQL_API IHqlExpression * queryPropertyInList(_ATOM search, IHqlExpression * cur);
  1298. extern HQL_API IHqlExpression * queryProperty(_ATOM search, const HqlExprArray & exprs);
  1299. extern HQL_API IHqlExpression * queryAnnotation(IHqlExpression * expr, annotate_kind search); // return first match
  1300. extern HQL_API IHqlNamedAnnotation * queryNameAnnotation(IHqlExpression * expr);
  1301. inline bool hasAnnotation(IHqlExpression * expr, annotate_kind search){ return queryAnnotation(expr, search) != NULL; }
  1302. inline IHqlExpression * queryNamedSymbol(IHqlExpression * expr) { return queryAnnotation(expr, annotate_symbol); }
  1303. inline bool hasNamedSymbol(IHqlExpression * expr) { return hasAnnotation(expr, annotate_symbol); }
  1304. inline bool hasProperty(_ATOM search, HqlExprArray & exprs) { return queryProperty(search, exprs) != NULL; }
  1305. extern HQL_API IHqlExpression * queryAnnotationProperty(_ATOM search, IHqlExpression * annotation);
  1306. extern HQL_API IHqlExpression * queryMetaProperty(_ATOM search, IHqlExpression * expr);
  1307. extern HQL_API void gatherMetaProperties(HqlExprArray & matches, _ATOM search, IHqlExpression * expr);
  1308. extern HQL_API void gatherMetaProperties(HqlExprCopyArray & matches, _ATOM search, IHqlExpression * expr);
  1309. extern HQL_API IHqlExpression * queryLocation(IHqlExpression * expr);
  1310. extern HQL_API void gatherLocations(HqlExprCopyArray & matches, IHqlExpression * expr);
  1311. extern HQL_API bool okToAddAnnotation(IHqlExpression * expr);
  1312. extern HQL_API bool okToAddLocation(IHqlExpression *);
  1313. extern HQL_API IHqlExpression * cloneAnnotationKind(IHqlExpression * donor, IHqlExpression * expr, annotate_kind search);
  1314. extern HQL_API IHqlExpression * cloneInheritedAnnotations(IHqlExpression * donor, IHqlExpression * expr);
  1315. extern HQL_API IHqlExpression * cloneMissingAnnotations(IHqlExpression * donor, IHqlExpression * body);
  1316. extern HQL_API IHqlExpression * forceCloneSymbol(IHqlExpression * donor, IHqlExpression * expr);
  1317. // donor must be a symbol. Any of the other arguments can be null to inherit the existing values
  1318. extern HQL_API IHqlExpression * cloneSymbol(IHqlExpression * donor, _ATOM optnewname, IHqlExpression * optnewbody, IHqlExpression * optnewfuncdef, HqlExprArray * optoperands);
  1319. extern HQL_API IHqlExpression * queryOperatorInList(node_operator search, IHqlExpression * cur);
  1320. extern HQL_API IHqlExpression * queryOperator(node_operator search, const HqlExprArray & args);
  1321. extern HQL_API IHqlExpression * queryRoot(IHqlExpression * dataset);
  1322. extern HQL_API IHqlExpression * queryTable(IHqlExpression * dataset);
  1323. extern HQL_API node_operator queryTableMode(IHqlExpression * expr);
  1324. // Code for producing simplified records that the file viewer can cope with
  1325. extern HQL_API ITypeInfo * getSimplifiedType(ITypeInfo * type, bool isConditional, bool isSerialized);
  1326. extern HQL_API IHqlExpression * getSimplifiedRecord(IHqlExpression * record, bool isKey);
  1327. extern HQL_API IHqlExpression * getRecordMappingTransform(node_operator op, IHqlExpression * tgt, IHqlExpression * src, IHqlExpression * sourceSelector);
  1328. extern HQL_API IHqlExpression * getSimplifiedTransform(IHqlExpression * tgt, IHqlExpression * src, IHqlExpression * sourceSelector);
  1329. extern HQL_API IHqlExpression * removeVirtualAttributes(IHqlExpression * record);
  1330. extern HQL_API bool isSimplifiedRecord(IHqlExpression * expr, bool isKey);
  1331. extern HQL_API void unwindChildren(HqlExprArray & children, IHqlExpression * expr);
  1332. extern HQL_API void unwindChildren(HqlExprArray & children, const IHqlExpression * expr, unsigned first);
  1333. extern HQL_API void unwindChildren(HqlExprArray & children, const IHqlExpression * expr, unsigned from, unsigned to);
  1334. extern HQL_API void unwindChildren(HqlExprCopyArray & children, const IHqlExpression * expr, unsigned first=0);
  1335. extern HQL_API void unwindRealChildren(HqlExprArray & children, const IHqlExpression * expr, unsigned first);
  1336. extern HQL_API void unwindAttributes(HqlExprArray & children, const IHqlExpression * expr);
  1337. extern HQL_API void unwindList(HqlExprArray &dst, IHqlExpression * expr, node_operator op);
  1338. extern HQL_API void unwindCopyList(HqlExprCopyArray &dst, IHqlExpression * expr, node_operator op);
  1339. extern HQL_API void unwindCommaCompound(HqlExprArray & target, IHqlExpression * expr);
  1340. extern HQL_API void unwindRecordAsSelects(HqlExprArray & children, IHqlExpression * record, IHqlExpression * ds, unsigned max = (unsigned)-1);
  1341. extern HQL_API unsigned unwoundCount(IHqlExpression * expr, node_operator op);
  1342. extern HQL_API void unwindProperty(HqlExprArray & args, IHqlExpression * expr, _ATOM name);
  1343. extern HQL_API IHqlExpression * queryChildOperator(node_operator op, IHqlExpression * expr);
  1344. extern HQL_API IHqlExpression * createSelector(node_operator op, IHqlExpression * ds, IHqlExpression * seq);
  1345. extern HQL_API IHqlExpression * createUniqueId();
  1346. extern HQL_API IHqlExpression * createUniqueRowsId();
  1347. extern HQL_API IHqlExpression * createCounter();
  1348. extern HQL_API IHqlExpression * createSelectorSequence();
  1349. extern HQL_API IHqlExpression * createSequenceExpr();
  1350. extern HQL_API IHqlExpression * createUniqueSelectorSequence();
  1351. extern HQL_API IHqlExpression * createDummySelectorSequence();
  1352. extern HQL_API IHqlExpression * expandBetween(IHqlExpression * expr);
  1353. extern HQL_API bool isAlwaysActiveRow(IHqlExpression * expr);
  1354. extern HQL_API IHqlExpression * ensureActiveRow(IHqlExpression * expr);
  1355. extern HQL_API bool isIndependentOfScope(IHqlExpression * expr);
  1356. extern HQL_API bool isActivityIndependentOfScope(IHqlExpression * expr);
  1357. extern HQL_API bool exprReferencesDataset(IHqlExpression * expr, IHqlExpression * dataset);
  1358. extern HQL_API bool canEvaluateInScope(const HqlExprCopyArray & activeScopes, IHqlExpression * expr);
  1359. extern HQL_API bool canEvaluateInScope(const HqlExprCopyArray & activeScopes, const HqlExprCopyArray & required);
  1360. extern HQL_API IHqlExpression * ensureDeserialized(IHqlExpression * expr, ITypeInfo * type);
  1361. extern HQL_API IHqlExpression * ensureSerialized(IHqlExpression * expr);
  1362. extern HQL_API bool isDummySerializeDeserialize(IHqlExpression * expr);
  1363. extern HQL_API unsigned getRepeatMax(IHqlExpression * expr);
  1364. extern HQL_API unsigned getRepeatMin(IHqlExpression * expr);
  1365. extern HQL_API bool isStandardRepeat(IHqlExpression * expr);
  1366. extern HQL_API bool transformContainsCounter(IHqlExpression * transform, IHqlExpression * counter);
  1367. extern HQL_API bool preservesValue(ITypeInfo * after, IHqlExpression * expr);
  1368. extern HQL_API IHqlExpression * getActiveTableSelector();
  1369. extern HQL_API IHqlExpression * queryActiveTableSelector();
  1370. extern HQL_API IHqlExpression * getSelf(IHqlExpression * ds);
  1371. extern HQL_API IHqlExpression * querySelfReference();
  1372. extern HQL_API bool removeProperty(HqlExprArray & args, _ATOM name);
  1373. extern HQL_API void removeProperties(HqlExprArray & args);
  1374. extern HQL_API bool isChildRelationOf(IHqlExpression * child, IHqlExpression * other);
  1375. extern HQL_API IHqlExpression * queryRecord(ITypeInfo * type);
  1376. extern HQL_API unsigned numPayloadFields(IHqlExpression * index);
  1377. extern HQL_API unsigned firstPayloadField(IHqlExpression * index);
  1378. extern HQL_API unsigned firstPayloadField(IHqlExpression * record, unsigned numPayloadFields);
  1379. extern HQL_API unsigned numKeyedFields(IHqlExpression * index);
  1380. extern HQL_API bool isSortDistribution(IHqlExpression * distribution);
  1381. extern HQL_API bool isChooseNAllLimit(IHqlExpression * limit);
  1382. extern HQL_API bool isZero(IHqlExpression * expr);
  1383. extern HQL_API bool isSelectFirstRow(IHqlExpression * expr);
  1384. extern HQL_API IHqlExpression * queryTransformSingleAssign(IHqlExpression * expr);
  1385. extern HQL_API IHqlExpression * convertToSimpleAggregate(IHqlExpression * expr); // return NULL if doesn't make sense
  1386. extern HQL_API node_operator querySimpleAggregate(IHqlExpression * expr, bool canFilterArg, bool canCast);
  1387. extern HQL_API node_operator querySingleAggregate(IHqlExpression * expr, bool canFilterArg, bool canBeGrouped, bool canCast);
  1388. extern HQL_API bool isSimpleCountAggregate(IHqlExpression * aggregateExpr, bool canFilterArg);
  1389. extern HQL_API bool isSimpleCountExistsAggregate(IHqlExpression * aggregateExpr, bool canFilterArg, bool canCast);
  1390. extern HQL_API bool isKeyedCountAggregate(IHqlExpression * aggregate);
  1391. extern HQL_API IHqlExpression * createNullDataset();
  1392. extern HQL_API IHqlExpression * queryNullRecord();
  1393. extern HQL_API IHqlExpression * queryNullRowRecord();
  1394. extern HQL_API IHqlExpression * queryExpression(ITypeInfo * t);
  1395. extern HQL_API IHqlExpression * queryExpression(IHqlDataset * ds);
  1396. inline IHqlExpression * queryExpression(IHqlScope * scope) { return scope ? scope->queryExpression() : NULL; }
  1397. extern HQL_API IHqlScope * queryScope(ITypeInfo * t);
  1398. extern HQL_API IHqlRemoteScope * queryRemoteScope(IHqlScope * scope);
  1399. extern HQL_API IHqlAlienTypeInfo * queryAlienType(ITypeInfo * t);
  1400. extern HQL_API bool includeChildInDependents(IHqlExpression * expr, unsigned which);
  1401. extern HQL_API IHqlExpression * extractFieldAttrs(IHqlExpression * field);
  1402. extern HQL_API IHqlExpression * extractAttrsFromExpr(IHqlExpression * value);
  1403. extern HQL_API bool isUninheritedFieldAttribute(IHqlExpression * expr);
  1404. extern HQL_API bool hasUninheritedAttribute(IHqlExpression * field);
  1405. extern HQL_API IHqlExpression * extractChildren(IHqlExpression * value);
  1406. extern HQL_API IHqlExpression * queryOnlyField(IHqlExpression * record);
  1407. extern HQL_API bool recordTypesMatch(ITypeInfo * left, ITypeInfo * right);
  1408. extern HQL_API bool recordTypesMatch(IHqlExpression * left, IHqlExpression * right);
  1409. extern HQL_API IHqlExpression * queryOriginalRecord(IHqlExpression * expr);
  1410. extern HQL_API IHqlExpression * queryOriginalRecord(ITypeInfo * type);
  1411. extern HQL_API IHqlExpression * queryOriginalTypeExpression(ITypeInfo * type);
  1412. extern HQL_API ITypeInfo * createRecordType(IHqlExpression * record);
  1413. extern HQL_API bool isTargetSelector(IHqlExpression * expr);
  1414. extern HQL_API IHqlExpression * queryDatasetCursor(IHqlExpression * ds);
  1415. extern HQL_API IHqlExpression * querySelectorDataset(IHqlExpression * select, bool & isNew);
  1416. extern HQL_API IHqlExpression * replaceSelectorDataset(IHqlExpression * expr, IHqlExpression * newDataset);
  1417. extern HQL_API IHqlExpression * querySkipDatasetMeta(IHqlExpression * dataset);
  1418. extern HQL_API bool isNewSelector(IHqlExpression * expr);
  1419. extern HQL_API IHqlExpression * queryRecordProperty(IHqlExpression * record, _ATOM name);
  1420. extern HQL_API bool isExported(IHqlExpression * expr);
  1421. extern HQL_API bool isShared(IHqlExpression * expr);
  1422. extern HQL_API bool isImport(IHqlExpression * expr);
  1423. extern HQL_API bool isPublicSymbol(IHqlExpression * expr);
  1424. extern HQL_API ITypeInfo * getSumAggType(IHqlExpression * arg);
  1425. extern HQL_API ITypeInfo * getSumAggType(ITypeInfo * argType);
  1426. extern HQL_API bool getProperty(IHqlExpression * expr, _ATOM propName, StringBuffer & ret);
  1427. extern HQL_API bool filterIsKeyed(IHqlExpression * expr);
  1428. extern HQL_API bool filterIsUnkeyed(IHqlExpression * expr);
  1429. extern HQL_API bool canEvaluateGlobally(IHqlExpression * expr);
  1430. extern HQL_API bool isTrivialDataset(IHqlExpression * expr);
  1431. extern HQL_API bool isInlineTrivialDataset(IHqlExpression * expr);
  1432. extern HQL_API void gatherChildTablesUsed(HqlExprCopyArray * newScope, HqlExprCopyArray * inScope, IHqlExpression * expr, unsigned firstChild);
  1433. extern HQL_API IHqlScope * closeScope(IHqlScope * scope);
  1434. extern HQL_API _ATOM queryPatternName(IHqlExpression * expr);
  1435. extern HQL_API IHqlExpression * closeAndLink(IHqlExpression * expr);
  1436. extern HQL_API IHqlExpression * createAbstractRecord(IHqlExpression * record);
  1437. extern HQL_API IHqlExpression * createSortList(HqlExprArray & elements);
  1438. // Same as expr->queryChild() except it doesn't return attributes.
  1439. inline IHqlExpression * queryRealChild(IHqlExpression * expr, unsigned i)
  1440. {
  1441. IHqlExpression * temp = expr->queryChild(i);
  1442. if (temp && !temp->isAttribute())
  1443. return temp;
  1444. return NULL;
  1445. }
  1446. inline bool isCast(IHqlExpression * expr)
  1447. {
  1448. node_operator op = expr->getOperator();
  1449. return (op == no_cast) || (op == no_implicitcast);
  1450. }
  1451. extern HQL_API bool isKey(IHqlExpression * expr);
  1452. inline IHqlExpression * queryGrouping(ITypeInfo * type) { return static_cast<IHqlExpression *>(type->queryGroupInfo()); }
  1453. inline IHqlExpression * queryDistribution(ITypeInfo * type) { return static_cast<IHqlExpression *>(type->queryDistributeInfo()); }
  1454. inline IHqlExpression * queryGlobalSortOrder(ITypeInfo * type) { return static_cast<IHqlExpression *>(type->queryGlobalSortInfo()); }
  1455. inline IHqlExpression * queryLocalUngroupedSortOrder(ITypeInfo * type) { return static_cast<IHqlExpression *>(type->queryLocalUngroupedSortInfo()); }
  1456. inline IHqlExpression * queryGroupSortOrder(ITypeInfo * type) { return static_cast<IHqlExpression *>(type->queryGroupSortInfo()); }
  1457. inline IHqlExpression * queryGrouping(IHqlExpression * expr) { return queryGrouping(expr->queryType()); }
  1458. inline IHqlExpression * queryDistribution(IHqlExpression * expr) { return queryDistribution(expr->queryType()); }
  1459. inline IHqlExpression * queryGlobalSortOrder(IHqlExpression * expr) { return queryGlobalSortOrder(expr->queryType()); }
  1460. inline IHqlExpression * queryLocalUngroupedSortOrder(IHqlExpression * expr) { return queryLocalUngroupedSortOrder(expr->queryType()); }
  1461. inline IHqlExpression * queryGroupSortOrder(IHqlExpression * expr) { return queryGroupSortOrder(expr->queryType()); }
  1462. inline bool isGrouped(ITypeInfo * type) { return type && type->queryGroupInfo() != NULL; }
  1463. inline bool isGrouped(IHqlExpression * expr) { return isGrouped(expr->queryType()); }
  1464. inline IFunctionTypeExtra * queryFunctionTypeExtra(ITypeInfo * type) { return static_cast<IFunctionTypeExtra *>(queryUnqualifiedType(type)->queryModifierExtra()); }
  1465. inline IHqlExpression * queryFunctionParameters(ITypeInfo * type) { return static_cast<IHqlExpression *>(queryFunctionTypeExtra(type)->queryParameters()); }
  1466. inline IHqlExpression * queryFunctionParameterDefaults(ITypeInfo * type) { return static_cast<IHqlExpression *>(queryFunctionTypeExtra(type)->queryDefaults()); }
  1467. inline IHqlExpression * queryFunctionParameters(IHqlExpression * expr) { return queryFunctionParameters(expr->queryType()); }
  1468. extern HQL_API IHqlExpression * queryFunctionDefaults(IHqlExpression * expr);
  1469. inline IHqlExpression * querySelSeq(IHqlExpression * expr)
  1470. {
  1471. return expr->queryProperty(_selectorSequence_Atom);
  1472. }
  1473. extern HQL_API IHqlExpression * createGroupedAttribute(ITypeInfo * type);
  1474. extern HQL_API bool isSameUnqualifiedType(ITypeInfo * l, ITypeInfo * r);
  1475. extern HQL_API bool isSameFullyUnqualifiedType(ITypeInfo * l, ITypeInfo * r);
  1476. //The following are wrappers for the code generator specific getInfoFlags()
  1477. //inline bool isTableInvariant(IHqlExpression * expr) { return (expr->getInfoFlags() & HEFtableInvariant) != 0; }
  1478. inline bool containsActiveDataset(IHqlExpression * expr){ return (expr->getInfoFlags() & HEFcontainsActiveDataset) != 0; }
  1479. inline bool containsActiveNonSelector(IHqlExpression * expr)
  1480. { return (expr->getInfoFlags() & HEFcontainsActiveNonSelector) != 0; }
  1481. inline bool containsNonActiveDataset(IHqlExpression * expr) { return (expr->getInfoFlags() & (HEFcontainsDataset)) != 0; }
  1482. inline bool containsAnyDataset(IHqlExpression * expr) { return (expr->getInfoFlags() & (HEFcontainsDataset|HEFcontainsActiveDataset)) != 0; }
  1483. inline bool containsAlias(IHqlExpression * expr) { return (expr->getInfoFlags() & HEFcontainsAlias) != 0; }
  1484. inline bool containsAliasLocally(IHqlExpression * expr) { return (expr->getInfoFlags() & HEFcontainsAliasLocally) != 0; }
  1485. inline bool containsDatasetAliasLocally(IHqlExpression * expr) { return (expr->getInfoFlags() & HEFcontainsDatasetAliasLocally) != 0; }
  1486. inline bool containsNonGlobalAlias(IHqlExpression * expr)
  1487. { return (expr->getInfoFlags2() & HEF2containsNonGlobalAlias) != 0; }
  1488. inline bool containsAssertKeyed(IHqlExpression * expr) { return (expr->getInfoFlags() & HEFassertkeyed) != 0; }
  1489. inline bool containsAssertStepped(IHqlExpression * expr){ return (expr->getInfoFlags2() & HEF2assertstepped) != 0; }
  1490. inline bool containsCounter(IHqlExpression * expr) { return (expr->getInfoFlags() & HEFcontainsCounter) != 0; }
  1491. inline bool isCountProject(IHqlExpression * expr) { return expr->hasProperty(_countProject_Atom); }
  1492. inline bool containsSkip(IHqlExpression * expr) { return (expr->getInfoFlags() & (HEFcontainsSkip|HEFtransformSkips)) != 0; }
  1493. inline bool isContextDependentExceptGraph(IHqlExpression * expr)
  1494. { return (expr->getInfoFlags() & (HEFcontextDependent & ~HEFgraphDependent)) != 0; }
  1495. inline bool isGraphDependent(IHqlExpression * expr) { return (expr->getInfoFlags() & HEFgraphDependent) != 0; }
  1496. inline bool containsTranslated(IHqlExpression * expr) { return (expr->getInfoFlags() & (HEFtranslated)) != 0; }
  1497. inline bool containsSideEffects(IHqlExpression * expr) { return (expr->getInfoFlags() & (HEFaction|HEFthrowscalar|HEFthrowds)) != 0; }
  1498. inline bool containsInternalVirtual(IHqlExpression * expr) { return (expr->getInfoFlags() & (HEFinternalVirtual)) != 0; }
  1499. inline bool containsThisNode(IHqlExpression * expr) { return (expr->getInfoFlags() & (HEFcontainsThisNode)) != 0; }
  1500. inline bool containsWorkflow(IHqlExpression * expr) { return (expr->getInfoFlags2() & (HEF2workflow)) != 0; }
  1501. inline bool containsMustHoist(IHqlExpression * expr) { return (expr->getInfoFlags2() & (HEF2mustHoist)) != 0; }
  1502. inline bool containsNewDataset(IHqlExpression * expr) { return (expr->getInfoFlags2() & HEF2containsNewDataset) != 0; }
  1503. inline bool containsCall(IHqlExpression * expr, bool includeOutOfLine)
  1504. {
  1505. unsigned mask = includeOutOfLine ? HEF2containsCall : HEF2containsDelayedCall;
  1506. return (expr->getInfoFlags2() & mask) != 0;
  1507. }
  1508. inline bool hasDynamic(IHqlExpression * expr) { return expr->hasProperty(dynamicAtom); }
  1509. inline bool isAbstractDataset(IHqlExpression * expr)
  1510. {
  1511. IHqlExpression * record = expr->queryRecord();
  1512. return record && record->hasProperty(abstractAtom);
  1513. }
  1514. inline IHqlExpression * queryRecord(IHqlExpression * expr)
  1515. {
  1516. if (!expr)
  1517. return NULL;
  1518. return expr->queryRecord();
  1519. }
  1520. extern HQL_API bool isPureVirtual(IHqlExpression * cur);
  1521. inline bool isForwardScope(IHqlScope * scope) { return scope && (queryExpression(scope)->getOperator() == no_forwardscope); }
  1522. extern HQL_API bool isContextDependent(IHqlExpression * expr, bool ignoreFailures = false, bool ignoreGraph = false);
  1523. extern HQL_API bool isPureCanSkip(IHqlExpression * expr);
  1524. extern HQL_API bool hasSideEffects(IHqlExpression * expr);
  1525. extern HQL_API bool containsAnyActions(IHqlExpression * expr);
  1526. extern bool canBeVirtual(IHqlExpression * expr);
  1527. extern bool areAllBasesFullyBound(IHqlExpression * module);
  1528. extern HQL_API bool isUpdatedConditionally(IHqlExpression * expr);
  1529. extern HQL_API bool activityMustBeCompound(IHqlExpression * expr);
  1530. extern HQL_API unsigned queryCurrentTransformDepth(); // debugging - only valid inside a transform
  1531. extern HQL_API bool isExternalFunction(IHqlExpression * funcdef);
  1532. typedef enum {
  1533. childdataset_none,
  1534. childdataset_dataset_noscope, // single dataset but this operation doesn't use any fields from it.
  1535. childdataset_dataset, // single dataset, fields are referenced by <dataset>.field
  1536. childdataset_datasetleft, // single dataset, fields are referenced by <dataset>|LEFT.field
  1537. childdataset_left, // single dataset, fields are referenced by LEFT.field
  1538. childdataset_leftright, // two datasets, fields are referenced by LEFT|RIGHT.field
  1539. childdataset_same_left_right, // single dataset, fields are referenced by LEFT|RIGHT.field
  1540. childdataset_top_left_right, // single dataset, fields are referenced by <dataset>|LEFT|RIGHT.field
  1541. childdataset_many_noscope, // multiple input files, no reference to any fields.
  1542. childdataset_many, // multiple input files, fields reference by <active>.field
  1543. childdataset_nway_left_right, // set of files for first parameter, fields accessed via LEFT and RIGHT
  1544. //weird exceptions
  1545. childdataset_evaluate, // EVALUATE
  1546. childdataset_if, // IF - second and third are datasets
  1547. childdataset_case, // CASE
  1548. childdataset_map, // MAP
  1549. childdataset_max
  1550. } childDatasetType;
  1551. extern HQL_API childDatasetType getChildDatasetType(IHqlExpression * expr);
  1552. // To improve error message.
  1553. extern HQL_API StringBuffer& getFriendlyTypeStr(IHqlExpression* e, StringBuffer& s);
  1554. extern HQL_API StringBuffer& getFriendlyTypeStr(ITypeInfo* type, StringBuffer& s);
  1555. #define ForEachChild(idx, expr) unsigned numOfChildren##idx = (expr)->numChildren(); \
  1556. for (unsigned idx = 0; idx < numOfChildren##idx; idx++)
  1557. #define ForEachChildFrom(idx, expr, first) unsigned numOfChildren##idx = (expr)->numChildren(); \
  1558. for (unsigned idx = first; idx < numOfChildren##idx; idx++)
  1559. extern HQL_API void exportData(IPropertyTree *data, IHqlExpression *table, bool flatten=false);
  1560. extern HQL_API void clearCacheCounts();
  1561. extern HQL_API void displayHqlCacheStats();
  1562. //only really makes sense on datasets, rows and selects.
  1563. inline bool isInScope(IHqlExpression * e) { return e == e->queryNormalizedSelector(); }
  1564. inline int boolToInt(bool x) { return x ? 1 : 0; }
  1565. extern HQL_API IHqlExpression * createFunctionDefinition(_ATOM name, IHqlExpression * value, IHqlExpression * parms, IHqlExpression * defaults, IHqlExpression * attrs);
  1566. extern HQL_API IHqlExpression * createFunctionDefinition(_ATOM name, HqlExprArray & args);
  1567. extern HQL_API IHqlExpression * queryNonDelayedBaseAttribute(IHqlExpression * expr);
  1568. extern HQL_API void gatherWarnings(IErrorReceiver * errs, IHqlExpression * expr);
  1569. #define NO_AGGREGATE \
  1570. no_count: \
  1571. case no_sum: \
  1572. case no_variance: \
  1573. case no_covariance: \
  1574. case no_correlation: \
  1575. case no_max: \
  1576. case no_min: \
  1577. case no_ave: \
  1578. case no_exists
  1579. #define NO_AGGREGATEGROUP \
  1580. no_countgroup: \
  1581. case no_sumgroup: \
  1582. case no_vargroup: \
  1583. case no_covargroup: \
  1584. case no_corrgroup: \
  1585. case no_maxgroup: \
  1586. case no_mingroup: \
  1587. case no_avegroup: \
  1588. case no_existsgroup
  1589. extern HQL_API ITypeInfo * getTypedefType(IHqlExpression * expr);
  1590. extern HQL_API ITypeInfo * getPromotedECLType(ITypeInfo * lType, ITypeInfo * rType);
  1591. extern HQL_API ITypeInfo * getPromotedECLCompareType(ITypeInfo * lType, ITypeInfo * rType);
  1592. extern HQL_API void extendAdd(SharedHqlExpr & value, IHqlExpression * expr);
  1593. inline bool isOmitted(IHqlExpression * actual) { return !actual || actual->getOperator() == no_omitted; }
  1594. extern HQL_API IFileContents * createFileContentsFromText(unsigned len, const char * text, ISourcePath * sourcePath);
  1595. extern HQL_API IFileContents * createFileContentsFromText(const char * text, ISourcePath * sourcePath);
  1596. extern HQL_API IFileContents * createFileContentsFromFile(const char * filename, ISourcePath * sourcePath);
  1597. extern HQL_API IFileContents * createFileContentsSubset(IFileContents * contents, size32_t offset, size32_t len);
  1598. extern HQL_API IFileContents * createFileContents(IFile * file, ISourcePath * sourcePath);
  1599. void addForwardDefinition(IHqlScope * scope, _ATOM symbolName, _ATOM moduleName, IFileContents * contents,
  1600. unsigned symbolFlags, bool isExported, unsigned startLine, unsigned startColumn);
  1601. extern HQL_API IPropertyTree * createAttributeArchive();
  1602. extern HQL_API void ensureSymbolsDefined(IHqlExpression * scope, HqlLookupContext & ctx);
  1603. extern HQL_API void ensureSymbolsDefined(IHqlScope * scope, HqlLookupContext & ctx);
  1604. extern HQL_API bool getBoolProperty(IHqlExpression * expr, _ATOM name, bool dft=false);
  1605. extern HQL_API void setLegacyEclSemantics(bool _value);
  1606. extern HQL_API bool queryLegacyEclSemantics();
  1607. void exportSymbols(IPropertyTree* data, IHqlScope * scope, HqlLookupContext & ctx);
  1608. #endif