nodeh.inc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. tconverttype = (
  106. tc_equal,
  107. tc_not_possible,
  108. tc_string_2_string,
  109. tc_char_2_string,
  110. tc_pchar_2_string,
  111. tc_cchar_2_pchar,
  112. tc_cstring_2_pchar,
  113. tc_ansistring_2_pchar,
  114. tc_string_2_chararray,
  115. tc_chararray_2_string,
  116. tc_array_2_pointer,
  117. tc_pointer_2_array,
  118. tc_int_2_int,
  119. tc_int_2_bool,
  120. tc_bool_2_bool,
  121. tc_bool_2_int,
  122. tc_real_2_real,
  123. tc_int_2_real,
  124. tc_int_2_fix,
  125. tc_real_2_fix,
  126. tc_fix_2_real,
  127. tc_proc_2_procvar,
  128. tc_arrayconstructor_2_set,
  129. tc_load_smallset,
  130. tc_cord_2_pointer
  131. );
  132. { allows to determine which elementes are to be replaced }
  133. tdisposetyp = (dt_nothing,dt_leftright,dt_left,dt_leftrighthigh,
  134. dt_mbleft,dt_typeconv,dt_inlinen,dt_leftrightmethod,
  135. dt_mbleft_and_method,dt_loop,dt_case,dt_with,dt_onn,
  136. dt_leftrightframe);
  137. { different assignment types }
  138. tassigntyp = (at_normal,at_plus,at_minus,at_star,at_slash);
  139. pcaserecord = ^tcaserecord;
  140. tcaserecord = record
  141. { range }
  142. _low,_high : longint;
  143. { only used by gentreejmp }
  144. _at : pasmlabel;
  145. { label of instruction }
  146. statement : pasmlabel;
  147. { is this the first of an case entry, needed to release statement
  148. label (PFV) }
  149. firstlabel : boolean;
  150. { left and right tree node }
  151. less,greater : pcaserecord;
  152. end;
  153. { this will be used mainly for the newcg }
  154. tnodeflags = (
  155. nf_needs_truefalselabel,
  156. nf_callunique,
  157. nf_swapable, { tbinop operands can be swaped }
  158. nf_swaped, { tbinop operands are swaped }
  159. nf_error
  160. );
  161. tnodeflagset = set of tnodeflags;
  162. const
  163. { contains the flags which must be equal for the equality }
  164. { of nodes }
  165. flagsequal : tnodeflagset = [nf_error];
  166. type
  167. { later (for the newcg) tnode will inherit from tlinkedlist_item }
  168. tnode = class
  169. nodetype : tnodetype;
  170. { the location of the result of this node }
  171. location : tlocation;
  172. { do we need to parse childs to set var state }
  173. varstateset : boolean;
  174. { the parent node of this is node }
  175. { this field is set by concattolist }
  176. parent : pnode;
  177. { there are some properties about the node stored }
  178. flags : tnodeflagset;
  179. { the number of registers needed to evalute the node }
  180. registersint,registersfpu : longint; { must be longint !!!! }
  181. {$ifdef SUPPORT_MMX}
  182. registersmmx,registerskni : longint;
  183. {$endif SUPPORT_MMX}
  184. resulttype : pdef;
  185. fileinfo : tfileposinfo;
  186. localswitches : tlocalswitches;
  187. {$ifdef extdebug}
  188. firstpasscount : longint;
  189. {$endif extdebug}
  190. list : paasmoutput;
  191. constructor init(tt : tnodetype);virtual;
  192. destructor done;virtual;
  193. { the 1.1 code generator may override pass_1 }
  194. { and it need not to implement det_* then }
  195. { 1.1: pass_1 returns a value<>0 if the node has been transformed }
  196. { 2.0: runs det_resulttype and det_temp }
  197. function pass_1 : tnode;virtual;
  198. { dermines the resulttype of the node }
  199. procedure det_resulttype;virtual;
  200. { dermines the number of necessary temp. locations to evaluate
  201. the node }
  202. procedure det_temp;virtual;
  203. procedure secondpass;virtual;
  204. { comparing of nodes }
  205. function isequal(p : tnode) : boolean;
  206. { to implement comparisation, override this method }
  207. function docompare(p : tnode) : boolean;virtual;
  208. {$ifdef EXTDEBUG}
  209. { writes a node for debugging purpose, shouldn't be called }
  210. { direct, because there is no test for nil, use writenode }
  211. { to write a complete tree }
  212. procedure dowrite;virtual;
  213. {$endif EXTDEBUG}
  214. procedure concattolist(l : plinkedlist);virtual;
  215. function ischild(p : tnode) : boolean;virtual;
  216. end;
  217. { this node is the anchestor for all nodes with at least }
  218. { one child, you have to use it if you want to use }
  219. { true- and falselabel }
  220. tparentnode = class(tnode);
  221. falselabel,truelabel : plabel;
  222. end;
  223. punarynode = ^tunarynode;
  224. tunarynode = class(tparentnode)
  225. left : tnode;
  226. {$ifdef extdebug}
  227. procedure dowrite;virtual;
  228. {$endif extdebug}
  229. constructor init(tt : tnodetype;l : tnode);virtual
  230. procedure concattolist(l : plinkedlist);virtual;
  231. function ischild(p : tnode) : boolean;virtual;
  232. procedure det_resulttype;virtual;
  233. procedure det_temp;virtual;
  234. end;
  235. pbinarynode = ^tbinarynode;
  236. tbinarynode = class(tunarynode)
  237. right : tnode;
  238. constructor init(tt : tnodetype;l,r : pnode);virtual;
  239. procedure concattolist(l : plinkedlist);virtual;
  240. function ischild(p : pnode) : boolean;virtual;
  241. procedure det_resulttype;virtual;
  242. procedure det_temp;virtual;
  243. end;
  244. pbinopnode = ^tbinopnode;
  245. tbinopnode = class(tbinarynode)
  246. constructor init(tt : tnodetype;l,r : pnode);virtual;
  247. end;
  248. {
  249. $Log$
  250. Revision 1.1 2000-08-26 12:27:04 florian
  251. * initial release
  252. }