tree.pas 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213
  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. symconst,globtype,cobjects,symtable,aasm,cpuasm,cpubase;
  25. type
  26. pconstset = ^tconstset;
  27. tconstset = array[0..31] of byte;
  28. ttreetyp = (
  29. addn, {Represents the + operator.}
  30. muln, {Represents the * operator.}
  31. subn, {Represents the - operator.}
  32. divn, {Represents the div operator.}
  33. symdifn, {Represents the >< operator.}
  34. modn, {Represents the mod operator.}
  35. assignn, {Represents an assignment.}
  36. loadn, {Represents the use of a variabele.}
  37. rangen, {Represents a range (i.e. 0..9).}
  38. ltn, {Represents the < operator.}
  39. lten, {Represents the <= operator.}
  40. gtn, {Represents the > operator.}
  41. gten, {Represents the >= operator.}
  42. equaln, {Represents the = operator.}
  43. unequaln, {Represents the <> operator.}
  44. inn, {Represents the in operator.}
  45. orn, {Represents the or operator.}
  46. xorn, {Represents the xor operator.}
  47. shrn, {Represents the shr operator.}
  48. shln, {Represents the shl operator.}
  49. slashn, {Represents the / operator.}
  50. andn, {Represents the and operator.}
  51. subscriptn, {access to a record/class/object field}
  52. derefn, {Dereferences a pointer.}
  53. addrn, {Represents the @ operator.}
  54. doubleaddrn, {Represents the @@ operator.}
  55. ordconstn, {Represents an ordinal value.}
  56. typeconvn, {Represents type-conversion/typecast.}
  57. calln, {Represents a call node.}
  58. callparan, {Represents a parameter.}
  59. realconstn, {Represents a real value.}
  60. fixconstn, {Represents a fixed value.}
  61. unaryminusn, {Represents a sign change (i.e. -2).}
  62. asmn, {Represents an assembler node }
  63. vecn, {Represents array indexing.}
  64. stringconstn, {Represents a string constant.}
  65. funcretn, {Represents the function result var.}
  66. selfn, {Represents the self parameter.}
  67. notn, {Represents the not operator.}
  68. inlinen, {Internal procedures (i.e. writeln).}
  69. niln, {Represents the nil pointer.}
  70. errorn, {This part of the tree could not be
  71. parsed because of a compiler error.}
  72. typen, {A type name. Used for i.e. typeof(obj).}
  73. hnewn, {The new operation, constructor call.}
  74. hdisposen, {The dispose operation with destructor call.}
  75. newn, {The new operation, constructor call.}
  76. simpledisposen, {The dispose operation.}
  77. setelementn, {A set element(s) (i.e. [a,b] and also [a..b]).}
  78. setconstn, {A set constant (i.e. [1,2]).}
  79. blockn, {A block of statements.}
  80. statementn, {One statement in a block of nodes.}
  81. loopn, { used in genloopnode, must be converted }
  82. ifn, {An if statement.}
  83. breakn, {A break statement.}
  84. continuen, {A continue statement.}
  85. repeatn, {A repeat until block.}
  86. whilen, {A while do statement.}
  87. forn, {A for loop.}
  88. exitn, {An exit statement.}
  89. withn, {A with statement.}
  90. casen, {A case statement.}
  91. labeln, {A label.}
  92. goton, {A goto statement.}
  93. simplenewn, {The new operation.}
  94. tryexceptn, {A try except block.}
  95. raisen, {A raise statement.}
  96. switchesn, {??? Currently unused...}
  97. tryfinallyn, {A try finally statement.}
  98. onn, { for an on statement in exception code }
  99. isn, {Represents the is operator.}
  100. asn, {Represents the as typecast.}
  101. caretn, {Represents the ^ operator.}
  102. failn, {Represents the fail statement.}
  103. starstarn, {Represents the ** operator exponentiation }
  104. procinlinen, {Procedures that can be inlined }
  105. arrayconstructn, {Construction node for [...] parsing}
  106. arrayconstructrangen, {Range element to allow sets in array construction tree}
  107. { added for optimizations where we cannot suppress }
  108. nothingn,
  109. loadvmtn,
  110. pointerconstn
  111. );
  112. tconverttype = (
  113. tc_equal,
  114. tc_not_possible,
  115. tc_string_2_string,
  116. tc_char_2_string,
  117. tc_pchar_2_string,
  118. tc_cchar_2_pchar,
  119. tc_cstring_2_pchar,
  120. tc_ansistring_2_pchar,
  121. tc_string_2_chararray,
  122. tc_chararray_2_string,
  123. tc_array_2_pointer,
  124. tc_pointer_2_array,
  125. tc_int_2_int,
  126. tc_int_2_bool,
  127. tc_bool_2_bool,
  128. tc_bool_2_int,
  129. tc_real_2_real,
  130. tc_int_2_real,
  131. tc_int_2_fix,
  132. tc_real_2_fix,
  133. tc_fix_2_real,
  134. tc_proc_2_procvar,
  135. tc_arrayconstructor_2_set,
  136. tc_load_smallset,
  137. tc_cord_2_pointer
  138. );
  139. { different assignment types }
  140. tassigntyp = (at_normal,at_plus,at_minus,at_star,at_slash);
  141. pcaserecord = ^tcaserecord;
  142. tcaserecord = record
  143. { range }
  144. _low,_high : longint;
  145. { only used by gentreejmp }
  146. _at : pasmlabel;
  147. { label of instruction }
  148. statement : pasmlabel;
  149. { is this the first of an case entry, needed to release statement
  150. label (PFV) }
  151. firstlabel : boolean;
  152. { left and right tree node }
  153. less,greater : pcaserecord;
  154. end;
  155. tnodeflags = (nf_needs_truefalselabel,tf_callunique);
  156. tnodeflagset = set of tnodeflags;
  157. pnode = ^tnode;
  158. tnode = object(tlinkedlist_item)
  159. treetype : ttreetyp;
  160. { the location of the result of this node }
  161. location : tlocation;
  162. { do we need to parse childs to set var state }
  163. varstateset : boolean;
  164. { the parent node of this is node }
  165. { this field is set by concattolist }
  166. parent : pnode;
  167. { there are some properties about the node stored }
  168. flags : tnodeflagset;
  169. { the number of registers needed to evalute the node }
  170. registersint,registersfpu : longint; { must be longint !!!! }
  171. {$ifdef SUPPORT_MMX}
  172. registersmmx,registerskni : longint;
  173. {$endif SUPPORT_MMX}
  174. resulttype : pdef;
  175. fileinfo : tfileposinfo;
  176. localswitches : tlocalswitches;
  177. {$ifdef extdebug}
  178. firstpasscount : longint;
  179. {$endif extdebug}
  180. error : boolean;
  181. list : paasmoutput;
  182. constructor init;
  183. destructor done;virtual;
  184. { runs det_resulttype and det_temp }
  185. procedure pass_1;
  186. { dermines the resulttype of the node }
  187. procedure det_resulttype;virtual;
  188. { dermines the number of necessary temp. locations to evaluate
  189. the node }
  190. procedure det_temp;virtual;
  191. procedure secondpass;virtual;
  192. {$ifdef EXTDEBUG}
  193. { writes a node for debugging purpose, shouldn't be called }
  194. { direct, because there is no test for nil, use writenode }
  195. { to write a complete tree }
  196. procedure dowrite;virtual;
  197. {$endif EXTDEBUG}
  198. procedure concattolist(l : plinkedlist);virtual;
  199. function ischild(p : pnode) : boolean;virtual;
  200. end;
  201. { allows to determine which elementes are to be replaced }
  202. tdisposetyp = (dt_nothing,dt_leftright,dt_left,dt_leftrighthigh,
  203. dt_mbleft,dt_typeconv,dt_inlinen,dt_leftrightmethod,
  204. dt_mbleft_and_method,dt_loop,dt_case,dt_with,dt_onn);
  205. ptree = ^ttree;
  206. ttree = record
  207. error : boolean;
  208. disposetyp : tdisposetyp;
  209. { is true, if the right and left operand are swaped }
  210. swaped : boolean;
  211. { do we need to parse childs to set var state }
  212. varstateset : boolean;
  213. { the location of the result of this node }
  214. location : tlocation;
  215. { the number of registers needed to evalute the node }
  216. registers32,registersfpu : longint; { must be longint !!!! }
  217. {$ifdef SUPPORT_MMX}
  218. registersmmx : longint;
  219. {$endif SUPPORT_MMX}
  220. left,right : ptree;
  221. resulttype : pdef;
  222. fileinfo : tfileposinfo;
  223. localswitches : tlocalswitches;
  224. {$ifdef extdebug}
  225. firstpasscount : longint;
  226. {$endif extdebug}
  227. {$ifdef TEMPS_NOT_PUSH}
  228. temp_offset : longint;
  229. {$endif TEMPS_NOT_PUSH}
  230. procvarload,isproperty : boolean;
  231. case treetype : ttreetyp of
  232. addn : (use_strconcat : boolean;string_typ : tstringtype);
  233. callparan : (is_colon_para : boolean;exact_match_found,
  234. convlevel1found,convlevel2found:boolean;hightree:ptree);
  235. assignn : (assigntyp : tassigntyp;concat_string : boolean);
  236. loadn : (symtableentry : psym;symtable : psymtable;
  237. is_absolute,is_first : boolean);
  238. calln : (symtableprocentry : pprocsym;
  239. symtableproc : psymtable;procdefinition : pabstractprocdef;
  240. methodpointer : ptree;
  241. no_check,unit_specific,
  242. return_value_used,static_call : boolean);
  243. ordconstn : (value : longint);
  244. realconstn : (value_real : bestreal;lab_real : pasmlabel);
  245. fixconstn : (value_fix: longint);
  246. funcretn : (funcretprocinfo : pointer;rettype : ttype;is_first_funcret : boolean);
  247. subscriptn : (vs : pvarsym);
  248. vecn : (memindex,memseg:boolean;callunique : boolean);
  249. stringconstn : (value_str : pchar;length : longint; lab_str : pasmlabel;stringtype : tstringtype);
  250. typeconvn : (convtyp : tconverttype;explizit : boolean);
  251. typen : (typenodetype : pdef;typenodesym:ptypesym);
  252. inlinen : (inlinenumber : byte;inlineconst:boolean);
  253. procinlinen : (inlinetree:ptree;inlineprocsym:pprocsym;retoffset,para_offset,para_size : longint);
  254. setconstn : (value_set : pconstset;lab_set:pasmlabel);
  255. loopn : (t1,t2 : ptree;backward : boolean);
  256. asmn : (p_asm : paasmoutput;object_preserved : boolean);
  257. casen : (nodes : pcaserecord;elseblock : ptree);
  258. labeln,goton : (labelnr : pasmlabel);
  259. withn : (withsymtable : pwithsymtable;tablecount : longint;withreference:preference;islocal:boolean);
  260. onn : (exceptsymtable : psymtable;excepttype : pobjectdef);
  261. arrayconstructn : (cargs,cargswap: boolean);
  262. end;
  263. { this node is the anchestor for all classes with at least }
  264. { one child, you have to use it if you want to use }
  265. { true- and falselabel }
  266. punarynode = ^tunarynode;
  267. tunarynode = object(tnode)
  268. left : pnode;
  269. truelabel,falselabel : pasmlabel;
  270. {$ifdef extdebug}
  271. procedure dowrite;virtual;
  272. {$endif extdebug}
  273. constructor init(l : pnode);
  274. procedure concattolist(l : plinkedlist);virtual;
  275. function ischild(p : pnode) : boolean;virtual;
  276. procedure det_resulttype;virtual;
  277. procedure det_temp;virtual;
  278. end;
  279. pbinarynode = ^tbinarynode;
  280. tbinarynode = object(tunarynode)
  281. right : pnode;
  282. constructor init(l,r : pnode);
  283. procedure concattolist(l : plinkedlist);virtual;
  284. function ischild(p : pnode) : boolean;virtual;
  285. procedure det_resulttype;virtual;
  286. procedure det_temp;virtual;
  287. end;
  288. pvecnode = ^tvecnode;
  289. tvecnode = object(tbinarynode)
  290. end;
  291. pbinopnode = ^tbinopnode;
  292. tbinopnode = object(tbinarynode)
  293. { is true, if the right and left operand are swaped }
  294. { against the original order }
  295. swaped : boolean;
  296. constructor init(l,r : pnode);
  297. end;
  298. {$ifdef dummy}
  299. case treetype : ttreetyp of
  300. addn : (use_strconcat : boolean;string_typ : tstringtype);
  301. callparan : (is_colon_para : boolean;exact_match_found : boolean);
  302. assignn : (assigntyp : tassigntyp;concat_string : boolean);
  303. calln : (symtableprocentry : psym;
  304. symtableproc : psymtable;procdefinition : pprocdef;
  305. methodpointer : ptree;
  306. no_check,unit_specific,return_value_used : boolean);
  307. ordconstn : (value : longint);
  308. realconstn : (value_real : bestreal;lab_real : plabel;realtyp : tait);
  309. fixconstn : (value_fix: longint);
  310. funcretn : (funcretprocinfo : pointer;retdef : pdef);
  311. subscriptn : (vs : pvarsym);
  312. vecn : (memindex,memseg:boolean;callunique : boolean);
  313. stringconstn : (value_str : pchar;length : longint; lab_str : plabel;stringtype : tstringtype);
  314. typeconvn : (convtyp : tconverttype;explizit : boolean);
  315. typen : (typenodetype : pdef);
  316. inlinen : (inlinenumber : byte;inlineconst:boolean);
  317. procinlinen : (inlineprocdef : pprocdef;
  318. retoffset,para_offset,para_size : longint);
  319. setconstn : (value_set : pconstset;lab_set:plabel);
  320. loopn : (t1,t2 : ptree;backward : boolean);
  321. casen : (nodes : pcaserecord;elseblock : ptree);
  322. labeln,goton : (labelnr : plabel);
  323. withn : (withsymtable : psymtable;tablecount : longint);
  324. onn : (exceptsymtable : psymtable;excepttype : pobjectdef);
  325. arrayconstructn : (cargs,cargswap: boolean);
  326. {$endif dummy}
  327. function gennode(t : ttreetyp;l,r : ptree) : ptree;
  328. function genlabelnode(t : ttreetyp;nr : pasmlabel) : ptree;
  329. function genloadnode(v : pvarsym;st : psymtable) : ptree;
  330. function genloadcallnode(v: pprocsym;st: psymtable): ptree;
  331. function gensinglenode(t : ttreetyp;l : ptree) : ptree;
  332. function gensubscriptnode(varsym : pvarsym;l : ptree) : ptree;
  333. function genordinalconstnode(v : longint;def : pdef) : ptree;
  334. function genfixconstnode(v : longint;def : pdef) : ptree;
  335. function genpointerconstnode(v : longint;def : pdef) : ptree;
  336. function gentypeconvnode(node : ptree;t : pdef) : ptree;
  337. function gentypenode(t : pdef;sym:ptypesym) : ptree;
  338. function gencallparanode(expr,next : ptree) : ptree;
  339. function genrealconstnode(v : bestreal;def : pdef) : ptree;
  340. function gencallnode(v : pprocsym;st : psymtable) : ptree;
  341. function genmethodcallnode(v : pprocsym;st : psymtable;mp : ptree) : ptree;
  342. function genloadmethodcallnode(v: pprocsym;st: psymtable; mp:ptree): ptree;
  343. { allow pchar or string for defining a pchar node }
  344. function genstringconstnode(const s : string) : ptree;
  345. { length is required for ansistrings }
  346. function genpcharconstnode(s : pchar;length : longint) : ptree;
  347. { helper routine for conststring node }
  348. function getpcharcopy(p : ptree) : pchar;
  349. function genzeronode(t : ttreetyp) : ptree;
  350. function geninlinenode(number : byte;is_const:boolean;l : ptree) : ptree;
  351. function genprocinlinenode(callp,code : ptree) : ptree;
  352. function gentypedconstloadnode(sym : ptypedconstsym;st : psymtable) : ptree;
  353. function genenumnode(v : penumsym) : ptree;
  354. function genselfnode(_class : pdef) : ptree;
  355. function gensetconstnode(s : pconstset;settype : psetdef) : ptree;
  356. function genloopnode(t : ttreetyp;l,r,n1: ptree;back : boolean) : ptree;
  357. function genasmnode(p_asm : paasmoutput) : ptree;
  358. function gencasenode(l,r : ptree;nodes : pcaserecord) : ptree;
  359. function genwithnode(symtable : psymtable;l,r : ptree;count : longint) : ptree;
  360. function getcopy(p : ptree) : ptree;
  361. function equal_trees(t1,t2 : ptree) : boolean;
  362. procedure swaptree(p:Ptree);
  363. procedure disposetree(p : ptree);
  364. procedure putnode(p : ptree);
  365. function getnode : ptree;
  366. procedure set_file_line(from,_to : ptree);
  367. procedure set_tree_filepos(p : ptree;const filepos : tfileposinfo);
  368. procedure set_location(var destloc,sourceloc : tlocation);
  369. {$ifdef EXTDEBUG}
  370. procedure compare_trees(oldp,p : ptree);
  371. const
  372. maxfirstpasscount : longint = 0;
  373. { writes a complete tree, checks for nil }
  374. procedure writenode(n : pnode);
  375. {$endif EXTDEBUG}
  376. { sets the callunique flag, if the node is a vecn, }
  377. { takes care of type casts etc. }
  378. procedure set_unique(p : pnode);
  379. {
  380. type
  381. tvarstaterequire = (vsr_can_be_undefined,vsr_must_be_valid,
  382. vsr_is_used_after,vsr_must_be_valid_and_is_used_after); }
  383. { sets varsym varstate field correctly }
  384. procedure set_varstate(p : ptree;must_be_valid : boolean);
  385. { gibt den ordinalen Werten der Node zurueck oder falls sie }
  386. { keinen ordinalen Wert hat, wird ein Fehler erzeugt }
  387. function get_ordinal_value(p : ptree) : longint;
  388. function is_constnode(p : ptree) : boolean;
  389. { true, if p is a pointer to a const int value }
  390. function is_constintnode(p : ptree) : boolean;
  391. function is_constboolnode(p : ptree) : boolean;
  392. function is_constrealnode(p : ptree) : boolean;
  393. function is_constcharnode(p : ptree) : boolean;
  394. function str_length(p : ptree) : longint;
  395. function is_emptyset(p : ptree):boolean;
  396. {$I innr.inc}
  397. implementation
  398. uses
  399. systems,
  400. globals,verbose,files,types,cgbase;
  401. {$ifdef EXTDEBUG}
  402. const
  403. indention : string = '';
  404. procedure writenode(n : pnode);
  405. begin
  406. if assigned(n) then
  407. n^.dowrite
  408. else
  409. writeln(indention,'nil');
  410. end;
  411. {$endif EXTDEBUG}
  412. {****************************************************************************
  413. TNODE
  414. ****************************************************************************}
  415. constructor tnode.init;
  416. begin
  417. inherited init;
  418. treetype:=nothingn;
  419. { this allows easier error tracing }
  420. location.loc:=LOC_INVALID;
  421. { save local info }
  422. fileinfo:=aktfilepos;
  423. localswitches:=aktlocalswitches;
  424. resulttype:=nil;
  425. registersint:=0;
  426. registersfpu:=0;
  427. {$ifdef SUPPORT_MMX}
  428. registersmmx:=0;
  429. {$endif SUPPORT_MMX}
  430. flags:=[];
  431. end;
  432. destructor tnode.done;
  433. begin
  434. { reference info }
  435. if (location.loc in [LOC_MEM,LOC_REFERENCE]) and
  436. assigned(location.reference.symbol) then
  437. dispose(location.reference.symbol,done);
  438. {$ifdef EXTDEBUG}
  439. if firstpasscount>maxfirstpasscount then
  440. maxfirstpasscount:=firstpasscount;
  441. {$endif EXTDEBUG}
  442. end;
  443. procedure tnode.pass_1;
  444. begin
  445. if not(assigned(resulttype)) then
  446. det_resulttype;
  447. det_temp;
  448. end;
  449. procedure tnode.det_resulttype;
  450. begin
  451. abstract;
  452. end;
  453. procedure tnode.det_temp;
  454. begin
  455. abstract;
  456. end;
  457. procedure tnode.secondpass;
  458. begin
  459. abstract;
  460. end;
  461. procedure tnode.concattolist(l : plinkedlist);
  462. begin
  463. l^.concat(@self);
  464. end;
  465. function tnode.ischild(p : pnode) : boolean;
  466. begin
  467. ischild:=false;
  468. end;
  469. {$ifdef EXTDEBUG}
  470. procedure tnode.dowrite;
  471. const treetype2str : array[ttreetyp] of string[20] = (
  472. 'addn',
  473. 'muln',
  474. 'subn',
  475. 'divn',
  476. 'symdifn',
  477. 'modn',
  478. 'assignn',
  479. 'loadn',
  480. 'rangen',
  481. 'ltn',
  482. 'lten',
  483. 'gtn',
  484. 'gten',
  485. 'equaln',
  486. 'unequaln',
  487. 'inn',
  488. 'orn',
  489. 'xorn',
  490. 'shrn',
  491. 'shln',
  492. 'slashn',
  493. 'andn',
  494. 'subscriptn',
  495. 'derefn',
  496. 'addrn',
  497. 'doubleaddrn',
  498. 'ordconstn',
  499. 'typeconvn',
  500. 'calln',
  501. 'callparan',
  502. 'realconstn',
  503. 'fixconstn',
  504. 'umminusn',
  505. 'asmn',
  506. 'vecn',
  507. 'stringconstn',
  508. 'funcretn',
  509. 'selfn',
  510. 'notn',
  511. 'inlinen',
  512. 'niln',
  513. 'errorn',
  514. 'typen',
  515. 'hnewn',
  516. 'hdisposen',
  517. 'newn',
  518. 'simpledisposen',
  519. 'setelementn',
  520. 'setconstn',
  521. 'blockn',
  522. 'statementn',
  523. 'loopn',
  524. 'ifn',
  525. 'breakn',
  526. 'continuen',
  527. 'repeatn',
  528. 'whilen',
  529. 'forn',
  530. 'exitn',
  531. 'withn',
  532. 'casen',
  533. 'labeln',
  534. 'goton',
  535. 'simplenewn',
  536. 'tryexceptn',
  537. 'raisen',
  538. 'switchesn',
  539. 'tryfinallyn',
  540. 'onn',
  541. 'isn',
  542. 'asn',
  543. 'caretn',
  544. 'failn',
  545. 'starstarn',
  546. 'procinlinen',
  547. 'arrayconstructn',
  548. 'arrayconstructrangen',
  549. 'nothingn',
  550. 'loadvmtn',
  551. 'pointerconstn');
  552. begin
  553. write(indention,'(',treetype2str[treetype]);
  554. end;
  555. {$endif EXTDEBUG}
  556. {****************************************************************************
  557. TUNARYNODE
  558. ****************************************************************************}
  559. constructor tunarynode.init(l : pnode);
  560. begin
  561. inherited init;
  562. left:=l;
  563. end;
  564. {$ifdef extdebug}
  565. procedure tunarynode.dowrite;
  566. begin
  567. inherited dowrite;
  568. writeln(',');
  569. writenode(left);
  570. writeln(')');
  571. dec(byte(indention[0]),2);
  572. end;
  573. {$endif}
  574. procedure tunarynode.concattolist(l : plinkedlist);
  575. begin
  576. left^.parent:=@self;
  577. left^.concattolist(l);
  578. inherited concattolist(l);
  579. end;
  580. function tunarynode.ischild(p : pnode) : boolean;
  581. begin
  582. ischild:=p=left;
  583. end;
  584. procedure tunarynode.det_resulttype;
  585. begin
  586. left^.det_resulttype;
  587. end;
  588. procedure tunarynode.det_temp;
  589. begin
  590. left^.det_temp;
  591. end;
  592. {****************************************************************************
  593. TBINARYNODE
  594. ****************************************************************************}
  595. constructor tbinarynode.init(l,r : pnode);
  596. begin
  597. inherited init(l);
  598. right:=r
  599. end;
  600. procedure tbinarynode.concattolist(l : plinkedlist);
  601. begin
  602. { we could change that depending on the number of }
  603. { required registers }
  604. left^.parent:=@self;
  605. left^.concattolist(l);
  606. left^.parent:=@self;
  607. left^.concattolist(l);
  608. inherited concattolist(l);
  609. end;
  610. function tbinarynode.ischild(p : pnode) : boolean;
  611. begin
  612. ischild:=(p=right) or (p=right);
  613. end;
  614. procedure tbinarynode.det_resulttype;
  615. begin
  616. left^.det_resulttype;
  617. right^.det_resulttype;
  618. end;
  619. procedure tbinarynode.det_temp;
  620. begin
  621. left^.det_temp;
  622. right^.det_temp;
  623. end;
  624. {****************************************************************************
  625. TBINOPYNODE
  626. ****************************************************************************}
  627. constructor tbinopnode.init(l,r : pnode);
  628. begin
  629. inherited init(l,r);
  630. swaped:=false;
  631. end;
  632. {$ifdef dummy}
  633. { clean up the contents of a node }
  634. case p^.treetype of
  635. asmn : if assigned(p^.p_asm) then
  636. dispose(p^.p_asm,done);
  637. stringconstn : begin
  638. ansistringdispose(p^.value_str,p^.length);
  639. end;
  640. setconstn : begin
  641. if assigned(p^.value_set) then
  642. dispose(p^.value_set);
  643. end;
  644. end;
  645. {$endif dummy}
  646. procedure deletecaselabels(p : pcaserecord);
  647. begin
  648. if assigned(p^.greater) then
  649. deletecaselabels(p^.greater);
  650. if assigned(p^.less) then
  651. deletecaselabels(p^.less);
  652. freelabel(p^._at);
  653. if p^.firstlabel then
  654. freelabel(p^.statement);
  655. dispose(p);
  656. end;
  657. procedure swaptree(p:Ptree);
  658. var swapp:Ptree;
  659. begin
  660. swapp:=p^.right;
  661. p^.right:=p^.left;
  662. p^.left:=swapp;
  663. p^.swaped:=not(p^.swaped);
  664. end;
  665. function gennode(t : ttreetyp;l,r : ptree) : ptree;
  666. var
  667. p : ptree;
  668. begin
  669. p:=getnode;
  670. p^.disposetyp:=dt_leftright;
  671. p^.treetype:=t;
  672. p^.left:=l;
  673. p^.right:=r;
  674. p^.registers32:=0;
  675. { p^.registers16:=0;
  676. p^.registers8:=0; }
  677. p^.registersfpu:=0;
  678. {$ifdef SUPPORT_MMX}
  679. p^.registersmmx:=0;
  680. {$endif SUPPORT_MMX}
  681. p^.resulttype:=nil;
  682. gennode:=p;
  683. end;
  684. procedure disposetree(p : ptree);
  685. var
  686. symt : psymtable;
  687. i : longint;
  688. begin
  689. if not(assigned(p)) then
  690. exit;
  691. case p^.disposetyp of
  692. dt_leftright :
  693. begin
  694. if assigned(p^.left) then
  695. disposetree(p^.left);
  696. if assigned(p^.right) then
  697. disposetree(p^.right);
  698. end;
  699. dt_leftrighthigh :
  700. begin
  701. if assigned(p^.left) then
  702. disposetree(p^.left);
  703. if assigned(p^.right) then
  704. disposetree(p^.right);
  705. if assigned(p^.hightree) then
  706. disposetree(p^.hightree);
  707. end;
  708. dt_leftrightmethod :
  709. begin
  710. if assigned(p^.left) then
  711. disposetree(p^.left);
  712. if assigned(p^.right) then
  713. disposetree(p^.right);
  714. if assigned(p^.methodpointer) then
  715. disposetree(p^.methodpointer);
  716. end;
  717. dt_case :
  718. begin
  719. if assigned(p^.left) then
  720. disposetree(p^.left);
  721. if assigned(p^.right) then
  722. disposetree(p^.right);
  723. if assigned(p^.nodes) then
  724. deletecaselabels(p^.nodes);
  725. if assigned(p^.elseblock) then
  726. disposetree(p^.elseblock);
  727. end;
  728. dt_nothing : ;
  729. dt_left :
  730. if assigned(p^.left) then
  731. disposetree(p^.left);
  732. dt_mbleft :
  733. if assigned(p^.left) then
  734. disposetree(p^.left);
  735. dt_mbleft_and_method :
  736. begin
  737. if assigned(p^.left) then disposetree(p^.left);
  738. disposetree(p^.methodpointer);
  739. end;
  740. dt_typeconv : disposetree(p^.left);
  741. dt_inlinen :
  742. if assigned(p^.left) then
  743. disposetree(p^.left);
  744. dt_loop :
  745. begin
  746. if assigned(p^.left) then
  747. disposetree(p^.left);
  748. if assigned(p^.right) then
  749. disposetree(p^.right);
  750. if assigned(p^.t1) then
  751. disposetree(p^.t1);
  752. if assigned(p^.t2) then
  753. disposetree(p^.t2);
  754. end;
  755. dt_onn:
  756. begin
  757. if assigned(p^.left) then
  758. disposetree(p^.left);
  759. if assigned(p^.right) then
  760. disposetree(p^.right);
  761. if assigned(p^.exceptsymtable) then
  762. dispose(p^.exceptsymtable,done);
  763. end;
  764. dt_with :
  765. begin
  766. if assigned(p^.left) then
  767. disposetree(p^.left);
  768. if assigned(p^.right) then
  769. disposetree(p^.right);
  770. symt:=p^.withsymtable;
  771. for i:=1 to p^.tablecount do
  772. begin
  773. if assigned(symt) then
  774. begin
  775. p^.withsymtable:=pwithsymtable(symt^.next);
  776. dispose(symt,done);
  777. end;
  778. symt:=p^.withsymtable;
  779. end;
  780. end;
  781. else internalerror(1209995);
  782. end;
  783. putnode(p);
  784. end;
  785. procedure set_file_line(from,_to : ptree);
  786. begin
  787. if assigned(from) then
  788. _to^.fileinfo:=from^.fileinfo;
  789. end;
  790. procedure set_tree_filepos(p : ptree;const filepos : tfileposinfo);
  791. begin
  792. p^.fileinfo:=filepos;
  793. end;
  794. function getnode : ptree;
  795. var
  796. hp : ptree;
  797. begin
  798. new(hp);
  799. { makes error tracking easier }
  800. fillchar(hp^,sizeof(ttree),0);
  801. { reset }
  802. hp^.location.loc:=LOC_INVALID;
  803. { save local info }
  804. hp^.fileinfo:=aktfilepos;
  805. hp^.localswitches:=aktlocalswitches;
  806. getnode:=hp;
  807. end;
  808. procedure putnode(p : ptree);
  809. begin
  810. { clean up the contents of a node }
  811. case p^.treetype of
  812. asmn : if assigned(p^.p_asm) then
  813. dispose(p^.p_asm,done);
  814. stringconstn : begin
  815. ansistringdispose(p^.value_str,p^.length);
  816. end;
  817. setconstn : begin
  818. if assigned(p^.value_set) then
  819. dispose(p^.value_set);
  820. end;
  821. end;
  822. { reference info }
  823. if (p^.location.loc in [LOC_MEM,LOC_REFERENCE]) and
  824. assigned(p^.location.reference.symbol) then
  825. dispose(p^.location.reference.symbol,done);
  826. {$ifdef extdebug}
  827. if p^.firstpasscount>maxfirstpasscount then
  828. maxfirstpasscount:=p^.firstpasscount;
  829. {$endif extdebug}
  830. dispose(p);
  831. end;
  832. function getcopy(p : ptree) : ptree;
  833. var
  834. hp : ptree;
  835. begin
  836. hp:=getnode;
  837. hp^:=p^;
  838. if assigned(p^.location.reference.symbol) then
  839. hp^.location.reference.symbol:=p^.location.reference.symbol;
  840. case p^.disposetyp of
  841. dt_leftright :
  842. begin
  843. if assigned(p^.left) then
  844. hp^.left:=getcopy(p^.left);
  845. if assigned(p^.right) then
  846. hp^.right:=getcopy(p^.right);
  847. end;
  848. dt_nothing : ;
  849. dt_left :
  850. if assigned(p^.left) then
  851. hp^.left:=getcopy(p^.left);
  852. dt_mbleft :
  853. if assigned(p^.left) then
  854. hp^.left:=getcopy(p^.left);
  855. dt_mbleft_and_method :
  856. begin
  857. if assigned(p^.left) then
  858. hp^.left:=getcopy(p^.left);
  859. hp^.methodpointer:=getcopy(p^.methodpointer);
  860. end;
  861. dt_loop :
  862. begin
  863. if assigned(p^.left) then
  864. hp^.left:=getcopy(p^.left);
  865. if assigned(p^.right) then
  866. hp^.right:=getcopy(p^.right);
  867. if assigned(p^.t1) then
  868. hp^.t1:=getcopy(p^.t1);
  869. if assigned(p^.t2) then
  870. hp^.t2:=getcopy(p^.t2);
  871. end;
  872. dt_typeconv : hp^.left:=getcopy(p^.left);
  873. dt_inlinen :
  874. if assigned(p^.left) then
  875. hp^.left:=getcopy(p^.left);
  876. else internalerror(11);
  877. end;
  878. { now check treetype }
  879. case p^.treetype of
  880. stringconstn : begin
  881. hp^.value_str:=getpcharcopy(p);
  882. hp^.length:=p^.length;
  883. end;
  884. setconstn : begin
  885. new(hp^.value_set);
  886. hp^.value_set:=p^.value_set;
  887. end;
  888. end;
  889. getcopy:=hp;
  890. end;
  891. function genloadnode(v : pvarsym;st : psymtable) : ptree;
  892. var
  893. p : ptree;
  894. begin
  895. p:=getnode;
  896. p^.registers32:=0;
  897. { p^.registers16:=0;
  898. p^.registers8:=0; }
  899. p^.registersfpu:=0;
  900. {$ifdef SUPPORT_MMX}
  901. p^.registersmmx:=0;
  902. {$endif SUPPORT_MMX}
  903. p^.treetype:=loadn;
  904. p^.resulttype:=v^.vartype.def;
  905. p^.symtableentry:=v;
  906. p^.symtable:=st;
  907. p^.is_first := False;
  908. { method pointer load nodes can use the left subtree }
  909. p^.disposetyp:=dt_left;
  910. p^.left:=nil;
  911. genloadnode:=p;
  912. end;
  913. function genwithnode(symtable : psymtable;l,r : ptree;count : longint) : ptree;
  914. var
  915. p : ptree;
  916. begin
  917. p:=getnode;
  918. p^.disposetyp:=dt_with;
  919. p^.treetype:=withn;
  920. p^.left:=l;
  921. p^.right:=r;
  922. p^.registers32:=0;
  923. { p^.registers16:=0;
  924. p^.registers8:=0; }
  925. p^.registersfpu:=0;
  926. {$ifdef SUPPORT_MMX}
  927. p^.registersmmx:=0;
  928. {$endif SUPPORT_MMX}
  929. p^.resulttype:=nil;
  930. p^.withsymtable:=pwithsymtable(symtable);
  931. p^.tablecount:=count;
  932. set_file_line(l,p);
  933. genwithnode:=p;
  934. end;
  935. function genfixconstnode(v : longint;def : pdef) : ptree;
  936. var
  937. p : ptree;
  938. begin
  939. p:=getnode;
  940. p^.disposetyp:=dt_nothing;
  941. p^.treetype:=fixconstn;
  942. p^.registers32:=0;
  943. { p^.registers16:=0;
  944. p^.registers8:=0; }
  945. p^.registersfpu:=0;
  946. {$ifdef SUPPORT_MMX}
  947. p^.registersmmx:=0;
  948. {$endif SUPPORT_MMX}
  949. p^.resulttype:=def;
  950. p^.value:=v;
  951. genfixconstnode:=p;
  952. end;
  953. function gencallparanode(expr,next : ptree) : ptree;
  954. var
  955. p : ptree;
  956. begin
  957. p:=getnode;
  958. p^.disposetyp:=dt_leftright;
  959. p^.treetype:=callparan;
  960. p^.left:=expr;
  961. p^.right:=next;
  962. p^.registers32:=0;
  963. { p^.registers16:=0;
  964. p^.registers8:=0; }
  965. {$ifdef SUPPORT_MMX}
  966. p^.registersmmx:=0;
  967. {$endif SUPPORT_MMX}
  968. p^.registersfpu:=0;
  969. p^.resulttype:=nil;
  970. p^.exact_match_found:=false;
  971. p^.is_colon_para:=false;
  972. set_file_line(expr,p);
  973. gencallparanode:=p;
  974. end;
  975. function gencasenode(l,r : ptree;nodes : pcaserecord) : ptree;
  976. var
  977. p : ptree;
  978. begin
  979. p:=getnode;
  980. p^.disposetyp:=dt_case;
  981. p^.treetype:=casen;
  982. p^.left:=l;
  983. p^.right:=r;
  984. p^.nodes:=nodes;
  985. p^.registers32:=0;
  986. p^.registersfpu:=0;
  987. {$ifdef SUPPORT_MMX}
  988. p^.registersmmx:=0;
  989. {$endif SUPPORT_MMX}
  990. p^.resulttype:=nil;
  991. set_file_line(l,p);
  992. gencasenode:=p;
  993. end;
  994. function genloopnode(t : ttreetyp;l,r,n1 : ptree;back : boolean) : ptree;
  995. var
  996. p : ptree;
  997. begin
  998. p:=getnode;
  999. p^.disposetyp:=dt_loop;
  1000. p^.treetype:=t;
  1001. p^.left:=l;
  1002. p^.right:=r;
  1003. p^.t1:=n1;
  1004. p^.t2:=nil;
  1005. p^.registers32:=0;
  1006. p^.backward:=back;
  1007. { p^.registers16:=0;
  1008. p^.registers8:=0; }
  1009. p^.registersfpu:=0;
  1010. {$ifdef SUPPORT_MMX}
  1011. p^.registersmmx:=0;
  1012. {$endif SUPPORT_MMX}
  1013. p^.resulttype:=nil;
  1014. set_file_line(l,p);
  1015. genloopnode:=p;
  1016. end;
  1017. function genordinalconstnode(v : longint;def : pdef) : ptree;
  1018. var
  1019. p : ptree;
  1020. begin
  1021. p:=getnode;
  1022. p^.disposetyp:=dt_nothing;
  1023. p^.treetype:=ordconstn;
  1024. p^.registers32:=0;
  1025. { p^.registers16:=0;
  1026. p^.registers8:=0; }
  1027. p^.registersfpu:=0;
  1028. {$ifdef SUPPORT_MMX}
  1029. p^.registersmmx:=0;
  1030. {$endif SUPPORT_MMX}
  1031. p^.resulttype:=def;
  1032. p^.value:=v;
  1033. if p^.resulttype^.deftype=orddef then
  1034. testrange(p^.resulttype,p^.value);
  1035. genordinalconstnode:=p;
  1036. end;
  1037. function genenumnode(v : penumsym) : ptree;
  1038. var
  1039. p : ptree;
  1040. begin
  1041. p:=getnode;
  1042. p^.disposetyp:=dt_nothing;
  1043. p^.treetype:=ordconstn;
  1044. p^.registers32:=0;
  1045. { p^.registers16:=0;
  1046. p^.registers8:=0; }
  1047. p^.registersfpu:=0;
  1048. {$ifdef SUPPORT_MMX}
  1049. p^.registersmmx:=0;
  1050. {$endif SUPPORT_MMX}
  1051. p^.resulttype:=v^.definition;
  1052. p^.value:=v^.value;
  1053. testrange(p^.resulttype,p^.value);
  1054. genenumnode:=p;
  1055. end;
  1056. function genrealconstnode(v : bestreal;def : pdef) : ptree;
  1057. var
  1058. p : ptree;
  1059. begin
  1060. p:=getnode;
  1061. p^.disposetyp:=dt_nothing;
  1062. p^.treetype:=realconstn;
  1063. p^.registers32:=0;
  1064. { p^.registers16:=0;
  1065. p^.registers8:=0; }
  1066. p^.registersfpu:=0;
  1067. {$ifdef SUPPORT_MMX}
  1068. p^.registersmmx:=0;
  1069. {$endif SUPPORT_MMX}
  1070. p^.resulttype:=def;
  1071. p^.value_real:=v;
  1072. p^.lab_real:=nil;
  1073. genrealconstnode:=p;
  1074. end;
  1075. function genstringconstnode(const s : string) : ptree;
  1076. var
  1077. p : ptree;
  1078. l : longint;
  1079. begin
  1080. p:=getnode;
  1081. p^.disposetyp:=dt_nothing;
  1082. p^.treetype:=stringconstn;
  1083. p^.registers32:=0;
  1084. { p^.registers16:=0;
  1085. p^.registers8:=0; }
  1086. p^.registersfpu:=0;
  1087. {$ifdef SUPPORT_MMX}
  1088. p^.registersmmx:=0;
  1089. {$endif SUPPORT_MMX}
  1090. l:=length(s);
  1091. p^.length:=l;
  1092. { stringdup write even past a #0 }
  1093. getmem(p^.value_str,l+1);
  1094. move(s[1],p^.value_str^,l);
  1095. p^.value_str[l]:=#0;
  1096. p^.lab_str:=nil;
  1097. if cs_ansistrings in aktlocalswitches then
  1098. begin
  1099. p^.stringtype:=st_ansistring;
  1100. p^.resulttype:=cansistringdef;
  1101. end
  1102. else
  1103. begin
  1104. p^.stringtype:=st_shortstring;
  1105. p^.resulttype:=cshortstringdef;
  1106. end;
  1107. genstringconstnode:=p;
  1108. end;
  1109. function getpcharcopy(p : ptree) : pchar;
  1110. var
  1111. pc : pchar;
  1112. begin
  1113. pc:=nil;
  1114. getmem(pc,p^.length+1);
  1115. if pc=nil then
  1116. Message(general_f_no_memory_left);
  1117. move(p^.value_str^,pc^,p^.length+1);
  1118. getpcharcopy:=pc;
  1119. end;
  1120. function genpcharconstnode(s : pchar;length : longint) : ptree;
  1121. var
  1122. p : ptree;
  1123. begin
  1124. p:=getnode;
  1125. p^.disposetyp:=dt_nothing;
  1126. p^.treetype:=stringconstn;
  1127. p^.registers32:=0;
  1128. { p^.registers16:=0;
  1129. p^.registers8:=0; }
  1130. p^.registersfpu:=0;
  1131. {$ifdef SUPPORT_MMX}
  1132. p^.registersmmx:=0;
  1133. {$endif SUPPORT_MMX}
  1134. p^.resulttype:=cshortstringdef;
  1135. p^.length:=length;
  1136. p^.value_str:=s;
  1137. p^.lab_str:=nil;
  1138. genpcharconstnode:=p;
  1139. end;
  1140. function genpointerconstnode(v : longint;def : pdef) : ptree;
  1141. var
  1142. p : ptree;
  1143. begin
  1144. p:=getnode;
  1145. p^.disposetyp:=dt_nothing;
  1146. p^.treetype:=pointerconstn;
  1147. p^.registers32:=0;
  1148. { p^.registers16:=0;
  1149. p^.registers8:=0; }
  1150. p^.registersfpu:=0;
  1151. {$ifdef SUPPORT_MMX}
  1152. p^.registersmmx:=0;
  1153. {$endif SUPPORT_MMX}
  1154. p^.resulttype:=def;
  1155. p^.value:=v;
  1156. genpointerconstnode:=p;
  1157. end;
  1158. function gensinglenode(t : ttreetyp;l : ptree) : ptree;
  1159. var
  1160. p : ptree;
  1161. begin
  1162. p:=getnode;
  1163. p^.disposetyp:=dt_left;
  1164. p^.treetype:=t;
  1165. p^.left:=l;
  1166. p^.registers32:=0;
  1167. { p^.registers16:=0;
  1168. p^.registers8:=0; }
  1169. p^.registersfpu:=0;
  1170. {$ifdef SUPPORT_MMX}
  1171. p^.registersmmx:=0;
  1172. {$endif SUPPORT_MMX}
  1173. p^.resulttype:=nil;
  1174. gensinglenode:=p;
  1175. end;
  1176. function genasmnode(p_asm : paasmoutput) : ptree;
  1177. var
  1178. p : ptree;
  1179. begin
  1180. p:=getnode;
  1181. p^.disposetyp:=dt_nothing;
  1182. p^.treetype:=asmn;
  1183. p^.registers32:=4;
  1184. p^.p_asm:=p_asm;
  1185. p^.object_preserved:=false;
  1186. { p^.registers16:=0;
  1187. p^.registers8:=0; }
  1188. p^.registersfpu:=8;
  1189. {$ifdef SUPPORT_MMX}
  1190. p^.registersmmx:=8;
  1191. {$endif SUPPORT_MMX}
  1192. p^.resulttype:=nil;
  1193. genasmnode:=p;
  1194. end;
  1195. function genloadcallnode(v: pprocsym;st: psymtable): ptree;
  1196. var
  1197. p : ptree;
  1198. begin
  1199. p:=getnode;
  1200. p^.registers32:=0;
  1201. { p^.registers16:=0;
  1202. p^.registers8:=0; }
  1203. p^.registersfpu:=0;
  1204. {$ifdef SUPPORT_MMX}
  1205. p^.registersmmx:=0;
  1206. {$endif SUPPORT_MMX}
  1207. p^.treetype:=loadn;
  1208. p^.resulttype:=v^.definition;
  1209. p^.symtableentry:=v;
  1210. p^.symtable:=st;
  1211. p^.is_first := False;
  1212. p^.disposetyp:=dt_nothing;
  1213. genloadcallnode:=p;
  1214. end;
  1215. function gentypedconstloadnode(sym : ptypedconstsym;st : psymtable) : ptree;
  1216. var
  1217. p : ptree;
  1218. begin
  1219. p:=getnode;
  1220. p^.registers32:=0;
  1221. { p^.registers16:=0;
  1222. p^.registers8:=0; }
  1223. p^.registersfpu:=0;
  1224. {$ifdef SUPPORT_MMX}
  1225. p^.registersmmx:=0;
  1226. {$endif SUPPORT_MMX}
  1227. p^.treetype:=loadn;
  1228. p^.resulttype:=sym^.typedconsttype.def;
  1229. p^.symtableentry:=pvarsym(sym);
  1230. p^.symtable:=st;
  1231. p^.disposetyp:=dt_nothing;
  1232. gentypedconstloadnode:=p;
  1233. end;
  1234. function gentypeconvnode(node : ptree;t : pdef) : ptree;
  1235. var
  1236. p : ptree;
  1237. begin
  1238. p:=getnode;
  1239. p^.disposetyp:=dt_typeconv;
  1240. p^.treetype:=typeconvn;
  1241. p^.left:=node;
  1242. p^.registers32:=0;
  1243. { p^.registers16:=0;
  1244. p^.registers8:=0; }
  1245. p^.convtyp:=tc_equal;
  1246. p^.registersfpu:=0;
  1247. {$ifdef SUPPORT_MMX}
  1248. p^.registersmmx:=0;
  1249. {$endif SUPPORT_MMX}
  1250. p^.resulttype:=t;
  1251. p^.explizit:=false;
  1252. set_file_line(node,p);
  1253. gentypeconvnode:=p;
  1254. end;
  1255. function gencallnode(v : pprocsym;st : psymtable) : ptree;
  1256. var
  1257. p : ptree;
  1258. begin
  1259. p:=getnode;
  1260. p^.registers32:=0;
  1261. { p^.registers16:=0;
  1262. p^.registers8:=0; }
  1263. p^.registersfpu:=0;
  1264. {$ifdef SUPPORT_MMX}
  1265. p^.registersmmx:=0;
  1266. {$endif SUPPORT_MMX}
  1267. p^.treetype:=calln;
  1268. p^.symtableprocentry:=v;
  1269. p^.symtableproc:=st;
  1270. p^.unit_specific:=false;
  1271. p^.no_check:=false;
  1272. p^.return_value_used:=true;
  1273. p^.disposetyp := dt_leftright;
  1274. p^.methodpointer:=nil;
  1275. p^.left:=nil;
  1276. p^.right:=nil;
  1277. p^.procdefinition:=nil;
  1278. gencallnode:=p;
  1279. end;
  1280. function genmethodcallnode(v : pprocsym;st : psymtable;mp : ptree) : ptree;
  1281. var
  1282. p : ptree;
  1283. begin
  1284. p:=getnode;
  1285. p^.registers32:=0;
  1286. { p^.registers16:=0;
  1287. p^.registers8:=0; }
  1288. p^.registersfpu:=0;
  1289. {$ifdef SUPPORT_MMX}
  1290. p^.registersmmx:=0;
  1291. {$endif SUPPORT_MMX}
  1292. p^.treetype:=calln;
  1293. p^.return_value_used:=true;
  1294. p^.symtableprocentry:=v;
  1295. p^.symtableproc:=st;
  1296. p^.disposetyp:=dt_mbleft_and_method;
  1297. p^.left:=nil;
  1298. p^.right:=nil;
  1299. p^.methodpointer:=mp;
  1300. p^.procdefinition:=nil;
  1301. genmethodcallnode:=p;
  1302. end;
  1303. function gensubscriptnode(varsym : pvarsym;l : ptree) : ptree;
  1304. var
  1305. p : ptree;
  1306. begin
  1307. p:=getnode;
  1308. p^.disposetyp:=dt_left;
  1309. p^.treetype:=subscriptn;
  1310. p^.left:=l;
  1311. p^.registers32:=0;
  1312. p^.vs:=varsym;
  1313. { p^.registers16:=0;
  1314. p^.registers8:=0; }
  1315. p^.registersfpu:=0;
  1316. {$ifdef SUPPORT_MMX}
  1317. p^.registersmmx:=0;
  1318. {$endif SUPPORT_MMX}
  1319. p^.resulttype:=nil;
  1320. gensubscriptnode:=p;
  1321. end;
  1322. function genzeronode(t : ttreetyp) : ptree;
  1323. var
  1324. p : ptree;
  1325. begin
  1326. p:=getnode;
  1327. p^.disposetyp:=dt_nothing;
  1328. p^.treetype:=t;
  1329. p^.registers32:=0;
  1330. { p^.registers16:=0;
  1331. p^.registers8:=0; }
  1332. p^.registersfpu:=0;
  1333. {$ifdef SUPPORT_MMX}
  1334. p^.registersmmx:=0;
  1335. {$endif SUPPORT_MMX}
  1336. p^.resulttype:=nil;
  1337. genzeronode:=p;
  1338. end;
  1339. function genlabelnode(t : ttreetyp;nr : pasmlabel) : ptree;
  1340. var
  1341. p : ptree;
  1342. begin
  1343. p:=getnode;
  1344. p^.disposetyp:=dt_nothing;
  1345. p^.treetype:=t;
  1346. p^.registers32:=0;
  1347. { p^.registers16:=0;
  1348. p^.registers8:=0; }
  1349. p^.registersfpu:=0;
  1350. {$ifdef SUPPORT_MMX}
  1351. p^.registersmmx:=0;
  1352. {$endif SUPPORT_MMX}
  1353. p^.resulttype:=nil;
  1354. { for security }
  1355. { nr^.is_used:=true;}
  1356. p^.labelnr:=nr;
  1357. genlabelnode:=p;
  1358. end;
  1359. function genselfnode(_class : pdef) : ptree;
  1360. var
  1361. p : ptree;
  1362. begin
  1363. p:=getnode;
  1364. p^.disposetyp:=dt_nothing;
  1365. p^.treetype:=selfn;
  1366. p^.registers32:=0;
  1367. { p^.registers16:=0;
  1368. p^.registers8:=0; }
  1369. p^.registersfpu:=0;
  1370. {$ifdef SUPPORT_MMX}
  1371. p^.registersmmx:=0;
  1372. {$endif SUPPORT_MMX}
  1373. p^.resulttype:=_class;
  1374. genselfnode:=p;
  1375. end;
  1376. function geninlinenode(number : byte;is_const:boolean;l : ptree) : ptree;
  1377. var
  1378. p : ptree;
  1379. begin
  1380. p:=getnode;
  1381. p^.disposetyp:=dt_inlinen;
  1382. p^.treetype:=inlinen;
  1383. p^.left:=l;
  1384. p^.inlinenumber:=number;
  1385. p^.inlineconst:=is_const;
  1386. p^.registers32:=0;
  1387. { p^.registers16:=0;
  1388. p^.registers8:=0; }
  1389. p^.registersfpu:=0;
  1390. {$ifdef SUPPORT_MMX}
  1391. p^.registersmmx:=0;
  1392. {$endif SUPPORT_MMX}
  1393. p^.resulttype:=nil;
  1394. geninlinenode:=p;
  1395. end;
  1396. function gentypenode(t : pdef;sym:ptypesym) : ptree;
  1397. var
  1398. p : ptree;
  1399. begin
  1400. p:=getnode;
  1401. p^.disposetyp:=dt_nothing;
  1402. p^.treetype:=typen;
  1403. p^.registers32:=0;
  1404. { p^.registers16:=0;
  1405. p^.registers8:=0; }
  1406. p^.registersfpu:=0;
  1407. {$ifdef SUPPORT_MMX}
  1408. p^.registersmmx:=0;
  1409. {$endif SUPPORT_MMX}
  1410. p^.resulttype:=generrordef;
  1411. p^.typenodetype:=t;
  1412. p^.typenodesym:=sym;
  1413. gentypenode:=p;
  1414. end;
  1415. function genloadmethodcallnode(v: pprocsym;st: psymtable; mp:ptree): ptree;
  1416. var
  1417. p : ptree;
  1418. begin
  1419. p:=getnode;
  1420. p^.registers32:=0;
  1421. { p^.registers16:=0;
  1422. p^.registers8:=0; }
  1423. p^.registersfpu:=0;
  1424. {$ifdef SUPPORT_MMX}
  1425. p^.registersmmx:=0;
  1426. {$endif SUPPORT_MMX}
  1427. p^.treetype:=loadn;
  1428. p^.left:=nil;
  1429. p^.resulttype:=v^.definition;
  1430. p^.symtableentry:=v;
  1431. p^.symtable:=st;
  1432. p^.is_first := False;
  1433. p^.disposetyp:=dt_left;
  1434. p^.left:=mp;
  1435. genloadmethodcallnode:=p;
  1436. end;
  1437. { uses the callnode to create the new procinline node }
  1438. function genprocinlinenode(callp,code : ptree) : ptree;
  1439. var
  1440. p : ptree;
  1441. begin
  1442. genprocinlinenode:=p;
  1443. end;
  1444. function gensetconstnode(s : pconstset;settype : psetdef) : ptree;
  1445. var
  1446. p : ptree;
  1447. begin
  1448. p:=getnode;
  1449. p^.disposetyp:=dt_nothing;
  1450. p^.treetype:=setconstn;
  1451. p^.registers32:=0;
  1452. p^.registersfpu:=0;
  1453. {$ifdef SUPPORT_MMX}
  1454. p^.registersmmx:=0;
  1455. {$endif SUPPORT_MMX}
  1456. p^.resulttype:=settype;
  1457. p^.left:=nil;
  1458. new(p^.value_set);
  1459. p^.value_set^:=s^;
  1460. gensetconstnode:=p;
  1461. end;
  1462. procedure set_varstate(p : ptree;must_be_valid : boolean);
  1463. begin
  1464. if not assigned(p) then
  1465. exit
  1466. else
  1467. begin
  1468. if p^.varstateset then
  1469. exit;
  1470. case p^.treetype of
  1471. typeconvn,subscriptn :
  1472. set_varstate(p^.left,must_be_valid);
  1473. vecn:
  1474. begin
  1475. if (p^.left^.resulttype^.deftype in [stringdef,arraydef]) then
  1476. set_varstate(p^.left,must_be_valid)
  1477. else
  1478. set_varstate(p^.left,true);
  1479. set_varstate(p^.right,true);
  1480. end;
  1481. { do not parse calln }
  1482. calln : ;
  1483. callparan:
  1484. begin
  1485. set_varstate(p^.left,must_be_valid);
  1486. set_varstate(p^.right,must_be_valid);
  1487. end;
  1488. loadn :
  1489. if (p^.symtableentry^.typ=varsym) then
  1490. begin
  1491. if must_be_valid and p^.is_first then
  1492. begin
  1493. if (pvarsym(p^.symtableentry)^.varstate=vs_declared_and_first_found) or
  1494. (pvarsym(p^.symtableentry)^.varstate=vs_set_but_first_not_passed) then
  1495. if (assigned(pvarsym(p^.symtableentry)^.owner) and
  1496. assigned(aktprocsym) and
  1497. (pvarsym(p^.symtableentry)^.owner = aktprocsym^.definition^.localst)) then
  1498. begin
  1499. if p^.symtable^.symtabletype=localsymtable then
  1500. Message1(sym_n_uninitialized_local_variable,pvarsym(p^.symtableentry)^.name)
  1501. else
  1502. Message1(sym_n_uninitialized_variable,pvarsym(p^.symtableentry)^.name);
  1503. end;
  1504. end;
  1505. if (p^.is_first) then
  1506. begin
  1507. if pvarsym(p^.symtableentry)^.varstate=vs_declared_and_first_found then
  1508. { this can only happen at left of an assignment, no ? PM }
  1509. if (parsing_para_level=0) and not must_be_valid then
  1510. pvarsym(p^.symtableentry)^.varstate:=vs_assigned
  1511. else
  1512. pvarsym(p^.symtableentry)^.varstate:=vs_used;
  1513. if pvarsym(p^.symtableentry)^.varstate=vs_set_but_first_not_passed then
  1514. pvarsym(p^.symtableentry)^.varstate:=vs_used;
  1515. p^.is_first:=false;
  1516. end
  1517. else
  1518. begin
  1519. if (pvarsym(p^.symtableentry)^.varstate=vs_assigned) and
  1520. (must_be_valid or (parsing_para_level>0) or
  1521. (p^.resulttype^.deftype=procvardef)) then
  1522. pvarsym(p^.symtableentry)^.varstate:=vs_used;
  1523. if (pvarsym(p^.symtableentry)^.varstate=vs_declared_and_first_found) and
  1524. (must_be_valid or (parsing_para_level>0) or
  1525. (p^.resulttype^.deftype=procvardef)) then
  1526. pvarsym(p^.symtableentry)^.varstate:=vs_set_but_first_not_passed;
  1527. end;
  1528. end;
  1529. funcretn:
  1530. begin
  1531. { no claim if setting higher return value_str }
  1532. if must_be_valid and
  1533. (procinfo=pprocinfo(p^.funcretprocinfo)) and
  1534. ((procinfo^.funcret_state=vs_declared) or
  1535. ((p^.is_first_funcret) and
  1536. (procinfo^.funcret_state=vs_declared_and_first_found))) then
  1537. begin
  1538. Message(sym_w_function_result_not_set);
  1539. { avoid multiple warnings }
  1540. procinfo^.funcret_state:=vs_assigned;
  1541. end;
  1542. if p^.is_first_funcret and not must_be_valid then
  1543. pprocinfo(p^.funcretprocinfo)^.funcret_state:=vs_assigned;
  1544. end;
  1545. else
  1546. begin
  1547. {internalerror(565656);}
  1548. end;
  1549. end;{case }
  1550. p^.varstateset:=true;
  1551. end;
  1552. end;
  1553. procedure set_location(var destloc,sourceloc : tlocation);
  1554. begin
  1555. destloc:= sourceloc;
  1556. end;
  1557. {$ifdef extdebug}
  1558. procedure compare_trees(oldp,p : ptree);
  1559. var
  1560. error_found : boolean;
  1561. begin
  1562. if oldp^.resulttype<>p^.resulttype then
  1563. begin
  1564. error_found:=true;
  1565. if is_equal(oldp^.resulttype,p^.resulttype) then
  1566. comment(v_debug,'resulttype fields are different but equal')
  1567. else
  1568. comment(v_warning,'resulttype fields are really different');
  1569. end;
  1570. if oldp^.treetype<>p^.treetype then
  1571. begin
  1572. comment(v_warning,'treetype field different');
  1573. error_found:=true;
  1574. end
  1575. else
  1576. comment(v_debug,' treetype '+tostr(longint(oldp^.treetype)));
  1577. if oldp^.error<>p^.error then
  1578. begin
  1579. comment(v_warning,'error field different');
  1580. error_found:=true;
  1581. end;
  1582. if oldp^.disposetyp<>p^.disposetyp then
  1583. begin
  1584. comment(v_warning,'disposetyp field different');
  1585. error_found:=true;
  1586. end;
  1587. { is true, if the right and left operand are swaped }
  1588. if oldp^.swaped<>p^.swaped then
  1589. begin
  1590. comment(v_warning,'swaped field different');
  1591. error_found:=true;
  1592. end;
  1593. { the location of the result of this node }
  1594. if oldp^.location.loc<>p^.location.loc then
  1595. begin
  1596. comment(v_warning,'location.loc field different');
  1597. error_found:=true;
  1598. end;
  1599. { the number of registers needed to evalute the node }
  1600. if oldp^.registers32<>p^.registers32 then
  1601. begin
  1602. comment(v_warning,'registers32 field different');
  1603. comment(v_warning,' old '+tostr(oldp^.registers32)+'<> new '+tostr(p^.registers32));
  1604. error_found:=true;
  1605. end;
  1606. if oldp^.registersfpu<>p^.registersfpu then
  1607. begin
  1608. comment(v_warning,'registersfpu field different');
  1609. error_found:=true;
  1610. end;
  1611. {$ifdef SUPPORT_MMX}
  1612. if oldp^.registersmmx<>p^.registersmmx then
  1613. begin
  1614. comment(v_warning,'registersmmx field different');
  1615. error_found:=true;
  1616. end;
  1617. {$endif SUPPORT_MMX}
  1618. if oldp^.left<>p^.left then
  1619. begin
  1620. comment(v_warning,'left field different');
  1621. error_found:=true;
  1622. end;
  1623. if oldp^.right<>p^.right then
  1624. begin
  1625. comment(v_warning,'right field different');
  1626. error_found:=true;
  1627. end;
  1628. if oldp^.fileinfo.line<>p^.fileinfo.line then
  1629. begin
  1630. comment(v_warning,'fileinfo.line field different');
  1631. error_found:=true;
  1632. end;
  1633. if oldp^.fileinfo.column<>p^.fileinfo.column then
  1634. begin
  1635. comment(v_warning,'fileinfo.column field different');
  1636. error_found:=true;
  1637. end;
  1638. if oldp^.fileinfo.fileindex<>p^.fileinfo.fileindex then
  1639. begin
  1640. comment(v_warning,'fileinfo.fileindex field different');
  1641. error_found:=true;
  1642. end;
  1643. if oldp^.localswitches<>p^.localswitches then
  1644. begin
  1645. comment(v_warning,'localswitches field different');
  1646. error_found:=true;
  1647. end;
  1648. {$ifdef extdebug}
  1649. if oldp^.firstpasscount<>p^.firstpasscount then
  1650. begin
  1651. comment(v_warning,'firstpasscount field different');
  1652. error_found:=true;
  1653. end;
  1654. {$endif extdebug}
  1655. if oldp^.treetype=p^.treetype then
  1656. case oldp^.treetype of
  1657. addn :
  1658. begin
  1659. if oldp^.use_strconcat<>p^.use_strconcat then
  1660. begin
  1661. comment(v_warning,'use_strconcat field different');
  1662. error_found:=true;
  1663. end;
  1664. if oldp^.string_typ<>p^.string_typ then
  1665. begin
  1666. comment(v_warning,'stringtyp field different');
  1667. error_found:=true;
  1668. end;
  1669. end;
  1670. callparan :
  1671. {(is_colon_para : boolean;exact_match_found : boolean);}
  1672. begin
  1673. if oldp^.is_colon_para<>p^.is_colon_para then
  1674. begin
  1675. comment(v_warning,'use_strconcat field different');
  1676. error_found:=true;
  1677. end;
  1678. if oldp^.exact_match_found<>p^.exact_match_found then
  1679. begin
  1680. comment(v_warning,'exact_match_found field different');
  1681. error_found:=true;
  1682. end;
  1683. end;
  1684. assignn :
  1685. {(assigntyp : tassigntyp;concat_string : boolean);}
  1686. begin
  1687. if oldp^.assigntyp<>p^.assigntyp then
  1688. begin
  1689. comment(v_warning,'assigntyp field different');
  1690. error_found:=true;
  1691. end;
  1692. if oldp^.concat_string<>p^.concat_string then
  1693. begin
  1694. comment(v_warning,'concat_string field different');
  1695. error_found:=true;
  1696. end;
  1697. end;
  1698. loadn :
  1699. {(symtableentry : psym;symtable : psymtable;
  1700. is_absolute,is_first : boolean);}
  1701. begin
  1702. if oldp^.symtableentry<>p^.symtableentry then
  1703. begin
  1704. comment(v_warning,'symtableentry field different');
  1705. error_found:=true;
  1706. end;
  1707. if oldp^.symtable<>p^.symtable then
  1708. begin
  1709. comment(v_warning,'symtable field different');
  1710. error_found:=true;
  1711. end;
  1712. if oldp^.is_absolute<>p^.is_absolute then
  1713. begin
  1714. comment(v_warning,'is_absolute field different');
  1715. error_found:=true;
  1716. end;
  1717. if oldp^.is_first<>p^.is_first then
  1718. begin
  1719. comment(v_warning,'is_first field different');
  1720. error_found:=true;
  1721. end;
  1722. end;
  1723. calln :
  1724. {(symtableprocentry : pprocsym;
  1725. symtableproc : psymtable;procdefinition : pprocdef;
  1726. methodpointer : ptree;
  1727. no_check,unit_specific : boolean);}
  1728. begin
  1729. if oldp^.symtableprocentry<>p^.symtableprocentry then
  1730. begin
  1731. comment(v_warning,'symtableprocentry field different');
  1732. error_found:=true;
  1733. end;
  1734. if oldp^.symtableproc<>p^.symtableproc then
  1735. begin
  1736. comment(v_warning,'symtableproc field different');
  1737. error_found:=true;
  1738. end;
  1739. if oldp^.procdefinition<>p^.procdefinition then
  1740. begin
  1741. comment(v_warning,'procdefinition field different');
  1742. error_found:=true;
  1743. end;
  1744. if oldp^.methodpointer<>p^.methodpointer then
  1745. begin
  1746. comment(v_warning,'methodpointer field different');
  1747. error_found:=true;
  1748. end;
  1749. if oldp^.no_check<>p^.no_check then
  1750. begin
  1751. comment(v_warning,'no_check field different');
  1752. error_found:=true;
  1753. end;
  1754. if oldp^.unit_specific<>p^.unit_specific then
  1755. begin
  1756. error_found:=true;
  1757. comment(v_warning,'unit_specific field different');
  1758. end;
  1759. end;
  1760. ordconstn :
  1761. begin
  1762. if oldp^.value<>p^.value then
  1763. begin
  1764. comment(v_warning,'value field different');
  1765. error_found:=true;
  1766. end;
  1767. end;
  1768. realconstn :
  1769. begin
  1770. if oldp^.value_real<>p^.value_real then
  1771. begin
  1772. comment(v_warning,'valued field different');
  1773. error_found:=true;
  1774. end;
  1775. if oldp^.lab_real<>p^.lab_real then
  1776. begin
  1777. comment(v_warning,'labnumber field different');
  1778. error_found:=true;
  1779. end;
  1780. end;
  1781. end;
  1782. if not error_found then
  1783. comment(v_warning,'did not find difference in trees');
  1784. end;
  1785. {$endif extdebug}
  1786. function equal_trees(t1,t2 : ptree) : boolean;
  1787. begin
  1788. if t1^.treetype=t2^.treetype then
  1789. begin
  1790. case t1^.treetype of
  1791. addn,
  1792. muln,
  1793. equaln,
  1794. orn,
  1795. xorn,
  1796. andn,
  1797. unequaln:
  1798. begin
  1799. equal_trees:=(equal_trees(t1^.left,t2^.left) and
  1800. equal_trees(t1^.right,t2^.right)) or
  1801. (equal_trees(t1^.right,t2^.left) and
  1802. equal_trees(t1^.left,t2^.right));
  1803. end;
  1804. subn,
  1805. divn,
  1806. modn,
  1807. assignn,
  1808. ltn,
  1809. lten,
  1810. gtn,
  1811. gten,
  1812. inn,
  1813. shrn,
  1814. shln,
  1815. slashn,
  1816. rangen:
  1817. begin
  1818. equal_trees:=(equal_trees(t1^.left,t2^.left) and
  1819. equal_trees(t1^.right,t2^.right));
  1820. end;
  1821. unaryminusn,
  1822. notn,
  1823. derefn,
  1824. addrn:
  1825. begin
  1826. equal_trees:=(equal_trees(t1^.left,t2^.left));
  1827. end;
  1828. loadn:
  1829. begin
  1830. equal_trees:=(t1^.symtableentry=t2^.symtableentry)
  1831. { not necessary
  1832. and (t1^.symtable=t2^.symtable)};
  1833. end;
  1834. {
  1835. subscriptn,
  1836. ordconstn,typeconvn,calln,callparan,
  1837. realconstn,asmn,vecn,
  1838. stringconstn,funcretn,selfn,
  1839. inlinen,niln,errorn,
  1840. typen,hnewn,hdisposen,newn,
  1841. disposen,setelen,setconstrn
  1842. }
  1843. else equal_trees:=false;
  1844. end;
  1845. end
  1846. else
  1847. equal_trees:=false;
  1848. end;
  1849. procedure set_unique(p : pnode);
  1850. begin
  1851. if assigned(p) then
  1852. begin
  1853. case p^.treetype of
  1854. vecn:
  1855. include(p^.flags,tf_callunique);
  1856. typeconvn:
  1857. set_unique(punarynode(p)^.left);
  1858. end;
  1859. end;
  1860. end;
  1861. function get_ordinal_value(p : ptree) : longint;
  1862. begin
  1863. if p^.treetype=ordconstn then
  1864. get_ordinal_value:=p^.value
  1865. else
  1866. Message(type_e_ordinal_expr_expected);
  1867. end;
  1868. function is_constnode(p : ptree) : boolean;
  1869. begin
  1870. is_constnode:=(p^.treetype in [ordconstn,realconstn,stringconstn,fixconstn,setconstn]);
  1871. end;
  1872. function is_constintnode(p : ptree) : boolean;
  1873. begin
  1874. is_constintnode:=(p^.treetype=ordconstn) and is_integer(p^.resulttype);
  1875. end;
  1876. function is_constcharnode(p : ptree) : boolean;
  1877. begin
  1878. is_constcharnode:=((p^.treetype=ordconstn) and
  1879. (p^.resulttype^.deftype=orddef) and
  1880. (porddef(p^.resulttype)^.typ=uchar));
  1881. end;
  1882. function is_constrealnode(p : ptree) : boolean;
  1883. begin
  1884. is_constrealnode:=(p^.treetype=realconstn);
  1885. end;
  1886. function is_constboolnode(p : ptree) : boolean;
  1887. begin
  1888. is_constboolnode:=((p^.treetype=ordconstn) and
  1889. (p^.resulttype^.deftype=orddef) and
  1890. (porddef(p^.resulttype)^.typ in [bool8bit,bool16bit,bool32bit]));
  1891. end;
  1892. function str_length(p : ptree) : longint;
  1893. begin
  1894. str_length:=p^.length;
  1895. end;
  1896. function is_emptyset(p : ptree):boolean;
  1897. {
  1898. return true if set s is empty
  1899. }
  1900. var
  1901. i : longint;
  1902. begin
  1903. i:=0;
  1904. if p^.treetype=setconstn then
  1905. begin
  1906. while (i<32) and (p^.value_set^[i]=0) do
  1907. inc(i);
  1908. end;
  1909. is_emptyset:=(i=32);
  1910. end;
  1911. end.
  1912. {
  1913. $Log$
  1914. Revision 1.18 1999-12-06 18:17:10 peter
  1915. * newcg compiler compiles again
  1916. Revision 1.17 1999/12/01 12:42:34 peter
  1917. * fixed bug 698
  1918. * removed some notes about unused vars
  1919. Revision 1.16 1999/11/05 13:15:01 florian
  1920. * some fixes to get the new cg compiling again
  1921. Revision 1.15 1999/10/12 21:20:47 florian
  1922. * new codegenerator compiles again
  1923. Revision 1.14 1999/09/14 11:16:09 florian
  1924. * only small updates to work with the current compiler
  1925. Revision 1.13 1999/08/06 18:05:55 florian
  1926. * implemented some stuff for assignments
  1927. Revision 1.12 1999/08/05 14:58:16 florian
  1928. * some fixes for the floating point registers
  1929. * more things for the new code generator
  1930. Revision 1.11 1999/08/04 00:23:59 florian
  1931. * renamed i386asm and i386base to cpuasm and cpubase
  1932. Revision 1.10 1999/08/02 17:14:12 florian
  1933. + changed the temp. generator to an object
  1934. Revision 1.9 1999/08/01 23:19:58 florian
  1935. + make a new makefile using the old compiler makefile
  1936. Revision 1.8 1999/08/01 23:04:52 michael
  1937. + Changes for Alpha
  1938. Revision 1.7 1999/08/01 18:22:39 florian
  1939. * made it again compilable
  1940. Revision 1.6 1999/01/24 22:32:36 florian
  1941. * well, more changes, especially parts of secondload ported
  1942. Revision 1.5 1999/01/23 23:29:49 florian
  1943. * first running version of the new code generator
  1944. * when compiling exceptions under Linux fixed
  1945. Revision 1.4 1999/01/19 10:19:06 florian
  1946. * bug with mul. of dwords fixed, reported by Alexander Stohr
  1947. * some changes to compile with TP
  1948. + small enhancements for the new code generator
  1949. Revision 1.3 1999/01/13 22:52:40 florian
  1950. + YES, finally the new code generator is compilable, but it doesn't run yet :(
  1951. Revision 1.2 1998/12/26 15:20:32 florian
  1952. + more changes for the new version
  1953. Revision 1.1 1998/12/15 22:21:53 florian
  1954. * first rough conversion
  1955. }