node.pas 43 KB

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