tree.pas 54 KB

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