tree.pas 57 KB

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