node.pas 43 KB

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