node.pas 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472
  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. { WARNING: there are now 32 elements in this type, and a set of this
  257. type is written to the PPU. So before adding more elements,
  258. either move some flags to specific nodes, or stream a normalset
  259. to the ppu
  260. }
  261. );
  262. tnodeflags = set of tnodeflag;
  263. const
  264. { contains the flags which must be equal for the equality }
  265. { of nodes }
  266. flagsequal : tnodeflags = [nf_error];
  267. type
  268. tnodelist = class
  269. end;
  270. pnode = ^tnode;
  271. { basic class for the intermediated representation fpc uses }
  272. tnode = class
  273. private
  274. fppuidx : longint;
  275. function getppuidx:longint;
  276. public
  277. { type of this node }
  278. nodetype : tnodetype;
  279. { type of the current code block, general/const/type }
  280. blocktype : tblock_type;
  281. { expected location of the result of this node (pass1) }
  282. expectloc : tcgloc;
  283. { the location of the result of this node (pass2) }
  284. location : tlocation;
  285. { the parent node of this is node }
  286. { this field is set by concattolist }
  287. parent : tnode;
  288. { next node in control flow on the same block level, i.e.
  289. for loop nodes, this is the next node after the end of the loop,
  290. same for if and case, if this field is nil, the next node is the procedure exit,
  291. for the last node in a loop this is set to the loop header
  292. this field is set only for control flow nodes }
  293. successor : tnode;
  294. { there are some properties about the node stored }
  295. flags : tnodeflags;
  296. resultdef : tdef;
  297. resultdefderef : tderef;
  298. fileinfo : tfileposinfo;
  299. localswitches : tlocalswitches;
  300. verbosity : longint;
  301. optinfo : poptinfo;
  302. constructor create(t:tnodetype);
  303. { this constructor is only for creating copies of class }
  304. { the fields are copied by getcopy }
  305. constructor createforcopy;
  306. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);virtual;
  307. destructor destroy;override;
  308. procedure ppuwrite(ppufile:tcompilerppufile);virtual;
  309. procedure buildderefimpl;virtual;
  310. procedure derefimpl;virtual;
  311. procedure resolveppuidx;virtual;
  312. { toggles the flag }
  313. procedure toggleflag(f : tnodeflag);
  314. { the 1.1 code generator may override pass_1 }
  315. { and it need not to implement det_* then }
  316. { 1.1: pass_1 returns a value<>0 if the node has been transformed }
  317. { 2.0: runs pass_typecheck and det_temp }
  318. function pass_1 : tnode;virtual;abstract;
  319. { dermines the resultdef of the node }
  320. function pass_typecheck : tnode;virtual;abstract;
  321. { tries to simplify the node, returns a value <>nil if a simplified
  322. node has been created }
  323. function simplify(forinline : boolean) : tnode;virtual;
  324. {$ifdef state_tracking}
  325. { Does optimizations by keeping track of the variable states
  326. in a procedure }
  327. function track_state_pass(exec_known:boolean):boolean;virtual;
  328. {$endif}
  329. { For a t1:=t2 tree, mark the part of the tree t1 that gets
  330. written to (normally the loadnode) as write access. }
  331. procedure mark_write;virtual;
  332. { dermines the number of necessary temp. locations to evaluate
  333. the node }
  334. procedure det_temp;virtual;abstract;
  335. procedure pass_generate_code;virtual;abstract;
  336. { comparing of nodes }
  337. function isequal(p : tnode) : boolean;
  338. { to implement comparisation, override this method }
  339. function docompare(p : tnode) : boolean;virtual;
  340. { wrapper for getcopy }
  341. function getcopy : tnode;
  342. { does the real copying of a node }
  343. function dogetcopy : tnode;virtual;
  344. procedure insertintolist(l : tnodelist);virtual;
  345. { writes a node for debugging purpose, shouldn't be called }
  346. { direct, because there is no test for nil, use printnode }
  347. { to write a complete tree }
  348. procedure printnodeinfo(var t:text);virtual;
  349. procedure printnodedata(var t:text);virtual;
  350. procedure printnodetree(var t:text);virtual;
  351. {$ifdef DEBUG_NODE_XML}
  352. { For writing nodes to XML files - do not call directly, but
  353. instead call XMLPrintNode to write a complete tree }
  354. procedure XMLPrintNodeInfo(var T: Text); dynamic;
  355. procedure XMLPrintNodeData(var T: Text); virtual;
  356. procedure XMLPrintNodeTree(var T: Text); virtual;
  357. {$endif DEBUG_NODE_XML}
  358. procedure concattolist(l : tlinkedlist);virtual;
  359. function ischild(p : tnode) : boolean;virtual;
  360. { ensures that the optimizer info record is allocated }
  361. function allocoptinfo : poptinfo;inline;
  362. property ppuidx:longint read getppuidx;
  363. end;
  364. tnodeclass = class of tnode;
  365. tnodeclassarray = array[tnodetype] of tnodeclass;
  366. { this node is the anchestor for all nodes with at least }
  367. { one child, you have to use it if you want to use }
  368. { true- and current_procinfo.CurrFalseLabel }
  369. //punarynode = ^tunarynode;
  370. tunarynode = class(tnode)
  371. left : tnode;
  372. constructor create(t:tnodetype;l : tnode);
  373. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  374. destructor destroy;override;
  375. procedure ppuwrite(ppufile:tcompilerppufile);override;
  376. procedure buildderefimpl;override;
  377. procedure derefimpl;override;
  378. procedure concattolist(l : tlinkedlist);override;
  379. function ischild(p : tnode) : boolean;override;
  380. function docompare(p : tnode) : boolean;override;
  381. function dogetcopy : tnode;override;
  382. procedure insertintolist(l : tnodelist);override;
  383. procedure printnodedata(var t:text);override;
  384. {$ifdef DEBUG_NODE_XML}
  385. procedure XMLPrintNodeData(var T: Text); override;
  386. {$endif DEBUG_NODE_XML}
  387. end;
  388. //pbinarynode = ^tbinarynode;
  389. tbinarynode = class(tunarynode)
  390. right : tnode;
  391. constructor create(t:tnodetype;l,r : tnode);
  392. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  393. destructor destroy;override;
  394. procedure ppuwrite(ppufile:tcompilerppufile);override;
  395. procedure buildderefimpl;override;
  396. procedure derefimpl;override;
  397. procedure concattolist(l : tlinkedlist);override;
  398. function ischild(p : tnode) : boolean;override;
  399. function docompare(p : tnode) : boolean;override;
  400. procedure swapleftright;
  401. function dogetcopy : tnode;override;
  402. procedure insertintolist(l : tnodelist);override;
  403. procedure printnodedata(var t:text);override;
  404. {$ifdef DEBUG_NODE_XML}
  405. procedure XMLPrintNodeTree(var T: Text); override;
  406. procedure XMLPrintNodeData(var T: Text); override;
  407. {$endif DEBUG_NODE_XML}
  408. procedure printnodelist(var t:text);
  409. end;
  410. //ptertiarynode = ^ttertiarynode;
  411. ttertiarynode = class(tbinarynode)
  412. third : tnode;
  413. constructor create(_t:tnodetype;l,r,t : tnode);
  414. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  415. destructor destroy;override;
  416. procedure ppuwrite(ppufile:tcompilerppufile);override;
  417. procedure buildderefimpl;override;
  418. procedure derefimpl;override;
  419. procedure concattolist(l : tlinkedlist);override;
  420. function ischild(p : tnode) : boolean;override;
  421. function docompare(p : tnode) : boolean;override;
  422. function dogetcopy : tnode;override;
  423. procedure insertintolist(l : tnodelist);override;
  424. procedure printnodedata(var t:text);override;
  425. {$ifdef DEBUG_NODE_XML}
  426. procedure XMLPrintNodeData(var T: Text); override;
  427. {$endif DEBUG_NODE_XML}
  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(tppuset4(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(tppuset4(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. procedure tnode.concattolist(l : tlinkedlist);
  733. begin
  734. end;
  735. function tnode.ischild(p : tnode) : boolean;
  736. begin
  737. ischild:=false;
  738. end;
  739. procedure tnode.mark_write;
  740. begin
  741. {$ifdef EXTDEBUG}
  742. Comment(V_Warning,'mark_write not implemented for '+nodetype2str[nodetype]);
  743. {$endif EXTDEBUG}
  744. end;
  745. procedure tnode.printnodeinfo(var t:text);
  746. var
  747. i : tnodeflag;
  748. first : boolean;
  749. begin
  750. write(t,nodetype2str[nodetype]);
  751. if assigned(resultdef) then
  752. write(t,', resultdef = ',resultdef.typesymbolprettyname,' = "',resultdef.GetTypeName,'"')
  753. else
  754. write(t,', resultdef = <nil>');
  755. write(t,', pos = (',fileinfo.line,',',fileinfo.column,')',
  756. ', loc = ',tcgloc2str[location.loc],
  757. ', expectloc = ',tcgloc2str[expectloc],
  758. ', flags = [');
  759. first:=true;
  760. for i:=low(tnodeflag) to high(tnodeflag) do
  761. if i in flags then
  762. begin
  763. if not(first) then
  764. write(t,',')
  765. else
  766. first:=false;
  767. write(t, i);
  768. end;
  769. write(t,']');
  770. if (nf_pass1_done in flags) then
  771. write(t,', cmplx = ',node_complexity(self));
  772. end;
  773. procedure tnode.printnodedata(var t:text);
  774. begin
  775. end;
  776. procedure tnode.printnodetree(var t:text);
  777. begin
  778. write(t,printnodeindention,'(');
  779. printnodeinfo(t);
  780. writeln(t);
  781. printnodeindent;
  782. printnodedata(t);
  783. printnodeunindent;
  784. writeln(t,printnodeindention,')');
  785. end;
  786. {$ifdef DEBUG_NODE_XML}
  787. { For writing nodes to XML files - do not call directly, but
  788. instead call XMLPrintNode to write a complete tree }
  789. procedure tnode.XMLPrintNodeInfo(var T: Text);
  790. var
  791. i: TNodeFlag;
  792. first: Boolean;
  793. begin
  794. if Assigned(resultdef) then
  795. Write(T,' resultdef="', SanitiseXMLString(resultdef.typesymbolprettyname), '"');
  796. Write(T,' pos="',fileinfo.line,',',fileinfo.column);
  797. First := True;
  798. for i := Low(TNodeFlag) to High(TNodeFlag) do
  799. if i in flags then
  800. begin
  801. if First then
  802. begin
  803. Write(T, '" flags="', i);
  804. First := False;
  805. end
  806. else
  807. Write(T, ',', i)
  808. end;
  809. write(t,'"');
  810. if (nf_pass1_done in flags) then
  811. write(t,' complexity="',node_complexity(self),'"');
  812. end;
  813. procedure tnode.XMLPrintNodeData(var T: Text);
  814. begin
  815. { Nothing by default }
  816. end;
  817. procedure tnode.XMLPrintNodeTree(var T: Text);
  818. begin
  819. Write(T, PrintNodeIndention, '<', nodetype2str[nodetype]);
  820. XMLPrintNodeInfo(T);
  821. WriteLn(T, '>');
  822. PrintNodeIndent;
  823. XMLPrintNodeData(T);
  824. PrintNodeUnindent;
  825. WriteLn(T, PrintNodeIndention, '</', nodetype2str[nodetype], '>');
  826. end;
  827. {$endif DEBUG_NODE_XML}
  828. function tnode.isequal(p : tnode) : boolean;
  829. begin
  830. isequal:=
  831. (not assigned(self) and not assigned(p)) or
  832. (assigned(self) and assigned(p) and
  833. { optimized subclasses have the same nodetype as their }
  834. { superclass (for compatibility), so also check the classtype (JM) }
  835. (p.classtype=classtype) and
  836. (p.nodetype=nodetype) and
  837. (flags*flagsequal=p.flags*flagsequal) and
  838. docompare(p));
  839. end;
  840. {$ifdef state_tracking}
  841. function Tnode.track_state_pass(exec_known:boolean):boolean;
  842. begin
  843. track_state_pass:=false;
  844. end;
  845. {$endif state_tracking}
  846. function tnode.docompare(p : tnode) : boolean;
  847. begin
  848. docompare:=true;
  849. end;
  850. function cleanupcopiedto(var n : tnode;arg : pointer) : foreachnoderesult;
  851. begin
  852. result:=fen_true;
  853. if n.nodetype=labeln then
  854. tlabelnode(n).copiedto:=nil;
  855. end;
  856. function setuplabelnode(var n : tnode;arg : pointer) : foreachnoderesult;
  857. begin
  858. result:=fen_true;
  859. if (n.nodetype=goton) and assigned(tgotonode(n).labelnode) and
  860. assigned(tgotonode(n).labelnode.copiedto) then
  861. tgotonode(n).labelnode:=tgotonode(n).labelnode.copiedto;
  862. end;
  863. function tnode.getcopy : tnode;
  864. begin
  865. result:=dogetcopy;
  866. foreachnodestatic(pm_postprocess,result,@setuplabelnode,nil);
  867. foreachnodestatic(pm_postprocess,self,@cleanupcopiedto,nil);
  868. end;
  869. function tnode.dogetcopy : tnode;
  870. var
  871. p : tnode;
  872. begin
  873. { this is quite tricky because we need a node of the current }
  874. { node type and not one of tnode! }
  875. p:=tnodeclass(classtype).createforcopy;
  876. p.nodetype:=nodetype;
  877. p.expectloc:=expectloc;
  878. p.location:=location;
  879. p.parent:=parent;
  880. p.flags:=flags;
  881. p.resultdef:=resultdef;
  882. p.fileinfo:=fileinfo;
  883. p.localswitches:=localswitches;
  884. p.verbosity:=verbosity;
  885. { p.list:=list; }
  886. result:=p;
  887. end;
  888. procedure tnode.insertintolist(l : tnodelist);
  889. begin
  890. end;
  891. { ensures that the optimizer info record is allocated }
  892. function tnode.allocoptinfo : poptinfo;inline;
  893. begin
  894. if not(assigned(optinfo)) then
  895. begin
  896. new(optinfo);
  897. fillchar(optinfo^,sizeof(optinfo^),0);
  898. end;
  899. result:=optinfo;
  900. end;
  901. {****************************************************************************
  902. TUNARYNODE
  903. ****************************************************************************}
  904. constructor tunarynode.create(t:tnodetype;l : tnode);
  905. begin
  906. inherited create(t);
  907. { transfer generic paramater flag }
  908. if assigned(l) and (nf_generic_para in l.flags) then
  909. include(flags,nf_generic_para);
  910. left:=l;
  911. end;
  912. constructor tunarynode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  913. begin
  914. inherited ppuload(t,ppufile);
  915. left:=ppuloadnode(ppufile);
  916. end;
  917. destructor tunarynode.destroy;
  918. begin
  919. left.free;
  920. inherited destroy;
  921. end;
  922. procedure tunarynode.ppuwrite(ppufile:tcompilerppufile);
  923. begin
  924. inherited ppuwrite(ppufile);
  925. ppuwritenode(ppufile,left);
  926. end;
  927. procedure tunarynode.buildderefimpl;
  928. begin
  929. inherited buildderefimpl;
  930. if assigned(left) then
  931. left.buildderefimpl;
  932. end;
  933. procedure tunarynode.derefimpl;
  934. begin
  935. inherited derefimpl;
  936. if assigned(left) then
  937. left.derefimpl;
  938. end;
  939. function tunarynode.docompare(p : tnode) : boolean;
  940. begin
  941. docompare:=(inherited docompare(p) and
  942. ((left=nil) or left.isequal(tunarynode(p).left))
  943. );
  944. end;
  945. function tunarynode.dogetcopy : tnode;
  946. var
  947. p : tunarynode;
  948. begin
  949. p:=tunarynode(inherited dogetcopy);
  950. if assigned(left) then
  951. p.left:=left.dogetcopy
  952. else
  953. p.left:=nil;
  954. result:=p;
  955. end;
  956. procedure tunarynode.insertintolist(l : tnodelist);
  957. begin
  958. end;
  959. procedure tunarynode.printnodedata(var t:text);
  960. begin
  961. inherited printnodedata(t);
  962. printnode(t,left);
  963. end;
  964. {$ifdef DEBUG_NODE_XML}
  965. procedure TUnaryNode.XMLPrintNodeData(var T: Text);
  966. begin
  967. inherited XMLPrintNodeData(T);
  968. XMLPrintNode(T, Left);
  969. end;
  970. {$endif DEBUG_NODE_XML}
  971. procedure tunarynode.concattolist(l : tlinkedlist);
  972. begin
  973. left.parent:=self;
  974. left.concattolist(l);
  975. inherited concattolist(l);
  976. end;
  977. function tunarynode.ischild(p : tnode) : boolean;
  978. begin
  979. ischild:=p=left;
  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. procedure tbinarynode.concattolist(l : tlinkedlist);
  1020. begin
  1021. { we could change that depending on the number of }
  1022. { required registers }
  1023. left.parent:=self;
  1024. left.concattolist(l);
  1025. left.parent:=self;
  1026. left.concattolist(l);
  1027. inherited concattolist(l);
  1028. end;
  1029. function tbinarynode.ischild(p : tnode) : boolean;
  1030. begin
  1031. ischild:=(p=right);
  1032. end;
  1033. function tbinarynode.docompare(p : tnode) : boolean;
  1034. begin
  1035. docompare:=(inherited docompare(p) and
  1036. ((right=nil) or right.isequal(tbinarynode(p).right))
  1037. );
  1038. end;
  1039. function tbinarynode.dogetcopy : tnode;
  1040. var
  1041. p : tbinarynode;
  1042. begin
  1043. p:=tbinarynode(inherited dogetcopy);
  1044. if assigned(right) then
  1045. p.right:=right.dogetcopy
  1046. else
  1047. p.right:=nil;
  1048. result:=p;
  1049. end;
  1050. procedure tbinarynode.insertintolist(l : tnodelist);
  1051. begin
  1052. end;
  1053. procedure tbinarynode.swapleftright;
  1054. var
  1055. swapp : tnode;
  1056. begin
  1057. swapp:=right;
  1058. right:=left;
  1059. left:=swapp;
  1060. if nf_swapped in flags then
  1061. exclude(flags,nf_swapped)
  1062. else
  1063. include(flags,nf_swapped);
  1064. end;
  1065. procedure tbinarynode.printnodedata(var t:text);
  1066. begin
  1067. inherited printnodedata(t);
  1068. printnode(t,right);
  1069. end;
  1070. {$ifdef DEBUG_NODE_XML}
  1071. procedure TBinaryNode.XMLPrintNodeTree(var T: Text);
  1072. begin
  1073. Write(T, PrintNodeIndention, '<', nodetype2str[nodetype]);
  1074. XMLPrintNodeInfo(T);
  1075. WriteLn(T, '>');
  1076. PrintNodeIndent;
  1077. XMLPrintNodeData(T);
  1078. end;
  1079. procedure TBinaryNode.XMLPrintNodeData(var T: Text);
  1080. begin
  1081. inherited XMLPrintNodeData(T);
  1082. PrintNodeUnindent;
  1083. WriteLn(T, PrintNodeIndention, '</', nodetype2str[nodetype], '>');
  1084. { Right nodes are on the same indentation level }
  1085. XMLPrintNode(T, Right);
  1086. end;
  1087. {$endif DEBUG_NODE_XML}
  1088. procedure tbinarynode.printnodelist(var t:text);
  1089. var
  1090. hp : tbinarynode;
  1091. begin
  1092. hp:=self;
  1093. while assigned(hp) do
  1094. begin
  1095. write(t,printnodeindention,'(');
  1096. printnodeindent;
  1097. hp.printnodeinfo(t);
  1098. writeln(t);
  1099. printnode(t,hp.left);
  1100. writeln(t);
  1101. printnodeunindent;
  1102. writeln(t,printnodeindention,')');
  1103. hp:=tbinarynode(hp.right);
  1104. end;
  1105. end;
  1106. {****************************************************************************
  1107. TTERTIARYNODE
  1108. ****************************************************************************}
  1109. constructor ttertiarynode.create(_t:tnodetype;l,r,t : tnode);
  1110. begin
  1111. inherited create(_t,l,r);
  1112. { transfer generic parameter flag }
  1113. if assigned(t) and (nf_generic_para in t.flags) then
  1114. include(flags,nf_generic_para);
  1115. third:=t;
  1116. end;
  1117. constructor ttertiarynode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  1118. begin
  1119. inherited ppuload(t,ppufile);
  1120. third:=ppuloadnode(ppufile);
  1121. end;
  1122. destructor ttertiarynode.destroy;
  1123. begin
  1124. third.free;
  1125. inherited destroy;
  1126. end;
  1127. procedure ttertiarynode.ppuwrite(ppufile:tcompilerppufile);
  1128. begin
  1129. inherited ppuwrite(ppufile);
  1130. ppuwritenode(ppufile,third);
  1131. end;
  1132. procedure ttertiarynode.buildderefimpl;
  1133. begin
  1134. inherited buildderefimpl;
  1135. if assigned(third) then
  1136. third.buildderefimpl;
  1137. end;
  1138. procedure ttertiarynode.derefimpl;
  1139. begin
  1140. inherited derefimpl;
  1141. if assigned(third) then
  1142. third.derefimpl;
  1143. end;
  1144. function ttertiarynode.docompare(p : tnode) : boolean;
  1145. begin
  1146. docompare:=(inherited docompare(p) and
  1147. ((third=nil) or third.isequal(ttertiarynode(p).third))
  1148. );
  1149. end;
  1150. function ttertiarynode.dogetcopy : tnode;
  1151. var
  1152. p : ttertiarynode;
  1153. begin
  1154. p:=ttertiarynode(inherited dogetcopy);
  1155. if assigned(third) then
  1156. p.third:=third.dogetcopy
  1157. else
  1158. p.third:=nil;
  1159. result:=p;
  1160. end;
  1161. procedure ttertiarynode.insertintolist(l : tnodelist);
  1162. begin
  1163. end;
  1164. procedure ttertiarynode.printnodedata(var t:text);
  1165. begin
  1166. inherited printnodedata(t);
  1167. printnode(t,third);
  1168. end;
  1169. {$ifdef DEBUG_NODE_XML}
  1170. procedure TTertiaryNode.XMLPrintNodeData(var T: Text);
  1171. begin
  1172. if Assigned(Third) then
  1173. begin
  1174. WriteLn(T, PrintNodeIndention, '<third-branch>');
  1175. PrintNodeIndent;
  1176. XMLPrintNode(T, Third);
  1177. PrintNodeUnindent;
  1178. WriteLn(T, PrintNodeIndention, '</third-branch>');
  1179. end;
  1180. inherited XMLPrintNodeData(T);
  1181. end;
  1182. {$endif DEBUG_NODE_XML}
  1183. procedure ttertiarynode.concattolist(l : tlinkedlist);
  1184. begin
  1185. third.parent:=self;
  1186. third.concattolist(l);
  1187. inherited concattolist(l);
  1188. end;
  1189. function ttertiarynode.ischild(p : tnode) : boolean;
  1190. begin
  1191. ischild:=p=third;
  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.