node.pas 44 KB

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