hqlcpp.ipp 122 KB

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