tree.pas 58 KB

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