nodeh.inc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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. pcaserecord = ^tcaserecord;
  133. tcaserecord = record
  134. { range }
  135. _low,_high : longint;
  136. { only used by gentreejmp }
  137. _at : pasmlabel;
  138. { label of instruction }
  139. statement : pasmlabel;
  140. { is this the first of an case entry, needed to release statement
  141. label (PFV) }
  142. firstlabel : boolean;
  143. { left and right tree node }
  144. less,greater : pcaserecord;
  145. end;
  146. { all boolean field of ttree are now collected in flags }
  147. tnodeflags = (
  148. nf_needs_truefalselabel,
  149. nf_swapable, { tbinop operands can be swaped }
  150. nf_swaped, { tbinop operands are swaped }
  151. nf_error,
  152. { flags used by tcallnode }
  153. nf_no_check,
  154. nf_unit_specific,
  155. nf_return_value_used,
  156. nf_static_call,
  157. { flags used by tcallparanode }
  158. nf_exact_match_found,
  159. nf_convlevel1found,
  160. nf_convlevel2found,
  161. nf_is_colon_para,
  162. { flags used by loop nodes }
  163. nf_backward, { set if it is a for ... downto ... do loop }
  164. nf_varstate, { do we need to parse childs to set var state }
  165. { taddrnode }
  166. nf_procvarload,
  167. { tvecnode }
  168. nf_memindex,
  169. nf_memseg,
  170. nf_callunique,
  171. { twithnode }
  172. nf_islocal,
  173. { tloadnode }
  174. nf_absolute, { 20th }
  175. nf_first,
  176. { tassignmentnode }
  177. nf_concat_string,
  178. { tfuncretnode }
  179. nf_is_first_funcret,
  180. { tarrayconstructnode }
  181. nf_cargs,
  182. nf_cargswap,
  183. nf_forcevaria,
  184. nf_novariaallowed,
  185. { ttypeconvnode }
  186. nf_explizit,
  187. { tinlinenode }
  188. nf_inlineconst,
  189. { general }
  190. nf_isproperty, { 30th }
  191. nf_varstateset
  192. );
  193. tnodeflagset = set of tnodeflags;
  194. const
  195. { contains the flags which must be equal for the equality }
  196. { of nodes }
  197. flagsequal : tnodeflagset = [nf_error,nf_static_call,nf_backward];
  198. type
  199. { later (for the newcg) tnode will inherit from tlinkedlist_item }
  200. tnode = class
  201. nodetype : tnodetype;
  202. { the location of the result of this node }
  203. location : tlocation;
  204. { the parent node of this is node }
  205. { this field is set by concattolist }
  206. parent : tnode;
  207. { there are some properties about the node stored }
  208. flags : tnodeflagset;
  209. { the number of registers needed to evalute the node }
  210. registers32,registersfpu : longint; { must be longint !!!! }
  211. {$ifdef SUPPORT_MMX}
  212. registersmmx,registerskni : longint;
  213. {$endif SUPPORT_MMX}
  214. resulttype : pdef;
  215. fileinfo : tfileposinfo;
  216. localswitches : tlocalswitches;
  217. {$ifdef extdebug}
  218. firstpasscount : longint;
  219. {$endif extdebug}
  220. list : paasmoutput;
  221. constructor create(tt : tnodetype);
  222. { this constructor is only for creating copies of class }
  223. { the fields are copied by getcopy }
  224. constructor createforcopy;
  225. destructor destroy;virtual;
  226. { the 1.1 code generator may override pass_1 }
  227. { and it need not to implement det_* then }
  228. { 1.1: pass_1 returns a value<>0 if the node has been transformed }
  229. { 2.0: runs det_resulttype and det_temp }
  230. function pass_1 : tnode;virtual;
  231. { dermines the resulttype of the node }
  232. procedure det_resulttype;virtual;abstract;
  233. { dermines the number of necessary temp. locations to evaluate
  234. the node }
  235. procedure det_temp;virtual;abstract;
  236. procedure pass_2;virtual;abstract;
  237. { comparing of nodes }
  238. function isequal(p : tnode) : boolean;
  239. { to implement comparisation, override this method }
  240. function docompare(p : tnode) : boolean;virtual;
  241. { gets a copy of the node }
  242. function getcopy : tnode;virtual;
  243. procedure unset_varstate;virtual;
  244. procedure set_varstate(must_be_valid : boolean);virtual;
  245. { it would be cleaner to make the following virtual methods }
  246. { but this would require an extra vmt entry }
  247. { so we do some hacking instead .... }
  248. procedure set_unique;
  249. procedure set_funcret_is_valid;
  250. {$ifdef EXTDEBUG}
  251. { writes a node for debugging purpose, shouldn't be called }
  252. { direct, because there is no test for nil, use writenode }
  253. { to write a complete tree }
  254. procedure dowrite;virtual;
  255. {$endif EXTDEBUG}
  256. procedure concattolist(l : plinkedlist);virtual;
  257. function ischild(p : tnode) : boolean;virtual;
  258. procedure set_file_line(from : tnode);
  259. procedure set_tree_filepos(const filepos : tfileposinfo);
  260. end;
  261. { this node is the anchestor for all nodes with at least }
  262. { one child, you have to use it if you want to use }
  263. { true- and falselabel }
  264. tparentnode = class(tnode)
  265. falselabel,truelabel : pasmlabel;
  266. end;
  267. punarynode = ^tunarynode;
  268. tunarynode = class(tparentnode)
  269. left : tnode;
  270. {$ifdef extdebug}
  271. procedure dowrite;override;
  272. {$endif extdebug}
  273. constructor create(tt : tnodetype;l : tnode);
  274. procedure concattolist(l : plinkedlist);override;
  275. function ischild(p : tnode) : boolean;override;
  276. procedure det_resulttype;override;
  277. procedure det_temp;override;
  278. function docompare(p : tnode) : boolean;override;
  279. function getcopy : tnode;override;
  280. procedure left_max;
  281. end;
  282. pbinarynode = ^tbinarynode;
  283. tbinarynode = class(tunarynode)
  284. right : tnode;
  285. constructor create(tt : tnodetype;l,r : tnode);
  286. procedure concattolist(l : plinkedlist);override;
  287. function ischild(p : tnode) : boolean;override;
  288. procedure det_resulttype;override;
  289. procedure det_temp;override;
  290. function docompare(p : tnode) : boolean;override;
  291. procedure swapleftright;
  292. function isbinaryoverloaded(var t : tnode) : boolean;
  293. function getcopy : tnode;override;
  294. procedure left_right_max;
  295. end;
  296. pbinopnode = ^tbinopnode;
  297. tbinopnode = class(tbinarynode)
  298. constructor create(tt : tnodetype;l,r : tnode);virtual;
  299. function docompare(p : tnode) : boolean;override;
  300. end;
  301. {
  302. $Log$
  303. Revision 1.10 2000-09-28 19:49:52 florian
  304. *** empty log message ***
  305. Revision 1.9 2000/09/27 18:14:31 florian
  306. * fixed a lot of syntax errors in the n*.pas stuff
  307. Revision 1.8 2000/09/26 20:06:13 florian
  308. * hmm, still a lot of work to get things compilable
  309. Revision 1.7 2000/09/26 14:59:34 florian
  310. * more conversion work done
  311. Revision 1.6 2000/09/25 15:37:14 florian
  312. * more fixes
  313. Revision 1.5 2000/09/25 15:05:25 florian
  314. * some updates
  315. Revision 1.4 2000/09/24 21:15:34 florian
  316. * some errors fix to get more stuff compilable
  317. Revision 1.3 2000/09/22 21:45:36 florian
  318. * some updates e.g. getcopy added
  319. Revision 1.2 2000/09/20 21:52:38 florian
  320. * removed a lot of errors
  321. Revision 1.1 2000/08/26 12:27:04 florian
  322. * initial release
  323. }