nodeh.inc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. {
  2. $Id$
  3. Copyright (c) 1999-2000 by Florian Klaempfl
  4. The declarations of the nodes for the new code generator
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. type
  19. pconstset = ^tconstset;
  20. tconstset = array[0..31] of byte;
  21. tnodetype = (
  22. addn, {Represents the + operator.}
  23. muln, {Represents the * operator.}
  24. subn, {Represents the - operator.}
  25. divn, {Represents the div operator.}
  26. symdifn, {Represents the >< operator.}
  27. modn, {Represents the mod operator.}
  28. assignn, {Represents an assignment.}
  29. loadn, {Represents the use of a variabele.}
  30. rangen, {Represents a range (i.e. 0..9).}
  31. ltn, {Represents the < operator.}
  32. lten, {Represents the <= operator.}
  33. gtn, {Represents the > operator.}
  34. gten, {Represents the >= operator.}
  35. equaln, {Represents the = operator.}
  36. unequaln, {Represents the <> operator.}
  37. inn, {Represents the in operator.}
  38. orn, {Represents the or operator.}
  39. xorn, {Represents the xor operator.}
  40. shrn, {Represents the shr operator.}
  41. shln, {Represents the shl operator.}
  42. slashn, {Represents the / operator.}
  43. andn, {Represents the and operator.}
  44. subscriptn, {??? Field in a record/object?}
  45. derefn, {Dereferences a pointer.}
  46. addrn, {Represents the @ operator.}
  47. doubleaddrn, {Represents the @@ operator.}
  48. ordconstn, {Represents an ordinal value.}
  49. typeconvn, {Represents type-conversion/typecast.}
  50. calln, {Represents a call node.}
  51. callparan, {Represents a parameter.}
  52. realconstn, {Represents a real value.}
  53. fixconstn, {Represents a fixed value.}
  54. unaryminusn, {Represents a sign change (i.e. -2).}
  55. asmn, {Represents an assembler node }
  56. vecn, {Represents array indexing.}
  57. pointerconstn,
  58. stringconstn, {Represents a string constant.}
  59. funcretn, {Represents the function result var.}
  60. selfn, {Represents the self parameter.}
  61. notn, {Represents the not operator.}
  62. inlinen, {Internal procedures (i.e. writeln).}
  63. niln, {Represents the nil pointer.}
  64. errorn, {This part of the tree could not be
  65. parsed because of a compiler error.}
  66. typen, {A type name. Used for i.e. typeof(obj).}
  67. hnewn, {The new operation, constructor call.}
  68. hdisposen, {The dispose operation with destructor call.}
  69. newn, {The new operation, constructor call.}
  70. simpledisposen, {The dispose operation.}
  71. setelementn, {A set element(s) (i.e. [a,b] and also [a..b]).}
  72. setconstn, {A set constant (i.e. [1,2]).}
  73. blockn, {A block of statements.}
  74. statementn, {One statement in a block of nodes.}
  75. loopn, { used in genloopnode, must be converted }
  76. ifn, {An if statement.}
  77. breakn, {A break statement.}
  78. continuen, {A continue statement.}
  79. repeatn, {A repeat until block.}
  80. whilen, {A while do statement.}
  81. forn, {A for loop.}
  82. exitn, {An exit statement.}
  83. withn, {A with statement.}
  84. casen, {A case statement.}
  85. labeln, {A label.}
  86. goton, {A goto statement.}
  87. simplenewn, {The new operation.}
  88. tryexceptn, {A try except block.}
  89. raisen, {A raise statement.}
  90. switchesn, {??? Currently unused...}
  91. tryfinallyn, {A try finally statement.}
  92. onn, { for an on statement in exception code }
  93. isn, {Represents the is operator.}
  94. asn, {Represents the as typecast.}
  95. caretn, {Represents the ^ operator.}
  96. failn, {Represents the fail statement.}
  97. starstarn, {Represents the ** operator exponentiation }
  98. procinlinen, {Procedures that can be inlined }
  99. arrayconstructorn, {Construction node for [...] parsing}
  100. arrayconstructorrangen, {Range element to allow sets in array construction tree}
  101. { added for optimizations where we cannot suppress }
  102. nothingn,
  103. loadvmtn
  104. );
  105. { all boolean field of ttree are now collected in flags }
  106. tnodeflags = (
  107. nf_needs_truefalselabel,
  108. nf_swapable, { tbinop operands can be swaped }
  109. nf_swaped, { tbinop operands are swaped }
  110. nf_error,
  111. { flags used by tcallnode }
  112. nf_no_check,
  113. nf_unit_specific,
  114. nf_return_value_used,
  115. nf_static_call,
  116. { flags used by loop nodes }
  117. nf_backward, { set if it is a for ... downto ... do loop }
  118. nf_varstate, { do we need to parse childs to set var state }
  119. { taddrnode }
  120. nf_procvarload,
  121. { tvecnode }
  122. nf_memindex,
  123. nf_memseg,
  124. nf_callunique,
  125. { twithnode }
  126. nf_islocal,
  127. { tloadnode }
  128. nf_absolute,
  129. nf_first,
  130. { tassignmentnode }
  131. nf_concat_string,
  132. { tfuncretnode }
  133. nf_is_first_funcret, { 20th }
  134. { tarrayconstructnode }
  135. nf_cargs,
  136. nf_cargswap,
  137. nf_forcevaria,
  138. nf_novariaallowed,
  139. { ttypeconvnode }
  140. nf_explizit,
  141. { tinlinenode }
  142. nf_inlineconst,
  143. { general }
  144. nf_isproperty,
  145. nf_varstateset,
  146. { tasmnode }
  147. nf_object_preserved,
  148. { taddnode }
  149. nf_use_strconcat
  150. );
  151. tnodeflagset = set of tnodeflags;
  152. const
  153. { contains the flags which must be equal for the equality }
  154. { of nodes }
  155. flagsequal : tnodeflagset = [nf_error,nf_static_call,nf_backward];
  156. type
  157. { later (for the newcg) tnode will inherit from tlinkedlist_item }
  158. tnode = class
  159. nodetype : tnodetype;
  160. { the location of the result of this node }
  161. location : tlocation;
  162. { the parent node of this is node }
  163. { this field is set by concattolist }
  164. parent : tnode;
  165. { there are some properties about the node stored }
  166. flags : tnodeflagset;
  167. { the number of registers needed to evalute the node }
  168. registers32,registersfpu : longint; { must be longint !!!! }
  169. {$ifdef SUPPORT_MMX}
  170. registersmmx,registerskni : longint;
  171. {$endif SUPPORT_MMX}
  172. resulttype : pdef;
  173. fileinfo : tfileposinfo;
  174. localswitches : tlocalswitches;
  175. {$ifdef extdebug}
  176. maxfirstpasscount,
  177. firstpasscount : longint;
  178. {$endif extdebug}
  179. list : paasmoutput;
  180. constructor create(tt : tnodetype);
  181. { this constructor is only for creating copies of class }
  182. { the fields are copied by getcopy }
  183. constructor createforcopy;
  184. destructor destroy;override;
  185. { toggles the flag }
  186. procedure toggleflag(f : tnodeflags);
  187. { the 1.1 code generator may override pass_1 }
  188. { and it need not to implement det_* then }
  189. { 1.1: pass_1 returns a value<>0 if the node has been transformed }
  190. { 2.0: runs det_resulttype and det_temp }
  191. function pass_1 : tnode;virtual;
  192. { dermines the resulttype of the node }
  193. procedure det_resulttype;virtual;abstract;
  194. { dermines the number of necessary temp. locations to evaluate
  195. the node }
  196. procedure det_temp;virtual;abstract;
  197. procedure pass_2;virtual;abstract;
  198. { comparing of nodes }
  199. function isequal(p : tnode) : boolean;
  200. { to implement comparisation, override this method }
  201. function docompare(p : tnode) : boolean;virtual;
  202. { gets a copy of the node }
  203. function getcopy : tnode;virtual;
  204. {$ifdef EXTDEBUG}
  205. { writes a node for debugging purpose, shouldn't be called }
  206. { direct, because there is no test for nil, use writenode }
  207. { to write a complete tree }
  208. procedure dowrite;virtual;
  209. procedure dowritenodetype;virtual;
  210. {$endif EXTDEBUG}
  211. procedure concattolist(l : plinkedlist);virtual;
  212. function ischild(p : tnode) : boolean;virtual;
  213. procedure set_file_line(from : tnode);
  214. procedure set_tree_filepos(const filepos : tfileposinfo);
  215. end;
  216. { this node is the anchestor for all nodes with at least }
  217. { one child, you have to use it if you want to use }
  218. { true- and falselabel }
  219. tparentnode = class(tnode)
  220. {$ifdef newcg}
  221. falselabel,truelabel : pasmlabel;
  222. {$endif newcg}
  223. end;
  224. tnodeclass = class of tnode;
  225. punarynode = ^tunarynode;
  226. tunarynode = class(tparentnode)
  227. left : tnode;
  228. constructor create(tt : tnodetype;l : tnode);
  229. destructor destroy;override;
  230. procedure concattolist(l : plinkedlist);override;
  231. function ischild(p : tnode) : boolean;override;
  232. procedure det_resulttype;override;
  233. procedure det_temp;override;
  234. function docompare(p : tnode) : boolean;override;
  235. function getcopy : tnode;override;
  236. procedure left_max;
  237. {$ifdef extdebug}
  238. procedure dowrite;override;
  239. {$endif extdebug}
  240. end;
  241. pbinarynode = ^tbinarynode;
  242. tbinarynode = class(tunarynode)
  243. right : tnode;
  244. constructor create(tt : tnodetype;l,r : tnode);
  245. destructor destroy;override;
  246. procedure concattolist(l : plinkedlist);override;
  247. function ischild(p : tnode) : boolean;override;
  248. procedure det_resulttype;override;
  249. procedure det_temp;override;
  250. function docompare(p : tnode) : boolean;override;
  251. procedure swapleftright;
  252. function getcopy : tnode;override;
  253. procedure left_right_max;
  254. {$ifdef extdebug}
  255. procedure dowrite;override;
  256. {$endif extdebug}
  257. end;
  258. pbinopnode = ^tbinopnode;
  259. tbinopnode = class(tbinarynode)
  260. constructor create(tt : tnodetype;l,r : tnode);virtual;
  261. function docompare(p : tnode) : boolean;override;
  262. end;
  263. {$ifdef EXTDEBUG}
  264. var
  265. writenodeindention : string;
  266. procedure writenode(t:tnode);
  267. {$endif EXTDEBUG}
  268. {
  269. $Log$
  270. Revision 1.13 2000-10-14 21:52:55 peter
  271. * fixed memory leaks
  272. Revision 1.12 2000/10/14 10:14:51 peter
  273. * moehrendorf oct 2000 rewrite
  274. Revision 1.11 2000/10/01 19:48:24 peter
  275. * lot of compile updates for cg11
  276. Revision 1.10 2000/09/28 19:49:52 florian
  277. *** empty log message ***
  278. Revision 1.9 2000/09/27 18:14:31 florian
  279. * fixed a lot of syntax errors in the n*.pas stuff
  280. Revision 1.8 2000/09/26 20:06:13 florian
  281. * hmm, still a lot of work to get things compilable
  282. Revision 1.7 2000/09/26 14:59:34 florian
  283. * more conversion work done
  284. Revision 1.6 2000/09/25 15:37:14 florian
  285. * more fixes
  286. Revision 1.5 2000/09/25 15:05:25 florian
  287. * some updates
  288. Revision 1.4 2000/09/24 21:15:34 florian
  289. * some errors fix to get more stuff compilable
  290. Revision 1.3 2000/09/22 21:45:36 florian
  291. * some updates e.g. getcopy added
  292. Revision 1.2 2000/09/20 21:52:38 florian
  293. * removed a lot of errors
  294. Revision 1.1 2000/08/26 12:27:04 florian
  295. * initial release
  296. }