hqlexpr.hpp 86 KB

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