hqlcpp.ipp 128 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154
  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 __HQLCPP_IPP_
  14. #define __HQLCPP_IPP_
  15. #include <stdio.h>
  16. #include "jfile.hpp"
  17. #include "hqlattr.hpp"
  18. #include "hqlcpp.hpp"
  19. #include "hqlstmt.ipp"
  20. #include "hqlcppc.hpp"
  21. #include "hqlres.hpp"
  22. #include "hqlutil.hpp"
  23. #include "hqlwcpp.hpp"
  24. #include "hqltrans.ipp"
  25. #include "hqlusage.hpp"
  26. #include "eclrtl.hpp"
  27. #ifdef _DEBUG
  28. //#define SPOT_POTENTIAL_COMMON_ACTIVITIES
  29. #endif
  30. #define MAX_RECORD_SIZE 4096 // default value
  31. #define OPTIMIZE_FUNCTION_ATTRIBUTE " OPTIMIZE"
  32. enum GraphLocalisation {
  33. GraphNeverAccess, // This variant of an activity never accesses the parent
  34. GraphNoAccess, // This activity would normally access the parent, but doesn't here
  35. GraphCoLocal, // activity runs on the same node as the
  36. GraphNonLocal,
  37. GraphCoNonLocal,
  38. GraphRemote
  39. };
  40. enum {
  41. EclTextPrio = 1000, // has no dependencies on anything else
  42. HashFunctionPrio = 1100,
  43. TypeInfoPrio = 1200,
  44. RowMetaPrio = 1500,
  45. XmlTransformerPrio = 1700,
  46. SteppedPrio = 1800,
  47. SegMonitorPrio = 2000,
  48. RecordTranslatorPrio = BuildCtx::NormalPrio,
  49. };
  50. enum ExpressionFormat {
  51. FormatNatural,
  52. FormatBlockedDataset,
  53. FormatLinkedDataset,
  54. FormatArrayDataset,
  55. FormatStreamedDataset,
  56. FormatMax,
  57. };
  58. ExpressionFormat queryNaturalFormat(ITypeInfo * type);
  59. class HqlCppLibraryImplementation;
  60. class HqlCppLibraryInstance;
  61. //===========================================================================
  62. class DatasetReference
  63. {
  64. public:
  65. DatasetReference(IHqlExpression * _ds) : ds(_ds) { side = no_none; }
  66. DatasetReference(IHqlExpression * _ds, node_operator _side, IHqlExpression * seq) : ds(_ds)
  67. {
  68. side = _side;
  69. if (side)
  70. selector.setown(getSelector(side, seq));
  71. }
  72. inline node_operator querySide() const { return side; }
  73. inline IHqlExpression * queryDataset() const { return ds; }
  74. IHqlExpression * getSelector(node_operator op, IHqlExpression * seq) const { return createSelector(op, ds, seq); }
  75. IHqlExpression * querySelector() const;
  76. IHqlExpression * querySelSeq() const;
  77. IHqlExpression * mapCompound(IHqlExpression * expr, IHqlExpression * to) const;
  78. IHqlExpression * mapScalar(IHqlExpression * expr, IHqlExpression * to) const;
  79. protected:
  80. LinkedHqlExpr ds;
  81. node_operator side;
  82. LinkedHqlExpr selector;
  83. };
  84. class LocationArray : public HqlExprArray
  85. {
  86. public:
  87. unsigned findLocation(IHqlExpression * location);
  88. bool queryNewLocation(IHqlExpression * location);
  89. };
  90. //===========================================================================
  91. class HQLCPP_API HqlCppSection : public CInterface
  92. {
  93. public:
  94. HqlCppSection() : section(NULL),stmts(NULL) {}
  95. public:
  96. IAtom * section;
  97. HqlStmts stmts;
  98. };
  99. class CppFileInfo : public CInterface
  100. {
  101. public:
  102. explicit CppFileInfo(unsigned activityId) : minActivityId(activityId), maxActivityId(activityId)
  103. {
  104. }
  105. public:
  106. unsigned minActivityId;
  107. unsigned maxActivityId;
  108. };
  109. class HQLCPP_API HqlCppInstance : public IHqlCppInstance, public CInterface
  110. {
  111. public:
  112. HqlCppInstance(IWorkUnit * _workunit, const char * _wupathname);
  113. IMPLEMENT_IINTERFACE
  114. virtual HqlStmts * ensureSection(IAtom * section);
  115. virtual const char * queryLibrary(unsigned idx);
  116. virtual const char * queryObjectFile(unsigned idx);
  117. virtual const char * querySourceFile(unsigned idx);
  118. virtual HqlStmts * querySection(IAtom * section);
  119. virtual void flushHints();
  120. virtual void flushResources(const char *filename, ICodegenContextCallback * ctxCallback);
  121. virtual void addResource(const char * type, unsigned len, const void * data, IPropertyTree *manifestEntry=NULL, unsigned id=(unsigned)-1);
  122. virtual void addCompressResource(const char * type, unsigned len, const void * data, IPropertyTree *manifestEntry=NULL, unsigned id=(unsigned)-1);
  123. virtual void addManifest(const char *filename){resources.addManifest(filename);}
  124. virtual void addManifestFromArchive(IPropertyTree *archive){resources.addManifestFromArchive(archive);}
  125. virtual void addWebServiceInfo(IPropertyTree *wsinfo){resources.addWebServiceInfo(wsinfo);}
  126. virtual void getActivityRange(unsigned cppIndex, unsigned & minActivityId, unsigned & maxActivityId);
  127. bool useFunction(IHqlExpression * funcdef);
  128. void useInclude(const char * include);
  129. void useLibrary(const char * libname);
  130. void useObjectFile(const char * objname);
  131. void useSourceFile(const char * srcname);
  132. unsigned addStringResource(unsigned len, const char * body);
  133. void addHint(const char * hintXml, ICodegenContextCallback * ctxCallback);
  134. void processIncludes();
  135. void addPlugin(const char *plugin, const char *version);
  136. private:
  137. void addPluginsAsResource();
  138. void appendHintText(const char * xml);
  139. public:
  140. CIArray sections;
  141. IArray helpers;
  142. StringAttrArray modules;
  143. StringAttrArray objectFiles;
  144. StringAttrArray sourceFiles;
  145. StringAttrArray includes;
  146. CIArray extra;
  147. ResourceManager resources;
  148. Owned<IWorkUnit> workunit;
  149. StringAttr wupathname;
  150. Owned<IPropertyTree> plugins;
  151. Owned<IFileIOStream> hintFile;
  152. CIArrayOf<CppFileInfo> cppInfo;
  153. };
  154. //---------------------------------------------------------------------------
  155. class HqlCppTranslator;
  156. class BoundRow;
  157. interface IHqlCppDatasetCursor : public IInterface
  158. {
  159. virtual void buildCount(BuildCtx & ctx, CHqlBoundExpr & tgt) = 0;
  160. virtual void buildExists(BuildCtx & ctx, CHqlBoundExpr & tgt) = 0;
  161. virtual BoundRow * buildIterateLoop(BuildCtx & ctx, bool needToBreak) = 0;
  162. virtual void buildIterateClass(BuildCtx & ctx, SharedHqlExpr & iter, SharedHqlExpr & row) = 0;
  163. virtual void buildIterateClass(BuildCtx & ctx, StringBuffer & cursorName, BuildCtx * initctx) = 0;
  164. virtual BoundRow * buildSelectNth(BuildCtx & ctx, IHqlExpression * indexExpr) = 0;
  165. virtual BoundRow * buildSelectMap(BuildCtx & ctx, IHqlExpression * indexExpr) = 0;
  166. virtual void buildInDataset(BuildCtx & ctx, IHqlExpression * inExpr, CHqlBoundExpr & tgt) = 0;
  167. virtual void buildIterateMembers(BuildCtx & declarectx, BuildCtx & initctx) = 0;
  168. virtual void buildCountDict(BuildCtx & ctx, CHqlBoundExpr & tgt) = 0;
  169. virtual void buildExistsDict(BuildCtx & ctx, CHqlBoundExpr & tgt) = 0;
  170. };
  171. interface IHqlCppSetCursor : public IInterface
  172. {
  173. virtual void buildCount(BuildCtx & ctx, CHqlBoundExpr & tgt) = 0;
  174. virtual void buildExists(BuildCtx & ctx, CHqlBoundExpr & tgt) = 0;
  175. virtual void buildIsAll(BuildCtx & ctx, CHqlBoundExpr & tgt) = 0;
  176. virtual void buildIterateLoop(BuildCtx & ctx, CHqlBoundExpr & tgt, bool needToBreak) = 0;
  177. virtual void buildExprSelect(BuildCtx & ctx, IHqlExpression * indexExpr, CHqlBoundExpr & tgt) = 0;
  178. virtual void buildAssignSelect(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * indexExpr) = 0;
  179. virtual bool isSingleValued() = 0;
  180. };
  181. interface IHqlCppDatasetBuilder : public IInterface
  182. {
  183. public:
  184. virtual void buildDeclare(BuildCtx & ctx) = 0;
  185. virtual BoundRow * buildCreateRow(BuildCtx & ctx) = 0; //NB: Must be called within a addGroup(), or another un-ambiguous child context, may create a filter
  186. virtual BoundRow * buildDeserializeRow(BuildCtx & ctx, IHqlExpression * serializedInput, IAtom * serializeForm) = 0;
  187. virtual void finishRow(BuildCtx & ctx, BoundRow * selfCursor) = 0;
  188. virtual void buildFinish(BuildCtx & ctx, const CHqlBoundTarget & target) = 0;
  189. virtual void buildFinish(BuildCtx & ctx, CHqlBoundExpr & bound) = 0;
  190. virtual bool buildLinkRow(BuildCtx & ctx, BoundRow * sourceRow) = 0;
  191. virtual bool buildAppendRows(BuildCtx & ctx, IHqlExpression * expr) = 0;
  192. virtual bool isRestricted() = 0;
  193. };
  194. interface IHqlCppSetBuilder : public IInterface
  195. {
  196. public:
  197. virtual void buildDeclare(BuildCtx & ctx) = 0;
  198. virtual IReferenceSelector * buildCreateElement(BuildCtx & ctx) = 0; //NB: Must be called within a addGroup(), or another un-ambiguous child context, may create a filter
  199. virtual void buildFinish(BuildCtx & ctx, const CHqlBoundTarget & target) = 0;
  200. virtual void finishElement(BuildCtx & ctx) = 0;
  201. virtual void setAll(BuildCtx & ctx, IHqlExpression * isAll) = 0;
  202. };
  203. interface IHqlCodeCallback : public IInterface
  204. {
  205. virtual void buildCode(HqlCppTranslator & translator, BuildCtx & ctx) = 0;
  206. };
  207. //---------------------------------------------------------------------------
  208. class CheckedLengthExprAttr : public HqlExprAttr
  209. {
  210. public:
  211. inline void set(IHqlExpression * e) { HqlExprAttr::set(e); check(); }
  212. inline void setown(IHqlExpression * e) { HqlExprAttr::setown(e); check(); }
  213. inline void check()
  214. {
  215. if (get())
  216. {
  217. ITypeInfo * type = get()->queryType();
  218. assertex(type->getTypeCode() == type_int && type->getSize() == 4 && !type->isSigned());
  219. }
  220. }
  221. };
  222. class CHqlBoundTarget;
  223. class HQLCPP_API CHqlBoundExpr
  224. {
  225. public:
  226. void clear() { expr.clear(); length.clear(); }
  227. bool exists() const { return (expr != NULL); }
  228. IHqlExpression * getIsAll() const;
  229. IHqlExpression * getComplexExpr() const;
  230. IHqlExpression * getTranslatedExpr() const;
  231. inline bool isStreamed() const { return hasStreamedModifier(queryType()); }
  232. ITypeInfo * queryType() const { return expr->queryType(); }
  233. void set(const CHqlBoundExpr & src) { expr.set(src.expr); length.set(src.length); count.set(src.count); isAll.set(src.isAll); }
  234. void setFromTarget(const CHqlBoundTarget & target);
  235. void setFromTranslated(IHqlExpression * expr);
  236. public:
  237. HqlExprAttr expr;
  238. HqlExprAttr count;
  239. #ifdef _DEBUG
  240. CheckedLengthExprAttr length;
  241. #else
  242. HqlExprAttr length;
  243. #endif
  244. HqlExprAttr isAll;
  245. };
  246. class HQLCPP_API CHqlBoundTarget
  247. {
  248. public:
  249. CHqlBoundTarget() {}
  250. ~CHqlBoundTarget() { validate(); }
  251. bool extractFrom(const CHqlBoundExpr & bound);
  252. bool isFixedSize() const;
  253. IHqlExpression * getTranslatedExpr() const;
  254. ITypeInfo * queryType() const;
  255. ITypeInfo * getType() const { return LINK(queryType()); }
  256. void set(const CHqlBoundTarget& other)
  257. {
  258. length.set(other.length);
  259. count.set(other.count);
  260. expr.set(other.expr);
  261. isAll.set(other.isAll);
  262. }
  263. void validate() const;
  264. public:
  265. HqlExprAttr expr;
  266. HqlExprAttr count; // currently only for link counted rows
  267. HqlExprAttr length;
  268. HqlExprAttr isAll; // if set location to store whether it is all or not
  269. };
  270. class BoundRow;
  271. class BoundRow;
  272. interface IReferenceSelector : public IInterface
  273. {
  274. public:
  275. //code generation
  276. //change these to inline functions
  277. virtual void assignTo(BuildCtx & ctx, const CHqlBoundTarget & target) = 0;
  278. virtual void buildAddress(BuildCtx & ctx, CHqlBoundExpr & target) = 0;
  279. virtual void buildClear(BuildCtx & ctx, int direction) = 0;
  280. virtual void get(BuildCtx & ctx, CHqlBoundExpr & bound) = 0;
  281. virtual void getOffset(BuildCtx & ctx, CHqlBoundExpr & bound) = 0;
  282. virtual void getSize(BuildCtx & ctx, CHqlBoundExpr & bound) = 0;
  283. virtual size32_t getContainerTrailingFixed() = 0;
  284. virtual bool isBinary() = 0;
  285. virtual bool isConditional() = 0;
  286. virtual bool isRoot() = 0;
  287. virtual void modifyOp(BuildCtx & ctx, IHqlExpression * expr, node_operator op) = 0;
  288. virtual void set(BuildCtx & ctx, IHqlExpression * expr) = 0;
  289. virtual void setRow(BuildCtx & ctx, IReferenceSelector * rhs) = 0;
  290. virtual void buildDeserialize(BuildCtx & ctx, IHqlExpression * helper, IAtom * serializeForm) = 0;
  291. virtual void buildSerialize(BuildCtx & ctx, IHqlExpression * helper, IAtom * serializeForm) = 0;
  292. //managing the selection
  293. virtual AColumnInfo * queryColumn() = 0;
  294. virtual BoundRow * queryRootRow() = 0;
  295. virtual IHqlExpression * queryExpr() = 0;
  296. virtual ITypeInfo * queryType() = 0;
  297. virtual IReferenceSelector * select(BuildCtx & ctx, IHqlExpression * selectExpr) = 0;
  298. virtual BoundRow * getRow(BuildCtx & ctx) = 0;
  299. };
  300. //---------------------------------------------------------------------------
  301. class HqlCppCaseInfo
  302. {
  303. friend class HqlCppTranslator;
  304. public:
  305. HqlCppCaseInfo(HqlCppTranslator & _translator);
  306. void addPair(IHqlExpression * expr);
  307. void addPairs(HqlExprArray & pairs);
  308. bool buildAssign(BuildCtx & ctx, const CHqlBoundTarget & target);
  309. bool buildReturn(BuildCtx & ctx);
  310. void setCond(IHqlExpression * expr);
  311. void setDefault(IHqlExpression * expr);
  312. protected:
  313. bool canBuildStaticList(ITypeInfo * type);
  314. void buildChop3Map(BuildCtx & ctx, const CHqlBoundTarget & target, CHqlBoundExpr & test, IHqlExpression * temp, unsigned start, unsigned end);
  315. void buildChop3Map(BuildCtx & ctx, const CHqlBoundTarget & target, CHqlBoundExpr & test);
  316. void buildChop2Map(BuildCtx & ctx, const CHqlBoundTarget & target, CHqlBoundExpr & test, unsigned start, unsigned end);
  317. IHqlExpression * buildIndexedMap(BuildCtx & ctx, const CHqlBoundExpr & test);
  318. void buildLoopChopMap(BuildCtx & ctx, const CHqlBoundTarget & target, CHqlBoundExpr & test);
  319. void buildIntegerSearchMap(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * est);
  320. void buildSwitchCondition(BuildCtx & ctx, CHqlBoundExpr & bound);
  321. void buildSwitchMap(BuildCtx & ctx, const CHqlBoundTarget * target, IHqlExpression * test);
  322. void buildGeneralAssign(BuildCtx & ctx, const CHqlBoundTarget & target);
  323. void buildGeneralReturn(BuildCtx & ctx);
  324. bool canBuildArrayLookup(const CHqlBoundExpr & test);
  325. IHqlExpression * createCompareList();
  326. IHqlExpression * createComparisons();
  327. IHqlExpression * createResultsExpr(IHqlExpression * matchVar, bool canIncludeDefault, bool * includedDefault = NULL);
  328. void generateCompareVar(BuildCtx & ctx, IHqlExpression * target, CHqlBoundExpr & test, IHqlExpression * other);
  329. unsigned getNumPairs();
  330. bool hasLibraryChop();
  331. bool okToAlwaysEvaluateDefault();
  332. void processBranches();
  333. void promoteTypes();
  334. IHqlExpression * queryCreateSimpleResultAssign(IHqlExpression * search, IHqlExpression * resultExpr);
  335. bool queryBuildArrayLookup(BuildCtx & ctx, const CHqlBoundTarget & target, const CHqlBoundExpr & test);
  336. IHqlExpression * queryCompare(unsigned index);
  337. ITypeInfo * queryCompareType();
  338. IHqlExpression * queryReturn(unsigned index);
  339. void removeDuplicates();
  340. void sortPairs();
  341. void updateResultType(IHqlExpression * expr);
  342. protected:
  343. HqlCppTranslator &translator;
  344. HqlExprAttr cond;
  345. HqlExprAttr defaultValue;
  346. HqlExprArray pairs;
  347. HqlExprArray originalPairs;
  348. OwnedHqlExpr lowestCompareExpr;
  349. OwnedHqlExpr highestCompareExpr;
  350. OwnedHqlExpr lowerTableBound;
  351. OwnedHqlExpr upperTableBound;
  352. bool complexCompare;
  353. bool constantCases;
  354. bool constantValues;
  355. bool useRangeIndex = false;
  356. bool allResultsMatch = true;
  357. OwnedITypeInfo resultType;
  358. OwnedITypeInfo indexType;
  359. OwnedITypeInfo promotedElementType;
  360. };
  361. //===========================================================================
  362. enum
  363. {
  364. MFdynamicproto = 1, // Prototype for the function is not a literal string
  365. MFsingle = 2, // This will only be executed once per activity instance
  366. MFopt = 4, // An optional function that will not be generated if it is empty
  367. };
  368. class MemberFunction
  369. {
  370. public:
  371. MemberFunction(HqlCppTranslator & translator, BuildCtx & classctx);
  372. MemberFunction(HqlCppTranslator & translator, BuildCtx & classctx, const char * text, unsigned _flags = 0);
  373. ~MemberFunction() noexcept(false);
  374. void start(const char * text, unsigned _flags = 0);
  375. void finish();
  376. unsigned numStmts() const;
  377. void setIncomplete(bool value);
  378. void setIncluded(bool value);
  379. inline bool isExecutedOnce() const { return (flags & MFsingle) != 0; }
  380. public:
  381. HqlCppTranslator & translator;
  382. IHqlStmt * stmt = nullptr;
  383. BuildCtx ctx;
  384. unsigned flags = 0;
  385. };
  386. //===========================================================================
  387. class GlobalFileTracker : public IHqlDelayedCodeGenerator, public CInterface
  388. {
  389. public:
  390. GlobalFileTracker(IHqlExpression * _filename, IPropertyTree * _graphNode)
  391. {
  392. filename.set(_filename->queryBody());
  393. graphNode.set(_graphNode);
  394. usageCount = 0;
  395. }
  396. IMPLEMENT_IINTERFACE
  397. //IHqlDelayedCodeGenerator
  398. virtual void generateCpp(StringBuffer & out) { out.append(usageCount); }
  399. bool checkMatch(IHqlExpression * searchFilename);
  400. void writeToGraph();
  401. public:
  402. unsigned usageCount;
  403. OwnedHqlExpr filename;
  404. Owned<IPropertyTree> graphNode;
  405. };
  406. //===========================================================================
  407. class WorkflowItem : public CInterface
  408. {
  409. friend class WorkflowTransformer;
  410. public:
  411. WorkflowItem(unsigned _wfid, node_operator _workflowOp) : wfid(_wfid), workflowOp(_workflowOp) { }
  412. WorkflowItem(IHqlExpression * _function);
  413. bool isFunction() const { return function != NULL; }
  414. IHqlExpression * getFunction() const;
  415. unsigned queryWfid() const { return wfid; }
  416. HqlExprArray & queryExprs() { return exprs; }
  417. private:
  418. LinkedHqlExpr function;
  419. HqlExprArray exprs;
  420. UnsignedArray dependencies;
  421. unsigned wfid;
  422. node_operator workflowOp;
  423. };
  424. typedef CIArrayOf<WorkflowItem> WorkflowArray;
  425. //---------------------------------------------------------------------------
  426. typedef CIArrayOf<BoundRow> CursorArray;
  427. enum AliasKind { NotFoundAlias, CreateTimeAlias, StartTimeAlias, RuntimeAlias };
  428. class ActivityInstance;
  429. class SerializationRow;
  430. class EvalContext;
  431. class InternalResultTracker;
  432. //---------------------------------------------------------------------------
  433. typedef CIArrayOf<BuildCtx> BuildCtxArray;
  434. struct GeneratedGraphInfo : public CInterface
  435. {
  436. public:
  437. GeneratedGraphInfo(const char * _name, const char *_label) : name(_name), label(_label)
  438. {
  439. xgmml.setown(createPTree("graph"));
  440. }
  441. public:
  442. StringAttr name, label;
  443. Owned<IPropertyTree> xgmml;
  444. };
  445. enum SubGraphType { SubGraphRoot, SubGraphRemote, SubGraphChild, SubGraphLoop };
  446. struct SubGraphInfo : public HqlExprAssociation
  447. {
  448. public:
  449. SubGraphInfo(IPropertyTree * _tree, unsigned _id, unsigned _graphId, IHqlExpression * graphTag, SubGraphType _type);
  450. virtual AssocKind getKind() { return AssocSubGraph; }
  451. public:
  452. Linked<IPropertyTree> tree;
  453. unsigned id;
  454. unsigned graphId;
  455. LinkedHqlExpr graphTag;
  456. SubGraphType type;
  457. };
  458. //MORE: This class is far too big and needs restructuring!!!!!
  459. class ColumnToOffsetMap;
  460. class RecordOffsetMap : public MapOf<IHqlExpression *, ColumnToOffsetMap>
  461. {
  462. public:
  463. ColumnToOffsetMap * queryMapping(IHqlExpression * record, unsigned maxRecordSize, bool isTarget);
  464. };
  465. class ExprExprMap : public MapOwnedToOwned<IHqlExpression, IHqlExpression>
  466. {
  467. };
  468. class SubStringInfo;
  469. class MetaInstance;
  470. class KeyedJoinInfo;
  471. class HqlMapTransformer;
  472. class TransformBuilder;
  473. struct HqlCppOptions
  474. {
  475. unsigned defaultImplicitKeyedJoinLimit;
  476. unsigned defaultImplicitIndexReadLimit;
  477. unsigned optimizeDiskFlag;
  478. unsigned activitiesPerCpp;
  479. unsigned maxRecordSize;
  480. unsigned inlineStringThreshold;
  481. unsigned maxRootMaybeThorActions;
  482. unsigned maxLocalRowSize;
  483. unsigned insertProjectCostLevel;
  484. unsigned dfaRepeatMax;
  485. unsigned dfaRepeatMaxScore;
  486. unsigned debugNlp;
  487. unsigned regexVersion;
  488. unsigned parseDfaComplexity;
  489. unsigned resourceMaxMemory;
  490. unsigned resourceMaxSockets;
  491. unsigned resourceMaxActivities;
  492. unsigned resourceMaxHeavy;
  493. unsigned resourceMaxDistribute;
  494. unsigned filteredReadSpillThreshold;
  495. unsigned topnLimit;
  496. unsigned specifiedClusterSize;
  497. unsigned globalFoldOptions;
  498. unsigned minimizeSpillSize;
  499. unsigned applyInstantEclTransformationsLimit;
  500. unsigned complexClassesThreshold;
  501. unsigned complexClassesActivityFilter;
  502. unsigned subgraphToRegenerate;
  503. unsigned defaultPersistExpiry;
  504. unsigned defaultExpiry;
  505. unsigned varFieldAccessorThreshold;
  506. unsigned searchDistanceThreshold;
  507. unsigned generateActivityThreshold; // Record activities which take more than this value (in ms) to generate (0 disables)
  508. cycle_t generateActivityThresholdCycles;
  509. int defaultNumPersistInstances;
  510. unsigned reportDFSinfo;
  511. CompilerType targetCompiler;
  512. DBZaction divideByZeroAction;
  513. bool peephole;
  514. bool foldConstantCast;
  515. bool optimizeBoolReturn;
  516. bool freezePersists;
  517. bool checkRoxieRestrictions;
  518. bool checkThorRestrictions;
  519. bool allowCsvWorkunitRead;
  520. bool evaluateCoLocalRowInvariantInExtract;
  521. bool allowInlineSpill;
  522. bool spanMultipleCpp;
  523. bool optimizeGlobalProjects;
  524. bool optimizeResourcedProjects;
  525. byte notifyOptimizedProjects;
  526. bool checkAsserts;
  527. bool assertSortedDistributed;
  528. bool optimizeLoopInvariant;
  529. bool warnOnImplicitJoinLimit;
  530. bool warnOnImplicitReadLimit;
  531. bool commonUpChildGraphs;
  532. bool detectAmbiguousSelector;
  533. bool allowAmbiguousSelector;
  534. bool regressionTest;
  535. bool recreateMapFromIf;
  536. bool reduceNetworkTraffic;
  537. bool optimizeProjectsPreservePersists;
  538. bool showMetaText;
  539. bool resourceConditionalActions;
  540. bool resourceSequential;
  541. bool workunitTemporaries;
  542. bool minimizeWorkunitTemporaries;
  543. bool pickBestEngine;
  544. bool groupedChildIterators;
  545. bool convertJoinToLookup;
  546. bool convertJoinToLookupIfSorted;
  547. bool spotCSE;
  548. bool spotCseInIfDatasetConditions;
  549. bool noAllToLookupConversion;
  550. bool optimizeNonEmpty;
  551. bool allowVariableRoxieFilenames;
  552. bool notifyWorkflowCse;
  553. bool performWorkflowCse;
  554. bool foldConstantDatasets;
  555. bool hoistSimpleGlobal;
  556. bool percolateConstants;
  557. bool percolateFilters;
  558. bool usePrefetchForAllProjects;
  559. bool allFilenamesDynamic;
  560. bool optimizeSteppingPostfilter;
  561. bool moveUnconditionalActions;
  562. bool paranoidCheckNormalized;
  563. bool paranoidCheckDependencies;
  564. bool preventKeyedSplit;
  565. bool preventSteppedSplit;
  566. bool canGenerateSimpleAction;
  567. bool minimizeActivityClasses;
  568. bool minimizeSkewBeforeSpill;
  569. bool createSerializeForUnknownSize;
  570. bool implicitLinkedChildRows;
  571. bool mainRowsAreLinkCounted;
  572. bool allowSections;
  573. bool autoPackRecords;
  574. bool commonUniqueNameAttributes;
  575. bool sortIndexPayload;
  576. bool foldFilter;
  577. bool finalizeAllRows;
  578. bool optimizeGraph;
  579. bool orderDiskFunnel;
  580. bool alwaysAllowAllNodes;
  581. bool slidingJoins;
  582. bool foldOptimized;
  583. bool globalOptimize;
  584. bool applyInstantEclTransformations;
  585. bool calculateComplexity;
  586. bool generateLogicalGraph;
  587. bool generateLogicalGraphOnly;
  588. bool globalAutoHoist;
  589. bool expandRepeatAnyAsDfa;
  590. bool unlimitedResources;
  591. bool allowThroughSpill;
  592. bool minimiseSpills;
  593. bool spillMultiCondition;
  594. bool spotThroughAggregate;
  595. bool hoistResourced;
  596. bool maximizeLexer;
  597. bool foldStored;
  598. bool spotTopN;
  599. bool groupAllDistribute;
  600. bool spotLocalMerge;
  601. bool spotPotentialKeyedJoins;
  602. bool combineTrivialStored;
  603. bool combineAllStored;
  604. bool allowStoredDuplicate;
  605. bool allowScopeMigrate;
  606. bool supportFilterProject;
  607. bool normalizeExplicitCasts;
  608. bool optimizeInlineSource;
  609. bool optimizeDiskSource;
  610. bool optimizeIndexSource;
  611. bool optimizeChildSource;
  612. bool reportLocations;
  613. bool debugGeneratedCpp;
  614. bool addFilesnamesToGraph;
  615. bool normalizeLocations;
  616. bool ensureRecordsHaveSymbols;
  617. bool constantFoldNormalize;
  618. bool constantFoldPostNormalize;
  619. bool optimizeGrouping;
  620. bool showMetaInGraph;
  621. bool spotComplexClasses;
  622. bool optimizeString1Compare;
  623. bool optimizeSpillProject;
  624. bool expressionPeephole;
  625. bool optimizeIncrement;
  626. bool supportsMergeDistribute;
  627. bool debugNlpAsHint;
  628. bool forceVariableWuid;
  629. bool okToDeclareAndAssign; // long time ago gcc had problems doing this for very complex functions
  630. bool noteRecordSizeInGraph;
  631. bool convertRealAssignToMemcpy;
  632. bool allowActivityForKeyedJoin;
  633. bool forceActivityForKeyedJoin;
  634. bool addLibraryInputsToGraph;
  635. bool showRecordCountInGraph;
  636. bool serializeRowsetInExtract;
  637. bool testIgnoreMaxLength;
  638. bool trackDuplicateActivities; // for diagnosing problems with code becoming duplicated
  639. bool showActivitySizeInGraph;
  640. bool addLocationToCpp;
  641. bool alwaysCreateRowBuilder; // allow paranoid check to ensure builders are built everywhere
  642. bool precalculateFieldOffsets; // useful for some queries, can be expensive
  643. bool generateStaticInlineTables;
  644. bool staticRowsUseStringInitializer;
  645. bool convertWhenExecutedToCompound;
  646. bool standAloneExe;
  647. bool enableCompoundCsvRead;
  648. bool optimizeNestedConditional;
  649. bool createImplicitAliases;
  650. bool combineSiblingGraphs;
  651. bool optimizeSharedGraphInputs;
  652. bool supportsSubSortActivity; // Does the target engine support SUBSORT?
  653. bool implicitSubSort; // convert sort when partially sorted to subsort (group,sort,ungroup)
  654. bool implicitBuildIndexSubSort; // use subsort when building indexes?
  655. bool implicitJoinSubSort; // use subsort for partially sorted join inputs when possible
  656. bool implicitGroupSubSort; // use subsort if some sort conditions match when grouping
  657. bool implicitGroupHashAggregate; // convert aggregate(sort(x,a),{..},a,d) to aggregate(group(sort(x,a),a_,{},d))
  658. bool implicitGroupHashDedup;
  659. bool reportFieldUsage;
  660. bool reportFileUsage;
  661. bool recordFieldUsage;
  662. bool subsortLocalJoinConditions;
  663. bool projectNestedTables;
  664. bool showSeqInGraph;
  665. bool normalizeSelectorSequence;
  666. bool removeXpathFromOutput;
  667. bool canLinkConstantRows;
  668. bool checkAmbiguousRollupCondition;
  669. bool paranoidCheckSelects;
  670. bool matchExistingDistributionForJoin;
  671. bool createImplicitKeyedDistributeForJoin;
  672. bool expandHashJoin;
  673. bool traceIR;
  674. bool preserveCaseExternalParameter;
  675. bool multiplePersistInstances;
  676. bool optimizeParentAccess;
  677. bool expandPersistInputDependencies;
  678. bool expirePersists;
  679. bool actionLinkInNewGraph;
  680. bool optimizeMax;
  681. bool useResultsForChildSpills;
  682. bool alwaysUseGraphResults;
  683. bool noConditionalLinks;
  684. bool reportAssertFilenameTail;
  685. bool newBalancedSpotter;
  686. bool keyedJoinPreservesOrder;
  687. bool expandSelectCreateRow;
  688. bool obfuscateOutput;
  689. bool showEclInGraph;
  690. bool showChildCountInGraph;
  691. bool optimizeSortAllFields;
  692. bool optimizeSortAllFieldsStrict;
  693. bool alwaysReuseGlobalSpills;
  694. bool forceAllDatasetsParallel;
  695. bool embeddedWarningsAsErrors;
  696. bool optimizeCriticalFunctions;
  697. bool addLikelihoodToGraph;
  698. bool translateDFSlayouts;
  699. bool timeTransforms;
  700. bool useGlobalCompareClass;
  701. };
  702. //Any information gathered while processing the query should be moved into here, rather than cluttering up the translator class
  703. struct HqlCppDerived
  704. {
  705. HqlCppDerived()
  706. {
  707. }
  708. };
  709. interface IDefRecordElement;
  710. class NlpParseContext;
  711. struct EvaluateCompareInfo
  712. {
  713. public:
  714. EvaluateCompareInfo(node_operator _op) { actionIfDiffer = null_stmt; op = _op; isBoolEquality = false; neverReturnMatch = true; alwaysReturns = false; }
  715. EvaluateCompareInfo(const EvaluateCompareInfo & info)
  716. {
  717. target.set(info.target); actionIfDiffer = info.actionIfDiffer; op = info.op; isBoolEquality = info.isBoolEquality;
  718. alwaysReturns = false;
  719. neverReturnMatch = true;
  720. }
  721. bool isEqualityCompare() const { return op == no_eq; }
  722. IHqlExpression * getEqualityReturnValue() { return isBoolEquality ? createConstant(false) : createIntConstant(1); }
  723. CHqlBoundTarget target;
  724. node_operator op;
  725. StmtKind actionIfDiffer;
  726. bool isBoolEquality;
  727. bool neverReturnMatch;
  728. bool alwaysReturns;
  729. };
  730. class AliasExpansionInfo;
  731. class HashCodeCreator;
  732. class ParentExtract;
  733. class ConstantRowArray;
  734. class SerializeKeyInfo;
  735. enum PEtype {
  736. PETnone,
  737. PETchild, // child query
  738. PETremote, // allnodes
  739. PETloop, // loop
  740. PETnested, // nested class
  741. PETcallback, // callback within a function
  742. PETlibrary, // a library
  743. PETmax };
  744. class HQLCPP_API HqlCppTranslator : implements IHqlCppTranslator, public CInterface
  745. {
  746. //MORE: This is in serious need of refactoring....
  747. friend class HqlCppCaseInfo;
  748. friend class ActivityInstance;
  749. friend class SourceBuilder;
  750. friend class DiskReadBuilder;
  751. friend class IndexReadBuilder;
  752. friend class FetchBuilder;
  753. friend class MonitorExtractor;
  754. friend class NlpParseContext;
  755. friend class KeyedJoinInfo;
  756. friend class ChildGraphBuilder;
  757. public:
  758. HqlCppTranslator(IErrorReceiver * _errors, const char * _soName, IHqlCppInstance * _code, ClusterType _targetClusterType, ICodegenContextCallback *_logger);
  759. ~HqlCppTranslator();
  760. IMPLEMENT_IINTERFACE
  761. //interface IHqlCppTranslator
  762. virtual bool buildCpp(IHqlCppInstance & _code, HqlQueryContext & query);
  763. virtual double getComplexity(IHqlCppInstance & _code, IHqlExpression * expr);
  764. virtual bool spanMultipleCppFiles() { return options.spanMultipleCpp; }
  765. virtual unsigned getNumExtraCppFiles() { return activitiesThisCpp ? curCppFile : 0; }
  766. //Statements.
  767. void buildStmt(BuildCtx & ctx, IHqlExpression * expr);
  768. //General
  769. IReferenceSelector * buildReference(BuildCtx & ctx, IHqlExpression * expr);
  770. IReferenceSelector * buildActiveReference(BuildCtx & ctx, IHqlExpression * expr);
  771. //Scalar processing
  772. void buildExpr(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  773. void buildSimpleExpr(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  774. void buildTempExpr(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt, ExpressionFormat format=FormatNatural);
  775. void buildTempExpr(BuildCtx & ctx, BuildCtx & declareCtx, CHqlBoundTarget & target, IHqlExpression * expr, ExpressionFormat format, bool ignoreSetAll);
  776. IHqlExpression * buildSimplifyExpr(BuildCtx & ctx, IHqlExpression * expr);
  777. void buildExprEnsureType(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt, ITypeInfo * type);
  778. void buildExprViaTypedTemp(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt, ITypeInfo * type);
  779. void buildAssign(BuildCtx & ctx, IHqlExpression * target, IHqlExpression * expr);
  780. void buildExprAssign(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  781. void assign(BuildCtx & ctx, const CHqlBoundTarget & target, CHqlBoundExpr & expr);
  782. void buildIncrementAssign(BuildCtx & ctx, IHqlExpression * target, IHqlExpression * value);
  783. void buildIncrementAssign(BuildCtx & ctx, IReferenceSelector * target, IHqlExpression * value);
  784. void buildIncrementAssign(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * value);
  785. void buildExprOrAssign(BuildCtx & ctx, const CHqlBoundTarget * target, IHqlExpression * expr, CHqlBoundExpr * tgt);
  786. //Set processing
  787. void buildSetAssign(BuildCtx & ctx, IHqlCppSetBuilder * builder, IHqlExpression * expr);
  788. void buildSetAssignViaBuilder(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * value);
  789. //Row Processing
  790. IReferenceSelector * buildActiveRow(BuildCtx & ctx, IHqlExpression * expr);
  791. IReferenceSelector * buildNewRow(BuildCtx & ctx, IHqlExpression * expr);
  792. IReferenceSelector * buildNewOrActiveRow(BuildCtx & ctx, IHqlExpression * expr, bool isNew);
  793. void buildRowAssign(BuildCtx & ctx, BoundRow * target, IHqlExpression * expr);
  794. void buildRowAssign(BuildCtx & ctx, IReferenceSelector * target, IHqlExpression * expr);
  795. void buildRowAssign(BuildCtx & ctx, IReferenceSelector * target, IReferenceSelector * source);
  796. BoundRow * ensureLinkCountedRow(BuildCtx & ctx, BoundRow * row);
  797. IReferenceSelector * ensureLinkCountedRow(BuildCtx & ctx, IReferenceSelector * source);
  798. //Dataset processing.
  799. void buildAnyExpr(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  800. void buildDataset(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt, ExpressionFormat format);
  801. void doBuildDataset(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt, ExpressionFormat format);
  802. void buildDatasetAssign(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  803. void buildDatasetAssign(BuildCtx & ctx, IHqlCppDatasetBuilder * builder, IHqlExpression * expr);
  804. void ensureDatasetFormat(BuildCtx & ctx, ITypeInfo * type, CHqlBoundExpr & tgt, ExpressionFormat format);
  805. BoundRow * buildDatasetIterate(BuildCtx & ctx, IHqlExpression * _expr, bool needToBreak);
  806. IReferenceSelector * buildDatasetIndex(BuildCtx & ctx, IHqlExpression * expr);
  807. IReferenceSelector * buildDatasetIndexViaIterator(BuildCtx & ctx, IHqlExpression * expr);
  808. IHqlExpression * ensureIteratedRowIsLive(BuildCtx & initctx, BuildCtx & searchctx, BuildCtx & iterctx, BoundRow * row, IHqlExpression * dataset, IHqlExpression * rowExpr);
  809. BoundRow * buildOptimizeSelectFirstRow(BuildCtx & ctx, IHqlExpression * expr);
  810. IReferenceSelector * buildDatasetSelectMap(BuildCtx & ctx, IHqlExpression * expr);
  811. // Helper functions
  812. __declspec(noreturn) void ThrowStringException(int code,const char *format, ...) __attribute__((format(printf, 3, 4), noreturn)); // override the global function to try and add more context information
  813. void buildAddress(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  814. void buildBlockCopy(BuildCtx & ctx, IHqlExpression * tgt, CHqlBoundExpr & src);
  815. void buildClear(BuildCtx & ctx, IHqlExpression * expr);
  816. void buildClear(BuildCtx & ctx, const CHqlBoundTarget & target);
  817. void buildFilter(BuildCtx & ctx, IHqlExpression * expr);
  818. void buildFilteredReturn(BuildCtx & ctx, IHqlExpression * filter, IHqlExpression * value);
  819. void buildCachedExpr(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  820. void buildReturn(BuildCtx & ctx, IHqlExpression * expr, ITypeInfo * type=NULL);
  821. ABoundActivity * buildActivity(BuildCtx & ctx, IHqlExpression * expr, bool isRoot);
  822. ABoundActivity * buildCachedActivity(BuildCtx & ctx, IHqlExpression * expr, bool isRoot = false);
  823. ABoundActivity * getConditionalActivity(BuildCtx & ctx, IHqlExpression * expr, bool isChild);
  824. void buildRootActivity(BuildCtx & ctx, IHqlExpression * expr);
  825. bool specialCaseBoolReturn(BuildCtx & ctx, IHqlExpression * expr);
  826. void buildCompoundAssign(BuildCtx & ctx, IHqlExpression * left, IReferenceSelector * leftSelector, IHqlExpression * rightScope, IHqlExpression * rightSelector);
  827. void buildCompoundAssign(BuildCtx & ctx, IHqlExpression * left, IHqlExpression * right);
  828. void associateCounter(BuildCtx & ctx, IHqlExpression * counterExpr, const char * name);
  829. // child dataset processing.
  830. IHqlExpression * buildSpillChildDataset(BuildCtx & ctx, IHqlExpression * expr);
  831. IHqlExpression * forceInlineAssignDataset(BuildCtx & ctx, IHqlExpression * expr);
  832. bool canProcessInline(BuildCtx * ctx, IHqlExpression * expr);
  833. bool canIterateInline(BuildCtx * ctx, IHqlExpression * expr);
  834. bool canAssignInline(BuildCtx * ctx, IHqlExpression * expr);
  835. bool canEvaluateInline(BuildCtx * ctx, IHqlExpression * expr);
  836. bool canEvaluateInlineNoSpill(BuildCtx * ctx, IHqlExpression * expr);
  837. void buildAssignChildDataset(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  838. void buildChildDataset(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  839. IHqlExpression * bindFunctionCall(IIdAtom * name, HqlExprArray & args);
  840. IHqlExpression * bindFunctionCall(IIdAtom * name, IHqlExpression * arg1);
  841. IHqlExpression * bindFunctionCall(IIdAtom * name, HqlExprArray & args, ITypeInfo * newType);
  842. IHqlExpression * bindFunctionCall(IHqlExpression * function, HqlExprArray & args);
  843. IHqlExpression * bindTranslatedFunctionCall(IIdAtom * name, HqlExprArray & args);
  844. IHqlExpression * bindTranslatedFunctionCall(IHqlExpression * function, HqlExprArray & args);
  845. void buildFunctionCall(BuildCtx & ctx, IIdAtom * name, HqlExprArray & args);
  846. void buildTranslatedFunctionCall(BuildCtx & ctx, IIdAtom * name, HqlExprArray & args);
  847. void callProcedure(BuildCtx & ctx, IIdAtom * name, HqlExprArray & args);
  848. void expandFunctions(bool expandInline);
  849. IHqlExpression * needFunction(IIdAtom * name);
  850. bool registerGlobalUsage(IHqlExpression * filename);
  851. IHqlExpression * queryActiveNamedActivity();
  852. IHqlExpression * queryActiveActivityLocation() const;
  853. void reportWarning(WarnErrorCategory category, unsigned id, const char * msg, ...) __attribute__((format(printf, 4, 5)));
  854. void reportWarning(WarnErrorCategory category, ErrorSeverity explicitSeverity, IHqlExpression * location, unsigned id, const char * msg, ...) __attribute__((format(printf, 6, 7)));
  855. void reportError(IHqlExpression * location, int code, const char *format, ...) __attribute__((format(printf, 4, 5)));
  856. void reportErrorNoAbort(IHqlExpression * location, int code, const char *format, ...) __attribute__((format(printf, 4, 5)));
  857. void reportErrorDirect(IHqlExpression * location, int code,const char *msg, bool alwaysAbort);
  858. void addWorkunitException(ErrorSeverity severity, unsigned code, const char * msg, IHqlExpression * location);
  859. void useFunction(IHqlExpression * funcdef);
  860. void useLibrary(const char * libname);
  861. void finalizeResources();
  862. void generateStatistics(const char * targetDir, const char * variant);
  863. inline bool queryEvaluateCoLocalRowInvariantInExtract() const { return options.evaluateCoLocalRowInvariantInExtract; }
  864. inline byte notifyOptimizedProjectsLevel() { return options.notifyOptimizedProjects; }
  865. inline bool generateAsserts() const { return options.checkAsserts; }
  866. inline bool getCheckRoxieRestrictions() const { return options.checkRoxieRestrictions; }
  867. inline bool queryFreezePersists() const { return options.freezePersists; }
  868. inline bool checkIndexReadLimit() const { return options.warnOnImplicitReadLimit; }
  869. inline unsigned getDefaultImplicitIndexReadLimit() const { return options.defaultImplicitIndexReadLimit; }
  870. inline bool queryCommonUpChildGraphs() const { return options.commonUpChildGraphs; }
  871. inline bool insideLibrary() const { return outputLibraryId != NULL; }
  872. inline bool hasDynamicFilename(IHqlExpression * expr) const { return options.allFilenamesDynamic || hasDynamic(expr); }
  873. inline bool canGenerateStringInline(unsigned len) { return ((options.inlineStringThreshold == 0) || (len <= options.inlineStringThreshold)); }
  874. unsigned getOptimizeFlags(bool insideChildQuery) const;
  875. unsigned getSourceAggregateOptimizeFlags() const;
  876. void addGlobalOnWarning(IHqlExpression * setMetaExpr);
  877. ClusterType getTargetClusterType() const { return targetClusterType; }
  878. inline bool targetRoxie() const { return targetClusterType == RoxieCluster; }
  879. inline bool targetHThor() const { return targetClusterType == HThorCluster; }
  880. inline bool targetThor() const { return isThorCluster(targetClusterType); }
  881. inline IErrorReceiver & queryErrorProcessor() { return *errorProcessor; }
  882. inline ErrorSeverityMapper & queryLocalOnWarningMapper() { return *localOnWarnings; }
  883. unsigned getConsistentUID(IHqlExpression * ptr);
  884. unsigned getNextGlobalCompareId();
  885. bool insideOnCreate(BuildCtx & ctx);
  886. bool insideOnStart(BuildCtx & ctx);
  887. bool tempRowRequiresFinalize(IHqlExpression * record) const;
  888. void convertBoundDatasetToFirstRow(IHqlExpression * expr, CHqlBoundExpr & bound);
  889. void convertBoundRowToDataset(BuildCtx & ctx, CHqlBoundExpr & bound, const BoundRow * row, ExpressionFormat preferredFormat);
  890. //Be very careful before calling this.......
  891. //Either isIndependentMaybeShared is set - which case the item inserted into the initctx can have no dependencies
  892. //or isIndependentMaybeShared is false, and the code that is inserted is never implicitly shared.
  893. bool getInvariantMemberContext(BuildCtx & ctx, BuildCtx * * declarectx, BuildCtx * * initctx, bool isIndependentMaybeShared, bool invariantEachStart);
  894. IPropertyTree * gatherFieldUsage(const char * variant, const IPropertyTree * exclude);
  895. void writeFieldUsage(const char * targetDir, IPropertyTree * xml, const char * variant);
  896. public:
  897. BoundRow * bindSelf(BuildCtx & ctx, IHqlExpression * dataset, const char * builder);
  898. BoundRow * bindSelf(BuildCtx & ctx, IHqlExpression * dataset, IHqlExpression * expr, IHqlExpression * builder);
  899. BoundRow * bindTableCursor(BuildCtx & ctx, IHqlExpression * dataset, const char * bound, bool isLinkCounted, node_operator no_side, IHqlExpression * selSeq);
  900. BoundRow * bindTableCursor(BuildCtx & ctx, IHqlExpression * dataset, IHqlExpression * bound, node_operator no_side, IHqlExpression * selSeq);
  901. BoundRow * bindCsvTableCursor(BuildCtx & ctx, IHqlExpression * dataset, const char * name, node_operator side, IHqlExpression * selSeq, bool translateVirtuals, IAtom * encoding);
  902. BoundRow * bindCsvTableCursor(BuildCtx & ctx, IHqlExpression * dataset, IHqlExpression * bound, node_operator side, IHqlExpression * selSeq, bool translateVirtuals, IAtom * encoding);
  903. BoundRow * bindXmlTableCursor(BuildCtx & ctx, IHqlExpression * dataset, const char * name, node_operator side, IHqlExpression * selSeq, bool translateVirtuals);
  904. BoundRow * bindXmlTableCursor(BuildCtx & ctx, IHqlExpression * dataset, IHqlExpression * bound, node_operator side, IHqlExpression * selSeq, bool translateVirtuals);
  905. BoundRow * createTableCursor(IHqlExpression * dataset, IHqlExpression * bound, bool useAccessorClass, node_operator side, IHqlExpression * selSeq);
  906. BoundRow * bindRow(BuildCtx & ctx, IHqlExpression * expr, IHqlExpression * bound);
  907. BoundRow * bindRow(BuildCtx & ctx, IHqlExpression * expr, const char * name);
  908. BoundRow * bindConstantRow(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & bound);
  909. BoundRow * bindSelectorAsSelf(BuildCtx & ctx, IReferenceSelector * selector, IHqlExpression * expr);
  910. BoundRow * bindSelectorAsRootRow(BuildCtx & ctx, IReferenceSelector * selector, IHqlExpression * expr);
  911. void bindRows(BuildCtx & ctx, node_operator side, IHqlExpression * selSeq, IHqlExpression * rowsid, IHqlExpression * dataset, const char * numText, const char * rowsText, bool mainRowsAreLinkCounted);
  912. BoundRow * bindTableCursorOrRow(BuildCtx & ctx, IHqlExpression * expr, const char * name);
  913. BoundRow * recreateTableCursor(IHqlExpression * dataset, BoundRow * row, node_operator side, IHqlExpression * selSeq);
  914. BoundRow * rebindTableCursor(BuildCtx & ctx, IHqlExpression * dataset, BoundRow * row, node_operator no_side, IHqlExpression * selSeq);
  915. void finishSelf(BuildCtx & ctx, BoundRow * self, BoundRow * target);
  916. void ensureRowAllocated(BuildCtx & ctx, const char * builder);
  917. void ensureRowAllocated(BuildCtx & ctx, BoundRow * row);
  918. inline BoundRow * bindTableCursor(BuildCtx & ctx, IHqlExpression * dataset, const char * bound, node_operator side, IHqlExpression * selSeq)
  919. { return bindTableCursor(ctx, dataset, bound, false, side, selSeq); }
  920. inline BoundRow * bindTableCursor(BuildCtx & ctx, IHqlExpression * dataset, const char * bound)
  921. { return bindTableCursor(ctx, dataset, bound, false, no_none, NULL); }
  922. inline BoundRow * bindTableCursor(BuildCtx & ctx, IHqlExpression * dataset, IHqlExpression * bound)
  923. { return bindTableCursor(ctx, dataset, bound, no_none, NULL); }
  924. IHqlExpression * getRtlFieldKey(IHqlExpression * expr, IHqlExpression * ownerRecord, bool &isPayload);
  925. unsigned buildRtlField(StringBuffer & instanceName, IHqlExpression * field, IHqlExpression * rowRecord);
  926. unsigned buildRtlType(StringBuffer & instanceName, ITypeInfo * type);
  927. unsigned buildRtlRecordFields(StringBuffer & instanceName, IHqlExpression * record, IHqlExpression * rowRecord);
  928. unsigned expandRtlRecordFields(StringBuffer & fieldListText, IHqlExpression * record, IHqlExpression * rowRecord);
  929. unsigned buildRtlIfBlockField(StringBuffer & instanceName, IHqlExpression * ifblock, IHqlExpression * rowRecord, bool isPayload);
  930. void buildMetaInfo(MetaInstance & instance);
  931. IHqlExpression * buildMetaParameter(IHqlExpression * arg);
  932. void buildMetaForRecord(StringBuffer & name, IHqlExpression * record);
  933. void buildMetaForSerializedRecord(StringBuffer & name, IHqlExpression * record, bool isGrouped);
  934. BoundRow * createBoundRow(IHqlExpression * dataset, IHqlExpression * bound);
  935. void getRecordSize(BuildCtx & ctx, IHqlExpression * dataset, CHqlBoundExpr & bound);
  936. BoundRow * resolveSelectorDataset(BuildCtx & ctx, IHqlExpression * dataset);
  937. BoundRow * resolveDatasetRequired(BuildCtx & ctx, IHqlExpression * expr);
  938. ColumnToOffsetMap * queryRecordOffsetMap(IHqlExpression * record, bool isTargetRow);
  939. IHqlExpression * queryRecord(BuildCtx & ctx, IHqlExpression * expr);
  940. RecordOffsetMap & queryRecordMap() { return recordMap; }
  941. unsigned getDefaultMaxRecordSize() { return options.maxRecordSize; }
  942. void buildReturnRecordSize(BuildCtx & ctx, BoundRow * cursor);
  943. bool isFixedRecordSize(IHqlExpression * record);
  944. bool recordContainsIfBlock(IHqlExpression * record);
  945. unsigned getFixedRecordSize(IHqlExpression * record);
  946. unsigned getMaxRecordSize(IHqlExpression * record);
  947. IHqlExpression * getRecordSize(IHqlExpression * dataset);
  948. unsigned getCsvMaxLength(IHqlExpression * csvAttr);
  949. void ensureRowSerializer(StringBuffer & serializerName, BuildCtx & ctx, IHqlExpression * record, IAtom * format, IAtom * kind);
  950. void ensureRowPrefetcher(StringBuffer & prefetcherName, BuildCtx & ctx, IHqlExpression * record);
  951. IHqlExpression * createSerializer(BuildCtx & ctx, IHqlExpression * record, IAtom * format, IAtom * kind);
  952. void buildRowAccessors();
  953. void buildRowAccessor(ColumnToOffsetMap * map);
  954. AliasKind buildExprInCorrectContext(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt, bool evaluateLocally);
  955. ParentExtract * createExtractBuilder(BuildCtx & ctx, PEtype type, IHqlExpression * graphId, IHqlExpression * expr, bool doDeclare);
  956. ParentExtract * createExtractBuilder(BuildCtx & ctx, PEtype type, IHqlExpression * graphId, GraphLocalisation localisation, bool doDeclare);
  957. void buildDefaultRow(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & bound);
  958. void buildNullRow(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & bound);
  959. void buildTransformBody(BuildCtx & ctx, IHqlExpression * transform, IHqlExpression * left, IHqlExpression * right, IHqlExpression * self, IHqlExpression * selSeq);
  960. BoundRow * buildTransformCursors(BuildCtx & ctx, IHqlExpression * transform, IHqlExpression * left, IHqlExpression * right, IHqlExpression * self, IHqlExpression * selSeq);
  961. void doBuildTransformBody(BuildCtx & ctx, IHqlExpression * transform, BoundRow * selfCursor);
  962. void noteXpathUsed(const char * xpath);
  963. void noteXpathUsed(IHqlExpression * expr);
  964. HqlCppOptions const & queryOptions() const { return options; }
  965. bool needToSerializeToSlave(IHqlExpression * expr) const;
  966. void noteFinishedTiming(const char * name, cycle_t startCycles)
  967. {
  968. timeReporter->addTiming(name, get_cycles_now()-startCycles);
  969. }
  970. void updateClusterType();
  971. bool buildCode(HqlQueryContext & query, const char * embeddedLibraryName, const char * embeddedGraphName);
  972. inline StringBuffer & generateExprCpp(StringBuffer & out, IHqlExpression * expr)
  973. {
  974. return ::generateExprCpp(out, expr, options.targetCompiler);
  975. }
  976. inline StringBuffer & generateTypeCpp(StringBuffer & out, ITypeInfo * type, const char * name)
  977. {
  978. return ::generateTypeCpp(out, type, name, options.targetCompiler);
  979. }
  980. void setTargetClusterType(ClusterType clusterType);
  981. void ensureDiskAccessAllowed(IHqlExpression * expr);
  982. void checkAbort();
  983. public:
  984. //various helper functions.
  985. IHqlExpression * addBigLiteral(const char *lit, unsigned litLen);
  986. IHqlExpression * addLiteral(const char * text);
  987. IHqlExpression * addDataLiteral(const char *lit, unsigned litLen);
  988. IHqlExpression * addStringLiteral(const char *lit);
  989. IHqlExpression * associateLocalFailure(BuildCtx & ctx, const char * exceptionName);
  990. IHqlExpression * convertBoundStringToChar(const CHqlBoundExpr & bound);
  991. void createTempFor(BuildCtx & ctx, ITypeInfo * exprType, CHqlBoundTarget & target, typemod_t modifier, ExpressionFormat format);
  992. void createTempFor(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundTarget & target);
  993. BoundRow * declareTempRow(BuildCtx & ctx, BuildCtx & codectx, IHqlExpression * expr);
  994. BoundRow * createRowBuilder(BuildCtx & ctx, BoundRow * targetRow);
  995. void finalizeTempRow(BuildCtx & ctx, BoundRow * targetRow, BoundRow * rowBuilder);
  996. BoundRow * declareTempAnonRow(BuildCtx & ctx, BuildCtx & codectx, IHqlExpression * record);
  997. IHqlExpression * declareLinkedRowExpr(BuildCtx & ctx, IHqlExpression * record, bool isMember);
  998. BoundRow * declareLinkedRow(BuildCtx & ctx, IHqlExpression * expr, bool isMember);
  999. BoundRow * declareStaticRow(BuildCtx & ctx, IHqlExpression * expr);
  1000. void expandTranslated(IHqlExpression * expr, CHqlBoundExpr & tgt);
  1001. IHqlExpression * getBoundCount(const CHqlBoundExpr & bound);
  1002. IHqlExpression * getBoundLength(const CHqlBoundExpr & bound);
  1003. IHqlExpression * getBoundSize(const CHqlBoundExpr & bound);
  1004. IHqlExpression * getBoundSize(ITypeInfo * type, IHqlExpression * length, IHqlExpression * data);
  1005. IHqlExpression * getElementPointer(IHqlExpression * source);
  1006. IHqlExpression * getIndexedElementPointer(IHqlExpression * source, IHqlExpression * index);
  1007. IHqlExpression * getIndexedElementPointer(IHqlExpression * source, unsigned index);
  1008. IHqlExpression * getListLength(BuildCtx & ctx, IHqlExpression * expr);
  1009. void getRecordECL(IHqlExpression * record, StringBuffer & eclText);
  1010. void ensureHasAddress(BuildCtx & ctx, CHqlBoundExpr & tgt);
  1011. void normalizeBoundExpr(BuildCtx & ctx, CHqlBoundExpr & bound);
  1012. ICodegenContextCallback * queryCallback() { return ctxCallback; }
  1013. IWorkUnit * wu() { return code->workunit; }
  1014. void useInclude(const char * name) { code->useInclude(name); }
  1015. HqlCppInstance * queryCode() const { return code; }
  1016. unsigned curSubGraphId(BuildCtx & ctx);
  1017. unsigned beginFunctionGetCppIndex(unsigned activityId, bool isChildActivity);
  1018. void buildAssignToTemp(BuildCtx & ctx, IHqlExpression * variable, IHqlExpression * expr); // create a bound target for the variable and assign
  1019. void queryAddResultDependancy(ABoundActivity & whoAmIActivity, IHqlExpression * seq, IHqlExpression * name);
  1020. void associateRemoteResult(ActivityInstance & instance, IHqlExpression * seq, IHqlExpression * name);
  1021. IHqlCppSetCursor * createSetSelector(BuildCtx & ctx, IHqlExpression * expr);
  1022. IHqlCppSetBuilder * createTempSetBuilder(ITypeInfo * type, IHqlExpression * allVar);
  1023. IHqlCppSetBuilder * createInlineSetBuilder(ITypeInfo * type, IHqlExpression * allVar, IHqlExpression * size, IHqlExpression * address);
  1024. IHqlCppDatasetCursor * createDatasetSelector(BuildCtx & ctx, IHqlExpression * expr, ExpressionFormat format = FormatNatural);
  1025. IHqlCppDatasetBuilder * createBlockedDatasetBuilder(IHqlExpression * record);
  1026. IHqlCppDatasetBuilder * createSingleRowTempDatasetBuilder(IHqlExpression * record, BoundRow * row);
  1027. IHqlCppDatasetBuilder * createInlineDatasetBuilder(IHqlExpression * record, IHqlExpression * size, IHqlExpression * address);
  1028. IHqlCppDatasetBuilder * createChoosenDatasetBuilder(IHqlExpression * record, IHqlExpression * maxCount);
  1029. IHqlCppDatasetBuilder * createLimitedDatasetBuilder(IHqlExpression * record, IHqlExpression * maxCount);
  1030. IHqlCppDatasetBuilder * createLinkedDatasetBuilder(IHqlExpression * record, IHqlExpression * choosenLimit = NULL);
  1031. IHqlCppDatasetBuilder * createLinkedDictionaryBuilder(IHqlExpression * record);
  1032. IReferenceSelector * createSelfSelect(BuildCtx & ctx, IReferenceSelector * target, IHqlExpression * expr, IHqlExpression * rootSelector);
  1033. IReferenceSelector * createReferenceSelector(BoundRow * cursor, IHqlExpression * path);
  1034. IReferenceSelector * createReferenceSelector(BoundRow * cursor);
  1035. IHqlExpression * convertBetweenCountAndSize(const CHqlBoundExpr & bound, bool getLength);
  1036. void assignBound(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * rhs); // assign rhs to
  1037. void assignBoundToTemp(BuildCtx & ctx, IHqlExpression * lhs, IHqlExpression * rhs);
  1038. bool expandFunctionPrototype(StringBuffer & s, IHqlExpression * funcdef);
  1039. void expandFunctionPrototype(BuildCtx & ctx, IHqlExpression * funcdef);
  1040. void buildCppFunctionDefinition(BuildCtx &funcctx, IHqlExpression * bodycode, const char *proto);
  1041. void buildScriptFunctionDefinition(BuildCtx &funcctx, IHqlExpression * bodycode, const char *proto);
  1042. void buildFunctionDefinition(IHqlExpression * funcdef);
  1043. void assignAndCast(BuildCtx & ctx, const CHqlBoundTarget & target, CHqlBoundExpr & expr);
  1044. void assignCastUnknownLength(BuildCtx & ctx, const CHqlBoundTarget & target, CHqlBoundExpr & pure);
  1045. void assignSwapInt(BuildCtx & ctx, ITypeInfo * to, const CHqlBoundTarget & target, CHqlBoundExpr & pure);
  1046. void buildAssignViaTemp(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1047. void buildRecordSerializeExtract(BuildCtx & ctx, IHqlExpression * memoryRecord);
  1048. void doBuildSetAssignAndCast(BuildCtx & ctx, IHqlCppSetBuilder * builder, IHqlExpression * value);
  1049. IHqlExpression * createWrapperTemp(BuildCtx & ctx, ITypeInfo * type, typemod_t modifier);
  1050. void doBuildExprAssign(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1051. void doBuildBoolAssign(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1052. void doBuildChoose(BuildCtx & ctx, const CHqlBoundTarget * target, IHqlExpression * expr);
  1053. void buildExprAssignViaType(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr, ITypeInfo * type);
  1054. void buildExprAssignViaString(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr, ITypeInfo * dest);
  1055. void doBuildDivideByZero(BuildCtx & ctx, const CHqlBoundTarget * target, IHqlExpression * zero, CHqlBoundExpr * bound);
  1056. void doBuildAssignAddSets(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * value);
  1057. void doBuildAssignAggregate(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1058. void doBuildAssignAll(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1059. void doBuildAssignAnd(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr, bool invert);
  1060. void doBuildAssignCall(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * src);
  1061. void doBuildAssignCast(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * src);
  1062. void doBuildAssignCatch(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1063. void doBuildAssignChoose(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1064. void doBuildAssignCompare(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1065. void doBuildAssignConcat(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1066. void doBuildAssignCount(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1067. void doBuildAssignDivide(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1068. void doBuildAssignExecuteWhen(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1069. void doBuildAssignEventExtra(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1070. void doBuildAssignEventName(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1071. void doBuildAssignFailMessage(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1072. void doBuildAssignFormat(IIdAtom * func, BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1073. void doBuildAssignGetResult(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1074. void doBuildAssignGetGraphResult(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1075. void doBuildAssignHashCrc(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1076. void doBuildAssignHashElement(BuildCtx & ctx, HashCodeCreator & creator, IHqlExpression * elem);
  1077. void doBuildAssignHashElement(BuildCtx & ctx, HashCodeCreator & creator, IHqlExpression * elem, IHqlExpression * record);
  1078. void doBuildAssignHashMd5(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1079. void doBuildAssignIdToBlob(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1080. void doBuildAssignIf(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1081. void doBuildAssignIn(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1082. void doBuildAssignInCreateSet(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1083. void doBuildAssignInStored(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1084. void doBuildAssignIndex(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1085. void doBuildAssignList(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1086. void doBuildAssignLoopCounter(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1087. void doBuildAssignOr(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1088. void doBuildAssignOrder(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1089. void doBuildAssignUnicodeOrder(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1090. void doBuildAssignRegexFindReplace(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1091. void doBuildAssignSubString(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1092. void doBuildAssignToXmlorJson(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1093. void doBuildAssignTrim(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1094. void doBuildAssignWhich(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1095. void doBuildAssignWuid(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1096. void doBuildCaseInfo(IHqlExpression * expr, HqlCppCaseInfo & info);
  1097. void doBuildInCaseInfo(IHqlExpression * expr, HqlCppCaseInfo & info, IHqlExpression * normalizedValues = NULL);
  1098. void doBuildAssignToFromUnicode(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1099. void buildAssignDeserializedDataset(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr, IAtom * serializeForm);
  1100. void buildAssignSerializedDataset(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr, IAtom * serializeForm);
  1101. void buildDeserializedDataset(BuildCtx & ctx, ITypeInfo * type, IHqlExpression * expr, CHqlBoundExpr & tgt, IAtom * serializeForm);
  1102. void buildSerializedDataset(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt, IAtom * serializeForm);
  1103. void buildDatasetAssignAggregate(BuildCtx & ctx, IHqlCppDatasetBuilder * target, IHqlExpression * expr);
  1104. void buildDatasetAssignChoose(BuildCtx & ctx, IHqlCppDatasetBuilder * target, IHqlExpression * expr);
  1105. void buildDatasetAssignCombine(BuildCtx & ctx, IHqlCppDatasetBuilder * target, IHqlExpression * expr);
  1106. void buildDatasetAssignInlineTable(BuildCtx & ctx, IHqlCppDatasetBuilder * target, IHqlExpression * expr);
  1107. void buildDatasetAssignDatasetFromTransform(BuildCtx & ctx, IHqlCppDatasetBuilder * target, IHqlExpression * expr);
  1108. void buildDatasetAssignJoin(BuildCtx & ctx, IHqlCppDatasetBuilder * target, IHqlExpression * expr);
  1109. void buildDatasetAssignProject(BuildCtx & ctx, IHqlCppDatasetBuilder * target, IHqlExpression * expr);
  1110. void buildDatasetAssignTempTable(BuildCtx & ctx, IHqlCppDatasetBuilder * target, IHqlExpression * expr);
  1111. void buildDatasetAssignXmlProject(BuildCtx & ctx, IHqlCppDatasetBuilder * target, IHqlExpression * expr);
  1112. void buildDatasetAssignChoose(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1113. void buildDatasetAssignIf(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr);
  1114. BoundRow * buildDatasetIterateSelectN(BuildCtx & ctx, IHqlExpression * expr, bool needToBreak);
  1115. BoundRow * buildDatasetIterateChoosen(BuildCtx & ctx, IHqlExpression * expr, bool needToBreak);
  1116. BoundRow * buildDatasetIterateFromDictionary(BuildCtx & ctx, IHqlExpression * expr, bool needToBreak);
  1117. BoundRow * buildDatasetIterateLimit(BuildCtx & ctx, IHqlExpression * expr, bool needToBreak);
  1118. BoundRow * buildDatasetIterateProject(BuildCtx & ctx, IHqlExpression * expr, bool needToBreak);
  1119. BoundRow * buildDatasetIterateUserTable(BuildCtx & ctx, IHqlExpression * expr, bool needToBreak);
  1120. BoundRow * buildDatasetIterateSpecialTempTable(BuildCtx & ctx, IHqlExpression * expr, bool needToBreak);
  1121. BoundRow * buildDatasetIterateStreamedCall(BuildCtx & ctx, IHqlExpression * expr, bool needToBreak);
  1122. void createInlineDictionaryRows(HqlExprArray & args, ConstantRowArray & boundRows, IHqlExpression * keyRecord, IHqlExpression * nullRow);
  1123. bool buildConstantRows(ConstantRowArray & boundRows, IHqlExpression * transforms);
  1124. void doBuildDatasetLimit(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt, ExpressionFormat format);
  1125. bool doBuildConstantDatasetInlineTable(IHqlExpression * expr, CHqlBoundExpr & tgt, ExpressionFormat format);
  1126. bool doBuildDictionaryInlineTable(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt, ExpressionFormat format);
  1127. void doBuildDatasetNull(IHqlExpression * expr, CHqlBoundExpr & tgt, ExpressionFormat format);
  1128. void doBuildCheckDatasetLimit(BuildCtx & ctx, IHqlExpression * expr, const CHqlBoundExpr & bound);
  1129. void doBuildRowAssignAggregate(BuildCtx & ctx, IReferenceSelector * target, IHqlExpression * expr);
  1130. void doBuildRowAssignAggregateClear(BuildCtx & ctx, IReferenceSelector * target, IHqlExpression * expr);
  1131. void doBuildRowAssignAggregateNext(BuildCtx & ctx, IReferenceSelector * target, IHqlExpression * expr, bool isSingleExists, IHqlExpression * guard);
  1132. void doBuildRowAssignCombine(BuildCtx & ctx, IReferenceSelector * target, IHqlExpression * expr);
  1133. void doBuildRowAssignNullRow(BuildCtx & ctx, IReferenceSelector * target, IHqlExpression * expr);
  1134. void doBuildRowAssignProject(BuildCtx & ctx, IReferenceSelector * target, IHqlExpression * expr);
  1135. void doBuildRowAssignUserTable(BuildCtx & ctx, IReferenceSelector * target, IHqlExpression * expr);
  1136. void doBuildRowAssignProjectRow(BuildCtx & ctx, IReferenceSelector * target, IHqlExpression * expr);
  1137. void doBuildRowAssignCreateRow(BuildCtx & ctx, IReferenceSelector * target, IHqlExpression * expr);
  1138. void doBuildRowAssignSerializeRow(BuildCtx & ctx, IReferenceSelector * target, IHqlExpression * expr);
  1139. IReferenceSelector * doBuildRowDeserializeRow(BuildCtx & ctx, IHqlExpression * expr);
  1140. IReferenceSelector * doBuildRowFromXMLorJSON(BuildCtx & ctx, IHqlExpression * expr);
  1141. IReferenceSelector * doBuildRowIdToBlob(BuildCtx & ctx, IHqlExpression * expr, bool isNew);
  1142. IReferenceSelector * doBuildRowIf(BuildCtx & ctx, IHqlExpression * expr);
  1143. IReferenceSelector * doBuildRowMatchAttr(BuildCtx & ctx, IHqlExpression * expr);
  1144. IReferenceSelector * doBuildRowMatchRow(BuildCtx & ctx, IHqlExpression * expr, bool isNew);
  1145. IReferenceSelector * doBuildRowSelectTop(BuildCtx & ctx, IHqlExpression * expr);
  1146. IReferenceSelector * doBuildRowViaTemp(BuildCtx & ctx, IHqlExpression * expr);
  1147. IReferenceSelector * doBuildRowCreateRow(BuildCtx & ctx, IHqlExpression * expr);
  1148. IReferenceSelector * doBuildRowNull(BuildCtx & ctx, IHqlExpression * expr);
  1149. void buildConstRow(IHqlExpression * record, IHqlExpression * rowData, CHqlBoundExpr & bound);
  1150. bool doBuildRowConstantNull(IHqlExpression * expr, CHqlBoundExpr & bound);
  1151. bool doBuildRowConstantTransform(IHqlExpression * transform, CHqlBoundExpr & bound);
  1152. void doBuildRowIfBranch(BuildCtx & initctx, BuildCtx & ctx, BoundRow * targetRow, IHqlExpression * branchExpr);
  1153. void doBuildReturnCompare(BuildCtx & ctx, IHqlExpression * expr, node_operator op, bool isBoolEquality, bool neverReturnTrue);
  1154. void buildReturnOrder(BuildCtx & ctx, IHqlExpression *sortList, const DatasetReference & dataset);
  1155. IHqlExpression * createLoopSubquery(IHqlExpression * dataset, IHqlExpression * selSeq, IHqlExpression * rowsid, IHqlExpression * body, IHqlExpression * filter, IHqlExpression * again, IHqlExpression * counter, bool multiInstance, unsigned & loopAgainResult);
  1156. unique_id_t buildGraphLoopSubgraph(BuildCtx & ctx, IHqlExpression * dataset, IHqlExpression * selSeq, IHqlExpression * rowsid, IHqlExpression * body, IHqlExpression * counter, bool multiInstance, bool unlimitedResources);
  1157. unique_id_t buildRemoteSubgraph(BuildCtx & ctx, IHqlExpression * dataset);
  1158. void doBuildCall(BuildCtx & ctx, const CHqlBoundTarget * tgt, IHqlExpression * expr, CHqlBoundExpr * result);
  1159. IHqlExpression * doBuildInternalFunction(IHqlExpression * funcdef);
  1160. IHqlExpression * doBuildCharLength(BuildCtx & ctx, IHqlExpression * expr);
  1161. void doBuildHashMd5Element(BuildCtx & ctx, IHqlExpression * elem, CHqlBoundExpr & state);
  1162. AliasKind doBuildAliasValue(BuildCtx & ctx, IHqlExpression * value, CHqlBoundExpr & tgt, AliasExpansionInfo * parentInfo);
  1163. void pushCluster(BuildCtx & ctx, IHqlExpression * cluster);
  1164. void popCluster(BuildCtx & ctx);
  1165. void noteResultAccessed(BuildCtx & ctx, IHqlExpression * seq, IHqlExpression * name);
  1166. void noteResultDefined(BuildCtx & ctx, ActivityInstance * activityInstance, IHqlExpression * seq, IHqlExpression * name, bool alwaysExecuted);
  1167. //Expressions:
  1168. void doBuildExprAbs(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1169. void doBuildExprAdd(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1170. void doBuildExprAggregate(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1171. void doBuildExprAlias(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr * tgt, AliasExpansionInfo * parentInfo);
  1172. void doBuildExprAll(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1173. void doBuildExprBlobToId(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1174. void doBuildExprArith(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1175. void doBuildExprCall(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1176. void doBuildExprCast(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1177. void doBuildExprCast(BuildCtx & ctx, ITypeInfo * type, CHqlBoundExpr & pure, CHqlBoundExpr & tgt);
  1178. void doBuildExprCompare(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1179. void doBuildExprCompareElement(BuildCtx & ctx, node_operator comp_op, IHqlExpression * lhs, IHqlExpression * rhs, CHqlBoundExpr & tgt);
  1180. void doBuildExprCountDict(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1181. void doBuildExprCount(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1182. void doBuildExprCounter(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1183. void doBuildExprDivide(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1184. void doBuildExprEmbedBody(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr * tgt);
  1185. void doBuildExprEvaluate(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1186. void doBuildExprExists(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1187. void doBuildExprExistsDict(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1188. void doBuildExprFailCode(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1189. void doBuildExprField(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1190. void doBuildExprFileLogicalName(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1191. void doBuildExprFilepos(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1192. void doBuildExprFormat(IIdAtom * func, BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1193. void doBuildExprGetGraphResult(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt, ExpressionFormat format);
  1194. void doBuildExprGetResult(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1195. void doBuildExprIdToBlob(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1196. void doBuildExprIf(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1197. void doBuildExprIndex(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1198. void doBuildExprInDict(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1199. void doBuildExprIsValid(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1200. void doBuildExprList(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1201. void doBuildExprConstList(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1202. void doBuildExprDynList(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1203. void doBuildExprMatchedInJoin(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1204. void doBuildExprNegate(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1205. void doBuildExprNot(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1206. void doBuildExprOffsetOf(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1207. void doBuildExprOrdered(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1208. void doBuildExprRank(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1209. void doBuildExprRanked(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1210. void doBuildExprRegexFindReplace(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & bound);
  1211. void doBuildExprRegexFindSet(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & bound);
  1212. void doBuildExprRound(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1213. void doBuildExprSelect(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1214. void doBuildExprSizeof(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1215. void doBuildExprSubString(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1216. void doBuildExprSysFunc(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt, IIdAtom * funcName, byte dbz = 0);
  1217. void doBuildExprTransfer(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1218. void doBuildExprTrim(BuildCtx & ctx, IHqlExpression * target, CHqlBoundExpr & tgt);
  1219. void doBuildExprTrunc(BuildCtx & ctx, IHqlExpression * target, CHqlBoundExpr & tgt);
  1220. void doBuildExprToFromUnicode(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1221. void doBuildExprKeyUnicode(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1222. void doBuildExprWuid(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1223. void doBuildExprXmlText(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1224. void doBuildExprXmlUnicode(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1225. bool doBuildExprInfiniteSubString(BuildCtx & ctx, SubStringInfo & info, CHqlBoundExpr & tgt);
  1226. bool doBuildExprSpecialSubString(BuildCtx & ctx, SubStringInfo & info, CHqlBoundExpr & tgt);
  1227. void doBuildExprAnySubString(BuildCtx & ctx, SubStringInfo & info, CHqlBoundExpr & tgt);
  1228. bool doBuildExprSetCompare(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1229. void doBuildExprSetCompareAll(BuildCtx & ctx, IHqlExpression * set, CHqlBoundExpr & tgt, bool invert);
  1230. void doBuildExprSetCompareNone(BuildCtx & ctx, IHqlExpression * set, CHqlBoundExpr & tgt, bool invert);
  1231. void doBuildAggregateList(BuildCtx & ctx, const CHqlBoundTarget * target, IHqlExpression * expr, CHqlBoundExpr * tgt);
  1232. bool doBuildAggregateMinMaxList(BuildCtx & ctx, const CHqlBoundTarget * target, IHqlExpression * expr, IHqlExpression * list, CHqlBoundExpr * tgt, node_operator compareOp);
  1233. void buildWorkflow(WorkflowArray & workflow);
  1234. void buildWorkflowItem(BuildCtx & ctx, IHqlStmt * switchStmt, unsigned wfid, IHqlExpression * expr);
  1235. void buildWorkflowPersistCheck(BuildCtx & ctx, IHqlExpression * expr);
  1236. IHqlExpression * cvtGetEnvToCall(IHqlExpression * expr);
  1237. //Statements
  1238. void doBuildStmtApply(BuildCtx & ctx, IHqlExpression * expr);
  1239. void doBuildStmtAssert(BuildCtx & ctx, IHqlExpression * expr);
  1240. void doBuildStmtAssign(BuildCtx & ctx, IHqlExpression * target, IHqlExpression * expr);
  1241. void doBuildStmtAssignModify(BuildCtx & ctx, IHqlExpression * target, IHqlExpression * expr, node_operator op);
  1242. void doBuildStmtCall(BuildCtx & ctx, IHqlExpression * expr);
  1243. void doBuildStmtCluster(BuildCtx & ctx, IHqlExpression * expr);
  1244. void doBuildStmtEnsureResult(BuildCtx & ctx, IHqlExpression * expr);
  1245. void doBuildStmtFail(BuildCtx & ctx, IHqlExpression * expr);
  1246. void doBuildStmtIf(BuildCtx & ctx, IHqlExpression * expr);
  1247. void doBuildStmtNotify(BuildCtx & ctx, IHqlExpression * expr);
  1248. void doBuildStmtOutput(BuildCtx & ctx, IHqlExpression * expr);
  1249. void doBuildStmtSetResult(BuildCtx & ctx, IHqlExpression * expr);
  1250. void doBuildStmtSkip(BuildCtx & ctx, IHqlExpression * expr, bool * canReachFollowing);
  1251. void doBuildStmtUpdate(BuildCtx & ctx, IHqlExpression * expr);
  1252. void doBuildStmtWait(BuildCtx & ctx, IHqlExpression * expr);
  1253. void optimizeBuildActionList(BuildCtx & ctx, IHqlExpression * exprs);
  1254. bool buildNWayInputs(CIArrayOf<ABoundActivity> & inputs, BuildCtx & ctx, IHqlExpression * input);
  1255. //Activities.
  1256. ABoundActivity * doBuildActivityAction(BuildCtx & ctx, IHqlExpression * expr, bool isRoot);
  1257. ABoundActivity * doBuildActivityAggregate(BuildCtx & ctx, IHqlExpression * expr);
  1258. ABoundActivity * doBuildActivityApply(BuildCtx & ctx, IHqlExpression * expr, bool isRoot);
  1259. ABoundActivity * doBuildActivityAssert(BuildCtx & ctx, IHqlExpression * expr);
  1260. ABoundActivity * doBuildActivityCacheAlias(BuildCtx & ctx, IHqlExpression * expr);
  1261. ABoundActivity * doBuildActivityCallSideEffect(BuildCtx & ctx, IHqlExpression * expr);
  1262. ABoundActivity * doBuildActivityCase(BuildCtx & ctx, IHqlExpression * expr, bool isRoot);
  1263. ABoundActivity * doBuildActivityCatch(BuildCtx & ctx, IHqlExpression * expr);
  1264. ABoundActivity * doBuildActivityChildAggregate(BuildCtx & ctx, IHqlExpression * expr);
  1265. ABoundActivity * doBuildActivityChildDataset(BuildCtx & ctx, IHqlExpression * expr);
  1266. ABoundActivity * doBuildActivityChildGroupAggregate(BuildCtx & ctx, IHqlExpression * expr);
  1267. ABoundActivity * doBuildActivityChildNormalize(BuildCtx & ctx, IHqlExpression * expr);
  1268. ABoundActivity * doBuildActivityChoose(BuildCtx & ctx, IHqlExpression * expr, IHqlExpression * cond, CIArrayOf<ABoundActivity> & inputs, bool isRoot);
  1269. ABoundActivity * doBuildActivityChoose(BuildCtx & ctx, IHqlExpression * expr, bool isRoot);
  1270. ABoundActivity * doBuildActivityChooseSets(BuildCtx & ctx, IHqlExpression * expr);
  1271. ABoundActivity * doBuildActivityChooseSetsEx(BuildCtx & ctx, IHqlExpression * expr);
  1272. ABoundActivity * doBuildActivityCloned(BuildCtx & ctx, IHqlExpression * expr);
  1273. ABoundActivity * doBuildActivityCombine(BuildCtx & ctx, IHqlExpression * expr);
  1274. ABoundActivity * doBuildActivityCombineGroup(BuildCtx & ctx, IHqlExpression * expr);
  1275. ABoundActivity * doBuildActivityCompoundSelectNew(BuildCtx & ctx, IHqlExpression * expr);
  1276. ABoundActivity * doBuildActivityConcat(BuildCtx & ctx, IHqlExpression * expr);
  1277. ABoundActivity * doBuildActivityCountTransform(BuildCtx & ctx, IHqlExpression * expr);
  1278. ABoundActivity * doBuildActivityCreateRow(BuildCtx & ctx, IHqlExpression * expr, bool isDataset);
  1279. ABoundActivity * doBuildActivityXmlRead(BuildCtx & ctx, IHqlExpression * expr);
  1280. ABoundActivity * doBuildActivityDedup(BuildCtx & ctx, IHqlExpression * expr);
  1281. ABoundActivity * doBuildActivityDefineSideEffect(BuildCtx & ctx, IHqlExpression * expr);
  1282. ABoundActivity * doBuildActivityDenormalize(BuildCtx & ctx, IHqlExpression * expr);
  1283. ABoundActivity * doBuildActivityDictionaryWorkunitWrite(BuildCtx & ctx, IHqlExpression * expr, bool isRoot);
  1284. ABoundActivity * doBuildActivityDiskAggregate(BuildCtx & ctx, IHqlExpression * expr);
  1285. ABoundActivity * doBuildActivityDiskGroupAggregate(BuildCtx & ctx, IHqlExpression * expr);
  1286. ABoundActivity * doBuildActivityDiskNormalize(BuildCtx & ctx, IHqlExpression * expr);
  1287. ABoundActivity * doBuildActivityDiskRead(BuildCtx & ctx, IHqlExpression * expr);
  1288. ABoundActivity * doBuildActivityDistribute(BuildCtx & ctx, IHqlExpression * expr);
  1289. ABoundActivity * doBuildActivityDistribution(BuildCtx & ctx, IHqlExpression * expr, bool isRoot);
  1290. ABoundActivity * doBuildActivitySectionInput(BuildCtx & ctx, IHqlExpression * expr);
  1291. ABoundActivity * doBuildActivityEnth(BuildCtx & ctx, IHqlExpression * expr);
  1292. ABoundActivity * doBuildActivityExecuteWhen(BuildCtx & ctx, IHqlExpression * expr, bool isRoot);
  1293. ABoundActivity * doBuildActivityForceLocal(BuildCtx & ctx, IHqlExpression * expr);
  1294. ABoundActivity * doBuildActivityFetch(BuildCtx & ctx, IHqlExpression * expr);
  1295. ABoundActivity * doBuildActivityFilter(BuildCtx & ctx, IHqlExpression * expr);
  1296. ABoundActivity * doBuildActivityFilterGroup(BuildCtx & ctx, IHqlExpression * expr);
  1297. ABoundActivity * doBuildActivityGetGraphResult(BuildCtx & ctx, IHqlExpression * expr);
  1298. ABoundActivity * doBuildActivityGetGraphLoopResult(BuildCtx & ctx, IHqlExpression * expr);
  1299. ABoundActivity * doBuildActivityGraphLoop(BuildCtx & ctx, IHqlExpression * expr);
  1300. ABoundActivity * doBuildActivityGroup(BuildCtx & ctx, IHqlExpression * expr);
  1301. ABoundActivity * doBuildActivityIf(BuildCtx & ctx, IHqlExpression * expr, bool isRoot);
  1302. ABoundActivity * doBuildActivityIndexAggregate(BuildCtx & ctx, IHqlExpression * expr);
  1303. ABoundActivity * doBuildActivityIndexGroupAggregate(BuildCtx & ctx, IHqlExpression * expr);
  1304. ABoundActivity * doBuildActivityIndexNormalize(BuildCtx & ctx, IHqlExpression * expr);
  1305. ABoundActivity * doBuildActivityIndexRead(BuildCtx & ctx, IHqlExpression * expr);
  1306. ABoundActivity * doBuildActivityInlineTable(BuildCtx & ctx, IHqlExpression * expr);
  1307. ABoundActivity * doBuildActivityIterate(BuildCtx & ctx, IHqlExpression * expr);
  1308. ABoundActivity * doBuildActivityJoin(BuildCtx & ctx, IHqlExpression * expr);
  1309. ABoundActivity * doBuildActivityJoinOrDenormalize(BuildCtx & ctx, IHqlExpression * expr);
  1310. ABoundActivity * doBuildActivityKeyDiff(BuildCtx & ctx, IHqlExpression * expr, bool isRoot);
  1311. ABoundActivity * doBuildActivityKeyedJoinOrDenormalize(BuildCtx & ctx, IHqlExpression * expr);
  1312. ABoundActivity * doBuildActivityKeyedDistribute(BuildCtx & ctx, IHqlExpression * expr);
  1313. ABoundActivity * doBuildActivityKeyPatch(BuildCtx & ctx, IHqlExpression * expr, bool isRoot);
  1314. ABoundActivity * doBuildActivityLibraryInstance(BuildCtx & ctx, IHqlExpression * expr);
  1315. ABoundActivity * doBuildActivityLibrarySelect(BuildCtx & ctx, IHqlExpression * expr);
  1316. ABoundActivity * doBuildActivityLimit(BuildCtx & ctx, IHqlExpression * expr);
  1317. ABoundActivity * doBuildActivityLinkedRawChildDataset(BuildCtx & ctx, IHqlExpression * expr);
  1318. ABoundActivity * doBuildActivityLoop(BuildCtx & ctx, IHqlExpression * expr);
  1319. ABoundActivity * doBuildActivityMerge(BuildCtx & ctx, IHqlExpression * expr);
  1320. ABoundActivity * doBuildActivityNonEmpty(BuildCtx & ctx, IHqlExpression * expr);
  1321. ABoundActivity * doBuildActivityNWayMerge(BuildCtx & ctx, IHqlExpression * expr);
  1322. ABoundActivity * doBuildActivityNWayMergeJoin(BuildCtx & ctx, IHqlExpression * expr);
  1323. ABoundActivity * doBuildActivityNormalize(BuildCtx & ctx, IHqlExpression * expr);
  1324. ABoundActivity * doBuildActivityNormalizeChild(BuildCtx & ctx, IHqlExpression * expr);
  1325. ABoundActivity * doBuildActivityNormalizeGroup(BuildCtx & ctx, IHqlExpression * expr);
  1326. ABoundActivity * doBuildActivityNormalizeLinkedChild(BuildCtx & ctx, IHqlExpression * expr);
  1327. ABoundActivity * doBuildActivityNull(BuildCtx & ctx, IHqlExpression * expr, bool isRoot);
  1328. ABoundActivity * doBuildActivityOutput(BuildCtx & ctx, IHqlExpression * expr, bool isRoot);
  1329. ABoundActivity * doBuildActivityOutputIndex(BuildCtx & ctx, IHqlExpression * expr, bool isRoot);
  1330. ABoundActivity * doBuildActivityOutputWorkunit(BuildCtx & ctx, IHqlExpression * expr, bool isRoot);
  1331. ABoundActivity * doBuildActivityParse(BuildCtx & ctx, IHqlExpression * expr);
  1332. ABoundActivity * doBuildActivityPipeThrough(BuildCtx & ctx, IHqlExpression * expr);
  1333. ABoundActivity * doBuildActivityPrefetchProject(BuildCtx & ctx, IHqlExpression * expr);
  1334. ABoundActivity * doBuildActivityProject(BuildCtx & ctx, IHqlExpression * expr);
  1335. ABoundActivity * doBuildActivityProcess(BuildCtx & ctx, IHqlExpression * expr);
  1336. ABoundActivity * doBuildActivityPullActivity(BuildCtx & ctx, IHqlExpression * expr);
  1337. ABoundActivity * doBuildActivityQuantile(BuildCtx & ctx, IHqlExpression * expr);
  1338. ABoundActivity * doBuildActivityRegroup(BuildCtx & ctx, IHqlExpression * expr);
  1339. ABoundActivity * doBuildActivityRemote(BuildCtx & ctx, IHqlExpression * expr, bool isRoot);
  1340. ABoundActivity * doBuildActivityReturnResult(BuildCtx & ctx, IHqlExpression * expr, bool isRoot);
  1341. ABoundActivity * doBuildActivityRollup(BuildCtx & ctx, IHqlExpression * expr);
  1342. ABoundActivity * doBuildActivityRollupGroup(BuildCtx & ctx, IHqlExpression * expr);
  1343. ABoundActivity * doBuildActivityRowsetIndex(BuildCtx & ctx, IHqlExpression * expr);
  1344. ABoundActivity * doBuildActivityRowsetRange(BuildCtx & ctx, IHqlExpression * expr);
  1345. ABoundActivity * doBuildActivityRowsetRange(BuildCtx & ctx, IHqlExpression * expr, IHqlExpression * rowset, IHqlExpression * inputSelection);
  1346. ABoundActivity * doBuildActivitySample(BuildCtx & ctx, IHqlExpression * expr);
  1347. ABoundActivity * doBuildActivitySection(BuildCtx & ctx, IHqlExpression * expr);
  1348. ABoundActivity * doBuildActivitySelectNew(BuildCtx & ctx, IHqlExpression * expr);
  1349. ABoundActivity * doBuildActivitySelectNth(BuildCtx & ctx, IHqlExpression * expr);
  1350. ABoundActivity * doBuildActivitySequentialParallel(BuildCtx & ctx, IHqlExpression * expr, bool isRoot);
  1351. ABoundActivity * doBuildActivitySerialize(BuildCtx & ctx, IHqlExpression * expr);
  1352. ABoundActivity * doBuildActivitySetGraphDictionaryResult(BuildCtx & ctx, IHqlExpression * expr, bool isRoot);
  1353. ABoundActivity * doBuildActivitySetGraphResult(BuildCtx & ctx, IHqlExpression * expr, bool isRoot);
  1354. ABoundActivity * doBuildActivitySetGraphLoopResult(BuildCtx & ctx, IHqlExpression * expr);
  1355. ABoundActivity * doBuildActivitySetResult(BuildCtx & ctx, IHqlExpression * expr, bool isRoot);
  1356. ABoundActivity * doBuildActivitySideEffect(BuildCtx & ctx, IHqlExpression * expr, bool isRoot, bool expandChildren);
  1357. ABoundActivity * doBuildActivitySpill(BuildCtx & ctx, IHqlExpression * expr);
  1358. ABoundActivity * doBuildActivitySplit(BuildCtx & ctx, IHqlExpression * expr);
  1359. ABoundActivity * doBuildActivityHTTP(BuildCtx & ctx, IHqlExpression * expr, bool isSink, bool isRoot);
  1360. ABoundActivity * doBuildActivitySOAP(BuildCtx & ctx, IHqlExpression * expr, bool isSink, bool isRoot);
  1361. ABoundActivity * doBuildActivitySort(BuildCtx & ctx, IHqlExpression * expr);
  1362. ABoundActivity * doBuildActivityStreamedCall(BuildCtx & ctx, IHqlExpression * expr);
  1363. ABoundActivity * doBuildActivitySub(BuildCtx & ctx, IHqlExpression * expr);
  1364. ABoundActivity * doBuildActivityTable(BuildCtx & ctx, IHqlExpression * expr);
  1365. ABoundActivity * doBuildActivityFirstN(BuildCtx & ctx, IHqlExpression * expr);
  1366. ABoundActivity * doBuildActivityTempTable(BuildCtx & ctx, IHqlExpression * expr);
  1367. ABoundActivity * doBuildActivityTraceActivity(BuildCtx & ctx, IHqlExpression * expr);
  1368. ABoundActivity * doBuildActivityUngroup(BuildCtx & ctx, IHqlExpression * expr, ABoundActivity * boundDataset);
  1369. ABoundActivity * doBuildActivityWorkunitRead(BuildCtx & ctx, IHqlExpression * expr);
  1370. ABoundActivity * doBuildActivityXmlParse(BuildCtx & ctx, IHqlExpression * expr);
  1371. void doBuildHttpHeaderStringFunction(BuildCtx & ctx, IHqlExpression * expr);
  1372. void doBuildTempTableFlags(BuildCtx & ctx, IHqlExpression * expr, bool isConstant, bool canFilter);
  1373. void doBuildXmlEncode(BuildCtx & ctx, const CHqlBoundTarget * tgt, IHqlExpression * expr, CHqlBoundExpr * result);
  1374. IHqlExpression * doBuildOrderElement(BuildCtx & ctx, IHqlExpression * left, IHqlExpression * right);
  1375. void doBuildFilterAnd(BuildCtx & ctx, IHqlExpression * expr);
  1376. void doBuildFilterAndRange(BuildCtx & ctx, unsigned first, unsigned last, HqlExprArray & conds);
  1377. void doBuildFilterToTarget(BuildCtx & ctx, const CHqlBoundTarget & isOk, HqlExprArray & conds, bool invert);
  1378. void doBuildFilterNextAndRange(BuildCtx & ctx, unsigned & curIndex, unsigned maxIterations, HqlExprArray & conds);
  1379. bool canBuildOptimizedCount(BuildCtx & ctx, IHqlExpression * dataset, CHqlBoundExpr & tgt, node_operator aggOp);
  1380. void setBoundCount(CHqlBoundExpr & tgt, const CHqlBoundExpr & src, node_operator aggOp);
  1381. bool canEvaluateInContext(BuildCtx & ctx, IHqlExpression * expr);
  1382. void gatherActiveCursors(BuildCtx & ctx, HqlExprCopyArray & activeRows);
  1383. IHqlStmt * buildFilterViaExpr(BuildCtx & ctx, IHqlExpression * expr);
  1384. void doBuildPureSubExpr(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1385. void doBuildTempExprConcat(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1386. void buildConcatFArgs(HqlExprArray & args, BuildCtx & ctx, const HqlExprArray & values, ITypeInfo * argType);
  1387. void doBuildVarLengthConcatF(BuildCtx & ctx, const CHqlBoundTarget & target, const HqlExprArray & values);
  1388. bool doBuildFixedLengthConcatF(BuildCtx & ctx, const CHqlBoundTarget & target, const HqlExprArray & values);
  1389. void doBuildCastViaTemp(BuildCtx & ctx, ITypeInfo * to, CHqlBoundExpr & pure, CHqlBoundExpr & tgt);
  1390. void doBuildCastViaString(BuildCtx & ctx, ITypeInfo * to, const CHqlBoundExpr & pure, CHqlBoundExpr & tgt);
  1391. void bindAndPush(BuildCtx & ctx, IHqlExpression * value);
  1392. IHqlExpression * createFormatCall(IIdAtom * func, IHqlExpression * expr);
  1393. void createOrderList(BuildCtx & ctx, IHqlExpression * expr, IHqlExpression * ascdesc, CHqlBoundExpr & tgt);
  1394. bool ensurePushed(BuildCtx & ctx, const CHqlBoundExpr & pure);
  1395. void ensureSimpleExpr(BuildCtx & ctx, CHqlBoundExpr & tgt);
  1396. IHqlExpression * ensureSimpleTranslatedExpr(BuildCtx & ctx, IHqlExpression * expr);
  1397. void ensureContextAvailable(BuildCtx & ctx);
  1398. IHqlExpression * getConstWuid(IHqlExpression * expr);
  1399. IHqlExpression * getFirstCharacter(IHqlExpression * source);
  1400. bool hasAddress(BuildCtx & ctx, IHqlExpression * expr);
  1401. void buildStartTimer(BuildCtx & ctx, CHqlBoundExpr & boundTimer, CHqlBoundExpr & boundStart, const char * name);
  1402. void buildStopTimer(BuildCtx & ctx, const CHqlBoundExpr & boundTimer, const CHqlBoundExpr & boundStart);
  1403. IHqlExpression * convertOrToAnd(IHqlExpression * expr);
  1404. bool childrenRequireTemp(BuildCtx & ctx, IHqlExpression * expr, bool includeChildren);
  1405. bool requiresTemp(BuildCtx & ctx, IHqlExpression * expr, bool includeChildren);
  1406. bool requiresTempAfterFirst(BuildCtx & ctx, IHqlExpression * expr);
  1407. void tidyupExpr(BuildCtx & ctx, CHqlBoundExpr & bound);
  1408. void doStringTranslation(BuildCtx & ctx, ICharsetInfo * tgtset, ICharsetInfo * srcset, unsigned tgtlen, IHqlExpression * srclen, IHqlExpression * target, IHqlExpression * src);
  1409. void cacheOptions();
  1410. void overrideOptionsForLibrary();
  1411. void overrideOptionsForQuery();
  1412. void doExpandAliases(BuildCtx & ctx, IHqlExpression * expr, AliasExpansionInfo & info);
  1413. void expandAliases(BuildCtx & ctx, IHqlExpression * expr, AliasExpansionInfo * parentInfo);
  1414. void expandAliasScope(BuildCtx & ctx, IHqlExpression * expr);
  1415. IHqlExpression * queryExpandAliasScope(BuildCtx & ctx, IHqlExpression * expr);
  1416. void addDependency(BuildCtx & ctx, ABoundActivity * element, ABoundActivity * dependent, IAtom * kind, const char * label=NULL);
  1417. void addDependency(BuildCtx & ctx, ABoundActivity * element, ActivityInstance * instance, IAtom * kind, const char * label=NULL);
  1418. void addDependency(BuildCtx & ctx, ABoundActivity * sourceActivity, IPropertyTree * sinkGraph, ABoundActivity * sinkActivity, IAtom * kind, const char * label, unsigned inputIndex, int whenId);
  1419. void addActionConnection(BuildCtx & ctx, ABoundActivity * element, ActivityInstance * instance, IAtom * kind, const char * label, unsigned inputIndex, int whenId);
  1420. void addFileDependency(IHqlExpression * name, ABoundActivity * whoAmI);
  1421. void doBuildClearAggregateRecord(BuildCtx & ctx, IHqlExpression * record, IHqlExpression * self, IHqlExpression * transform);
  1422. void doBuildAggregateClearFunc(BuildCtx & ctx, IHqlExpression * expr);
  1423. void doBuildAggregateFirstFunc(BuildCtx & ctx, IHqlExpression * expr);
  1424. void doBuildAggregateNextFunc(BuildCtx & ctx, IHqlExpression * expr);
  1425. void doBuildAggregateMergeFunc(BuildCtx & ctx, IHqlExpression * expr, bool & requiresOrderedMerge);
  1426. void doBuildAggregateProcessTransform(BuildCtx & ctx, BoundRow * selfRow, IHqlExpression * expr, IHqlExpression * alreadyDoneExpr);
  1427. void doBuildFuncIsSameGroup(BuildCtx & ctx, IHqlExpression * dataset, IHqlExpression * sortlist);
  1428. void processUserAggregateTransform(IHqlExpression * expr, IHqlExpression * transform, SharedHqlExpr & firstTransform, SharedHqlExpr & nextTransform);
  1429. void doBuildUserAggregateFuncs(BuildCtx & ctx, IHqlExpression * expr, bool & requiresOrderedMerge);
  1430. void doBuildUserAggregateProcessTransform(BuildCtx & ctx, BoundRow * selfRow, IHqlExpression * expr, IHqlExpression * transform, IHqlExpression * alreadyDoneExpr);
  1431. void doBuildUserMergeAggregateFunc(BuildCtx & ctx, IHqlExpression * expr, IHqlExpression * mergeTransform);
  1432. IHqlExpression * getUserAggregateMergeTransform(IHqlExpression * expr, bool & requiresOrderedMerge);
  1433. void doBuildDistributionClearFunc(BuildCtx & ctx, IHqlExpression * dataset, HqlExprArray & fields);
  1434. void doBuildDistributionNextFunc(BuildCtx & ctx, IHqlExpression * dataset, HqlExprArray & fields);
  1435. void doBuildDistributionFunc(BuildCtx & funcctx, unsigned numFields, const char * action);
  1436. void doBuildDistributionDestructFunc(BuildCtx & funcctx, unsigned numFields);
  1437. void doBuildDistributionSerializeFunc(BuildCtx & funcctx, unsigned numFields);
  1438. void doBuildDistributionMergeFunc(BuildCtx & funcctx, unsigned numFields);
  1439. void doBuildDistributionGatherFunc(BuildCtx & funcctx, unsigned numFields);
  1440. void doBuildParseTransform(BuildCtx & classctx, IHqlExpression * expr);
  1441. void doBuildParseValidators(BuildCtx & classctx, IHqlExpression * expr);
  1442. void doBuildMatched(BuildCtx & ctx, const CHqlBoundTarget * target, IHqlExpression * expr, CHqlBoundExpr * bound);
  1443. void doBuildMatchAttr(BuildCtx & ctx, const CHqlBoundTarget * target, IHqlExpression * expr, CHqlBoundExpr * bound);
  1444. void doBuildParseSearchText(BuildCtx & classctx, IHqlExpression * dataset, IHqlExpression * search, type_t searchType, ITypeInfo * transferType);
  1445. void doBuildParseSearchText(BuildCtx & classctx, IHqlExpression * expr);
  1446. void doBuildParseCompiled(BuildCtx & classctx, MemoryBuffer & buffer);
  1447. void doBuildParseExtra(BuildCtx & classctx, IHqlExpression * expr);
  1448. void compileParseSearchPattern(IHqlExpression * expr);
  1449. void gatherExplicitMatched(IHqlExpression * expr);
  1450. void doBuildNewRegexFindReplace(BuildCtx & ctx, const CHqlBoundTarget * target, IHqlExpression * expr, CHqlBoundExpr * bound);
  1451. IHqlExpression * doBuildRegexCompileInstance(BuildCtx & ctx, IHqlExpression * pattern, bool unicode, bool caseSensitive);
  1452. IHqlExpression * doBuildRegexFindInstance(BuildCtx & ctx, IHqlExpression * compiled, IHqlExpression * search, bool cloneSearch);
  1453. IHqlExpression * doCreateGraphLookup(BuildCtx & declarectx, BuildCtx & resolvectx, unique_id_t id, const char * activity, bool isChild);
  1454. IHqlExpression * buildGetLocalResult(BuildCtx & ctx, IHqlExpression * expr);
  1455. IHqlExpression * queryOptimizedExists(BuildCtx & ctx, IHqlExpression * expr, IHqlExpression * dataset);
  1456. void doBuildAssignAggregateLoop(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr, IHqlExpression * dataset, IHqlExpression * doneFirstVar, bool multiPath);
  1457. void validateExprScope(BuildCtx & ctx, IHqlExpression * dataset, IHqlExpression * expr, const char * opName, const char * argName);
  1458. void buildActivityFramework(ActivityInstance * instance);
  1459. void buildActivityFramework(ActivityInstance * instance, bool alwaysExecuted); // called for all actions
  1460. void buildCompareClass(BuildCtx & ctx, const char * name, IHqlExpression * sortList, const DatasetReference & dataset, StringBuffer & compareFuncName);
  1461. void buildCompareClass(BuildCtx & ctx, const char * name, IHqlExpression * orderExpr, IHqlExpression * datasetLeft, IHqlExpression * datasetRight, IHqlExpression * selSeq);
  1462. void buildCompareMemberLR(BuildCtx & ctx, const char * name, IHqlExpression * orderExpr, IHqlExpression * datasetLeft, IHqlExpression * datasetRight, IHqlExpression * selSeq);
  1463. void buildCompareMember(BuildCtx & ctx, const char * name, IHqlExpression * cond, const DatasetReference & dataset);
  1464. void buildOrderedCompare(BuildCtx & ctx, IHqlExpression * dataset, IHqlExpression * sorts, CHqlBoundExpr & bound, IHqlExpression * leftDataset, IHqlExpression * rightDataset);
  1465. void buildCompareEqClass(BuildCtx & ctx, const char * name, IHqlExpression * sortList, const DatasetReference & dataset);
  1466. void buildCompareEqClass(BuildCtx & ctx, const char * name, IHqlExpression * orderExpr, IHqlExpression * datasetLeft, IHqlExpression * datasetRight, IHqlExpression * selSeq);
  1467. void buildCompareEqMemberLR(BuildCtx & ctx, const char * name, IHqlExpression * orderExpr, IHqlExpression * datasetLeft, IHqlExpression * datasetRight, IHqlExpression * selSeq);
  1468. void buildCompareEqMember(BuildCtx & ctx, const char * name, IHqlExpression * cond, const DatasetReference & dataset);
  1469. void buildNaryCompareClass(BuildCtx & ctx, const char * name, IHqlExpression * expr, IHqlExpression * datasetLeft, IHqlExpression * selSeq, IHqlExpression * rowsid);
  1470. void buildNaryCompareMember(BuildCtx & ctx, const char * name, IHqlExpression * expr, IHqlExpression * datasetLeft, IHqlExpression * selSeq, IHqlExpression * rowsid);
  1471. void buildConnectInputOutput(BuildCtx & ctx, ActivityInstance * instance, ABoundActivity * table, unsigned outputIndex, unsigned inputIndex, const char * label = NULL, bool nWay = false);
  1472. void buildConnectOrders(BuildCtx & ctx, ABoundActivity * slaveActivity, ABoundActivity * masterActivity);
  1473. void buildDedupFilterFunction(BuildCtx & ctx, HqlExprArray & equalities, HqlExprArray & conds, IHqlExpression * dataset, IHqlExpression * selSeq);
  1474. void buildDedupSerializeFunction(BuildCtx & ctx, const char * funcName, IHqlExpression * srcDataset, IHqlExpression * tgtDataset, HqlExprArray & srcValues, HqlExprArray & tgtValues, IHqlExpression * selSeq);
  1475. void buildDictionaryHashClass(IHqlExpression *record, StringBuffer &lookupHelperName);
  1476. void buildDictionaryHashMember(BuildCtx & ctx, IHqlExpression *dictionary, const char * memberName);
  1477. void buildHashClass(BuildCtx & ctx, const char * name, IHqlExpression * orderExpr, const DatasetReference & dataset);
  1478. void buildHashOfExprsClass(BuildCtx & ctx, const char * name, IHqlExpression * cond, const DatasetReference & dataset, bool compareToSelf);
  1479. void buildInstancePrefix(ActivityInstance * instance);
  1480. void buildInstanceSuffix(ActivityInstance * instance);
  1481. void buildIterateTransformFunction(BuildCtx & ctx, IHqlExpression * boundDataset, IHqlExpression * transform, IHqlExpression * counter, IHqlExpression * selSeq);
  1482. void buildProcessTransformFunction(BuildCtx & ctx, IHqlExpression * expr);
  1483. void buildRollupTransformFunction(BuildCtx & ctx, IHqlExpression * dataset, IHqlExpression * transform, IHqlExpression * selSeq );
  1484. void buildClearRecord(BuildCtx & ctx, IHqlExpression * dataset, IHqlExpression * record, int direction);
  1485. void buildClearRecordMember(BuildCtx & ctx, const char * name, IHqlExpression * dataset);
  1486. IHqlExpression * getSerializedLayoutFunction(IHqlExpression * record, unsigned numKeyedFields);
  1487. void buildSerializedLayoutMember(BuildCtx & ctx, IHqlExpression * record, const char * name, unsigned numKeyedFields);
  1488. IHqlExpression * getClearRecordFunction(IHqlExpression * record, int direction=0);
  1489. void doBuildSequenceFunc(BuildCtx & ctx, IHqlExpression * expr, bool ignoreInternal);
  1490. void buildSetResultInfo(BuildCtx & ctx, IHqlExpression * originalExpr, IHqlExpression * value, ITypeInfo * type, bool isPersist, bool associateResult);
  1491. void buildTransformXml(BuildCtx & ctx, IHqlExpression * expr, HqlExprArray & assigns, IHqlExpression * parentSelector);
  1492. void buildHTTPtoXml(BuildCtx & ctx);
  1493. void buildSOAPtoXml(BuildCtx & ctx, IHqlExpression * dataset, IHqlExpression * transform, IHqlExpression * selSeq);
  1494. void buildRecordEcl(BuildCtx & subctx, IHqlExpression * dataset, const char * methodName);
  1495. void doTransform(BuildCtx & ctx, IHqlExpression * transform, BoundRow * self);
  1496. void doUpdateTransform(BuildCtx & ctx, IHqlExpression * transform, BoundRow * self, BoundRow * previous, bool alwaysNextRow);
  1497. void doInlineTransform(BuildCtx & ctx, IHqlExpression * transform, BoundRow * targetRow);
  1498. void doUserTransform(BuildCtx & ctx, IHqlExpression * transform, BoundRow * self);
  1499. IHqlExpression * createOrderFromSortList(const DatasetReference & dataset, IHqlExpression * sortList, IHqlExpression * leftSelect, IHqlExpression * rightSelect);
  1500. void buildSkewThresholdMembers(BuildCtx & ctx, IHqlExpression * expr);
  1501. void doCompareLeftRight(BuildCtx & ctx, const char * funcname, const DatasetReference & datasetLeft, const DatasetReference & datasetRight, const HqlExprArray & left, const HqlExprArray & right);
  1502. void buildSlidingMatchFunction(BuildCtx & ctx, const HqlExprArray & leftEq, const HqlExprArray & rightEq, const HqlExprArray & slidingMatches, const char * funcname, unsigned childIndex, const DatasetReference & datasetL, const DatasetReference & datasetR);
  1503. void doBuildIndexOutputTransform(BuildCtx & ctx, IHqlExpression * record, SharedHqlExpr & rawRecord, bool hasFileposition, IHqlExpression * maxlength);
  1504. void associateLocalJoinTransformFlags(BuildCtx & ctx, const char * name, IHqlExpression *ds, node_operator side, IHqlExpression *selSeq);
  1505. void buildKeyedJoinExtra(ActivityInstance & instance, IHqlExpression * expr, KeyedJoinInfo * joinKey);
  1506. void buildKeyJoinIndexReadHelper(ActivityInstance & instance, IHqlExpression * expr, KeyedJoinInfo * joinKey);
  1507. void buildKeyJoinFetchHelper(ActivityInstance & instance, IHqlExpression * expr, KeyedJoinInfo * joinKey);
  1508. void doBuildJoinRowLimitHelper(ActivityInstance & instance, IHqlExpression * rowlimit, IHqlExpression * filename, bool generateImplicitLimit);
  1509. IHqlExpression * createFailMessage(const char * prefix, IHqlExpression * limit, IHqlExpression * filename, unique_id_t id);
  1510. IHqlExpression * createFailAction(const char * prefix, IHqlExpression * limit, IHqlExpression * filename, unique_id_t id);
  1511. void buildJoinMatchFunction(BuildCtx & ctx, const char * name, IHqlExpression * left, IHqlExpression * right, IHqlExpression * match, IHqlExpression * selSeq);
  1512. void associateBlobHelper(BuildCtx & ctx, IHqlExpression * ds, const char * name);
  1513. IHqlExpression * getBlobRowSelector(BuildCtx & ctx, IHqlExpression * expr);
  1514. void buildXmlSerialize(BuildCtx & subctx, IHqlExpression * expr, IHqlExpression * selector, HqlExprArray * assigns, unsigned pass, unsigned & expectedIndex);
  1515. void buildXmlSerialize(BuildCtx & subctx, IHqlExpression * expr, IHqlExpression * selector, HqlExprArray * assigns);
  1516. void buildXmlSerialize(BuildCtx & ctx, IHqlExpression * dataset, const char * funcname, bool isMeta);
  1517. void buildXmlSerializeScalar(BuildCtx & ctx, IHqlExpression * selected, IHqlExpression * name);
  1518. void buildXmlSerializeSet(BuildCtx & ctx, IHqlExpression * field, IHqlExpression * value);
  1519. void buildXmlSerializeSetValues(BuildCtx & ctx, IHqlExpression * value, IHqlExpression * itemName, bool includeAll);
  1520. void buildXmlSerializeDataset(BuildCtx & ctx, IHqlExpression * field, IHqlExpression * value, HqlExprArray * assigns);
  1521. void buildXmlSerializeBeginArray(BuildCtx & ctx, IHqlExpression * name);
  1522. void buildXmlSerializeEndArray(BuildCtx & ctx, IHqlExpression * name);
  1523. void buildXmlSerializeBeginNested(BuildCtx & ctx, IHqlExpression * name, bool doIndent);
  1524. void buildXmlSerializeEndNested(BuildCtx & ctx, IHqlExpression * name);
  1525. void buildXmlSerializeUsingMeta(BuildCtx & ctx, IHqlExpression * dataset, const char * self);
  1526. void buildSetXmlSerializer(StringBuffer & helper, ITypeInfo * valueType);
  1527. void buildMetaMember(BuildCtx & ctx, IHqlExpression * datasetOrRecord, bool isGrouped, const char * name);
  1528. void buildMetaSerializerClass(BuildCtx & ctx, IHqlExpression * record, const char * serializerName, IAtom * serializeForm);
  1529. void buildMetaDeserializerClass(BuildCtx & ctx, IHqlExpression * record, const char * deserializerName, IAtom * serializeForm);
  1530. bool buildMetaPrefetcherClass(BuildCtx & ctx, IHqlExpression * record, const char * prefetcherName);
  1531. void buildLibraryInstanceExtract(BuildCtx & ctx, HqlCppLibraryInstance * libraryInstance);
  1532. void buildLibraryGraph(BuildCtx & graphctx, IHqlExpression * expr, const char * graphName);
  1533. ActivityInstance * queryCurrentActivity(BuildCtx & ctx);
  1534. unique_id_t queryCurrentActivityId(BuildCtx & ctx);
  1535. IHqlExpression * getCurrentActivityId(BuildCtx & ctx); // can be variable
  1536. void associateSkipReturnMarker(BuildCtx & ctx, IHqlExpression * value, BoundRow * self);
  1537. IHqlExpression * createClearRowCall(BuildCtx & ctx, BoundRow * self);
  1538. bool insideActivityRemoteSerialize(BuildCtx & ctx);
  1539. EvalContext * queryEvalContext(BuildCtx & ctx) { return (EvalContext *)ctx.queryFirstAssociation(AssocExtractContext); }
  1540. inline unsigned nextActivityId() { return ++curActivityId; }
  1541. bool insideChildOrLoopGraph(BuildCtx & ctx);
  1542. bool insideChildQuery(BuildCtx & ctx);
  1543. bool insideRemoteGraph(BuildCtx & ctx);
  1544. bool isCurrentActiveGraph(BuildCtx & ctx, IHqlExpression * graphTag);
  1545. void buildChildGraph(BuildCtx & ctx, IHqlExpression * expr);
  1546. void buildXmlReadChildrenIterator(BuildCtx & subctx, const char * iterTag, IHqlExpression * rowName, SharedHqlExpr & subRowExpr);
  1547. void buildXmlReadTransform(IHqlExpression * dataset, StringBuffer & className, bool & usesContents);
  1548. void doBuildXmlReadMember(ActivityInstance & instance, IHqlExpression * expr, const char * functionName, bool & usesContents);
  1549. void ensureSerialized(const CHqlBoundTarget & variable, BuildCtx & serializectx, BuildCtx & deserializectx, const char * inBufferName, const char * outBufferName, IAtom * serializeForm);
  1550. void ensureRowAllocator(StringBuffer & allocatorName, BuildCtx & ctx, IHqlExpression * record, IHqlExpression * activityId);
  1551. IHqlExpression * createRowAllocator(BuildCtx & ctx, IHqlExpression * record);
  1552. void beginExtract(BuildCtx & ctx, ParentExtract * extractBuilder);
  1553. void endExtract(BuildCtx & ctx, ParentExtract * extractBuilder);
  1554. IDefRecordElement * createMetaRecord(IHqlExpression * record);
  1555. public:
  1556. void doBuildBoolFunction(BuildCtx & ctx, const char * name, bool value);
  1557. void doBuildBoolFunction(BuildCtx & ctx, const char * name, IHqlExpression * value);
  1558. void doBuildSignedFunction(BuildCtx & ctx, const char * name, IHqlExpression * value);
  1559. void doBuildSizetFunction(BuildCtx & ctx, const char * name, size32_t value);
  1560. void doBuildUnsignedFunction(BuildCtx & ctx, const char * name, unsigned value);
  1561. void doBuildUnsignedFunction(BuildCtx & ctx, const char * name, IHqlExpression * value);
  1562. void doBuildUnsignedFunction(BuildCtx & ctx, const char * name, const char * value);
  1563. void doBuildUnsigned64Function(BuildCtx & ctx, const char * name, IHqlExpression * value);
  1564. void doBuildVarStringFunction(BuildCtx & ctx, const char * name, IHqlExpression * value);
  1565. void doBuildDataFunction(BuildCtx & ctx, const char * name, IHqlExpression * value);
  1566. void doBuildStringFunction(BuildCtx & ctx, const char * name, IHqlExpression * value);
  1567. void doBuildDoubleFunction(BuildCtx & ctx, const char * name, IHqlExpression * value);
  1568. void doBuildFunction(BuildCtx & ctx, ITypeInfo * type, const char * name, IHqlExpression * value);
  1569. void doBuildFunctionReturn(BuildCtx & ctx, ITypeInfo * type, IHqlExpression * value);
  1570. void doBuildUserFunctionReturn(BuildCtx & ctx, ITypeInfo * type, IHqlExpression * value);
  1571. void addFilenameConstructorParameter(ActivityInstance & instance, const char * name, IHqlExpression * expr);
  1572. void buildFilenameFunction(ActivityInstance & instance, BuildCtx & classctx, const char * name, IHqlExpression * expr, bool isDynamic);
  1573. void buildRefFilenameFunction(ActivityInstance & instance, BuildCtx & classctx, const char * name, IHqlExpression * dataset);
  1574. void createAccessFunctions(StringBuffer & helperFunc, BuildCtx & declarectx, unsigned prio, const char * interfaceName, const char * object);
  1575. IHqlStmt * beginNestedClass(BuildCtx & classctx, const char * member, const char * bases, const char * memberExtra = NULL, ParentExtract * extract = NULL);
  1576. void endNestedClass(IHqlStmt * stmt);
  1577. void buildEncryptHelper(BuildCtx & ctx, IHqlExpression * encryptAttr, const char * funcname = NULL);
  1578. void buildFormatCrcFunction(BuildCtx & ctx, const char * name, bool removeFilepos, IHqlExpression * dataset, IHqlExpression * expr, unsigned payloadDelta);
  1579. void buildLimitHelpers(BuildCtx & ctx, IHqlExpression * expr, IHqlExpression * filename, unique_id_t id);
  1580. void buildLimitHelpers(BuildCtx & ctx, IHqlExpression * rowLimit, IHqlExpression * failAction, bool isSkip, IHqlExpression * filename, unique_id_t id);
  1581. void doGenerateMetaDestruct(BuildCtx & ctx, IHqlExpression * selector, IHqlExpression * record);
  1582. void generateMetaRecordSerialize(BuildCtx & ctx, IHqlExpression * record, const char * diskSerializerName, const char * diskDeserializerName, const char * internalSerializerName, const char * internalDeserializerName, const char * prefetcherName);
  1583. void filterExpandAssignments(BuildCtx & ctx, TransformBuilder * builder, HqlExprArray & assigns, IHqlExpression * expr);
  1584. protected:
  1585. void buildIteratorFirst(BuildCtx & ctx, IHqlExpression * iter, IHqlExpression * row);
  1586. void buildIteratorNext(BuildCtx & ctx, IHqlExpression * iter, IHqlExpression * row);
  1587. bool shouldEvaluateSelectAsAlias(BuildCtx & ctx, IHqlExpression * expr);
  1588. IWUResult * createWorkunitResult(int sequence, IHqlExpression * nameExpr);
  1589. void noteFilename(ActivityInstance & instance, const char * name, IHqlExpression * expr, bool isDynamic);
  1590. bool checkGetResultContext(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1591. void buildGetResultInfo(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr * boundTarget, const CHqlBoundTarget * targetAssign);
  1592. void buildGetResultSetInfo(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr * boundTarget, const CHqlBoundTarget * targetAssign);
  1593. void buildExpiryHelper(BuildCtx & ctx, IHqlExpression * expireAttr);
  1594. void buildUpdateHelper(BuildCtx & ctx, ActivityInstance & instance, IHqlExpression * input, IHqlExpression * updateAttr);
  1595. void buildClusterHelper(BuildCtx & ctx, IHqlExpression * expr);
  1596. void precalculateFieldOffsets(BuildCtx & ctx, IHqlExpression * expr, BoundRow * cursor);
  1597. IHqlExpression * optimizeIncrementAssign(BuildCtx & ctx, IHqlExpression * value);
  1598. void doBuildEvalOnce(BuildCtx & ctx, const CHqlBoundTarget * target, IHqlExpression * expr, CHqlBoundExpr * bound);
  1599. void doBuildAssignCompareRow(BuildCtx & ctx, EvaluateCompareInfo & info, IHqlExpression * left, IHqlExpression * right);
  1600. void doBuildAssignCompareTable(BuildCtx & ctx, EvaluateCompareInfo & info, IHqlExpression * left, IHqlExpression * right);
  1601. void doBuildAssignCompareElement(BuildCtx & ctx, EvaluateCompareInfo & info, IHqlExpression * left, IHqlExpression * right, bool isFirst, bool isLast);
  1602. void doBuildAssignCompare(BuildCtx & ctx, EvaluateCompareInfo & target, HqlExprArray & leftValues, HqlExprArray & rightValues, bool isFirst, bool isOuter);
  1603. void expandRowOrder(IHqlExpression * selector, IHqlExpression * record, HqlExprArray & values, bool isRow);
  1604. void expandSimpleOrder(IHqlExpression * left, IHqlExpression * right, HqlExprArray & leftValues, HqlExprArray & rightValues);
  1605. void expandOrder(IHqlExpression * expr, HqlExprArray & leftValues, HqlExprArray & rightValues, SharedHqlExpr & defaultValue);
  1606. void optimizeOrderValues(HqlExprArray & leftValues, HqlExprArray & rightValues, bool isEqualityCompare);
  1607. IHqlExpression * querySimpleOrderSelector(IHqlExpression * expr);
  1608. unsigned doBuildThorChildSubGraph(BuildCtx & ctx, IHqlExpression * expr, SubGraphType kind, unsigned thisId=0, IHqlExpression * represents=NULL);
  1609. unsigned doBuildThorSubGraph(BuildCtx & ctx, IHqlExpression * expr, SubGraphType kind, unsigned thisId=0, IHqlExpression * represents=NULL);
  1610. void doBuildThorGraph(BuildCtx & ctx, IHqlExpression * expr);
  1611. IHqlExpression * createResultName(IHqlExpression * name, bool isPersist);
  1612. bool isFixedWidthDataset(IHqlExpression * dataset);
  1613. IHqlExpression * normalizeGlobalIfCondition(BuildCtx & ctx, IHqlExpression * expr);
  1614. void substituteClusterSize(HqlExprArray & exprs);
  1615. void throwCannotCast(ITypeInfo * from, ITypeInfo * to);
  1616. bool useRowAccessorClass(IHqlExpression * record, bool isTargetRow);
  1617. void ensureSerialized(BuildCtx & ctx, const CHqlBoundTarget & variable);
  1618. void doBuildExprRowDiff(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr, IHqlExpression * leftSelector, IHqlExpression * rightRecord, IHqlExpression * rightSelector, StringBuffer & selectorText, bool isCount);
  1619. void doBuildExprRowDiff(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
  1620. void doFilterAssignment(BuildCtx & ctx, TransformBuilder * builder, HqlExprArray & assigns, IHqlExpression * expr);
  1621. void doFilterAssignments(BuildCtx & ctx, TransformBuilder * builder, HqlExprArray & assigns, IHqlExpression * expr);
  1622. bool extractSerializeKey(SerializeKeyInfo & info, const DatasetReference & dataset, const HqlExprArray & sorts, bool isGlobal);
  1623. void generateSerializeAssigns(BuildCtx & ctx, IHqlExpression * record, IHqlExpression * selector, IHqlExpression * selfSelect, IHqlExpression * leftSelect, const DatasetReference & srcDataset, const DatasetReference & tgtDataset, HqlExprArray & srcSelects, HqlExprArray & tgtSelects, bool needToClear, node_operator serializeOp, IAtom * serialForm);
  1624. void generateSerializeFunction(BuildCtx & ctx, const char * funcName, const DatasetReference & srcDataset, const DatasetReference & tgtDataset, HqlExprArray & srcSelects, HqlExprArray & tgtSelects, node_operator serializeOp, IAtom * serialForm);
  1625. void generateSerializeKey(BuildCtx & nestedctx, node_operator side, SerializeKeyInfo & keyInfo, const DatasetReference & dataset, bool generateCompares);
  1626. void generateSerializeKey(BuildCtx & ctx, node_operator side, const DatasetReference & dataset, const HqlExprArray & sorts, bool isGlobal, bool generateCompares); //NB: sorts are ats.xyz
  1627. void generateSortCompare(BuildCtx & nestedctx, BuildCtx & ctx, node_operator index, const DatasetReference & dataset, const HqlExprArray & sorts, IHqlExpression * noSortAttr, bool canReuseLeft, bool isLightweight, bool isLocal);
  1628. void addSchemaField(IHqlExpression *field, MemoryBuffer &schema, IHqlExpression *selector);
  1629. void addSchemaFields(IHqlExpression * record, MemoryBuffer &schema, IHqlExpression *selector);
  1630. void addSchemaResource(int seq, const char * name, IHqlExpression * record, unsigned keyedCount);
  1631. void addSchemaResource(int seq, const char * name, unsigned len, const char * schemaXml);
  1632. void doAddSchemaFields(IHqlExpression * record, MemoryBuffer &schema, IHqlExpression *selector);
  1633. IWUResult * createDatasetResultSchema(IHqlExpression * sequenceExpr, IHqlExpression * name, IHqlExpression * record, HqlExprArray &xmlnsAttrs, bool createTransformer, bool isFile, unsigned keyedCount);
  1634. void buildReturnCsvValue(BuildCtx & ctx, IHqlExpression * _expr);
  1635. void buildCsvListFunc(BuildCtx & classctx, const char * func, IHqlExpression * value, const char * defaultValue);
  1636. void buildCsvParameters(BuildCtx & subctx, IHqlExpression * csvAttr, IHqlExpression * record, bool isReading);
  1637. unsigned buildCsvReadTransform(BuildCtx & subctx, IHqlExpression * dataset, bool newInterface, IHqlExpression * csvAttr);
  1638. void buildCsvReadTransform(BuildCtx & subctx, IHqlExpression * expr, IHqlExpression * selector, unsigned & numFields);
  1639. void buildCsvReadTransformer(IHqlExpression * dataset, StringBuffer & instanceName, IHqlExpression * optCsvAttr);
  1640. void buildCsvWriteScalar(BuildCtx & ctx, IHqlExpression * expr, IAtom * encoding);
  1641. void buildCsvWriteTransform(BuildCtx & subctx, IHqlExpression * dataset, IAtom * encoding);
  1642. void buildCsvWriteTransform(BuildCtx & subctx, IHqlExpression * expr, IHqlExpression * selector, IAtom * encoding);
  1643. void buildCsvWriteMembers(ActivityInstance * instance, IHqlExpression * dataset, IHqlExpression * csvAttr);
  1644. void buildXmlWriteMembers(ActivityInstance * instance, IHqlExpression * dataset, IHqlExpression * xmlAttr);
  1645. //ThorHole helper functions...
  1646. IHqlExpression * doBuildDatabaseLoader(BuildCtx & ctx, IHqlExpression * expr);
  1647. void doReportWarning(WarnErrorCategory category, ErrorSeverity explicitSeverity, IHqlExpression * location, unsigned id, const char * msg);
  1648. void optimizePersists(HqlExprArray & exprs);
  1649. IHqlExpression * convertSetResultToExtract(IHqlExpression * expr);
  1650. void allocateSequenceNumbers(HqlExprArray & exprs);
  1651. void convertLogicalToActivities(WorkflowItem & curWorkflow);
  1652. void flattenDatasets(WorkflowArray & array);
  1653. void spotGlobalCSE(WorkflowItem & curWorkflow);
  1654. IHqlExpression * spotGlobalCSE(IHqlExpression * _expr);
  1655. void spotGlobalCSE(HqlExprArray & exprs);
  1656. IHqlExpression * extractGlobalCSE(IHqlExpression * expr);
  1657. void processCppBodyDirectives(IHqlExpression * expr);
  1658. void markThorBoundaries(WorkflowItem & curWorkflow);
  1659. void normalizeGraphForGeneration(HqlExprArray & exprs, HqlQueryContext & query);
  1660. void applyGlobalOptimizations(HqlExprArray & exprs);
  1661. void transformWorkflowItem(WorkflowItem & curWorkflow);
  1662. bool transformGraphForGeneration(HqlQueryContext & query, WorkflowArray & exprs);
  1663. void processEmbeddedLibraries(HqlExprArray & exprs, HqlExprArray & internalLibraries, bool isLibrary);
  1664. void pickBestEngine(WorkflowArray & array);
  1665. void pickBestEngine(HqlExprArray & exprs);
  1666. IHqlExpression * separateLibraries(IHqlExpression * query, HqlExprArray & internalLibraries);
  1667. void doBuildSerialize(BuildCtx & ctx, IIdAtom * name, IHqlExpression * length, CHqlBoundExpr & bound, const char * bufferName);
  1668. void modifyOutputLocations(HqlExprArray & exprs);
  1669. IHqlExpression * getDefaultOutputAttr(IHqlExpression * expr);
  1670. IHqlExpression * calculatePersistInputCrc(BuildCtx & ctx, IHqlExpression * expr);
  1671. IHqlExpression * calculatePersistInputCrc(BuildCtx & ctx, DependenciesUsed & dependencies);
  1672. bool ifRequiresAssignment(BuildCtx & ctx, IHqlExpression * expr);
  1673. void logGraphEdge(IPropertyTree * subGraph, unsigned __int64 source, unsigned __int64 target, unsigned sourceIndex, unsigned targetIndex, const char * label, bool nWay);
  1674. void beginGraph(const char * graphName = NULL);
  1675. void clearGraph();
  1676. void endGraph();
  1677. double getComplexity(WorkflowArray & exprs);
  1678. double getComplexity(HqlExprArray & exprs);
  1679. double getComplexity(IHqlExpression * expr, ClusterType cluster);
  1680. bool prepareToGenerate(HqlQueryContext & query, WorkflowArray & exprs, bool isEmbeddedLibrary);
  1681. IHqlExpression * getResourcedGraph(IHqlExpression * expr, IHqlExpression * graphIdExpr);
  1682. IHqlExpression * getResourcedChildGraph(BuildCtx & ctx, IHqlExpression * childQuery, unsigned numResults, node_operator graphKind, bool unlimitedResources);
  1683. IHqlExpression * optimizeCompoundSource(IHqlExpression * expr, unsigned flags);
  1684. IHqlExpression * optimizeGraphPostResource(IHqlExpression * expr, unsigned csfFlags, bool projectBeforeSpill, bool insideChildQuery);
  1685. bool isInlineOk();
  1686. GraphLocalisation getGraphLocalisation(IHqlExpression * expr, bool isInsideChildQuery);
  1687. bool isAlwaysCoLocal();
  1688. bool isNeverDistributed(IHqlExpression * expr);
  1689. void ensureWorkUnitUpdated();
  1690. bool getDebugFlag(const char * name, bool defValue);
  1691. void initOptions();
  1692. void postProcessOptions();
  1693. SourceFieldUsage * querySourceFieldUsage(IHqlExpression * expr);
  1694. void noteAllFieldsUsed(IHqlExpression * expr);
  1695. IHqlExpression * translateGetGraphResult(BuildCtx & ctx, IHqlExpression * expr);
  1696. public:
  1697. IHqlExpression * convertToPhysicalIndex(IHqlExpression * tableExpr);
  1698. IHqlExpression * buildIndexFromPhysical(IHqlExpression * expr);
  1699. //MORE: At some point the global getUniqueId() should be killed so there are only local references.
  1700. inline unsigned __int64 getUniqueId() { return ::getUniqueId(); } //{ return ++nextUid; }
  1701. inline StringBuffer & getUniqueId(StringBuffer & target) { return appendUniqueId(target, getUniqueId()); }
  1702. inline unsigned curGraphSequence() const { return activeGraph ? graphSeqNumber : 0; }
  1703. UniqueSequenceCounter & querySpillSequence() { return spillSequence; }
  1704. public:
  1705. void traceExpression(const char * title, IHqlExpression * expr, unsigned level=500);
  1706. void traceExpressions(const char * title, HqlExprArray & exprs, unsigned level=500);
  1707. void traceExpressions(const char * title, WorkflowItem & workflow, unsigned level=500) { traceExpressions(title, workflow.queryExprs(), level); };
  1708. void traceExpressions(const char * title, WorkflowArray & exprs);
  1709. void checkNormalized(IHqlExpression * expr);
  1710. void checkNormalized(WorkflowArray & array);
  1711. void checkNormalized(WorkflowItem & workflow) { checkNormalized(workflow.queryExprs()); }
  1712. void checkNormalized(HqlExprArray & exprs);
  1713. void checkNormalized(BuildCtx & ctx, IHqlExpression * expr);
  1714. void checkAmbiguousRollupCondition(IHqlExpression * expr);
  1715. void exportWarningMappings();
  1716. protected:
  1717. HqlCppInstance * code;
  1718. IHqlScope * internalScope;
  1719. RecordOffsetMap recordMap; // no_record -> offset information
  1720. ExprExprMap physicalIndexCache;
  1721. unsigned litno;
  1722. StringAttr soName;
  1723. Owned<ErrorSeverityMapper> globalOnWarnings;
  1724. Owned<ErrorSeverityMapper> localOnWarnings;
  1725. Linked<IErrorReceiver> errorProcessor;
  1726. HqlCppOptions options;
  1727. HqlCppDerived derived;
  1728. unsigned activitiesThisCpp;
  1729. unsigned curCppFile;
  1730. Linked<ICodegenContextCallback> ctxCallback;
  1731. ClusterType targetClusterType;
  1732. bool contextAvailable;
  1733. unsigned maxSequence;
  1734. unsigned startCursorSet;
  1735. bool requireTable;
  1736. BuildCtx * activeGraphCtx;
  1737. HqlExprArray metas;
  1738. Owned<GeneratedGraphInfo> activeGraph;
  1739. unsigned graphSeqNumber;
  1740. StringAttr graphLabel;
  1741. NlpParseContext * nlpParse; // Not linked so it can try and stay opaque.
  1742. bool xmlUsesContents;
  1743. CIArrayOf<GlobalFileTracker> globalFiles;
  1744. CIArrayOf<InternalResultTracker> internalResults;
  1745. HqlCppLibraryImplementation * outputLibrary; // not linked to opaque
  1746. OwnedHqlExpr outputLibraryId;
  1747. unsigned curActivityId;
  1748. unsigned holeUniqueSequence;
  1749. unsigned nextUid;
  1750. unsigned nextTypeId;
  1751. unsigned nextFieldId;
  1752. unsigned curWfid;
  1753. unsigned implicitFunctionId = 0;
  1754. unsigned nextGlobalCompareId = 1;
  1755. HqlExprArray internalFunctions;
  1756. HqlExprArray internalFunctionExternals;
  1757. UniqueSequenceCounter spillSequence;
  1758. #ifdef SPOT_POTENTIAL_COMMON_ACTIVITIES
  1759. LocationArray savedActivityLocations;
  1760. HqlExprArray savedActivities;
  1761. #endif
  1762. struct
  1763. {
  1764. HqlExprArray activityExprs;
  1765. HqlExprArray activityNorms;
  1766. UnsignedArray activityIds;
  1767. UnsignedArray activityCrcs;
  1768. } tracking;
  1769. //The following are only ok to access the top value - but not to build a parent tree.
  1770. //the activities cannot be assumed to be generated in a stackwise manner.
  1771. //e.g, could generate a a.b a.c (while a.b is still active) (because of strength reduction).
  1772. CIArrayOf<ABoundActivity> activeActivities;
  1773. CIArrayOf<GeneratedGraphInfo> graphs;
  1774. HqlExprArray activityExprStack; //only used for improving the error reporting
  1775. PointerArray recordIndexCache;
  1776. Owned<ITimeReporter> timeReporter;
  1777. CIArrayOf<SourceFieldUsage> trackedSources;
  1778. };
  1779. //===========================================================================
  1780. class HQLCPP_API HqlQueryInstance : implements IHqlQueryInstance, public CInterface
  1781. {
  1782. public:
  1783. HqlQueryInstance();
  1784. IMPLEMENT_IINTERFACE
  1785. StringBuffer & queryDllName(StringBuffer & out);
  1786. protected:
  1787. unique_id_t instance;
  1788. };
  1789. //---------------------------------------------------------------------------------------------------------------------
  1790. class CompoundBuilder
  1791. {
  1792. public:
  1793. CompoundBuilder(node_operator _op);
  1794. void addOperand(IHqlExpression * arg);
  1795. IHqlExpression * getCompound();
  1796. protected:
  1797. node_operator op;
  1798. HqlExprAttr compound;
  1799. HqlExprAttr first;
  1800. };
  1801. class LoopInvariantHelper
  1802. {
  1803. public:
  1804. LoopInvariantHelper() { active = NULL; }
  1805. ~LoopInvariantHelper() { finished(); }
  1806. bool getBestContext(BuildCtx & ctx, IHqlExpression * expr);
  1807. protected:
  1808. void finished();
  1809. protected:
  1810. IHqlStmt * active;
  1811. };
  1812. //===========================================================================
  1813. void cvtChooseListToPairs(HqlExprArray & target, IHqlExpression * from, unsigned base);
  1814. void cvtIndexListToPairs(HqlExprArray & target, IHqlExpression * from);
  1815. void cvtInListToPairs(HqlExprArray & target, IHqlExpression * from, bool valueIfMatch);
  1816. HQLCPP_API IHqlExpression * splitLongString(IHqlExpression * expr);
  1817. void createTempFor(ITypeInfo * exprType, CHqlBoundTarget & target, const char * prefix);
  1818. void checkSelectFlags(IHqlExpression * expr);
  1819. extern HQLCPP_API IHqlExpression * getPointer(IHqlExpression * source);
  1820. extern IHqlExpression * adjustIndexBaseToZero(IHqlExpression * index);
  1821. extern IHqlExpression * adjustIndexBaseToOne(IHqlExpression * index);
  1822. extern IHqlExpression * multiplyValue(IHqlExpression * expr, unsigned __int64 value);
  1823. extern bool isComplexSet(ITypeInfo * type, bool isConstant);
  1824. extern bool isComplexSet(IHqlExpression * expr);
  1825. extern bool isConstantSet(IHqlExpression * expr);
  1826. extern bool canProcessInline(BuildCtx * ctx, IHqlExpression * expr);
  1827. extern bool canIterateInline(BuildCtx * ctx, IHqlExpression * expr);
  1828. extern bool canAssignInline(BuildCtx * ctx, IHqlExpression * expr);
  1829. extern bool canEvaluateInline(BuildCtx * ctx, IHqlExpression * expr);
  1830. extern bool canAssignNotEvaluateInline(BuildCtx * ctx, IHqlExpression * expr);
  1831. extern bool isNonLocal(IHqlExpression * expr, bool optimizeParentAccess);
  1832. extern bool alwaysEvaluatesToBound(IHqlExpression * expr);
  1833. extern void buildClearPointer(BuildCtx & ctx, IHqlExpression * expr);
  1834. extern IHqlExpression * getVirtualReplacement(IHqlExpression * expr, IHqlExpression * virtualDef, IHqlExpression * dataset);
  1835. extern IHqlExpression * convertWrapperToPointer(IHqlExpression * expr);
  1836. extern IHqlExpression * createVariable(ITypeInfo * type);
  1837. extern void getMappedFields(HqlExprArray & aggregateFields, IHqlExpression * transform, HqlExprArray & recordFields, IHqlExpression * newSelector);
  1838. extern IHqlExpression * queryBlobHelper(BuildCtx & ctx, IHqlExpression * select);
  1839. inline bool isInPayload() { return true; } // placeholder - otherwise records in non payload can't be keyed sometimes.
  1840. extern bool filterIsTableInvariant(IHqlExpression * expr);
  1841. //NB: Watch out about calling this - if expression can be evaluated in a context; may not mean it is the correct context to evaluate it in
  1842. // e.g., if same LEFT selector is in current context and parent.
  1843. extern bool mustEvaluateInContext(BuildCtx & ctx, IHqlExpression * expr);
  1844. extern const char * boolToText(bool value);
  1845. extern bool activityNeedsParent(IHqlExpression * expr);
  1846. extern GraphLocalisation queryActivityLocalisation(IHqlExpression * expr, bool optimizeParentAccess);
  1847. extern bool isGraphIndependent(IHqlExpression * expr, IHqlExpression * graph);
  1848. extern IHqlExpression * adjustBoundIntegerValues(IHqlExpression * left, IHqlExpression * right, bool subtract);
  1849. extern bool isNullAssign(const CHqlBoundTarget & target, IHqlExpression * expr);
  1850. SubGraphInfo * matchActiveGraph(BuildCtx & ctx, IHqlExpression * graphTag);
  1851. bool isActiveGraph(BuildCtx & ctx, IHqlExpression * graphTag);
  1852. inline SubGraphInfo * queryActiveSubGraph(BuildCtx & ctx)
  1853. {
  1854. return static_cast<SubGraphInfo *>(ctx.queryFirstAssociation(AssocSubGraph));
  1855. }
  1856. #endif