nodeh.inc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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. arrayconstructn, {Construction node for [...] parsing}
  100. arrayconstructrangen, {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 tcallparanode }
  117. nf_exact_match_found,
  118. nf_convlevel1found,
  119. nf_convlevel2found,
  120. nf_is_colon_para,
  121. { flags used by loop nodes }
  122. nf_backward, { set if it is a for ... downto ... do loop }
  123. nf_varstate, { do we need to parse childs to set var state }
  124. { taddrnode }
  125. nf_procvarload,
  126. { tvecnode }
  127. nf_memindex,
  128. nf_memseg,
  129. nf_callunique,
  130. { twithnode }
  131. nf_islocal,
  132. { tloadnode }
  133. nf_absolute, { 20th }
  134. nf_first,
  135. { tassignmentnode }
  136. nf_concat_string,
  137. { tfuncretnode }
  138. nf_is_first_funcret,
  139. { tarrayconstructnode }
  140. nf_cargs,
  141. nf_cargswap,
  142. nf_forcevaria,
  143. nf_novariaallowed,
  144. { ttypeconvnode }
  145. nf_explizit,
  146. { tinlinenode }
  147. nf_inlineconst,
  148. { general }
  149. nf_isproperty, { 30th }
  150. nf_varstateset
  151. );
  152. tnodeflagset = set of tnodeflags;
  153. const
  154. { contains the flags which must be equal for the equality }
  155. { of nodes }
  156. flagsequal : tnodeflagset = [nf_error,nf_static_call,nf_backward];
  157. type
  158. { later (for the newcg) tnode will inherit from tlinkedlist_item }
  159. tnode = class
  160. nodetype : tnodetype;
  161. { the location of the result of this node }
  162. location : tlocation;
  163. { the parent node of this is node }
  164. { this field is set by concattolist }
  165. parent : tnode;
  166. { there are some properties about the node stored }
  167. flags : tnodeflagset;
  168. { the number of registers needed to evalute the node }
  169. registers32,registersfpu : longint; { must be longint !!!! }
  170. {$ifdef SUPPORT_MMX}
  171. registersmmx,registerskni : longint;
  172. {$endif SUPPORT_MMX}
  173. resulttype : pdef;
  174. fileinfo : tfileposinfo;
  175. localswitches : tlocalswitches;
  176. {$ifdef extdebug}
  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;virtual;
  185. { the 1.1 code generator may override pass_1 }
  186. { and it need not to implement det_* then }
  187. { 1.1: pass_1 returns a value<>0 if the node has been transformed }
  188. { 2.0: runs det_resulttype and det_temp }
  189. function pass_1 : tnode;virtual;
  190. { dermines the resulttype of the node }
  191. procedure det_resulttype;virtual;abstract;
  192. { dermines the number of necessary temp. locations to evaluate
  193. the node }
  194. procedure det_temp;virtual;abstract;
  195. procedure pass_2;virtual;abstract;
  196. { comparing of nodes }
  197. function isequal(p : tnode) : boolean;
  198. { to implement comparisation, override this method }
  199. function docompare(p : tnode) : boolean;virtual;
  200. { gets a copy of the node }
  201. function getcopy : tnode;virtual;
  202. {$ifdef EXTDEBUG}
  203. { writes a node for debugging purpose, shouldn't be called }
  204. { direct, because there is no test for nil, use writenode }
  205. { to write a complete tree }
  206. procedure dowrite;virtual;
  207. {$endif EXTDEBUG}
  208. procedure concattolist(l : plinkedlist);virtual;
  209. function ischild(p : tnode) : boolean;virtual;
  210. procedure set_file_line(from : tnode);
  211. procedure set_tree_filepos(const filepos : tfileposinfo);
  212. end;
  213. { this node is the anchestor for all nodes with at least }
  214. { one child, you have to use it if you want to use }
  215. { true- and falselabel }
  216. tparentnode = class(tnode)
  217. falselabel,truelabel : pasmlabel;
  218. end;
  219. punarynode = ^tunarynode;
  220. tunarynode = class(tparentnode)
  221. left : tnode;
  222. {$ifdef extdebug}
  223. procedure dowrite;override;
  224. {$endif extdebug}
  225. constructor create(tt : tnodetype;l : tnode);
  226. procedure concattolist(l : plinkedlist);override;
  227. function ischild(p : tnode) : boolean;override;
  228. procedure det_resulttype;override;
  229. procedure det_temp;override;
  230. function docompare(p : tnode) : boolean;override;
  231. function getcopy : tnode;override;
  232. procedure left_max;
  233. end;
  234. pbinarynode = ^tbinarynode;
  235. tbinarynode = class(tunarynode)
  236. right : tnode;
  237. constructor create(tt : tnodetype;l,r : tnode);
  238. procedure concattolist(l : plinkedlist);override;
  239. function ischild(p : tnode) : boolean;override;
  240. procedure det_resulttype;override;
  241. procedure det_temp;override;
  242. function docompare(p : tnode) : boolean;override;
  243. procedure swapleftright;
  244. function getcopy : tnode;override;
  245. procedure left_right_max;
  246. end;
  247. pbinopnode = ^tbinopnode;
  248. tbinopnode = class(tbinarynode)
  249. constructor create(tt : tnodetype;l,r : tnode);virtual;
  250. function docompare(p : tnode) : boolean;override;
  251. end;
  252. {
  253. $Log$
  254. Revision 1.11 2000-10-01 19:48:24 peter
  255. * lot of compile updates for cg11
  256. Revision 1.10 2000/09/28 19:49:52 florian
  257. *** empty log message ***
  258. Revision 1.9 2000/09/27 18:14:31 florian
  259. * fixed a lot of syntax errors in the n*.pas stuff
  260. Revision 1.8 2000/09/26 20:06:13 florian
  261. * hmm, still a lot of work to get things compilable
  262. Revision 1.7 2000/09/26 14:59:34 florian
  263. * more conversion work done
  264. Revision 1.6 2000/09/25 15:37:14 florian
  265. * more fixes
  266. Revision 1.5 2000/09/25 15:05:25 florian
  267. * some updates
  268. Revision 1.4 2000/09/24 21:15:34 florian
  269. * some errors fix to get more stuff compilable
  270. Revision 1.3 2000/09/22 21:45:36 florian
  271. * some updates e.g. getcopy added
  272. Revision 1.2 2000/09/20 21:52:38 florian
  273. * removed a lot of errors
  274. Revision 1.1 2000/08/26 12:27:04 florian
  275. * initial release
  276. }