pass_1.pas 201 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408
  1. {
  2. $Id$
  3. Copyright (c) 1996-98 by Florian Klaempfl
  4. This unit implements the first pass of the code generator
  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. {$F+}
  20. {$endif tp}
  21. unit pass_1;
  22. interface
  23. uses tree;
  24. function do_firstpass(var p : ptree) : boolean;
  25. implementation
  26. uses
  27. cobjects,verbose,comphook,systems,globals,
  28. aasm,symtable,types,strings,hcodegen,files
  29. {$ifdef i386}
  30. ,i386
  31. ,tgeni386
  32. {$endif}
  33. {$ifdef m68k}
  34. ,m68k
  35. ,tgen68k
  36. {$endif}
  37. {$ifdef UseBrowser}
  38. ,browser
  39. {$endif UseBrowser}
  40. ;
  41. { firstcallparan without varspez
  42. we don't count the ref }
  43. const
  44. count_ref : boolean = true;
  45. procedure message(const t : tmsgconst);
  46. var
  47. olderrorcount : longint;
  48. begin
  49. if not(codegenerror) then
  50. begin
  51. olderrorcount:=status.errorcount;
  52. verbose.Message(t);
  53. codegenerror:=olderrorcount<>status.errorcount;
  54. end;
  55. end;
  56. procedure message1(const t : tmsgconst;const s : string);
  57. var
  58. olderrorcount : longint;
  59. begin
  60. if not(codegenerror) then
  61. begin
  62. olderrorcount:=status.errorcount;
  63. verbose.Message1(t,s);
  64. codegenerror:=olderrorcount<>status.errorcount;
  65. end;
  66. end;
  67. procedure message2(const t : tmsgconst;const s1,s2 : string);
  68. var
  69. olderrorcount : longint;
  70. begin
  71. if not(codegenerror) then
  72. begin
  73. olderrorcount:=status.errorcount;
  74. verbose.Message2(t,s1,s2);
  75. codegenerror:=olderrorcount<>status.errorcount;
  76. end;
  77. end;
  78. procedure message3(const t : tmsgconst;const s1,s2,s3 : string);
  79. var
  80. olderrorcount : longint;
  81. begin
  82. if not(codegenerror) then
  83. begin
  84. olderrorcount:=status.errorcount;
  85. verbose.Message3(t,s1,s2,s3);
  86. codegenerror:=olderrorcount<>status.errorcount;
  87. end;
  88. end;
  89. procedure firstpass(var p : ptree);forward;
  90. { marks an lvalue as "unregable" }
  91. procedure make_not_regable(p : ptree);
  92. begin
  93. case p^.treetype of
  94. typeconvn :
  95. make_not_regable(p^.left);
  96. loadn :
  97. if p^.symtableentry^.typ=varsym then
  98. pvarsym(p^.symtableentry)^.var_options :=
  99. pvarsym(p^.symtableentry)^.var_options and not vo_regable;
  100. end;
  101. end;
  102. procedure left_right_max(p : ptree);
  103. begin
  104. p^.registers32:=max(p^.left^.registers32,p^.right^.registers32);
  105. p^.registersfpu:=max(p^.left^.registersfpu,p^.right^.registersfpu);
  106. {$ifdef SUPPORT_MMX}
  107. p^.registersmmx:=max(p^.left^.registersmmx,p^.right^.registersmmx);
  108. {$endif SUPPORT_MMX}
  109. end;
  110. { calculates the needed registers for a binary operator }
  111. procedure calcregisters(p : ptree;r32,fpu,mmx : word);
  112. begin
  113. left_right_max(p);
  114. { Nur wenn links und rechts ein Unterschied < ben”tige Anzahl ist, }
  115. { wird ein zus„tzliches Register ben”tigt, da es dann keinen }
  116. { schwierigeren Ast gibt, welcher erst ausgewertet werden kann }
  117. if (abs(p^.left^.registers32-p^.right^.registers32)<r32) then
  118. inc(p^.registers32,r32);
  119. if (abs(p^.left^.registersfpu-p^.right^.registersfpu)<fpu) then
  120. inc(p^.registersfpu,fpu);
  121. {$ifdef SUPPORT_MMX}
  122. if (abs(p^.left^.registersmmx-p^.right^.registersmmx)<mmx) then
  123. inc(p^.registersmmx,mmx);
  124. {$endif SUPPORT_MMX}
  125. { error message, if more than 8 floating point }
  126. { registers are needed }
  127. if p^.registersfpu>8 then
  128. Message(cg_e_too_complex_expr);
  129. end;
  130. function both_rm(p : ptree) : boolean;
  131. begin
  132. both_rm:=(p^.left^.location.loc in [LOC_MEM,LOC_REFERENCE]) and
  133. (p^.right^.location.loc in [LOC_MEM,LOC_REFERENCE]);
  134. end;
  135. function is_assignment_overloaded(from_def,to_def : pdef) : boolean;forward;
  136. function isconvertable(def_from,def_to : pdef;
  137. var doconv : tconverttype;fromtreetype : ttreetyp;
  138. explicit : boolean) : boolean;
  139. { Tbasetype: uauto,uvoid,uchar,
  140. u8bit,u16bit,u32bit,
  141. s8bit,s16bit,s32,
  142. bool8bit,bool16bit,boot32bit }
  143. const
  144. basedefconverts : array[tbasetype,tbasetype] of tconverttype =
  145. {uauto}
  146. ((tc_not_possible,tc_not_possible,tc_not_possible,
  147. tc_not_possible,tc_not_possible,tc_not_possible,
  148. tc_not_possible,tc_not_possible,tc_not_possible,
  149. tc_not_possible,tc_not_possible,tc_not_possible),
  150. {uvoid}
  151. (tc_not_possible,tc_not_possible,tc_not_possible,
  152. tc_not_possible,tc_not_possible,tc_not_possible,
  153. tc_not_possible,tc_not_possible,tc_not_possible,
  154. tc_not_possible,tc_not_possible,tc_not_possible),
  155. {uchar}
  156. (tc_not_possible,tc_not_possible,tc_only_rangechecks32bit,
  157. tc_not_possible,tc_not_possible,tc_not_possible,
  158. tc_not_possible,tc_not_possible,tc_not_possible,
  159. tc_not_possible,tc_not_possible,tc_not_possible),
  160. {u8bit}
  161. (tc_not_possible,tc_not_possible,tc_not_possible,
  162. tc_only_rangechecks32bit,tc_u8bit_2_u16bit,tc_u8bit_2_u32bit,
  163. tc_only_rangechecks32bit,tc_u8bit_2_s16bit,tc_u8bit_2_s32bit,
  164. tc_int_2_bool,tc_int_2_bool,tc_int_2_bool),
  165. {u16bit}
  166. (tc_not_possible,tc_not_possible,tc_not_possible,
  167. tc_u16bit_2_u8bit,tc_only_rangechecks32bit,tc_u16bit_2_u32bit,
  168. tc_u16bit_2_s8bit,tc_only_rangechecks32bit,tc_u16bit_2_s32bit,
  169. tc_int_2_bool,tc_int_2_bool,tc_int_2_bool),
  170. {u32bit}
  171. (tc_not_possible,tc_not_possible,tc_not_possible,
  172. tc_u32bit_2_u8bit,tc_u32bit_2_u16bit,tc_only_rangechecks32bit,
  173. tc_u32bit_2_s8bit,tc_u32bit_2_s16bit,tc_only_rangechecks32bit,
  174. tc_int_2_bool,tc_int_2_bool,tc_int_2_bool),
  175. {s8bit}
  176. (tc_not_possible,tc_not_possible,tc_not_possible,
  177. tc_only_rangechecks32bit,tc_s8bit_2_u16bit,tc_s8bit_2_u32bit,
  178. tc_only_rangechecks32bit,tc_s8bit_2_s16bit,tc_s8bit_2_s32bit,
  179. tc_int_2_bool,tc_int_2_bool,tc_int_2_bool),
  180. {s16bit}
  181. (tc_not_possible,tc_not_possible,tc_not_possible,
  182. tc_s16bit_2_u8bit,tc_only_rangechecks32bit,tc_s16bit_2_u32bit,
  183. tc_s16bit_2_s8bit,tc_only_rangechecks32bit,tc_s16bit_2_s32bit,
  184. tc_int_2_bool,tc_int_2_bool,tc_int_2_bool),
  185. {s32bit}
  186. (tc_not_possible,tc_not_possible,tc_not_possible,
  187. tc_s32bit_2_u8bit,tc_s32bit_2_u16bit,tc_only_rangechecks32bit,
  188. tc_s32bit_2_s8bit,tc_s32bit_2_s16bit,tc_only_rangechecks32bit,
  189. tc_int_2_bool,tc_int_2_bool,tc_int_2_bool),
  190. {bool8bit}
  191. (tc_not_possible,tc_not_possible,tc_not_possible,
  192. tc_bool_2_int,tc_bool_2_int,tc_bool_2_int,
  193. tc_bool_2_int,tc_bool_2_int,tc_bool_2_int,
  194. tc_only_rangechecks32bit,tc_bool_2_int,tc_bool_2_int),
  195. {bool16bit}
  196. (tc_not_possible,tc_not_possible,tc_not_possible,
  197. tc_bool_2_int,tc_bool_2_int,tc_bool_2_int,
  198. tc_bool_2_int,tc_bool_2_int,tc_bool_2_int,
  199. tc_bool_2_int,tc_only_rangechecks32bit,tc_bool_2_int),
  200. {bool32bit}
  201. (tc_not_possible,tc_not_possible,tc_not_possible,
  202. tc_bool_2_int,tc_bool_2_int,tc_bool_2_int,
  203. tc_bool_2_int,tc_bool_2_int,tc_bool_2_int,
  204. tc_bool_2_int,tc_bool_2_int,tc_only_rangechecks32bit));
  205. var
  206. b : boolean;
  207. begin
  208. b:=false;
  209. if (not assigned(def_from)) or (not assigned(def_to)) then
  210. begin
  211. isconvertable:=false;
  212. exit;
  213. end;
  214. if (def_from^.deftype=orddef) and (def_to^.deftype=orddef) then
  215. begin
  216. doconv:=basedefconverts[porddef(def_from)^.typ,porddef(def_to)^.typ];
  217. if doconv<>tc_not_possible then
  218. b:=true;
  219. end
  220. else if (def_from^.deftype=orddef) and (def_to^.deftype=floatdef) then
  221. begin
  222. if pfloatdef(def_to)^.typ=f32bit then
  223. doconv:=tc_int_2_fix
  224. else
  225. doconv:=tc_int_2_real;
  226. b:=true;
  227. end
  228. else if (def_from^.deftype=floatdef) and (def_to^.deftype=floatdef) then
  229. begin
  230. if pfloatdef(def_from)^.typ=pfloatdef(def_to)^.typ then
  231. doconv:=tc_equal
  232. else
  233. begin
  234. if pfloatdef(def_from)^.typ=f32bit then
  235. doconv:=tc_fix_2_real
  236. else if pfloatdef(def_to)^.typ=f32bit then
  237. doconv:=tc_real_2_fix
  238. else
  239. doconv:=tc_real_2_real;
  240. { comp isn't a floating type }
  241. {$ifdef i386}
  242. if (pfloatdef(def_to)^.typ=s64bit) and
  243. (pfloatdef(def_from)^.typ<>s64bit) and
  244. not (explicit) then
  245. Message(parser_w_convert_real_2_comp);
  246. {$endif}
  247. end;
  248. b:=true;
  249. end
  250. { assignment overwritten ?? }
  251. else if is_assignment_overloaded(def_from,def_to) then
  252. b:=true
  253. else if (def_from^.deftype=pointerdef) and (def_to^.deftype=arraydef) and
  254. (parraydef(def_to)^.lowrange=0) and
  255. is_equal(ppointerdef(def_from)^.definition,
  256. parraydef(def_to)^.definition) then
  257. begin
  258. doconv:=tc_pointer_to_array;
  259. b:=true;
  260. end
  261. else if (def_from^.deftype=arraydef) and (def_to^.deftype=pointerdef) and
  262. (parraydef(def_from)^.lowrange=0) and
  263. is_equal(parraydef(def_from)^.definition,
  264. ppointerdef(def_to)^.definition) then
  265. begin
  266. doconv:=tc_array_to_pointer;
  267. b:=true;
  268. end
  269. { typed files are all equal to the abstract file type
  270. name TYPEDFILE in system.pp in is_equal in types.pas
  271. the problem is that it sholud be also compatible to FILE
  272. but this would leed to a problem for ASSIGN RESET and REWRITE
  273. when trying to find the good overloaded function !!
  274. so all file function are doubled in system.pp
  275. this is not very beautiful !!}
  276. else if (def_from^.deftype=filedef) and (def_to^.deftype=filedef) and
  277. (
  278. (
  279. (pfiledef(def_from)^.filetype = ft_typed) and
  280. (pfiledef(def_to)^.filetype = ft_typed) and
  281. (
  282. (pfiledef(def_from)^.typed_as = pdef(voiddef)) or
  283. (pfiledef(def_to)^.typed_as = pdef(voiddef))
  284. )
  285. ) or
  286. (
  287. (
  288. (pfiledef(def_from)^.filetype = ft_untyped) and
  289. (pfiledef(def_to)^.filetype = ft_typed)
  290. ) or
  291. (
  292. (pfiledef(def_from)^.filetype = ft_typed) and
  293. (pfiledef(def_to)^.filetype = ft_untyped)
  294. )
  295. )
  296. ) then
  297. begin
  298. doconv:=tc_equal;
  299. b:=true;
  300. end
  301. { object pascal objects }
  302. else if (def_from^.deftype=objectdef) and (def_to^.deftype=objectdef) {and
  303. pobjectdef(def_from)^.isclass and pobjectdef(def_to)^.isclass }then
  304. begin
  305. doconv:=tc_equal;
  306. b:=pobjectdef(def_from)^.isrelated(
  307. pobjectdef(def_to));
  308. end
  309. { class reference types }
  310. else if (def_from^.deftype=classrefdef) and (def_from^.deftype=classrefdef) then
  311. begin
  312. doconv:=tc_equal;
  313. b:=pobjectdef(pclassrefdef(def_from)^.definition)^.isrelated(
  314. pobjectdef(pclassrefdef(def_to)^.definition));
  315. end
  316. else if (def_from^.deftype=pointerdef) and (def_to^.deftype=pointerdef) then
  317. begin
  318. { child class pointer can be assigned to anchestor pointers }
  319. if (
  320. (ppointerdef(def_from)^.definition^.deftype=objectdef) and
  321. (ppointerdef(def_to)^.definition^.deftype=objectdef) and
  322. pobjectdef(ppointerdef(def_from)^.definition)^.isrelated(
  323. pobjectdef(ppointerdef(def_to)^.definition))
  324. ) or
  325. { all pointers can be assigned to void-pointer }
  326. is_equal(ppointerdef(def_to)^.definition,voiddef) or
  327. { in my opnion, is this not clean pascal }
  328. { well, but it's handy to use, it isn't ? (FK) }
  329. is_equal(ppointerdef(def_from)^.definition,voiddef) then
  330. begin
  331. doconv:=tc_equal;
  332. b:=true;
  333. end
  334. end
  335. else
  336. if (def_from^.deftype=stringdef) and (def_to^.deftype=stringdef) then
  337. begin
  338. doconv:=tc_string_to_string;
  339. b:=true;
  340. end
  341. else
  342. { char to string}
  343. if is_equal(def_from,cchardef) and
  344. (def_to^.deftype=stringdef) then
  345. begin
  346. doconv:=tc_char_to_string;
  347. b:=true;
  348. end
  349. else
  350. { string constant to zero terminated string constant }
  351. if (fromtreetype=stringconstn) and
  352. (
  353. (def_to^.deftype=pointerdef) and
  354. is_equal(Ppointerdef(def_to)^.definition,cchardef)
  355. ) then
  356. begin
  357. doconv:=tc_cstring_charpointer;
  358. b:=true;
  359. end
  360. else
  361. { array of char to string }
  362. { the length check is done by the firstpass of this node }
  363. if (def_from^.deftype=stringdef) and
  364. (
  365. (def_to^.deftype=arraydef) and
  366. is_equal(parraydef(def_to)^.definition,cchardef)
  367. ) then
  368. begin
  369. doconv:=tc_string_chararray;
  370. b:=true;
  371. end
  372. else
  373. { string to array of char }
  374. { the length check is done by the firstpass of this node }
  375. if (
  376. (def_from^.deftype=arraydef) and
  377. is_equal(parraydef(def_from)^.definition,cchardef)
  378. ) and
  379. (def_to^.deftype=stringdef) then
  380. begin
  381. doconv:=tc_chararray_2_string;
  382. b:=true;
  383. end
  384. else
  385. if (fromtreetype=ordconstn) and is_equal(def_from,cchardef) then
  386. begin
  387. if (def_to^.deftype=pointerdef) and
  388. is_equal(ppointerdef(def_to)^.definition,cchardef) then
  389. begin
  390. doconv:=tc_cchar_charpointer;
  391. b:=true;
  392. end;
  393. end
  394. else
  395. if (def_to^.deftype=procvardef) and (def_from^.deftype=procdef) then
  396. begin
  397. def_from^.deftype:=procvardef;
  398. doconv:=tc_proc2procvar;
  399. b:=is_equal(def_from,def_to);
  400. def_from^.deftype:=procdef;
  401. end
  402. else
  403. { nil is compatible with class instances }
  404. if (fromtreetype=niln) and (def_to^.deftype=objectdef)
  405. and (pobjectdef(def_to)^.isclass) then
  406. begin
  407. doconv:=tc_equal;
  408. b:=true;
  409. end
  410. else
  411. { nil is compatible with class references }
  412. if (fromtreetype=niln) and (def_to^.deftype=classrefdef) then
  413. begin
  414. doconv:=tc_equal;
  415. b:=true;
  416. end
  417. else
  418. { nil is compatible with procvars }
  419. if (fromtreetype=niln) and (def_to^.deftype=procvardef) then
  420. begin
  421. doconv:=tc_equal;
  422. b:=true;
  423. end
  424. else
  425. { nil is compatible with ansi- and wide strings }
  426. if (fromtreetype=niln) and (def_to^.deftype=stringdef)
  427. and (pstringdef(def_to)^.string_typ in [st_ansistring,st_widestring]) then
  428. begin
  429. doconv:=tc_equal;
  430. b:=true;
  431. end
  432. else
  433. { ansi- and wide strings can be assigned to void pointers }
  434. if (def_from^.deftype=stringdef) and
  435. (pstringdef(def_from)^.string_typ in [st_ansistring,st_widestring]) and
  436. (def_to^.deftype=pointerdef) and
  437. (ppointerdef(def_to)^.definition^.deftype=orddef) and
  438. (porddef(ppointerdef(def_to)^.definition)^.typ=uvoid) then
  439. begin
  440. doconv:=tc_equal;
  441. b:=true;
  442. end
  443. { procedure variable can be assigned to an void pointer }
  444. { Not anymore. Use the @ operator now.}
  445. else
  446. if not (cs_tp_compatible in aktmoduleswitches) then
  447. begin
  448. if (def_from^.deftype=procvardef) and
  449. (def_to^.deftype=pointerdef) and
  450. (ppointerdef(def_to)^.definition^.deftype=orddef) and
  451. (porddef(ppointerdef(def_to)^.definition)^.typ=uvoid) then
  452. begin
  453. doconv:=tc_equal;
  454. b:=true;
  455. end;
  456. end;
  457. isconvertable:=b;
  458. end;
  459. procedure firsterror(var p : ptree);
  460. begin
  461. p^.error:=true;
  462. codegenerror:=true;
  463. p^.resulttype:=generrordef;
  464. end;
  465. procedure firstload(var p : ptree);
  466. begin
  467. p^.location.loc:=LOC_REFERENCE;
  468. p^.registers32:=0;
  469. p^.registersfpu:=0;
  470. {$ifdef SUPPORT_MMX}
  471. p^.registersmmx:=0;
  472. {$endif SUPPORT_MMX}
  473. clear_reference(p^.location.reference);
  474. {$ifdef TEST_FUNCRET}
  475. if p^.symtableentry^.typ=funcretsym then
  476. begin
  477. putnode(p);
  478. p:=genzeronode(funcretn);
  479. p^.funcretprocinfo:=pprocinfo(pfuncretsym(p^.symtableentry)^.funcretprocinfo);
  480. p^.retdef:=pfuncretsym(p^.symtableentry)^.funcretdef;
  481. firstpass(p);
  482. exit;
  483. end;
  484. {$endif TEST_FUNCRET}
  485. if p^.symtableentry^.typ=absolutesym then
  486. begin
  487. p^.resulttype:=pabsolutesym(p^.symtableentry)^.definition;
  488. if pabsolutesym(p^.symtableentry)^.abstyp=tovar then
  489. p^.symtableentry:=pabsolutesym(p^.symtableentry)^.ref;
  490. p^.symtable:=p^.symtableentry^.owner;
  491. p^.is_absolute:=true;
  492. end;
  493. case p^.symtableentry^.typ of
  494. absolutesym :;
  495. varsym :
  496. begin
  497. if not(p^.is_absolute) and (p^.resulttype=nil) then
  498. p^.resulttype:=pvarsym(p^.symtableentry)^.definition;
  499. if ((p^.symtable^.symtabletype=parasymtable) or
  500. (p^.symtable^.symtabletype=localsymtable)) and
  501. (lexlevel>p^.symtable^.symtablelevel) then
  502. begin
  503. { sollte sich die Variable in einem anderen Stackframe }
  504. { befinden, so brauchen wir ein Register zum Dereferenceieren }
  505. if (p^.symtable^.symtablelevel)>0 then
  506. begin
  507. p^.registers32:=1;
  508. { auáerdem kann sie nicht mehr in ein Register
  509. geladen werden }
  510. pvarsym(p^.symtableentry)^.var_options :=
  511. pvarsym(p^.symtableentry)^.var_options and not vo_regable;
  512. end;
  513. end;
  514. if (pvarsym(p^.symtableentry)^.varspez=vs_const) then
  515. p^.location.loc:=LOC_MEM;
  516. { we need a register for call by reference parameters }
  517. if (pvarsym(p^.symtableentry)^.varspez=vs_var) or
  518. ((pvarsym(p^.symtableentry)^.varspez=vs_const) and
  519. dont_copy_const_param(pvarsym(p^.symtableentry)^.definition)
  520. ) or
  521. { call by value open arrays are also indirect addressed }
  522. is_open_array(pvarsym(p^.symtableentry)^.definition) then
  523. p^.registers32:=1;
  524. if p^.symtable^.symtabletype=withsymtable then
  525. p^.registers32:=1;
  526. { a class variable is a pointer !!!
  527. yes, but we have to resolve the reference in an
  528. appropriate tree node (FK)
  529. if (pvarsym(p^.symtableentry)^.definition^.deftype=objectdef) and
  530. ((pobjectdef(pvarsym(p^.symtableentry)^.definition)^.options and oois_class)<>0) then
  531. p^.registers32:=1;
  532. }
  533. { count variable references }
  534. if must_be_valid and p^.is_first then
  535. begin
  536. if pvarsym(p^.symtableentry)^.is_valid=2 then
  537. if (assigned(pvarsym(p^.symtableentry)^.owner) and assigned(aktprocsym)
  538. and (pvarsym(p^.symtableentry)^.owner = aktprocsym^.definition^.localst)) then
  539. Message1(sym_n_uninitialized_local_variable,pvarsym(p^.symtableentry)^.name);
  540. end;
  541. if count_ref then
  542. begin
  543. if (p^.is_first) then
  544. begin
  545. if (pvarsym(p^.symtableentry)^.is_valid=2) then
  546. pvarsym(p^.symtableentry)^.is_valid:=1;
  547. p^.is_first:=false;
  548. end;
  549. end;
  550. { this will create problem with local var set by
  551. under_procedures
  552. if (assigned(pvarsym(p^.symtableentry)^.owner) and assigned(aktprocsym)
  553. and ((pvarsym(p^.symtableentry)^.owner = aktprocsym^.definition^.localst)
  554. or (pvarsym(p^.symtableentry)^.owner = aktprocsym^.definition^.localst))) then }
  555. if t_times<1 then
  556. inc(pvarsym(p^.symtableentry)^.refs)
  557. else
  558. inc(pvarsym(p^.symtableentry)^.refs,t_times);
  559. end;
  560. typedconstsym :
  561. if not p^.is_absolute then
  562. p^.resulttype:=ptypedconstsym(p^.symtableentry)^.definition;
  563. procsym :
  564. begin
  565. if assigned(pprocsym(p^.symtableentry)^.definition^.nextoverloaded) then
  566. Message(parser_e_no_overloaded_procvars);
  567. p^.resulttype:=pprocsym(p^.symtableentry)^.definition;
  568. end;
  569. else internalerror(3);
  570. end;
  571. end;
  572. procedure firstadd(var p : ptree);
  573. procedure make_bool_equal_size(var p:ptree);
  574. begin
  575. if porddef(p^.left^.resulttype)^.typ>porddef(p^.right^.resulttype)^.typ then
  576. begin
  577. p^.right:=gentypeconvnode(p^.right,porddef(p^.left^.resulttype));
  578. p^.right^.convtyp:=tc_bool_2_int;
  579. p^.right^.explizit:=true;
  580. firstpass(p^.right);
  581. end
  582. else
  583. if porddef(p^.left^.resulttype)^.typ<porddef(p^.right^.resulttype)^.typ then
  584. begin
  585. p^.left:=gentypeconvnode(p^.left,porddef(p^.right^.resulttype));
  586. p^.left^.convtyp:=tc_bool_2_int;
  587. p^.left^.explizit:=true;
  588. firstpass(p^.left);
  589. end;
  590. end;
  591. var
  592. lt,rt : ttreetyp;
  593. t : ptree;
  594. rv,lv : longint;
  595. rvd,lvd : {double}bestreal;
  596. rd,ld : pdef;
  597. concatstrings : boolean;
  598. { to evalute const sets }
  599. resultset : pconstset;
  600. i : longint;
  601. b : boolean;
  602. {$ifndef UseAnsiString}
  603. s1,s2:^string;
  604. {$else UseAnsiString}
  605. s1,s2 : pchar;
  606. l1,l2 : longint;
  607. {$endif UseAnsiString}
  608. { this totally forgets to set the pi_do_call flag !! }
  609. label
  610. no_overload;
  611. begin
  612. { first do the two subtrees }
  613. firstpass(p^.left);
  614. firstpass(p^.right);
  615. lt:=p^.left^.treetype;
  616. rt:=p^.right^.treetype;
  617. rd:=p^.right^.resulttype;
  618. ld:=p^.left^.resulttype;
  619. if codegenerror then
  620. exit;
  621. { overloaded operator ? }
  622. if (p^.treetype=starstarn) or
  623. (ld^.deftype=recorddef) or
  624. { <> and = are defined for classes }
  625. ((ld^.deftype=objectdef) and
  626. (not(pobjectdef(ld)^.isclass) or
  627. not(p^.treetype in [equaln,unequaln])
  628. )
  629. ) or
  630. (rd^.deftype=recorddef) or
  631. { <> and = are defined for classes }
  632. ((rd^.deftype=objectdef) and
  633. (not(pobjectdef(rd)^.isclass) or
  634. not(p^.treetype in [equaln,unequaln])
  635. )
  636. ) then
  637. begin
  638. {!!!!!!!!! handle paras }
  639. case p^.treetype of
  640. { the nil as symtable signs firstcalln that this is
  641. an overloaded operator }
  642. addn:
  643. t:=gencallnode(overloaded_operators[plus],nil);
  644. subn:
  645. t:=gencallnode(overloaded_operators[minus],nil);
  646. muln:
  647. t:=gencallnode(overloaded_operators[star],nil);
  648. starstarn:
  649. t:=gencallnode(overloaded_operators[starstar],nil);
  650. slashn:
  651. t:=gencallnode(overloaded_operators[slash],nil);
  652. ltn:
  653. t:=gencallnode(overloaded_operators[globals.lt],nil);
  654. gtn:
  655. t:=gencallnode(overloaded_operators[gt],nil);
  656. lten:
  657. t:=gencallnode(overloaded_operators[lte],nil);
  658. gten:
  659. t:=gencallnode(overloaded_operators[gte],nil);
  660. equaln,unequaln :
  661. t:=gencallnode(overloaded_operators[equal],nil);
  662. else goto no_overload;
  663. end;
  664. { we have to convert p^.left and p^.right into
  665. callparanodes }
  666. t^.left:=gencallparanode(p^.left,nil);
  667. t^.left:=gencallparanode(p^.right,t^.left);
  668. if t^.symtableprocentry=nil then
  669. Message(parser_e_operator_not_overloaded);
  670. if p^.treetype=unequaln then
  671. t:=gensinglenode(notn,t);
  672. firstpass(t);
  673. putnode(p);
  674. p:=t;
  675. exit;
  676. end;
  677. no_overload:
  678. { compact consts }
  679. { convert int consts to real consts, if the }
  680. { other operand is a real const }
  681. if is_constintnode(p^.left) and
  682. (rt=realconstn) then
  683. begin
  684. t:=genrealconstnode(p^.left^.value);
  685. disposetree(p^.left);
  686. p^.left:=t;
  687. lt:=realconstn;
  688. end;
  689. if is_constintnode(p^.right) and
  690. (lt=realconstn) then
  691. begin
  692. t:=genrealconstnode(p^.right^.value);
  693. disposetree(p^.right);
  694. p^.right:=t;
  695. rt:=realconstn;
  696. end;
  697. if is_constintnode(p^.left) and
  698. is_constintnode(p^.right) then
  699. begin
  700. lv:=p^.left^.value;
  701. rv:=p^.right^.value;
  702. case p^.treetype of
  703. addn:
  704. t:=genordinalconstnode(lv+rv,s32bitdef);
  705. subn:
  706. t:=genordinalconstnode(lv-rv,s32bitdef);
  707. muln:
  708. t:=genordinalconstnode(lv*rv,s32bitdef);
  709. xorn:
  710. t:=genordinalconstnode(lv xor rv,s32bitdef);
  711. orn:
  712. t:=genordinalconstnode(lv or rv,s32bitdef);
  713. andn:
  714. t:=genordinalconstnode(lv and rv,s32bitdef);
  715. ltn:
  716. t:=genordinalconstnode(ord(lv<rv),booldef);
  717. lten:
  718. t:=genordinalconstnode(ord(lv<=rv),booldef);
  719. gtn:
  720. t:=genordinalconstnode(ord(lv>rv),booldef);
  721. gten:
  722. t:=genordinalconstnode(ord(lv>=rv),booldef);
  723. equaln:
  724. t:=genordinalconstnode(ord(lv=rv),booldef);
  725. unequaln:
  726. t:=genordinalconstnode(ord(lv<>rv),booldef);
  727. slashn :
  728. begin
  729. { int/int becomes a real }
  730. t:=genrealconstnode(int(lv)/int(rv));
  731. firstpass(t);
  732. end;
  733. else
  734. Message(sym_e_type_mismatch);
  735. end;
  736. disposetree(p);
  737. firstpass(t);
  738. p:=t;
  739. exit;
  740. end
  741. else
  742. { real constants }
  743. if (lt=realconstn) and (rt=realconstn) then
  744. begin
  745. lvd:=p^.left^.valued;
  746. rvd:=p^.right^.valued;
  747. case p^.treetype of
  748. addn:
  749. t:=genrealconstnode(lvd+rvd);
  750. subn:
  751. t:=genrealconstnode(lvd-rvd);
  752. muln:
  753. t:=genrealconstnode(lvd*rvd);
  754. caretn:
  755. t:=genrealconstnode(exp(ln(lvd)*rvd));
  756. slashn:
  757. t:=genrealconstnode(lvd/rvd);
  758. ltn:
  759. t:=genordinalconstnode(ord(lvd<rvd),booldef);
  760. lten:
  761. t:=genordinalconstnode(ord(lvd<=rvd),booldef);
  762. gtn:
  763. t:=genordinalconstnode(ord(lvd>rvd),booldef);
  764. gten:
  765. t:=genordinalconstnode(ord(lvd>=rvd),booldef);
  766. equaln:
  767. t:=genordinalconstnode(ord(lvd=rvd),booldef);
  768. unequaln:
  769. t:=genordinalconstnode(ord(lvd<>rvd),booldef);
  770. else
  771. Message(sym_e_type_mismatch);
  772. end;
  773. disposetree(p);
  774. p:=t;
  775. firstpass(p);
  776. exit;
  777. end;
  778. concatstrings:=false;
  779. {$ifdef UseAnsiString}
  780. s1:=nil;
  781. s2:=nil;
  782. {$else UseAnsiString}
  783. new(s1);
  784. new(s2);
  785. {$endif UseAnsiString}
  786. if (lt=ordconstn) and (rt=ordconstn) and
  787. (ld^.deftype=orddef) and
  788. (porddef(ld)^.typ=uchar) and
  789. (rd^.deftype=orddef) and
  790. (porddef(rd)^.typ=uchar) then
  791. begin
  792. {$ifdef UseAnsiString}
  793. s1:=strpnew(char(byte(p^.left^.value)));
  794. s2:=strpnew(char(byte(p^.right^.value)));
  795. l1:=1;l2:=1;
  796. {$else UseAnsiString}
  797. s1^:=char(byte(p^.left^.value));
  798. s2^:=char(byte(p^.right^.value));
  799. concatstrings:=true;
  800. {$endif UseAnsiString}
  801. end
  802. else if (lt=stringconstn) and (rt=ordconstn) and
  803. (rd^.deftype=orddef) and
  804. (porddef(rd)^.typ=uchar) then
  805. begin
  806. {$ifdef UseAnsiString}
  807. { here there is allways the damn #0 problem !! }
  808. s1:=getpcharcopy(p^.left);
  809. l1:=p^.left^.length;
  810. s2:=strpnew(char(byte(p^.right^.value)));
  811. l2:=1;
  812. {$else UseAnsiString}
  813. s1^:=p^.left^.values^;
  814. s2^:=char(byte(p^.right^.value));
  815. concatstrings:=true;
  816. {$endif UseAnsiString}
  817. end
  818. else if (lt=ordconstn) and (rt=stringconstn) and
  819. (ld^.deftype=orddef) and
  820. (porddef(ld)^.typ=uchar) then
  821. begin
  822. {$ifdef UseAnsiString}
  823. { here there is allways the damn #0 problem !! }
  824. s1:=strpnew(char(byte(p^.left^.value)));
  825. l1:=1;
  826. s2:=getpcharcopy(p^.right);
  827. l2:=p^.right^.length;
  828. {$else UseAnsiString}
  829. s1^:=char(byte(p^.left^.value));
  830. s2^:=p^.right^.values^;
  831. concatstrings:=true;
  832. {$endif UseAnsiString}
  833. end
  834. else if (lt=stringconstn) and (rt=stringconstn) then
  835. begin
  836. {$ifdef UseAnsiString}
  837. s1:=getpcharcopy(p^.left);
  838. l1:=p^.left^.length;
  839. s2:=getpcharcopy(p^.right);
  840. l2:=p^.right^.length;
  841. concatstrings:=true;
  842. {$else UseAnsiString}
  843. s1^:=p^.left^.values^;
  844. s2^:=p^.right^.values^;
  845. concatstrings:=true;
  846. {$endif UseAnsiString}
  847. end;
  848. { I will need to translate all this to ansistrings !!! }
  849. if concatstrings then
  850. begin
  851. case p^.treetype of
  852. {$ifndef UseAnsiString}
  853. addn : t:=genstringconstnode(s1^+s2^);
  854. ltn : t:=genordinalconstnode(byte(s1^<s2^),booldef);
  855. lten : t:=genordinalconstnode(byte(s1^<=s2^),booldef);
  856. gtn : t:=genordinalconstnode(byte(s1^>s2^),booldef);
  857. gten : t:=genordinalconstnode(byte(s1^>=s2^),booldef);
  858. equaln : t:=genordinalconstnode(byte(s1^=s2^),booldef);
  859. unequaln : t:=genordinalconstnode(byte(s1^<>s2^),booldef);
  860. {$else UseAnsiString}
  861. addn : t:=genpcharconstnode(
  862. concatansistrings(s1,s2,l1,l2),l1+l2);
  863. ltn : t:=genordinalconstnode(
  864. byte(compareansistrings(s1,s2,l1,l2)<0),booldef);
  865. lten : t:=genordinalconstnode(
  866. byte(compareansistrings(s1,s2,l1,l2)<=0),booldef);
  867. gtn : t:=genordinalconstnode(
  868. byte(compareansistrings(s1,s2,l1,l2)>0),booldef);
  869. gten : t:=genordinalconstnode(
  870. byte(compareansistrings(s1,s2,l1,l2)>=0),booldef);
  871. equaln : t:=genordinalconstnode(
  872. byte(compareansistrings(s1,s2,l1,l2)=0),booldef);
  873. unequaln : t:=genordinalconstnode(
  874. byte(compareansistrings(s1,s2,l1,l2)<>0),booldef);
  875. {$endif UseAnsiString}
  876. end;
  877. {$ifdef UseAnsiString}
  878. ansistringdispose(s1,l1);
  879. ansistringdispose(s2,l2);
  880. {$else UseAnsiString}
  881. dispose(s1);
  882. dispose(s2);
  883. {$endif UseAnsiString}
  884. disposetree(p);
  885. firstpass(t);
  886. p:=t;
  887. exit;
  888. end;
  889. {$ifdef UseAnsiString}
  890. ansistringdispose(s1,l1);
  891. ansistringdispose(s2,l2);
  892. {$else UseAnsiString}
  893. dispose(s1);
  894. dispose(s2);
  895. {$endif UseAnsiString}
  896. { we can set this globally but it not allways true }
  897. { procinfo.flags:=procinfo.flags or pi_do_call; }
  898. { if both are boolean: }
  899. if ((ld^.deftype=orddef) and
  900. (porddef(ld)^.typ in [bool8bit,bool16bit,bool32bit])) and
  901. ((rd^.deftype=orddef) and
  902. (porddef(rd)^.typ in [bool8bit,bool16bit,bool32bit])) then
  903. begin
  904. case p^.treetype of
  905. andn,orn : begin
  906. calcregisters(p,0,0,0);
  907. p^.location.loc:=LOC_JUMP;
  908. end;
  909. unequaln,
  910. equaln,xorn : begin
  911. make_bool_equal_size(p);
  912. calcregisters(p,1,0,0);
  913. end
  914. else
  915. Message(sym_e_type_mismatch);
  916. end;
  917. end
  918. { wenn beides vom Char dann keine Konvertiereung einf�gen }
  919. { h”chstens es handelt sich um einen +-Operator }
  920. else if ((rd^.deftype=orddef) and (porddef(rd)^.typ=uchar)) and
  921. ((ld^.deftype=orddef) and (porddef(ld)^.typ=uchar)) then
  922. begin
  923. if p^.treetype=addn then
  924. begin
  925. p^.left:=gentypeconvnode(p^.left,cstringdef);
  926. firstpass(p^.left);
  927. p^.right:=gentypeconvnode(p^.right,cstringdef);
  928. firstpass(p^.right);
  929. { here we call STRCOPY }
  930. procinfo.flags:=procinfo.flags or pi_do_call;
  931. calcregisters(p,0,0,0);
  932. p^.location.loc:=LOC_MEM;
  933. end
  934. else
  935. calcregisters(p,1,0,0);
  936. end
  937. { if string and character, then conver the character to a string }
  938. else if ((rd^.deftype=stringdef) and
  939. ((ld^.deftype=orddef) and (porddef(ld)^.typ=uchar))) or
  940. ((ld^.deftype=stringdef) and
  941. ((rd^.deftype=orddef) and (porddef(rd)^.typ=uchar))) then
  942. begin
  943. if ((ld^.deftype=orddef) and (porddef(ld)^.typ=uchar)) then
  944. p^.left:=gentypeconvnode(p^.left,cstringdef)
  945. else
  946. p^.right:=gentypeconvnode(p^.right,cstringdef);
  947. firstpass(p^.left);
  948. firstpass(p^.right);
  949. { here we call STRCONCAT or STRCMP }
  950. procinfo.flags:=procinfo.flags or pi_do_call;
  951. calcregisters(p,0,0,0);
  952. p^.location.loc:=LOC_MEM;
  953. end
  954. else
  955. if ((rd^.deftype=setdef) and (ld^.deftype=setdef)) then
  956. begin
  957. case p^.treetype of
  958. subn,symdifn,addn,muln,equaln,unequaln : ;
  959. else Message(sym_e_type_mismatch);
  960. end;
  961. if not(is_equal(rd,ld)) then
  962. Message(sym_e_set_element_are_not_comp);
  963. { why here its is alredy in entry of firstadd
  964. firstpass(p^.left);
  965. firstpass(p^.right); }
  966. { do constant evalution }
  967. { set constructor ? }
  968. if (p^.right^.treetype=setconstrn) and
  969. (p^.left^.treetype=setconstrn) and
  970. { and no variables ? }
  971. (p^.right^.left=nil) and
  972. (p^.left^.left=nil) then
  973. begin
  974. new(resultset);
  975. case p^.treetype of
  976. addn : begin
  977. for i:=0 to 31 do
  978. resultset^[i]:=
  979. p^.right^.constset^[i] or p^.left^.constset^[i];
  980. t:=gensetconstruktnode(resultset,psetdef(ld));
  981. end;
  982. muln : begin
  983. for i:=0 to 31 do
  984. resultset^[i]:=
  985. p^.right^.constset^[i] and p^.left^.constset^[i];
  986. t:=gensetconstruktnode(resultset,psetdef(ld));
  987. end;
  988. subn : begin
  989. for i:=0 to 31 do
  990. resultset^[i]:=
  991. p^.left^.constset^[i] and not(p^.right^.constset^[i]);
  992. t:=gensetconstruktnode(resultset,psetdef(ld));
  993. end;
  994. symdifn : begin
  995. for i:=0 to 31 do
  996. resultset^[i]:=
  997. p^.left^.constset^[i] xor p^.right^.constset^[i];
  998. t:=gensetconstruktnode(resultset,psetdef(ld));
  999. end;
  1000. unequaln : begin
  1001. b:=true;
  1002. for i:=0 to 31 do
  1003. if p^.right^.constset^[i]=p^.left^.constset^[i] then
  1004. begin
  1005. b:=false;
  1006. break;
  1007. end;
  1008. t:=genordinalconstnode(ord(b),booldef);
  1009. end;
  1010. equaln : begin
  1011. b:=true;
  1012. for i:=0 to 31 do
  1013. if p^.right^.constset^[i]<>p^.left^.constset^[i] then
  1014. begin
  1015. b:=false;
  1016. break;
  1017. end;
  1018. t:=genordinalconstnode(ord(b),booldef);
  1019. end;
  1020. end;
  1021. dispose(resultset);
  1022. disposetree(p);
  1023. p:=t;
  1024. firstpass(p);
  1025. exit;
  1026. end
  1027. else if psetdef(rd)^.settype=smallset then
  1028. begin
  1029. calcregisters(p,1,0,0);
  1030. p^.location.loc:=LOC_REGISTER;
  1031. end
  1032. else
  1033. begin
  1034. calcregisters(p,0,0,0);
  1035. { here we call SET... }
  1036. procinfo.flags:=procinfo.flags or pi_do_call;
  1037. p^.location.loc:=LOC_MEM;
  1038. end;
  1039. end
  1040. else
  1041. if ((rd^.deftype=stringdef) and (ld^.deftype=stringdef)) then
  1042. { here we call STR... }
  1043. procinfo.flags:=procinfo.flags or pi_do_call
  1044. { if there is a real float, convert both to float 80 bit }
  1045. else
  1046. if ((rd^.deftype=floatdef) and (pfloatdef(rd)^.typ<>f32bit)) or
  1047. ((ld^.deftype=floatdef) and (pfloatdef(ld)^.typ<>f32bit)) then
  1048. begin
  1049. p^.right:=gentypeconvnode(p^.right,c64floatdef);
  1050. p^.left:=gentypeconvnode(p^.left,c64floatdef);
  1051. firstpass(p^.left);
  1052. firstpass(p^.right);
  1053. calcregisters(p,1,1,0);
  1054. p^.location.loc:=LOC_FPU;
  1055. end
  1056. else
  1057. { if there is one fix comma number, convert both to 32 bit fixcomma }
  1058. if ((rd^.deftype=floatdef) and (pfloatdef(rd)^.typ=f32bit)) or
  1059. ((ld^.deftype=floatdef) and (pfloatdef(ld)^.typ=f32bit)) then
  1060. begin
  1061. if not(porddef(rd)^.typ in [u8bit,s8bit,u16bit,
  1062. s16bit,s32bit]) or (p^.treetype<>muln) then
  1063. p^.right:=gentypeconvnode(p^.right,s32fixeddef);
  1064. if not(porddef(rd)^.typ in [u8bit,s8bit,u16bit,
  1065. s16bit,s32bit]) or (p^.treetype<>muln) then
  1066. p^.left:=gentypeconvnode(p^.left,s32fixeddef);
  1067. firstpass(p^.left);
  1068. firstpass(p^.right);
  1069. calcregisters(p,1,0,0);
  1070. p^.location.loc:=LOC_REGISTER;
  1071. end
  1072. { pointer comperation and subtraction }
  1073. else if (rd^.deftype=pointerdef) and (ld^.deftype=pointerdef) then
  1074. begin
  1075. p^.location.loc:=LOC_REGISTER;
  1076. p^.right:=gentypeconvnode(p^.right,ld);
  1077. firstpass(p^.right);
  1078. calcregisters(p,1,0,0);
  1079. case p^.treetype of
  1080. equaln,unequaln : ;
  1081. ltn,lten,gtn,gten:
  1082. begin
  1083. if not(cs_extsyntax in aktmoduleswitches) then
  1084. Message(sym_e_type_mismatch);
  1085. end;
  1086. subn:
  1087. begin
  1088. if not(cs_extsyntax in aktmoduleswitches) then
  1089. Message(sym_e_type_mismatch);
  1090. p^.resulttype:=s32bitdef;
  1091. exit;
  1092. end;
  1093. else Message(sym_e_type_mismatch);
  1094. end;
  1095. end
  1096. else if (rd^.deftype=objectdef) and (ld^.deftype=objectdef) and
  1097. pobjectdef(rd)^.isclass and pobjectdef(ld)^.isclass then
  1098. begin
  1099. p^.location.loc:=LOC_REGISTER;
  1100. if pobjectdef(rd)^.isrelated(pobjectdef(ld)) then
  1101. p^.right:=gentypeconvnode(p^.right,ld)
  1102. else
  1103. p^.left:=gentypeconvnode(p^.left,rd);
  1104. firstpass(p^.right);
  1105. firstpass(p^.left);
  1106. calcregisters(p,1,0,0);
  1107. case p^.treetype of
  1108. equaln,unequaln : ;
  1109. else Message(sym_e_type_mismatch);
  1110. end;
  1111. end
  1112. else if (rd^.deftype=classrefdef) and (ld^.deftype=classrefdef) then
  1113. begin
  1114. p^.location.loc:=LOC_REGISTER;
  1115. if pobjectdef(pclassrefdef(rd)^.definition)^.isrelated(pobjectdef(
  1116. pclassrefdef(ld)^.definition)) then
  1117. p^.right:=gentypeconvnode(p^.right,ld)
  1118. else
  1119. p^.left:=gentypeconvnode(p^.left,rd);
  1120. firstpass(p^.right);
  1121. firstpass(p^.left);
  1122. calcregisters(p,1,0,0);
  1123. case p^.treetype of
  1124. equaln,unequaln : ;
  1125. else Message(sym_e_type_mismatch);
  1126. end;
  1127. end
  1128. { allows comperasion with nil pointer }
  1129. else if (rd^.deftype=objectdef) and
  1130. pobjectdef(rd)^.isclass then
  1131. begin
  1132. p^.location.loc:=LOC_REGISTER;
  1133. p^.left:=gentypeconvnode(p^.left,rd);
  1134. firstpass(p^.left);
  1135. calcregisters(p,1,0,0);
  1136. case p^.treetype of
  1137. equaln,unequaln : ;
  1138. else Message(sym_e_type_mismatch);
  1139. end;
  1140. end
  1141. else if (ld^.deftype=objectdef) and
  1142. pobjectdef(ld)^.isclass then
  1143. begin
  1144. p^.location.loc:=LOC_REGISTER;
  1145. p^.right:=gentypeconvnode(p^.right,ld);
  1146. firstpass(p^.right);
  1147. calcregisters(p,1,0,0);
  1148. case p^.treetype of
  1149. equaln,unequaln : ;
  1150. else Message(sym_e_type_mismatch);
  1151. end;
  1152. end
  1153. else if (rd^.deftype=classrefdef) then
  1154. begin
  1155. p^.left:=gentypeconvnode(p^.left,rd);
  1156. firstpass(p^.left);
  1157. calcregisters(p,1,0,0);
  1158. case p^.treetype of
  1159. equaln,unequaln : ;
  1160. else Message(sym_e_type_mismatch);
  1161. end;
  1162. end
  1163. else if (ld^.deftype=classrefdef) then
  1164. begin
  1165. p^.right:=gentypeconvnode(p^.right,ld);
  1166. firstpass(p^.right);
  1167. calcregisters(p,1,0,0);
  1168. case p^.treetype of
  1169. equaln,unequaln : ;
  1170. else Message(sym_e_type_mismatch);
  1171. end;
  1172. end
  1173. else if (rd^.deftype=pointerdef) then
  1174. begin
  1175. p^.location.loc:=LOC_REGISTER;
  1176. p^.left:=gentypeconvnode(p^.left,s32bitdef);
  1177. firstpass(p^.left);
  1178. calcregisters(p,1,0,0);
  1179. if p^.treetype=addn then
  1180. begin
  1181. if not(cs_extsyntax in aktmoduleswitches) then
  1182. Message(sym_e_type_mismatch);
  1183. end
  1184. else Message(sym_e_type_mismatch);
  1185. end
  1186. else if (ld^.deftype=pointerdef) then
  1187. begin
  1188. p^.location.loc:=LOC_REGISTER;
  1189. p^.right:=gentypeconvnode(p^.right,s32bitdef);
  1190. firstpass(p^.right);
  1191. calcregisters(p,1,0,0);
  1192. case p^.treetype of
  1193. addn,subn : if not(cs_extsyntax in aktmoduleswitches) then
  1194. Message(sym_e_type_mismatch);
  1195. else Message(sym_e_type_mismatch);
  1196. end;
  1197. end
  1198. else if (rd^.deftype=procvardef) and (ld^.deftype=procvardef) and
  1199. is_equal(rd,ld) then
  1200. begin
  1201. calcregisters(p,1,0,0);
  1202. p^.location.loc:=LOC_REGISTER;
  1203. case p^.treetype of
  1204. equaln,unequaln : ;
  1205. else Message(sym_e_type_mismatch);
  1206. end;
  1207. end
  1208. else if (ld^.deftype=enumdef) and (rd^.deftype=enumdef)
  1209. and (is_equal(ld,rd)) then
  1210. begin
  1211. calcregisters(p,1,0,0);
  1212. case p^.treetype of
  1213. equaln,unequaln,
  1214. ltn,lten,gtn,gten : ;
  1215. else Message(sym_e_type_mismatch);
  1216. end;
  1217. end
  1218. {$ifdef SUPPORT_MMX}
  1219. else if (cs_mmx in aktmoduleswitches) and is_mmx_able_array(ld)
  1220. and is_mmx_able_array(rd) and is_equal(ld,rd) then
  1221. begin
  1222. firstpass(p^.right);
  1223. firstpass(p^.left);
  1224. case p^.treetype of
  1225. addn,subn,xorn,orn,andn:
  1226. ;
  1227. { mul is a little bit restricted }
  1228. muln:
  1229. if not(mmx_type(p^.left^.resulttype) in
  1230. [mmxu16bit,mmxs16bit,mmxfixed16]) then
  1231. Message(sym_e_type_mismatch);
  1232. else
  1233. Message(sym_e_type_mismatch);
  1234. end;
  1235. p^.location.loc:=LOC_MMXREGISTER;
  1236. calcregisters(p,0,0,1);
  1237. end
  1238. {$endif SUPPORT_MMX}
  1239. { the general solution is to convert to 32 bit int }
  1240. else
  1241. begin
  1242. { but an int/int gives real/real! }
  1243. if p^.treetype=slashn then
  1244. begin
  1245. Message(parser_w_use_int_div_int_op);
  1246. p^.right:=gentypeconvnode(p^.right,c64floatdef);
  1247. p^.left:=gentypeconvnode(p^.left,c64floatdef);
  1248. firstpass(p^.left);
  1249. firstpass(p^.right);
  1250. { maybe we need an integer register to save }
  1251. { a reference }
  1252. if ((p^.left^.location.loc<>LOC_FPU) or
  1253. (p^.right^.location.loc<>LOC_FPU)) and
  1254. (p^.left^.registers32=p^.right^.registers32) then
  1255. calcregisters(p,1,1,0)
  1256. else
  1257. calcregisters(p,0,1,0);
  1258. p^.location.loc:=LOC_FPU;
  1259. end
  1260. else
  1261. begin
  1262. p^.right:=gentypeconvnode(p^.right,s32bitdef);
  1263. p^.left:=gentypeconvnode(p^.left,s32bitdef);
  1264. firstpass(p^.left);
  1265. firstpass(p^.right);
  1266. calcregisters(p,1,0,0);
  1267. p^.location.loc:=LOC_REGISTER;
  1268. end;
  1269. end;
  1270. if codegenerror then
  1271. exit;
  1272. { determines result type for comparions }
  1273. { here the is a problem with multiple passes }
  1274. { example length(s)+1 gets internal 'longint' type first }
  1275. { if it is a arg it is converted to 'LONGINT' }
  1276. { but a second first pass will reset this to 'longint' }
  1277. case p^.treetype of
  1278. ltn,lten,gtn,gten,equaln,unequaln:
  1279. begin
  1280. if not assigned(p^.resulttype) then
  1281. p^.resulttype:=booldef;
  1282. p^.location.loc:=LOC_FLAGS;
  1283. end;
  1284. xorn:
  1285. begin
  1286. if not assigned(p^.resulttype) then
  1287. p^.resulttype:=p^.left^.resulttype;
  1288. p^.location.loc:=LOC_REGISTER;
  1289. end;
  1290. addn:
  1291. begin
  1292. { the result of a string addition is a string of length 255 }
  1293. if (p^.left^.resulttype^.deftype=stringdef) or
  1294. (p^.right^.resulttype^.deftype=stringdef) then
  1295. begin
  1296. {$ifndef UseAnsiString}
  1297. if not assigned(p^.resulttype) then
  1298. p^.resulttype:=cstringdef
  1299. {$else UseAnsiString}
  1300. if is_ansistring(p^.left^.resulttype) or
  1301. is_ansistring(p^.right^.resulttype) then
  1302. p^.resulttype:=cansistringdef
  1303. else
  1304. p^.resulttype:=cstringdef;
  1305. {$endif UseAnsiString}
  1306. end
  1307. else
  1308. if not assigned(p^.resulttype) then
  1309. p^.resulttype:=p^.left^.resulttype;
  1310. end;
  1311. else if not assigned(p^.resulttype) then
  1312. p^.resulttype:=p^.left^.resulttype;
  1313. end;
  1314. end;
  1315. procedure firstmoddiv(var p : ptree);
  1316. var
  1317. t : ptree;
  1318. {power : longint; }
  1319. begin
  1320. firstpass(p^.left);
  1321. firstpass(p^.right);
  1322. if codegenerror then
  1323. exit;
  1324. if is_constintnode(p^.left) and is_constintnode(p^.right) then
  1325. begin
  1326. case p^.treetype of
  1327. modn : t:=genordinalconstnode(p^.left^.value mod p^.right^.value,s32bitdef);
  1328. divn : t:=genordinalconstnode(p^.left^.value div p^.right^.value,s32bitdef);
  1329. end;
  1330. disposetree(p);
  1331. firstpass(t);
  1332. p:=t;
  1333. exit;
  1334. end;
  1335. { !!!!!! u32bit }
  1336. p^.right:=gentypeconvnode(p^.right,s32bitdef);
  1337. p^.left:=gentypeconvnode(p^.left,s32bitdef);
  1338. firstpass(p^.left);
  1339. firstpass(p^.right);
  1340. if codegenerror then
  1341. exit;
  1342. left_right_max(p);
  1343. p^.resulttype:=s32bitdef;
  1344. p^.location.loc:=LOC_REGISTER;
  1345. end;
  1346. procedure firstshlshr(var p : ptree);
  1347. var
  1348. t : ptree;
  1349. begin
  1350. firstpass(p^.left);
  1351. firstpass(p^.right);
  1352. if codegenerror then
  1353. exit;
  1354. if is_constintnode(p^.left) and is_constintnode(p^.right) then
  1355. begin
  1356. case p^.treetype of
  1357. shrn : t:=genordinalconstnode(p^.left^.value shr p^.right^.value,s32bitdef);
  1358. shln : t:=genordinalconstnode(p^.left^.value shl p^.right^.value,s32bitdef);
  1359. end;
  1360. disposetree(p);
  1361. firstpass(t);
  1362. p:=t;
  1363. exit;
  1364. end;
  1365. p^.right:=gentypeconvnode(p^.right,s32bitdef);
  1366. p^.left:=gentypeconvnode(p^.left,s32bitdef);
  1367. firstpass(p^.left);
  1368. firstpass(p^.right);
  1369. if codegenerror then
  1370. exit;
  1371. calcregisters(p,2,0,0);
  1372. {
  1373. p^.registers32:=p^.left^.registers32;
  1374. if p^.registers32<p^.right^.registers32 then
  1375. p^.registers32:=p^.right^.registers32;
  1376. if p^.registers32<1 then p^.registers32:=1;
  1377. }
  1378. p^.resulttype:=s32bitdef;
  1379. p^.location.loc:=LOC_REGISTER;
  1380. end;
  1381. procedure firstrealconst(var p : ptree);
  1382. begin
  1383. p^.location.loc:=LOC_MEM;
  1384. end;
  1385. procedure firstfixconst(var p : ptree);
  1386. begin
  1387. p^.location.loc:=LOC_MEM;
  1388. end;
  1389. procedure firstordconst(var p : ptree);
  1390. begin
  1391. p^.location.loc:=LOC_MEM;
  1392. end;
  1393. procedure firstniln(var p : ptree);
  1394. begin
  1395. p^.resulttype:=voidpointerdef;
  1396. p^.location.loc:=LOC_MEM;
  1397. end;
  1398. procedure firststringconst(var p : ptree);
  1399. begin
  1400. {why this !!! lost of dummy type definitions
  1401. one per const string !!!
  1402. p^.resulttype:=new(pstringdef,init(length(p^.values^)));}
  1403. if cs_ansistrings in aktlocalswitches then
  1404. p^.resulttype:=cansistringdef
  1405. else
  1406. p^.resulttype:=cstringdef;
  1407. p^.location.loc:=LOC_MEM;
  1408. end;
  1409. procedure firstumminus(var p : ptree);
  1410. var
  1411. t : ptree;
  1412. minusdef : pprocdef;
  1413. begin
  1414. firstpass(p^.left);
  1415. p^.registers32:=p^.left^.registers32;
  1416. p^.registersfpu:=p^.left^.registersfpu;
  1417. {$ifdef SUPPORT_MMX}
  1418. p^.registersmmx:=p^.left^.registersmmx;
  1419. {$endif SUPPORT_MMX}
  1420. p^.resulttype:=p^.left^.resulttype;
  1421. if codegenerror then
  1422. exit;
  1423. if is_constintnode(p^.left) then
  1424. begin
  1425. t:=genordinalconstnode(-p^.left^.value,s32bitdef);
  1426. disposetree(p);
  1427. firstpass(t);
  1428. p:=t;
  1429. exit;
  1430. end;
  1431. { nasm can not cope with negativ reals !! }
  1432. if is_constrealnode(p^.left)
  1433. {$ifdef i386}
  1434. and not(aktoutputformat in [as_nasmcoff,as_nasmelf,as_nasmobj])
  1435. {$endif}
  1436. then
  1437. begin
  1438. t:=genrealconstnode(-p^.left^.valued);
  1439. disposetree(p);
  1440. firstpass(t);
  1441. p:=t;
  1442. exit;
  1443. end;
  1444. if (p^.left^.resulttype^.deftype=floatdef) then
  1445. begin
  1446. if pfloatdef(p^.left^.resulttype)^.typ=f32bit then
  1447. begin
  1448. if (p^.left^.location.loc<>LOC_REGISTER) and
  1449. (p^.registers32<1) then
  1450. p^.registers32:=1;
  1451. p^.location.loc:=LOC_REGISTER;
  1452. end
  1453. else
  1454. p^.location.loc:=LOC_FPU;
  1455. end
  1456. {$ifdef SUPPORT_MMX}
  1457. else if (cs_mmx in aktmoduleswitches) and
  1458. is_mmx_able_array(p^.left^.resulttype) then
  1459. begin
  1460. if (p^.left^.location.loc<>LOC_MMXREGISTER) and
  1461. (p^.registersmmx<1) then
  1462. p^.registersmmx:=1;
  1463. { if saturation is on, p^.left^.resulttype isn't
  1464. "mmx able" (FK)
  1465. if (cs_mmx_saturation in aktmoduleswitches^) and
  1466. (porddef(parraydef(p^.resulttype)^.definition)^.typ in
  1467. [s32bit,u32bit]) then
  1468. Message(sym_e_type_mismatch);
  1469. }
  1470. end
  1471. {$endif SUPPORT_MMX}
  1472. else if (p^.left^.resulttype^.deftype=orddef) then
  1473. begin
  1474. p^.left:=gentypeconvnode(p^.left,s32bitdef);
  1475. firstpass(p^.left);
  1476. p^.registersfpu:=p^.left^.registersfpu;
  1477. {$ifdef SUPPORT_MMX}
  1478. p^.registersmmx:=p^.left^.registersmmx;
  1479. {$endif SUPPORT_MMX}
  1480. p^.registers32:=p^.left^.registers32;
  1481. if codegenerror then
  1482. exit;
  1483. if (p^.left^.location.loc<>LOC_REGISTER) and
  1484. (p^.registers32<1) then
  1485. p^.registers32:=1;
  1486. p^.location.loc:=LOC_REGISTER;
  1487. p^.resulttype:=p^.left^.resulttype;
  1488. end
  1489. else
  1490. begin
  1491. if assigned(overloaded_operators[minus]) then
  1492. minusdef:=overloaded_operators[minus]^.definition
  1493. else
  1494. minusdef:=nil;
  1495. while assigned(minusdef) do
  1496. begin
  1497. if (minusdef^.para1^.data=p^.left^.resulttype) and
  1498. (minusdef^.para1^.next=nil) then
  1499. begin
  1500. t:=gencallnode(overloaded_operators[minus],nil);
  1501. t^.left:=gencallparanode(p^.left,nil);
  1502. putnode(p);
  1503. p:=t;
  1504. firstpass(p);
  1505. exit;
  1506. end;
  1507. minusdef:=minusdef^.nextoverloaded;
  1508. end;
  1509. Message(sym_e_type_mismatch);
  1510. end;
  1511. end;
  1512. procedure firstaddr(var p : ptree);
  1513. var
  1514. hp : ptree;
  1515. hp2 : pdefcoll;
  1516. store_valid : boolean;
  1517. begin
  1518. make_not_regable(p^.left);
  1519. if not(assigned(p^.resulttype)) then
  1520. begin
  1521. if p^.left^.treetype=calln then
  1522. begin
  1523. hp:=genloadnode(pvarsym(p^.left^.symtableprocentry),p^.left^.symtableproc);
  1524. { result is a procedure variable }
  1525. { No, to be TP compatible, you must return a pointer to
  1526. the procedure that is stored in the procvar.}
  1527. if not(cs_tp_compatible in aktmoduleswitches) then
  1528. begin
  1529. p^.resulttype:=new(pprocvardef,init);
  1530. pprocvardef(p^.resulttype)^.options:=
  1531. p^.left^.symtableprocentry^.definition^.options;
  1532. pprocvardef(p^.resulttype)^.retdef:=
  1533. p^.left^.symtableprocentry^.definition^.retdef;
  1534. hp2:=p^.left^.symtableprocentry^.definition^.para1;
  1535. while assigned(hp2) do
  1536. begin
  1537. pprocvardef(p^.resulttype)^.concatdef(hp2^.data,hp2^.paratyp);
  1538. hp2:=hp2^.next;
  1539. end;
  1540. end
  1541. else
  1542. p^.resulttype:=voidpointerdef;
  1543. disposetree(p^.left);
  1544. p^.left:=hp;
  1545. end
  1546. else
  1547. begin
  1548. if not(cs_typed_addresses in aktlocalswitches) then
  1549. p^.resulttype:=voidpointerdef
  1550. else p^.resulttype:=new(ppointerdef,init(p^.left^.resulttype));
  1551. end;
  1552. end;
  1553. store_valid:=must_be_valid;
  1554. must_be_valid:=false;
  1555. firstpass(p^.left);
  1556. must_be_valid:=store_valid;
  1557. if codegenerror then
  1558. exit;
  1559. { we should allow loc_mem for @string }
  1560. if (p^.left^.location.loc<>LOC_REFERENCE) and
  1561. (p^.left^.location.loc<>LOC_MEM) then
  1562. Message(cg_e_illegal_expression);
  1563. p^.registers32:=p^.left^.registers32;
  1564. p^.registersfpu:=p^.left^.registersfpu;
  1565. {$ifdef SUPPORT_MMX}
  1566. p^.registersmmx:=p^.left^.registersmmx;
  1567. {$endif SUPPORT_MMX}
  1568. if p^.registers32<1 then
  1569. p^.registers32:=1;
  1570. p^.location.loc:=LOC_REGISTER;
  1571. end;
  1572. procedure firstdoubleaddr(var p : ptree);
  1573. begin
  1574. make_not_regable(p^.left);
  1575. firstpass(p^.left);
  1576. if p^.resulttype=nil then
  1577. p^.resulttype:=voidpointerdef;
  1578. if (p^.left^.resulttype^.deftype)<>procvardef then
  1579. Message(cg_e_illegal_expression);
  1580. if codegenerror then
  1581. exit;
  1582. if (p^.left^.location.loc<>LOC_REFERENCE) then
  1583. Message(cg_e_illegal_expression);
  1584. p^.registers32:=p^.left^.registers32;
  1585. p^.registersfpu:=p^.left^.registersfpu;
  1586. {$ifdef SUPPORT_MMX}
  1587. p^.registersmmx:=p^.left^.registersmmx;
  1588. {$endif SUPPORT_MMX}
  1589. if p^.registers32<1 then
  1590. p^.registers32:=1;
  1591. p^.location.loc:=LOC_REGISTER;
  1592. end;
  1593. procedure firstnot(var p : ptree);
  1594. var
  1595. t : ptree;
  1596. begin
  1597. firstpass(p^.left);
  1598. if codegenerror then
  1599. exit;
  1600. if (p^.left^.treetype=ordconstn) then
  1601. begin
  1602. t:=genordinalconstnode(not(p^.left^.value),p^.left^.resulttype);
  1603. disposetree(p);
  1604. firstpass(t);
  1605. p:=t;
  1606. exit;
  1607. end;
  1608. p^.resulttype:=p^.left^.resulttype;
  1609. p^.location.loc:=p^.left^.location.loc;
  1610. {$ifdef SUPPORT_MMX}
  1611. p^.registersmmx:=p^.left^.registersmmx;
  1612. {$endif SUPPORT_MMX}
  1613. if is_equal(p^.resulttype,booldef) then
  1614. begin
  1615. p^.registers32:=p^.left^.registers32;
  1616. if ((p^.location.loc=LOC_REFERENCE) or
  1617. (p^.location.loc=LOC_CREGISTER)) and
  1618. (p^.registers32<1) then
  1619. p^.registers32:=1;
  1620. end
  1621. else
  1622. {$ifdef SUPPORT_MMX}
  1623. if (cs_mmx in aktmoduleswitches) and
  1624. is_mmx_able_array(p^.left^.resulttype) then
  1625. begin
  1626. if (p^.left^.location.loc<>LOC_MMXREGISTER) and
  1627. (p^.registersmmx<1) then
  1628. p^.registersmmx:=1;
  1629. end
  1630. else
  1631. {$endif SUPPORT_MMX}
  1632. begin
  1633. p^.left:=gentypeconvnode(p^.left,s32bitdef);
  1634. firstpass(p^.left);
  1635. if codegenerror then
  1636. exit;
  1637. p^.resulttype:=p^.left^.resulttype;
  1638. p^.registers32:=p^.left^.registers32;
  1639. {$ifdef SUPPORT_MMX}
  1640. p^.registersmmx:=p^.left^.registersmmx;
  1641. {$endif SUPPORT_MMX}
  1642. if (p^.left^.location.loc<>LOC_REGISTER) and
  1643. (p^.registers32<1) then
  1644. p^.registers32:=1;
  1645. p^.location.loc:=LOC_REGISTER;
  1646. end;
  1647. p^.registersfpu:=p^.left^.registersfpu;
  1648. end;
  1649. procedure firstnothing(var p : ptree);
  1650. begin
  1651. p^.resulttype:=voiddef;
  1652. end;
  1653. procedure firstassignment(var p : ptree);
  1654. var
  1655. store_valid : boolean;
  1656. hp : ptree;
  1657. begin
  1658. store_valid:=must_be_valid;
  1659. must_be_valid:=false;
  1660. firstpass(p^.left);
  1661. if codegenerror then
  1662. exit;
  1663. { assignements to open arrays aren't allowed }
  1664. if is_open_array(p^.left^.resulttype) then
  1665. Message(sym_e_type_mismatch);
  1666. { test if we can avoid copying string to temp
  1667. as in s:=s+...; (PM) }
  1668. {$ifdef dummyi386}
  1669. if ((p^.right^.treetype=addn) or (p^.right^.treetype=subn)) and
  1670. equal_trees(p^.left,p^.right^.left) and
  1671. (ret_in_acc(p^.left^.resulttype)) and
  1672. (not cs_rangechecking in aktmoduleswitches^) then
  1673. begin
  1674. disposetree(p^.right^.left);
  1675. hp:=p^.right;
  1676. p^.right:=p^.right^.right;
  1677. if hp^.treetype=addn then
  1678. p^.assigntyp:=at_plus
  1679. else
  1680. p^.assigntyp:=at_minus;
  1681. putnode(hp);
  1682. end;
  1683. if p^.assigntyp<>at_normal then
  1684. begin
  1685. { for fpu type there is no faster way }
  1686. if is_fpu(p^.left^.resulttype) then
  1687. case p^.assigntyp of
  1688. at_plus : p^.right:=gennode(addn,getcopy(p^.left),p^.right);
  1689. at_minus : p^.right:=gennode(subn,getcopy(p^.left),p^.right);
  1690. at_star : p^.right:=gennode(muln,getcopy(p^.left),p^.right);
  1691. at_slash : p^.right:=gennode(slashn,getcopy(p^.left),p^.right);
  1692. end;
  1693. end;
  1694. {$endif i386}
  1695. must_be_valid:=true;
  1696. firstpass(p^.right);
  1697. must_be_valid:=store_valid;
  1698. if codegenerror then
  1699. exit;
  1700. { some string functions don't need conversion, so treat them separatly }
  1701. if is_shortstring(p^.left^.resulttype) and (assigned(p^.right^.resulttype)) then
  1702. begin
  1703. if not ((p^.right^.resulttype^.deftype=stringdef) or
  1704. ((p^.right^.resulttype^.deftype=orddef) and (porddef(p^.right^.resulttype)^.typ=uchar))) then
  1705. begin
  1706. p^.right:=gentypeconvnode(p^.right,p^.left^.resulttype);
  1707. firstpass(p^.right);
  1708. if codegenerror then
  1709. exit;
  1710. end;
  1711. { we call STRCOPY }
  1712. procinfo.flags:=procinfo.flags or pi_do_call;
  1713. hp:=p^.right;
  1714. { test for s:=s+anything ... }
  1715. { the problem is for
  1716. s:=s+s+s;
  1717. this is broken here !! }
  1718. { while hp^.treetype=addn do hp:=hp^.left;
  1719. if equal_trees(p^.left,hp) then
  1720. begin
  1721. p^.concat_string:=true;
  1722. hp:=p^.right;
  1723. while hp^.treetype=addn do
  1724. begin
  1725. hp^.use_strconcat:=true;
  1726. hp:=hp^.left;
  1727. end;
  1728. end; }
  1729. end
  1730. else
  1731. begin
  1732. if (p^.right^.treetype=realconstn) then
  1733. begin
  1734. if p^.left^.resulttype^.deftype=floatdef then
  1735. begin
  1736. case pfloatdef(p^.left^.resulttype)^.typ of
  1737. s32real : p^.right^.realtyp:=ait_real_32bit;
  1738. s64real : p^.right^.realtyp:=ait_real_64bit;
  1739. s80real : p^.right^.realtyp:=ait_real_extended;
  1740. { what about f32bit and s64bit }
  1741. else
  1742. begin
  1743. p^.right:=gentypeconvnode(p^.right,p^.left^.resulttype);
  1744. { nochmal firstpass wegen der Typkonvertierung aufrufen }
  1745. firstpass(p^.right);
  1746. if codegenerror then
  1747. exit;
  1748. end;
  1749. end;
  1750. end;
  1751. end
  1752. else
  1753. begin
  1754. p^.right:=gentypeconvnode(p^.right,p^.left^.resulttype);
  1755. firstpass(p^.right);
  1756. if codegenerror then
  1757. exit;
  1758. end;
  1759. end;
  1760. p^.resulttype:=voiddef;
  1761. {
  1762. p^.registers32:=max(p^.left^.registers32,p^.right^.registers32);
  1763. p^.registersfpu:=max(p^.left^.registersfpu,p^.right^.registersfpu);
  1764. }
  1765. p^.registers32:=p^.left^.registers32+p^.right^.registers32;
  1766. p^.registersfpu:=max(p^.left^.registersfpu,p^.right^.registersfpu);
  1767. {$ifdef SUPPORT_MMX}
  1768. p^.registersmmx:=max(p^.left^.registersmmx,p^.right^.registersmmx);
  1769. {$endif SUPPORT_MMX}
  1770. end;
  1771. procedure firstlr(var p : ptree);
  1772. begin
  1773. firstpass(p^.left);
  1774. firstpass(p^.right);
  1775. end;
  1776. procedure firstderef(var p : ptree);
  1777. begin
  1778. firstpass(p^.left);
  1779. if codegenerror then
  1780. begin
  1781. p^.resulttype:=generrordef;
  1782. exit;
  1783. end;
  1784. p^.registers32:=max(p^.left^.registers32,1);
  1785. p^.registersfpu:=p^.left^.registersfpu;
  1786. {$ifdef SUPPORT_MMX}
  1787. p^.registersmmx:=p^.left^.registersmmx;
  1788. {$endif SUPPORT_MMX}
  1789. if p^.left^.resulttype^.deftype<>pointerdef then
  1790. Message(cg_e_invalid_qualifier);
  1791. p^.resulttype:=ppointerdef(p^.left^.resulttype)^.definition;
  1792. p^.location.loc:=LOC_REFERENCE;
  1793. end;
  1794. procedure firstrange(var p : ptree);
  1795. var
  1796. ct : tconverttype;
  1797. begin
  1798. firstpass(p^.left);
  1799. firstpass(p^.right);
  1800. if codegenerror then
  1801. exit;
  1802. { allow only ordinal constants }
  1803. if not((p^.left^.treetype=ordconstn) and
  1804. (p^.right^.treetype=ordconstn)) then
  1805. Message(cg_e_illegal_expression);
  1806. { upper limit must be greater or equal than lower limit }
  1807. { not if u32bit }
  1808. if (p^.left^.value>p^.right^.value) and
  1809. (( p^.left^.value<0) or (p^.right^.value>=0)) then
  1810. Message(cg_e_upper_lower_than_lower);
  1811. { both types must be compatible }
  1812. if not(isconvertable(p^.left^.resulttype,p^.right^.resulttype,
  1813. ct,ordconstn,false)) and
  1814. not(is_equal(p^.left^.resulttype,p^.right^.resulttype)) then
  1815. Message(sym_e_type_mismatch);
  1816. end;
  1817. {
  1818. begin
  1819. p^.registers32:=max(p^.left^.registers32,p^.right^.registers32);
  1820. if p^.right^.treetype<>ordconstn then
  1821. begin
  1822. case p^.right^.location.loc of
  1823. LOC_MEM,LOC_REFERENCE,
  1824. LOC_CREGISTER,LOC_FLAGS:
  1825. inc(p^.registers32);
  1826. end;
  1827. end;
  1828. end;
  1829. }
  1830. procedure firstvecn(var p : ptree);
  1831. var
  1832. harr : pdef;
  1833. ct : tconverttype;
  1834. begin
  1835. firstpass(p^.left);
  1836. firstpass(p^.right);
  1837. if codegenerror then
  1838. exit;
  1839. { range check only for arrays }
  1840. if (p^.left^.resulttype^.deftype=arraydef) then
  1841. begin
  1842. if not(isconvertable(p^.right^.resulttype,
  1843. parraydef(p^.left^.resulttype)^.rangedef,
  1844. ct,ordconstn,false)) and
  1845. not(is_equal(p^.right^.resulttype,
  1846. parraydef(p^.left^.resulttype)^.rangedef)) then
  1847. Message(sym_e_type_mismatch);
  1848. end;
  1849. { Never convert a boolean or a char !}
  1850. { maybe type conversion }
  1851. if (p^.right^.resulttype^.deftype<>enumdef) and
  1852. not ((p^.right^.resulttype^.deftype=orddef) and
  1853. (Porddef(p^.right^.resulttype)^.typ in [bool8bit,bool16bit,bool32bit,uchar])) then
  1854. begin
  1855. p^.right:=gentypeconvnode(p^.right,s32bitdef);
  1856. { once more firstpass }
  1857. {?? It's better to only firstpass when the tree has
  1858. changed, isn't it ?}
  1859. firstpass(p^.right);
  1860. end;
  1861. if codegenerror then
  1862. exit;
  1863. { determine return type }
  1864. if not assigned(p^.resulttype) then
  1865. if p^.left^.resulttype^.deftype=arraydef then
  1866. p^.resulttype:=parraydef(p^.left^.resulttype)^.definition
  1867. else if (p^.left^.resulttype^.deftype=pointerdef) then
  1868. begin
  1869. { convert pointer to array }
  1870. harr:=new(parraydef,init(0,$7fffffff,s32bitdef));
  1871. parraydef(harr)^.definition:=ppointerdef(p^.left^.resulttype)^.definition;
  1872. p^.left:=gentypeconvnode(p^.left,harr);
  1873. firstpass(p^.left);
  1874. if codegenerror then
  1875. exit;
  1876. p^.resulttype:=parraydef(harr)^.definition
  1877. end
  1878. else if p^.left^.resulttype^.deftype=stringdef then
  1879. begin
  1880. { indexed access to strings }
  1881. case pstringdef(p^.left^.resulttype)^.string_typ of
  1882. {
  1883. st_widestring : p^.resulttype:=cwchardef;
  1884. }
  1885. st_ansistring : p^.resulttype:=cchardef;
  1886. st_longstring : p^.resulttype:=cchardef;
  1887. st_shortstring : p^.resulttype:=cchardef;
  1888. end;
  1889. end
  1890. else
  1891. Message(sym_e_type_mismatch);
  1892. { the register calculation is easy if a const index is used }
  1893. if p^.right^.treetype=ordconstn then
  1894. begin
  1895. p^.registers32:=p^.left^.registers32;
  1896. { for ansi/wide strings, we need at least one register }
  1897. if is_ansistring(p^.left^.resulttype) or
  1898. is_widestring(p^.left^.resulttype) then
  1899. p^.registers32:=max(p^.registers32,1);
  1900. end
  1901. else
  1902. begin
  1903. { this rules are suboptimal, but they should give }
  1904. { good results }
  1905. p^.registers32:=max(p^.left^.registers32,p^.right^.registers32);
  1906. { for ansi/wide strings, we need at least one register }
  1907. if is_ansistring(p^.left^.resulttype) or
  1908. is_widestring(p^.left^.resulttype) then
  1909. p^.registers32:=max(p^.registers32,1);
  1910. { need we an extra register when doing the restore ? }
  1911. if (p^.left^.registers32<=p^.right^.registers32) and
  1912. { only if the node needs less than 3 registers }
  1913. { two for the right node and one for the }
  1914. { left address }
  1915. (p^.registers32<3) then
  1916. inc(p^.registers32);
  1917. { need we an extra register for the index ? }
  1918. if (p^.right^.location.loc<>LOC_REGISTER)
  1919. { only if the right node doesn't need a register }
  1920. and (p^.right^.registers32<1) then
  1921. inc(p^.registers32);
  1922. { not correct, but what works better ?
  1923. if p^.left^.registers32>0 then
  1924. p^.registers32:=max(p^.registers32,2)
  1925. else
  1926. min. one register
  1927. p^.registers32:=max(p^.registers32,1);
  1928. }
  1929. end;
  1930. p^.registersfpu:=max(p^.left^.registersfpu,p^.right^.registersfpu);
  1931. {$ifdef SUPPORT_MMX}
  1932. p^.registersmmx:=max(p^.left^.registersmmx,p^.right^.registersmmx);
  1933. {$endif SUPPORT_MMX}
  1934. p^.location.loc:=p^.left^.location.loc;
  1935. end;
  1936. type
  1937. tfirstconvproc = procedure(var p : ptree);
  1938. procedure first_bigger_smaller(var p : ptree);
  1939. begin
  1940. if (p^.left^.location.loc<>LOC_REGISTER) and (p^.registers32=0) then
  1941. p^.registers32:=1;
  1942. p^.location.loc:=LOC_REGISTER;
  1943. end;
  1944. procedure first_cstring_charpointer(var p : ptree);
  1945. begin
  1946. p^.registers32:=1;
  1947. p^.location.loc:=LOC_REGISTER;
  1948. end;
  1949. procedure first_string_chararray(var p : ptree);
  1950. begin
  1951. p^.registers32:=1;
  1952. p^.location.loc:=LOC_REGISTER;
  1953. end;
  1954. procedure first_string_string(var p : ptree);
  1955. begin
  1956. if pstringdef(p^.resulttype)^.string_typ<>
  1957. pstringdef(p^.left^.resulttype)^.string_typ then
  1958. begin
  1959. if p^.left^.treetype=stringconstn then
  1960. p^.left^.stringtype:=pstringdef(p^.resulttype)^.string_typ
  1961. else
  1962. procinfo.flags:=procinfo.flags or pi_do_call;
  1963. end;
  1964. { for simplicity lets first keep all ansistrings
  1965. as LOC_MEM, could also become LOC_REGISTER }
  1966. p^.location.loc:=LOC_MEM;
  1967. end;
  1968. procedure first_char_to_string(var p : ptree);
  1969. var
  1970. hp : ptree;
  1971. begin
  1972. if p^.left^.treetype=ordconstn then
  1973. begin
  1974. hp:=genstringconstnode(chr(p^.left^.value));
  1975. firstpass(hp);
  1976. disposetree(p);
  1977. p:=hp;
  1978. end
  1979. else
  1980. p^.location.loc:=LOC_MEM;
  1981. end;
  1982. procedure first_nothing(var p : ptree);
  1983. begin
  1984. p^.location.loc:=LOC_MEM;
  1985. end;
  1986. procedure first_array_to_pointer(var p : ptree);
  1987. begin
  1988. if p^.registers32<1 then
  1989. p^.registers32:=1;
  1990. p^.location.loc:=LOC_REGISTER;
  1991. end;
  1992. procedure first_int_real(var p : ptree);
  1993. var t : ptree;
  1994. begin
  1995. if p^.left^.treetype=ordconstn then
  1996. begin
  1997. { convert constants direct }
  1998. { not because of type conversion }
  1999. t:=genrealconstnode(p^.left^.value);
  2000. { do a first pass here
  2001. because firstpass of typeconv does
  2002. not redo it for left field !! }
  2003. firstpass(t);
  2004. { the type can be something else than s64real !!}
  2005. t:=gentypeconvnode(t,p^.resulttype);
  2006. firstpass(t);
  2007. disposetree(p);
  2008. p:=t;
  2009. exit;
  2010. end
  2011. else
  2012. begin
  2013. if p^.registersfpu<1 then
  2014. p^.registersfpu:=1;
  2015. p^.location.loc:=LOC_FPU;
  2016. end;
  2017. end;
  2018. procedure first_int_fix(var p : ptree);
  2019. begin
  2020. if p^.left^.treetype=ordconstn then
  2021. begin
  2022. { convert constants direct }
  2023. p^.treetype:=fixconstn;
  2024. p^.valuef:=p^.left^.value shl 16;
  2025. p^.disposetyp:=dt_nothing;
  2026. disposetree(p^.left);
  2027. p^.location.loc:=LOC_MEM;
  2028. end
  2029. else
  2030. begin
  2031. if p^.registers32<1 then
  2032. p^.registers32:=1;
  2033. p^.location.loc:=LOC_REGISTER;
  2034. end;
  2035. end;
  2036. procedure first_real_fix(var p : ptree);
  2037. begin
  2038. if p^.left^.treetype=realconstn then
  2039. begin
  2040. { convert constants direct }
  2041. p^.treetype:=fixconstn;
  2042. p^.valuef:=round(p^.left^.valued*65536);
  2043. p^.disposetyp:=dt_nothing;
  2044. disposetree(p^.left);
  2045. p^.location.loc:=LOC_MEM;
  2046. end
  2047. else
  2048. begin
  2049. { at least one fpu and int register needed }
  2050. if p^.registers32<1 then
  2051. p^.registers32:=1;
  2052. if p^.registersfpu<1 then
  2053. p^.registersfpu:=1;
  2054. p^.location.loc:=LOC_REGISTER;
  2055. end;
  2056. end;
  2057. procedure first_fix_real(var p : ptree);
  2058. begin
  2059. if p^.left^.treetype=fixconstn then
  2060. begin
  2061. { convert constants direct }
  2062. p^.treetype:=realconstn;
  2063. p^.valued:=round(p^.left^.valuef/65536.0);
  2064. p^.disposetyp:=dt_nothing;
  2065. disposetree(p^.left);
  2066. p^.location.loc:=LOC_MEM;
  2067. end
  2068. else
  2069. begin
  2070. if p^.registersfpu<1 then
  2071. p^.registersfpu:=1;
  2072. p^.location.loc:=LOC_FPU;
  2073. end;
  2074. end;
  2075. procedure first_real_real(var p : ptree);
  2076. begin
  2077. if p^.registersfpu<1 then
  2078. p^.registersfpu:=1;
  2079. p^.location.loc:=LOC_FPU;
  2080. end;
  2081. procedure first_pointer_to_array(var p : ptree);
  2082. begin
  2083. if p^.registers32<1 then
  2084. p^.registers32:=1;
  2085. p^.location.loc:=LOC_REFERENCE;
  2086. end;
  2087. procedure first_chararray_string(var p : ptree);
  2088. begin
  2089. { the only important information is the location of the }
  2090. { result }
  2091. { other stuff is done by firsttypeconv }
  2092. p^.location.loc:=LOC_MEM;
  2093. end;
  2094. procedure first_cchar_charpointer(var p : ptree);
  2095. begin
  2096. p^.left:=gentypeconvnode(p^.left,cstringdef);
  2097. { convert constant char to constant string }
  2098. firstpass(p^.left);
  2099. { evalute tree }
  2100. firstpass(p);
  2101. end;
  2102. procedure first_locmem(var p : ptree);
  2103. begin
  2104. p^.location.loc:=LOC_MEM;
  2105. end;
  2106. procedure first_bool_int(var p : ptree);
  2107. begin
  2108. p^.location.loc:=LOC_REGISTER;
  2109. { Florian I think this is overestimated
  2110. but I still do not really understand how to get this right (PM) }
  2111. { Hmmm, I think we need only one reg to return the result of }
  2112. { this node => so }
  2113. if p^.registers32<1 then
  2114. p^.registers32:=1;
  2115. { should work (FK)
  2116. p^.registers32:=p^.left^.registers32+1;}
  2117. end;
  2118. procedure first_int_bool(var p : ptree);
  2119. begin
  2120. p^.location.loc:=LOC_REGISTER;
  2121. { Florian I think this is overestimated
  2122. but I still do not really understand how to get this right (PM) }
  2123. { Hmmm, I think we need only one reg to return the result of }
  2124. { this node => so }
  2125. p^.left:=gentypeconvnode(p^.left,s32bitdef);
  2126. firstpass(p^.left);
  2127. if p^.registers32<1 then
  2128. p^.registers32:=1;
  2129. { p^.resulttype:=booldef; }
  2130. { should work (FK)
  2131. p^.registers32:=p^.left^.registers32+1;}
  2132. end;
  2133. procedure first_proc_to_procvar(var p : ptree);
  2134. begin
  2135. firstpass(p^.left);
  2136. if codegenerror then
  2137. exit;
  2138. if (p^.left^.location.loc<>LOC_REFERENCE) then
  2139. Message(cg_e_illegal_expression);
  2140. p^.registers32:=p^.left^.registers32;
  2141. if p^.registers32<1 then
  2142. p^.registers32:=1;
  2143. p^.location.loc:=LOC_REGISTER;
  2144. end;
  2145. function is_procsym_load(p:Ptree):boolean;
  2146. begin
  2147. is_procsym_load:=((p^.treetype=loadn) and (p^.symtableentry^.typ=procsym)) or
  2148. ((p^.treetype=addrn) and (p^.left^.treetype=loadn)
  2149. and (p^.left^.symtableentry^.typ=procsym)) ;
  2150. end;
  2151. { change a proc call to a procload for assignment to a procvar }
  2152. { this can only happen for proc/function without arguments }
  2153. function is_procsym_call(p:Ptree):boolean;
  2154. begin
  2155. is_procsym_call:=(p^.treetype=calln) and (p^.left=nil) and
  2156. (((p^.symtableprocentry^.typ=procsym) and (p^.right=nil)) or
  2157. ((p^.right<>nil) and (p^.right^.symtableprocentry^.typ=varsym)));
  2158. end;
  2159. {***}
  2160. function is_assignment_overloaded(from_def,to_def : pdef) : boolean;
  2161. var
  2162. passproc : pprocdef;
  2163. convtyp : tconverttype;
  2164. begin
  2165. is_assignment_overloaded:=false;
  2166. if assigned(overloaded_operators[assignment]) then
  2167. passproc:=overloaded_operators[assignment]^.definition
  2168. else
  2169. exit;
  2170. while passproc<>nil do
  2171. begin
  2172. if is_equal(passproc^.retdef,to_def) and
  2173. isconvertable(from_def,passproc^.para1^.data,convtyp,
  2174. ordconstn { nur Dummy},false ) then
  2175. begin
  2176. is_assignment_overloaded:=true;
  2177. break;
  2178. end;
  2179. passproc:=passproc^.nextoverloaded;
  2180. end;
  2181. end;
  2182. { Attention: do *** no *** recursive call of firstpass }
  2183. { because the child tree is always passed }
  2184. procedure firsttypeconv(var p : ptree);
  2185. var
  2186. hp : ptree;
  2187. aprocdef : pprocdef;
  2188. proctype : tdeftype;
  2189. const
  2190. firstconvert : array[tc_u8bit_2_s32bit..tc_cchar_charpointer] of
  2191. tfirstconvproc = (first_bigger_smaller,first_nothing,first_bigger_smaller,
  2192. first_bigger_smaller,first_bigger_smaller,
  2193. first_bigger_smaller,first_bigger_smaller,
  2194. first_bigger_smaller,first_string_string,
  2195. first_cstring_charpointer,first_string_chararray,
  2196. first_array_to_pointer,first_pointer_to_array,
  2197. first_char_to_string,first_bigger_smaller,
  2198. first_bigger_smaller,first_bigger_smaller,
  2199. first_bigger_smaller,first_bigger_smaller,
  2200. first_bigger_smaller,first_bigger_smaller,
  2201. first_bigger_smaller,first_bigger_smaller,
  2202. first_bigger_smaller,first_bigger_smaller,
  2203. first_bigger_smaller,first_bigger_smaller,
  2204. first_bigger_smaller,first_bigger_smaller,
  2205. first_bigger_smaller,first_bigger_smaller,
  2206. first_bigger_smaller,first_bigger_smaller,
  2207. first_bool_int,first_int_bool,
  2208. first_int_real,first_real_fix,
  2209. first_fix_real,first_int_fix,first_real_real,
  2210. first_locmem,first_proc_to_procvar,
  2211. first_cchar_charpointer);
  2212. begin
  2213. aprocdef:=nil;
  2214. { if explicite type conversation, then run firstpass }
  2215. if p^.explizit then
  2216. firstpass(p^.left);
  2217. if codegenerror then
  2218. begin
  2219. p^.resulttype:=generrordef;
  2220. exit;
  2221. end;
  2222. if not assigned(p^.left^.resulttype) then
  2223. begin
  2224. codegenerror:=true;
  2225. internalerror(52349);
  2226. exit;
  2227. end;
  2228. { remove obsolete type conversions }
  2229. if is_equal(p^.left^.resulttype,p^.resulttype) then
  2230. begin
  2231. hp:=p;
  2232. p:=p^.left;
  2233. p^.resulttype:=hp^.resulttype;
  2234. putnode(hp);
  2235. exit;
  2236. end;
  2237. p^.registers32:=p^.left^.registers32;
  2238. p^.registersfpu:=p^.left^.registersfpu;
  2239. {$ifdef SUPPORT_MMX}
  2240. p^.registersmmx:=p^.left^.registersmmx;
  2241. {$endif}
  2242. set_location(p^.location,p^.left^.location);
  2243. if is_assignment_overloaded(p^.left^.resulttype,p^.resulttype) then
  2244. begin
  2245. procinfo.flags:=procinfo.flags or pi_do_call;
  2246. hp:=gencallnode(overloaded_operators[assignment],nil);
  2247. hp^.left:=gencallparanode(p^.left,nil);
  2248. putnode(p);
  2249. p:=hp;
  2250. firstpass(p);
  2251. exit;
  2252. end;
  2253. if (not(isconvertable(p^.left^.resulttype,p^.resulttype,
  2254. p^.convtyp,p^.left^.treetype,p^.explizit))) then
  2255. begin
  2256. {Procedures have a resulttype of voiddef and functions of their
  2257. own resulttype. They will therefore always be incompatible with
  2258. a procvar. Because isconvertable cannot check for procedures we
  2259. use an extra check for them.}
  2260. if (cs_tp_compatible in aktmoduleswitches) and
  2261. ((is_procsym_load(p^.left) or is_procsym_call(p^.left)) and
  2262. (p^.resulttype^.deftype=procvardef)) then
  2263. begin
  2264. { just a test: p^.explizit:=false; }
  2265. if is_procsym_call(p^.left) then
  2266. begin
  2267. if p^.left^.right=nil then
  2268. begin
  2269. p^.left^.treetype:=loadn;
  2270. { are at same offset so this could be spared, but
  2271. it more secure to do it anyway }
  2272. p^.left^.symtableentry:=p^.left^.symtableprocentry;
  2273. p^.left^.resulttype:=pprocsym(p^.left^.symtableentry)^.definition;
  2274. aprocdef:=pprocdef(p^.left^.resulttype);
  2275. end
  2276. else
  2277. begin
  2278. p^.left^.right^.treetype:=loadn;
  2279. p^.left^.right^.symtableentry:=p^.left^.right^.symtableentry;
  2280. P^.left^.right^.resulttype:=pvarsym(p^.left^.symtableentry)^.definition;
  2281. hp:=p^.left^.right;
  2282. putnode(p^.left);
  2283. p^.left:=hp;
  2284. { should we do that ? }
  2285. firstpass(p^.left);
  2286. if not is_equal(p^.left^.resulttype,p^.resulttype) then
  2287. begin
  2288. Message(sym_e_type_mismatch);
  2289. exit;
  2290. end
  2291. else
  2292. begin
  2293. hp:=p;
  2294. p:=p^.left;
  2295. p^.resulttype:=hp^.resulttype;
  2296. putnode(hp);
  2297. exit;
  2298. end;
  2299. end;
  2300. end
  2301. else
  2302. begin
  2303. if p^.left^.treetype=addrn then
  2304. begin
  2305. hp:=p^.left;
  2306. p^.left:=p^.left^.left;
  2307. putnode(p^.left);
  2308. end
  2309. else
  2310. aprocdef:=pprocsym(p^.left^.symtableentry)^.definition;
  2311. end;
  2312. p^.convtyp:=tc_proc2procvar;
  2313. { Now check if the procedure we are going to assign to
  2314. the procvar, is compatible with the procvar's type.
  2315. Did the original procvar support do such a check?
  2316. I can't find any.}
  2317. { answer : is_equal works for procvardefs !! }
  2318. { but both must be procvardefs, so we cheet little }
  2319. if assigned(aprocdef) then
  2320. begin
  2321. proctype:=aprocdef^.deftype;
  2322. aprocdef^.deftype:=procvardef;
  2323. if not is_equal(aprocdef,p^.resulttype) then
  2324. begin
  2325. aprocdef^.deftype:=proctype;
  2326. Message(sym_e_type_mismatch);
  2327. end;
  2328. aprocdef^.deftype:=proctype;
  2329. firstconvert[p^.convtyp](p);
  2330. end
  2331. else
  2332. Message(sym_e_type_mismatch);
  2333. exit;
  2334. end
  2335. else
  2336. begin
  2337. if p^.explizit then
  2338. begin
  2339. { boolean to byte are special because the
  2340. location can be different }
  2341. if (p^.resulttype^.deftype=orddef) and
  2342. (porddef(p^.resulttype)^.typ=u8bit) and
  2343. (p^.left^.resulttype^.deftype=orddef) and
  2344. (porddef(p^.left^.resulttype)^.typ=bool8bit) then
  2345. begin
  2346. p^.convtyp:=tc_bool_2_int;
  2347. firstconvert[p^.convtyp](p);
  2348. exit;
  2349. end;
  2350. { normal tc_equal-Konvertierung durchf�hren }
  2351. p^.convtyp:=tc_equal;
  2352. { wenn Aufz„hltyp nach Ordinal konvertiert werden soll }
  2353. { dann Aufz„hltyp=s32bit }
  2354. if (p^.left^.resulttype^.deftype=enumdef) and
  2355. is_ordinal(p^.resulttype) then
  2356. begin
  2357. if p^.left^.treetype=ordconstn then
  2358. begin
  2359. hp:=genordinalconstnode(p^.left^.value,p^.resulttype);
  2360. disposetree(p);
  2361. firstpass(hp);
  2362. p:=hp;
  2363. exit;
  2364. end
  2365. else
  2366. begin
  2367. if not isconvertable(s32bitdef,p^.resulttype,p^.convtyp,
  2368. ordconstn { nur Dummy},false ) then
  2369. Message(cg_e_illegal_type_conversion);
  2370. end;
  2371. end
  2372. { ordinal to enumeration }
  2373. else
  2374. if (p^.resulttype^.deftype=enumdef) and
  2375. is_ordinal(p^.left^.resulttype) then
  2376. begin
  2377. if p^.left^.treetype=ordconstn then
  2378. begin
  2379. hp:=genordinalconstnode(p^.left^.value,p^.resulttype);
  2380. disposetree(p);
  2381. firstpass(hp);
  2382. p:=hp;
  2383. exit;
  2384. end
  2385. else
  2386. begin
  2387. if not isconvertable(p^.left^.resulttype,s32bitdef,p^.convtyp,
  2388. ordconstn { nur Dummy},false ) then
  2389. Message(cg_e_illegal_type_conversion);
  2390. end;
  2391. end
  2392. {Are we typecasting an ordconst to a char?}
  2393. else
  2394. if is_equal(p^.resulttype,cchardef) and
  2395. is_ordinal(p^.left^.resulttype) then
  2396. begin
  2397. if p^.left^.treetype=ordconstn then
  2398. begin
  2399. hp:=genordinalconstnode(p^.left^.value,p^.resulttype);
  2400. firstpass(hp);
  2401. disposetree(p);
  2402. p:=hp;
  2403. exit;
  2404. end
  2405. else
  2406. begin
  2407. { this is wrong because it converts to a 4 byte long var !!
  2408. if not isconvertable(p^.left^.resulttype,s32bitdef,p^.convtyp,ordconstn nur Dummy ) then }
  2409. if not isconvertable(p^.left^.resulttype,u8bitdef,
  2410. p^.convtyp,ordconstn { nur Dummy},false ) then
  2411. Message(cg_e_illegal_type_conversion);
  2412. end;
  2413. end
  2414. { only if the same size or formal def }
  2415. { why do we allow typecasting of voiddef ?? (PM) }
  2416. else
  2417. if not(
  2418. (p^.left^.resulttype^.deftype=formaldef) or
  2419. (p^.left^.resulttype^.size=p^.resulttype^.size) or
  2420. (is_equal(p^.left^.resulttype,voiddef) and
  2421. (p^.left^.treetype=derefn))
  2422. ) then
  2423. Message(cg_e_illegal_type_conversion);
  2424. { the conversion into a strutured type is only }
  2425. { possible, if the source is no register }
  2426. if (p^.resulttype^.deftype in [recorddef,stringdef,arraydef,objectdef]) and
  2427. (p^.left^.location.loc in [LOC_REGISTER,LOC_CREGISTER]) and
  2428. {it also works if the assignment is overloaded }
  2429. not is_assignment_overloaded(p^.left^.resulttype,p^.resulttype) then
  2430. Message(cg_e_illegal_type_conversion);
  2431. end
  2432. else
  2433. Message(sym_e_type_mismatch);
  2434. end
  2435. end
  2436. else
  2437. begin
  2438. { just a test: p^.explizit:=false; }
  2439. { ordinale contants are direct converted }
  2440. if (p^.left^.treetype=ordconstn) and is_ordinal(p^.resulttype) then
  2441. begin
  2442. { perform range checking }
  2443. if not(p^.explizit and (cs_tp_compatible in aktmoduleswitches)) then
  2444. testrange(p^.resulttype,p^.left^.value);
  2445. hp:=genordinalconstnode(p^.left^.value,p^.resulttype);
  2446. disposetree(p);
  2447. firstpass(hp);
  2448. p:=hp;
  2449. exit;
  2450. end;
  2451. if p^.convtyp<>tc_equal then
  2452. firstconvert[p^.convtyp](p);
  2453. end;
  2454. end;
  2455. { *************** subroutine handling **************** }
  2456. { protected field handling
  2457. protected field can not appear in
  2458. var parameters of function !!
  2459. this can only be done after we have determined the
  2460. overloaded function
  2461. this is the reason why it is not in the parser
  2462. PM }
  2463. procedure test_protected_sym(sym : psym);
  2464. begin
  2465. if ((sym^.properties and sp_protected)<>0) and
  2466. ((sym^.owner^.symtabletype=unitsymtable) or
  2467. ((sym^.owner^.symtabletype=objectsymtable) and
  2468. (pobjectdef(sym^.owner^.defowner)^.owner^.symtabletype=unitsymtable))) then
  2469. Message(parser_e_cant_access_protected_member);
  2470. end;
  2471. procedure test_protected(p : ptree);
  2472. begin
  2473. if p^.treetype=loadn then
  2474. begin
  2475. test_protected_sym(p^.symtableentry);
  2476. end
  2477. else if p^.treetype=typeconvn then
  2478. begin
  2479. test_protected(p^.left);
  2480. end
  2481. else if p^.treetype=derefn then
  2482. begin
  2483. test_protected(p^.left);
  2484. end
  2485. else if p^.treetype=subscriptn then
  2486. begin
  2487. { test_protected(p^.left);
  2488. Is a field of a protected var
  2489. also protected ??? PM }
  2490. test_protected_sym(p^.vs);
  2491. end;
  2492. end;
  2493. procedure firstcallparan(var p : ptree;defcoll : pdefcoll);
  2494. var store_valid : boolean;
  2495. convtyp : tconverttype;
  2496. begin
  2497. inc(parsing_para_level);
  2498. if assigned(p^.right) then
  2499. begin
  2500. if defcoll=nil then
  2501. firstcallparan(p^.right,nil)
  2502. else
  2503. firstcallparan(p^.right,defcoll^.next);
  2504. p^.registers32:=p^.right^.registers32;
  2505. p^.registersfpu:=p^.right^.registersfpu;
  2506. {$ifdef SUPPORT_MMX}
  2507. p^.registersmmx:=p^.right^.registersmmx;
  2508. {$endif}
  2509. end;
  2510. if defcoll=nil then
  2511. begin
  2512. { this breaks typeconversions in write !!! (PM) }
  2513. {if not(assigned(p^.resulttype)) then }
  2514. if not(assigned(p^.resulttype)) or
  2515. (p^.left^.treetype=typeconvn) then
  2516. firstpass(p^.left);
  2517. {else
  2518. exit; this broke the
  2519. value of registers32 !! }
  2520. if codegenerror then
  2521. begin
  2522. dec(parsing_para_level);
  2523. exit;
  2524. end;
  2525. p^.resulttype:=p^.left^.resulttype;
  2526. end
  2527. { if we know the routine which is called, then the type }
  2528. { conversions are inserted }
  2529. else
  2530. begin
  2531. if count_ref then
  2532. begin
  2533. store_valid:=must_be_valid;
  2534. if (defcoll^.paratyp=vs_var) then
  2535. test_protected(p^.left);
  2536. if (defcoll^.paratyp<>vs_var) then
  2537. must_be_valid:=true
  2538. else
  2539. must_be_valid:=false;
  2540. { here we must add something for the implicit type }
  2541. { conversion from array of char to pchar }
  2542. if isconvertable(p^.left^.resulttype,defcoll^.data,convtyp,
  2543. p^.left^.treetype,false) then
  2544. if convtyp=tc_array_to_pointer then
  2545. must_be_valid:=false;
  2546. firstpass(p^.left);
  2547. must_be_valid:=store_valid;
  2548. end;
  2549. if not(is_shortstring(p^.left^.resulttype) and
  2550. is_shortstring(defcoll^.data)) and
  2551. (defcoll^.data^.deftype<>formaldef) then
  2552. begin
  2553. if (defcoll^.paratyp=vs_var) and
  2554. { allows conversion from word to integer and
  2555. byte to shortint }
  2556. (not(
  2557. (p^.left^.resulttype^.deftype=orddef) and
  2558. (defcoll^.data^.deftype=orddef) and
  2559. (p^.left^.resulttype^.size=defcoll^.data^.size)
  2560. ) and
  2561. { an implicit pointer conversion is allowed }
  2562. not(
  2563. (p^.left^.resulttype^.deftype=pointerdef) and
  2564. (defcoll^.data^.deftype=pointerdef)
  2565. ) and
  2566. { child classes can be also passed }
  2567. not(
  2568. (p^.left^.resulttype^.deftype=objectdef) and
  2569. (defcoll^.data^.deftype=objectdef) and
  2570. pobjectdef(p^.left^.resulttype)^.isrelated(pobjectdef(defcoll^.data))
  2571. ) and
  2572. { an implicit file conversion is also allowed }
  2573. { from a typed file to an untyped one }
  2574. not(
  2575. (p^.left^.resulttype^.deftype=filedef) and
  2576. (defcoll^.data^.deftype=filedef) and
  2577. (pfiledef(defcoll^.data)^.filetype = ft_untyped) and
  2578. (pfiledef(p^.left^.resulttype)^.filetype = ft_typed)
  2579. ) and
  2580. not(is_equal(p^.left^.resulttype,defcoll^.data))) then
  2581. Message(parser_e_call_by_ref_without_typeconv);
  2582. { don't generate an type conversion for open arrays }
  2583. { else we loss the ranges }
  2584. if not(is_open_array(defcoll^.data)) then
  2585. begin
  2586. p^.left:=gentypeconvnode(p^.left,defcoll^.data);
  2587. firstpass(p^.left);
  2588. end;
  2589. if codegenerror then
  2590. begin
  2591. dec(parsing_para_level);
  2592. exit;
  2593. end;
  2594. end;
  2595. { check var strings }
  2596. if (cs_strict_var_strings in aktlocalswitches) and
  2597. is_shortstring(p^.left^.resulttype) and
  2598. is_shortstring(defcoll^.data) and
  2599. (defcoll^.paratyp=vs_var) and
  2600. not(is_equal(p^.left^.resulttype,defcoll^.data)) then
  2601. Message(parser_e_strict_var_string_violation);
  2602. { Variablen, die call by reference �bergeben werden, }
  2603. { k”nnen nicht in ein Register kopiert werden }
  2604. { is this usefull here ? }
  2605. { this was missing in formal parameter list }
  2606. if defcoll^.paratyp=vs_var then
  2607. make_not_regable(p^.left);
  2608. p^.resulttype:=defcoll^.data;
  2609. end;
  2610. if p^.left^.registers32>p^.registers32 then
  2611. p^.registers32:=p^.left^.registers32;
  2612. if p^.left^.registersfpu>p^.registersfpu then
  2613. p^.registersfpu:=p^.left^.registersfpu;
  2614. {$ifdef SUPPORT_MMX}
  2615. if p^.left^.registersmmx>p^.registersmmx then
  2616. p^.registersmmx:=p^.left^.registersmmx;
  2617. {$endif SUPPORT_MMX}
  2618. dec(parsing_para_level);
  2619. end;
  2620. procedure firstcalln(var p : ptree);
  2621. type
  2622. pprocdefcoll = ^tprocdefcoll;
  2623. tprocdefcoll = record
  2624. data : pprocdef;
  2625. nextpara : pdefcoll;
  2626. firstpara : pdefcoll;
  2627. next : pprocdefcoll;
  2628. end;
  2629. var
  2630. hp,procs,hp2 : pprocdefcoll;
  2631. pd : pprocdef;
  2632. actprocsym : pprocsym;
  2633. def_from,def_to,conv_to : pdef;
  2634. pt,inlinecode : ptree;
  2635. exactmatch,inlined : boolean;
  2636. paralength,l : longint;
  2637. pdc : pdefcoll;
  2638. {$ifdef UseBrowser}
  2639. curtokenpos : tfileposinfo;
  2640. {$endif UseBrowser}
  2641. { only Dummy }
  2642. hcvt : tconverttype;
  2643. regi : tregister;
  2644. store_valid, old_count_ref : boolean;
  2645. { types.is_equal can't handle a formaldef ! }
  2646. function is_equal(def1,def2 : pdef) : boolean;
  2647. begin
  2648. { all types can be passed to a formaldef }
  2649. is_equal:=(def1^.deftype=formaldef) or
  2650. (assigned(def2) and types.is_equal(def1,def2))
  2651. { to support ansi/long/wide strings in a proper way }
  2652. { string and string[10] are assumed as equal }
  2653. { when searching the correct overloaded procedure }
  2654. or
  2655. (assigned(def1) and assigned(def2) and
  2656. (def1^.deftype=stringdef) and (def2^.deftype=stringdef) and
  2657. (pstringdef(def1)^.string_typ=pstringdef(def2)^.string_typ)
  2658. )
  2659. ;
  2660. end;
  2661. function is_in_limit(def_from,def_to : pdef) : boolean;
  2662. begin
  2663. is_in_limit:=(def_from^.deftype = orddef) and
  2664. (def_to^.deftype = orddef) and
  2665. (porddef(def_from)^.low>porddef(def_to)^.low) and
  2666. (porddef(def_from)^.high<porddef(def_to)^.high);
  2667. end;
  2668. begin
  2669. { release registers! }
  2670. { if procdefinition<>nil then we called firstpass already }
  2671. { it seems to be bad because of the registers }
  2672. { at least we can avoid the overloaded search !! }
  2673. procs:=nil;
  2674. { made this global for disposing !! }
  2675. store_valid:=must_be_valid;
  2676. must_be_valid:=false;
  2677. inlined:=false;
  2678. if assigned(p^.procdefinition) and
  2679. ((p^.procdefinition^.options and poinline)<>0) then
  2680. begin
  2681. inlinecode:=p^.right;
  2682. if assigned(inlinecode) then
  2683. begin
  2684. inlined:=true;
  2685. p^.procdefinition^.options:=p^.procdefinition^.options and (not poinline);
  2686. end;
  2687. p^.right:=nil;
  2688. end;
  2689. { procedure variable ? }
  2690. if assigned(p^.right) then
  2691. begin
  2692. { procedure does a call }
  2693. procinfo.flags:=procinfo.flags or pi_do_call;
  2694. { calc the correture value for the register }
  2695. {$ifdef i386}
  2696. for regi:=R_EAX to R_EDI do
  2697. inc(reg_pushes[regi],t_times*2);
  2698. {$endif}
  2699. {$ifdef m68k}
  2700. for regi:=R_D0 to R_A6 do
  2701. inc(reg_pushes[regi],t_times*2);
  2702. {$endif}
  2703. { calculate the type of the parameters }
  2704. if assigned(p^.left) then
  2705. begin
  2706. old_count_ref:=count_ref;
  2707. count_ref:=false;
  2708. firstcallparan(p^.left,nil);
  2709. count_ref:=old_count_ref;
  2710. if codegenerror then
  2711. exit;
  2712. end;
  2713. firstpass(p^.right);
  2714. { check the parameters }
  2715. pdc:=pprocvardef(p^.right^.resulttype)^.para1;
  2716. pt:=p^.left;
  2717. while assigned(pdc) and assigned(pt) do
  2718. begin
  2719. pt:=pt^.right;
  2720. pdc:=pdc^.next;
  2721. end;
  2722. if assigned(pt) or assigned(pdc) then
  2723. Message(parser_e_illegal_parameter_list);
  2724. { insert type conversions }
  2725. if assigned(p^.left) then
  2726. begin
  2727. old_count_ref:=count_ref;
  2728. count_ref:=true;
  2729. firstcallparan(p^.left,pprocvardef(p^.right^.resulttype)^.para1);
  2730. count_ref:=old_count_ref;
  2731. if codegenerror then
  2732. exit;
  2733. end;
  2734. p^.resulttype:=pprocvardef(p^.right^.resulttype)^.retdef;
  2735. { this was missing, leads to a bug below if
  2736. the procvar is a function }
  2737. p^.procdefinition:=pprocdef(p^.right^.resulttype);
  2738. end
  2739. else
  2740. { not a procedure variable }
  2741. begin
  2742. { determine the type of the parameters }
  2743. if assigned(p^.left) then
  2744. begin
  2745. old_count_ref:=count_ref;
  2746. count_ref:=false;
  2747. store_valid:=must_be_valid;
  2748. must_be_valid:=false;
  2749. firstcallparan(p^.left,nil);
  2750. count_ref:=old_count_ref;
  2751. must_be_valid:=store_valid;
  2752. if codegenerror then
  2753. exit;
  2754. end;
  2755. { do we know the procedure to call ? }
  2756. if not(assigned(p^.procdefinition)) then
  2757. begin
  2758. actprocsym:=p^.symtableprocentry;
  2759. { determine length of parameter list }
  2760. pt:=p^.left;
  2761. paralength:=0;
  2762. while assigned(pt) do
  2763. begin
  2764. inc(paralength);
  2765. pt:=pt^.right;
  2766. end;
  2767. { alle in Frage kommenden Prozeduren in eine }
  2768. { verkettete Liste einf�gen }
  2769. pd:=actprocsym^.definition;
  2770. while assigned(pd) do
  2771. begin
  2772. { we should also check that the overloaded function
  2773. has been declared in a unit that is in the uses !! }
  2774. { pd^.owner should be in the symtablestack !! }
  2775. { Laenge der deklarierten Parameterliste feststellen: }
  2776. { not necessary why nextprocsym field }
  2777. {st:=symtablestack;
  2778. if (pd^.owner^.symtabletype<>objectsymtable) then
  2779. while assigned(st) do
  2780. begin
  2781. if (st=pd^.owner) then break;
  2782. st:=st^.next;
  2783. end;
  2784. if assigned(st) then }
  2785. begin
  2786. pdc:=pd^.para1;
  2787. l:=0;
  2788. while assigned(pdc) do
  2789. begin
  2790. inc(l);
  2791. pdc:=pdc^.next;
  2792. end;
  2793. { nur wenn die Parameterl„nge paát, dann Einf�gen }
  2794. if l=paralength then
  2795. begin
  2796. new(hp);
  2797. hp^.data:=pd;
  2798. hp^.next:=procs;
  2799. hp^.nextpara:=pd^.para1;
  2800. hp^.firstpara:=pd^.para1;
  2801. procs:=hp;
  2802. end;
  2803. end;
  2804. pd:=pd^.nextoverloaded;
  2805. {$ifdef CHAINPROCSYMS}
  2806. if (pd=nil) and not (p^.unit_specific) then
  2807. begin
  2808. actprocsym:=actprocsym^.nextprocsym;
  2809. if assigned(actprocsym) then
  2810. pd:=actprocsym^.definition;
  2811. end;
  2812. {$endif CHAINPROCSYMS}
  2813. end;
  2814. { nun alle Parameter nacheinander vergleichen }
  2815. pt:=p^.left;
  2816. while assigned(pt) do
  2817. begin
  2818. { matches a parameter of one procedure exact ? }
  2819. exactmatch:=false;
  2820. hp:=procs;
  2821. while assigned(hp) do
  2822. begin
  2823. if is_equal(hp^.nextpara^.data,pt^.resulttype) then
  2824. begin
  2825. if hp^.nextpara^.data=pt^.resulttype then
  2826. begin
  2827. pt^.exact_match_found:=true;
  2828. hp^.nextpara^.argconvtyp:=act_exact;
  2829. end
  2830. else
  2831. hp^.nextpara^.argconvtyp:=act_equal;
  2832. exactmatch:=true;
  2833. end
  2834. else
  2835. hp^.nextpara^.argconvtyp:=act_convertable;
  2836. hp:=hp^.next;
  2837. end;
  2838. { .... if yes, del all the other procedures }
  2839. if exactmatch then
  2840. begin
  2841. { the first .... }
  2842. while (assigned(procs)) and not(is_equal(procs^.nextpara^.data,pt^.resulttype)) do
  2843. begin
  2844. hp:=procs^.next;
  2845. dispose(procs);
  2846. procs:=hp;
  2847. end;
  2848. { and the others }
  2849. hp:=procs;
  2850. while (assigned(hp)) and assigned(hp^.next) do
  2851. begin
  2852. if not(is_equal(hp^.next^.nextpara^.data,pt^.resulttype)) then
  2853. begin
  2854. hp2:=hp^.next^.next;
  2855. dispose(hp^.next);
  2856. hp^.next:=hp2;
  2857. end
  2858. else
  2859. hp:=hp^.next;
  2860. end;
  2861. end
  2862. { sollte nirgendwo ein Parameter exakt passen, }
  2863. { so alle Prozeduren entfernen, bei denen }
  2864. { der Parameter auch nach einer impliziten }
  2865. { Typkonvertierung nicht passt }
  2866. else
  2867. begin
  2868. { erst am Anfang }
  2869. while (assigned(procs)) and
  2870. not(isconvertable(pt^.resulttype,procs^.nextpara^.data,
  2871. hcvt,pt^.left^.treetype,false)) do
  2872. begin
  2873. hp:=procs^.next;
  2874. dispose(procs);
  2875. procs:=hp;
  2876. end;
  2877. { und jetzt aus der Mitte }
  2878. hp:=procs;
  2879. while (assigned(hp)) and assigned(hp^.next) do
  2880. begin
  2881. if not(isconvertable(pt^.resulttype,hp^.next^.nextpara^.data,
  2882. hcvt,pt^.left^.treetype,false)) then
  2883. begin
  2884. hp2:=hp^.next^.next;
  2885. dispose(hp^.next);
  2886. hp^.next:=hp2;
  2887. end
  2888. else
  2889. hp:=hp^.next;
  2890. end;
  2891. end;
  2892. { nun bei denn Prozeduren den nextpara-Zeiger auf den }
  2893. { naechsten Parameter setzen }
  2894. hp:=procs;
  2895. while assigned(hp) do
  2896. begin
  2897. hp^.nextpara:=hp^.nextpara^.next;
  2898. hp:=hp^.next;
  2899. end;
  2900. pt:=pt^.right;
  2901. end;
  2902. if procs=nil then
  2903. if (parsing_para_level=0) or (p^.left<>nil) then
  2904. begin
  2905. Message(parser_e_illegal_parameter_list);
  2906. exit;
  2907. end
  2908. else
  2909. begin
  2910. { try to convert to procvar }
  2911. p^.treetype:=loadn;
  2912. p^.resulttype:=pprocsym(p^.symtableprocentry)^.definition;
  2913. p^.symtableentry:=p^.symtableprocentry;
  2914. p^.is_first:=false;
  2915. p^.disposetyp:=dt_nothing;
  2916. firstpass(p);
  2917. exit;
  2918. end;
  2919. { if there are several choices left then for orddef }
  2920. { if a type is totally included in the other }
  2921. { we don't fear an overflow , }
  2922. { so we can do as if it is an exact match }
  2923. { this will convert integer to longint }
  2924. { rather than to words }
  2925. { conversion of byte to integer or longint }
  2926. {would still not be solved }
  2927. if assigned(procs^.next) then
  2928. begin
  2929. hp:=procs;
  2930. while assigned(hp) do
  2931. begin
  2932. hp^.nextpara:=hp^.firstpara;
  2933. hp:=hp^.next;
  2934. end;
  2935. pt:=p^.left;
  2936. while assigned(pt) do
  2937. begin
  2938. { matches a parameter of one procedure exact ? }
  2939. exactmatch:=false;
  2940. def_from:=pt^.resulttype;
  2941. hp:=procs;
  2942. while assigned(hp) do
  2943. begin
  2944. if not is_equal(hp^.nextpara^.data,pt^.resulttype) then
  2945. begin
  2946. def_to:=hp^.nextpara^.data;
  2947. if ((def_from^.deftype=orddef) and (def_to^.deftype=orddef)) and
  2948. (is_in_limit(def_from,def_to) or
  2949. ((hp^.nextpara^.paratyp=vs_var) and
  2950. (def_from^.size=def_to^.size))) then
  2951. begin
  2952. exactmatch:=true;
  2953. conv_to:=def_to;
  2954. end;
  2955. end;
  2956. hp:=hp^.next;
  2957. end;
  2958. { .... if yes, del all the other procedures }
  2959. if exactmatch then
  2960. begin
  2961. { the first .... }
  2962. while (assigned(procs)) and not(is_in_limit(def_from,procs^.nextpara^.data)) do
  2963. begin
  2964. hp:=procs^.next;
  2965. dispose(procs);
  2966. procs:=hp;
  2967. end;
  2968. { and the others }
  2969. hp:=procs;
  2970. while (assigned(hp)) and assigned(hp^.next) do
  2971. begin
  2972. if not(is_in_limit(def_from,hp^.next^.nextpara^.data)) then
  2973. begin
  2974. hp2:=hp^.next^.next;
  2975. dispose(hp^.next);
  2976. hp^.next:=hp2;
  2977. end
  2978. else
  2979. begin
  2980. def_to:=hp^.next^.nextpara^.data;
  2981. if (conv_to^.size>def_to^.size) or
  2982. ((porddef(conv_to)^.low<porddef(def_to)^.low) and
  2983. (porddef(conv_to)^.high>porddef(def_to)^.high)) then
  2984. begin
  2985. hp2:=procs;
  2986. procs:=hp;
  2987. conv_to:=def_to;
  2988. dispose(hp2);
  2989. end
  2990. else
  2991. hp:=hp^.next;
  2992. end;
  2993. end;
  2994. end;
  2995. { nun bei denn Prozeduren den nextpara-Zeiger auf den }
  2996. { naechsten Parameter setzen }
  2997. hp:=procs;
  2998. while assigned(hp) do
  2999. begin
  3000. hp^.nextpara:=hp^.nextpara^.next;
  3001. hp:=hp^.next;
  3002. end;
  3003. pt:=pt^.right;
  3004. end;
  3005. end;
  3006. { let's try to eliminate equal is exact is there }
  3007. {if assigned(procs^.next) then
  3008. begin
  3009. pt:=p^.left;
  3010. while assigned(pt) do
  3011. begin
  3012. if pt^.exact_match_found then
  3013. begin
  3014. hp:=procs;
  3015. while (assigned(procs)) and (procs^.nextpara^.data<>pt^.resulttype) do
  3016. begin
  3017. hp:=procs^.next;
  3018. dispose(procs);
  3019. procs:=hp;
  3020. end;
  3021. end;
  3022. pt:=pt^.right;
  3023. end;
  3024. end; }
  3025. {$ifndef CHAINPROCSYMS}
  3026. if assigned(procs^.next) then
  3027. Message(cg_e_cant_choose_overload_function);
  3028. {$else CHAINPROCSYMS}
  3029. if assigned(procs^.next) then
  3030. { if the last retained is the only one }
  3031. { from a unit it is OK PM }
  3032. { the last is the one coming from the first symtable }
  3033. { as the diff defcoll are inserted in front }
  3034. begin
  3035. hp2:=procs;
  3036. while assigned(hp2^.next) and assigned(hp2^.next^.next) do
  3037. hp2:=hp2^.next;
  3038. if (hp2^.data^.owner<>hp2^.next^.data^.owner) then
  3039. begin
  3040. hp:=procs^.next;
  3041. {hp2 is the correct one }
  3042. hp2:=hp2^.next;
  3043. while hp<>hp2 do
  3044. begin
  3045. dispose(procs);
  3046. procs:=hp;
  3047. hp:=procs^.next;
  3048. end;
  3049. procs:=hp2;
  3050. end
  3051. else
  3052. Message(cg_e_cant_choose_overload_function);
  3053. error(too_much_matches);
  3054. end;
  3055. {$endif CHAINPROCSYMS}
  3056. {$ifdef UseBrowser}
  3057. if make_ref then
  3058. begin
  3059. get_cur_file_pos(curtokenpos);
  3060. procs^.data^.lastref:=new(pref,init(procs^.data^.lastref,@curtokenpos));
  3061. end;
  3062. {$endif UseBrowser}
  3063. p^.procdefinition:=procs^.data;
  3064. p^.resulttype:=procs^.data^.retdef;
  3065. { big error for with statements
  3066. p^.symtableproc:=p^.procdefinition^.owner; }
  3067. p^.location.loc:=LOC_MEM;
  3068. {$ifdef CHAINPROCSYMS}
  3069. { object with method read;
  3070. call to read(x) will be a usual procedure call }
  3071. if assigned(p^.methodpointer) and
  3072. (p^.procdefinition^._class=nil) then
  3073. begin
  3074. { not ok for extended }
  3075. case p^.methodpointer^.treetype of
  3076. typen,hnewn : fatalerror(no_para_match);
  3077. end;
  3078. disposetree(p^.methodpointer);
  3079. p^.methodpointer:=nil;
  3080. end;
  3081. {$endif CHAINPROCSYMS}
  3082. end;{ end of procedure to call determination }
  3083. { handle predefined procedures }
  3084. if (p^.procdefinition^.options and pointernproc)<>0 then
  3085. begin
  3086. { settextbuf needs two args }
  3087. if assigned(p^.left^.right) then
  3088. pt:=geninlinenode(pprocdef(p^.procdefinition)^.extnumber,p^.left)
  3089. else
  3090. begin
  3091. pt:=geninlinenode(pprocdef(p^.procdefinition)^.extnumber,p^.left^.left);
  3092. putnode(p^.left);
  3093. end;
  3094. putnode(p);
  3095. firstpass(pt);
  3096. { was placed after the exit }
  3097. { caused GPF }
  3098. { error caused and corrected by (PM) }
  3099. p:=pt;
  3100. must_be_valid:=store_valid;
  3101. if codegenerror then
  3102. exit;
  3103. dispose(procs);
  3104. exit;
  3105. end
  3106. else
  3107. { no intern procedure => we do a call }
  3108. { calc the correture value for the register }
  3109. { handle predefined procedures }
  3110. if (p^.procdefinition^.options and poinline)<>0 then
  3111. begin
  3112. if assigned(p^.methodpointer) then
  3113. Message(cg_e_unable_inline_object_methods);
  3114. if assigned(p^.right) and (p^.right^.treetype<>procinlinen) then
  3115. Message(cg_e_unable_inline_procvar);
  3116. { p^.treetype:=procinlinen; }
  3117. if not assigned(p^.right) then
  3118. begin
  3119. if assigned(p^.procdefinition^.code) then
  3120. inlinecode:=genprocinlinenode(p,ptree(p^.procdefinition^.code))
  3121. else
  3122. Message(cg_e_no_code_for_inline_stored);
  3123. if assigned(inlinecode) then
  3124. begin
  3125. { consider it has not inlined if called
  3126. again inside the args }
  3127. p^.procdefinition^.options:=p^.procdefinition^.options and (not poinline);
  3128. firstpass(inlinecode);
  3129. inlined:=true;
  3130. end;
  3131. end;
  3132. end
  3133. else
  3134. procinfo.flags:=procinfo.flags or pi_do_call;
  3135. { work trough all parameters to insert the type conversions }
  3136. { !!! done now after internproc !! (PM) }
  3137. if assigned(p^.left) then
  3138. begin
  3139. old_count_ref:=count_ref;
  3140. count_ref:=true;
  3141. firstcallparan(p^.left,p^.procdefinition^.para1);
  3142. count_ref:=old_count_ref;
  3143. end;
  3144. {$ifdef i386}
  3145. for regi:=R_EAX to R_EDI do
  3146. begin
  3147. if (p^.procdefinition^.usedregisters and ($80 shr word(regi)))<>0 then
  3148. inc(reg_pushes[regi],t_times*2);
  3149. end;
  3150. {$endif}
  3151. {$ifdef m68k}
  3152. for regi:=R_D0 to R_A6 do
  3153. begin
  3154. if (p^.procdefinition^.usedregisters and ($800 shr word(regi)))<>0 then
  3155. inc(reg_pushes[regi],t_times*2);
  3156. end;
  3157. {$endif}
  3158. end;
  3159. { ensure that the result type is set }
  3160. p^.resulttype:=p^.procdefinition^.retdef;
  3161. { get a register for the return value }
  3162. if (p^.resulttype<>pdef(voiddef)) then
  3163. begin
  3164. if (p^.procdefinition^.options and poconstructor)<>0 then
  3165. begin
  3166. { extra handling of classes }
  3167. { p^.methodpointer should be assigned! }
  3168. if assigned(p^.methodpointer) and assigned(p^.methodpointer^.resulttype) and
  3169. (p^.methodpointer^.resulttype^.deftype=classrefdef) then
  3170. begin
  3171. p^.location.loc:=LOC_REGISTER;
  3172. p^.registers32:=1;
  3173. { the result type depends on the classref }
  3174. p^.resulttype:=pclassrefdef(p^.methodpointer^.resulttype)^.definition;
  3175. end
  3176. { a object constructor returns the result with the flags }
  3177. else
  3178. p^.location.loc:=LOC_FLAGS;
  3179. end
  3180. else
  3181. begin
  3182. {$ifdef SUPPORT_MMX}
  3183. if (cs_mmx in aktmoduleswitches) and
  3184. is_mmx_able_array(p^.resulttype) then
  3185. begin
  3186. p^.location.loc:=LOC_MMXREGISTER;
  3187. p^.registersmmx:=1;
  3188. end
  3189. else
  3190. {$endif SUPPORT_MMX}
  3191. if ret_in_acc(p^.resulttype) then
  3192. begin
  3193. p^.location.loc:=LOC_REGISTER;
  3194. p^.registers32:=1;
  3195. end
  3196. else if (p^.resulttype^.deftype=floatdef) then
  3197. begin
  3198. p^.location.loc:=LOC_FPU;
  3199. p^.registersfpu:=1;
  3200. end
  3201. end;
  3202. end;
  3203. {$ifdef StoreFPULevel}
  3204. { a fpu can be used in any procedure !! }
  3205. p^.registersfpu:=p^.procdefinition^.fpu_used;
  3206. {$endif StoreFPULevel}
  3207. { if this is a call to a method calc the registers }
  3208. if (p^.methodpointer<>nil) then
  3209. begin
  3210. case p^.methodpointer^.treetype of
  3211. { but only, if this is not a supporting node }
  3212. typen,hnewn : ;
  3213. else
  3214. begin
  3215. { R.Assign is not a constructor !!! }
  3216. { but for R^.Assign, R must be valid !! }
  3217. if ((p^.procdefinition^.options and poconstructor) <> 0) or
  3218. ((p^.methodpointer^.treetype=loadn) and
  3219. ((pobjectdef(p^.methodpointer^.resulttype)^.options and oo_hasvirtual) = 0)) then
  3220. must_be_valid:=false
  3221. else
  3222. must_be_valid:=true;
  3223. firstpass(p^.methodpointer);
  3224. p^.registersfpu:=max(p^.methodpointer^.registersfpu,p^.registersfpu);
  3225. p^.registers32:=max(p^.methodpointer^.registers32,p^.registers32);
  3226. {$ifdef SUPPORT_MMX}
  3227. p^.registersmmx:=max(p^.methodpointer^.registersmmx,p^.registersmmx);
  3228. {$endif SUPPORT_MMX}
  3229. end;
  3230. end;
  3231. end;
  3232. if inlined then
  3233. begin
  3234. p^.right:=inlinecode;
  3235. p^.procdefinition^.options:=p^.procdefinition^.options or poinline;
  3236. end;
  3237. { determine the registers of the procedure variable }
  3238. { is this OK for inlined procs also ?? (PM) }
  3239. if assigned(p^.right) then
  3240. begin
  3241. p^.registersfpu:=max(p^.right^.registersfpu,p^.registersfpu);
  3242. p^.registers32:=max(p^.right^.registers32,p^.registers32);
  3243. {$ifdef SUPPORT_MMX}
  3244. p^.registersmmx:=max(p^.right^.registersmmx,p^.registersmmx);
  3245. {$endif SUPPORT_MMX}
  3246. end;
  3247. { determine the registers of the procedure }
  3248. if assigned(p^.left) then
  3249. begin
  3250. p^.registersfpu:=max(p^.left^.registersfpu,p^.registersfpu);
  3251. p^.registers32:=max(p^.left^.registers32,p^.registers32);
  3252. {$ifdef SUPPORT_MMX}
  3253. p^.registersmmx:=max(p^.left^.registersmmx,p^.registersmmx);
  3254. {$endif SUPPORT_MMX}
  3255. end;
  3256. if assigned(procs) then
  3257. dispose(procs);
  3258. must_be_valid:=store_valid;
  3259. end;
  3260. procedure firstfuncret(var p : ptree);
  3261. begin
  3262. {$ifdef TEST_FUNCRET}
  3263. p^.resulttype:=p^.retdef;
  3264. p^.location.loc:=LOC_REFERENCE;
  3265. if ret_in_param(p^.retdef) or
  3266. (@procinfo<>pprocinfo(p^.funcretprocinfo)) then
  3267. p^.registers32:=1;
  3268. { no claim if setting higher return values }
  3269. if must_be_valid and
  3270. (@procinfo=pprocinfo(p^.funcretprocinfo)) and
  3271. not procinfo.funcret_is_valid then
  3272. note(uninitialized_function_return);
  3273. if count_ref then pprocinfo(p^.funcretprocinfo)^.funcret_is_valid:=true;
  3274. {$else TEST_FUNCRET}
  3275. p^.resulttype:=procinfo.retdef;
  3276. p^.location.loc:=LOC_REFERENCE;
  3277. if ret_in_param(procinfo.retdef) then
  3278. p^.registers32:=1;
  3279. if must_be_valid and
  3280. not(procinfo.funcret_is_valid) {and
  3281. ((procinfo.flags and pi_uses_asm)=0)} then
  3282. Message(sym_w_function_result_not_set);
  3283. if count_ref then procinfo.funcret_is_valid:=true;
  3284. {$endif TEST_FUNCRET}
  3285. end;
  3286. { intern inline suborutines }
  3287. procedure firstinline(var p : ptree);
  3288. var
  3289. hp,hpp : ptree;
  3290. store_count_ref,isreal,store_valid,file_is_typed : boolean;
  3291. procedure do_lowhigh(adef : pdef);
  3292. var
  3293. v : longint;
  3294. enum : penumsym;
  3295. begin
  3296. case Adef^.deftype of
  3297. orddef:
  3298. begin
  3299. if p^.inlinenumber=in_low_x then
  3300. v:=porddef(Adef)^.low
  3301. else
  3302. v:=porddef(Adef)^.high;
  3303. hp:=genordinalconstnode(v,adef);
  3304. firstpass(hp);
  3305. disposetree(p);
  3306. p:=hp;
  3307. end;
  3308. enumdef:
  3309. begin
  3310. enum:=Penumdef(Adef)^.first;
  3311. if p^.inlinenumber=in_high_x then
  3312. while enum^.next<>nil do
  3313. enum:=enum^.next;
  3314. hp:=genenumnode(enum);
  3315. disposetree(p);
  3316. p:=hp;
  3317. end
  3318. end;
  3319. end;
  3320. begin
  3321. store_valid:=must_be_valid;
  3322. store_count_ref:=count_ref;
  3323. count_ref:=false;
  3324. if not (p^.inlinenumber in [in_read_x,in_readln_x,in_sizeof_x,
  3325. in_typeof_x,in_ord_x,in_str_x_string,
  3326. in_reset_typedfile,in_rewrite_typedfile]) then
  3327. must_be_valid:=true
  3328. else
  3329. must_be_valid:=false;
  3330. { if we handle writeln; p^.left contains no valid address }
  3331. if assigned(p^.left) then
  3332. begin
  3333. if p^.left^.treetype=callparan then
  3334. firstcallparan(p^.left,nil)
  3335. else
  3336. firstpass(p^.left);
  3337. p^.registers32:=p^.left^.registers32;
  3338. p^.registersfpu:=p^.left^.registersfpu;
  3339. {$ifdef SUPPORT_MMX}
  3340. p^.registersmmx:=p^.left^.registersmmx;
  3341. {$endif SUPPORT_MMX}
  3342. set_location(p^.location,p^.left^.location);
  3343. end;
  3344. case p^.inlinenumber of
  3345. in_lo_word,in_hi_word:
  3346. begin
  3347. if p^.registers32<1 then
  3348. p^.registers32:=1;
  3349. p^.resulttype:=u8bitdef;
  3350. p^.location.loc:=LOC_REGISTER;
  3351. end;
  3352. in_lo_long,in_hi_long:
  3353. begin
  3354. if p^.registers32<1 then
  3355. p^.registers32:=1;
  3356. p^.resulttype:=u16bitdef;
  3357. p^.location.loc:=LOC_REGISTER;
  3358. end;
  3359. in_sizeof_x:
  3360. begin
  3361. if p^.registers32<1 then
  3362. p^.registers32:=1;
  3363. p^.resulttype:=s32bitdef;
  3364. p^.location.loc:=LOC_REGISTER;
  3365. end;
  3366. in_typeof_x:
  3367. begin
  3368. if p^.registers32<1 then
  3369. p^.registers32:=1;
  3370. p^.location.loc:=LOC_REGISTER;
  3371. p^.resulttype:=voidpointerdef;
  3372. end;
  3373. in_ord_x:
  3374. begin
  3375. if (p^.left^.treetype=ordconstn) then
  3376. begin
  3377. hp:=genordinalconstnode(p^.left^.value,s32bitdef);
  3378. disposetree(p);
  3379. p:=hp;
  3380. firstpass(p);
  3381. end
  3382. else
  3383. begin
  3384. if (p^.left^.resulttype^.deftype=orddef) then
  3385. if (porddef(p^.left^.resulttype)^.typ in [uchar,bool8bit]) then
  3386. begin
  3387. if porddef(p^.left^.resulttype)^.typ=bool8bit then
  3388. begin
  3389. hp:=gentypeconvnode(p^.left,u8bitdef);
  3390. putnode(p);
  3391. p:=hp;
  3392. p^.convtyp:=tc_bool_2_int;
  3393. p^.explizit:=true;
  3394. firstpass(p);
  3395. end
  3396. else
  3397. begin
  3398. hp:=gentypeconvnode(p^.left,u8bitdef);
  3399. putnode(p);
  3400. p:=hp;
  3401. p^.explizit:=true;
  3402. firstpass(p);
  3403. end;
  3404. end
  3405. { can this happen ? }
  3406. else if (porddef(p^.left^.resulttype)^.typ=uvoid) then
  3407. Message(sym_e_type_mismatch)
  3408. else
  3409. { all other orddef need no transformation }
  3410. begin
  3411. hp:=p^.left;
  3412. putnode(p);
  3413. p:=hp;
  3414. end
  3415. else if (p^.left^.resulttype^.deftype=enumdef) then
  3416. begin
  3417. hp:=gentypeconvnode(p^.left,s32bitdef);
  3418. putnode(p);
  3419. p:=hp;
  3420. p^.explizit:=true;
  3421. firstpass(p);
  3422. end
  3423. else
  3424. begin
  3425. { can anything else be ord() ?}
  3426. Message(sym_e_type_mismatch);
  3427. end;
  3428. end;
  3429. end;
  3430. in_chr_byte:
  3431. begin
  3432. hp:=gentypeconvnode(p^.left,cchardef);
  3433. putnode(p);
  3434. p:=hp;
  3435. p^.explizit:=true;
  3436. firstpass(p);
  3437. end;
  3438. in_length_string:
  3439. begin
  3440. {$ifdef UseAnsiString}
  3441. if is_ansistring(p^.left^.resulttype) then
  3442. p^.resulttype:=s32bitdef
  3443. else
  3444. {$endif UseAnsiString}
  3445. p^.resulttype:=u8bitdef;
  3446. { wer don't need string conversations here }
  3447. if (p^.left^.treetype=typeconvn) and
  3448. (p^.left^.left^.resulttype^.deftype=stringdef) then
  3449. begin
  3450. hp:=p^.left^.left;
  3451. putnode(p^.left);
  3452. p^.left:=hp;
  3453. end;
  3454. { evalutes length of constant strings direct }
  3455. if (p^.left^.treetype=stringconstn) then
  3456. begin
  3457. {$ifdef UseAnsiString}
  3458. hp:=genordinalconstnode(p^.left^.length,s32bitdef);
  3459. {$else UseAnsiString}
  3460. hp:=genordinalconstnode(length(p^.left^.values^),s32bitdef);
  3461. {$endif UseAnsiString}
  3462. disposetree(p);
  3463. firstpass(hp);
  3464. p:=hp;
  3465. end;
  3466. end;
  3467. in_assigned_x:
  3468. begin
  3469. p^.resulttype:=booldef;
  3470. p^.location.loc:=LOC_FLAGS;
  3471. end;
  3472. in_pred_x,
  3473. in_succ_x:
  3474. begin
  3475. p^.resulttype:=p^.left^.resulttype;
  3476. p^.location.loc:=LOC_REGISTER;
  3477. if not is_ordinal(p^.resulttype) then
  3478. Message(sym_e_type_mismatch)
  3479. else
  3480. begin
  3481. if (p^.resulttype^.deftype=enumdef) and
  3482. (penumdef(p^.resulttype)^.has_jumps) then
  3483. begin
  3484. Message(parser_e_succ_and_pred_enums_with_assign_not_possible);
  3485. end
  3486. else if p^.left^.treetype=ordconstn then
  3487. begin
  3488. if p^.inlinenumber=in_pred_x then
  3489. hp:=genordinalconstnode(p^.left^.value+1,
  3490. p^.left^.resulttype)
  3491. else
  3492. hp:=genordinalconstnode(p^.left^.value-1,
  3493. p^.left^.resulttype);
  3494. disposetree(p);
  3495. firstpass(hp);
  3496. p:=hp;
  3497. end;
  3498. end;
  3499. end;
  3500. in_dec_dword,
  3501. in_dec_word,
  3502. in_dec_byte,
  3503. in_inc_dword,
  3504. in_inc_word,
  3505. in_inc_byte :
  3506. begin
  3507. p^.resulttype:=voiddef;
  3508. if p^.left^.location.loc<>LOC_REFERENCE then
  3509. Message(cg_e_illegal_expression);
  3510. end;
  3511. in_inc_x,
  3512. in_dec_x:
  3513. begin
  3514. p^.resulttype:=voiddef;
  3515. if assigned(p^.left) then
  3516. begin
  3517. firstcallparan(p^.left,nil);
  3518. { first param must be var }
  3519. if not (p^.left^.left^.location.loc in [LOC_MEM,LOC_REFERENCE]) then
  3520. Message(cg_e_illegal_expression);
  3521. { check type }
  3522. if (p^.left^.resulttype^.deftype in [enumdef,pointerdef]) or
  3523. ((p^.left^.resulttype^.deftype=orddef) and
  3524. (porddef(p^.left^.resulttype)^.typ in [uchar,bool8bit,u8bit,s8bit,
  3525. bool16bit,u16bit,s16bit,bool32bit,u32bit,s32bit])) then
  3526. begin
  3527. { two paras ? }
  3528. if assigned(p^.left^.right) then
  3529. begin
  3530. { insert a type conversion }
  3531. { the second param is always longint }
  3532. p^.left^.right^.left:=gentypeconvnode(p^.left^.right^.left,s32bitdef);
  3533. { check the type conversion }
  3534. firstpass(p^.left^.right^.left);
  3535. if assigned(p^.left^.right^.right) then
  3536. Message(cg_e_illegal_expression);
  3537. end;
  3538. end
  3539. else
  3540. Message(sym_e_type_mismatch);
  3541. end
  3542. else
  3543. Message(sym_e_type_mismatch);
  3544. end;
  3545. in_read_x,
  3546. in_readln_x,
  3547. in_write_x,
  3548. in_writeln_x :
  3549. begin
  3550. { needs a call }
  3551. procinfo.flags:=procinfo.flags or pi_do_call;
  3552. p^.resulttype:=voiddef;
  3553. { we must know if it is a typed file or not }
  3554. { but we must first do the firstpass for it }
  3555. file_is_typed:=false;
  3556. if assigned(p^.left) then
  3557. begin
  3558. firstcallparan(p^.left,nil);
  3559. { now we can check }
  3560. hp:=p^.left;
  3561. while assigned(hp^.right) do
  3562. hp:=hp^.right;
  3563. { if resulttype is not assigned, then automatically }
  3564. { file is not typed. }
  3565. if assigned(hp) and assigned(hp^.resulttype) then
  3566. Begin
  3567. if (hp^.resulttype^.deftype=filedef) and
  3568. (pfiledef(hp^.resulttype)^.filetype=ft_typed) then
  3569. begin
  3570. file_is_typed:=true;
  3571. { test the type here
  3572. so we can use a trick in cgi386 (PM) }
  3573. hpp:=p^.left;
  3574. while (hpp<>hp) do
  3575. begin
  3576. { should we allow type conversion ? (PM)
  3577. if not isconvertable(hpp^.resulttype,
  3578. pfiledef(hp^.resulttype)^.typed_as,convtyp,hpp^.treetype) then
  3579. Message(sym_e_type_mismatch);
  3580. if not(is_equal(hpp^.resulttype,pfiledef(hp^.resulttype)^.typed_as)) then
  3581. begin
  3582. hpp^.left:=gentypeconvnode(hpp^.left,pfiledef(hp^.resulttype)^.typed_as);
  3583. end; }
  3584. if not is_equal(hpp^.resulttype,pfiledef(hp^.resulttype)^.typed_as) then
  3585. Message(sym_e_type_mismatch);
  3586. hpp:=hpp^.right;
  3587. end;
  3588. { once again for typeconversions }
  3589. firstcallparan(p^.left,nil);
  3590. end;
  3591. end; { endif assigned(hp) }
  3592. { insert type conversions for write(ln) }
  3593. if (not file_is_typed) and
  3594. ((p^.inlinenumber=in_write_x) or (p^.inlinenumber=in_writeln_x)) then
  3595. begin
  3596. hp:=p^.left;
  3597. while assigned(hp) do
  3598. begin
  3599. if assigned(hp^.left^.resulttype) then
  3600. begin
  3601. if hp^.left^.resulttype^.deftype=floatdef then
  3602. begin
  3603. isreal:=true;
  3604. end
  3605. else if hp^.left^.resulttype^.deftype=orddef then
  3606. case porddef(hp^.left^.resulttype)^.typ of
  3607. u8bit,s8bit,
  3608. u16bit,s16bit : hp^.left:=gentypeconvnode(hp^.left,s32bitdef);
  3609. bool16bit,bool32bit : hp^.left:=gentypeconvnode(hp^.left,booldef);
  3610. end
  3611. { but we convert only if the first index<>0, because in this case }
  3612. { we have a ASCIIZ string }
  3613. else if (hp^.left^.resulttype^.deftype=arraydef) and
  3614. (parraydef(hp^.left^.resulttype)^.lowrange<>0) and
  3615. (parraydef(hp^.left^.resulttype)^.definition^.deftype=orddef) and
  3616. (porddef(parraydef(hp^.left^.resulttype)^.definition)^.typ=uchar) then
  3617. hp^.left:=gentypeconvnode(hp^.left,cstringdef);
  3618. end;
  3619. hp:=hp^.right;
  3620. end;
  3621. end;
  3622. { pass all parameters again }
  3623. firstcallparan(p^.left,nil);
  3624. end;
  3625. end;
  3626. in_settextbuf_file_x :
  3627. begin
  3628. { warning here p^.left is the callparannode
  3629. not the argument directly }
  3630. { p^.left^.left is text var }
  3631. { p^.left^.right^.left is the buffer var }
  3632. { firstcallparan(p^.left,nil);
  3633. already done in firstcalln }
  3634. { now we know the type of buffer }
  3635. getsymonlyin(systemunit,'SETTEXTBUF');
  3636. hp:=gencallnode(pprocsym(srsym),systemunit);
  3637. hp^.left:=gencallparanode(
  3638. genordinalconstnode(p^.left^.left^.resulttype^.size,s32bitdef),p^.left);
  3639. putnode(p);
  3640. p:=hp;
  3641. firstpass(p);
  3642. end;
  3643. { the firstpass of the arg has been done in firstcalln ? }
  3644. in_reset_typedfile,in_rewrite_typedfile :
  3645. begin
  3646. procinfo.flags:=procinfo.flags or pi_do_call;
  3647. { to be sure the right definition is loaded }
  3648. p^.left^.resulttype:=nil;
  3649. firstload(p^.left);
  3650. p^.resulttype:=voiddef;
  3651. end;
  3652. in_str_x_string :
  3653. begin
  3654. procinfo.flags:=procinfo.flags or pi_do_call;
  3655. p^.resulttype:=voiddef;
  3656. if assigned(p^.left) then
  3657. begin
  3658. hp:=p^.left^.right;
  3659. { first pass just the string for first local use }
  3660. must_be_valid:=false;
  3661. count_ref:=true;
  3662. p^.left^.right:=nil;
  3663. firstcallparan(p^.left,nil);
  3664. must_be_valid:=true;
  3665. p^.left^.right:=hp;
  3666. firstcallparan(p^.left^.right,nil);
  3667. hp:=p^.left;
  3668. isreal:=false;
  3669. { valid string ? }
  3670. if not assigned(hp) or
  3671. (hp^.left^.resulttype^.deftype<>stringdef) or
  3672. (hp^.right=nil) or
  3673. (hp^.left^.location.loc<>LOC_REFERENCE) then
  3674. Message(cg_e_illegal_expression);
  3675. { !!!! check length of string }
  3676. while assigned(hp^.right) do hp:=hp^.right;
  3677. { check and convert the first param }
  3678. if hp^.is_colon_para then
  3679. Message(cg_e_illegal_expression)
  3680. else if hp^.resulttype^.deftype=orddef then
  3681. case porddef(hp^.left^.resulttype)^.typ of
  3682. u8bit,s8bit,
  3683. u16bit,s16bit :
  3684. hp^.left:=gentypeconvnode(hp^.left,s32bitdef);
  3685. end
  3686. else if hp^.resulttype^.deftype=floatdef then
  3687. begin
  3688. isreal:=true;
  3689. end
  3690. else Message(cg_e_illegal_expression);
  3691. { some format options ? }
  3692. hp:=p^.left^.right;
  3693. if assigned(hp) and hp^.is_colon_para then
  3694. begin
  3695. hp^.left:=gentypeconvnode(hp^.left,s32bitdef);
  3696. hp:=hp^.right;
  3697. end;
  3698. if assigned(hp) and hp^.is_colon_para then
  3699. begin
  3700. if isreal then
  3701. hp^.left:=gentypeconvnode(hp^.left,s32bitdef)
  3702. else
  3703. Message(parser_e_illegal_colon_qualifier);
  3704. hp:=hp^.right;
  3705. end;
  3706. { for first local use }
  3707. must_be_valid:=false;
  3708. count_ref:=true;
  3709. if assigned(hp) then
  3710. firstcallparan(hp,nil);
  3711. end
  3712. else
  3713. Message(parser_e_illegal_parameter_list);
  3714. { check params once more }
  3715. if codegenerror then
  3716. exit;
  3717. must_be_valid:=true;
  3718. firstcallparan(p^.left,nil);
  3719. end;
  3720. in_include_x_y,
  3721. in_exclude_x_y:
  3722. begin
  3723. p^.resulttype:=voiddef;
  3724. if assigned(p^.left) then
  3725. begin
  3726. firstcallparan(p^.left,nil);
  3727. p^.registers32:=p^.left^.registers32;
  3728. p^.registersfpu:=p^.left^.registersfpu;
  3729. {$ifdef SUPPORT_MMX}
  3730. p^.registersmmx:=p^.left^.registersmmx;
  3731. {$endif SUPPORT_MMX}
  3732. { first param must be var }
  3733. if (p^.left^.left^.location.loc<>LOC_REFERENCE) and
  3734. (p^.left^.left^.location.loc<>LOC_CREGISTER) then
  3735. Message(cg_e_illegal_expression);
  3736. { check type }
  3737. if (p^.left^.resulttype^.deftype=setdef) then
  3738. begin
  3739. { two paras ? }
  3740. if assigned(p^.left^.right) then
  3741. begin
  3742. { insert a type conversion }
  3743. { to the type of the set elements }
  3744. p^.left^.right^.left:=gentypeconvnode(
  3745. p^.left^.right^.left,
  3746. psetdef(p^.left^.resulttype)^.setof);
  3747. { check the type conversion }
  3748. firstpass(p^.left^.right^.left);
  3749. { only three parameters are allowed }
  3750. if assigned(p^.left^.right^.right) then
  3751. Message(cg_e_illegal_expression);
  3752. end;
  3753. end
  3754. else
  3755. Message(sym_e_type_mismatch);
  3756. end
  3757. else
  3758. Message(sym_e_type_mismatch);
  3759. end;
  3760. in_low_x,in_high_x:
  3761. begin
  3762. if p^.left^.treetype in [typen,loadn] then
  3763. begin
  3764. case p^.left^.resulttype^.deftype of
  3765. orddef,enumdef:
  3766. begin
  3767. do_lowhigh(p^.left^.resulttype);
  3768. firstpass(p);
  3769. end;
  3770. setdef:
  3771. begin
  3772. do_lowhigh(Psetdef(p^.left^.resulttype)^.setof);
  3773. firstpass(p);
  3774. end;
  3775. arraydef:
  3776. begin
  3777. if is_open_array(p^.left^.resulttype) then
  3778. begin
  3779. if p^.inlinenumber=in_low_x then
  3780. begin
  3781. hp:=genordinalconstnode(Parraydef(p^.left^.resulttype)^.lowrange,s32bitdef);
  3782. disposetree(p);
  3783. p:=hp;
  3784. firstpass(p);
  3785. end
  3786. else
  3787. begin
  3788. p^.resulttype:=s32bitdef;
  3789. p^.registers32:=max(1,
  3790. p^.registers32);
  3791. p^.location.loc:=LOC_REGISTER;
  3792. end;
  3793. end
  3794. else
  3795. begin
  3796. if p^.inlinenumber=in_low_x then
  3797. hp:=genordinalconstnode(Parraydef(p^.left^.resulttype)^.lowrange,s32bitdef)
  3798. else
  3799. hp:=genordinalconstnode(Parraydef(p^.left^.resulttype)^.highrange,s32bitdef);
  3800. disposetree(p);
  3801. p:=hp;
  3802. firstpass(p);
  3803. end;
  3804. end;
  3805. stringdef:
  3806. begin
  3807. if p^.inlinenumber=in_low_x then
  3808. hp:=genordinalconstnode(0,u8bitdef)
  3809. else
  3810. hp:=genordinalconstnode(Pstringdef(p^.left^.resulttype)^.len,u8bitdef);
  3811. disposetree(p);
  3812. p:=hp;
  3813. firstpass(p);
  3814. end;
  3815. else
  3816. Message(sym_e_type_mismatch);
  3817. end;
  3818. end
  3819. else
  3820. Message(parser_e_varid_or_typeid_expected);
  3821. end
  3822. else internalerror(8);
  3823. end;
  3824. must_be_valid:=store_valid;
  3825. count_ref:=store_count_ref;
  3826. end;
  3827. procedure firstsubscriptn(var p : ptree);
  3828. begin
  3829. firstpass(p^.left);
  3830. if codegenerror then
  3831. begin
  3832. p^.resulttype:=generrordef;
  3833. exit;
  3834. end;
  3835. p^.resulttype:=p^.vs^.definition;
  3836. { this must be done in the parser
  3837. if count_ref and not must_be_valid then
  3838. if (p^.vs^.properties and sp_protected)<>0 then
  3839. Message(parser_e_cant_write_protected_member);
  3840. }
  3841. p^.registers32:=p^.left^.registers32;
  3842. p^.registersfpu:=p^.left^.registersfpu;
  3843. {$ifdef SUPPORT_MMX}
  3844. p^.registersmmx:=p^.left^.registersmmx;
  3845. {$endif SUPPORT_MMX}
  3846. { classes must be dereferenced implicit }
  3847. if (p^.left^.resulttype^.deftype=objectdef) and
  3848. pobjectdef(p^.left^.resulttype)^.isclass then
  3849. begin
  3850. if p^.registers32=0 then
  3851. p^.registers32:=1;
  3852. p^.location.loc:=LOC_REFERENCE;
  3853. end
  3854. else
  3855. begin
  3856. if (p^.left^.location.loc<>LOC_MEM) and
  3857. (p^.left^.location.loc<>LOC_REFERENCE) then
  3858. Message(cg_e_illegal_expression);
  3859. set_location(p^.location,p^.left^.location);
  3860. end;
  3861. end;
  3862. procedure firstselfn(var p : ptree);
  3863. begin
  3864. if (p^.resulttype^.deftype=classrefdef) or
  3865. ((p^.resulttype^.deftype=objectdef)
  3866. and pobjectdef(p^.resulttype)^.isclass
  3867. ) then
  3868. p^.location.loc:=LOC_REGISTER
  3869. else
  3870. p^.location.loc:=LOC_REFERENCE;
  3871. end;
  3872. procedure firsttypen(var p : ptree);
  3873. begin
  3874. { DM: Why not allowed? For example: low(word) results in a type
  3875. id of word.
  3876. error(typeid_here_not_allowed);}
  3877. end;
  3878. procedure firsthnewn(var p : ptree);
  3879. begin
  3880. end;
  3881. procedure firsthdisposen(var p : ptree);
  3882. begin
  3883. firstpass(p^.left);
  3884. if codegenerror then
  3885. exit;
  3886. p^.registers32:=p^.left^.registers32;
  3887. p^.registersfpu:=p^.left^.registersfpu;
  3888. {$ifdef SUPPORT_MMX}
  3889. p^.registersmmx:=p^.left^.registersmmx;
  3890. {$endif SUPPORT_MMX}
  3891. if p^.registers32<1 then
  3892. p^.registers32:=1;
  3893. {
  3894. if p^.left^.location.loc<>LOC_REFERENCE then
  3895. Message(cg_e_illegal_expression);
  3896. }
  3897. p^.location.loc:=LOC_REFERENCE;
  3898. p^.resulttype:=ppointerdef(p^.left^.resulttype)^.definition;
  3899. end;
  3900. procedure firstnewn(var p : ptree);
  3901. begin
  3902. { Standardeinleitung }
  3903. firstpass(p^.left);
  3904. if codegenerror then
  3905. exit;
  3906. p^.registers32:=p^.left^.registers32;
  3907. p^.registersfpu:=p^.left^.registersfpu;
  3908. {$ifdef SUPPORT_MMX}
  3909. p^.registersmmx:=p^.left^.registersmmx;
  3910. {$endif SUPPORT_MMX}
  3911. { result type is already set }
  3912. procinfo.flags:=procinfo.flags or pi_do_call;
  3913. p^.location.loc:=LOC_REGISTER;
  3914. end;
  3915. procedure firstsimplenewdispose(var p : ptree);
  3916. begin
  3917. { this cannot be in a register !! }
  3918. make_not_regable(p^.left);
  3919. firstpass(p^.left);
  3920. { check the type }
  3921. if (p^.left^.resulttype=nil) or (p^.left^.resulttype^.deftype<>pointerdef) then
  3922. Message(parser_e_pointer_type_expected);
  3923. if (p^.left^.location.loc<>LOC_REFERENCE) {and
  3924. (p^.left^.location.loc<>LOC_CREGISTER)} then
  3925. Message(cg_e_illegal_expression);
  3926. p^.registers32:=p^.left^.registers32;
  3927. p^.registersfpu:=p^.left^.registersfpu;
  3928. {$ifdef SUPPORT_MMX}
  3929. p^.registersmmx:=p^.left^.registersmmx;
  3930. {$endif SUPPORT_MMX}
  3931. p^.resulttype:=voiddef;
  3932. procinfo.flags:=procinfo.flags or pi_do_call;
  3933. end;
  3934. procedure firstsetcons(var p : ptree);
  3935. var
  3936. hp : ptree;
  3937. begin
  3938. p^.location.loc:=LOC_MEM;
  3939. hp:=p^.left;
  3940. { is done by getnode*
  3941. p^.registers32:=0;
  3942. p^.registersfpu:=0;
  3943. }
  3944. while assigned(hp) do
  3945. begin
  3946. firstpass(hp^.left);
  3947. if codegenerror then
  3948. exit;
  3949. p^.registers32:=max(p^.registers32,hp^.left^.registers32);
  3950. p^.registersfpu:=max(p^.registersfpu,hp^.left^.registersfpu);;
  3951. {$ifdef SUPPORT_MMX}
  3952. p^.registersmmx:=max(p^.registersmmx,hp^.left^.registersmmx);
  3953. {$endif SUPPORT_MMX}
  3954. hp:=hp^.right;
  3955. end;
  3956. { result type is already set }
  3957. end;
  3958. procedure firstin(var p : ptree);
  3959. begin
  3960. p^.location.loc:=LOC_FLAGS;
  3961. p^.resulttype:=booldef;
  3962. firstpass(p^.right);
  3963. if codegenerror then
  3964. exit;
  3965. if p^.right^.resulttype^.deftype<>setdef then
  3966. Message(sym_e_set_expected);
  3967. firstpass(p^.left);
  3968. if codegenerror then
  3969. exit;
  3970. p^.left:=gentypeconvnode(p^.left,psetdef(p^.right^.resulttype)^.setof);
  3971. firstpass(p^.left);
  3972. if codegenerror then
  3973. exit;
  3974. left_right_max(p);
  3975. { this is not allways true due to optimization }
  3976. { but if we don't set this we get problems with optimizing self code }
  3977. if psetdef(p^.right^.resulttype)^.settype<>smallset then
  3978. procinfo.flags:=procinfo.flags or pi_do_call;
  3979. end;
  3980. procedure firststatement(var p : ptree);
  3981. begin
  3982. { left is the next statement in the list }
  3983. p^.resulttype:=voiddef;
  3984. { no temps over several statements }
  3985. cleartempgen;
  3986. { right is the statement itself calln assignn or a complex one }
  3987. firstpass(p^.right);
  3988. if (not (cs_extsyntax in aktmoduleswitches)) and
  3989. assigned(p^.right^.resulttype) and
  3990. (p^.right^.resulttype<>pdef(voiddef)) then
  3991. Message(cg_e_illegal_expression);
  3992. if codegenerror then
  3993. exit;
  3994. p^.registers32:=p^.right^.registers32;
  3995. p^.registersfpu:=p^.right^.registersfpu;
  3996. {$ifdef SUPPORT_MMX}
  3997. p^.registersmmx:=p^.right^.registersmmx;
  3998. {$endif SUPPORT_MMX}
  3999. { left is the next in the list }
  4000. firstpass(p^.left);
  4001. if codegenerror then
  4002. exit;
  4003. if p^.right^.registers32>p^.registers32 then
  4004. p^.registers32:=p^.right^.registers32;
  4005. if p^.right^.registersfpu>p^.registersfpu then
  4006. p^.registersfpu:=p^.right^.registersfpu;
  4007. {$ifdef SUPPORT_MMX}
  4008. if p^.right^.registersmmx>p^.registersmmx then
  4009. p^.registersmmx:=p^.right^.registersmmx;
  4010. {$endif}
  4011. end;
  4012. procedure firstblock(var p : ptree);
  4013. var
  4014. hp : ptree;
  4015. count : longint;
  4016. begin
  4017. count:=0;
  4018. hp:=p^.left;
  4019. while assigned(hp) do
  4020. begin
  4021. if cs_maxoptimize in aktglobalswitches then
  4022. begin
  4023. { Codeumstellungen }
  4024. { Funktionsresultate an exit anh„ngen }
  4025. { this is wrong for string or other complex
  4026. result types !!! }
  4027. if ret_in_acc(procinfo.retdef) and
  4028. assigned(hp^.left) and
  4029. (hp^.left^.right^.treetype=exitn) and
  4030. (hp^.right^.treetype=assignn) and
  4031. (hp^.right^.left^.treetype=funcretn) then
  4032. begin
  4033. if assigned(hp^.left^.right^.left) then
  4034. Message(cg_n_inefficient_code)
  4035. else
  4036. begin
  4037. hp^.left^.right^.left:=getcopy(hp^.right^.right);
  4038. disposetree(hp^.right);
  4039. hp^.right:=nil;
  4040. end;
  4041. end
  4042. { warning if unreachable code occurs and elimate this }
  4043. else if (hp^.right^.treetype in
  4044. [exitn,breakn,continuen,goton]) and
  4045. assigned(hp^.left) and
  4046. (hp^.left^.treetype<>labeln) then
  4047. begin
  4048. { use correct line number }
  4049. aktfilepos:=hp^.left^.fileinfo;
  4050. disposetree(hp^.left);
  4051. hp^.left:=nil;
  4052. Message(cg_w_unreachable_code);
  4053. { old lines }
  4054. aktfilepos:=hp^.right^.fileinfo;
  4055. end;
  4056. end;
  4057. if assigned(hp^.right) then
  4058. begin
  4059. cleartempgen;
  4060. firstpass(hp^.right);
  4061. if (not (cs_extsyntax in aktmoduleswitches)) and
  4062. assigned(hp^.right^.resulttype) and
  4063. (hp^.right^.resulttype<>pdef(voiddef)) then
  4064. Message(cg_e_illegal_expression);
  4065. if codegenerror then
  4066. exit;
  4067. hp^.registers32:=hp^.right^.registers32;
  4068. hp^.registersfpu:=hp^.right^.registersfpu;
  4069. {$ifdef SUPPORT_MMX}
  4070. hp^.registersmmx:=hp^.right^.registersmmx;
  4071. {$endif SUPPORT_MMX}
  4072. end
  4073. else
  4074. hp^.registers32:=0;
  4075. if hp^.registers32>p^.registers32 then
  4076. p^.registers32:=hp^.registers32;
  4077. if hp^.registersfpu>p^.registersfpu then
  4078. p^.registersfpu:=hp^.registersfpu;
  4079. {$ifdef SUPPORT_MMX}
  4080. if hp^.registersmmx>p^.registersmmx then
  4081. p^.registersmmx:=hp^.registersmmx;
  4082. {$endif}
  4083. inc(count);
  4084. hp:=hp^.left;
  4085. end;
  4086. { p^.registers32:=round(p^.registers32/count); }
  4087. end;
  4088. procedure first_while_repeat(var p : ptree);
  4089. var
  4090. old_t_times : longint;
  4091. begin
  4092. old_t_times:=t_times;
  4093. { Registergewichtung bestimmen }
  4094. if not(cs_littlesize in aktglobalswitches ) then
  4095. t_times:=t_times*8;
  4096. cleartempgen;
  4097. must_be_valid:=true;
  4098. firstpass(p^.left);
  4099. if codegenerror then
  4100. exit;
  4101. if not((p^.left^.resulttype^.deftype=orddef) and
  4102. (porddef(p^.left^.resulttype)^.typ=bool8bit)) then
  4103. begin
  4104. Message(sym_e_type_mismatch);
  4105. exit;
  4106. end;
  4107. p^.registers32:=p^.left^.registers32;
  4108. p^.registersfpu:=p^.left^.registersfpu;
  4109. {$ifdef SUPPORT_MMX}
  4110. p^.registersmmx:=p^.left^.registersmmx;
  4111. {$endif SUPPORT_MMX}
  4112. { loop instruction }
  4113. if assigned(p^.right) then
  4114. begin
  4115. cleartempgen;
  4116. firstpass(p^.right);
  4117. if codegenerror then
  4118. exit;
  4119. if p^.registers32<p^.right^.registers32 then
  4120. p^.registers32:=p^.right^.registers32;
  4121. if p^.registersfpu<p^.right^.registersfpu then
  4122. p^.registersfpu:=p^.right^.registersfpu;
  4123. {$ifdef SUPPORT_MMX}
  4124. if p^.registersmmx<p^.right^.registersmmx then
  4125. p^.registersmmx:=p^.right^.registersmmx;
  4126. {$endif SUPPORT_MMX}
  4127. end;
  4128. t_times:=old_t_times;
  4129. end;
  4130. procedure firstif(var p : ptree);
  4131. var
  4132. old_t_times : longint;
  4133. hp : ptree;
  4134. begin
  4135. old_t_times:=t_times;
  4136. cleartempgen;
  4137. must_be_valid:=true;
  4138. firstpass(p^.left);
  4139. if codegenerror then
  4140. exit;
  4141. if not((p^.left^.resulttype^.deftype=orddef) and
  4142. (porddef(p^.left^.resulttype)^.typ in [bool8bit,bool16bit,bool32bit])) then
  4143. begin
  4144. Message(sym_e_type_mismatch);
  4145. exit;
  4146. end;
  4147. p^.registers32:=p^.left^.registers32;
  4148. p^.registersfpu:=p^.left^.registersfpu;
  4149. {$ifdef SUPPORT_MMX}
  4150. p^.registersmmx:=p^.left^.registersmmx;
  4151. {$endif SUPPORT_MMX}
  4152. { determines registers weigths }
  4153. if not(cs_littlesize in aktglobalswitches) then
  4154. t_times:=t_times div 2;
  4155. if t_times=0 then
  4156. t_times:=1;
  4157. { if path }
  4158. if assigned(p^.right) then
  4159. begin
  4160. cleartempgen;
  4161. firstpass(p^.right);
  4162. if codegenerror then
  4163. exit;
  4164. if p^.registers32<p^.right^.registers32 then
  4165. p^.registers32:=p^.right^.registers32;
  4166. if p^.registersfpu<p^.right^.registersfpu then
  4167. p^.registersfpu:=p^.right^.registersfpu;
  4168. {$ifdef SUPPORT_MMX}
  4169. if p^.registersmmx<p^.right^.registersmmx then
  4170. p^.registersmmx:=p^.right^.registersmmx;
  4171. {$endif SUPPORT_MMX}
  4172. end;
  4173. { else path }
  4174. if assigned(p^.t1) then
  4175. begin
  4176. cleartempgen;
  4177. firstpass(p^.t1);
  4178. if codegenerror then
  4179. exit;
  4180. if p^.registers32<p^.t1^.registers32 then
  4181. p^.registers32:=p^.t1^.registers32;
  4182. if p^.registersfpu<p^.t1^.registersfpu then
  4183. p^.registersfpu:=p^.t1^.registersfpu;
  4184. {$ifdef SUPPORT_MMX}
  4185. if p^.registersmmx<p^.t1^.registersmmx then
  4186. p^.registersmmx:=p^.t1^.registersmmx;
  4187. {$endif SUPPORT_MMX}
  4188. end;
  4189. if p^.left^.treetype=ordconstn then
  4190. begin
  4191. { optimize }
  4192. if p^.left^.value=1 then
  4193. begin
  4194. disposetree(p^.left);
  4195. hp:=p^.right;
  4196. disposetree(p^.t1);
  4197. { we cannot set p to nil !!! }
  4198. if assigned(hp) then
  4199. begin
  4200. putnode(p);
  4201. p:=hp;
  4202. end
  4203. else
  4204. begin
  4205. p^.left:=nil;
  4206. p^.t1:=nil;
  4207. p^.treetype:=nothingn;
  4208. end;
  4209. end
  4210. else
  4211. begin
  4212. disposetree(p^.left);
  4213. hp:=p^.t1;
  4214. disposetree(p^.right);
  4215. { we cannot set p to nil !!! }
  4216. if assigned(hp) then
  4217. begin
  4218. putnode(p);
  4219. p:=hp;
  4220. end
  4221. else
  4222. begin
  4223. p^.left:=nil;
  4224. p^.right:=nil;
  4225. p^.treetype:=nothingn;
  4226. end;
  4227. end;
  4228. end;
  4229. t_times:=old_t_times;
  4230. end;
  4231. procedure firstexitn(var p : ptree);
  4232. begin
  4233. if assigned(p^.left) then
  4234. begin
  4235. firstpass(p^.left);
  4236. p^.registers32:=p^.left^.registers32;
  4237. p^.registersfpu:=p^.left^.registersfpu;
  4238. {$ifdef SUPPORT_MMX}
  4239. p^.registersmmx:=p^.left^.registersmmx;
  4240. {$endif SUPPORT_MMX}
  4241. end;
  4242. end;
  4243. procedure firstfor(var p : ptree);
  4244. var
  4245. old_t_times : longint;
  4246. begin
  4247. { Registergewichtung bestimmen
  4248. (nicht genau), }
  4249. old_t_times:=t_times;
  4250. if not(cs_littlesize in aktglobalswitches) then
  4251. t_times:=t_times*8;
  4252. cleartempgen;
  4253. if p^.t1<>nil then
  4254. firstpass(p^.t1);
  4255. p^.registers32:=p^.t1^.registers32;
  4256. p^.registersfpu:=p^.t1^.registersfpu;
  4257. {$ifdef SUPPORT_MMX}
  4258. p^.registersmmx:=p^.left^.registersmmx;
  4259. {$endif SUPPORT_MMX}
  4260. if p^.left^.treetype<>assignn then
  4261. Message(cg_e_illegal_expression);
  4262. { Laufvariable retten }
  4263. p^.t2:=getcopy(p^.left^.left);
  4264. { Check count var }
  4265. if (p^.t2^.treetype<>loadn) then
  4266. Message(cg_e_illegal_count_var);
  4267. if (not(is_ordinal(p^.t2^.resulttype))) then
  4268. Message(parser_e_ordinal_expected);
  4269. cleartempgen;
  4270. must_be_valid:=false;
  4271. firstpass(p^.left);
  4272. must_be_valid:=true;
  4273. if p^.left^.registers32>p^.registers32 then
  4274. p^.registers32:=p^.left^.registers32;
  4275. if p^.left^.registersfpu>p^.registersfpu then
  4276. p^.registersfpu:=p^.left^.registersfpu;
  4277. {$ifdef SUPPORT_MMX}
  4278. if p^.left^.registersmmx>p^.registersmmx then
  4279. p^.registersmmx:=p^.left^.registersmmx;
  4280. {$endif SUPPORT_MMX}
  4281. cleartempgen;
  4282. firstpass(p^.t2);
  4283. if p^.t2^.registers32>p^.registers32 then
  4284. p^.registers32:=p^.t2^.registers32;
  4285. if p^.t2^.registersfpu>p^.registersfpu then
  4286. p^.registersfpu:=p^.t2^.registersfpu;
  4287. {$ifdef SUPPORT_MMX}
  4288. if p^.t2^.registersmmx>p^.registersmmx then
  4289. p^.registersmmx:=p^.t2^.registersmmx;
  4290. {$endif SUPPORT_MMX}
  4291. cleartempgen;
  4292. firstpass(p^.right);
  4293. if p^.right^.treetype<>ordconstn then
  4294. begin
  4295. p^.right:=gentypeconvnode(p^.right,p^.t2^.resulttype);
  4296. cleartempgen;
  4297. firstpass(p^.right);
  4298. end;
  4299. if p^.right^.registers32>p^.registers32 then
  4300. p^.registers32:=p^.right^.registers32;
  4301. if p^.right^.registersfpu>p^.registersfpu then
  4302. p^.registersfpu:=p^.right^.registersfpu;
  4303. {$ifdef SUPPORT_MMX}
  4304. if p^.right^.registersmmx>p^.registersmmx then
  4305. p^.registersmmx:=p^.right^.registersmmx;
  4306. {$endif SUPPORT_MMX}
  4307. t_times:=old_t_times;
  4308. end;
  4309. procedure firstasm(var p : ptree);
  4310. begin
  4311. { it's a f... to determine the used registers }
  4312. { should be done by getnode
  4313. I think also, that all values should be set to their maximum (FK)
  4314. p^.registers32:=0;
  4315. p^.registersfpu:=0;
  4316. p^.registersmmx:=0;
  4317. }
  4318. procinfo.flags:=procinfo.flags or pi_uses_asm;
  4319. end;
  4320. procedure firstgoto(var p : ptree);
  4321. begin
  4322. {
  4323. p^.registers32:=0;
  4324. p^.registersfpu:=0;
  4325. }
  4326. p^.resulttype:=voiddef;
  4327. end;
  4328. procedure firstlabel(var p : ptree);
  4329. begin
  4330. cleartempgen;
  4331. firstpass(p^.left);
  4332. p^.registers32:=p^.left^.registers32;
  4333. p^.registersfpu:=p^.left^.registersfpu;
  4334. {$ifdef SUPPORT_MMX}
  4335. p^.registersmmx:=p^.left^.registersmmx;
  4336. {$endif SUPPORT_MMX}
  4337. p^.resulttype:=voiddef;
  4338. end;
  4339. procedure firstcase(var p : ptree);
  4340. var
  4341. old_t_times : longint;
  4342. hp : ptree;
  4343. begin
  4344. { evalutes the case expression }
  4345. cleartempgen;
  4346. must_be_valid:=true;
  4347. firstpass(p^.left);
  4348. if codegenerror then
  4349. exit;
  4350. p^.registers32:=p^.left^.registers32;
  4351. p^.registersfpu:=p^.left^.registersfpu;
  4352. {$ifdef SUPPORT_MMX}
  4353. p^.registersmmx:=p^.left^.registersmmx;
  4354. {$endif SUPPORT_MMX}
  4355. { walk through all instructions }
  4356. { estimates the repeat of each instruction }
  4357. old_t_times:=t_times;
  4358. if not(cs_littlesize in aktglobalswitches) then
  4359. begin
  4360. t_times:=t_times div case_count_labels(p^.nodes);
  4361. if t_times<1 then
  4362. t_times:=1;
  4363. end;
  4364. { first case }
  4365. hp:=p^.right;
  4366. while assigned(hp) do
  4367. begin
  4368. cleartempgen;
  4369. firstpass(hp^.right);
  4370. { searchs max registers }
  4371. if hp^.right^.registers32>p^.registers32 then
  4372. p^.registers32:=hp^.right^.registers32;
  4373. if hp^.right^.registersfpu>p^.registersfpu then
  4374. p^.registersfpu:=hp^.right^.registersfpu;
  4375. {$ifdef SUPPORT_MMX}
  4376. if hp^.right^.registersmmx>p^.registersmmx then
  4377. p^.registersmmx:=hp^.right^.registersmmx;
  4378. {$endif SUPPORT_MMX}
  4379. hp:=hp^.left;
  4380. end;
  4381. { may be handle else tree }
  4382. if assigned(p^.elseblock) then
  4383. begin
  4384. cleartempgen;
  4385. firstpass(p^.elseblock);
  4386. if codegenerror then
  4387. exit;
  4388. if p^.registers32<p^.elseblock^.registers32 then
  4389. p^.registers32:=p^.elseblock^.registers32;
  4390. if p^.registersfpu<p^.elseblock^.registersfpu then
  4391. p^.registersfpu:=p^.elseblock^.registersfpu;
  4392. {$ifdef SUPPORT_MMX}
  4393. if p^.registersmmx<p^.elseblock^.registersmmx then
  4394. p^.registersmmx:=p^.elseblock^.registersmmx;
  4395. {$endif SUPPORT_MMX}
  4396. end;
  4397. t_times:=old_t_times;
  4398. { there is one register required for the case expression }
  4399. if p^.registers32<1 then p^.registers32:=1;
  4400. end;
  4401. procedure firsttryexcept(var p : ptree);
  4402. begin
  4403. cleartempgen;
  4404. firstpass(p^.left);
  4405. { on statements }
  4406. if assigned(p^.right) then
  4407. begin
  4408. cleartempgen;
  4409. firstpass(p^.right);
  4410. p^.registers32:=max(p^.registers32,p^.right^.registers32);
  4411. p^.registersfpu:=max(p^.registersfpu,p^.right^.registersfpu);
  4412. {$ifdef SUPPORT_MMX}
  4413. p^.registersmmx:=max(p^.registersmmx,p^.right^.registersmmx);
  4414. {$endif SUPPORT_MMX}
  4415. end;
  4416. { else block }
  4417. if assigned(p^.t1) then
  4418. begin
  4419. firstpass(p^.t1);
  4420. p^.registers32:=max(p^.registers32,p^.t1^.registers32);
  4421. p^.registersfpu:=max(p^.registersfpu,p^.t1^.registersfpu);
  4422. {$ifdef SUPPORT_MMX}
  4423. p^.registersmmx:=max(p^.registersmmx,p^.t1^.registersmmx);
  4424. {$endif SUPPORT_MMX}
  4425. end;
  4426. end;
  4427. procedure firsttryfinally(var p : ptree);
  4428. begin
  4429. p^.resulttype:=voiddef;
  4430. cleartempgen;
  4431. must_be_valid:=true;
  4432. firstpass(p^.left);
  4433. cleartempgen;
  4434. must_be_valid:=true;
  4435. firstpass(p^.right);
  4436. if codegenerror then
  4437. exit;
  4438. p^.registers32:=max(p^.left^.registers32,p^.right^.registers32);
  4439. p^.registersfpu:=max(p^.left^.registersfpu,p^.right^.registersfpu);
  4440. {$ifdef SUPPORT_MMX}
  4441. p^.registersmmx:=max(p^.left^.registersmmx,p^.right^.registersmmx);
  4442. {$endif SUPPORT_MMX}
  4443. end;
  4444. procedure firstis(var p : ptree);
  4445. begin
  4446. firstpass(p^.left);
  4447. firstpass(p^.right);
  4448. if (p^.right^.resulttype^.deftype<>classrefdef) then
  4449. Message(sym_e_type_mismatch);
  4450. if codegenerror then
  4451. exit;
  4452. left_right_max(p);
  4453. { left must be a class }
  4454. if (p^.left^.resulttype^.deftype<>objectdef) or
  4455. not(pobjectdef(p^.left^.resulttype)^.isclass) then
  4456. Message(sym_e_type_mismatch);
  4457. { the operands must be related }
  4458. if (not(pobjectdef(p^.left^.resulttype)^.isrelated(
  4459. pobjectdef(pclassrefdef(p^.right^.resulttype)^.definition)))) and
  4460. (not(pobjectdef(pclassrefdef(p^.right^.resulttype)^.definition)^.isrelated(
  4461. pobjectdef(p^.left^.resulttype)))) then
  4462. Message(sym_e_type_mismatch);
  4463. p^.location.loc:=LOC_FLAGS;
  4464. p^.resulttype:=booldef;
  4465. end;
  4466. procedure firstas(var p : ptree);
  4467. begin
  4468. firstpass(p^.right);
  4469. firstpass(p^.left);
  4470. if (p^.right^.resulttype^.deftype<>classrefdef) then
  4471. Message(sym_e_type_mismatch);
  4472. if codegenerror then
  4473. exit;
  4474. left_right_max(p);
  4475. (* this was wrong,no ??
  4476. p^.registersfpu:=max(p^.left^.registersfpu,p^.left^.registersfpu);
  4477. p^.registers32:=max(p^.left^.registers32,p^.right^.registers32);
  4478. {$ifdef SUPPORT_MMX}
  4479. p^.registersmmx:=max(p^.left^.registersmmx,p^.right^.registersmmx);
  4480. {$endif SUPPORT_MMX} *)
  4481. { left must be a class }
  4482. if (p^.left^.resulttype^.deftype<>objectdef) or
  4483. not(pobjectdef(p^.left^.resulttype)^.isclass) then
  4484. Message(sym_e_type_mismatch);
  4485. { the operands must be related }
  4486. if (not(pobjectdef(p^.left^.resulttype)^.isrelated(
  4487. pobjectdef(pclassrefdef(p^.right^.resulttype)^.definition)))) and
  4488. (not(pobjectdef(pclassrefdef(p^.right^.resulttype)^.definition)^.isrelated(
  4489. pobjectdef(p^.left^.resulttype)))) then
  4490. Message(sym_e_type_mismatch);
  4491. p^.location:=p^.left^.location;
  4492. p^.resulttype:=pclassrefdef(p^.right^.resulttype)^.definition;
  4493. end;
  4494. procedure firstloadvmt(var p : ptree);
  4495. begin
  4496. { resulttype must be set !
  4497. p^.registersfpu:=0;
  4498. }
  4499. p^.registers32:=1;
  4500. p^.location.loc:=LOC_REGISTER;
  4501. end;
  4502. procedure firstraise(var p : ptree);
  4503. begin
  4504. p^.resulttype:=voiddef;
  4505. {
  4506. p^.registersfpu:=0;
  4507. p^.registers32:=0;
  4508. }
  4509. if assigned(p^.left) then
  4510. begin
  4511. firstpass(p^.left);
  4512. { this must be a _class_ }
  4513. if (p^.left^.resulttype^.deftype<>objectdef) or
  4514. ((pobjectdef(p^.left^.resulttype)^.options and oois_class)=0) then
  4515. Message(sym_e_type_mismatch);
  4516. p^.registersfpu:=p^.left^.registersfpu;
  4517. p^.registers32:=p^.left^.registers32;
  4518. {$ifdef SUPPORT_MMX}
  4519. p^.registersmmx:=p^.left^.registersmmx;
  4520. {$endif SUPPORT_MMX}
  4521. if assigned(p^.right) then
  4522. begin
  4523. firstpass(p^.right);
  4524. p^.right:=gentypeconvnode(p^.right,s32bitdef);
  4525. firstpass(p^.right);
  4526. left_right_max(p);
  4527. end;
  4528. end;
  4529. end;
  4530. procedure firstwith(var p : ptree);
  4531. begin
  4532. if assigned(p^.left) and assigned(p^.right) then
  4533. begin
  4534. firstpass(p^.left);
  4535. if codegenerror then
  4536. exit;
  4537. firstpass(p^.right);
  4538. if codegenerror then
  4539. exit;
  4540. left_right_max(p);
  4541. p^.resulttype:=voiddef;
  4542. end
  4543. else
  4544. begin
  4545. { optimization }
  4546. disposetree(p);
  4547. p:=nil;
  4548. end;
  4549. end;
  4550. procedure firstonn(var p : ptree);
  4551. begin
  4552. { that's really an example procedure for a firstpass :) }
  4553. cleartempgen;
  4554. p^.resulttype:=voiddef;
  4555. p^.registers32:=0;
  4556. p^.registersfpu:=0;
  4557. {$ifdef SUPPORT_MMX}
  4558. p^.registersmmx:=0;
  4559. {$endif SUPPORT_MMX}
  4560. if assigned(p^.left) then
  4561. begin
  4562. firstpass(p^.left);
  4563. p^.registers32:=p^.left^.registers32;
  4564. p^.registersfpu:=p^.left^.registersfpu;
  4565. {$ifdef SUPPORT_MMX}
  4566. p^.registersmmx:=p^.left^.registersmmx;
  4567. {$endif SUPPORT_MMX}
  4568. end;
  4569. cleartempgen;
  4570. if assigned(p^.right) then
  4571. begin
  4572. firstpass(p^.right);
  4573. p^.registers32:=max(p^.registers32,p^.right^.registers32);
  4574. p^.registersfpu:=max(p^.registersfpu,p^.right^.registersfpu);
  4575. {$ifdef SUPPORT_MMX}
  4576. p^.registersmmx:=max(p^.registersmmx,p^.right^.registersmmx);
  4577. {$endif SUPPORT_MMX}
  4578. end;
  4579. end;
  4580. procedure firstprocinline(var p : ptree);
  4581. begin
  4582. {left contains the code in tree form }
  4583. { but it has already been firstpassed }
  4584. { so firstpass(p^.left); does not seem required }
  4585. { might be required later if we change the arg handling !! }
  4586. end;
  4587. type
  4588. firstpassproc = procedure(var p : ptree);
  4589. procedure firstpass(var p : ptree);
  4590. (* ttreetyp = (addn, {Represents the + operator.}
  4591. muln, {Represents the * operator.}
  4592. subn, {Represents the - operator.}
  4593. divn, {Represents the div operator.}
  4594. symdifn, {Represents the >< operator.}
  4595. modn, {Represents the mod operator.}
  4596. assignn, {Represents an assignment.}
  4597. loadn, {Represents the use of a variabele.}
  4598. rangen, {Represents a range (i.e. 0..9).}
  4599. ltn, {Represents the < operator.}
  4600. lten, {Represents the <= operator.}
  4601. gtn, {Represents the > operator.}
  4602. gten, {Represents the >= operator.}
  4603. equaln, {Represents the = operator.}
  4604. unequaln, {Represents the <> operator.}
  4605. inn, {Represents the in operator.}
  4606. orn, {Represents the or operator.}
  4607. xorn, {Represents the xor operator.}
  4608. shrn, {Represents the shr operator.}
  4609. shln, {Represents the shl operator.}
  4610. slashn, {Represents the / operator.}
  4611. andn, {Represents the and operator.}
  4612. subscriptn, {??? Field in a record/object?}
  4613. derefn, {Dereferences a pointer.}
  4614. addrn, {Represents the @ operator.}
  4615. doubleaddrn, {Represents the @@ operator.}
  4616. ordconstn, {Represents an ordinal value.}
  4617. typeconvn, {Represents type-conversion/typecast.}
  4618. calln, {Represents a call node.}
  4619. callparan, {Represents a parameter.}
  4620. realconstn, {Represents a real value.}
  4621. fixconstn, {Represents a fixed value.}
  4622. umminusn, {Represents a sign change (i.e. -2).}
  4623. asmn, {Represents an assembler node }
  4624. vecn, {Represents array indexing.}
  4625. stringconstn, {Represents a string constant.}
  4626. funcretn, {Represents the function result var.}
  4627. selfn, {Represents the self parameter.}
  4628. notn, {Represents the not operator.}
  4629. inlinen, {Internal procedures (i.e. writeln).}
  4630. niln, {Represents the nil pointer.}
  4631. errorn, {This part of the tree could not be
  4632. parsed because of a compiler error.}
  4633. typen, {A type name. Used for i.e. typeof(obj).}
  4634. hnewn, {The new operation, constructor call.}
  4635. hdisposen, {The dispose operation with destructor call.}
  4636. newn, {The new operation, constructor call.}
  4637. simpledisposen, {The dispose operation.}
  4638. setelen, {A set element (i.e. [a,b]).}
  4639. setconstrn, {A set constant (i.e. [1,2]).}
  4640. blockn, {A block of statements.}
  4641. statementn, {One statement in list of nodes.}
  4642. loopn, { used in genloopnode, must be converted }
  4643. ifn, {An if statement.}
  4644. breakn, {A break statement.}
  4645. continuen, {A continue statement.}
  4646. repeatn, {A repeat until block.}
  4647. whilen, {A while do statement.}
  4648. forn, {A for loop.}
  4649. exitn, {An exit statement.}
  4650. withn, {A with statement.}
  4651. casen, {A case statement.}
  4652. labeln, {A label.}
  4653. goton, {A goto statement.}
  4654. simplenewn, {The new operation.}
  4655. tryexceptn, {A try except block.}
  4656. raisen, {A raise statement.}
  4657. switchesn, {??? Currently unused...}
  4658. tryfinallyn, {A try finally statement.}
  4659. isn, {Represents the is operator.}
  4660. asn, {Represents the as typecast.}
  4661. caretn, {Represents the ^ operator.}
  4662. failn, {Represents the fail statement.}
  4663. starstarn, {Represents the ** operator exponentiation }
  4664. procinlinen, {Procedures that can be inlined }
  4665. { added for optimizations where we cannot suppress }
  4666. nothingn,
  4667. loadvmtn); {???.} *)
  4668. const
  4669. procedures : array[ttreetyp] of firstpassproc =
  4670. (firstadd,firstadd,firstadd,firstmoddiv,firstadd,
  4671. firstmoddiv,firstassignment,firstload,firstrange,
  4672. firstadd,firstadd,firstadd,firstadd,
  4673. firstadd,firstadd,firstin,firstadd,
  4674. firstadd,firstshlshr,firstshlshr,firstadd,
  4675. firstadd,firstsubscriptn,firstderef,firstaddr,firstdoubleaddr,
  4676. firstordconst,firsttypeconv,firstcalln,firstnothing,
  4677. firstrealconst,firstfixconst,firstumminus,firstasm,firstvecn,
  4678. firststringconst,firstfuncret,firstselfn,
  4679. firstnot,firstinline,firstniln,firsterror,
  4680. firsttypen,firsthnewn,firsthdisposen,firstnewn,
  4681. firstsimplenewdispose,firstnothing,firstsetcons,firstblock,
  4682. firststatement,firstnothing,firstif,firstnothing,
  4683. firstnothing,first_while_repeat,first_while_repeat,firstfor,
  4684. firstexitn,firstwith,firstcase,firstlabel,
  4685. firstgoto,firstsimplenewdispose,firsttryexcept,
  4686. firstraise,firstnothing,firsttryfinally,
  4687. firstonn,firstis,firstas,firstadd,
  4688. firstnothing,firstadd,firstprocinline,firstnothing,firstloadvmt);
  4689. var
  4690. oldcodegenerror : boolean;
  4691. oldlocalswitches : tlocalswitches;
  4692. oldpos : tfileposinfo;
  4693. {$ifdef extdebug}
  4694. str1,str2 : string;
  4695. oldp : ptree;
  4696. not_first : boolean;
  4697. {$endif extdebug}
  4698. begin
  4699. {$ifdef extdebug}
  4700. if (p^.firstpasscount>0) and only_one_pass then
  4701. exit;
  4702. {$endif extdebug}
  4703. oldcodegenerror:=codegenerror;
  4704. oldpos:=aktfilepos;
  4705. oldlocalswitches:=aktlocalswitches;
  4706. {$ifdef extdebug}
  4707. if p^.firstpasscount>0 then
  4708. begin
  4709. move(p^,str1[1],sizeof(ttree));
  4710. str1[0]:=char(sizeof(ttree));
  4711. new(oldp);
  4712. oldp^:=p^;
  4713. not_first:=true;
  4714. end
  4715. else
  4716. not_first:=false;
  4717. {$endif extdebug}
  4718. aktfilepos:=p^.fileinfo;
  4719. aktlocalswitches:=p^.localswitches;
  4720. if not p^.error then
  4721. begin
  4722. codegenerror:=false;
  4723. procedures[p^.treetype](p);
  4724. p^.error:=codegenerror;
  4725. codegenerror:=codegenerror or oldcodegenerror;
  4726. end
  4727. else
  4728. codegenerror:=true;
  4729. {$ifdef extdebug}
  4730. if not_first then
  4731. begin
  4732. { dirty trick to compare two ttree's (PM) }
  4733. move(p^,str2[1],sizeof(ttree));
  4734. str2[0]:=char(sizeof(ttree));
  4735. if str1<>str2 then
  4736. begin
  4737. comment(v_debug,'tree changed after first counting pass '
  4738. +tostr(longint(p^.treetype)));
  4739. compare_trees(oldp,p);
  4740. end;
  4741. dispose(oldp);
  4742. end;
  4743. if count_ref then
  4744. inc(p^.firstpasscount);
  4745. {$endif extdebug}
  4746. aktlocalswitches:=oldlocalswitches;
  4747. aktfilepos:=oldpos;
  4748. end;
  4749. function do_firstpass(var p : ptree) : boolean;
  4750. begin
  4751. codegenerror:=false;
  4752. firstpass(p);
  4753. do_firstpass:=codegenerror;
  4754. end;
  4755. { to be called only for a whole function }
  4756. { to insert code at entry and exit }
  4757. function function_firstpass(var p : ptree) : boolean;
  4758. begin
  4759. codegenerror:=false;
  4760. firstpass(p);
  4761. function_firstpass:=codegenerror;
  4762. end;
  4763. end.
  4764. {
  4765. $Log$
  4766. Revision 1.52 1998-08-10 14:50:08 peter
  4767. + localswitches, moduleswitches, globalswitches splitting
  4768. Revision 1.51 1998/08/10 10:18:29 peter
  4769. + Compiler,Comphook unit which are the new interface units to the
  4770. compiler
  4771. Revision 1.50 1998/08/08 21:51:39 peter
  4772. * small crash prevent is firstassignment
  4773. Revision 1.49 1998/07/30 16:07:08 florian
  4774. * try ... expect <statement> end; works now
  4775. Revision 1.48 1998/07/30 13:30:35 florian
  4776. * final implemenation of exception support, maybe it needs
  4777. some fixes :)
  4778. Revision 1.47 1998/07/30 11:18:17 florian
  4779. + first implementation of try ... except on .. do end;
  4780. * limitiation of 65535 bytes parameters for cdecl removed
  4781. Revision 1.46 1998/07/28 21:52:52 florian
  4782. + implementation of raise and try..finally
  4783. + some misc. exception stuff
  4784. Revision 1.45 1998/07/26 21:58:59 florian
  4785. + better support for switch $H
  4786. + index access to ansi strings added
  4787. + assigment of data (records/arrays) containing ansi strings
  4788. Revision 1.44 1998/07/24 22:16:59 florian
  4789. * internal error 10 together with array access fixed. I hope
  4790. that's the final fix.
  4791. Revision 1.43 1998/07/20 18:40:14 florian
  4792. * handling of ansi string constants should now work
  4793. Revision 1.42 1998/07/20 10:23:01 florian
  4794. * better ansi string assignement
  4795. Revision 1.41 1998/07/18 22:54:27 florian
  4796. * some ansi/wide/longstring support fixed:
  4797. o parameter passing
  4798. o returning as result from functions
  4799. Revision 1.40 1998/07/18 17:11:09 florian
  4800. + ansi string constants fixed
  4801. + switch $H partial implemented
  4802. Revision 1.39 1998/07/14 21:46:47 peter
  4803. * updated messages file
  4804. Revision 1.38 1998/07/14 14:46:50 peter
  4805. * released NEWINPUT
  4806. Revision 1.37 1998/07/07 12:31:44 peter
  4807. * fixed string:= which allowed almost any type
  4808. Revision 1.36 1998/07/07 11:20:00 peter
  4809. + NEWINPUT for a better inputfile and scanner object
  4810. Revision 1.35 1998/06/25 14:04:19 peter
  4811. + internal inc/dec
  4812. Revision 1.34 1998/06/25 08:48:14 florian
  4813. * first version of rtti support
  4814. Revision 1.33 1998/06/16 08:56:24 peter
  4815. + targetcpu
  4816. * cleaner pmodules for newppu
  4817. Revision 1.32 1998/06/14 18:23:57 peter
  4818. * fixed xor bug (from mailinglist)
  4819. Revision 1.31 1998/06/13 00:10:09 peter
  4820. * working browser and newppu
  4821. * some small fixes against crashes which occured in bp7 (but not in
  4822. fpc?!)
  4823. Revision 1.30 1998/06/12 10:32:28 pierre
  4824. * column problem hopefully solved
  4825. + C vars declaration changed
  4826. Revision 1.29 1998/06/09 16:01:44 pierre
  4827. + added procedure directive parsing for procvars
  4828. (accepted are popstack cdecl and pascal)
  4829. + added C vars with the following syntax
  4830. var C calias 'true_c_name';(can be followed by external)
  4831. reason is that you must add the Cprefix
  4832. which is target dependent
  4833. Revision 1.28 1998/06/05 14:37:29 pierre
  4834. * fixes for inline for operators
  4835. * inline procedure more correctly restricted
  4836. Revision 1.27 1998/06/05 00:01:06 florian
  4837. * bugs with assigning related objects and passing objects by reference
  4838. to a procedure
  4839. Revision 1.26 1998/06/04 09:55:39 pierre
  4840. * demangled name of procsym reworked to become independant
  4841. of the mangling scheme
  4842. Revision 1.25 1998/06/03 22:48:57 peter
  4843. + wordbool,longbool
  4844. * rename bis,von -> high,low
  4845. * moved some systemunit loading/creating to psystem.pas
  4846. Revision 1.24 1998/06/02 17:03:01 pierre
  4847. * with node corrected for objects
  4848. * small bugs for SUPPORT_MMX fixed
  4849. Revision 1.23 1998/06/01 16:50:20 peter
  4850. + boolean -> ord conversion
  4851. * fixed ord -> boolean conversion
  4852. Revision 1.22 1998/05/28 17:26:49 peter
  4853. * fixed -R switch, it didn't work after my previous akt/init patch
  4854. * fixed bugs 110,130,136
  4855. Revision 1.21 1998/05/25 17:11:41 pierre
  4856. * firstpasscount bug fixed
  4857. now all is already set correctly the first time
  4858. under EXTDEBUG try -gp to skip all other firstpasses
  4859. it works !!
  4860. * small bug fixes
  4861. - for smallsets with -dTESTSMALLSET
  4862. - some warnings removed (by correcting code !)
  4863. Revision 1.20 1998/05/23 01:21:17 peter
  4864. + aktasmmode, aktoptprocessor, aktoutputformat
  4865. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  4866. + $LIBNAME to set the library name where the unit will be put in
  4867. * splitted cgi386 a bit (codeseg to large for bp7)
  4868. * nasm, tasm works again. nasm moved to ag386nsm.pas
  4869. Revision 1.19 1998/05/20 09:42:34 pierre
  4870. + UseTokenInfo now default
  4871. * unit in interface uses and implementation uses gives error now
  4872. * only one error for unknown symbol (uses lastsymknown boolean)
  4873. the problem came from the label code !
  4874. + first inlined procedures and function work
  4875. (warning there might be allowed cases were the result is still wrong !!)
  4876. * UseBrower updated gives a global list of all position of all used symbols
  4877. with switch -gb
  4878. Revision 1.18 1998/05/11 13:07:55 peter
  4879. + $ifdef NEWPPU for the new ppuformat
  4880. + $define GDB not longer required
  4881. * removed all warnings and stripped some log comments
  4882. * no findfirst/findnext anymore to remove smartlink *.o files
  4883. Revision 1.17 1998/05/06 08:38:43 pierre
  4884. * better position info with UseTokenInfo
  4885. UseTokenInfo greatly simplified
  4886. + added check for changed tree after first time firstpass
  4887. (if we could remove all the cases were it happen
  4888. we could skip all firstpass if firstpasscount > 1)
  4889. Only with ExtDebug
  4890. Revision 1.16 1998/05/01 16:38:45 florian
  4891. * handling of private and protected fixed
  4892. + change_keywords_to_tp implemented to remove
  4893. keywords which aren't supported by tp
  4894. * break and continue are now symbols of the system unit
  4895. + widestring, longstring and ansistring type released
  4896. Revision 1.15 1998/05/01 09:01:23 florian
  4897. + correct semantics of private and protected
  4898. * small fix in variable scope:
  4899. a id can be used in a parameter list of a method, even it is used in
  4900. an anchestor class as field id
  4901. Revision 1.14 1998/04/30 15:59:41 pierre
  4902. * GDB works again better :
  4903. correct type info in one pass
  4904. + UseTokenInfo for better source position
  4905. * fixed one remaining bug in scanner for line counts
  4906. * several little fixes
  4907. Revision 1.13 1998/04/29 10:33:56 pierre
  4908. + added some code for ansistring (not complete nor working yet)
  4909. * corrected operator overloading
  4910. * corrected nasm output
  4911. + started inline procedures
  4912. + added starstarn : use ** for exponentiation (^ gave problems)
  4913. + started UseTokenInfo cond to get accurate positions
  4914. Revision 1.12 1998/04/22 21:06:50 florian
  4915. * last fixes before the release:
  4916. - veryyyy slow firstcall fixed
  4917. Revision 1.11 1998/04/21 10:16:48 peter
  4918. * patches from strasbourg
  4919. * objects is not used anymore in the fpc compiled version
  4920. Revision 1.10 1998/04/14 23:27:03 florian
  4921. + exclude/include with constant second parameter added
  4922. Revision 1.9 1998/04/13 21:15:42 florian
  4923. * error handling of pass_1 and cgi386 fixed
  4924. * the following bugs fixed: 0117, 0118, 0119 and 0129, 0122 was already
  4925. fixed, verified
  4926. Revision 1.8 1998/04/13 08:42:52 florian
  4927. * call by reference and call by value open arrays fixed
  4928. Revision 1.7 1998/04/12 22:39:44 florian
  4929. * problem with read access to properties solved
  4930. * correct handling of hidding methods via virtual (COM)
  4931. * correct result type of constructor calls (COM), the resulttype
  4932. depends now on the type of the class reference
  4933. Revision 1.6 1998/04/09 22:16:34 florian
  4934. * problem with previous REGALLOC solved
  4935. * improved property support
  4936. Revision 1.5 1998/04/08 16:58:04 pierre
  4937. * several bugfixes
  4938. ADD ADC and AND are also sign extended
  4939. nasm output OK (program still crashes at end
  4940. and creates wrong assembler files !!)
  4941. procsym types sym in tdef removed !!
  4942. Revision 1.4 1998/04/07 22:45:04 florian
  4943. * bug0092, bug0115 and bug0121 fixed
  4944. + packed object/class/array
  4945. }