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;exceptionblock : ptree;labsym : plabelsym);
  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. dispose(p);
  653. end;
  654. procedure swaptree(p:Ptree);
  655. var swapp:Ptree;
  656. begin
  657. swapp:=p^.right;
  658. p^.right:=p^.left;
  659. p^.left:=swapp;
  660. p^.swaped:=not(p^.swaped);
  661. end;
  662. function gennode(t : ttreetyp;l,r : ptree) : ptree;
  663. var
  664. p : ptree;
  665. begin
  666. p:=getnode;
  667. p^.disposetyp:=dt_leftright;
  668. p^.treetype:=t;
  669. p^.left:=l;
  670. p^.right:=r;
  671. p^.registers32:=0;
  672. { p^.registers16:=0;
  673. p^.registers8:=0; }
  674. p^.registersfpu:=0;
  675. {$ifdef SUPPORT_MMX}
  676. p^.registersmmx:=0;
  677. {$endif SUPPORT_MMX}
  678. p^.resulttype:=nil;
  679. gennode:=p;
  680. end;
  681. procedure disposetree(p : ptree);
  682. var
  683. symt : psymtable;
  684. i : longint;
  685. begin
  686. if not(assigned(p)) then
  687. exit;
  688. case p^.disposetyp of
  689. dt_leftright :
  690. begin
  691. if assigned(p^.left) then
  692. disposetree(p^.left);
  693. if assigned(p^.right) then
  694. disposetree(p^.right);
  695. end;
  696. dt_leftrighthigh :
  697. begin
  698. if assigned(p^.left) then
  699. disposetree(p^.left);
  700. if assigned(p^.right) then
  701. disposetree(p^.right);
  702. if assigned(p^.hightree) then
  703. disposetree(p^.hightree);
  704. end;
  705. dt_leftrightmethod :
  706. begin
  707. if assigned(p^.left) then
  708. disposetree(p^.left);
  709. if assigned(p^.right) then
  710. disposetree(p^.right);
  711. if assigned(p^.methodpointer) then
  712. disposetree(p^.methodpointer);
  713. end;
  714. dt_case :
  715. begin
  716. if assigned(p^.left) then
  717. disposetree(p^.left);
  718. if assigned(p^.right) then
  719. disposetree(p^.right);
  720. if assigned(p^.nodes) then
  721. deletecaselabels(p^.nodes);
  722. if assigned(p^.elseblock) then
  723. disposetree(p^.elseblock);
  724. end;
  725. dt_nothing : ;
  726. dt_left :
  727. if assigned(p^.left) then
  728. disposetree(p^.left);
  729. dt_mbleft :
  730. if assigned(p^.left) then
  731. disposetree(p^.left);
  732. dt_mbleft_and_method :
  733. begin
  734. if assigned(p^.left) then disposetree(p^.left);
  735. disposetree(p^.methodpointer);
  736. end;
  737. dt_typeconv : disposetree(p^.left);
  738. dt_inlinen :
  739. if assigned(p^.left) then
  740. disposetree(p^.left);
  741. dt_loop :
  742. begin
  743. if assigned(p^.left) then
  744. disposetree(p^.left);
  745. if assigned(p^.right) then
  746. disposetree(p^.right);
  747. if assigned(p^.t1) then
  748. disposetree(p^.t1);
  749. if assigned(p^.t2) then
  750. disposetree(p^.t2);
  751. end;
  752. dt_onn:
  753. begin
  754. if assigned(p^.left) then
  755. disposetree(p^.left);
  756. if assigned(p^.right) then
  757. disposetree(p^.right);
  758. if assigned(p^.exceptsymtable) then
  759. dispose(p^.exceptsymtable,done);
  760. end;
  761. dt_with :
  762. begin
  763. if assigned(p^.left) then
  764. disposetree(p^.left);
  765. if assigned(p^.right) then
  766. disposetree(p^.right);
  767. symt:=p^.withsymtable;
  768. for i:=1 to p^.tablecount do
  769. begin
  770. if assigned(symt) then
  771. begin
  772. p^.withsymtable:=pwithsymtable(symt^.next);
  773. dispose(symt,done);
  774. end;
  775. symt:=p^.withsymtable;
  776. end;
  777. end;
  778. else internalerror(1209995);
  779. end;
  780. putnode(p);
  781. end;
  782. procedure set_file_line(from,_to : ptree);
  783. begin
  784. if assigned(from) then
  785. _to^.fileinfo:=from^.fileinfo;
  786. end;
  787. procedure set_tree_filepos(p : ptree;const filepos : tfileposinfo);
  788. begin
  789. p^.fileinfo:=filepos;
  790. end;
  791. function getnode : ptree;
  792. var
  793. hp : ptree;
  794. begin
  795. new(hp);
  796. { makes error tracking easier }
  797. fillchar(hp^,sizeof(ttree),0);
  798. { reset }
  799. hp^.location.loc:=LOC_INVALID;
  800. { save local info }
  801. hp^.fileinfo:=aktfilepos;
  802. hp^.localswitches:=aktlocalswitches;
  803. getnode:=hp;
  804. end;
  805. procedure putnode(p : ptree);
  806. begin
  807. { clean up the contents of a node }
  808. case p^.treetype of
  809. asmn : if assigned(p^.p_asm) then
  810. dispose(p^.p_asm,done);
  811. stringconstn : begin
  812. ansistringdispose(p^.value_str,p^.length);
  813. end;
  814. setconstn : begin
  815. if assigned(p^.value_set) then
  816. dispose(p^.value_set);
  817. end;
  818. end;
  819. { reference info }
  820. if (p^.location.loc in [LOC_MEM,LOC_REFERENCE]) and
  821. assigned(p^.location.reference.symbol) then
  822. dispose(p^.location.reference.symbol,done);
  823. {$ifdef extdebug}
  824. if p^.firstpasscount>maxfirstpasscount then
  825. maxfirstpasscount:=p^.firstpasscount;
  826. {$endif extdebug}
  827. dispose(p);
  828. end;
  829. function getcopy(p : ptree) : ptree;
  830. var
  831. hp : ptree;
  832. begin
  833. hp:=getnode;
  834. hp^:=p^;
  835. if assigned(p^.location.reference.symbol) then
  836. hp^.location.reference.symbol:=p^.location.reference.symbol;
  837. case p^.disposetyp of
  838. dt_leftright :
  839. begin
  840. if assigned(p^.left) then
  841. hp^.left:=getcopy(p^.left);
  842. if assigned(p^.right) then
  843. hp^.right:=getcopy(p^.right);
  844. end;
  845. dt_nothing : ;
  846. dt_left :
  847. if assigned(p^.left) then
  848. hp^.left:=getcopy(p^.left);
  849. dt_mbleft :
  850. if assigned(p^.left) then
  851. hp^.left:=getcopy(p^.left);
  852. dt_mbleft_and_method :
  853. begin
  854. if assigned(p^.left) then
  855. hp^.left:=getcopy(p^.left);
  856. hp^.methodpointer:=getcopy(p^.methodpointer);
  857. end;
  858. dt_loop :
  859. begin
  860. if assigned(p^.left) then
  861. hp^.left:=getcopy(p^.left);
  862. if assigned(p^.right) then
  863. hp^.right:=getcopy(p^.right);
  864. if assigned(p^.t1) then
  865. hp^.t1:=getcopy(p^.t1);
  866. if assigned(p^.t2) then
  867. hp^.t2:=getcopy(p^.t2);
  868. end;
  869. dt_typeconv : hp^.left:=getcopy(p^.left);
  870. dt_inlinen :
  871. if assigned(p^.left) then
  872. hp^.left:=getcopy(p^.left);
  873. else internalerror(11);
  874. end;
  875. { now check treetype }
  876. case p^.treetype of
  877. stringconstn : begin
  878. hp^.value_str:=getpcharcopy(p);
  879. hp^.length:=p^.length;
  880. end;
  881. setconstn : begin
  882. new(hp^.value_set);
  883. hp^.value_set:=p^.value_set;
  884. end;
  885. end;
  886. getcopy:=hp;
  887. end;
  888. function genloadnode(v : pvarsym;st : psymtable) : ptree;
  889. var
  890. p : ptree;
  891. begin
  892. p:=getnode;
  893. p^.registers32:=0;
  894. { p^.registers16:=0;
  895. p^.registers8:=0; }
  896. p^.registersfpu:=0;
  897. {$ifdef SUPPORT_MMX}
  898. p^.registersmmx:=0;
  899. {$endif SUPPORT_MMX}
  900. p^.treetype:=loadn;
  901. p^.resulttype:=v^.vartype.def;
  902. p^.symtableentry:=v;
  903. p^.symtable:=st;
  904. p^.is_first := False;
  905. { method pointer load nodes can use the left subtree }
  906. p^.disposetyp:=dt_left;
  907. p^.left:=nil;
  908. genloadnode:=p;
  909. end;
  910. function genwithnode(symtable : psymtable;l,r : ptree;count : longint) : ptree;
  911. var
  912. p : ptree;
  913. begin
  914. p:=getnode;
  915. p^.disposetyp:=dt_with;
  916. p^.treetype:=withn;
  917. p^.left:=l;
  918. p^.right:=r;
  919. p^.registers32:=0;
  920. { p^.registers16:=0;
  921. p^.registers8:=0; }
  922. p^.registersfpu:=0;
  923. {$ifdef SUPPORT_MMX}
  924. p^.registersmmx:=0;
  925. {$endif SUPPORT_MMX}
  926. p^.resulttype:=nil;
  927. p^.withsymtable:=pwithsymtable(symtable);
  928. p^.tablecount:=count;
  929. set_file_line(l,p);
  930. genwithnode:=p;
  931. end;
  932. function genfixconstnode(v : longint;def : pdef) : ptree;
  933. var
  934. p : ptree;
  935. begin
  936. p:=getnode;
  937. p^.disposetyp:=dt_nothing;
  938. p^.treetype:=fixconstn;
  939. p^.registers32:=0;
  940. { p^.registers16:=0;
  941. p^.registers8:=0; }
  942. p^.registersfpu:=0;
  943. {$ifdef SUPPORT_MMX}
  944. p^.registersmmx:=0;
  945. {$endif SUPPORT_MMX}
  946. p^.resulttype:=def;
  947. p^.value:=v;
  948. genfixconstnode:=p;
  949. end;
  950. function gencallparanode(expr,next : ptree) : ptree;
  951. var
  952. p : ptree;
  953. begin
  954. p:=getnode;
  955. p^.disposetyp:=dt_leftright;
  956. p^.treetype:=callparan;
  957. p^.left:=expr;
  958. p^.right:=next;
  959. p^.registers32:=0;
  960. { p^.registers16:=0;
  961. p^.registers8:=0; }
  962. {$ifdef SUPPORT_MMX}
  963. p^.registersmmx:=0;
  964. {$endif SUPPORT_MMX}
  965. p^.registersfpu:=0;
  966. p^.resulttype:=nil;
  967. p^.exact_match_found:=false;
  968. p^.is_colon_para:=false;
  969. set_file_line(expr,p);
  970. gencallparanode:=p;
  971. end;
  972. function gencasenode(l,r : ptree;nodes : pcaserecord) : ptree;
  973. var
  974. p : ptree;
  975. begin
  976. p:=getnode;
  977. p^.disposetyp:=dt_case;
  978. p^.treetype:=casen;
  979. p^.left:=l;
  980. p^.right:=r;
  981. p^.nodes:=nodes;
  982. p^.registers32:=0;
  983. p^.registersfpu:=0;
  984. {$ifdef SUPPORT_MMX}
  985. p^.registersmmx:=0;
  986. {$endif SUPPORT_MMX}
  987. p^.resulttype:=nil;
  988. set_file_line(l,p);
  989. gencasenode:=p;
  990. end;
  991. function genloopnode(t : ttreetyp;l,r,n1 : ptree;back : boolean) : ptree;
  992. var
  993. p : ptree;
  994. begin
  995. p:=getnode;
  996. p^.disposetyp:=dt_loop;
  997. p^.treetype:=t;
  998. p^.left:=l;
  999. p^.right:=r;
  1000. p^.t1:=n1;
  1001. p^.t2:=nil;
  1002. p^.registers32:=0;
  1003. p^.backward:=back;
  1004. { p^.registers16:=0;
  1005. p^.registers8:=0; }
  1006. p^.registersfpu:=0;
  1007. {$ifdef SUPPORT_MMX}
  1008. p^.registersmmx:=0;
  1009. {$endif SUPPORT_MMX}
  1010. p^.resulttype:=nil;
  1011. set_file_line(l,p);
  1012. genloopnode:=p;
  1013. end;
  1014. function genordinalconstnode(v : longint;def : pdef) : ptree;
  1015. var
  1016. p : ptree;
  1017. begin
  1018. p:=getnode;
  1019. p^.disposetyp:=dt_nothing;
  1020. p^.treetype:=ordconstn;
  1021. p^.registers32:=0;
  1022. { p^.registers16:=0;
  1023. p^.registers8:=0; }
  1024. p^.registersfpu:=0;
  1025. {$ifdef SUPPORT_MMX}
  1026. p^.registersmmx:=0;
  1027. {$endif SUPPORT_MMX}
  1028. p^.resulttype:=def;
  1029. p^.value:=v;
  1030. if p^.resulttype^.deftype=orddef then
  1031. testrange(p^.resulttype,p^.value);
  1032. genordinalconstnode:=p;
  1033. end;
  1034. function genenumnode(v : penumsym) : ptree;
  1035. var
  1036. p : ptree;
  1037. begin
  1038. p:=getnode;
  1039. p^.disposetyp:=dt_nothing;
  1040. p^.treetype:=ordconstn;
  1041. p^.registers32:=0;
  1042. { p^.registers16:=0;
  1043. p^.registers8:=0; }
  1044. p^.registersfpu:=0;
  1045. {$ifdef SUPPORT_MMX}
  1046. p^.registersmmx:=0;
  1047. {$endif SUPPORT_MMX}
  1048. p^.resulttype:=v^.definition;
  1049. p^.value:=v^.value;
  1050. testrange(p^.resulttype,p^.value);
  1051. genenumnode:=p;
  1052. end;
  1053. function genrealconstnode(v : bestreal;def : pdef) : ptree;
  1054. var
  1055. p : ptree;
  1056. begin
  1057. p:=getnode;
  1058. p^.disposetyp:=dt_nothing;
  1059. p^.treetype:=realconstn;
  1060. p^.registers32:=0;
  1061. { p^.registers16:=0;
  1062. p^.registers8:=0; }
  1063. p^.registersfpu:=0;
  1064. {$ifdef SUPPORT_MMX}
  1065. p^.registersmmx:=0;
  1066. {$endif SUPPORT_MMX}
  1067. p^.resulttype:=def;
  1068. p^.value_real:=v;
  1069. p^.lab_real:=nil;
  1070. genrealconstnode:=p;
  1071. end;
  1072. function genstringconstnode(const s : string) : ptree;
  1073. var
  1074. p : ptree;
  1075. l : longint;
  1076. begin
  1077. p:=getnode;
  1078. p^.disposetyp:=dt_nothing;
  1079. p^.treetype:=stringconstn;
  1080. p^.registers32:=0;
  1081. { p^.registers16:=0;
  1082. p^.registers8:=0; }
  1083. p^.registersfpu:=0;
  1084. {$ifdef SUPPORT_MMX}
  1085. p^.registersmmx:=0;
  1086. {$endif SUPPORT_MMX}
  1087. l:=length(s);
  1088. p^.length:=l;
  1089. { stringdup write even past a #0 }
  1090. getmem(p^.value_str,l+1);
  1091. move(s[1],p^.value_str^,l);
  1092. p^.value_str[l]:=#0;
  1093. p^.lab_str:=nil;
  1094. if cs_ansistrings in aktlocalswitches then
  1095. begin
  1096. p^.stringtype:=st_ansistring;
  1097. p^.resulttype:=cansistringdef;
  1098. end
  1099. else
  1100. begin
  1101. p^.stringtype:=st_shortstring;
  1102. p^.resulttype:=cshortstringdef;
  1103. end;
  1104. genstringconstnode:=p;
  1105. end;
  1106. function getpcharcopy(p : ptree) : pchar;
  1107. var
  1108. pc : pchar;
  1109. begin
  1110. pc:=nil;
  1111. getmem(pc,p^.length+1);
  1112. if pc=nil then
  1113. Message(general_f_no_memory_left);
  1114. move(p^.value_str^,pc^,p^.length+1);
  1115. getpcharcopy:=pc;
  1116. end;
  1117. function genpcharconstnode(s : pchar;length : longint) : ptree;
  1118. var
  1119. p : ptree;
  1120. begin
  1121. p:=getnode;
  1122. p^.disposetyp:=dt_nothing;
  1123. p^.treetype:=stringconstn;
  1124. p^.registers32:=0;
  1125. { p^.registers16:=0;
  1126. p^.registers8:=0; }
  1127. p^.registersfpu:=0;
  1128. {$ifdef SUPPORT_MMX}
  1129. p^.registersmmx:=0;
  1130. {$endif SUPPORT_MMX}
  1131. p^.resulttype:=cshortstringdef;
  1132. p^.length:=length;
  1133. p^.value_str:=s;
  1134. p^.lab_str:=nil;
  1135. genpcharconstnode:=p;
  1136. end;
  1137. function genpointerconstnode(v : longint;def : pdef) : ptree;
  1138. var
  1139. p : ptree;
  1140. begin
  1141. p:=getnode;
  1142. p^.disposetyp:=dt_nothing;
  1143. p^.treetype:=pointerconstn;
  1144. p^.registers32:=0;
  1145. { p^.registers16:=0;
  1146. p^.registers8:=0; }
  1147. p^.registersfpu:=0;
  1148. {$ifdef SUPPORT_MMX}
  1149. p^.registersmmx:=0;
  1150. {$endif SUPPORT_MMX}
  1151. p^.resulttype:=def;
  1152. p^.value:=v;
  1153. genpointerconstnode:=p;
  1154. end;
  1155. function gensinglenode(t : ttreetyp;l : ptree) : ptree;
  1156. var
  1157. p : ptree;
  1158. begin
  1159. p:=getnode;
  1160. p^.disposetyp:=dt_left;
  1161. p^.treetype:=t;
  1162. p^.left:=l;
  1163. p^.registers32:=0;
  1164. { p^.registers16:=0;
  1165. p^.registers8:=0; }
  1166. p^.registersfpu:=0;
  1167. {$ifdef SUPPORT_MMX}
  1168. p^.registersmmx:=0;
  1169. {$endif SUPPORT_MMX}
  1170. p^.resulttype:=nil;
  1171. gensinglenode:=p;
  1172. end;
  1173. function genasmnode(p_asm : paasmoutput) : ptree;
  1174. var
  1175. p : ptree;
  1176. begin
  1177. p:=getnode;
  1178. p^.disposetyp:=dt_nothing;
  1179. p^.treetype:=asmn;
  1180. p^.registers32:=4;
  1181. p^.p_asm:=p_asm;
  1182. p^.object_preserved:=false;
  1183. { p^.registers16:=0;
  1184. p^.registers8:=0; }
  1185. p^.registersfpu:=8;
  1186. {$ifdef SUPPORT_MMX}
  1187. p^.registersmmx:=8;
  1188. {$endif SUPPORT_MMX}
  1189. p^.resulttype:=nil;
  1190. genasmnode:=p;
  1191. end;
  1192. function genloadcallnode(v: pprocsym;st: psymtable): ptree;
  1193. var
  1194. p : ptree;
  1195. begin
  1196. p:=getnode;
  1197. p^.registers32:=0;
  1198. { p^.registers16:=0;
  1199. p^.registers8:=0; }
  1200. p^.registersfpu:=0;
  1201. {$ifdef SUPPORT_MMX}
  1202. p^.registersmmx:=0;
  1203. {$endif SUPPORT_MMX}
  1204. p^.treetype:=loadn;
  1205. p^.resulttype:=v^.definition;
  1206. p^.symtableentry:=v;
  1207. p^.symtable:=st;
  1208. p^.is_first := False;
  1209. p^.disposetyp:=dt_nothing;
  1210. genloadcallnode:=p;
  1211. end;
  1212. function gentypedconstloadnode(sym : ptypedconstsym;st : psymtable) : ptree;
  1213. var
  1214. p : ptree;
  1215. begin
  1216. p:=getnode;
  1217. p^.registers32:=0;
  1218. { p^.registers16:=0;
  1219. p^.registers8:=0; }
  1220. p^.registersfpu:=0;
  1221. {$ifdef SUPPORT_MMX}
  1222. p^.registersmmx:=0;
  1223. {$endif SUPPORT_MMX}
  1224. p^.treetype:=loadn;
  1225. p^.resulttype:=sym^.typedconsttype.def;
  1226. p^.symtableentry:=pvarsym(sym);
  1227. p^.symtable:=st;
  1228. p^.disposetyp:=dt_nothing;
  1229. gentypedconstloadnode:=p;
  1230. end;
  1231. function gentypeconvnode(node : ptree;t : pdef) : ptree;
  1232. var
  1233. p : ptree;
  1234. begin
  1235. p:=getnode;
  1236. p^.disposetyp:=dt_typeconv;
  1237. p^.treetype:=typeconvn;
  1238. p^.left:=node;
  1239. p^.registers32:=0;
  1240. { p^.registers16:=0;
  1241. p^.registers8:=0; }
  1242. p^.convtyp:=tc_equal;
  1243. p^.registersfpu:=0;
  1244. {$ifdef SUPPORT_MMX}
  1245. p^.registersmmx:=0;
  1246. {$endif SUPPORT_MMX}
  1247. p^.resulttype:=t;
  1248. p^.explizit:=false;
  1249. set_file_line(node,p);
  1250. gentypeconvnode:=p;
  1251. end;
  1252. function gencallnode(v : pprocsym;st : psymtable) : ptree;
  1253. var
  1254. p : ptree;
  1255. begin
  1256. p:=getnode;
  1257. p^.registers32:=0;
  1258. { p^.registers16:=0;
  1259. p^.registers8:=0; }
  1260. p^.registersfpu:=0;
  1261. {$ifdef SUPPORT_MMX}
  1262. p^.registersmmx:=0;
  1263. {$endif SUPPORT_MMX}
  1264. p^.treetype:=calln;
  1265. p^.symtableprocentry:=v;
  1266. p^.symtableproc:=st;
  1267. p^.unit_specific:=false;
  1268. p^.no_check:=false;
  1269. p^.return_value_used:=true;
  1270. p^.disposetyp := dt_leftright;
  1271. p^.methodpointer:=nil;
  1272. p^.left:=nil;
  1273. p^.right:=nil;
  1274. p^.procdefinition:=nil;
  1275. gencallnode:=p;
  1276. end;
  1277. function genmethodcallnode(v : pprocsym;st : psymtable;mp : ptree) : ptree;
  1278. var
  1279. p : ptree;
  1280. begin
  1281. p:=getnode;
  1282. p^.registers32:=0;
  1283. { p^.registers16:=0;
  1284. p^.registers8:=0; }
  1285. p^.registersfpu:=0;
  1286. {$ifdef SUPPORT_MMX}
  1287. p^.registersmmx:=0;
  1288. {$endif SUPPORT_MMX}
  1289. p^.treetype:=calln;
  1290. p^.return_value_used:=true;
  1291. p^.symtableprocentry:=v;
  1292. p^.symtableproc:=st;
  1293. p^.disposetyp:=dt_mbleft_and_method;
  1294. p^.left:=nil;
  1295. p^.right:=nil;
  1296. p^.methodpointer:=mp;
  1297. p^.procdefinition:=nil;
  1298. genmethodcallnode:=p;
  1299. end;
  1300. function gensubscriptnode(varsym : pvarsym;l : ptree) : ptree;
  1301. var
  1302. p : ptree;
  1303. begin
  1304. p:=getnode;
  1305. p^.disposetyp:=dt_left;
  1306. p^.treetype:=subscriptn;
  1307. p^.left:=l;
  1308. p^.registers32:=0;
  1309. p^.vs:=varsym;
  1310. { p^.registers16:=0;
  1311. p^.registers8:=0; }
  1312. p^.registersfpu:=0;
  1313. {$ifdef SUPPORT_MMX}
  1314. p^.registersmmx:=0;
  1315. {$endif SUPPORT_MMX}
  1316. p^.resulttype:=nil;
  1317. gensubscriptnode:=p;
  1318. end;
  1319. function genzeronode(t : ttreetyp) : ptree;
  1320. var
  1321. p : ptree;
  1322. begin
  1323. p:=getnode;
  1324. p^.disposetyp:=dt_nothing;
  1325. p^.treetype:=t;
  1326. p^.registers32:=0;
  1327. { p^.registers16:=0;
  1328. p^.registers8:=0; }
  1329. p^.registersfpu:=0;
  1330. {$ifdef SUPPORT_MMX}
  1331. p^.registersmmx:=0;
  1332. {$endif SUPPORT_MMX}
  1333. p^.resulttype:=nil;
  1334. genzeronode:=p;
  1335. end;
  1336. function genlabelnode(t : ttreetyp;nr : pasmlabel) : ptree;
  1337. var
  1338. p : ptree;
  1339. begin
  1340. p:=getnode;
  1341. p^.disposetyp:=dt_nothing;
  1342. p^.treetype:=t;
  1343. p^.registers32:=0;
  1344. { p^.registers16:=0;
  1345. p^.registers8:=0; }
  1346. p^.registersfpu:=0;
  1347. {$ifdef SUPPORT_MMX}
  1348. p^.registersmmx:=0;
  1349. {$endif SUPPORT_MMX}
  1350. p^.resulttype:=nil;
  1351. { for security }
  1352. { nr^.is_used:=true;}
  1353. p^.labelnr:=nr;
  1354. genlabelnode:=p;
  1355. end;
  1356. function genselfnode(_class : pdef) : ptree;
  1357. var
  1358. p : ptree;
  1359. begin
  1360. p:=getnode;
  1361. p^.disposetyp:=dt_nothing;
  1362. p^.treetype:=selfn;
  1363. p^.registers32:=0;
  1364. { p^.registers16:=0;
  1365. p^.registers8:=0; }
  1366. p^.registersfpu:=0;
  1367. {$ifdef SUPPORT_MMX}
  1368. p^.registersmmx:=0;
  1369. {$endif SUPPORT_MMX}
  1370. p^.resulttype:=_class;
  1371. genselfnode:=p;
  1372. end;
  1373. function geninlinenode(number : byte;is_const:boolean;l : ptree) : ptree;
  1374. var
  1375. p : ptree;
  1376. begin
  1377. p:=getnode;
  1378. p^.disposetyp:=dt_inlinen;
  1379. p^.treetype:=inlinen;
  1380. p^.left:=l;
  1381. p^.inlinenumber:=number;
  1382. p^.inlineconst:=is_const;
  1383. p^.registers32:=0;
  1384. { p^.registers16:=0;
  1385. p^.registers8:=0; }
  1386. p^.registersfpu:=0;
  1387. {$ifdef SUPPORT_MMX}
  1388. p^.registersmmx:=0;
  1389. {$endif SUPPORT_MMX}
  1390. p^.resulttype:=nil;
  1391. geninlinenode:=p;
  1392. end;
  1393. function gentypenode(t : pdef;sym:ptypesym) : ptree;
  1394. var
  1395. p : ptree;
  1396. begin
  1397. p:=getnode;
  1398. p^.disposetyp:=dt_nothing;
  1399. p^.treetype:=typen;
  1400. p^.registers32:=0;
  1401. { p^.registers16:=0;
  1402. p^.registers8:=0; }
  1403. p^.registersfpu:=0;
  1404. {$ifdef SUPPORT_MMX}
  1405. p^.registersmmx:=0;
  1406. {$endif SUPPORT_MMX}
  1407. p^.resulttype:=generrordef;
  1408. p^.typenodetype:=t;
  1409. p^.typenodesym:=sym;
  1410. gentypenode:=p;
  1411. end;
  1412. function genloadmethodcallnode(v: pprocsym;st: psymtable; mp:ptree): ptree;
  1413. var
  1414. p : ptree;
  1415. begin
  1416. p:=getnode;
  1417. p^.registers32:=0;
  1418. { p^.registers16:=0;
  1419. p^.registers8:=0; }
  1420. p^.registersfpu:=0;
  1421. {$ifdef SUPPORT_MMX}
  1422. p^.registersmmx:=0;
  1423. {$endif SUPPORT_MMX}
  1424. p^.treetype:=loadn;
  1425. p^.left:=nil;
  1426. p^.resulttype:=v^.definition;
  1427. p^.symtableentry:=v;
  1428. p^.symtable:=st;
  1429. p^.is_first := False;
  1430. p^.disposetyp:=dt_left;
  1431. p^.left:=mp;
  1432. genloadmethodcallnode:=p;
  1433. end;
  1434. { uses the callnode to create the new procinline node }
  1435. function genprocinlinenode(callp,code : ptree) : ptree;
  1436. var
  1437. p : ptree;
  1438. begin
  1439. genprocinlinenode:=p;
  1440. end;
  1441. function gensetconstnode(s : pconstset;settype : psetdef) : ptree;
  1442. var
  1443. p : ptree;
  1444. begin
  1445. p:=getnode;
  1446. p^.disposetyp:=dt_nothing;
  1447. p^.treetype:=setconstn;
  1448. p^.registers32:=0;
  1449. p^.registersfpu:=0;
  1450. {$ifdef SUPPORT_MMX}
  1451. p^.registersmmx:=0;
  1452. {$endif SUPPORT_MMX}
  1453. p^.resulttype:=settype;
  1454. p^.left:=nil;
  1455. new(p^.value_set);
  1456. p^.value_set^:=s^;
  1457. gensetconstnode:=p;
  1458. end;
  1459. procedure set_varstate(p : ptree;must_be_valid : boolean);
  1460. begin
  1461. if not assigned(p) then
  1462. exit
  1463. else
  1464. begin
  1465. if p^.varstateset then
  1466. exit;
  1467. case p^.treetype of
  1468. typeconvn,subscriptn :
  1469. set_varstate(p^.left,must_be_valid);
  1470. vecn:
  1471. begin
  1472. if (p^.left^.resulttype^.deftype in [stringdef,arraydef]) then
  1473. set_varstate(p^.left,must_be_valid)
  1474. else
  1475. set_varstate(p^.left,true);
  1476. set_varstate(p^.right,true);
  1477. end;
  1478. { do not parse calln }
  1479. calln : ;
  1480. callparan:
  1481. begin
  1482. set_varstate(p^.left,must_be_valid);
  1483. set_varstate(p^.right,must_be_valid);
  1484. end;
  1485. loadn :
  1486. if (p^.symtableentry^.typ=varsym) then
  1487. begin
  1488. if must_be_valid and p^.is_first then
  1489. begin
  1490. if (pvarsym(p^.symtableentry)^.varstate=vs_declared_and_first_found) or
  1491. (pvarsym(p^.symtableentry)^.varstate=vs_set_but_first_not_passed) then
  1492. if (assigned(pvarsym(p^.symtableentry)^.owner) and
  1493. assigned(aktprocsym) and
  1494. (pvarsym(p^.symtableentry)^.owner = aktprocsym^.definition^.localst)) then
  1495. begin
  1496. if p^.symtable^.symtabletype=localsymtable then
  1497. Message1(sym_n_uninitialized_local_variable,pvarsym(p^.symtableentry)^.name)
  1498. else
  1499. Message1(sym_n_uninitialized_variable,pvarsym(p^.symtableentry)^.name);
  1500. end;
  1501. end;
  1502. if (p^.is_first) then
  1503. begin
  1504. if pvarsym(p^.symtableentry)^.varstate=vs_declared_and_first_found then
  1505. { this can only happen at left of an assignment, no ? PM }
  1506. if (parsing_para_level=0) and not must_be_valid then
  1507. pvarsym(p^.symtableentry)^.varstate:=vs_assigned
  1508. else
  1509. pvarsym(p^.symtableentry)^.varstate:=vs_used;
  1510. if pvarsym(p^.symtableentry)^.varstate=vs_set_but_first_not_passed then
  1511. pvarsym(p^.symtableentry)^.varstate:=vs_used;
  1512. p^.is_first:=false;
  1513. end
  1514. else
  1515. begin
  1516. if (pvarsym(p^.symtableentry)^.varstate=vs_assigned) and
  1517. (must_be_valid or (parsing_para_level>0) or
  1518. (p^.resulttype^.deftype=procvardef)) then
  1519. pvarsym(p^.symtableentry)^.varstate:=vs_used;
  1520. if (pvarsym(p^.symtableentry)^.varstate=vs_declared_and_first_found) and
  1521. (must_be_valid or (parsing_para_level>0) or
  1522. (p^.resulttype^.deftype=procvardef)) then
  1523. pvarsym(p^.symtableentry)^.varstate:=vs_set_but_first_not_passed;
  1524. end;
  1525. end;
  1526. funcretn:
  1527. begin
  1528. { no claim if setting higher return value_str }
  1529. if must_be_valid and
  1530. (procinfo=pprocinfo(p^.funcretprocinfo)) and
  1531. ((procinfo^.funcret_state=vs_declared) or
  1532. ((p^.is_first_funcret) and
  1533. (procinfo^.funcret_state=vs_declared_and_first_found))) then
  1534. begin
  1535. Message(sym_w_function_result_not_set);
  1536. { avoid multiple warnings }
  1537. procinfo^.funcret_state:=vs_assigned;
  1538. end;
  1539. if p^.is_first_funcret and not must_be_valid then
  1540. pprocinfo(p^.funcretprocinfo)^.funcret_state:=vs_assigned;
  1541. end;
  1542. else
  1543. begin
  1544. {internalerror(565656);}
  1545. end;
  1546. end;{case }
  1547. p^.varstateset:=true;
  1548. end;
  1549. end;
  1550. procedure set_location(var destloc,sourceloc : tlocation);
  1551. begin
  1552. destloc:= sourceloc;
  1553. end;
  1554. {$ifdef extdebug}
  1555. procedure compare_trees(oldp,p : ptree);
  1556. var
  1557. error_found : boolean;
  1558. begin
  1559. if oldp^.resulttype<>p^.resulttype then
  1560. begin
  1561. error_found:=true;
  1562. if is_equal(oldp^.resulttype,p^.resulttype) then
  1563. comment(v_debug,'resulttype fields are different but equal')
  1564. else
  1565. comment(v_warning,'resulttype fields are really different');
  1566. end;
  1567. if oldp^.treetype<>p^.treetype then
  1568. begin
  1569. comment(v_warning,'treetype field different');
  1570. error_found:=true;
  1571. end
  1572. else
  1573. comment(v_debug,' treetype '+tostr(longint(oldp^.treetype)));
  1574. if oldp^.error<>p^.error then
  1575. begin
  1576. comment(v_warning,'error field different');
  1577. error_found:=true;
  1578. end;
  1579. if oldp^.disposetyp<>p^.disposetyp then
  1580. begin
  1581. comment(v_warning,'disposetyp field different');
  1582. error_found:=true;
  1583. end;
  1584. { is true, if the right and left operand are swaped }
  1585. if oldp^.swaped<>p^.swaped then
  1586. begin
  1587. comment(v_warning,'swaped field different');
  1588. error_found:=true;
  1589. end;
  1590. { the location of the result of this node }
  1591. if oldp^.location.loc<>p^.location.loc then
  1592. begin
  1593. comment(v_warning,'location.loc field different');
  1594. error_found:=true;
  1595. end;
  1596. { the number of registers needed to evalute the node }
  1597. if oldp^.registers32<>p^.registers32 then
  1598. begin
  1599. comment(v_warning,'registers32 field different');
  1600. comment(v_warning,' old '+tostr(oldp^.registers32)+'<> new '+tostr(p^.registers32));
  1601. error_found:=true;
  1602. end;
  1603. if oldp^.registersfpu<>p^.registersfpu then
  1604. begin
  1605. comment(v_warning,'registersfpu field different');
  1606. error_found:=true;
  1607. end;
  1608. {$ifdef SUPPORT_MMX}
  1609. if oldp^.registersmmx<>p^.registersmmx then
  1610. begin
  1611. comment(v_warning,'registersmmx field different');
  1612. error_found:=true;
  1613. end;
  1614. {$endif SUPPORT_MMX}
  1615. if oldp^.left<>p^.left then
  1616. begin
  1617. comment(v_warning,'left field different');
  1618. error_found:=true;
  1619. end;
  1620. if oldp^.right<>p^.right then
  1621. begin
  1622. comment(v_warning,'right field different');
  1623. error_found:=true;
  1624. end;
  1625. if oldp^.fileinfo.line<>p^.fileinfo.line then
  1626. begin
  1627. comment(v_warning,'fileinfo.line field different');
  1628. error_found:=true;
  1629. end;
  1630. if oldp^.fileinfo.column<>p^.fileinfo.column then
  1631. begin
  1632. comment(v_warning,'fileinfo.column field different');
  1633. error_found:=true;
  1634. end;
  1635. if oldp^.fileinfo.fileindex<>p^.fileinfo.fileindex then
  1636. begin
  1637. comment(v_warning,'fileinfo.fileindex field different');
  1638. error_found:=true;
  1639. end;
  1640. if oldp^.localswitches<>p^.localswitches then
  1641. begin
  1642. comment(v_warning,'localswitches field different');
  1643. error_found:=true;
  1644. end;
  1645. {$ifdef extdebug}
  1646. if oldp^.firstpasscount<>p^.firstpasscount then
  1647. begin
  1648. comment(v_warning,'firstpasscount field different');
  1649. error_found:=true;
  1650. end;
  1651. {$endif extdebug}
  1652. if oldp^.treetype=p^.treetype then
  1653. case oldp^.treetype of
  1654. addn :
  1655. begin
  1656. if oldp^.use_strconcat<>p^.use_strconcat then
  1657. begin
  1658. comment(v_warning,'use_strconcat field different');
  1659. error_found:=true;
  1660. end;
  1661. if oldp^.string_typ<>p^.string_typ then
  1662. begin
  1663. comment(v_warning,'stringtyp field different');
  1664. error_found:=true;
  1665. end;
  1666. end;
  1667. callparan :
  1668. {(is_colon_para : boolean;exact_match_found : boolean);}
  1669. begin
  1670. if oldp^.is_colon_para<>p^.is_colon_para then
  1671. begin
  1672. comment(v_warning,'use_strconcat field different');
  1673. error_found:=true;
  1674. end;
  1675. if oldp^.exact_match_found<>p^.exact_match_found then
  1676. begin
  1677. comment(v_warning,'exact_match_found field different');
  1678. error_found:=true;
  1679. end;
  1680. end;
  1681. assignn :
  1682. {(assigntyp : tassigntyp;concat_string : boolean);}
  1683. begin
  1684. if oldp^.assigntyp<>p^.assigntyp then
  1685. begin
  1686. comment(v_warning,'assigntyp field different');
  1687. error_found:=true;
  1688. end;
  1689. if oldp^.concat_string<>p^.concat_string then
  1690. begin
  1691. comment(v_warning,'concat_string field different');
  1692. error_found:=true;
  1693. end;
  1694. end;
  1695. loadn :
  1696. {(symtableentry : psym;symtable : psymtable;
  1697. is_absolute,is_first : boolean);}
  1698. begin
  1699. if oldp^.symtableentry<>p^.symtableentry then
  1700. begin
  1701. comment(v_warning,'symtableentry field different');
  1702. error_found:=true;
  1703. end;
  1704. if oldp^.symtable<>p^.symtable then
  1705. begin
  1706. comment(v_warning,'symtable field different');
  1707. error_found:=true;
  1708. end;
  1709. if oldp^.is_absolute<>p^.is_absolute then
  1710. begin
  1711. comment(v_warning,'is_absolute field different');
  1712. error_found:=true;
  1713. end;
  1714. if oldp^.is_first<>p^.is_first then
  1715. begin
  1716. comment(v_warning,'is_first field different');
  1717. error_found:=true;
  1718. end;
  1719. end;
  1720. calln :
  1721. {(symtableprocentry : pprocsym;
  1722. symtableproc : psymtable;procdefinition : pprocdef;
  1723. methodpointer : ptree;
  1724. no_check,unit_specific : boolean);}
  1725. begin
  1726. if oldp^.symtableprocentry<>p^.symtableprocentry then
  1727. begin
  1728. comment(v_warning,'symtableprocentry field different');
  1729. error_found:=true;
  1730. end;
  1731. if oldp^.symtableproc<>p^.symtableproc then
  1732. begin
  1733. comment(v_warning,'symtableproc field different');
  1734. error_found:=true;
  1735. end;
  1736. if oldp^.procdefinition<>p^.procdefinition then
  1737. begin
  1738. comment(v_warning,'procdefinition field different');
  1739. error_found:=true;
  1740. end;
  1741. if oldp^.methodpointer<>p^.methodpointer then
  1742. begin
  1743. comment(v_warning,'methodpointer field different');
  1744. error_found:=true;
  1745. end;
  1746. if oldp^.no_check<>p^.no_check then
  1747. begin
  1748. comment(v_warning,'no_check field different');
  1749. error_found:=true;
  1750. end;
  1751. if oldp^.unit_specific<>p^.unit_specific then
  1752. begin
  1753. error_found:=true;
  1754. comment(v_warning,'unit_specific field different');
  1755. end;
  1756. end;
  1757. ordconstn :
  1758. begin
  1759. if oldp^.value<>p^.value then
  1760. begin
  1761. comment(v_warning,'value field different');
  1762. error_found:=true;
  1763. end;
  1764. end;
  1765. realconstn :
  1766. begin
  1767. if oldp^.value_real<>p^.value_real then
  1768. begin
  1769. comment(v_warning,'valued field different');
  1770. error_found:=true;
  1771. end;
  1772. if oldp^.lab_real<>p^.lab_real then
  1773. begin
  1774. comment(v_warning,'labnumber field different');
  1775. error_found:=true;
  1776. end;
  1777. end;
  1778. end;
  1779. if not error_found then
  1780. comment(v_warning,'did not find difference in trees');
  1781. end;
  1782. {$endif extdebug}
  1783. function equal_trees(t1,t2 : ptree) : boolean;
  1784. begin
  1785. if t1^.treetype=t2^.treetype then
  1786. begin
  1787. case t1^.treetype of
  1788. addn,
  1789. muln,
  1790. equaln,
  1791. orn,
  1792. xorn,
  1793. andn,
  1794. unequaln:
  1795. begin
  1796. equal_trees:=(equal_trees(t1^.left,t2^.left) and
  1797. equal_trees(t1^.right,t2^.right)) or
  1798. (equal_trees(t1^.right,t2^.left) and
  1799. equal_trees(t1^.left,t2^.right));
  1800. end;
  1801. subn,
  1802. divn,
  1803. modn,
  1804. assignn,
  1805. ltn,
  1806. lten,
  1807. gtn,
  1808. gten,
  1809. inn,
  1810. shrn,
  1811. shln,
  1812. slashn,
  1813. rangen:
  1814. begin
  1815. equal_trees:=(equal_trees(t1^.left,t2^.left) and
  1816. equal_trees(t1^.right,t2^.right));
  1817. end;
  1818. unaryminusn,
  1819. notn,
  1820. derefn,
  1821. addrn:
  1822. begin
  1823. equal_trees:=(equal_trees(t1^.left,t2^.left));
  1824. end;
  1825. loadn:
  1826. begin
  1827. equal_trees:=(t1^.symtableentry=t2^.symtableentry)
  1828. { not necessary
  1829. and (t1^.symtable=t2^.symtable)};
  1830. end;
  1831. {
  1832. subscriptn,
  1833. ordconstn,typeconvn,calln,callparan,
  1834. realconstn,asmn,vecn,
  1835. stringconstn,funcretn,selfn,
  1836. inlinen,niln,errorn,
  1837. typen,hnewn,hdisposen,newn,
  1838. disposen,setelen,setconstrn
  1839. }
  1840. else equal_trees:=false;
  1841. end;
  1842. end
  1843. else
  1844. equal_trees:=false;
  1845. end;
  1846. procedure set_unique(p : pnode);
  1847. begin
  1848. if assigned(p) then
  1849. begin
  1850. case p^.treetype of
  1851. vecn:
  1852. include(p^.flags,tf_callunique);
  1853. typeconvn:
  1854. set_unique(punarynode(p)^.left);
  1855. end;
  1856. end;
  1857. end;
  1858. function get_ordinal_value(p : ptree) : longint;
  1859. begin
  1860. if p^.treetype=ordconstn then
  1861. get_ordinal_value:=p^.value
  1862. else
  1863. Message(type_e_ordinal_expr_expected);
  1864. end;
  1865. function is_constnode(p : ptree) : boolean;
  1866. begin
  1867. is_constnode:=(p^.treetype in [ordconstn,realconstn,stringconstn,fixconstn,setconstn]);
  1868. end;
  1869. function is_constintnode(p : ptree) : boolean;
  1870. begin
  1871. is_constintnode:=(p^.treetype=ordconstn) and is_integer(p^.resulttype);
  1872. end;
  1873. function is_constcharnode(p : ptree) : boolean;
  1874. begin
  1875. is_constcharnode:=((p^.treetype=ordconstn) and
  1876. (p^.resulttype^.deftype=orddef) and
  1877. (porddef(p^.resulttype)^.typ=uchar));
  1878. end;
  1879. function is_constrealnode(p : ptree) : boolean;
  1880. begin
  1881. is_constrealnode:=(p^.treetype=realconstn);
  1882. end;
  1883. function is_constboolnode(p : ptree) : boolean;
  1884. begin
  1885. is_constboolnode:=((p^.treetype=ordconstn) and
  1886. (p^.resulttype^.deftype=orddef) and
  1887. (porddef(p^.resulttype)^.typ in [bool8bit,bool16bit,bool32bit]));
  1888. end;
  1889. function str_length(p : ptree) : longint;
  1890. begin
  1891. str_length:=p^.length;
  1892. end;
  1893. function is_emptyset(p : ptree):boolean;
  1894. {
  1895. return true if set s is empty
  1896. }
  1897. var
  1898. i : longint;
  1899. begin
  1900. i:=0;
  1901. if p^.treetype=setconstn then
  1902. begin
  1903. while (i<32) and (p^.value_set^[i]=0) do
  1904. inc(i);
  1905. end;
  1906. is_emptyset:=(i=32);
  1907. end;
  1908. end.
  1909. {
  1910. $Log$
  1911. Revision 1.19 1999-12-22 22:27:41 peter
  1912. * compiles again
  1913. Revision 1.18 1999/12/06 18:17:10 peter
  1914. * newcg compiler compiles again
  1915. Revision 1.17 1999/12/01 12:42:34 peter
  1916. * fixed bug 698
  1917. * removed some notes about unused vars
  1918. Revision 1.16 1999/11/05 13:15:01 florian
  1919. * some fixes to get the new cg compiling again
  1920. Revision 1.15 1999/10/12 21:20:47 florian
  1921. * new codegenerator compiles again
  1922. Revision 1.14 1999/09/14 11:16:09 florian
  1923. * only small updates to work with the current compiler
  1924. Revision 1.13 1999/08/06 18:05:55 florian
  1925. * implemented some stuff for assignments
  1926. Revision 1.12 1999/08/05 14:58:16 florian
  1927. * some fixes for the floating point registers
  1928. * more things for the new code generator
  1929. Revision 1.11 1999/08/04 00:23:59 florian
  1930. * renamed i386asm and i386base to cpuasm and cpubase
  1931. Revision 1.10 1999/08/02 17:14:12 florian
  1932. + changed the temp. generator to an object
  1933. Revision 1.9 1999/08/01 23:19:58 florian
  1934. + make a new makefile using the old compiler makefile
  1935. Revision 1.8 1999/08/01 23:04:52 michael
  1936. + Changes for Alpha
  1937. Revision 1.7 1999/08/01 18:22:39 florian
  1938. * made it again compilable
  1939. Revision 1.6 1999/01/24 22:32:36 florian
  1940. * well, more changes, especially parts of secondload ported
  1941. Revision 1.5 1999/01/23 23:29:49 florian
  1942. * first running version of the new code generator
  1943. * when compiling exceptions under Linux fixed
  1944. Revision 1.4 1999/01/19 10:19:06 florian
  1945. * bug with mul. of dwords fixed, reported by Alexander Stohr
  1946. * some changes to compile with TP
  1947. + small enhancements for the new code generator
  1948. Revision 1.3 1999/01/13 22:52:40 florian
  1949. + YES, finally the new code generator is compilable, but it doesn't run yet :(
  1950. Revision 1.2 1998/12/26 15:20:32 florian
  1951. + more changes for the new version
  1952. Revision 1.1 1998/12/15 22:21:53 florian
  1953. * first rough conversion
  1954. }