node.pas 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468
  1. {
  2. Copyright (c) 2000-2002 by Florian Klaempfl
  3. Basic node handling
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit node;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cclasses,
  22. globtype,globals,cgbase,cgutils,
  23. symtype,
  24. optbase;
  25. type
  26. tnodetype = (
  27. emptynode, {No node (returns nil when loading from ppu)}
  28. addn, {Represents the + operator}
  29. muln, {Represents the * operator}
  30. subn, {Represents the - operator}
  31. divn, {Represents the div operator}
  32. symdifn, {Represents the >< operator}
  33. modn, {Represents the mod operator}
  34. assignn, {Represents an assignment}
  35. loadn, {Represents the use of a variabele}
  36. rangen, {Represents a range (i.e. 0..9)}
  37. ltn, {Represents the < operator}
  38. lten, {Represents the <= operator}
  39. gtn, {Represents the > operator}
  40. gten, {Represents the >= operator}
  41. equaln, {Represents the = operator}
  42. unequaln, {Represents the <> operator}
  43. inn, {Represents the in operator}
  44. orn, {Represents the or operator}
  45. xorn, {Represents the xor operator}
  46. shrn, {Represents the shr operator}
  47. shln, {Represents the shl operator}
  48. slashn, {Represents the / operator}
  49. andn, {Represents the and operator}
  50. subscriptn, {Field in a record/object}
  51. derefn, {Dereferences a pointer}
  52. addrn, {Represents the @ operator}
  53. ordconstn, {Represents an ordinal value}
  54. typeconvn, {Represents type-conversion/typecast}
  55. calln, {Represents a call node}
  56. callparan, {Represents a parameter}
  57. realconstn, {Represents a real value}
  58. unaryminusn, {Represents a sign change (i.e. -2)}
  59. unaryplusn, {Represents a check for +Value}
  60. asmn, {Represents an assembler node }
  61. vecn, {Represents array indexing}
  62. pointerconstn, {Represents a pointer constant}
  63. stringconstn, {Represents a string constant}
  64. notn, {Represents the not operator}
  65. inlinen, {Internal procedures (i.e. writeln)}
  66. niln, {Represents the nil pointer}
  67. errorn, {This part of the tree could not be
  68. parsed because of a compiler error}
  69. typen, {A type name. Used for i.e. typeof(obj)}
  70. setelementn, {A set element(s) (i.e. [a,b] and also [a..b])}
  71. setconstn, {A set constant (i.e. [1,2])}
  72. blockn, {A block of statements}
  73. statementn, {One statement in a block of nodes}
  74. ifn, {An if statement}
  75. breakn, {A break statement}
  76. continuen, {A continue statement}
  77. whilerepeatn, {A while or repeat statement}
  78. forn, {A for loop}
  79. exitn, {An exit statement}
  80. casen, {A case statement}
  81. labeln, {A label}
  82. goton, {A goto statement}
  83. tryexceptn, {A try except block}
  84. raisen, {A raise statement}
  85. tryfinallyn, {A try finally statement}
  86. onn, {For an on statement in exception code}
  87. isn, {Represents the is operator}
  88. asn, {Represents the as typecast}
  89. starstarn, {Represents the ** operator exponentiation }
  90. arrayconstructorn, {Construction node for [...] parsing}
  91. arrayconstructorrangen, {Range element to allow sets in array construction tree}
  92. tempcreaten, { for temps in the result/firstpass }
  93. temprefn, { references to temps }
  94. tempdeleten, { for temps in the result/firstpass }
  95. addoptn, { added for optimizations where we cannot suppress }
  96. nothingn, { NOP, Do nothing}
  97. loadvmtaddrn, { Load the address of the VMT of a class/object}
  98. guidconstn, { A GUID COM Interface constant }
  99. rttin, { Rtti information so they can be accessed in result/firstpass}
  100. loadparentfpn, { Load the framepointer of the parent for nested procedures }
  101. objcselectorn, { node for an Objective-C message selector }
  102. objcprotocoln, { node for an Objective-C @protocol() expression (returns metaclass associated with protocol) }
  103. specializen, { parser-only node to handle Delphi-mode inline specializations }
  104. finalizetempsn { Internal node used to clean up code generator temps (warning: must NOT create additional tepms that may need to be finalised!) }
  105. );
  106. tnodetypeset = set of tnodetype;
  107. pnodetypeset = ^tnodetypeset;
  108. const
  109. nodetype2str : array[tnodetype] of string[24] = (
  110. '<emptynode>',
  111. 'addn',
  112. 'muln',
  113. 'subn',
  114. 'divn',
  115. 'symdifn',
  116. 'modn',
  117. 'assignn',
  118. 'loadn',
  119. 'rangen',
  120. 'ltn',
  121. 'lten',
  122. 'gtn',
  123. 'gten',
  124. 'equaln',
  125. 'unequaln',
  126. 'inn',
  127. 'orn',
  128. 'xorn',
  129. 'shrn',
  130. 'shln',
  131. 'slashn',
  132. 'andn',
  133. 'subscriptn',
  134. 'derefn',
  135. 'addrn',
  136. 'ordconstn',
  137. 'typeconvn',
  138. 'calln',
  139. 'callparan',
  140. 'realconstn',
  141. 'unaryminusn',
  142. 'unaryplusn',
  143. 'asmn',
  144. 'vecn',
  145. 'pointerconstn',
  146. 'stringconstn',
  147. 'notn',
  148. 'inlinen',
  149. 'niln',
  150. 'errorn',
  151. 'typen',
  152. 'setelementn',
  153. 'setconstn',
  154. 'blockn',
  155. 'statementn',
  156. 'ifn',
  157. 'breakn',
  158. 'continuen',
  159. 'whilerepeatn',
  160. 'forn',
  161. 'exitn',
  162. 'casen',
  163. 'labeln',
  164. 'goton',
  165. 'tryexceptn',
  166. 'raisen',
  167. 'tryfinallyn',
  168. 'onn',
  169. 'isn',
  170. 'asn',
  171. 'starstarn',
  172. 'arrayconstructn',
  173. 'arrayconstructrangen',
  174. 'tempcreaten',
  175. 'temprefn',
  176. 'tempdeleten',
  177. 'addoptn',
  178. 'nothingn',
  179. 'loadvmtaddrn',
  180. 'guidconstn',
  181. 'rttin',
  182. 'loadparentfpn',
  183. 'objcselectorn',
  184. 'objcprotocoln',
  185. 'specializen',
  186. 'finalizetempsn');
  187. { a set containing all const nodes }
  188. nodetype_const = [niln,
  189. ordconstn,
  190. pointerconstn,
  191. stringconstn,
  192. guidconstn,
  193. realconstn,
  194. setconstn];
  195. type
  196. { all boolean field of ttree are now collected in flags }
  197. tnodeflag = (
  198. { tbinop operands can be swaped }
  199. nf_swapable,
  200. { tbinop operands are swaped }
  201. nf_swapped,
  202. nf_error,
  203. { general }
  204. nf_pass1_done,
  205. { Node is written to }
  206. nf_write,
  207. { Node is modified }
  208. nf_modify,
  209. { address of node is taken }
  210. nf_address_taken,
  211. nf_is_funcret,
  212. nf_isproperty,
  213. nf_processing,
  214. { Node cannot be assigned to }
  215. nf_no_lvalue,
  216. { this node is the user code entry, if a node with this flag is removed
  217. during simplify, the flag must be moved to another node. Though
  218. normally applicable to block nodes, they can also appear on asm nodes
  219. in the case of pure assembly routines }
  220. nf_usercode_entry,
  221. { tderefnode }
  222. nf_no_checkpointer,
  223. { tloadnode/ttypeconvnode }
  224. nf_absolute,
  225. { taddnode }
  226. { if the result type of a node is currency, then this flag denotes, that the value is already mulitplied by 10000 }
  227. nf_is_currency,
  228. nf_has_pointerdiv,
  229. { the node shall be short boolean evaluated, this flag has priority over localswitches }
  230. nf_short_bool,
  231. { tmoddivnode }
  232. nf_isomod,
  233. { tassignmentnode }
  234. nf_assign_done_in_right,
  235. { tarrayconstructnode }
  236. nf_forcevaria,
  237. nf_novariaallowed,
  238. { ttypeconvnode, and the first one also treal/ord/pointerconstn }
  239. { second one also for subtractions of u32-u32 implicitly upcasted to s64 }
  240. { last one also used on addnode to inhibit procvar calling }
  241. nf_explicit,
  242. nf_internal, { no warnings/hints generated }
  243. nf_load_procvar,
  244. { tinlinenode }
  245. nf_inlineconst,
  246. { tasmnode }
  247. nf_get_asm_position,
  248. { tblocknode / this is not node-specific because it can also appear on
  249. implicit try/finally nodes }
  250. nf_block_with_exit,
  251. { tloadvmtaddrnode / tisnode }
  252. nf_ignore_for_wpo, { we know that this loadvmtaddrnode cannot be used to construct a class instance }
  253. { node is derived from generic parameter }
  254. nf_generic_para,
  255. { internal flag to indicate that this node has been removed from the tree or must otherwise not be
  256. execute. Running it through firstpass etc. will raise an internal error }
  257. nf_do_not_execute
  258. );
  259. tnodeflags = set of tnodeflag;
  260. const
  261. { contains the flags which must be equal for the equality }
  262. { of nodes }
  263. flagsequal : tnodeflags = [nf_error];
  264. type
  265. tnodelist = class
  266. end;
  267. pnode = ^tnode;
  268. { basic class for the intermediated representation fpc uses }
  269. tnode = class
  270. private
  271. fppuidx : longint;
  272. function getppuidx:longint;
  273. public
  274. { type of this node }
  275. nodetype : tnodetype;
  276. { type of the current code block, general/const/type }
  277. blocktype : tblock_type;
  278. { expected location of the result of this node (pass1) }
  279. expectloc : tcgloc;
  280. { the location of the result of this node (pass2) }
  281. location : tlocation;
  282. { next node in control flow on the same block level, i.e.
  283. for loop nodes, this is the next node after the end of the loop,
  284. same for if and case, if this field is nil, the next node is the procedure exit,
  285. for the last node in a loop this is set to the loop header
  286. this field is set only for control flow nodes }
  287. successor : tnode;
  288. { there are some properties about the node stored }
  289. flags : tnodeflags;
  290. resultdef : tdef;
  291. resultdefderef : tderef;
  292. fileinfo : tfileposinfo;
  293. localswitches : tlocalswitches;
  294. verbosity : longint;
  295. optinfo : poptinfo;
  296. constructor create(t:tnodetype);
  297. { this constructor is only for creating copies of class }
  298. { the fields are copied by getcopy }
  299. constructor createforcopy;
  300. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);virtual;
  301. destructor destroy;override;
  302. procedure ppuwrite(ppufile:tcompilerppufile);virtual;
  303. procedure buildderefimpl;virtual;
  304. procedure derefimpl;virtual;
  305. procedure resolveppuidx;virtual;
  306. { toggles the flag }
  307. procedure toggleflag(f : tnodeflag);
  308. { the 1.1 code generator may override pass_1 }
  309. { and it need not to implement det_* then }
  310. { 1.1: pass_1 returns a value<>0 if the node has been transformed }
  311. { 2.0: runs pass_typecheck and det_temp }
  312. function pass_1 : tnode;virtual;abstract;
  313. { dermines the resultdef of the node }
  314. function pass_typecheck : tnode;virtual;abstract;
  315. { tries to simplify the node, returns a value <>nil if a simplified
  316. node has been created }
  317. function simplify(forinline : boolean) : tnode;virtual;
  318. {$ifdef state_tracking}
  319. { Does optimizations by keeping track of the variable states
  320. in a procedure }
  321. function track_state_pass(exec_known:boolean):boolean;virtual;
  322. {$endif}
  323. { For a t1:=t2 tree, mark the part of the tree t1 that gets
  324. written to (normally the loadnode) as write access. }
  325. procedure mark_write;virtual;
  326. { dermines the number of necessary temp. locations to evaluate
  327. the node }
  328. procedure det_temp;virtual;abstract;
  329. procedure pass_generate_code;virtual;abstract;
  330. { comparing of nodes }
  331. function isequal(p : tnode) : boolean;
  332. { to implement comparisation, override this method }
  333. function docompare(p : tnode) : boolean;virtual;
  334. { wrapper for getcopy }
  335. function getcopy : tnode;
  336. { does the real copying of a node }
  337. function dogetcopy : tnode;virtual;
  338. procedure insertintolist(l : tnodelist);virtual;
  339. { writes a node for debugging purpose, shouldn't be called }
  340. { direct, because there is no test for nil, use printnode }
  341. { to write a complete tree }
  342. procedure printnodeinfo(var t:text);virtual;
  343. procedure printnodedata(var t:text);virtual;
  344. procedure printnodetree(var t:text);virtual;
  345. {$ifdef DEBUG_NODE_XML}
  346. { For writing nodes to XML files - do not call directly, but
  347. instead call XMLPrintNode to write a complete tree }
  348. procedure XMLPrintNodeInfo(var T: Text); dynamic;
  349. procedure XMLPrintNodeData(var T: Text); virtual;
  350. procedure XMLPrintNodeTree(var T: Text); virtual;
  351. {$endif DEBUG_NODE_XML}
  352. function ischild(p : tnode) : boolean;virtual;
  353. { ensures that the optimizer info record is allocated }
  354. function allocoptinfo : poptinfo;inline;
  355. property ppuidx:longint read getppuidx;
  356. end;
  357. tnodeclass = class of tnode;
  358. tnodeclassarray = array[tnodetype] of tnodeclass;
  359. { this node is the anchestor for all nodes with at least }
  360. { one child, you have to use it if you want to use }
  361. { true- and current_procinfo.CurrFalseLabel }
  362. //punarynode = ^tunarynode;
  363. tunarynode = class(tnode)
  364. left : tnode;
  365. constructor create(t:tnodetype;l : tnode);
  366. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  367. destructor destroy;override;
  368. procedure ppuwrite(ppufile:tcompilerppufile);override;
  369. procedure buildderefimpl;override;
  370. procedure derefimpl;override;
  371. function ischild(p : tnode) : boolean;override;
  372. function docompare(p : tnode) : boolean;override;
  373. function dogetcopy : tnode;override;
  374. procedure insertintolist(l : tnodelist);override;
  375. procedure printnodedata(var t:text);override;
  376. {$ifdef DEBUG_NODE_XML}
  377. procedure XMLPrintNodeData(var T: Text); override;
  378. {$endif DEBUG_NODE_XML}
  379. { Marks the current node for deletion and sets 'left' to nil.
  380. Returns what 'left' was previously set to }
  381. function PruneKeepLeft: TNode; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  382. end;
  383. //pbinarynode = ^tbinarynode;
  384. tbinarynode = class(tunarynode)
  385. right : tnode;
  386. constructor create(t:tnodetype;l,r : tnode);
  387. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  388. destructor destroy;override;
  389. procedure ppuwrite(ppufile:tcompilerppufile);override;
  390. procedure buildderefimpl;override;
  391. procedure derefimpl;override;
  392. function ischild(p : tnode) : boolean;override;
  393. function docompare(p : tnode) : boolean;override;
  394. procedure swapleftright;
  395. function dogetcopy : tnode;override;
  396. procedure insertintolist(l : tnodelist);override;
  397. procedure printnodedata(var t:text);override;
  398. {$ifdef DEBUG_NODE_XML}
  399. procedure XMLPrintNodeTree(var T: Text); override;
  400. procedure XMLPrintNodeData(var T: Text); override;
  401. {$endif DEBUG_NODE_XML}
  402. procedure printnodelist(var t:text);
  403. { Marks the current node for deletion and sets 'right' to nil.
  404. Returns what 'right' was previously set to }
  405. function PruneKeepRight: TNode; {$IFDEF USEINLINE}inline;{$endif USEINLINE}
  406. end;
  407. //ptertiarynode = ^ttertiarynode;
  408. ttertiarynode = class(tbinarynode)
  409. third : tnode;
  410. constructor create(_t:tnodetype;l,r,t : tnode);
  411. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  412. destructor destroy;override;
  413. procedure ppuwrite(ppufile:tcompilerppufile);override;
  414. procedure buildderefimpl;override;
  415. procedure derefimpl;override;
  416. function ischild(p : tnode) : boolean;override;
  417. function docompare(p : tnode) : boolean;override;
  418. function dogetcopy : tnode;override;
  419. procedure insertintolist(l : tnodelist);override;
  420. procedure printnodedata(var t:text);override;
  421. {$ifdef DEBUG_NODE_XML}
  422. procedure XMLPrintNodeData(var T: Text); override;
  423. {$endif DEBUG_NODE_XML}
  424. { Marks the current node for deletion and sets 'third' to nil.
  425. Returns what 'third' was previously set to }
  426. function PruneKeepThird: TNode; {$IFDEF USEINLINE}inline;{$endif USEINLINE}
  427. end;
  428. tbinopnode = class(tbinarynode)
  429. constructor create(t:tnodetype;l,r : tnode);virtual;
  430. function docompare(p : tnode) : boolean;override;
  431. {$ifdef DEBUG_NODE_XML}
  432. procedure XMLPrintNodeData(var T: Text); override;
  433. {$endif DEBUG_NODE_XML}
  434. end;
  435. var
  436. { array with all class types for tnodes }
  437. nodeclass : tnodeclassarray;
  438. function nodeppuidxget(i:longint):tnode;
  439. function ppuloadnode(ppufile:tcompilerppufile):tnode;
  440. procedure ppuwritenode(ppufile:tcompilerppufile;n:tnode);
  441. function ppuloadnodetree(ppufile:tcompilerppufile):tnode;
  442. procedure ppuwritenodetree(ppufile:tcompilerppufile;n:tnode);
  443. procedure printnode(var t:text;n:tnode);
  444. procedure printnode(n:tnode);
  445. {$ifdef DEBUG_NODE_XML}
  446. procedure XMLPrintNode(var T: Text; N: TNode);
  447. {$endif DEBUG_NODE_XML}
  448. function is_constnode(p : tnode) : boolean;
  449. function is_constintnode(p : tnode) : boolean;
  450. function is_constcharnode(p : tnode) : boolean;
  451. function is_constrealnode(p : tnode) : boolean;
  452. function is_constboolnode(p : tnode) : boolean;
  453. function is_constenumnode(p : tnode) : boolean;
  454. function is_constwidecharnode(p : tnode) : boolean;
  455. function is_constpointernode(p : tnode) : boolean;
  456. function is_conststringnode(p : tnode) : boolean;
  457. function is_constwidestringnode(p : tnode) : boolean;
  458. function is_conststring_or_constcharnode(p : tnode) : boolean;
  459. implementation
  460. uses
  461. verbose,entfile,comphook,
  462. {$ifdef DEBUG_NODE_XML}
  463. cutils,
  464. {$endif DEBUG_NODE_XML}
  465. ppu,
  466. symconst,
  467. nutils,nflw,
  468. defutil;
  469. const
  470. ppunodemarker = 255;
  471. {****************************************************************************
  472. Helpers
  473. ****************************************************************************}
  474. var
  475. nodeppulist : TFPObjectList;
  476. nodeppuidx : longint;
  477. procedure nodeppuidxcreate;
  478. begin
  479. nodeppulist:=TFPObjectList.Create(false);
  480. nodeppuidx:=0;
  481. end;
  482. procedure nodeppuidxresolve;
  483. var
  484. i : longint;
  485. n : tnode;
  486. begin
  487. for i:=0 to nodeppulist.count-1 do
  488. begin
  489. n:=tnode(nodeppulist[i]);
  490. if assigned(n) then
  491. n.resolveppuidx;
  492. end;
  493. end;
  494. procedure nodeppuidxfree;
  495. begin
  496. nodeppulist.free;
  497. nodeppulist:=nil;
  498. nodeppuidx:=0;
  499. end;
  500. procedure nodeppuidxadd(n:tnode);
  501. var
  502. i : longint;
  503. begin
  504. i:=n.ppuidx;
  505. if i<=0 then
  506. internalerror(200311072);
  507. if i>=nodeppulist.capacity then
  508. nodeppulist.capacity:=((i div 1024)+1)*1024;
  509. if i>=nodeppulist.count then
  510. nodeppulist.count:=i+1;
  511. nodeppulist[i]:=n;
  512. end;
  513. function nodeppuidxget(i:longint):tnode;
  514. begin
  515. if i<=0 then
  516. internalerror(200311073);
  517. result:=tnode(nodeppulist[i]);
  518. end;
  519. function ppuloadnode(ppufile:tcompilerppufile):tnode;
  520. var
  521. b : byte;
  522. t : tnodetype;
  523. hppuidx : longint;
  524. begin
  525. { marker }
  526. b:=ppufile.getbyte;
  527. if b<>ppunodemarker then
  528. internalerror(200208151);
  529. { load nodetype }
  530. t:=tnodetype(ppufile.getbyte);
  531. if t>high(tnodetype) then
  532. internalerror(200208152);
  533. if t<>emptynode then
  534. begin
  535. if not assigned(nodeclass[t]) then
  536. internalerror(200208153);
  537. hppuidx:=ppufile.getlongint;
  538. //writeln('load: ',nodetype2str[t]);
  539. { generate node of the correct class }
  540. result:=nodeclass[t].ppuload(t,ppufile);
  541. result.fppuidx:=hppuidx;
  542. nodeppuidxadd(result);
  543. end
  544. else
  545. result:=nil;
  546. end;
  547. procedure ppuwritenode(ppufile:tcompilerppufile;n:tnode);
  548. begin
  549. { marker, read by ppuloadnode }
  550. ppufile.putbyte(ppunodemarker);
  551. { type, read by ppuloadnode }
  552. if assigned(n) then
  553. begin
  554. ppufile.putbyte(byte(n.nodetype));
  555. ppufile.putlongint(n.ppuidx);
  556. //writeln('write: ',nodetype2str[n.nodetype]);
  557. n.ppuwrite(ppufile);
  558. end
  559. else
  560. ppufile.putbyte(byte(emptynode));
  561. end;
  562. function ppuloadnodetree(ppufile:tcompilerppufile):tnode;
  563. begin
  564. if ppufile.readentry<>ibnodetree then
  565. Message(unit_f_ppu_read_error);
  566. nodeppuidxcreate;
  567. result:=ppuloadnode(ppufile);
  568. nodeppuidxresolve;
  569. nodeppuidxfree;
  570. end;
  571. procedure ppuwritenodetree(ppufile:tcompilerppufile;n:tnode);
  572. begin
  573. nodeppuidxcreate;
  574. ppuwritenode(ppufile,n);
  575. ppufile.writeentry(ibnodetree);
  576. nodeppuidxfree;
  577. end;
  578. procedure printnode(var t:text;n:tnode);
  579. begin
  580. if assigned(n) then
  581. n.printnodetree(t)
  582. else
  583. writeln(t,printnodeindention,'nil');
  584. end;
  585. procedure printnode(n:tnode);
  586. begin
  587. printnode(output,n);
  588. end;
  589. {$ifdef DEBUG_NODE_XML}
  590. procedure XMLPrintNode(var T: Text; N: TNode);
  591. begin
  592. if Assigned(N) then
  593. N.XMLPrintNodeTree(T);
  594. end;
  595. {$endif DEBUG_NODE_XML}
  596. function is_constnode(p : tnode) : boolean;
  597. begin
  598. is_constnode:=(p.nodetype in nodetype_const);
  599. end;
  600. function is_constintnode(p : tnode) : boolean;
  601. begin
  602. is_constintnode:=(p.nodetype=ordconstn) and is_integer(p.resultdef);
  603. end;
  604. function is_constcharnode(p : tnode) : boolean;
  605. begin
  606. is_constcharnode:=(p.nodetype=ordconstn) and is_char(p.resultdef);
  607. end;
  608. function is_constwidecharnode(p : tnode) : boolean;
  609. begin
  610. is_constwidecharnode:=(p.nodetype=ordconstn) and is_widechar(p.resultdef);
  611. end;
  612. function is_constrealnode(p : tnode) : boolean;
  613. begin
  614. is_constrealnode:=(p.nodetype=realconstn);
  615. end;
  616. function is_constboolnode(p : tnode) : boolean;
  617. begin
  618. is_constboolnode:=(p.nodetype=ordconstn) and is_boolean(p.resultdef);
  619. end;
  620. function is_constenumnode(p : tnode) : boolean;
  621. begin
  622. is_constenumnode:=(p.nodetype=ordconstn) and (p.resultdef.typ=enumdef);
  623. end;
  624. function is_constpointernode(p : tnode) : boolean;
  625. begin
  626. is_constpointernode:=(p.nodetype in [pointerconstn,niln]);
  627. end;
  628. function is_conststringnode(p : tnode) : boolean;
  629. begin
  630. is_conststringnode :=
  631. (p.nodetype = stringconstn) and
  632. (is_chararray(p.resultdef) or
  633. is_shortstring(p.resultdef) or
  634. is_ansistring(p.resultdef));
  635. end;
  636. function is_constwidestringnode(p : tnode) : boolean;
  637. begin
  638. is_constwidestringnode :=
  639. (p.nodetype = stringconstn) and
  640. (is_widechararray(p.resultdef) or
  641. is_wide_or_unicode_string(p.resultdef));
  642. end;
  643. function is_conststring_or_constcharnode(p : tnode) : boolean;
  644. begin
  645. is_conststring_or_constcharnode :=
  646. is_conststringnode(p) or is_constcharnode(p) or
  647. is_constwidestringnode(p) or is_constwidecharnode(p);
  648. end;
  649. {****************************************************************************
  650. TNODE
  651. ****************************************************************************}
  652. constructor tnode.create(t:tnodetype);
  653. begin
  654. inherited create;
  655. nodetype:=t;
  656. blocktype:=block_type;
  657. { updated by firstpass }
  658. expectloc:=LOC_INVALID;
  659. { updated by secondpass }
  660. location.loc:=LOC_INVALID;
  661. { save local info }
  662. fileinfo:=current_filepos;
  663. localswitches:=current_settings.localswitches;
  664. verbosity:=status.verbosity;
  665. resultdef:=nil;
  666. flags:=[];
  667. end;
  668. constructor tnode.createforcopy;
  669. begin
  670. end;
  671. constructor tnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  672. begin
  673. nodetype:=t;
  674. { tnode fields }
  675. blocktype:=tblock_type(ppufile.getbyte);
  676. ppufile.getposinfo(fileinfo);
  677. ppufile.getset(tppuset5(localswitches));
  678. verbosity:=ppufile.getlongint;
  679. ppufile.getderef(resultdefderef);
  680. ppufile.getset(tppuset4(flags));
  681. { updated by firstpass }
  682. expectloc:=LOC_INVALID;
  683. { updated by secondpass }
  684. location.loc:=LOC_INVALID;
  685. end;
  686. procedure tnode.ppuwrite(ppufile:tcompilerppufile);
  687. begin
  688. ppufile.putbyte(byte(block_type));
  689. ppufile.putposinfo(fileinfo);
  690. ppufile.putset(tppuset5(localswitches));
  691. ppufile.putlongint(verbosity);
  692. ppufile.putderef(resultdefderef);
  693. ppufile.putset(tppuset4(flags));
  694. end;
  695. function tnode.getppuidx:longint;
  696. begin
  697. if fppuidx=0 then
  698. begin
  699. inc(nodeppuidx);
  700. fppuidx:=nodeppuidx;
  701. end;
  702. result:=fppuidx;
  703. end;
  704. procedure tnode.resolveppuidx;
  705. begin
  706. end;
  707. procedure tnode.buildderefimpl;
  708. begin
  709. resultdefderef.build(resultdef);
  710. end;
  711. procedure tnode.derefimpl;
  712. begin
  713. resultdef:=tdef(resultdefderef.resolve);
  714. end;
  715. procedure tnode.toggleflag(f : tnodeflag);
  716. begin
  717. if f in flags then
  718. exclude(flags,f)
  719. else
  720. include(flags,f);
  721. end;
  722. function tnode.simplify(forinline : boolean) : tnode;
  723. begin
  724. result:=nil;
  725. end;
  726. destructor tnode.destroy;
  727. begin
  728. if assigned(optinfo) then
  729. dispose(optinfo);
  730. end;
  731. function tnode.ischild(p : tnode) : boolean;
  732. begin
  733. ischild:=false;
  734. end;
  735. procedure tnode.mark_write;
  736. begin
  737. {$ifdef EXTDEBUG}
  738. Comment(V_Warning,'mark_write not implemented for '+nodetype2str[nodetype]);
  739. {$endif EXTDEBUG}
  740. end;
  741. procedure tnode.printnodeinfo(var t:text);
  742. var
  743. i : tnodeflag;
  744. first : boolean;
  745. begin
  746. write(t,nodetype2str[nodetype]);
  747. if assigned(resultdef) then
  748. write(t,', resultdef = ',resultdef.typesymbolprettyname,' = "',resultdef.GetTypeName,'"')
  749. else
  750. write(t,', resultdef = <nil>');
  751. write(t,', pos = (',fileinfo.line,',',fileinfo.column,')',
  752. ', loc = ',tcgloc2str[location.loc],
  753. ', expectloc = ',tcgloc2str[expectloc],
  754. ', flags = [');
  755. first:=true;
  756. for i:=low(tnodeflag) to high(tnodeflag) do
  757. if i in flags then
  758. begin
  759. if not(first) then
  760. write(t,',')
  761. else
  762. first:=false;
  763. write(t, i);
  764. end;
  765. write(t,']');
  766. if (nf_pass1_done in flags) then
  767. write(t,', cmplx = ',node_complexity(self));
  768. if assigned(optinfo) then
  769. write(t,', optinfo = ',HexStr(optinfo));
  770. end;
  771. procedure tnode.printnodedata(var t:text);
  772. begin
  773. end;
  774. procedure tnode.printnodetree(var t:text);
  775. begin
  776. write(t,printnodeindention,'(');
  777. printnodeinfo(t);
  778. writeln(t);
  779. printnodeindent;
  780. printnodedata(t);
  781. printnodeunindent;
  782. writeln(t,printnodeindention,')');
  783. end;
  784. {$ifdef DEBUG_NODE_XML}
  785. { For writing nodes to XML files - do not call directly, but
  786. instead call XMLPrintNode to write a complete tree }
  787. procedure tnode.XMLPrintNodeInfo(var T: Text);
  788. var
  789. i: TNodeFlag;
  790. first: Boolean;
  791. begin
  792. if Assigned(resultdef) then
  793. Write(T,' resultdef="', SanitiseXMLString(resultdef.typesymbolprettyname), '"');
  794. Write(T,' pos="',fileinfo.line,',',fileinfo.column);
  795. First := True;
  796. for i := Low(TNodeFlag) to High(TNodeFlag) do
  797. if i in flags then
  798. begin
  799. if First then
  800. begin
  801. Write(T, '" flags="', i);
  802. First := False;
  803. end
  804. else
  805. Write(T, ',', i)
  806. end;
  807. write(t,'"');
  808. if (nf_pass1_done in flags) then
  809. write(t,' complexity="',node_complexity(self),'"');
  810. end;
  811. procedure tnode.XMLPrintNodeData(var T: Text);
  812. begin
  813. { Nothing by default }
  814. end;
  815. procedure tnode.XMLPrintNodeTree(var T: Text);
  816. begin
  817. Write(T, PrintNodeIndention, '<', nodetype2str[nodetype]);
  818. XMLPrintNodeInfo(T);
  819. WriteLn(T, '>');
  820. PrintNodeIndent;
  821. XMLPrintNodeData(T);
  822. PrintNodeUnindent;
  823. WriteLn(T, PrintNodeIndention, '</', nodetype2str[nodetype], '>');
  824. end;
  825. {$endif DEBUG_NODE_XML}
  826. function tnode.isequal(p : tnode) : boolean;
  827. begin
  828. isequal:=
  829. (not assigned(self) and not assigned(p)) or
  830. (assigned(self) and assigned(p) and
  831. { optimized subclasses have the same nodetype as their }
  832. { superclass (for compatibility), so also check the classtype (JM) }
  833. (p.classtype=classtype) and
  834. (p.nodetype=nodetype) and
  835. (flags*flagsequal=p.flags*flagsequal) and
  836. docompare(p));
  837. end;
  838. {$ifdef state_tracking}
  839. function Tnode.track_state_pass(exec_known:boolean):boolean;
  840. begin
  841. track_state_pass:=false;
  842. end;
  843. {$endif state_tracking}
  844. function tnode.docompare(p : tnode) : boolean;
  845. begin
  846. docompare:=true;
  847. end;
  848. function cleanupcopiedto(var n : tnode;arg : pointer) : foreachnoderesult;
  849. begin
  850. result:=fen_true;
  851. if n.nodetype=labeln then
  852. tlabelnode(n).copiedto:=nil;
  853. end;
  854. function setuplabelnode(var n : tnode;arg : pointer) : foreachnoderesult;
  855. begin
  856. result:=fen_true;
  857. if (n.nodetype=goton) and assigned(tgotonode(n).labelnode) and
  858. assigned(tgotonode(n).labelnode.copiedto) then
  859. tgotonode(n).labelnode:=tgotonode(n).labelnode.copiedto;
  860. end;
  861. function tnode.getcopy : tnode;
  862. begin
  863. result:=dogetcopy;
  864. foreachnodestatic(pm_postprocess,result,@setuplabelnode,nil);
  865. foreachnodestatic(pm_postprocess,self,@cleanupcopiedto,nil);
  866. end;
  867. function tnode.dogetcopy : tnode;
  868. var
  869. p : tnode;
  870. begin
  871. { this is quite tricky because we need a node of the current }
  872. { node type and not one of tnode! }
  873. p:=tnodeclass(classtype).createforcopy;
  874. p.nodetype:=nodetype;
  875. p.expectloc:=expectloc;
  876. p.location:=location;
  877. p.flags:=flags;
  878. p.resultdef:=resultdef;
  879. p.fileinfo:=fileinfo;
  880. p.localswitches:=localswitches;
  881. p.verbosity:=verbosity;
  882. { p.list:=list; }
  883. result:=p;
  884. end;
  885. procedure tnode.insertintolist(l : tnodelist);
  886. begin
  887. end;
  888. { ensures that the optimizer info record is allocated }
  889. function tnode.allocoptinfo : poptinfo;inline;
  890. begin
  891. if not(assigned(optinfo)) then
  892. begin
  893. new(optinfo);
  894. fillchar(optinfo^,sizeof(optinfo^),0);
  895. end;
  896. result:=optinfo;
  897. end;
  898. {****************************************************************************
  899. TUNARYNODE
  900. ****************************************************************************}
  901. constructor tunarynode.create(t:tnodetype;l : tnode);
  902. begin
  903. inherited create(t);
  904. { transfer generic paramater flag }
  905. if assigned(l) and (nf_generic_para in l.flags) then
  906. include(flags,nf_generic_para);
  907. left:=l;
  908. end;
  909. constructor tunarynode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  910. begin
  911. inherited ppuload(t,ppufile);
  912. left:=ppuloadnode(ppufile);
  913. end;
  914. destructor tunarynode.destroy;
  915. begin
  916. left.free;
  917. inherited destroy;
  918. end;
  919. procedure tunarynode.ppuwrite(ppufile:tcompilerppufile);
  920. begin
  921. inherited ppuwrite(ppufile);
  922. ppuwritenode(ppufile,left);
  923. end;
  924. procedure tunarynode.buildderefimpl;
  925. begin
  926. inherited buildderefimpl;
  927. if assigned(left) then
  928. left.buildderefimpl;
  929. end;
  930. procedure tunarynode.derefimpl;
  931. begin
  932. inherited derefimpl;
  933. if assigned(left) then
  934. left.derefimpl;
  935. end;
  936. function tunarynode.docompare(p : tnode) : boolean;
  937. begin
  938. docompare:=(inherited docompare(p) and
  939. ((left=nil) or left.isequal(tunarynode(p).left))
  940. );
  941. end;
  942. function tunarynode.dogetcopy : tnode;
  943. var
  944. p : tunarynode;
  945. begin
  946. p:=tunarynode(inherited dogetcopy);
  947. if assigned(left) then
  948. p.left:=left.dogetcopy
  949. else
  950. p.left:=nil;
  951. result:=p;
  952. end;
  953. procedure tunarynode.insertintolist(l : tnodelist);
  954. begin
  955. end;
  956. procedure tunarynode.printnodedata(var t:text);
  957. begin
  958. inherited printnodedata(t);
  959. printnode(t,left);
  960. end;
  961. {$ifdef DEBUG_NODE_XML}
  962. procedure TUnaryNode.XMLPrintNodeData(var T: Text);
  963. begin
  964. inherited XMLPrintNodeData(T);
  965. XMLPrintNode(T, Left);
  966. end;
  967. {$endif DEBUG_NODE_XML}
  968. function tunarynode.ischild(p : tnode) : boolean;
  969. begin
  970. ischild:=p=left;
  971. end;
  972. { Marks the current node for deletion and sets 'left' to nil.
  973. Returns what 'left' was previously set to }
  974. function tunarynode.PruneKeepLeft: TNode; {$IFDEF USEINLINE}inline;{$endif USEINLINE}
  975. begin
  976. Result := left;
  977. left := nil;
  978. Include(flags, nf_do_not_execute);
  979. end;
  980. {****************************************************************************
  981. TBINARYNODE
  982. ****************************************************************************}
  983. constructor tbinarynode.create(t:tnodetype;l,r : tnode);
  984. begin
  985. inherited create(t,l);
  986. { transfer generic paramater flag }
  987. if assigned(r) and (nf_generic_para in r.flags) then
  988. include(flags,nf_generic_para);
  989. right:=r;
  990. end;
  991. constructor tbinarynode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  992. begin
  993. inherited ppuload(t,ppufile);
  994. right:=ppuloadnode(ppufile);
  995. end;
  996. destructor tbinarynode.destroy;
  997. begin
  998. right.free;
  999. inherited destroy;
  1000. end;
  1001. procedure tbinarynode.ppuwrite(ppufile:tcompilerppufile);
  1002. begin
  1003. inherited ppuwrite(ppufile);
  1004. ppuwritenode(ppufile,right);
  1005. end;
  1006. procedure tbinarynode.buildderefimpl;
  1007. begin
  1008. inherited buildderefimpl;
  1009. if assigned(right) then
  1010. right.buildderefimpl;
  1011. end;
  1012. procedure tbinarynode.derefimpl;
  1013. begin
  1014. inherited derefimpl;
  1015. if assigned(right) then
  1016. right.derefimpl;
  1017. end;
  1018. function tbinarynode.ischild(p : tnode) : boolean;
  1019. begin
  1020. ischild:=(p=right);
  1021. end;
  1022. function tbinarynode.docompare(p : tnode) : boolean;
  1023. begin
  1024. docompare:=(inherited docompare(p) and
  1025. ((right=nil) or right.isequal(tbinarynode(p).right))
  1026. );
  1027. end;
  1028. function tbinarynode.dogetcopy : tnode;
  1029. var
  1030. p : tbinarynode;
  1031. begin
  1032. p:=tbinarynode(inherited dogetcopy);
  1033. if assigned(right) then
  1034. p.right:=right.dogetcopy
  1035. else
  1036. p.right:=nil;
  1037. result:=p;
  1038. end;
  1039. procedure tbinarynode.insertintolist(l : tnodelist);
  1040. begin
  1041. end;
  1042. procedure tbinarynode.swapleftright;
  1043. var
  1044. swapp : tnode;
  1045. begin
  1046. swapp:=right;
  1047. right:=left;
  1048. left:=swapp;
  1049. if nf_swapped in flags then
  1050. exclude(flags,nf_swapped)
  1051. else
  1052. include(flags,nf_swapped);
  1053. end;
  1054. procedure tbinarynode.printnodedata(var t:text);
  1055. begin
  1056. inherited printnodedata(t);
  1057. printnode(t,right);
  1058. end;
  1059. {$ifdef DEBUG_NODE_XML}
  1060. procedure TBinaryNode.XMLPrintNodeTree(var T: Text);
  1061. begin
  1062. Write(T, PrintNodeIndention, '<', nodetype2str[nodetype]);
  1063. XMLPrintNodeInfo(T);
  1064. WriteLn(T, '>');
  1065. PrintNodeIndent;
  1066. XMLPrintNodeData(T);
  1067. end;
  1068. procedure TBinaryNode.XMLPrintNodeData(var T: Text);
  1069. begin
  1070. inherited XMLPrintNodeData(T);
  1071. PrintNodeUnindent;
  1072. WriteLn(T, PrintNodeIndention, '</', nodetype2str[nodetype], '>');
  1073. { Right nodes are on the same indentation level }
  1074. XMLPrintNode(T, Right);
  1075. end;
  1076. {$endif DEBUG_NODE_XML}
  1077. procedure tbinarynode.printnodelist(var t:text);
  1078. var
  1079. hp : tbinarynode;
  1080. begin
  1081. hp:=self;
  1082. while assigned(hp) do
  1083. begin
  1084. write(t,printnodeindention,'(');
  1085. printnodeindent;
  1086. hp.printnodeinfo(t);
  1087. writeln(t);
  1088. printnode(t,hp.left);
  1089. writeln(t);
  1090. printnodeunindent;
  1091. writeln(t,printnodeindention,')');
  1092. hp:=tbinarynode(hp.right);
  1093. end;
  1094. end;
  1095. { Marks the current node for deletion and sets 'right' to nil.
  1096. Returns what 'right' was previously set to }
  1097. function tbinarynode.PruneKeepRight: TNode; {$IFDEF USEINLINE}inline;{$endif USEINLINE}
  1098. begin
  1099. Result := right;
  1100. right := nil;
  1101. Include(flags, nf_do_not_execute);
  1102. end;
  1103. {****************************************************************************
  1104. TTERTIARYNODE
  1105. ****************************************************************************}
  1106. constructor ttertiarynode.create(_t:tnodetype;l,r,t : tnode);
  1107. begin
  1108. inherited create(_t,l,r);
  1109. { transfer generic parameter flag }
  1110. if assigned(t) and (nf_generic_para in t.flags) then
  1111. include(flags,nf_generic_para);
  1112. third:=t;
  1113. end;
  1114. constructor ttertiarynode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  1115. begin
  1116. inherited ppuload(t,ppufile);
  1117. third:=ppuloadnode(ppufile);
  1118. end;
  1119. destructor ttertiarynode.destroy;
  1120. begin
  1121. third.free;
  1122. inherited destroy;
  1123. end;
  1124. procedure ttertiarynode.ppuwrite(ppufile:tcompilerppufile);
  1125. begin
  1126. inherited ppuwrite(ppufile);
  1127. ppuwritenode(ppufile,third);
  1128. end;
  1129. procedure ttertiarynode.buildderefimpl;
  1130. begin
  1131. inherited buildderefimpl;
  1132. if assigned(third) then
  1133. third.buildderefimpl;
  1134. end;
  1135. procedure ttertiarynode.derefimpl;
  1136. begin
  1137. inherited derefimpl;
  1138. if assigned(third) then
  1139. third.derefimpl;
  1140. end;
  1141. function ttertiarynode.docompare(p : tnode) : boolean;
  1142. begin
  1143. docompare:=(inherited docompare(p) and
  1144. ((third=nil) or third.isequal(ttertiarynode(p).third))
  1145. );
  1146. end;
  1147. function ttertiarynode.dogetcopy : tnode;
  1148. var
  1149. p : ttertiarynode;
  1150. begin
  1151. p:=ttertiarynode(inherited dogetcopy);
  1152. if assigned(third) then
  1153. p.third:=third.dogetcopy
  1154. else
  1155. p.third:=nil;
  1156. result:=p;
  1157. end;
  1158. procedure ttertiarynode.insertintolist(l : tnodelist);
  1159. begin
  1160. end;
  1161. procedure ttertiarynode.printnodedata(var t:text);
  1162. begin
  1163. inherited printnodedata(t);
  1164. printnode(t,third);
  1165. end;
  1166. {$ifdef DEBUG_NODE_XML}
  1167. procedure TTertiaryNode.XMLPrintNodeData(var T: Text);
  1168. begin
  1169. if Assigned(Third) then
  1170. begin
  1171. WriteLn(T, PrintNodeIndention, '<third-branch>');
  1172. PrintNodeIndent;
  1173. XMLPrintNode(T, Third);
  1174. PrintNodeUnindent;
  1175. WriteLn(T, PrintNodeIndention, '</third-branch>');
  1176. end;
  1177. inherited XMLPrintNodeData(T);
  1178. end;
  1179. {$endif DEBUG_NODE_XML}
  1180. function ttertiarynode.ischild(p : tnode) : boolean;
  1181. begin
  1182. ischild:=p=third;
  1183. end;
  1184. { Marks the current node for deletion and sets 'third' to nil.
  1185. Returns what 'third' was previously set to }
  1186. function ttertiarynode.PruneKeepThird: TNode; {$IFDEF USEINLINE}inline;{$endif USEINLINE}
  1187. begin
  1188. Result := third;
  1189. third := nil;
  1190. Include(flags, nf_do_not_execute);
  1191. end;
  1192. {****************************************************************************
  1193. TBINOPNODE
  1194. ****************************************************************************}
  1195. constructor tbinopnode.create(t:tnodetype;l,r : tnode);
  1196. begin
  1197. inherited create(t,l,r);
  1198. end;
  1199. function tbinopnode.docompare(p : tnode) : boolean;
  1200. begin
  1201. docompare:=(inherited docompare(p)) or
  1202. { if that's in the flags, is p then always a tbinopnode (?) (JM) }
  1203. ((nf_swapable in flags) and
  1204. left.isequal(tbinopnode(p).right) and
  1205. right.isequal(tbinopnode(p).left));
  1206. end;
  1207. {$ifdef DEBUG_NODE_XML}
  1208. procedure TBinOpNode.XMLPrintNodeData(var T: Text);
  1209. begin
  1210. { For binary operations, put the left and right branches on the same level for clarity }
  1211. XMLPrintNode(T, Left);
  1212. XMLPrintNode(T, Right);
  1213. PrintNodeUnindent;
  1214. WriteLn(T, PrintNodeIndention, '</', nodetype2str[nodetype], '>');
  1215. end;
  1216. {$endif DEBUG_NODE_XML}
  1217. begin
  1218. {$push}{$warnings off}
  1219. { tvaroption must fit into a 4 byte set for speed reasons }
  1220. if ord(high(tvaroption))>31 then
  1221. internalerror(201110301);
  1222. (* { tnodeflags must fit into a 4 byte set for speed reasons }
  1223. if ord(high(tnodeflags))>31 then
  1224. internalerror(2014020701); *)
  1225. {$pop}
  1226. end.