node.pas 43 KB

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