tree.pas 63 KB

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