tree.pas 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752
  1. {
  2. $Id$
  3. Copyright (c) 1993-98 by Florian Klaempfl
  4. This units exports some routines to manage the parse tree
  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. {$ifdef tp}
  19. {$E+,N+}
  20. {$endif}
  21. unit tree;
  22. interface
  23. uses
  24. cobjects,globals,symtable,aasm
  25. {$ifdef i386}
  26. ,i386
  27. {$endif}
  28. {$ifdef m68k}
  29. ,m68k
  30. {$endif}
  31. {$ifdef alpha}
  32. ,alpha
  33. {$endif}
  34. ;
  35. type
  36. pconstset = ^tconstset;
  37. tconstset = array[0..31] of byte;
  38. ttreetyp = (addn, {Represents the + operator.}
  39. muln, {Represents the * operator.}
  40. subn, {Represents the - operator.}
  41. divn, {Represents the div operator.}
  42. symdifn, {Represents the >< operator.}
  43. modn, {Represents the mod operator.}
  44. assignn, {Represents an assignment.}
  45. loadn, {Represents the use of a variabele.}
  46. rangen, {Represents a range (i.e. 0..9).}
  47. ltn, {Represents the < operator.}
  48. lten, {Represents the <= operator.}
  49. gtn, {Represents the > operator.}
  50. gten, {Represents the >= operator.}
  51. equaln, {Represents the = operator.}
  52. unequaln, {Represents the <> operator.}
  53. inn, {Represents the in operator.}
  54. orn, {Represents the or operator.}
  55. xorn, {Represents the xor operator.}
  56. shrn, {Represents the shr operator.}
  57. shln, {Represents the shl operator.}
  58. slashn, {Represents the / operator.}
  59. andn, {Represents the and operator.}
  60. subscriptn, {??? Field in a record/object?}
  61. derefn, {Dereferences a pointer.}
  62. addrn, {Represents the @ operator.}
  63. doubleaddrn, {Represents the @@ operator.}
  64. ordconstn, {Represents an ordinal value.}
  65. typeconvn, {Represents type-conversion/typecast.}
  66. calln, {Represents a call node.}
  67. callparan, {Represents a parameter.}
  68. realconstn, {Represents a real value.}
  69. fixconstn, {Represents a fixed value.}
  70. umminusn, {Represents a sign change (i.e. -2).}
  71. asmn, {Represents an assembler node }
  72. vecn, {Represents array indexing.}
  73. stringconstn, {Represents a string constant.}
  74. funcretn, {Represents the function result var.}
  75. selfn, {Represents the self parameter.}
  76. notn, {Represents the not operator.}
  77. inlinen, {Internal procedures (i.e. writeln).}
  78. niln, {Represents the nil pointer.}
  79. errorn, {This part of the tree could not be
  80. parsed because of a compiler error.}
  81. typen, {A type name. Used for i.e. typeof(obj).}
  82. hnewn, {The new operation, constructor call.}
  83. hdisposen, {The dispose operation with destructor call.}
  84. newn, {The new operation, constructor call.}
  85. simpledisposen, {The dispose operation.}
  86. setelementn, {A set element(s) (i.e. [a,b] and also [a..b]).}
  87. setconstn, {A set constant (i.e. [1,2]).}
  88. blockn, {A block of statements.}
  89. statementn, {One statement in a block of nodes.}
  90. loopn, { used in genloopnode, must be converted }
  91. ifn, {An if statement.}
  92. breakn, {A break statement.}
  93. continuen, {A continue statement.}
  94. repeatn, {A repeat until block.}
  95. whilen, {A while do statement.}
  96. forn, {A for loop.}
  97. exitn, {An exit statement.}
  98. withn, {A with statement.}
  99. casen, {A case statement.}
  100. labeln, {A label.}
  101. goton, {A goto statement.}
  102. simplenewn, {The new operation.}
  103. tryexceptn, {A try except block.}
  104. raisen, {A raise statement.}
  105. switchesn, {??? Currently unused...}
  106. tryfinallyn, {A try finally statement.}
  107. onn, { for an on statement in exception code }
  108. isn, {Represents the is operator.}
  109. asn, {Represents the as typecast.}
  110. caretn, {Represents the ^ operator.}
  111. failn, {Represents the fail statement.}
  112. starstarn, {Represents the ** operator exponentiation }
  113. procinlinen, {Procedures that can be inlined }
  114. arrayconstructn, {Construction node for [...] parsing}
  115. arrayconstructrangen, {Range element to allow sets in array construction tree}
  116. { added for optimizations where we cannot suppress }
  117. nothingn,
  118. loadvmtn); {???.}
  119. tconverttype = (tc_equal,tc_not_possible,tc_u8bit_2_s32bit,
  120. tc_only_rangechecks32bit,tc_s8bit_2_s32bit,
  121. tc_u16bit_2_s32bit,tc_s16bit_2_s32bit,
  122. tc_s32bit_2_s16bit,tc_s32bit_2_u8bit,
  123. tc_s32bit_2_u16bit,tc_string_to_string,
  124. tc_cstring_charpointer,tc_string_chararray,
  125. tc_array_to_pointer,tc_pointer_to_array,
  126. tc_char_to_string,tc_u8bit_2_s16bit,
  127. tc_u8bit_2_u16bit,tc_s8bit_2_s16bit,
  128. tc_s16bit_2_s8bit,tc_s16bit_2_u8bit,
  129. tc_u16bit_2_s8bit,tc_u16bit_2_u8bit,
  130. tc_s8bit_2_u16bit,tc_s32bit_2_s8bit,
  131. tc_s32bit_2_u32bit,tc_s16bit_2_u32bit,
  132. tc_s8bit_2_u32bit,tc_u16bit_2_u32bit,
  133. tc_u8bit_2_u32bit,tc_u32bit_2_s32bit,
  134. tc_u32bit_2_s8bit,tc_u32bit_2_u8bit,
  135. tc_u32bit_2_s16bit,tc_u32bit_2_u16bit,
  136. tc_bool_2_int,tc_int_2_bool,
  137. tc_int_2_real,tc_real_2_fix,
  138. tc_fix_2_real,tc_int_2_fix,tc_real_2_real,
  139. tc_chararray_2_string,
  140. tc_proc2procvar,tc_cchar_charpointer,tc_load_smallset,
  141. tc_ansistring_2_pchar,tc_pchar_2_string);
  142. { allows to determine which elementes are to be replaced }
  143. tdisposetyp = (dt_nothing,dt_leftright,dt_left,
  144. dt_mbleft,dt_typeconv,dt_inlinen,
  145. dt_mbleft_and_method,dt_loop,dt_case,dt_with,dt_onn);
  146. { different assignment types }
  147. tassigntyp = (at_normal,at_plus,at_minus,at_star,at_slash);
  148. pcaserecord = ^tcaserecord;
  149. tcaserecord = record
  150. { range }
  151. _low,_high : longint;
  152. { only used by gentreejmp }
  153. _at : plabel;
  154. { label of instruction }
  155. statement : plabel;
  156. { left and right tree node }
  157. less,greater : pcaserecord;
  158. end;
  159. ptree = ^ttree;
  160. ttree = record
  161. error : boolean;
  162. disposetyp : tdisposetyp;
  163. { is true, if the right and left operand are swaped }
  164. swaped : boolean;
  165. { the location of the result of this node }
  166. location : tlocation;
  167. { the number of registers needed to evalute the node }
  168. registers32,registersfpu : longint; { must be longint !!!! }
  169. {$ifdef SUPPORT_MMX}
  170. registersmmx : longint;
  171. {$endif SUPPORT_MMX}
  172. left,right : ptree;
  173. resulttype : pdef;
  174. fileinfo : tfileposinfo;
  175. localswitches : tlocalswitches;
  176. {$ifdef extdebug}
  177. firstpasscount : longint;
  178. {$endif extdebug}
  179. case treetype : ttreetyp of
  180. addn : (use_strconcat : boolean;string_typ : tstringtype);
  181. callparan : (is_colon_para : boolean;exact_match_found : boolean);
  182. assignn : (assigntyp : tassigntyp;concat_string : boolean);
  183. loadn : (symtableentry : psym;symtable : psymtable;
  184. is_absolute,is_first : boolean);
  185. calln : (symtableprocentry : psym;
  186. symtableproc : psymtable;procdefinition : pprocdef;
  187. methodpointer : ptree;
  188. no_check,unit_specific,return_value_used : boolean);
  189. ordconstn : (value : longint);
  190. realconstn : (value_real : bestreal;lab_real : plabel;realtyp : tait);
  191. fixconstn : (value_fix: longint);
  192. funcretn : (funcretprocinfo : pointer;retdef : pdef);
  193. subscriptn : (vs : pvarsym);
  194. vecn : (memindex,memseg:boolean);
  195. {$ifdef UseAnsiString}
  196. stringconstn : (value_str : pchar;length : longint; lab_str : plabel;stringtype : tstringtype);
  197. {$else UseAnsiString}
  198. stringconstn : (value_str : pstring; lab_str:plabel;stringtype : tstringtype);
  199. {$endif UseAnsiString}
  200. typeconvn : (convtyp : tconverttype;explizit : boolean);
  201. inlinen : (inlinenumber : longint;inlineconst:boolean);
  202. procinlinen : (inlineprocdef : pprocdef;
  203. retoffset,para_offset,para_size : longint);
  204. setconstn : (value_set : pconstset;lab_set:plabel);
  205. loopn : (t1,t2 : ptree;backward : boolean);
  206. asmn : (p_asm : paasmoutput;object_preserved : boolean);
  207. casen : (nodes : pcaserecord;elseblock : ptree);
  208. labeln,goton : (labelnr : plabel);
  209. withn : (withsymtable : psymtable;tablecount : longint);
  210. onn : (exceptsymtable : psymtable;excepttype : pobjectdef);
  211. end;
  212. function gennode(t : ttreetyp;l,r : ptree) : ptree;
  213. function genlabelnode(t : ttreetyp;nr : plabel) : ptree;
  214. function genloadnode(v : pvarsym;st : psymtable) : ptree;
  215. function genloadcallnode(v: pprocsym;st: psymtable): ptree;
  216. function gensinglenode(t : ttreetyp;l : ptree) : ptree;
  217. function gensubscriptnode(varsym : pvarsym;l : ptree) : ptree;
  218. function genordinalconstnode(v : longint;def : pdef) : ptree;
  219. function genfixconstnode(v : longint;def : pdef) : ptree;
  220. function gentypeconvnode(node : ptree;t : pdef) : ptree;
  221. function gencallparanode(expr,next : ptree) : ptree;
  222. function genrealconstnode(v : bestreal) : ptree;
  223. function gencallnode(v : pprocsym;st : psymtable) : ptree;
  224. function genmethodcallnode(v : pprocsym;st : psymtable;mp : ptree) : ptree;
  225. { allow pchar or string for defining a pchar node }
  226. function genstringconstnode(const s : string) : ptree;
  227. {$ifdef UseAnsiString}
  228. { length is required for ansistrings }
  229. function genpcharconstnode(s : pchar;length : longint) : ptree;
  230. { helper routine for conststring node }
  231. function getpcharcopy(p : ptree) : pchar;
  232. {$endif UseAnsiString}
  233. function genzeronode(t : ttreetyp) : ptree;
  234. function geninlinenode(number : longint;is_const:boolean;l : ptree) : ptree;
  235. function genprocinlinenode(callp,code : ptree) : ptree;
  236. function gentypedconstloadnode(sym : ptypedconstsym;st : psymtable) : ptree;
  237. function genenumnode(v : penumsym) : ptree;
  238. function genselfnode(_class : pdef) : ptree;
  239. function gensetconstnode(s : pconstset;settype : psetdef) : ptree;
  240. function genloopnode(t : ttreetyp;l,r,n1: ptree;back : boolean) : ptree;
  241. function genasmnode(p_asm : paasmoutput) : ptree;
  242. function gencasenode(l,r : ptree;nodes : pcaserecord) : ptree;
  243. function genwithnode(symtable : psymtable;l,r : ptree;count : longint) : ptree;
  244. function getcopy(p : ptree) : ptree;
  245. function equal_trees(t1,t2 : ptree) : boolean;
  246. procedure swaptree(p:Ptree);
  247. procedure disposetree(p : ptree);
  248. procedure putnode(p : ptree);
  249. function getnode : ptree;
  250. procedure set_location(var destloc,sourceloc : tlocation);
  251. procedure swap_location(var destloc,sourceloc : tlocation);
  252. procedure set_file_line(from,_to : ptree);
  253. procedure set_tree_filepos(p : ptree;const filepos : tfileposinfo);
  254. {$ifdef extdebug}
  255. procedure compare_trees(oldp,p : ptree);
  256. const
  257. maxfirstpasscount : longint = 0;
  258. {$endif extdebug}
  259. { gibt den ordinalen Werten der Node zurueck oder falls sie }
  260. { keinen ordinalen Wert hat, wird ein Fehler erzeugt }
  261. function get_ordinal_value(p : ptree) : longint;
  262. function is_constnode(p : ptree) : boolean;
  263. { true, if p is a pointer to a const int value }
  264. function is_constintnode(p : ptree) : boolean;
  265. function is_constboolnode(p : ptree) : boolean;
  266. function is_constrealnode(p : ptree) : boolean;
  267. function is_constcharnode(p : ptree) : boolean;
  268. {$I innr.inc}
  269. implementation
  270. uses
  271. { $ifdef extdebug}
  272. types,
  273. { $endif extdebug}
  274. verbose,files;
  275. function getnode : ptree;
  276. var
  277. hp : ptree;
  278. begin
  279. new(hp);
  280. { makes error tracking easier }
  281. fillchar(hp^,sizeof(ttree),0);
  282. { reset }
  283. hp^.location.loc:=LOC_INVALID;
  284. { save local info }
  285. hp^.fileinfo:=aktfilepos;
  286. hp^.localswitches:=aktlocalswitches;
  287. getnode:=hp;
  288. end;
  289. procedure putnode(p : ptree);
  290. begin
  291. { clean up the contents of a node }
  292. case p^.treetype of
  293. asmn : if assigned(p^.p_asm) then
  294. dispose(p^.p_asm,done);
  295. stringconstn : begin
  296. {$ifndef UseAnsiString}
  297. stringdispose(p^.value_str);
  298. {$else UseAnsiString}
  299. ansistringdispose(p^.value_str,p^.length);
  300. {$endif UseAnsiString}
  301. end;
  302. setconstn : begin
  303. if assigned(p^.value_set) then
  304. dispose(p^.value_set);
  305. end;
  306. end;
  307. { reference info }
  308. if (p^.location.loc in [LOC_MEM,LOC_REFERENCE]) and
  309. assigned(p^.location.reference.symbol) then
  310. stringdispose(p^.location.reference.symbol);
  311. {$ifdef extdebug}
  312. if p^.firstpasscount>maxfirstpasscount then
  313. maxfirstpasscount:=p^.firstpasscount;
  314. {$endif extdebug}
  315. dispose(p);
  316. end;
  317. function getcopy(p : ptree) : ptree;
  318. var
  319. hp : ptree;
  320. begin
  321. hp:=getnode;
  322. hp^:=p^;
  323. if assigned(p^.location.reference.symbol) then
  324. hp^.location.reference.symbol:=stringdup(p^.location.reference.symbol^);
  325. case p^.disposetyp of
  326. dt_leftright :
  327. begin
  328. if assigned(p^.left) then
  329. hp^.left:=getcopy(p^.left);
  330. if assigned(p^.right) then
  331. hp^.right:=getcopy(p^.right);
  332. end;
  333. dt_nothing : ;
  334. dt_left :
  335. if assigned(p^.left) then
  336. hp^.left:=getcopy(p^.left);
  337. dt_mbleft :
  338. if assigned(p^.left) then
  339. hp^.left:=getcopy(p^.left);
  340. dt_mbleft_and_method :
  341. begin
  342. if assigned(p^.left) then
  343. hp^.left:=getcopy(p^.left);
  344. hp^.methodpointer:=getcopy(p^.methodpointer);
  345. end;
  346. dt_loop :
  347. begin
  348. if assigned(p^.left) then
  349. hp^.left:=getcopy(p^.left);
  350. if assigned(p^.right) then
  351. hp^.right:=getcopy(p^.right);
  352. if assigned(p^.t1) then
  353. hp^.t1:=getcopy(p^.t1);
  354. if assigned(p^.t2) then
  355. hp^.t2:=getcopy(p^.t2);
  356. end;
  357. dt_typeconv : hp^.left:=getcopy(p^.left);
  358. dt_inlinen :
  359. if assigned(p^.left) then
  360. hp^.left:=getcopy(p^.left);
  361. else internalerror(11);
  362. end;
  363. { now check treetype }
  364. case p^.treetype of
  365. stringconstn : begin
  366. {$ifdef UseAnsiString}
  367. hp^.value_str:=getpcharcopy(p);
  368. hp^.length:=p^.length;
  369. {$else UseAnsiString}
  370. hp^.value_str:=stringdup(p^.value_str^);
  371. {$endif UseAnsiString}
  372. end;
  373. setconstn : begin
  374. new(hp^.value_set);
  375. hp^.value_set:=p^.value_set;
  376. end;
  377. end;
  378. getcopy:=hp;
  379. end;
  380. procedure deletecaselabels(p : pcaserecord);
  381. begin
  382. if assigned(p^.greater) then
  383. deletecaselabels(p^.greater);
  384. if assigned(p^.less) then
  385. deletecaselabels(p^.less);
  386. dispose(p);
  387. end;
  388. procedure swaptree(p:Ptree);
  389. var swapp:Ptree;
  390. begin
  391. swapp:=p^.right;
  392. p^.right:=p^.left;
  393. p^.left:=swapp;
  394. p^.swaped:=not(p^.swaped);
  395. end;
  396. procedure disposetree(p : ptree);
  397. begin
  398. if not(assigned(p)) then
  399. exit;
  400. case p^.disposetyp of
  401. dt_leftright :
  402. begin
  403. if assigned(p^.left) then
  404. disposetree(p^.left);
  405. if assigned(p^.right) then
  406. disposetree(p^.right);
  407. end;
  408. dt_case :
  409. begin
  410. if assigned(p^.left) then
  411. disposetree(p^.left);
  412. if assigned(p^.right) then
  413. disposetree(p^.right);
  414. if assigned(p^.nodes) then
  415. deletecaselabels(p^.nodes);
  416. if assigned(p^.elseblock) then
  417. disposetree(p^.elseblock);
  418. end;
  419. dt_nothing : ;
  420. dt_left :
  421. if assigned(p^.left) then
  422. disposetree(p^.left);
  423. dt_mbleft :
  424. if assigned(p^.left) then
  425. disposetree(p^.left);
  426. dt_mbleft_and_method :
  427. begin
  428. if assigned(p^.left) then disposetree(p^.left);
  429. disposetree(p^.methodpointer);
  430. end;
  431. dt_typeconv : disposetree(p^.left);
  432. dt_inlinen :
  433. if assigned(p^.left) then
  434. disposetree(p^.left);
  435. dt_loop :
  436. begin
  437. if assigned(p^.left) then
  438. disposetree(p^.left);
  439. if assigned(p^.right) then
  440. disposetree(p^.right);
  441. if assigned(p^.t1) then
  442. disposetree(p^.t1);
  443. if assigned(p^.t2) then
  444. disposetree(p^.t2);
  445. end;
  446. dt_onn:
  447. begin
  448. if assigned(p^.left) then
  449. disposetree(p^.left);
  450. if assigned(p^.right) then
  451. disposetree(p^.right);
  452. if assigned(p^.exceptsymtable) then
  453. dispose(p^.exceptsymtable,done);
  454. end;
  455. dt_with :
  456. begin
  457. if assigned(p^.left) then
  458. disposetree(p^.left);
  459. if assigned(p^.right) then
  460. disposetree(p^.right);
  461. if assigned(p^.withsymtable) then
  462. dispose(p^.withsymtable,done);
  463. end;
  464. else internalerror(12);
  465. end;
  466. putnode(p);
  467. end;
  468. procedure set_file_line(from,_to : ptree);
  469. begin
  470. if assigned(from) then
  471. _to^.fileinfo:=from^.fileinfo;
  472. end;
  473. procedure set_tree_filepos(p : ptree;const filepos : tfileposinfo);
  474. begin
  475. p^.fileinfo:=filepos;
  476. end;
  477. function genwithnode(symtable : psymtable;l,r : ptree;count : longint) : ptree;
  478. var
  479. p : ptree;
  480. begin
  481. p:=getnode;
  482. p^.disposetyp:=dt_with;
  483. p^.treetype:=withn;
  484. p^.left:=l;
  485. p^.right:=r;
  486. p^.registers32:=0;
  487. { p^.registers16:=0;
  488. p^.registers8:=0; }
  489. p^.registersfpu:=0;
  490. {$ifdef SUPPORT_MMX}
  491. p^.registersmmx:=0;
  492. {$endif SUPPORT_MMX}
  493. p^.resulttype:=nil;
  494. p^.withsymtable:=symtable;
  495. p^.tablecount:=count;
  496. set_file_line(l,p);
  497. genwithnode:=p;
  498. end;
  499. function genfixconstnode(v : longint;def : pdef) : ptree;
  500. var
  501. p : ptree;
  502. begin
  503. p:=getnode;
  504. p^.disposetyp:=dt_nothing;
  505. p^.treetype:=fixconstn;
  506. p^.registers32:=0;
  507. { p^.registers16:=0;
  508. p^.registers8:=0; }
  509. p^.registersfpu:=0;
  510. {$ifdef SUPPORT_MMX}
  511. p^.registersmmx:=0;
  512. {$endif SUPPORT_MMX}
  513. p^.resulttype:=def;
  514. p^.value:=v;
  515. genfixconstnode:=p;
  516. end;
  517. function gencallparanode(expr,next : ptree) : ptree;
  518. var
  519. p : ptree;
  520. begin
  521. p:=getnode;
  522. p^.disposetyp:=dt_leftright;
  523. p^.treetype:=callparan;
  524. p^.left:=expr;
  525. p^.right:=next;
  526. p^.registers32:=0;
  527. { p^.registers16:=0;
  528. p^.registers8:=0; }
  529. {$ifdef SUPPORT_MMX}
  530. p^.registersmmx:=0;
  531. {$endif SUPPORT_MMX}
  532. p^.registersfpu:=0;
  533. p^.resulttype:=nil;
  534. p^.exact_match_found:=false;
  535. p^.is_colon_para:=false;
  536. set_file_line(expr,p);
  537. gencallparanode:=p;
  538. end;
  539. function gennode(t : ttreetyp;l,r : ptree) : ptree;
  540. var
  541. p : ptree;
  542. begin
  543. p:=getnode;
  544. p^.disposetyp:=dt_leftright;
  545. p^.treetype:=t;
  546. p^.left:=l;
  547. p^.right:=r;
  548. p^.registers32:=0;
  549. { p^.registers16:=0;
  550. p^.registers8:=0; }
  551. p^.registersfpu:=0;
  552. {$ifdef SUPPORT_MMX}
  553. p^.registersmmx:=0;
  554. {$endif SUPPORT_MMX}
  555. p^.resulttype:=nil;
  556. gennode:=p;
  557. end;
  558. function gencasenode(l,r : ptree;nodes : pcaserecord) : ptree;
  559. var
  560. p : ptree;
  561. begin
  562. p:=getnode;
  563. p^.disposetyp:=dt_case;
  564. p^.treetype:=casen;
  565. p^.left:=l;
  566. p^.right:=r;
  567. p^.nodes:=nodes;
  568. p^.registers32:=0;
  569. p^.registersfpu:=0;
  570. {$ifdef SUPPORT_MMX}
  571. p^.registersmmx:=0;
  572. {$endif SUPPORT_MMX}
  573. p^.resulttype:=nil;
  574. set_file_line(l,p);
  575. gencasenode:=p;
  576. end;
  577. function genloopnode(t : ttreetyp;l,r,n1 : ptree;back : boolean) : ptree;
  578. var
  579. p : ptree;
  580. begin
  581. p:=getnode;
  582. p^.disposetyp:=dt_loop;
  583. p^.treetype:=t;
  584. p^.left:=l;
  585. p^.right:=r;
  586. p^.t1:=n1;
  587. p^.t2:=nil;
  588. p^.registers32:=0;
  589. p^.backward:=back;
  590. { p^.registers16:=0;
  591. p^.registers8:=0; }
  592. p^.registersfpu:=0;
  593. {$ifdef SUPPORT_MMX}
  594. p^.registersmmx:=0;
  595. {$endif SUPPORT_MMX}
  596. p^.resulttype:=nil;
  597. set_file_line(l,p);
  598. genloopnode:=p;
  599. end;
  600. function genordinalconstnode(v : longint;def : pdef) : ptree;
  601. var
  602. p : ptree;
  603. begin
  604. p:=getnode;
  605. p^.disposetyp:=dt_nothing;
  606. p^.treetype:=ordconstn;
  607. p^.registers32:=0;
  608. { p^.registers16:=0;
  609. p^.registers8:=0; }
  610. p^.registersfpu:=0;
  611. {$ifdef SUPPORT_MMX}
  612. p^.registersmmx:=0;
  613. {$endif SUPPORT_MMX}
  614. p^.resulttype:=def;
  615. p^.value:=v;
  616. genordinalconstnode:=p;
  617. end;
  618. function genenumnode(v : penumsym) : ptree;
  619. var
  620. p : ptree;
  621. begin
  622. p:=getnode;
  623. p^.disposetyp:=dt_nothing;
  624. p^.treetype:=ordconstn;
  625. p^.registers32:=0;
  626. { p^.registers16:=0;
  627. p^.registers8:=0; }
  628. p^.registersfpu:=0;
  629. {$ifdef SUPPORT_MMX}
  630. p^.registersmmx:=0;
  631. {$endif SUPPORT_MMX}
  632. p^.resulttype:=v^.definition;
  633. p^.value:=v^.value;
  634. genenumnode:=p;
  635. end;
  636. function genrealconstnode(v : bestreal) : ptree;
  637. var
  638. p : ptree;
  639. begin
  640. p:=getnode;
  641. p^.disposetyp:=dt_nothing;
  642. p^.treetype:=realconstn;
  643. p^.registers32:=0;
  644. { p^.registers16:=0;
  645. p^.registers8:=0; }
  646. p^.registersfpu:=0;
  647. {$ifdef SUPPORT_MMX}
  648. p^.registersmmx:=0;
  649. {$endif SUPPORT_MMX}
  650. {$ifdef i386}
  651. p^.resulttype:=c64floatdef;
  652. p^.value_real:=v;
  653. { default value is double }
  654. p^.realtyp:=ait_real_64bit;
  655. {$endif}
  656. {$ifdef m68k}
  657. p^.resulttype:=new(pfloatdef,init(s32real));
  658. p^.value_real:=v;
  659. { default value is double }
  660. p^.realtyp:=ait_real_32bit;
  661. {$endif}
  662. p^.lab_real:=nil;
  663. genrealconstnode:=p;
  664. end;
  665. function genstringconstnode(const s : string) : ptree;
  666. var
  667. p : ptree;
  668. {$ifdef UseAnsiString}
  669. l : longint;
  670. {$endif UseAnsiString}
  671. begin
  672. p:=getnode;
  673. p^.disposetyp:=dt_nothing;
  674. p^.treetype:=stringconstn;
  675. p^.registers32:=0;
  676. { p^.registers16:=0;
  677. p^.registers8:=0; }
  678. p^.registersfpu:=0;
  679. {$ifdef SUPPORT_MMX}
  680. p^.registersmmx:=0;
  681. {$endif SUPPORT_MMX}
  682. p^.resulttype:=cstringdef;
  683. {$ifdef UseAnsiString}
  684. l:=length(s);
  685. p^.length:=l;
  686. { stringdup write even past a #0 }
  687. getmem(p^.value_str,l+1);
  688. move(s[1],p^.value_str^,l);
  689. p^.value_str[l]:=#0;
  690. {$else UseAnsiString}
  691. p^.value_str:=stringdup(s);
  692. {$endif UseAnsiString}
  693. p^.lab_str:=nil;
  694. p^.stringtype:=st_shortstring;
  695. genstringconstnode:=p;
  696. end;
  697. {$ifdef UseAnsiString}
  698. function getpcharcopy(p : ptree) : pchar;
  699. var
  700. pc : pchar;
  701. begin
  702. pc:=nil;
  703. getmem(pc,p^.length+1);
  704. { Peter can you change that ? }
  705. if pc=nil then
  706. Message(general_f_no_memory_left);
  707. move(p^.value_str^,pc^,p^.length+1);
  708. getpcharcopy:=pc;
  709. end;
  710. function genpcharconstnode(s : pchar;length : longint) : ptree;
  711. var
  712. p : ptree;
  713. begin
  714. p:=getnode;
  715. p^.disposetyp:=dt_nothing;
  716. p^.treetype:=stringconstn;
  717. p^.registers32:=0;
  718. { p^.registers16:=0;
  719. p^.registers8:=0; }
  720. p^.registersfpu:=0;
  721. {$ifdef SUPPORT_MMX}
  722. p^.registersmmx:=0;
  723. {$endif SUPPORT_MMX}
  724. p^.resulttype:=cstringdef;
  725. p^.length:=length;
  726. p^.value_str:=s;
  727. p^.lab_str:=nil;
  728. genpcharconstnode:=p;
  729. end;
  730. {$endif UseAnsiString}
  731. function gensinglenode(t : ttreetyp;l : ptree) : ptree;
  732. var
  733. p : ptree;
  734. begin
  735. p:=getnode;
  736. p^.disposetyp:=dt_left;
  737. p^.treetype:=t;
  738. p^.left:=l;
  739. p^.registers32:=0;
  740. { p^.registers16:=0;
  741. p^.registers8:=0; }
  742. p^.registersfpu:=0;
  743. {$ifdef SUPPORT_MMX}
  744. p^.registersmmx:=0;
  745. {$endif SUPPORT_MMX}
  746. p^.resulttype:=nil;
  747. gensinglenode:=p;
  748. end;
  749. function genasmnode(p_asm : paasmoutput) : ptree;
  750. var
  751. p : ptree;
  752. begin
  753. p:=getnode;
  754. p^.disposetyp:=dt_nothing;
  755. p^.treetype:=asmn;
  756. p^.registers32:=4;
  757. p^.p_asm:=p_asm;
  758. p^.object_preserved:=false;
  759. { p^.registers16:=0;
  760. p^.registers8:=0; }
  761. p^.registersfpu:=8;
  762. {$ifdef SUPPORT_MMX}
  763. p^.registersmmx:=8;
  764. {$endif SUPPORT_MMX}
  765. p^.resulttype:=nil;
  766. genasmnode:=p;
  767. end;
  768. function genloadnode(v : pvarsym;st : psymtable) : ptree;
  769. var
  770. p : ptree;
  771. begin
  772. p:=getnode;
  773. p^.registers32:=0;
  774. { p^.registers16:=0;
  775. p^.registers8:=0; }
  776. p^.registersfpu:=0;
  777. {$ifdef SUPPORT_MMX}
  778. p^.registersmmx:=0;
  779. {$endif SUPPORT_MMX}
  780. p^.treetype:=loadn;
  781. p^.resulttype:=v^.definition;
  782. p^.symtableentry:=v;
  783. p^.symtable:=st;
  784. p^.is_first := False;
  785. p^.disposetyp:=dt_nothing;
  786. genloadnode:=p;
  787. end;
  788. function genloadcallnode(v: pprocsym;st: psymtable): ptree;
  789. var
  790. p : ptree;
  791. begin
  792. p:=getnode;
  793. p^.registers32:=0;
  794. { p^.registers16:=0;
  795. p^.registers8:=0; }
  796. p^.registersfpu:=0;
  797. {$ifdef SUPPORT_MMX}
  798. p^.registersmmx:=0;
  799. {$endif SUPPORT_MMX}
  800. p^.treetype:=loadn;
  801. p^.resulttype:=v^.definition;
  802. p^.symtableentry:=v;
  803. p^.symtable:=st;
  804. p^.is_first := False;
  805. p^.disposetyp:=dt_nothing;
  806. genloadcallnode:=p;
  807. end;
  808. function gentypedconstloadnode(sym : ptypedconstsym;st : psymtable) : ptree;
  809. var
  810. p : ptree;
  811. begin
  812. p:=getnode;
  813. p^.registers32:=0;
  814. { p^.registers16:=0;
  815. p^.registers8:=0; }
  816. p^.registersfpu:=0;
  817. {$ifdef SUPPORT_MMX}
  818. p^.registersmmx:=0;
  819. {$endif SUPPORT_MMX}
  820. p^.treetype:=loadn;
  821. p^.resulttype:=sym^.definition;
  822. p^.symtableentry:=pvarsym(sym);
  823. p^.symtable:=st;
  824. p^.disposetyp:=dt_nothing;
  825. gentypedconstloadnode:=p;
  826. end;
  827. function gentypeconvnode(node : ptree;t : pdef) : ptree;
  828. var
  829. p : ptree;
  830. begin
  831. p:=getnode;
  832. p^.disposetyp:=dt_typeconv;
  833. p^.treetype:=typeconvn;
  834. p^.left:=node;
  835. p^.registers32:=0;
  836. { p^.registers16:=0;
  837. p^.registers8:=0; }
  838. p^.convtyp:=tc_equal;
  839. p^.registersfpu:=0;
  840. {$ifdef SUPPORT_MMX}
  841. p^.registersmmx:=0;
  842. {$endif SUPPORT_MMX}
  843. p^.resulttype:=t;
  844. p^.explizit:=false;
  845. set_file_line(node,p);
  846. gentypeconvnode:=p;
  847. end;
  848. function gencallnode(v : pprocsym;st : psymtable) : ptree;
  849. var
  850. p : ptree;
  851. begin
  852. p:=getnode;
  853. p^.registers32:=0;
  854. { p^.registers16:=0;
  855. p^.registers8:=0; }
  856. p^.registersfpu:=0;
  857. {$ifdef SUPPORT_MMX}
  858. p^.registersmmx:=0;
  859. {$endif SUPPORT_MMX}
  860. p^.treetype:=calln;
  861. p^.symtableprocentry:=v;
  862. p^.symtableproc:=st;
  863. p^.unit_specific:=false;
  864. p^.no_check:=false;
  865. p^.return_value_used:=true;
  866. p^.disposetyp := dt_leftright;
  867. p^.methodpointer:=nil;
  868. p^.left:=nil;
  869. p^.right:=nil;
  870. p^.procdefinition:=nil;
  871. gencallnode:=p;
  872. end;
  873. function genmethodcallnode(v : pprocsym;st : psymtable;mp : ptree) : ptree;
  874. var
  875. p : ptree;
  876. begin
  877. p:=getnode;
  878. p^.registers32:=0;
  879. { p^.registers16:=0;
  880. p^.registers8:=0; }
  881. p^.registersfpu:=0;
  882. {$ifdef SUPPORT_MMX}
  883. p^.registersmmx:=0;
  884. {$endif SUPPORT_MMX}
  885. p^.treetype:=calln;
  886. p^.return_value_used:=true;
  887. p^.symtableprocentry:=v;
  888. p^.symtableproc:=st;
  889. p^.disposetyp:=dt_mbleft_and_method;
  890. p^.left:=nil;
  891. p^.right:=nil;
  892. p^.methodpointer:=mp;
  893. p^.procdefinition:=nil;
  894. genmethodcallnode:=p;
  895. end;
  896. function gensubscriptnode(varsym : pvarsym;l : ptree) : ptree;
  897. var
  898. p : ptree;
  899. begin
  900. p:=getnode;
  901. p^.disposetyp:=dt_left;
  902. p^.treetype:=subscriptn;
  903. p^.left:=l;
  904. p^.registers32:=0;
  905. p^.vs:=varsym;
  906. { p^.registers16:=0;
  907. p^.registers8:=0; }
  908. p^.registersfpu:=0;
  909. {$ifdef SUPPORT_MMX}
  910. p^.registersmmx:=0;
  911. {$endif SUPPORT_MMX}
  912. p^.resulttype:=nil;
  913. gensubscriptnode:=p;
  914. end;
  915. function genzeronode(t : ttreetyp) : ptree;
  916. var
  917. p : ptree;
  918. begin
  919. p:=getnode;
  920. p^.disposetyp:=dt_nothing;
  921. p^.treetype:=t;
  922. p^.registers32:=0;
  923. { p^.registers16:=0;
  924. p^.registers8:=0; }
  925. p^.registersfpu:=0;
  926. {$ifdef SUPPORT_MMX}
  927. p^.registersmmx:=0;
  928. {$endif SUPPORT_MMX}
  929. p^.resulttype:=nil;
  930. genzeronode:=p;
  931. end;
  932. function genlabelnode(t : ttreetyp;nr : plabel) : ptree;
  933. var
  934. p : ptree;
  935. begin
  936. p:=getnode;
  937. p^.disposetyp:=dt_nothing;
  938. p^.treetype:=t;
  939. p^.registers32:=0;
  940. { p^.registers16:=0;
  941. p^.registers8:=0; }
  942. p^.registersfpu:=0;
  943. {$ifdef SUPPORT_MMX}
  944. p^.registersmmx:=0;
  945. {$endif SUPPORT_MMX}
  946. p^.resulttype:=nil;
  947. { for security }
  948. { nr^.is_used:=true;}
  949. p^.labelnr:=nr;
  950. genlabelnode:=p;
  951. end;
  952. function genselfnode(_class : pdef) : ptree;
  953. var
  954. p : ptree;
  955. begin
  956. p:=getnode;
  957. p^.disposetyp:=dt_nothing;
  958. p^.treetype:=selfn;
  959. p^.registers32:=0;
  960. { p^.registers16:=0;
  961. p^.registers8:=0; }
  962. p^.registersfpu:=0;
  963. {$ifdef SUPPORT_MMX}
  964. p^.registersmmx:=0;
  965. {$endif SUPPORT_MMX}
  966. p^.resulttype:=_class;
  967. genselfnode:=p;
  968. end;
  969. function geninlinenode(number : longint;is_const:boolean;l : ptree) : ptree;
  970. var
  971. p : ptree;
  972. begin
  973. p:=getnode;
  974. p^.disposetyp:=dt_inlinen;
  975. p^.treetype:=inlinen;
  976. p^.left:=l;
  977. p^.inlinenumber:=number;
  978. p^.inlineconst:=is_const;
  979. p^.registers32:=0;
  980. { p^.registers16:=0;
  981. p^.registers8:=0; }
  982. p^.registersfpu:=0;
  983. {$ifdef SUPPORT_MMX}
  984. p^.registersmmx:=0;
  985. {$endif SUPPORT_MMX}
  986. p^.resulttype:=nil;
  987. geninlinenode:=p;
  988. end;
  989. { uses the callnode to create the new procinline node }
  990. function genprocinlinenode(callp,code : ptree) : ptree;
  991. var
  992. p : ptree;
  993. begin
  994. p:=getnode;
  995. p^.disposetyp:=dt_left;
  996. p^.treetype:=procinlinen;
  997. p^.inlineprocdef:=callp^.procdefinition;
  998. p^.retoffset:=-4; { less dangerous as zero (PM) }
  999. p^.para_offset:=0;
  1000. p^.para_size:=p^.inlineprocdef^.para_size;
  1001. if ret_in_param(p^.inlineprocdef^.retdef) then
  1002. p^.para_size:=p^.para_size+sizeof(pointer);
  1003. { copy args }
  1004. p^.left:=getcopy(code);
  1005. p^.registers32:=code^.registers32;
  1006. p^.registersfpu:=code^.registersfpu;
  1007. {$ifdef SUPPORT_MMX}
  1008. p^.registersmmx:=0;
  1009. {$endif SUPPORT_MMX}
  1010. p^.resulttype:=p^.inlineprocdef^.retdef;
  1011. genprocinlinenode:=p;
  1012. end;
  1013. function gensetconstnode(s : pconstset;settype : psetdef) : ptree;
  1014. var
  1015. p : ptree;
  1016. begin
  1017. p:=getnode;
  1018. p^.disposetyp:=dt_nothing;
  1019. p^.treetype:=setconstn;
  1020. p^.registers32:=0;
  1021. p^.registersfpu:=0;
  1022. {$ifdef SUPPORT_MMX}
  1023. p^.registersmmx:=0;
  1024. {$endif SUPPORT_MMX}
  1025. p^.resulttype:=settype;
  1026. p^.left:=nil;
  1027. new(p^.value_set);
  1028. p^.value_set^:=s^;
  1029. gensetconstnode:=p;
  1030. end;
  1031. {$ifdef extdebug}
  1032. procedure compare_trees(oldp,p : ptree);
  1033. var
  1034. error_found : boolean;
  1035. begin
  1036. if oldp^.resulttype<>p^.resulttype then
  1037. begin
  1038. error_found:=true;
  1039. if is_equal(oldp^.resulttype,p^.resulttype) then
  1040. comment(v_debug,'resulttype fields are different but equal')
  1041. else
  1042. comment(v_warning,'resulttype fields are really different');
  1043. end;
  1044. if oldp^.treetype<>p^.treetype then
  1045. begin
  1046. comment(v_warning,'treetype field different');
  1047. error_found:=true;
  1048. end
  1049. else
  1050. comment(v_debug,' treetype '+tostr(longint(oldp^.treetype)));
  1051. if oldp^.error<>p^.error then
  1052. begin
  1053. comment(v_warning,'error field different');
  1054. error_found:=true;
  1055. end;
  1056. if oldp^.disposetyp<>p^.disposetyp then
  1057. begin
  1058. comment(v_warning,'disposetyp field different');
  1059. error_found:=true;
  1060. end;
  1061. { is true, if the right and left operand are swaped }
  1062. if oldp^.swaped<>p^.swaped then
  1063. begin
  1064. comment(v_warning,'swaped field different');
  1065. error_found:=true;
  1066. end;
  1067. { the location of the result of this node }
  1068. if oldp^.location.loc<>p^.location.loc then
  1069. begin
  1070. comment(v_warning,'location.loc field different');
  1071. error_found:=true;
  1072. end;
  1073. { the number of registers needed to evalute the node }
  1074. if oldp^.registers32<>p^.registers32 then
  1075. begin
  1076. comment(v_warning,'registers32 field different');
  1077. comment(v_warning,' old '+tostr(oldp^.registers32)+'<> new '+tostr(p^.registers32));
  1078. error_found:=true;
  1079. end;
  1080. if oldp^.registersfpu<>p^.registersfpu then
  1081. begin
  1082. comment(v_warning,'registersfpu field different');
  1083. error_found:=true;
  1084. end;
  1085. {$ifdef SUPPORT_MMX}
  1086. if oldp^.registersmmx<>p^.registersmmx then
  1087. begin
  1088. comment(v_warning,'registersmmx field different');
  1089. error_found:=true;
  1090. end;
  1091. {$endif SUPPORT_MMX}
  1092. if oldp^.left<>p^.left then
  1093. begin
  1094. comment(v_warning,'left field different');
  1095. error_found:=true;
  1096. end;
  1097. if oldp^.right<>p^.right then
  1098. begin
  1099. comment(v_warning,'right field different');
  1100. error_found:=true;
  1101. end;
  1102. if oldp^.fileinfo.line<>p^.fileinfo.line then
  1103. begin
  1104. comment(v_warning,'fileinfo.line field different');
  1105. error_found:=true;
  1106. end;
  1107. if oldp^.fileinfo.column<>p^.fileinfo.column then
  1108. begin
  1109. comment(v_warning,'fileinfo.column field different');
  1110. error_found:=true;
  1111. end;
  1112. if oldp^.fileinfo.fileindex<>p^.fileinfo.fileindex then
  1113. begin
  1114. comment(v_warning,'fileinfo.fileindex field different');
  1115. error_found:=true;
  1116. end;
  1117. if oldp^.localswitches<>p^.localswitches then
  1118. begin
  1119. comment(v_warning,'localswitches field different');
  1120. error_found:=true;
  1121. end;
  1122. {$ifdef extdebug}
  1123. if oldp^.firstpasscount<>p^.firstpasscount then
  1124. begin
  1125. comment(v_warning,'firstpasscount field different');
  1126. error_found:=true;
  1127. end;
  1128. {$endif extdebug}
  1129. if oldp^.treetype=p^.treetype then
  1130. case oldp^.treetype of
  1131. addn :
  1132. begin
  1133. if oldp^.use_strconcat<>p^.use_strconcat then
  1134. begin
  1135. comment(v_warning,'use_strconcat field different');
  1136. error_found:=true;
  1137. end;
  1138. if oldp^.string_typ<>p^.string_typ then
  1139. begin
  1140. comment(v_warning,'stringtyp field different');
  1141. error_found:=true;
  1142. end;
  1143. end;
  1144. callparan :
  1145. {(is_colon_para : boolean;exact_match_found : boolean);}
  1146. begin
  1147. if oldp^.is_colon_para<>p^.is_colon_para then
  1148. begin
  1149. comment(v_warning,'use_strconcat field different');
  1150. error_found:=true;
  1151. end;
  1152. if oldp^.exact_match_found<>p^.exact_match_found then
  1153. begin
  1154. comment(v_warning,'exact_match_found field different');
  1155. error_found:=true;
  1156. end;
  1157. end;
  1158. assignn :
  1159. {(assigntyp : tassigntyp;concat_string : boolean);}
  1160. begin
  1161. if oldp^.assigntyp<>p^.assigntyp then
  1162. begin
  1163. comment(v_warning,'assigntyp field different');
  1164. error_found:=true;
  1165. end;
  1166. if oldp^.concat_string<>p^.concat_string then
  1167. begin
  1168. comment(v_warning,'concat_string field different');
  1169. error_found:=true;
  1170. end;
  1171. end;
  1172. loadn :
  1173. {(symtableentry : psym;symtable : psymtable;
  1174. is_absolute,is_first : boolean);}
  1175. begin
  1176. if oldp^.symtableentry<>p^.symtableentry then
  1177. begin
  1178. comment(v_warning,'symtableentry field different');
  1179. error_found:=true;
  1180. end;
  1181. if oldp^.symtable<>p^.symtable then
  1182. begin
  1183. comment(v_warning,'symtable field different');
  1184. error_found:=true;
  1185. end;
  1186. if oldp^.is_absolute<>p^.is_absolute then
  1187. begin
  1188. comment(v_warning,'is_absolute field different');
  1189. error_found:=true;
  1190. end;
  1191. if oldp^.is_first<>p^.is_first then
  1192. begin
  1193. comment(v_warning,'is_first field different');
  1194. error_found:=true;
  1195. end;
  1196. end;
  1197. calln :
  1198. {(symtableprocentry : pprocsym;
  1199. symtableproc : psymtable;procdefinition : pprocdef;
  1200. methodpointer : ptree;
  1201. no_check,unit_specific : boolean);}
  1202. begin
  1203. if oldp^.symtableprocentry<>p^.symtableprocentry then
  1204. begin
  1205. comment(v_warning,'symtableprocentry field different');
  1206. error_found:=true;
  1207. end;
  1208. if oldp^.symtableproc<>p^.symtableproc then
  1209. begin
  1210. comment(v_warning,'symtableproc field different');
  1211. error_found:=true;
  1212. end;
  1213. if oldp^.procdefinition<>p^.procdefinition then
  1214. begin
  1215. comment(v_warning,'procdefinition field different');
  1216. error_found:=true;
  1217. end;
  1218. if oldp^.methodpointer<>p^.methodpointer then
  1219. begin
  1220. comment(v_warning,'methodpointer field different');
  1221. error_found:=true;
  1222. end;
  1223. if oldp^.no_check<>p^.no_check then
  1224. begin
  1225. comment(v_warning,'no_check field different');
  1226. error_found:=true;
  1227. end;
  1228. if oldp^.unit_specific<>p^.unit_specific then
  1229. begin
  1230. error_found:=true;
  1231. comment(v_warning,'unit_specific field different');
  1232. end;
  1233. end;
  1234. ordconstn :
  1235. begin
  1236. if oldp^.value<>p^.value then
  1237. begin
  1238. comment(v_warning,'value field different');
  1239. error_found:=true;
  1240. end;
  1241. end;
  1242. realconstn :
  1243. begin
  1244. if oldp^.value_real<>p^.value_real then
  1245. begin
  1246. comment(v_warning,'valued field different');
  1247. error_found:=true;
  1248. end;
  1249. if oldp^.lab_real<>p^.lab_real then
  1250. begin
  1251. comment(v_warning,'labnumber field different');
  1252. error_found:=true;
  1253. end;
  1254. if oldp^.realtyp<>p^.realtyp then
  1255. begin
  1256. comment(v_warning,'realtyp field different');
  1257. error_found:=true;
  1258. end;
  1259. end;
  1260. (*realconstn : (valued : bestreal;labnumber : longint;realtyp : tait);
  1261. fixconstn : (valuef: longint);
  1262. funcretn : (funcretprocinfo : pointer;retdef : pdef);
  1263. subscriptn : (vs : pvarsym);
  1264. vecn : (memindex,memseg:boolean);
  1265. { stringconstn : (length : longint; value_str : pstring;labstrnumber : longint); }
  1266. { string const can be longer then 255 with ansistring !! }
  1267. {$ifdef UseAnsiString}
  1268. stringconstn : (value_str : pchar;length : longint; labstrnumber : longint);
  1269. {$else UseAnsiString}
  1270. stringconstn : (value_str : pstring; labstrnumber : longint);
  1271. {$endif UseAnsiString}
  1272. typeconvn : (convtyp : tconverttype;explizit : boolean);
  1273. inlinen : (inlinenumber : longint);
  1274. procinlinen : (inlineprocdef : pprocdef);
  1275. setconstrn : (constset : pconstset);
  1276. loopn : (t1,t2 : ptree;backward : boolean);
  1277. asmn : (p_asm : paasmoutput);
  1278. casen : (nodes : pcaserecord;elseblock : ptree);
  1279. labeln,goton : (labelnr : plabel);
  1280. withn : (withsymtable : psymtable;tablecount : longint);
  1281. end; *)
  1282. end;
  1283. if not error_found then
  1284. comment(v_warning,'did not find difference in trees');
  1285. end;
  1286. {$endif extdebug}
  1287. function equal_trees(t1,t2 : ptree) : boolean;
  1288. begin
  1289. if t1^.treetype=t2^.treetype then
  1290. begin
  1291. case t1^.treetype of
  1292. addn,
  1293. muln,
  1294. equaln,
  1295. orn,
  1296. xorn,
  1297. andn,
  1298. unequaln:
  1299. begin
  1300. equal_trees:=(equal_trees(t1^.left,t2^.left) and
  1301. equal_trees(t1^.right,t2^.right)) or
  1302. (equal_trees(t1^.right,t2^.left) and
  1303. equal_trees(t1^.left,t2^.right));
  1304. end;
  1305. subn,
  1306. divn,
  1307. modn,
  1308. assignn,
  1309. ltn,
  1310. lten,
  1311. gtn,
  1312. gten,
  1313. inn,
  1314. shrn,
  1315. shln,
  1316. slashn,
  1317. rangen:
  1318. begin
  1319. equal_trees:=(equal_trees(t1^.left,t2^.left) and
  1320. equal_trees(t1^.right,t2^.right));
  1321. end;
  1322. umminusn,
  1323. notn,
  1324. derefn,
  1325. addrn:
  1326. begin
  1327. equal_trees:=(equal_trees(t1^.left,t2^.left));
  1328. end;
  1329. loadn:
  1330. begin
  1331. equal_trees:=(t1^.symtableentry=t2^.symtableentry)
  1332. { not necessary
  1333. and (t1^.symtable=t2^.symtable)};
  1334. end;
  1335. {
  1336. subscriptn,
  1337. ordconstn,typeconvn,calln,callparan,
  1338. realconstn,asmn,vecn,
  1339. stringconstn,funcretn,selfn,
  1340. inlinen,niln,errorn,
  1341. typen,hnewn,hdisposen,newn,
  1342. disposen,setelen,setconstrn
  1343. }
  1344. else equal_trees:=false;
  1345. end;
  1346. end
  1347. else
  1348. equal_trees:=false;
  1349. end;
  1350. {This is needed if you want to be able to delete the string with the nodes !!}
  1351. procedure set_location(var destloc,sourceloc : tlocation);
  1352. begin
  1353. if assigned(destloc.reference.symbol) then
  1354. stringdispose(destloc.reference.symbol);
  1355. destloc:= sourceloc;
  1356. if sourceloc.loc in [LOC_MEM,LOC_REFERENCE] then
  1357. begin
  1358. if assigned(sourceloc.reference.symbol) then
  1359. destloc.reference.symbol:=
  1360. stringdup(sourceloc.reference.symbol^);
  1361. end
  1362. else
  1363. destloc.reference.symbol:=nil;
  1364. end;
  1365. procedure swap_location(var destloc,sourceloc : tlocation);
  1366. var
  1367. swapl : tlocation;
  1368. begin
  1369. swapl := destloc;
  1370. destloc := sourceloc;
  1371. sourceloc := swapl;
  1372. end;
  1373. function get_ordinal_value(p : ptree) : longint;
  1374. begin
  1375. if p^.treetype=ordconstn then
  1376. get_ordinal_value:=p^.value
  1377. else
  1378. Message(type_e_ordinal_expr_expected);
  1379. end;
  1380. function is_constnode(p : ptree) : boolean;
  1381. begin
  1382. is_constnode:=(p^.treetype in [ordconstn,realconstn,stringconstn,fixconstn,setconstn]);
  1383. end;
  1384. function is_constintnode(p : ptree) : boolean;
  1385. begin
  1386. is_constintnode:=(p^.treetype=ordconstn) and is_integer(p^.resulttype);
  1387. end;
  1388. function is_constcharnode(p : ptree) : boolean;
  1389. begin
  1390. is_constcharnode:=((p^.treetype=ordconstn) and
  1391. (p^.resulttype^.deftype=orddef) and
  1392. (porddef(p^.resulttype)^.typ=uchar));
  1393. end;
  1394. function is_constrealnode(p : ptree) : boolean;
  1395. begin
  1396. is_constrealnode:=(p^.treetype=realconstn);
  1397. end;
  1398. function is_constboolnode(p : ptree) : boolean;
  1399. begin
  1400. is_constboolnode:=((p^.treetype=ordconstn) and
  1401. (p^.resulttype^.deftype=orddef) and
  1402. (porddef(p^.resulttype)^.typ in [bool8bit,bool16bit,bool32bit]));
  1403. end;
  1404. end.
  1405. {
  1406. $Log$
  1407. Revision 1.41 1998-09-23 09:58:55 peter
  1408. * first working array of const things
  1409. Revision 1.40 1998/09/22 15:34:07 peter
  1410. + pchar -> string conversion
  1411. Revision 1.39 1998/09/21 08:45:27 pierre
  1412. + added vmt_offset in tobjectdef.write for fututre use
  1413. (first steps to have objects without vmt if no virtual !!)
  1414. + added fpu_used field for tabstractprocdef :
  1415. sets this level to 2 if the functions return with value in FPU
  1416. (is then set to correct value at parsing of implementation)
  1417. THIS MIGHT refuse some code with FPU expression too complex
  1418. that were accepted before and even in some cases
  1419. that don't overflow in fact
  1420. ( like if f : float; is a forward that finally in implementation
  1421. only uses one fpu register !!)
  1422. Nevertheless I think that it will improve security on
  1423. FPU operations !!
  1424. * most other changes only for UseBrowser code
  1425. (added symtable references for record and objects)
  1426. local switch for refs to args and local of each function
  1427. (static symtable still missing)
  1428. UseBrowser still not stable and probably broken by
  1429. the definition hash array !!
  1430. Revision 1.38 1998/09/16 01:06:47 carl
  1431. * crash bugfix in firstaddr
  1432. Revision 1.37 1998/09/08 10:38:04 pierre
  1433. * some variable fields inside conditionnal were not updated
  1434. Revision 1.36 1998/09/07 18:46:17 peter
  1435. * update smartlinking, uses getdatalabel
  1436. * renamed ptree.value vars to value_str,value_real,value_set
  1437. Revision 1.35 1998/09/04 08:42:11 peter
  1438. * updated some error messages
  1439. Revision 1.34 1998/09/01 17:39:54 peter
  1440. + internal constant functions
  1441. Revision 1.33 1998/08/28 12:51:44 florian
  1442. + ansistring to pchar type cast fixed
  1443. Revision 1.32 1998/08/28 10:54:25 peter
  1444. * fixed smallset generation from elements, it has never worked before!
  1445. Revision 1.31 1998/08/21 14:08:58 pierre
  1446. + TEST_FUNCRET now default (old code removed)
  1447. works also for m68k (at least compiles)
  1448. Revision 1.30 1998/08/18 09:24:47 pierre
  1449. * small warning position bug fixed
  1450. * support_mmx switches splitting was missing
  1451. * rhide error and warning output corrected
  1452. Revision 1.29 1998/08/14 18:18:48 peter
  1453. + dynamic set contruction
  1454. * smallsets are now working (always longint size)
  1455. Revision 1.28 1998/08/13 11:00:13 peter
  1456. * fixed procedure<>procedure construct
  1457. Revision 1.27 1998/08/10 14:50:35 peter
  1458. + localswitches, moduleswitches, globalswitches splitting
  1459. Revision 1.26 1998/08/10 09:57:19 peter
  1460. - Remove InitTree which was empty and obsolete
  1461. Revision 1.25 1998/08/02 16:42:02 florian
  1462. * on o : tobject do should also work now, the exceptsymtable shouldn't be
  1463. disposed by dellexlevel
  1464. Revision 1.24 1998/07/30 11:18:23 florian
  1465. + first implementation of try ... except on .. do end;
  1466. * limitiation of 65535 bytes parameters for cdecl removed
  1467. Revision 1.23 1998/07/24 22:17:01 florian
  1468. * internal error 10 together with array access fixed. I hope
  1469. that's the final fix.
  1470. Revision 1.22 1998/07/20 10:23:05 florian
  1471. * better ansi string assignement
  1472. Revision 1.21 1998/07/14 21:46:56 peter
  1473. * updated messages file
  1474. Revision 1.20 1998/07/14 14:47:11 peter
  1475. * released NEWINPUT
  1476. Revision 1.19 1998/07/08 14:56:53 daniel
  1477. * Fixed $ifdef TP.
  1478. Revision 1.18 1998/07/07 11:20:18 peter
  1479. + NEWINPUT for a better inputfile and scanner object
  1480. Revision 1.17 1998/06/22 08:59:03 daniel
  1481. - Removed pool of nodes.
  1482. Revision 1.16 1998/06/12 14:50:49 peter
  1483. * removed the tree dependency to types.pas
  1484. * long_fil.pas support (not fully tested yet)
  1485. Revision 1.15 1998/06/06 08:39:07 peter
  1486. * it needs types
  1487. Revision 1.14 1998/06/05 14:37:40 pierre
  1488. * fixes for inline for operators
  1489. * inline procedure more correctly restricted
  1490. Revision 1.13 1998/06/04 09:55:49 pierre
  1491. * demangled name of procsym reworked to become independant of the mangling scheme
  1492. Revision 1.12 1998/06/03 22:49:06 peter
  1493. + wordbool,longbool
  1494. * rename bis,von -> high,low
  1495. * moved some systemunit loading/creating to psystem.pas
  1496. Revision 1.10 1998/05/20 09:42:38 pierre
  1497. + UseTokenInfo now default
  1498. * unit in interface uses and implementation uses gives error now
  1499. * only one error for unknown symbol (uses lastsymknown boolean)
  1500. the problem came from the label code !
  1501. + first inlined procedures and function work
  1502. (warning there might be allowed cases were the result is still wrong !!)
  1503. * UseBrower updated gives a global list of all position of all used symbols
  1504. with switch -gb
  1505. Revision 1.9 1998/05/12 10:47:00 peter
  1506. * moved printstatus to verb_def
  1507. + V_Normal which is between V_Error and V_Warning and doesn't have a
  1508. prefix like error: warning: and is included in V_Default
  1509. * fixed some messages
  1510. * first time parameter scan is only for -v and -T
  1511. - removed old style messages
  1512. Revision 1.8 1998/05/07 00:17:01 peter
  1513. * smartlinking for sets
  1514. + consts labels are now concated/generated in hcodegen
  1515. * moved some cpu code to cga and some none cpu depended code from cga
  1516. to tree and hcodegen and cleanup of hcodegen
  1517. * assembling .. output reduced for smartlinking ;)
  1518. Revision 1.7 1998/05/06 15:04:21 pierre
  1519. + when trying to find source files of a ppufile
  1520. check the includepathlist for included files
  1521. the main file must still be in the same directory
  1522. Revision 1.6 1998/05/06 08:38:52 pierre
  1523. * better position info with UseTokenInfo
  1524. UseTokenInfo greatly simplified
  1525. + added check for changed tree after first time firstpass
  1526. (if we could remove all the cases were it happen
  1527. we could skip all firstpass if firstpasscount > 1)
  1528. Only with ExtDebug
  1529. Revision 1.5 1998/04/30 15:59:43 pierre
  1530. * GDB works again better :
  1531. correct type info in one pass
  1532. + UseTokenInfo for better source position
  1533. * fixed one remaining bug in scanner for line counts
  1534. * several little fixes
  1535. Revision 1.4 1998/04/29 10:34:08 pierre
  1536. + added some code for ansistring (not complete nor working yet)
  1537. * corrected operator overloading
  1538. * corrected nasm output
  1539. + started inline procedures
  1540. + added starstarn : use ** for exponentiation (^ gave problems)
  1541. + started UseTokenInfo cond to get accurate positions
  1542. Revision 1.3 1998/04/21 10:16:49 peter
  1543. * patches from strasbourg
  1544. * objects is not used anymore in the fpc compiled version
  1545. Revision 1.2 1998/04/07 22:45:05 florian
  1546. * bug0092, bug0115 and bug0121 fixed
  1547. + packed object/class/array
  1548. }