pass_1.pas 212 KB

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