tree.pas 57 KB

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