node.pas 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469
  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 }
  218. nf_usercode_entry,
  219. { tderefnode }
  220. nf_no_checkpointer,
  221. { tvecnode }
  222. nf_memindex,
  223. nf_memseg,
  224. nf_callunique,
  225. { tloadnode/ttypeconvnode }
  226. nf_absolute,
  227. { taddnode }
  228. { if the result type of a node is currency, then this flag denotes, that the value is already mulitplied by 10000 }
  229. nf_is_currency,
  230. nf_has_pointerdiv,
  231. { the node shall be short boolean evaluated, this flag has priority over localswitches }
  232. nf_short_bool,
  233. { tmoddivnode }
  234. nf_isomod,
  235. { tassignmentnode }
  236. nf_assign_done_in_right,
  237. { tarrayconstructnode }
  238. nf_forcevaria,
  239. nf_novariaallowed,
  240. { ttypeconvnode, and the first one also treal/ord/pointerconstn }
  241. { second one also for subtractions of u32-u32 implicitly upcasted to s64 }
  242. { last one also used on addnode to inhibit procvar calling }
  243. nf_explicit,
  244. nf_internal, { no warnings/hints generated }
  245. nf_load_procvar,
  246. { tinlinenode }
  247. nf_inlineconst,
  248. { tasmnode }
  249. nf_get_asm_position,
  250. { tblocknode }
  251. nf_block_with_exit,
  252. { tloadvmtaddrnode }
  253. nf_ignore_for_wpo, { we know that this loadvmtaddrnode cannot be used to construct a class instance }
  254. { node is derived from generic parameter }
  255. nf_generic_para,
  256. { internal flag to indicate that this node has been removed from the tree or must otherwise not be
  257. execute. Running it through firstpass etc. will raise an internal error }
  258. nf_do_not_execute
  259. );
  260. tnodeflags = set of tnodeflag;
  261. const
  262. { contains the flags which must be equal for the equality }
  263. { of nodes }
  264. flagsequal : tnodeflags = [nf_error];
  265. type
  266. tnodelist = class
  267. end;
  268. pnode = ^tnode;
  269. { basic class for the intermediated representation fpc uses }
  270. tnode = class
  271. private
  272. fppuidx : longint;
  273. function getppuidx:longint;
  274. public
  275. { type of this node }
  276. nodetype : tnodetype;
  277. { type of the current code block, general/const/type }
  278. blocktype : tblock_type;
  279. { expected location of the result of this node (pass1) }
  280. expectloc : tcgloc;
  281. { the location of the result of this node (pass2) }
  282. location : tlocation;
  283. { next node in control flow on the same block level, i.e.
  284. for loop nodes, this is the next node after the end of the loop,
  285. same for if and case, if this field is nil, the next node is the procedure exit,
  286. for the last node in a loop this is set to the loop header
  287. this field is set only for control flow nodes }
  288. successor : tnode;
  289. { there are some properties about the node stored }
  290. flags : tnodeflags;
  291. resultdef : tdef;
  292. resultdefderef : tderef;
  293. fileinfo : tfileposinfo;
  294. localswitches : tlocalswitches;
  295. verbosity : longint;
  296. optinfo : poptinfo;
  297. constructor create(t:tnodetype);
  298. { this constructor is only for creating copies of class }
  299. { the fields are copied by getcopy }
  300. constructor createforcopy;
  301. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);virtual;
  302. destructor destroy;override;
  303. procedure ppuwrite(ppufile:tcompilerppufile);virtual;
  304. procedure buildderefimpl;virtual;
  305. procedure derefimpl;virtual;
  306. procedure resolveppuidx;virtual;
  307. { toggles the flag }
  308. procedure toggleflag(f : tnodeflag);
  309. { the 1.1 code generator may override pass_1 }
  310. { and it need not to implement det_* then }
  311. { 1.1: pass_1 returns a value<>0 if the node has been transformed }
  312. { 2.0: runs pass_typecheck and det_temp }
  313. function pass_1 : tnode;virtual;abstract;
  314. { dermines the resultdef of the node }
  315. function pass_typecheck : tnode;virtual;abstract;
  316. { tries to simplify the node, returns a value <>nil if a simplified
  317. node has been created }
  318. function simplify(forinline : boolean) : tnode;virtual;
  319. {$ifdef state_tracking}
  320. { Does optimizations by keeping track of the variable states
  321. in a procedure }
  322. function track_state_pass(exec_known:boolean):boolean;virtual;
  323. {$endif}
  324. { For a t1:=t2 tree, mark the part of the tree t1 that gets
  325. written to (normally the loadnode) as write access. }
  326. procedure mark_write;virtual;
  327. { dermines the number of necessary temp. locations to evaluate
  328. the node }
  329. procedure det_temp;virtual;abstract;
  330. procedure pass_generate_code;virtual;abstract;
  331. { comparing of nodes }
  332. function isequal(p : tnode) : boolean;
  333. { to implement comparisation, override this method }
  334. function docompare(p : tnode) : boolean;virtual;
  335. { wrapper for getcopy }
  336. function getcopy : tnode;
  337. { does the real copying of a node }
  338. function dogetcopy : tnode;virtual;
  339. procedure insertintolist(l : tnodelist);virtual;
  340. { writes a node for debugging purpose, shouldn't be called }
  341. { direct, because there is no test for nil, use printnode }
  342. { to write a complete tree }
  343. procedure printnodeinfo(var t:text);virtual;
  344. procedure printnodedata(var t:text);virtual;
  345. procedure printnodetree(var t:text);virtual;
  346. {$ifdef DEBUG_NODE_XML}
  347. { For writing nodes to XML files - do not call directly, but
  348. instead call XMLPrintNode to write a complete tree }
  349. procedure XMLPrintNodeInfo(var T: Text); dynamic;
  350. procedure XMLPrintNodeData(var T: Text); virtual;
  351. procedure XMLPrintNodeTree(var T: Text); virtual;
  352. {$endif DEBUG_NODE_XML}
  353. function ischild(p : tnode) : boolean;virtual;
  354. { ensures that the optimizer info record is allocated }
  355. function allocoptinfo : poptinfo;inline;
  356. property ppuidx:longint read getppuidx;
  357. end;
  358. tnodeclass = class of tnode;
  359. tnodeclassarray = array[tnodetype] of tnodeclass;
  360. { this node is the anchestor for all nodes with at least }
  361. { one child, you have to use it if you want to use }
  362. { true- and current_procinfo.CurrFalseLabel }
  363. //punarynode = ^tunarynode;
  364. tunarynode = class(tnode)
  365. left : tnode;
  366. constructor create(t:tnodetype;l : tnode);
  367. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  368. destructor destroy;override;
  369. procedure ppuwrite(ppufile:tcompilerppufile);override;
  370. procedure buildderefimpl;override;
  371. procedure derefimpl;override;
  372. function ischild(p : tnode) : boolean;override;
  373. function docompare(p : tnode) : boolean;override;
  374. function dogetcopy : tnode;override;
  375. procedure insertintolist(l : tnodelist);override;
  376. procedure printnodedata(var t:text);override;
  377. {$ifdef DEBUG_NODE_XML}
  378. procedure XMLPrintNodeData(var T: Text); override;
  379. {$endif DEBUG_NODE_XML}
  380. { Marks the current node for deletion and sets 'left' to nil.
  381. Returns what 'left' was previously set to }
  382. function PruneKeepLeft: TNode; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  383. end;
  384. //pbinarynode = ^tbinarynode;
  385. tbinarynode = class(tunarynode)
  386. right : tnode;
  387. constructor create(t:tnodetype;l,r : tnode);
  388. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  389. destructor destroy;override;
  390. procedure ppuwrite(ppufile:tcompilerppufile);override;
  391. procedure buildderefimpl;override;
  392. procedure derefimpl;override;
  393. function ischild(p : tnode) : boolean;override;
  394. function docompare(p : tnode) : boolean;override;
  395. procedure swapleftright;
  396. function dogetcopy : tnode;override;
  397. procedure insertintolist(l : tnodelist);override;
  398. procedure printnodedata(var t:text);override;
  399. {$ifdef DEBUG_NODE_XML}
  400. procedure XMLPrintNodeTree(var T: Text); override;
  401. procedure XMLPrintNodeData(var T: Text); override;
  402. {$endif DEBUG_NODE_XML}
  403. procedure printnodelist(var t:text);
  404. { Marks the current node for deletion and sets 'right' to nil.
  405. Returns what 'right' was previously set to }
  406. function PruneKeepRight: TNode; {$IFDEF USEINLINE}inline;{$endif USEINLINE}
  407. end;
  408. //ptertiarynode = ^ttertiarynode;
  409. ttertiarynode = class(tbinarynode)
  410. third : tnode;
  411. constructor create(_t:tnodetype;l,r,t : tnode);
  412. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  413. destructor destroy;override;
  414. procedure ppuwrite(ppufile:tcompilerppufile);override;
  415. procedure buildderefimpl;override;
  416. procedure derefimpl;override;
  417. function ischild(p : tnode) : boolean;override;
  418. function docompare(p : tnode) : boolean;override;
  419. function dogetcopy : tnode;override;
  420. procedure insertintolist(l : tnodelist);override;
  421. procedure printnodedata(var t:text);override;
  422. {$ifdef DEBUG_NODE_XML}
  423. procedure XMLPrintNodeData(var T: Text); override;
  424. {$endif DEBUG_NODE_XML}
  425. { Marks the current node for deletion and sets 'third' to nil.
  426. Returns what 'third' was previously set to }
  427. function PruneKeepThird: TNode; {$IFDEF USEINLINE}inline;{$endif USEINLINE}
  428. end;
  429. tbinopnode = class(tbinarynode)
  430. constructor create(t:tnodetype;l,r : tnode);virtual;
  431. function docompare(p : tnode) : boolean;override;
  432. {$ifdef DEBUG_NODE_XML}
  433. procedure XMLPrintNodeData(var T: Text); override;
  434. {$endif DEBUG_NODE_XML}
  435. end;
  436. var
  437. { array with all class types for tnodes }
  438. nodeclass : tnodeclassarray;
  439. function nodeppuidxget(i:longint):tnode;
  440. function ppuloadnode(ppufile:tcompilerppufile):tnode;
  441. procedure ppuwritenode(ppufile:tcompilerppufile;n:tnode);
  442. function ppuloadnodetree(ppufile:tcompilerppufile):tnode;
  443. procedure ppuwritenodetree(ppufile:tcompilerppufile;n:tnode);
  444. procedure printnode(var t:text;n:tnode);
  445. procedure printnode(n:tnode);
  446. {$ifdef DEBUG_NODE_XML}
  447. procedure XMLPrintNode(var T: Text; N: TNode);
  448. {$endif DEBUG_NODE_XML}
  449. function is_constnode(p : tnode) : boolean;
  450. function is_constintnode(p : tnode) : boolean;
  451. function is_constcharnode(p : tnode) : boolean;
  452. function is_constrealnode(p : tnode) : boolean;
  453. function is_constboolnode(p : tnode) : boolean;
  454. function is_constenumnode(p : tnode) : boolean;
  455. function is_constwidecharnode(p : tnode) : boolean;
  456. function is_constpointernode(p : tnode) : boolean;
  457. function is_conststringnode(p : tnode) : boolean;
  458. function is_constwidestringnode(p : tnode) : boolean;
  459. function is_conststring_or_constcharnode(p : tnode) : boolean;
  460. implementation
  461. uses
  462. verbose,entfile,comphook,
  463. {$ifdef DEBUG_NODE_XML}
  464. cutils,
  465. {$endif DEBUG_NODE_XML}
  466. ppu,
  467. symconst,
  468. nutils,nflw,
  469. defutil;
  470. const
  471. ppunodemarker = 255;
  472. {****************************************************************************
  473. Helpers
  474. ****************************************************************************}
  475. var
  476. nodeppulist : TFPObjectList;
  477. nodeppuidx : longint;
  478. procedure nodeppuidxcreate;
  479. begin
  480. nodeppulist:=TFPObjectList.Create(false);
  481. nodeppuidx:=0;
  482. end;
  483. procedure nodeppuidxresolve;
  484. var
  485. i : longint;
  486. n : tnode;
  487. begin
  488. for i:=0 to nodeppulist.count-1 do
  489. begin
  490. n:=tnode(nodeppulist[i]);
  491. if assigned(n) then
  492. n.resolveppuidx;
  493. end;
  494. end;
  495. procedure nodeppuidxfree;
  496. begin
  497. nodeppulist.free;
  498. nodeppulist:=nil;
  499. nodeppuidx:=0;
  500. end;
  501. procedure nodeppuidxadd(n:tnode);
  502. var
  503. i : longint;
  504. begin
  505. i:=n.ppuidx;
  506. if i<=0 then
  507. internalerror(200311072);
  508. if i>=nodeppulist.capacity then
  509. nodeppulist.capacity:=((i div 1024)+1)*1024;
  510. if i>=nodeppulist.count then
  511. nodeppulist.count:=i+1;
  512. nodeppulist[i]:=n;
  513. end;
  514. function nodeppuidxget(i:longint):tnode;
  515. begin
  516. if i<=0 then
  517. internalerror(200311073);
  518. result:=tnode(nodeppulist[i]);
  519. end;
  520. function ppuloadnode(ppufile:tcompilerppufile):tnode;
  521. var
  522. b : byte;
  523. t : tnodetype;
  524. hppuidx : longint;
  525. begin
  526. { marker }
  527. b:=ppufile.getbyte;
  528. if b<>ppunodemarker then
  529. internalerror(200208151);
  530. { load nodetype }
  531. t:=tnodetype(ppufile.getbyte);
  532. if t>high(tnodetype) then
  533. internalerror(200208152);
  534. if t<>emptynode then
  535. begin
  536. if not assigned(nodeclass[t]) then
  537. internalerror(200208153);
  538. hppuidx:=ppufile.getlongint;
  539. //writeln('load: ',nodetype2str[t]);
  540. { generate node of the correct class }
  541. result:=nodeclass[t].ppuload(t,ppufile);
  542. result.fppuidx:=hppuidx;
  543. nodeppuidxadd(result);
  544. end
  545. else
  546. result:=nil;
  547. end;
  548. procedure ppuwritenode(ppufile:tcompilerppufile;n:tnode);
  549. begin
  550. { marker, read by ppuloadnode }
  551. ppufile.putbyte(ppunodemarker);
  552. { type, read by ppuloadnode }
  553. if assigned(n) then
  554. begin
  555. ppufile.putbyte(byte(n.nodetype));
  556. ppufile.putlongint(n.ppuidx);
  557. //writeln('write: ',nodetype2str[n.nodetype]);
  558. n.ppuwrite(ppufile);
  559. end
  560. else
  561. ppufile.putbyte(byte(emptynode));
  562. end;
  563. function ppuloadnodetree(ppufile:tcompilerppufile):tnode;
  564. begin
  565. if ppufile.readentry<>ibnodetree then
  566. Message(unit_f_ppu_read_error);
  567. nodeppuidxcreate;
  568. result:=ppuloadnode(ppufile);
  569. nodeppuidxresolve;
  570. nodeppuidxfree;
  571. end;
  572. procedure ppuwritenodetree(ppufile:tcompilerppufile;n:tnode);
  573. begin
  574. nodeppuidxcreate;
  575. ppuwritenode(ppufile,n);
  576. ppufile.writeentry(ibnodetree);
  577. nodeppuidxfree;
  578. end;
  579. procedure printnode(var t:text;n:tnode);
  580. begin
  581. if assigned(n) then
  582. n.printnodetree(t)
  583. else
  584. writeln(t,printnodeindention,'nil');
  585. end;
  586. procedure printnode(n:tnode);
  587. begin
  588. printnode(output,n);
  589. end;
  590. {$ifdef DEBUG_NODE_XML}
  591. procedure XMLPrintNode(var T: Text; N: TNode);
  592. begin
  593. if Assigned(N) then
  594. N.XMLPrintNodeTree(T);
  595. end;
  596. {$endif DEBUG_NODE_XML}
  597. function is_constnode(p : tnode) : boolean;
  598. begin
  599. is_constnode:=(p.nodetype in nodetype_const);
  600. end;
  601. function is_constintnode(p : tnode) : boolean;
  602. begin
  603. is_constintnode:=(p.nodetype=ordconstn) and is_integer(p.resultdef);
  604. end;
  605. function is_constcharnode(p : tnode) : boolean;
  606. begin
  607. is_constcharnode:=(p.nodetype=ordconstn) and is_char(p.resultdef);
  608. end;
  609. function is_constwidecharnode(p : tnode) : boolean;
  610. begin
  611. is_constwidecharnode:=(p.nodetype=ordconstn) and is_widechar(p.resultdef);
  612. end;
  613. function is_constrealnode(p : tnode) : boolean;
  614. begin
  615. is_constrealnode:=(p.nodetype=realconstn);
  616. end;
  617. function is_constboolnode(p : tnode) : boolean;
  618. begin
  619. is_constboolnode:=(p.nodetype=ordconstn) and is_boolean(p.resultdef);
  620. end;
  621. function is_constenumnode(p : tnode) : boolean;
  622. begin
  623. is_constenumnode:=(p.nodetype=ordconstn) and (p.resultdef.typ=enumdef);
  624. end;
  625. function is_constpointernode(p : tnode) : boolean;
  626. begin
  627. is_constpointernode:=(p.nodetype in [pointerconstn,niln]);
  628. end;
  629. function is_conststringnode(p : tnode) : boolean;
  630. begin
  631. is_conststringnode :=
  632. (p.nodetype = stringconstn) and
  633. (is_chararray(p.resultdef) or
  634. is_shortstring(p.resultdef) or
  635. is_ansistring(p.resultdef));
  636. end;
  637. function is_constwidestringnode(p : tnode) : boolean;
  638. begin
  639. is_constwidestringnode :=
  640. (p.nodetype = stringconstn) and
  641. (is_widechararray(p.resultdef) or
  642. is_wide_or_unicode_string(p.resultdef));
  643. end;
  644. function is_conststring_or_constcharnode(p : tnode) : boolean;
  645. begin
  646. is_conststring_or_constcharnode :=
  647. is_conststringnode(p) or is_constcharnode(p) or
  648. is_constwidestringnode(p) or is_constwidecharnode(p);
  649. end;
  650. {****************************************************************************
  651. TNODE
  652. ****************************************************************************}
  653. constructor tnode.create(t:tnodetype);
  654. begin
  655. inherited create;
  656. nodetype:=t;
  657. blocktype:=block_type;
  658. { updated by firstpass }
  659. expectloc:=LOC_INVALID;
  660. { updated by secondpass }
  661. location.loc:=LOC_INVALID;
  662. { save local info }
  663. fileinfo:=current_filepos;
  664. localswitches:=current_settings.localswitches;
  665. verbosity:=status.verbosity;
  666. resultdef:=nil;
  667. flags:=[];
  668. end;
  669. constructor tnode.createforcopy;
  670. begin
  671. end;
  672. constructor tnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  673. begin
  674. nodetype:=t;
  675. { tnode fields }
  676. blocktype:=tblock_type(ppufile.getbyte);
  677. ppufile.getposinfo(fileinfo);
  678. ppufile.getset(tppuset5(localswitches));
  679. verbosity:=ppufile.getlongint;
  680. ppufile.getderef(resultdefderef);
  681. ppufile.getset(tppuset5(flags));
  682. { updated by firstpass }
  683. expectloc:=LOC_INVALID;
  684. { updated by secondpass }
  685. location.loc:=LOC_INVALID;
  686. end;
  687. procedure tnode.ppuwrite(ppufile:tcompilerppufile);
  688. begin
  689. ppufile.putbyte(byte(block_type));
  690. ppufile.putposinfo(fileinfo);
  691. ppufile.putset(tppuset5(localswitches));
  692. ppufile.putlongint(verbosity);
  693. ppufile.putderef(resultdefderef);
  694. ppufile.putset(tppuset5(flags));
  695. end;
  696. function tnode.getppuidx:longint;
  697. begin
  698. if fppuidx=0 then
  699. begin
  700. inc(nodeppuidx);
  701. fppuidx:=nodeppuidx;
  702. end;
  703. result:=fppuidx;
  704. end;
  705. procedure tnode.resolveppuidx;
  706. begin
  707. end;
  708. procedure tnode.buildderefimpl;
  709. begin
  710. resultdefderef.build(resultdef);
  711. end;
  712. procedure tnode.derefimpl;
  713. begin
  714. resultdef:=tdef(resultdefderef.resolve);
  715. end;
  716. procedure tnode.toggleflag(f : tnodeflag);
  717. begin
  718. if f in flags then
  719. exclude(flags,f)
  720. else
  721. include(flags,f);
  722. end;
  723. function tnode.simplify(forinline : boolean) : tnode;
  724. begin
  725. result:=nil;
  726. end;
  727. destructor tnode.destroy;
  728. begin
  729. if assigned(optinfo) then
  730. dispose(optinfo);
  731. end;
  732. function tnode.ischild(p : tnode) : boolean;
  733. begin
  734. ischild:=false;
  735. end;
  736. procedure tnode.mark_write;
  737. begin
  738. {$ifdef EXTDEBUG}
  739. Comment(V_Warning,'mark_write not implemented for '+nodetype2str[nodetype]);
  740. {$endif EXTDEBUG}
  741. end;
  742. procedure tnode.printnodeinfo(var t:text);
  743. var
  744. i : tnodeflag;
  745. first : boolean;
  746. begin
  747. write(t,nodetype2str[nodetype]);
  748. if assigned(resultdef) then
  749. write(t,', resultdef = ',resultdef.typesymbolprettyname,' = "',resultdef.GetTypeName,'"')
  750. else
  751. write(t,', resultdef = <nil>');
  752. write(t,', pos = (',fileinfo.line,',',fileinfo.column,')',
  753. ', loc = ',tcgloc2str[location.loc],
  754. ', expectloc = ',tcgloc2str[expectloc],
  755. ', flags = [');
  756. first:=true;
  757. for i:=low(tnodeflag) to high(tnodeflag) do
  758. if i in flags then
  759. begin
  760. if not(first) then
  761. write(t,',')
  762. else
  763. first:=false;
  764. write(t, i);
  765. end;
  766. write(t,']');
  767. if (nf_pass1_done in flags) then
  768. write(t,', cmplx = ',node_complexity(self));
  769. if assigned(optinfo) then
  770. write(t,', optinfo = ',HexStr(optinfo));
  771. end;
  772. procedure tnode.printnodedata(var t:text);
  773. begin
  774. end;
  775. procedure tnode.printnodetree(var t:text);
  776. begin
  777. write(t,printnodeindention,'(');
  778. printnodeinfo(t);
  779. writeln(t);
  780. printnodeindent;
  781. printnodedata(t);
  782. printnodeunindent;
  783. writeln(t,printnodeindention,')');
  784. end;
  785. {$ifdef DEBUG_NODE_XML}
  786. { For writing nodes to XML files - do not call directly, but
  787. instead call XMLPrintNode to write a complete tree }
  788. procedure tnode.XMLPrintNodeInfo(var T: Text);
  789. var
  790. i: TNodeFlag;
  791. first: Boolean;
  792. begin
  793. if Assigned(resultdef) then
  794. Write(T,' resultdef="', SanitiseXMLString(resultdef.typesymbolprettyname), '"');
  795. Write(T,' pos="',fileinfo.line,',',fileinfo.column);
  796. First := True;
  797. for i := Low(TNodeFlag) to High(TNodeFlag) do
  798. if i in flags then
  799. begin
  800. if First then
  801. begin
  802. Write(T, '" flags="', i);
  803. First := False;
  804. end
  805. else
  806. Write(T, ',', i)
  807. end;
  808. write(t,'"');
  809. if (nf_pass1_done in flags) then
  810. write(t,' complexity="',node_complexity(self),'"');
  811. end;
  812. procedure tnode.XMLPrintNodeData(var T: Text);
  813. begin
  814. { Nothing by default }
  815. end;
  816. procedure tnode.XMLPrintNodeTree(var T: Text);
  817. begin
  818. Write(T, PrintNodeIndention, '<', nodetype2str[nodetype]);
  819. XMLPrintNodeInfo(T);
  820. WriteLn(T, '>');
  821. PrintNodeIndent;
  822. XMLPrintNodeData(T);
  823. PrintNodeUnindent;
  824. WriteLn(T, PrintNodeIndention, '</', nodetype2str[nodetype], '>');
  825. end;
  826. {$endif DEBUG_NODE_XML}
  827. function tnode.isequal(p : tnode) : boolean;
  828. begin
  829. isequal:=
  830. (not assigned(self) and not assigned(p)) or
  831. (assigned(self) and assigned(p) and
  832. { optimized subclasses have the same nodetype as their }
  833. { superclass (for compatibility), so also check the classtype (JM) }
  834. (p.classtype=classtype) and
  835. (p.nodetype=nodetype) and
  836. (flags*flagsequal=p.flags*flagsequal) and
  837. docompare(p));
  838. end;
  839. {$ifdef state_tracking}
  840. function Tnode.track_state_pass(exec_known:boolean):boolean;
  841. begin
  842. track_state_pass:=false;
  843. end;
  844. {$endif state_tracking}
  845. function tnode.docompare(p : tnode) : boolean;
  846. begin
  847. docompare:=true;
  848. end;
  849. function cleanupcopiedto(var n : tnode;arg : pointer) : foreachnoderesult;
  850. begin
  851. result:=fen_true;
  852. if n.nodetype=labeln then
  853. tlabelnode(n).copiedto:=nil;
  854. end;
  855. function setuplabelnode(var n : tnode;arg : pointer) : foreachnoderesult;
  856. begin
  857. result:=fen_true;
  858. if (n.nodetype=goton) and assigned(tgotonode(n).labelnode) and
  859. assigned(tgotonode(n).labelnode.copiedto) then
  860. tgotonode(n).labelnode:=tgotonode(n).labelnode.copiedto;
  861. end;
  862. function tnode.getcopy : tnode;
  863. begin
  864. result:=dogetcopy;
  865. foreachnodestatic(pm_postprocess,result,@setuplabelnode,nil);
  866. foreachnodestatic(pm_postprocess,self,@cleanupcopiedto,nil);
  867. end;
  868. function tnode.dogetcopy : tnode;
  869. var
  870. p : tnode;
  871. begin
  872. { this is quite tricky because we need a node of the current }
  873. { node type and not one of tnode! }
  874. p:=tnodeclass(classtype).createforcopy;
  875. p.nodetype:=nodetype;
  876. p.expectloc:=expectloc;
  877. p.location:=location;
  878. p.flags:=flags;
  879. p.resultdef:=resultdef;
  880. p.fileinfo:=fileinfo;
  881. p.localswitches:=localswitches;
  882. p.verbosity:=verbosity;
  883. { p.list:=list; }
  884. result:=p;
  885. end;
  886. procedure tnode.insertintolist(l : tnodelist);
  887. begin
  888. end;
  889. { ensures that the optimizer info record is allocated }
  890. function tnode.allocoptinfo : poptinfo;inline;
  891. begin
  892. if not(assigned(optinfo)) then
  893. begin
  894. new(optinfo);
  895. fillchar(optinfo^,sizeof(optinfo^),0);
  896. end;
  897. result:=optinfo;
  898. end;
  899. {****************************************************************************
  900. TUNARYNODE
  901. ****************************************************************************}
  902. constructor tunarynode.create(t:tnodetype;l : tnode);
  903. begin
  904. inherited create(t);
  905. { transfer generic paramater flag }
  906. if assigned(l) and (nf_generic_para in l.flags) then
  907. include(flags,nf_generic_para);
  908. left:=l;
  909. end;
  910. constructor tunarynode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  911. begin
  912. inherited ppuload(t,ppufile);
  913. left:=ppuloadnode(ppufile);
  914. end;
  915. destructor tunarynode.destroy;
  916. begin
  917. left.free;
  918. inherited destroy;
  919. end;
  920. procedure tunarynode.ppuwrite(ppufile:tcompilerppufile);
  921. begin
  922. inherited ppuwrite(ppufile);
  923. ppuwritenode(ppufile,left);
  924. end;
  925. procedure tunarynode.buildderefimpl;
  926. begin
  927. inherited buildderefimpl;
  928. if assigned(left) then
  929. left.buildderefimpl;
  930. end;
  931. procedure tunarynode.derefimpl;
  932. begin
  933. inherited derefimpl;
  934. if assigned(left) then
  935. left.derefimpl;
  936. end;
  937. function tunarynode.docompare(p : tnode) : boolean;
  938. begin
  939. docompare:=(inherited docompare(p) and
  940. ((left=nil) or left.isequal(tunarynode(p).left))
  941. );
  942. end;
  943. function tunarynode.dogetcopy : tnode;
  944. var
  945. p : tunarynode;
  946. begin
  947. p:=tunarynode(inherited dogetcopy);
  948. if assigned(left) then
  949. p.left:=left.dogetcopy
  950. else
  951. p.left:=nil;
  952. result:=p;
  953. end;
  954. procedure tunarynode.insertintolist(l : tnodelist);
  955. begin
  956. end;
  957. procedure tunarynode.printnodedata(var t:text);
  958. begin
  959. inherited printnodedata(t);
  960. printnode(t,left);
  961. end;
  962. {$ifdef DEBUG_NODE_XML}
  963. procedure TUnaryNode.XMLPrintNodeData(var T: Text);
  964. begin
  965. inherited XMLPrintNodeData(T);
  966. XMLPrintNode(T, Left);
  967. end;
  968. {$endif DEBUG_NODE_XML}
  969. function tunarynode.ischild(p : tnode) : boolean;
  970. begin
  971. ischild:=p=left;
  972. end;
  973. { Marks the current node for deletion and sets 'left' to nil.
  974. Returns what 'left' was previously set to }
  975. function tunarynode.PruneKeepLeft: TNode; {$IFDEF USEINLINE}inline;{$endif USEINLINE}
  976. begin
  977. Result := left;
  978. left := nil;
  979. Include(flags, nf_do_not_execute);
  980. end;
  981. {****************************************************************************
  982. TBINARYNODE
  983. ****************************************************************************}
  984. constructor tbinarynode.create(t:tnodetype;l,r : tnode);
  985. begin
  986. inherited create(t,l);
  987. { transfer generic paramater flag }
  988. if assigned(r) and (nf_generic_para in r.flags) then
  989. include(flags,nf_generic_para);
  990. right:=r;
  991. end;
  992. constructor tbinarynode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  993. begin
  994. inherited ppuload(t,ppufile);
  995. right:=ppuloadnode(ppufile);
  996. end;
  997. destructor tbinarynode.destroy;
  998. begin
  999. right.free;
  1000. inherited destroy;
  1001. end;
  1002. procedure tbinarynode.ppuwrite(ppufile:tcompilerppufile);
  1003. begin
  1004. inherited ppuwrite(ppufile);
  1005. ppuwritenode(ppufile,right);
  1006. end;
  1007. procedure tbinarynode.buildderefimpl;
  1008. begin
  1009. inherited buildderefimpl;
  1010. if assigned(right) then
  1011. right.buildderefimpl;
  1012. end;
  1013. procedure tbinarynode.derefimpl;
  1014. begin
  1015. inherited derefimpl;
  1016. if assigned(right) then
  1017. right.derefimpl;
  1018. end;
  1019. function tbinarynode.ischild(p : tnode) : boolean;
  1020. begin
  1021. ischild:=(p=right);
  1022. end;
  1023. function tbinarynode.docompare(p : tnode) : boolean;
  1024. begin
  1025. docompare:=(inherited docompare(p) and
  1026. ((right=nil) or right.isequal(tbinarynode(p).right))
  1027. );
  1028. end;
  1029. function tbinarynode.dogetcopy : tnode;
  1030. var
  1031. p : tbinarynode;
  1032. begin
  1033. p:=tbinarynode(inherited dogetcopy);
  1034. if assigned(right) then
  1035. p.right:=right.dogetcopy
  1036. else
  1037. p.right:=nil;
  1038. result:=p;
  1039. end;
  1040. procedure tbinarynode.insertintolist(l : tnodelist);
  1041. begin
  1042. end;
  1043. procedure tbinarynode.swapleftright;
  1044. var
  1045. swapp : tnode;
  1046. begin
  1047. swapp:=right;
  1048. right:=left;
  1049. left:=swapp;
  1050. if nf_swapped in flags then
  1051. exclude(flags,nf_swapped)
  1052. else
  1053. include(flags,nf_swapped);
  1054. end;
  1055. procedure tbinarynode.printnodedata(var t:text);
  1056. begin
  1057. inherited printnodedata(t);
  1058. printnode(t,right);
  1059. end;
  1060. {$ifdef DEBUG_NODE_XML}
  1061. procedure TBinaryNode.XMLPrintNodeTree(var T: Text);
  1062. begin
  1063. Write(T, PrintNodeIndention, '<', nodetype2str[nodetype]);
  1064. XMLPrintNodeInfo(T);
  1065. WriteLn(T, '>');
  1066. PrintNodeIndent;
  1067. XMLPrintNodeData(T);
  1068. end;
  1069. procedure TBinaryNode.XMLPrintNodeData(var T: Text);
  1070. begin
  1071. inherited XMLPrintNodeData(T);
  1072. PrintNodeUnindent;
  1073. WriteLn(T, PrintNodeIndention, '</', nodetype2str[nodetype], '>');
  1074. { Right nodes are on the same indentation level }
  1075. XMLPrintNode(T, Right);
  1076. end;
  1077. {$endif DEBUG_NODE_XML}
  1078. procedure tbinarynode.printnodelist(var t:text);
  1079. var
  1080. hp : tbinarynode;
  1081. begin
  1082. hp:=self;
  1083. while assigned(hp) do
  1084. begin
  1085. write(t,printnodeindention,'(');
  1086. printnodeindent;
  1087. hp.printnodeinfo(t);
  1088. writeln(t);
  1089. printnode(t,hp.left);
  1090. writeln(t);
  1091. printnodeunindent;
  1092. writeln(t,printnodeindention,')');
  1093. hp:=tbinarynode(hp.right);
  1094. end;
  1095. end;
  1096. { Marks the current node for deletion and sets 'right' to nil.
  1097. Returns what 'right' was previously set to }
  1098. function tbinarynode.PruneKeepRight: TNode; {$IFDEF USEINLINE}inline;{$endif USEINLINE}
  1099. begin
  1100. Result := right;
  1101. right := nil;
  1102. Include(flags, nf_do_not_execute);
  1103. end;
  1104. {****************************************************************************
  1105. TTERTIARYNODE
  1106. ****************************************************************************}
  1107. constructor ttertiarynode.create(_t:tnodetype;l,r,t : tnode);
  1108. begin
  1109. inherited create(_t,l,r);
  1110. { transfer generic parameter flag }
  1111. if assigned(t) and (nf_generic_para in t.flags) then
  1112. include(flags,nf_generic_para);
  1113. third:=t;
  1114. end;
  1115. constructor ttertiarynode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  1116. begin
  1117. inherited ppuload(t,ppufile);
  1118. third:=ppuloadnode(ppufile);
  1119. end;
  1120. destructor ttertiarynode.destroy;
  1121. begin
  1122. third.free;
  1123. inherited destroy;
  1124. end;
  1125. procedure ttertiarynode.ppuwrite(ppufile:tcompilerppufile);
  1126. begin
  1127. inherited ppuwrite(ppufile);
  1128. ppuwritenode(ppufile,third);
  1129. end;
  1130. procedure ttertiarynode.buildderefimpl;
  1131. begin
  1132. inherited buildderefimpl;
  1133. if assigned(third) then
  1134. third.buildderefimpl;
  1135. end;
  1136. procedure ttertiarynode.derefimpl;
  1137. begin
  1138. inherited derefimpl;
  1139. if assigned(third) then
  1140. third.derefimpl;
  1141. end;
  1142. function ttertiarynode.docompare(p : tnode) : boolean;
  1143. begin
  1144. docompare:=(inherited docompare(p) and
  1145. ((third=nil) or third.isequal(ttertiarynode(p).third))
  1146. );
  1147. end;
  1148. function ttertiarynode.dogetcopy : tnode;
  1149. var
  1150. p : ttertiarynode;
  1151. begin
  1152. p:=ttertiarynode(inherited dogetcopy);
  1153. if assigned(third) then
  1154. p.third:=third.dogetcopy
  1155. else
  1156. p.third:=nil;
  1157. result:=p;
  1158. end;
  1159. procedure ttertiarynode.insertintolist(l : tnodelist);
  1160. begin
  1161. end;
  1162. procedure ttertiarynode.printnodedata(var t:text);
  1163. begin
  1164. inherited printnodedata(t);
  1165. printnode(t,third);
  1166. end;
  1167. {$ifdef DEBUG_NODE_XML}
  1168. procedure TTertiaryNode.XMLPrintNodeData(var T: Text);
  1169. begin
  1170. if Assigned(Third) then
  1171. begin
  1172. WriteLn(T, PrintNodeIndention, '<third-branch>');
  1173. PrintNodeIndent;
  1174. XMLPrintNode(T, Third);
  1175. PrintNodeUnindent;
  1176. WriteLn(T, PrintNodeIndention, '</third-branch>');
  1177. end;
  1178. inherited XMLPrintNodeData(T);
  1179. end;
  1180. {$endif DEBUG_NODE_XML}
  1181. function ttertiarynode.ischild(p : tnode) : boolean;
  1182. begin
  1183. ischild:=p=third;
  1184. end;
  1185. { Marks the current node for deletion and sets 'third' to nil.
  1186. Returns what 'third' was previously set to }
  1187. function ttertiarynode.PruneKeepThird: TNode; {$IFDEF USEINLINE}inline;{$endif USEINLINE}
  1188. begin
  1189. Result := third;
  1190. third := nil;
  1191. Include(flags, nf_do_not_execute);
  1192. end;
  1193. {****************************************************************************
  1194. TBINOPNODE
  1195. ****************************************************************************}
  1196. constructor tbinopnode.create(t:tnodetype;l,r : tnode);
  1197. begin
  1198. inherited create(t,l,r);
  1199. end;
  1200. function tbinopnode.docompare(p : tnode) : boolean;
  1201. begin
  1202. docompare:=(inherited docompare(p)) or
  1203. { if that's in the flags, is p then always a tbinopnode (?) (JM) }
  1204. ((nf_swapable in flags) and
  1205. left.isequal(tbinopnode(p).right) and
  1206. right.isequal(tbinopnode(p).left));
  1207. end;
  1208. {$ifdef DEBUG_NODE_XML}
  1209. procedure TBinOpNode.XMLPrintNodeData(var T: Text);
  1210. begin
  1211. { For binary operations, put the left and right branches on the same level for clarity }
  1212. XMLPrintNode(T, Left);
  1213. XMLPrintNode(T, Right);
  1214. PrintNodeUnindent;
  1215. WriteLn(T, PrintNodeIndention, '</', nodetype2str[nodetype], '>');
  1216. end;
  1217. {$endif DEBUG_NODE_XML}
  1218. begin
  1219. {$push}{$warnings off}
  1220. { tvaroption must fit into a 4 byte set for speed reasons }
  1221. if ord(high(tvaroption))>31 then
  1222. internalerror(201110301);
  1223. (* { tnodeflags must fit into a 4 byte set for speed reasons }
  1224. if ord(high(tnodeflags))>31 then
  1225. internalerror(2014020701); *)
  1226. {$pop}
  1227. end.