symdef.pas 243 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508
  1. {
  2. Symbol table implementation for the definitions
  3. Copyright (c) 1998-2005 by Florian Klaempfl, Pierre Muller
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit symdef;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. { common }
  22. cclasses,
  23. { global }
  24. globtype,globals,tokens,constexp,
  25. { symtable }
  26. symconst,symbase,symtype,
  27. { ppu }
  28. ppu,
  29. { node }
  30. node,
  31. { aasm }
  32. aasmbase,aasmtai,
  33. {$ifdef jvm}
  34. aasmdata,
  35. {$endif}
  36. cpubase,cpuinfo,
  37. cgbase,
  38. parabase
  39. ;
  40. type
  41. {************************************************
  42. TDef
  43. ************************************************}
  44. tgenericconstraintdata=class
  45. interfaces : tfpobjectlist;
  46. interfacesderef : tfplist;
  47. flags : tgenericconstraintflags;
  48. constructor create;
  49. destructor destroy;override;
  50. procedure ppuload(ppufile:tcompilerppufile);
  51. procedure ppuwrite(ppufile:tcompilerppufile);
  52. procedure buildderef;
  53. procedure deref;
  54. end;
  55. { tstoreddef }
  56. tstoreddef = class(tdef)
  57. private
  58. _fullownerhierarchyname : pshortstring;
  59. protected
  60. typesymderef : tderef;
  61. procedure fillgenericparas(symtable:tsymtable);
  62. public
  63. {$ifdef EXTDEBUG}
  64. fileinfo : tfileposinfo;
  65. {$endif}
  66. { generic support }
  67. genericdef : tstoreddef;
  68. genericdefderef : tderef;
  69. generictokenbuf : tdynamicarray;
  70. { this list contains references to the symbols that make up the
  71. generic parameters; the symbols are not owned by this list
  72. Note: this list is allocated on demand! }
  73. genericparas : tfphashobjectlist;
  74. { contains additional data if this def is a generic constraint
  75. Note: this class is allocated on demand! }
  76. genconstraintdata : tgenericconstraintdata;
  77. constructor create(dt:tdeftyp);
  78. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  79. destructor destroy;override;
  80. function getcopy : tstoreddef;virtual;
  81. procedure ppuwrite(ppufile:tcompilerppufile);virtual;
  82. procedure buildderef;override;
  83. procedure buildderefimpl;override;
  84. procedure deref;override;
  85. procedure derefimpl;override;
  86. function size:asizeint;override;
  87. function getvardef:longint;override;
  88. function alignment:shortint;override;
  89. function is_publishable : boolean;override;
  90. function needs_inittable : boolean;override;
  91. function rtti_mangledname(rt:trttitype):string;override;
  92. function OwnerHierarchyName: string; override;
  93. function fullownerhierarchyname:string;override;
  94. function needs_separate_initrtti:boolean;override;
  95. function in_currentunit: boolean;
  96. { regvars }
  97. function is_intregable : boolean;
  98. function is_fpuregable : boolean;
  99. { def can be put into a register if it is const/immutable }
  100. function is_const_intregable : boolean;
  101. { generics }
  102. procedure initgeneric;
  103. { this function can be used to determine whether a def is really a
  104. generic declaration or just a normal type declared inside another
  105. generic }
  106. function is_generic:boolean;inline;
  107. { same as above for specializations }
  108. function is_specialization:boolean;inline;
  109. private
  110. savesize : asizeuint;
  111. end;
  112. tfiletyp = (ft_text,ft_typed,ft_untyped);
  113. tfiledef = class(tstoreddef)
  114. filetyp : tfiletyp;
  115. typedfiledef : tdef;
  116. typedfiledefderef : tderef;
  117. constructor createtext;
  118. constructor createuntyped;
  119. constructor createtyped(def : tdef);
  120. constructor ppuload(ppufile:tcompilerppufile);
  121. function getcopy : tstoreddef;override;
  122. procedure ppuwrite(ppufile:tcompilerppufile);override;
  123. procedure buildderef;override;
  124. procedure deref;override;
  125. function GetTypeName:string;override;
  126. function getmangledparaname:TSymStr;override;
  127. function size:asizeint;override;
  128. procedure setsize;
  129. end;
  130. tvariantdef = class(tstoreddef)
  131. varianttype : tvarianttype;
  132. constructor create(v : tvarianttype);
  133. constructor ppuload(ppufile:tcompilerppufile);
  134. function getcopy : tstoreddef;override;
  135. function GetTypeName:string;override;
  136. procedure ppuwrite(ppufile:tcompilerppufile);override;
  137. function getvardef:longint;override;
  138. procedure setsize;
  139. function is_publishable : boolean;override;
  140. function needs_inittable : boolean;override;
  141. end;
  142. tformaldef = class(tstoreddef)
  143. typed:boolean;
  144. constructor create(Atyped:boolean);
  145. constructor ppuload(ppufile:tcompilerppufile);
  146. procedure ppuwrite(ppufile:tcompilerppufile);override;
  147. function GetTypeName:string;override;
  148. end;
  149. tforwarddef = class(tstoreddef)
  150. tosymname : pshortstring;
  151. forwardpos : tfileposinfo;
  152. constructor create(const s:string;const pos:tfileposinfo);
  153. destructor destroy;override;
  154. function getcopy:tstoreddef;override;
  155. function GetTypeName:string;override;
  156. end;
  157. tundefineddef = class(tstoreddef)
  158. constructor create;
  159. constructor ppuload(ppufile:tcompilerppufile);
  160. procedure ppuwrite(ppufile:tcompilerppufile);override;
  161. function GetTypeName:string;override;
  162. end;
  163. terrordef = class(tstoreddef)
  164. constructor create;
  165. procedure ppuwrite(ppufile:tcompilerppufile);override;
  166. function GetTypeName:string;override;
  167. function getmangledparaname : TSymStr;override;
  168. end;
  169. tabstractpointerdef = class(tstoreddef)
  170. pointeddef : tdef;
  171. pointeddefderef : tderef;
  172. constructor create(dt:tdeftyp;def:tdef);
  173. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  174. procedure ppuwrite(ppufile:tcompilerppufile);override;
  175. procedure buildderef;override;
  176. procedure deref;override;
  177. end;
  178. { tpointerdef }
  179. tpointerdef = class(tabstractpointerdef)
  180. {$ifdef x86}
  181. x86pointertyp : tx86pointertyp;
  182. {$endif x86}
  183. has_pointer_math : boolean;
  184. constructor create(def:tdef);
  185. {$ifdef x86}
  186. constructor createx86(def:tdef;x86typ:tx86pointertyp);
  187. {$endif x86}
  188. function size:asizeint;override;
  189. function getcopy:tstoreddef;override;
  190. constructor ppuload(ppufile:tcompilerppufile);
  191. procedure ppuwrite(ppufile:tcompilerppufile);override;
  192. function GetTypeName:string;override;
  193. end;
  194. tprocdef = class;
  195. tabstractrecorddef= class(tstoreddef)
  196. objname,
  197. objrealname : PShortString;
  198. { for C++ classes: name of the library this class is imported from }
  199. { for Java classes/records: package name }
  200. import_lib : PShortString;
  201. symtable : TSymtable;
  202. cloneddef : tabstractrecorddef;
  203. cloneddefderef : tderef;
  204. objectoptions : tobjectoptions;
  205. { for targets that initialise typed constants via explicit assignments
  206. instead of by generating an initialised data sectino }
  207. tcinitcode : tnode;
  208. constructor create(const n:string; dt:tdeftyp);
  209. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  210. procedure ppuwrite(ppufile:tcompilerppufile);override;
  211. destructor destroy; override;
  212. procedure check_forwards; virtual;
  213. function find_procdef_bytype(pt:tproctypeoption): tprocdef;
  214. function GetSymtable(t:tGetSymtable):TSymtable;override;
  215. function is_packed:boolean;
  216. function RttiName: string;
  217. { enumerator support }
  218. function search_enumerator_get: tprocdef; virtual;
  219. function search_enumerator_move: tprocdef; virtual;
  220. function search_enumerator_current: tsym; virtual;
  221. { JVM }
  222. function jvm_full_typename(with_package_name: boolean): string;
  223. { check if the symtable contains a float field }
  224. function contains_float_field : boolean;
  225. end;
  226. pvariantrecdesc = ^tvariantrecdesc;
  227. tvariantrecbranch = record
  228. { we store only single values here and no ranges because tvariantrecdesc is only needed in iso mode
  229. which does not support range expressions in variant record definitions }
  230. values : array of Tconstexprint;
  231. nestedvariant : pvariantrecdesc;
  232. end;
  233. ppvariantrecdesc = ^pvariantrecdesc;
  234. tvariantrecdesc = record
  235. variantselector : tsym;
  236. variantselectorderef : tderef;
  237. branches : array of tvariantrecbranch;
  238. end;
  239. trecorddef = class(tabstractrecorddef)
  240. public
  241. variantrecdesc : pvariantrecdesc;
  242. isunion : boolean;
  243. constructor create(const n:string; p:TSymtable);
  244. constructor ppuload(ppufile:tcompilerppufile);
  245. destructor destroy;override;
  246. function getcopy : tstoreddef;override;
  247. procedure ppuwrite(ppufile:tcompilerppufile);override;
  248. procedure buildderef;override;
  249. procedure buildderefimpl;override;
  250. procedure deref;override;
  251. function size:asizeint;override;
  252. function alignment : shortint;override;
  253. function padalignment: shortint;
  254. function GetTypeName:string;override;
  255. { debug }
  256. function needs_inittable : boolean;override;
  257. function needs_separate_initrtti:boolean;override;
  258. end;
  259. tobjectdef = class;
  260. { TImplementedInterface }
  261. TImplementedInterface = class
  262. private
  263. fIOffset : longint;
  264. function GetIOffset: longint;
  265. public
  266. IntfDef : tobjectdef;
  267. IntfDefDeref : tderef;
  268. IType : tinterfaceentrytype;
  269. VtblImplIntf : TImplementedInterface;
  270. NameMappings : TFPHashList;
  271. ProcDefs : TFPObjectList;
  272. ImplementsGetter : tsym;
  273. ImplementsGetterDeref : tderef;
  274. ImplementsField : tsym;
  275. constructor create(aintf: tobjectdef);
  276. constructor create_deref(intfd,getterd:tderef);
  277. destructor destroy; override;
  278. function getcopy:TImplementedInterface;
  279. procedure buildderef;
  280. procedure deref;
  281. procedure AddMapping(const origname, newname: string);
  282. function GetMapping(const origname: string):string;
  283. procedure AddImplProc(pd:tprocdef);
  284. function IsImplMergePossible(MergingIntf:TImplementedInterface;out weight: longint): boolean;
  285. property IOffset: longint read GetIOffset write fIOffset;
  286. end;
  287. { tvmtentry }
  288. tvmtentry = record
  289. procdef : tprocdef;
  290. procdefderef : tderef;
  291. visibility : tvisibility;
  292. end;
  293. pvmtentry = ^tvmtentry;
  294. { tobjectdef }
  295. tvmcallstatic = (vmcs_default, vmcs_yes, vmcs_no, vmcs_unreachable);
  296. pmvcallstaticinfo = ^tmvcallstaticinfo;
  297. tmvcallstaticinfo = array[0..1024*1024-1] of tvmcallstatic;
  298. tobjectdef = class(tabstractrecorddef)
  299. private
  300. fcurrent_dispid: longint;
  301. public
  302. dwarf_struct_lab : tasmsymbol;
  303. childof : tobjectdef;
  304. childofderef : tderef;
  305. { for Object Pascal helpers }
  306. extendeddef : tdef;
  307. extendeddefderef: tderef;
  308. { for Objective-C: protocols and classes can have the same name there }
  309. objextname : pshortstring;
  310. { to be able to have a variable vmt position }
  311. { and no vmt field for objects without virtuals }
  312. vmtentries : TFPList;
  313. vmcallstaticinfo : pmvcallstaticinfo;
  314. vmt_offset : longint;
  315. iidguid : pguid;
  316. iidstr : pshortstring;
  317. { store implemented interfaces defs and name mappings }
  318. ImplementedInterfaces : TFPObjectList;
  319. { number of abstract methods (used by JVM target to determine whether
  320. or not the class should be marked as abstract: must be done if 1 or
  321. more abstract methods) }
  322. abstractcnt : longint;
  323. writing_class_record_dbginfo,
  324. { a class of this type has been created in this module }
  325. created_in_current_module,
  326. { a loadvmtnode for this class has been created in this
  327. module, so if a classrefdef variable of this or a parent
  328. class is used somewhere to instantiate a class, then this
  329. class may be instantiated
  330. }
  331. maybe_created_in_current_module,
  332. { a "class of" this particular class has been created in
  333. this module
  334. }
  335. classref_created_in_current_module : boolean;
  336. objecttype : tobjecttyp;
  337. constructor create(ot:tobjecttyp;const n:string;c:tobjectdef);
  338. constructor ppuload(ppufile:tcompilerppufile);
  339. destructor destroy;override;
  340. function getcopy : tstoreddef;override;
  341. procedure ppuwrite(ppufile:tcompilerppufile);override;
  342. function GetTypeName:string;override;
  343. procedure buildderef;override;
  344. procedure deref;override;
  345. procedure buildderefimpl;override;
  346. procedure derefimpl;override;
  347. procedure resetvmtentries;
  348. procedure copyvmtentries(objdef:tobjectdef);
  349. function getparentdef:tdef;override;
  350. function size : asizeint;override;
  351. function alignment:shortint;override;
  352. function vmtmethodoffset(index:longint):longint;
  353. function members_need_inittable : boolean;
  354. { this should be called when this class implements an interface }
  355. procedure prepareguid;
  356. function is_publishable : boolean;override;
  357. function needs_inittable : boolean;override;
  358. function needs_separate_initrtti : boolean;override;
  359. function rtti_mangledname(rt:trttitype):string;override;
  360. function vmt_mangledname : TSymStr;
  361. procedure check_forwards; override;
  362. procedure insertvmt;
  363. procedure set_parent(c : tobjectdef);
  364. function find_destructor: tprocdef;
  365. function implements_any_interfaces: boolean;
  366. { dispinterface support }
  367. function get_next_dispid: longint;
  368. { enumerator support }
  369. function search_enumerator_get: tprocdef; override;
  370. function search_enumerator_move: tprocdef; override;
  371. function search_enumerator_current: tsym; override;
  372. { WPO }
  373. procedure register_created_object_type;override;
  374. procedure register_maybe_created_object_type;
  375. procedure register_created_classref_type;
  376. procedure register_vmt_call(index:longint);
  377. { ObjC }
  378. procedure finish_objc_data;
  379. function check_objc_types: boolean;
  380. { C++ }
  381. procedure finish_cpp_data;
  382. end;
  383. tclassrefdef = class(tabstractpointerdef)
  384. constructor create(def:tdef);
  385. constructor ppuload(ppufile:tcompilerppufile);
  386. procedure ppuwrite(ppufile:tcompilerppufile);override;
  387. function getcopy:tstoreddef;override;
  388. function GetTypeName:string;override;
  389. function is_publishable : boolean;override;
  390. function rtti_mangledname(rt:trttitype):string;override;
  391. procedure register_created_object_type;override;
  392. end;
  393. tarraydef = class(tstoreddef)
  394. lowrange,
  395. highrange : asizeint;
  396. rangedef : tdef;
  397. rangedefderef : tderef;
  398. arrayoptions : tarraydefoptions;
  399. symtable : TSymtable;
  400. protected
  401. _elementdef : tdef;
  402. _elementdefderef : tderef;
  403. procedure setelementdef(def:tdef);
  404. public
  405. function elesize : asizeint;
  406. function elepackedbitsize : asizeint;
  407. function elecount : asizeuint;
  408. constructor create_from_pointer(def:tdef);
  409. constructor create(l,h:asizeint;def:tdef);
  410. constructor ppuload(ppufile:tcompilerppufile);
  411. destructor destroy; override;
  412. function getcopy : tstoreddef;override;
  413. procedure ppuwrite(ppufile:tcompilerppufile);override;
  414. function GetTypeName:string;override;
  415. function getmangledparaname : TSymStr;override;
  416. procedure buildderef;override;
  417. procedure deref;override;
  418. function size : asizeint;override;
  419. function alignment : shortint;override;
  420. { returns the label of the range check string }
  421. function needs_inittable : boolean;override;
  422. function needs_separate_initrtti : boolean;override;
  423. property elementdef : tdef read _elementdef write setelementdef;
  424. function is_publishable : boolean;override;
  425. end;
  426. torddef = class(tstoreddef)
  427. low,high : TConstExprInt;
  428. ordtype : tordtype;
  429. constructor create(t : tordtype;v,b : TConstExprInt);
  430. constructor ppuload(ppufile:tcompilerppufile);
  431. function getcopy : tstoreddef;override;
  432. procedure ppuwrite(ppufile:tcompilerppufile);override;
  433. function is_publishable : boolean;override;
  434. function GetTypeName:string;override;
  435. function alignment:shortint;override;
  436. procedure setsize;
  437. function packedbitsize: asizeint; override;
  438. function getvardef : longint;override;
  439. end;
  440. tfloatdef = class(tstoreddef)
  441. floattype : tfloattype;
  442. constructor create(t : tfloattype);
  443. constructor ppuload(ppufile:tcompilerppufile);
  444. function getcopy : tstoreddef;override;
  445. procedure ppuwrite(ppufile:tcompilerppufile);override;
  446. function GetTypeName:string;override;
  447. function is_publishable : boolean;override;
  448. function alignment:shortint;override;
  449. function structalignment: shortint;override;
  450. procedure setsize;
  451. function getvardef:longint;override;
  452. end;
  453. { tabstractprocdef }
  454. tprocnameoption = (pno_showhidden, pno_proctypeoption, pno_paranames,
  455. pno_ownername, pno_noclassmarker, pno_noleadingdollar);
  456. tprocnameoptions = set of tprocnameoption;
  457. tproccopytyp = (pc_normal,
  458. { always creates a top-level function, removes all
  459. special parameters (self, vmt, parentfp, ...) }
  460. pc_bareproc
  461. );
  462. tabstractprocdef = class(tstoreddef)
  463. { saves a definition to the return type }
  464. returndef : tdef;
  465. returndefderef : tderef;
  466. parast : TSymtable;
  467. paras : tparalist;
  468. proctypeoption : tproctypeoption;
  469. proccalloption : tproccalloption;
  470. procoptions : tprocoptions;
  471. callerargareasize,
  472. calleeargareasize: pint;
  473. {$ifdef m68k}
  474. exp_funcretloc : tregister; { explicit funcretloc for AmigaOS }
  475. {$endif}
  476. funcretloc : array[tcallercallee] of TCGPara;
  477. has_paraloc_info : tcallercallee; { paraloc info is available }
  478. { number of user visible parameters }
  479. maxparacount,
  480. minparacount : byte;
  481. constructor create(dt:tdeftyp;level:byte);
  482. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  483. destructor destroy;override;
  484. procedure ppuwrite(ppufile:tcompilerppufile);override;
  485. procedure buildderef;override;
  486. procedure deref;override;
  487. procedure calcparas;
  488. function typename_paras(pno: tprocnameoptions): ansistring;
  489. function is_methodpointer:boolean;virtual;
  490. function is_addressonly:boolean;virtual;
  491. function no_self_node:boolean;
  492. { get either a copy as a procdef or procvardef }
  493. function getcopyas(newtyp:tdeftyp;copytyp:tproccopytyp): tstoreddef; virtual;
  494. procedure check_mark_as_nested;
  495. procedure init_paraloc_info(side: tcallercallee);
  496. function stack_tainting_parameter(side: tcallercallee): boolean;
  497. function is_pushleftright: boolean;
  498. function address_type:tdef;
  499. private
  500. procedure count_para(p:TObject;arg:pointer);
  501. procedure insert_para(p:TObject;arg:pointer);
  502. end;
  503. tprocvardef = class(tabstractprocdef)
  504. {$ifdef jvm}
  505. { class representing this procvar on the Java side }
  506. classdef : tobjectdef;
  507. classdefderef : tderef;
  508. {$endif}
  509. constructor create(level:byte);
  510. constructor ppuload(ppufile:tcompilerppufile);
  511. function getcopy : tstoreddef;override;
  512. procedure ppuwrite(ppufile:tcompilerppufile);override;
  513. {$ifdef jvm}
  514. procedure buildderef;override;
  515. procedure deref;override;
  516. {$endif}
  517. function GetSymtable(t:tGetSymtable):TSymtable;override;
  518. function size : asizeint;override;
  519. function GetTypeName:string;override;
  520. function is_publishable : boolean;override;
  521. function is_methodpointer:boolean;override;
  522. function is_addressonly:boolean;override;
  523. function getmangledparaname:TSymStr;override;
  524. end;
  525. tmessageinf = record
  526. case integer of
  527. 0 : (str : pshortstring);
  528. 1 : (i : longint);
  529. end;
  530. tinlininginfo = record
  531. { node tree }
  532. code : tnode;
  533. flags : tprocinfoflags;
  534. end;
  535. pinlininginfo = ^tinlininginfo;
  536. {$ifdef oldregvars}
  537. { register variables }
  538. pregvarinfo = ^tregvarinfo;
  539. tregvarinfo = record
  540. regvars : array[1..maxvarregs] of tsym;
  541. regvars_para : array[1..maxvarregs] of boolean;
  542. regvars_refs : array[1..maxvarregs] of longint;
  543. fpuregvars : array[1..maxfpuvarregs] of tsym;
  544. fpuregvars_para : array[1..maxfpuvarregs] of boolean;
  545. fpuregvars_refs : array[1..maxfpuvarregs] of longint;
  546. end;
  547. {$endif oldregvars}
  548. timplprocdefinfo = record
  549. resultname : pshortstring;
  550. parentfpstruct: tsym;
  551. parentfpstructptrtype: tdef;
  552. parentfpinitblock: tnode;
  553. procstarttai,
  554. procendtai : tai;
  555. skpara: pointer;
  556. forwarddef,
  557. interfacedef : boolean;
  558. hasforward : boolean;
  559. end;
  560. pimplprocdefinfo = ^timplprocdefinfo;
  561. { tprocdef }
  562. tprocdef = class(tabstractprocdef)
  563. private
  564. {$ifdef symansistr}
  565. _mangledname : ansistring;
  566. {$else symansistr}
  567. _mangledname : pshortstring;
  568. {$endif}
  569. { information that is only required until the implementation of the
  570. procdef has been handled }
  571. implprocdefinfo : pimplprocdefinfo;
  572. function GetResultName: PShortString;
  573. procedure SetResultName(AValue: PShortString);
  574. function GetParentFPStruct: tsym;
  575. procedure SetParentFPStruct(AValue: tsym);
  576. function GetParentFPStructPtrType: tdef;
  577. procedure SetParentFPStructPtrType(AValue: tdef);
  578. function GetParentFPInitBlock: tnode;
  579. procedure SetParentFPInitBlock(AValue: tnode);
  580. function Getprocstarttai: tai;
  581. procedure Setprocstarttai(AValue: tai);
  582. function Getprocendtai: tai;
  583. procedure Setprocendtai(AValue: tai);
  584. function Getskpara: pointer;
  585. procedure Setskpara(AValue: pointer);
  586. function Getforwarddef: boolean;
  587. procedure Setforwarddef(AValue: boolean);
  588. function Getinterfacedef: boolean;
  589. procedure Setinterfacedef(AValue: boolean);
  590. function Gethasforward: boolean;
  591. procedure Sethasforward(AValue: boolean);
  592. public
  593. messageinf : tmessageinf;
  594. dispid : longint;
  595. {$ifndef EXTDEBUG}
  596. { where is this function defined and what were the symbol
  597. flags, needed here because there
  598. is only one symbol for all overloaded functions
  599. EXTDEBUG has fileinfo in tdef (PFV) }
  600. fileinfo : tfileposinfo;
  601. {$endif}
  602. symoptions : tsymoptions;
  603. deprecatedmsg : pshortstring;
  604. { symbol owning this definition }
  605. procsym : tsym;
  606. procsymderef : tderef;
  607. { alias names }
  608. aliasnames : TCmdStrList;
  609. { symtables }
  610. localst : TSymtable;
  611. funcretsym : tsym;
  612. funcretsymderef : tderef;
  613. struct : tabstractrecorddef;
  614. structderef : tderef;
  615. {$if defined(powerpc) or defined(m68k)}
  616. { library symbol for AmigaOS/MorphOS }
  617. libsym : tsym;
  618. libsymderef : tderef;
  619. {$endif powerpc or m68k}
  620. { import info }
  621. import_dll,
  622. import_name : pshortstring;
  623. { info for inlining the subroutine, if this pointer is nil,
  624. the procedure can't be inlined }
  625. inlininginfo : pinlininginfo;
  626. {$ifdef jvm}
  627. { generated assembler code; used by JVM backend so it can afterwards
  628. easily write out all methods grouped per class }
  629. exprasmlist : TAsmList;
  630. {$endif jvm}
  631. {$ifdef oldregvars}
  632. regvarinfo: pregvarinfo;
  633. {$endif oldregvars}
  634. import_nr : word;
  635. extnumber : word;
  636. {$if defined(i386) or defined(i8086)}
  637. fpu_used : byte;
  638. {$endif i386 or i8086}
  639. {$if defined(arm)}
  640. { the arm paramanager might need to know the total size of the stackframe
  641. to avoid cyclic unit dependencies or global variables, this infomatation is
  642. stored in total_stackframe_size }
  643. total_stackframe_size : aint;
  644. {$endif defined(arm)}
  645. {$ifdef mips}
  646. { needed for stabs debugging }
  647. total_local_size : longint;
  648. {$endif mips}
  649. visibility : tvisibility;
  650. { set to a value different from tsk_none in case this procdef is for
  651. a routine that has to be internally generated by the compiler }
  652. synthetickind : tsynthetickind;
  653. { true, if the procedure contains no code }
  654. isempty: boolean;
  655. constructor create(level:byte);
  656. constructor ppuload(ppufile:tcompilerppufile);
  657. destructor destroy;override;
  658. procedure ppuwrite(ppufile:tcompilerppufile);override;
  659. procedure buildderef;override;
  660. procedure buildderefimpl;override;
  661. procedure deref;override;
  662. procedure derefimpl;override;
  663. function GetSymtable(t:tGetSymtable):TSymtable;override;
  664. { warnings:
  665. * the symtablestack top has to be the symtable to which the copy
  666. should be added
  667. * getcopy does not create a finished/ready-to-use procdef; it
  668. needs to be finalised afterwards by calling
  669. symcreat.finish_copied_procdef() afterwards
  670. }
  671. function getcopyas(newtyp:tdeftyp;copytyp:tproccopytyp): tstoreddef; override;
  672. function getcopy: tstoreddef; override;
  673. function GetTypeName : string;override;
  674. function mangledname : TSymStr;
  675. procedure setmangledname(const s : TSymStr);
  676. function fullprocname(showhidden:boolean):string;
  677. function customprocname(pno: tprocnameoptions):ansistring;
  678. function defaultmangledname: TSymStr;
  679. function cplusplusmangledname : TSymStr;
  680. function objcmangledname : TSymStr;
  681. {$ifdef jvm}
  682. function jvmmangledbasename(signature: boolean): TSymStr;
  683. {$endif}
  684. function is_methodpointer:boolean;override;
  685. function is_addressonly:boolean;override;
  686. procedure make_external;
  687. { aliases to fields only required when a function is implemented in
  688. the current unit }
  689. property resultname: PShortString read GetResultName write SetResultName;
  690. { temporary reference to structure containing copies of all local
  691. variables and parameters accessed by nested routines; reference to
  692. this structure is passed as "parent frame pointer" on targets that
  693. lack this concept (at least JVM and LLVM); no need to save to/
  694. restore from ppu, since nested routines are always in the same
  695. unit }
  696. property parentfpstruct: tsym read GetParentFPStruct write SetParentFPStruct;
  697. { pointer to parentfpstruct's type (not yet valid during parsing, so
  698. cannot be used for $parentfp parameter) (no need to save to ppu) }
  699. property parentfpstructptrtype: tdef read GetParentFPStructPtrType write SetParentFPStructPtrType;
  700. { code to copy the parameters accessed from nested routines into the
  701. parentfpstruct (no need to save to ppu) }
  702. property parentfpinitblock: tnode read GetParentFPInitBlock write SetParentFPInitBlock;
  703. { First/last assembler symbol/instruction in aasmoutput list.
  704. Note: initialised after compiling the code for the procdef, but
  705. not saved to/restored from ppu. Used when inserting debug info }
  706. property procstarttai: tai read Getprocstarttai write Setprocstarttai;
  707. property procendtai: tai read Getprocendtai write Setprocendtai;
  708. { optional parameter for the synthetic routine generation logic }
  709. property skpara: pointer read Getskpara write Setskpara;
  710. { true, if the procedure is only declared
  711. (forward procedure) }
  712. property forwarddef: boolean read Getforwarddef write Setforwarddef;
  713. { true if the procedure is declared in the interface }
  714. property interfacedef: boolean read Getinterfacedef write Setinterfacedef;
  715. { true if the procedure has a forward declaration }
  716. property hasforward: boolean read Gethasforward write Sethasforward;
  717. end;
  718. { single linked list of overloaded procs }
  719. pprocdeflist = ^tprocdeflist;
  720. tprocdeflist = record
  721. def : tprocdef;
  722. defderef : tderef;
  723. next : pprocdeflist;
  724. end;
  725. tstringdef = class(tstoreddef)
  726. encoding : tstringencoding;
  727. stringtype : tstringtype;
  728. len : asizeint;
  729. constructor createshort(l : byte);
  730. constructor loadshort(ppufile:tcompilerppufile);
  731. constructor createlong(l : asizeint);
  732. constructor loadlong(ppufile:tcompilerppufile);
  733. constructor createansi(aencoding:tstringencoding);
  734. constructor loadansi(ppufile:tcompilerppufile);
  735. constructor createwide;
  736. constructor loadwide(ppufile:tcompilerppufile);
  737. constructor createunicode;
  738. constructor loadunicode(ppufile:tcompilerppufile);
  739. function getcopy : tstoreddef;override;
  740. function stringtypname:string;
  741. procedure ppuwrite(ppufile:tcompilerppufile);override;
  742. function GetTypeName:string;override;
  743. function getmangledparaname:TSymStr;override;
  744. function is_publishable : boolean;override;
  745. function alignment : shortint;override;
  746. function needs_inittable : boolean;override;
  747. function getvardef:longint;override;
  748. end;
  749. { tenumdef }
  750. tenumdef = class(tstoreddef)
  751. minval,
  752. maxval : asizeint;
  753. basedef : tenumdef;
  754. basedefderef : tderef;
  755. symtable : TSymtable;
  756. {$ifdef jvm}
  757. { class representing this enum on the Java side }
  758. classdef : tobjectdef;
  759. classdefderef : tderef;
  760. {$endif}
  761. has_jumps : boolean;
  762. constructor create;
  763. constructor create_subrange(_basedef:tenumdef;_min,_max:asizeint);
  764. constructor ppuload(ppufile:tcompilerppufile);
  765. destructor destroy;override;
  766. function getcopy : tstoreddef;override;
  767. procedure ppuwrite(ppufile:tcompilerppufile);override;
  768. procedure buildderef;override;
  769. procedure deref;override;
  770. function GetTypeName:string;override;
  771. function is_publishable : boolean;override;
  772. procedure calcsavesize;
  773. function packedbitsize: asizeint; override;
  774. procedure setmax(_max:asizeint);
  775. procedure setmin(_min:asizeint);
  776. function min:asizeint;
  777. function max:asizeint;
  778. function getfirstsym:tsym;
  779. function int2enumsym(l: asizeint): tsym;
  780. { returns basedef if assigned, otherwise self }
  781. function getbasedef: tenumdef;
  782. end;
  783. tsetdef = class(tstoreddef)
  784. elementdef : tdef;
  785. elementdefderef : tderef;
  786. setbase,
  787. setmax : aword;
  788. constructor create(def:tdef;low, high : asizeint);
  789. constructor ppuload(ppufile:tcompilerppufile);
  790. function getcopy : tstoreddef;override;
  791. procedure ppuwrite(ppufile:tcompilerppufile);override;
  792. procedure buildderef;override;
  793. procedure deref;override;
  794. function GetTypeName:string;override;
  795. function is_publishable : boolean;override;
  796. end;
  797. tgenericdummyentry = class
  798. dummysym : tsym;
  799. resolvedsym : tsym;
  800. end;
  801. tdefawaresymtablestack = class(TSymtablestack)
  802. private
  803. procedure add_helpers_and_generics(st:tsymtable;addgenerics:boolean);
  804. procedure remove_helpers_and_generics(st:tsymtable);inline;
  805. procedure remove_helpers(st:tsymtable);
  806. procedure remove_generics(st:tsymtable);
  807. procedure pushcommon(st:tsymtable);inline;
  808. public
  809. procedure push(st: TSymtable); override;
  810. procedure pushafter(st,afterst:TSymtable); override;
  811. procedure pop(st: TSymtable); override;
  812. end;
  813. var
  814. current_structdef: tabstractrecorddef; { used for private functions check !! }
  815. current_genericdef: tstoreddef; { used to reject declaration of generic class inside generic class }
  816. current_specializedef: tstoreddef; { used to implement usage of generic class in itself }
  817. { default types }
  818. generrordef, { error in definition }
  819. voidpointertype, { pointer for Void-pointeddef }
  820. charpointertype, { pointer for Char-pointeddef }
  821. widecharpointertype, { pointer for WideChar-pointeddef }
  822. parentfpvoidpointertype, { void pointer with the size of the hidden parentfp parameter, passed to nested functions }
  823. {$ifdef x86}
  824. voidnearpointertype,
  825. voidnearcspointertype,
  826. voidneardspointertype,
  827. voidnearsspointertype,
  828. voidnearespointertype,
  829. voidnearfspointertype,
  830. voidneargspointertype,
  831. {$ifdef i8086}
  832. voidfarpointertype,
  833. voidhugepointertype,
  834. bytefarpointertype, { used for Mem[] }
  835. wordfarpointertype, { used for MemW[] }
  836. longintfarpointertype, { used for MemL[] }
  837. {$endif i8086}
  838. {$endif x86}
  839. cundefinedtype,
  840. cformaltype, { unique formal definition }
  841. ctypedformaltype, { unique typed formal definition }
  842. voidtype, { Void (procedure) }
  843. cansichartype, { Char }
  844. cwidechartype, { WideChar }
  845. pasbool8type, { boolean type }
  846. pasbool16type,
  847. pasbool32type,
  848. pasbool64type,
  849. bool8type,
  850. bool16type,
  851. bool32type,
  852. bool64type, { implement me }
  853. u8inttype, { 8-Bit unsigned integer }
  854. s8inttype, { 8-Bit signed integer }
  855. u16inttype, { 16-Bit unsigned integer }
  856. s16inttype, { 16-Bit signed integer }
  857. u32inttype, { 32-Bit unsigned integer }
  858. s32inttype, { 32-Bit signed integer }
  859. u64inttype, { 64-bit unsigned integer }
  860. s64inttype, { 64-bit signed integer }
  861. s32floattype, { 32 bit floating point number }
  862. s64floattype, { 64 bit floating point number }
  863. s80floattype, { 80 bit floating point number }
  864. sc80floattype, { 80 bit floating point number but stored like in C }
  865. s64currencytype, { pointer to a currency type }
  866. cshortstringtype, { pointer to type of short string const }
  867. clongstringtype, { pointer to type of long string const }
  868. cansistringtype, { pointer to type of ansi string const }
  869. cwidestringtype, { pointer to type of wide string const }
  870. cunicodestringtype,
  871. openshortstringtype, { pointer to type of an open shortstring,
  872. needed for readln() }
  873. openchararraytype, { pointer to type of an open array of char,
  874. needed for readln() }
  875. cfiletype, { get the same definition for all file }
  876. { used for stabs }
  877. methodpointertype, { typecasting of methodpointers to extract self }
  878. hresultdef,
  879. { we use only one variant def for every variant class }
  880. cvarianttype,
  881. colevarianttype,
  882. { default integer type s32inttype on 32 bit systems, s64bittype on 64 bit systems }
  883. sinttype,
  884. uinttype,
  885. { integer types corresponding to OS_SINT/OS_INT }
  886. ossinttype,
  887. osuinttype,
  888. { unsigned and signed ord type with the same size as a pointer }
  889. ptruinttype,
  890. ptrsinttype,
  891. { several types to simulate more or less C++ objects for GDB }
  892. vmttype,
  893. vmtarraytype,
  894. pvmttype : tdef; { type of classrefs, used for stabs }
  895. { pointer to the anchestor of all classes }
  896. class_tobject : tobjectdef;
  897. { pointer to the ancestor of all COM interfaces }
  898. interface_iunknown : tobjectdef;
  899. { pointer to the ancestor of all dispinterfaces }
  900. interface_idispatch : tobjectdef;
  901. { pointer to the TGUID type
  902. of all interfaces }
  903. rec_tguid : trecorddef;
  904. { pointer to jump buffer }
  905. rec_jmp_buf : trecorddef;
  906. { Objective-C base types }
  907. objc_metaclasstype,
  908. objc_superclasstype,
  909. objc_idtype,
  910. objc_seltype : tpointerdef;
  911. objc_objecttype : trecorddef;
  912. { base type of @protocol(protocolname) Objective-C statements }
  913. objc_protocoltype : tobjectdef;
  914. { helper types for for-in "fast enumeration" support in Objective-C 2.0 }
  915. objc_fastenumeration : tobjectdef;
  916. objc_fastenumerationstate : trecorddef;
  917. { Java base types }
  918. { java.lang.Object }
  919. java_jlobject : tobjectdef;
  920. { java.lang.Throwable }
  921. java_jlthrowable : tobjectdef;
  922. { FPC base type for records }
  923. java_fpcbaserecordtype : tobjectdef;
  924. { java.lang.String }
  925. java_jlstring : tobjectdef;
  926. { java.lang.Enum }
  927. java_jlenum : tobjectdef;
  928. { java.util.EnumSet }
  929. java_juenumset : tobjectdef;
  930. { java.util.BitSet }
  931. java_jubitset : tobjectdef;
  932. { FPC java implementation of ansistrings }
  933. java_ansistring : tobjectdef;
  934. { FPC java implementation of shortstrings }
  935. java_shortstring : tobjectdef;
  936. { FPC java procvar base class }
  937. java_procvarbase : tobjectdef;
  938. const
  939. {$ifdef i8086}
  940. pbestrealtype : ^tdef = @s80floattype;
  941. {$endif}
  942. {$ifdef i386}
  943. pbestrealtype : ^tdef = @s80floattype;
  944. {$endif}
  945. {$ifdef x86_64}
  946. pbestrealtype : ^tdef = @s80floattype;
  947. {$endif}
  948. {$ifdef m68k}
  949. pbestrealtype : ^tdef = @s64floattype;
  950. {$endif}
  951. {$ifdef alpha}
  952. pbestrealtype : ^tdef = @s64floattype;
  953. {$endif}
  954. {$ifdef powerpc}
  955. pbestrealtype : ^tdef = @s64floattype;
  956. {$endif}
  957. {$ifdef POWERPC64}
  958. pbestrealtype : ^tdef = @s64floattype;
  959. {$endif}
  960. {$ifdef ia64}
  961. pbestrealtype : ^tdef = @s64floattype;
  962. {$endif}
  963. {$ifdef SPARC}
  964. pbestrealtype : ^tdef = @s64floattype;
  965. {$endif SPARC}
  966. {$ifdef vis}
  967. pbestrealtype : ^tdef = @s64floattype;
  968. {$endif vis}
  969. {$ifdef ARM}
  970. pbestrealtype : ^tdef = @s64floattype;
  971. {$endif ARM}
  972. {$ifdef MIPS}
  973. pbestrealtype : ^tdef = @s64floattype;
  974. {$endif MIPS}
  975. {$ifdef AVR}
  976. pbestrealtype : ^tdef = @s64floattype;
  977. {$endif AVR}
  978. {$ifdef JVM}
  979. pbestrealtype : ^tdef = @s64floattype;
  980. {$endif JVM}
  981. {$ifdef AARCH64}
  982. pbestrealtype : ^tdef = @s64floattype;
  983. {$endif AARCH64}
  984. function make_mangledname(const typeprefix:TSymStr;st:TSymtable;const suffix:TSymStr):TSymStr;
  985. function make_dllmangledname(const dllname,importname:TSymStr;
  986. import_nr : word; pco : tproccalloption):TSymStr;
  987. { should be in the types unit, but the types unit uses the node stuff :( }
  988. function is_interfacecom(def: tdef): boolean;
  989. function is_interfacecom_or_dispinterface(def: tdef): boolean;
  990. function is_any_interface_kind(def: tdef): boolean;
  991. function is_interfacecorba(def: tdef): boolean;
  992. function is_interface(def: tdef): boolean;
  993. function is_dispinterface(def: tdef): boolean;
  994. function is_object(def: tdef): boolean;
  995. function is_class(def: tdef): boolean;
  996. function is_cppclass(def: tdef): boolean;
  997. function is_objectpascal_helper(def: tdef): boolean;
  998. function is_objcclass(def: tdef): boolean;
  999. function is_objcclassref(def: tdef): boolean;
  1000. function is_objcprotocol(def: tdef): boolean;
  1001. function is_objccategory(def: tdef): boolean;
  1002. function is_objc_class_or_protocol(def: tdef): boolean;
  1003. function is_objc_protocol_or_category(def: tdef): boolean;
  1004. function is_classhelper(def: tdef): boolean;
  1005. function is_class_or_interface(def: tdef): boolean;
  1006. function is_class_or_interface_or_objc(def: tdef): boolean;
  1007. function is_class_or_interface_or_objc_or_java(def: tdef): boolean;
  1008. function is_class_or_interface_or_dispinterface_or_objc_or_java(def: tdef): boolean;
  1009. function is_class_or_interface_or_object(def: tdef): boolean;
  1010. function is_class_or_interface_or_dispinterface(def: tdef): boolean;
  1011. function is_implicit_pointer_object_type(def: tdef): boolean;
  1012. { returns true, if def is a type which is an implicit pointer to an array (dyn. array or dyn. string) }
  1013. function is_implicit_array_pointer(def: tdef): boolean;
  1014. function is_class_or_object(def: tdef): boolean;
  1015. function is_record(def: tdef): boolean;
  1016. function is_javaclass(def: tdef): boolean;
  1017. function is_javaclassref(def: tdef): boolean;
  1018. function is_javainterface(def: tdef): boolean;
  1019. function is_java_class_or_interface(def: tdef): boolean;
  1020. procedure loadobjctypes;
  1021. procedure maybeloadcocoatypes;
  1022. function use_vectorfpu(def : tdef) : boolean;
  1023. { returns a pointerdef for def, reusing an existing one in case it exists
  1024. in the current module }
  1025. function getpointerdef(def: tdef): tpointerdef;
  1026. { returns an arraydef for an array containing a single array of def, resuing
  1027. an existing one in case it exists in the current module }
  1028. function getsingletonarraydef(def: tdef): tarraydef;
  1029. function getarraydef(def: tdef; elecount: asizeint): tarraydef;
  1030. function getansistringcodepage:tstringencoding; inline;
  1031. function getansistringdef:tstringdef;
  1032. function getparaencoding(def:tdef):tstringencoding; inline;
  1033. {$ifdef x86}
  1034. function default_x86_data_pointer_type: tx86pointertyp;
  1035. {$endif x86}
  1036. implementation
  1037. uses
  1038. SysUtils,
  1039. cutils,
  1040. { global }
  1041. verbose,
  1042. { target }
  1043. systems,paramgr,
  1044. { symtable }
  1045. symsym,symtable,defutil,objcdef,
  1046. {$ifdef jvm}
  1047. jvmdef,
  1048. {$endif}
  1049. { parser }
  1050. pgenutil,
  1051. { module }
  1052. fmodule,
  1053. { other }
  1054. gendef,
  1055. fpccrc
  1056. ;
  1057. {****************************************************************************
  1058. Helpers
  1059. ****************************************************************************}
  1060. function getansistringcodepage:tstringencoding; inline;
  1061. begin
  1062. if cs_explicit_codepage in current_settings.moduleswitches then
  1063. result:=current_settings.sourcecodepage
  1064. else
  1065. result:=0;
  1066. end;
  1067. function getansistringdef:tstringdef;
  1068. var
  1069. symtable:tsymtable;
  1070. begin
  1071. { if codepage is explicitly defined in this mudule we need to return
  1072. a replacement for ansistring def }
  1073. if cs_explicit_codepage in current_settings.moduleswitches then
  1074. begin
  1075. if not assigned(current_module) then
  1076. internalerror(2011101301);
  1077. { codepage can be redeclared only once per unit so we don't need a list of
  1078. redefined ansistring but only one pointer }
  1079. if not assigned(current_module.ansistrdef) then
  1080. begin
  1081. { if we did not create it yet we need to do this now }
  1082. if current_module.is_unit then
  1083. symtable:=current_module.globalsymtable
  1084. else
  1085. symtable:=current_module.localsymtable;
  1086. symtablestack.push(symtable);
  1087. current_module.ansistrdef:=tstringdef.createansi(current_settings.sourcecodepage);
  1088. symtablestack.pop(symtable);
  1089. end;
  1090. result:=tstringdef(current_module.ansistrdef);
  1091. end
  1092. else
  1093. result:=tstringdef(cansistringtype);
  1094. end;
  1095. function getparaencoding(def:tdef):tstringencoding; inline;
  1096. begin
  1097. { don't pass CP_NONE encoding to internal functions
  1098. they expect 0 encoding instead
  1099. exception: result of string concatenation, because if you pass the
  1100. result of a string concatenation to a rawbytestring, the result of
  1101. that concatenation shouldn't be converted to defaultsystemcodepage
  1102. if all strings have the same type }
  1103. result:=tstringdef(def).encoding;
  1104. if result=globals.CP_NONE then
  1105. result:=0
  1106. end;
  1107. function make_mangledname(const typeprefix:TSymStr;st:TSymtable;const suffix:TSymStr):TSymStr;
  1108. var
  1109. s,hs,
  1110. prefix : TSymStr;
  1111. oldlen,
  1112. newlen,
  1113. i : longint;
  1114. crc : dword;
  1115. hp : tparavarsym;
  1116. begin
  1117. prefix:='';
  1118. hp:=nil;
  1119. if not assigned(st) then
  1120. internalerror(200204212);
  1121. { sub procedures }
  1122. while (st.symtabletype=localsymtable) do
  1123. begin
  1124. if st.defowner.typ<>procdef then
  1125. internalerror(200204173);
  1126. { Add the full mangledname of procedure to prevent
  1127. conflicts with 2 overloads having both a nested procedure
  1128. with the same name, see tb0314 (PFV) }
  1129. s:=tprocdef(st.defowner).procsym.name;
  1130. oldlen:=length(s);
  1131. for i:=0 to tprocdef(st.defowner).paras.count-1 do
  1132. begin
  1133. hp:=tparavarsym(tprocdef(st.defowner).paras[i]);
  1134. if not(vo_is_hidden_para in hp.varoptions) then
  1135. s:=s+'$'+hp.vardef.mangledparaname;
  1136. end;
  1137. if not is_void(tprocdef(st.defowner).returndef) then
  1138. s:=s+'$$'+tprocdef(st.defowner).returndef.mangledparaname;
  1139. newlen:=length(s);
  1140. { Replace with CRC if the parameter line is very long }
  1141. if (newlen-oldlen>12) and
  1142. ((newlen+length(prefix)>100) or (newlen-oldlen>32)) then
  1143. begin
  1144. crc:=0;
  1145. for i:=0 to tprocdef(st.defowner).paras.count-1 do
  1146. begin
  1147. hp:=tparavarsym(tprocdef(st.defowner).paras[i]);
  1148. if not(vo_is_hidden_para in hp.varoptions) then
  1149. begin
  1150. hs:=hp.vardef.mangledparaname;
  1151. crc:=UpdateCrc32(crc,hs[1],length(hs));
  1152. end;
  1153. end;
  1154. hs:=hp.vardef.mangledparaname;
  1155. crc:=UpdateCrc32(crc,hs[1],length(hs));
  1156. s:=Copy(s,1,oldlen)+'$crc'+hexstr(crc,8);
  1157. end;
  1158. if prefix<>'' then
  1159. prefix:=s+'_'+prefix
  1160. else
  1161. prefix:=s;
  1162. if length(prefix)>100 then
  1163. begin
  1164. crc:=0;
  1165. crc:=UpdateCrc32(crc,prefix[1],length(prefix));
  1166. prefix:='$CRC'+hexstr(crc,8);
  1167. end;
  1168. st:=st.defowner.owner;
  1169. end;
  1170. { object/classes symtable, nested type definitions in classes require the while loop }
  1171. while st.symtabletype in [ObjectSymtable,recordsymtable] do
  1172. begin
  1173. if not (st.defowner.typ in [objectdef,recorddef]) then
  1174. internalerror(200204174);
  1175. prefix:=tabstractrecorddef(st.defowner).objname^+'_$_'+prefix;
  1176. st:=st.defowner.owner;
  1177. end;
  1178. { symtable must now be static or global }
  1179. if not(st.symtabletype in [staticsymtable,globalsymtable]) then
  1180. internalerror(200204175);
  1181. { The mangled name is made out of at most 4 parts:
  1182. 1) Optional typeprefix given as first parameter
  1183. with '_$' appended if not empty
  1184. 2) Unit name or 'P$'+program name (never empty)
  1185. 3) optional prefix variable that contains a unique
  1186. name for the local symbol table (prepended with '$_$'
  1187. if not empty)
  1188. 4) suffix as given as third parameter,
  1189. also optional (i.e. can be empty)
  1190. prepended by '_$$_' if not empty }
  1191. result:='';
  1192. if typeprefix<>'' then
  1193. result:=result+typeprefix+'_$';
  1194. { Add P$ for program, which can have the same name as
  1195. a unit }
  1196. if (TSymtable(main_module.localsymtable)=st) and
  1197. (not main_module.is_unit) then
  1198. result:=result+'P$'+st.name^
  1199. else
  1200. result:=result+st.name^;
  1201. if prefix<>'' then
  1202. result:=result+'$_$'+prefix;
  1203. if suffix<>'' then
  1204. result:=result+'_$$_'+suffix;
  1205. { the Darwin assembler assumes that all symbols starting with 'L' are local }
  1206. { Further, the Mac OS X 10.5 linker does not consider symbols which do not }
  1207. { start with '_' as regular symbols (it does not generate N_GSYM entries }
  1208. { those in the debug map, leading to troubles with dsymutil). So always }
  1209. { add an underscore on darwin. }
  1210. if (target_info.system in systems_darwin) then
  1211. result := '_' + result;
  1212. {$ifdef llvm}
  1213. { in LLVM, all non-procedure local symbols have to start with an '@' }
  1214. result:='@'+result;
  1215. {$endif llvm}
  1216. end;
  1217. function make_dllmangledname(const dllname,importname:TSymStr;import_nr : word; pco : tproccalloption):TSymStr;
  1218. var
  1219. crc : cardinal;
  1220. i : longint;
  1221. use_crc : boolean;
  1222. dllprefix : TSymStr;
  1223. begin
  1224. if (target_info.system in (systems_all_windows + systems_nativent +
  1225. [system_i386_emx, system_i386_os2]))
  1226. and (dllname <> '') then
  1227. begin
  1228. dllprefix:=lower(ExtractFileName(dllname));
  1229. { Remove .dll suffix if present }
  1230. if copy(dllprefix,length(dllprefix)-3,length(dllprefix))='.dll' then
  1231. dllprefix:=copy(dllprefix,1,length(dllprefix)-4);
  1232. use_crc:=false;
  1233. for i:=1 to length(dllprefix) do
  1234. if not (dllprefix[i] in ['a'..'z','A'..'Z','_','0'..'9']) then
  1235. begin
  1236. use_crc:=true;
  1237. break;
  1238. end;
  1239. if use_crc then
  1240. begin
  1241. crc:=0;
  1242. crc:=UpdateCrc32(crc,dllprefix[1],length(dllprefix));
  1243. dllprefix:='_$dll$crc$'+hexstr(crc,8)+'$';
  1244. end
  1245. else
  1246. dllprefix:='_$dll$'+dllprefix+'$';
  1247. if importname<>'' then
  1248. result:=dllprefix+importname
  1249. else
  1250. result:=dllprefix+'_index_'+tostr(import_nr);
  1251. { Replace ? and @ in import name, since GNU AS does not allow these characters in symbol names. }
  1252. { This allows to import VC++ mangled names from DLLs. }
  1253. { Do not perform replacement, if external symbol is not imported from DLL. }
  1254. if (dllname<>'') then
  1255. begin
  1256. Replace(result,'?','__q$$');
  1257. {$ifdef arm}
  1258. { @ symbol is not allowed in ARM assembler only }
  1259. Replace(result,'@','__a$$');
  1260. {$endif arm}
  1261. end;
  1262. end
  1263. else
  1264. begin
  1265. if importname<>'' then
  1266. begin
  1267. if not(pco in [pocall_cdecl,pocall_cppdecl]) then
  1268. result:=importname
  1269. else
  1270. result:=target_info.Cprefix+importname;
  1271. end
  1272. else
  1273. result:='_index_'+tostr(import_nr);
  1274. end;
  1275. end;
  1276. {****************************************************************************
  1277. TDEFAWARESYMTABLESTACK
  1278. (symtablestack descendant that does some special actions on
  1279. the pushed/popped symtables)
  1280. ****************************************************************************}
  1281. procedure tdefawaresymtablestack.add_helpers_and_generics(st:tsymtable;addgenerics:boolean);
  1282. var
  1283. i: integer;
  1284. s: string;
  1285. list: TFPObjectList;
  1286. def: tdef;
  1287. sym,srsym : tsym;
  1288. srsymtable : tsymtable;
  1289. entry : tgenericdummyentry;
  1290. begin
  1291. { search the symtable from first to last; the helper to use will be the
  1292. last one in the list }
  1293. for i:=0 to st.symlist.count-1 do
  1294. begin
  1295. if not (st.symlist[i] is ttypesym) then
  1296. continue;
  1297. def:=ttypesym(st.SymList[i]).typedef;
  1298. sym:=tsym(st.symlist[i]);
  1299. if is_objectpascal_helper(def) then
  1300. begin
  1301. s:=generate_objectpascal_helper_key(tobjectdef(def).extendeddef);
  1302. Message1(sym_d_adding_helper_for,s);
  1303. list:=TFPObjectList(current_module.extendeddefs.Find(s));
  1304. if not assigned(list) then
  1305. begin
  1306. list:=TFPObjectList.Create(false);
  1307. current_module.extendeddefs.Add(s,list);
  1308. end;
  1309. list.Add(def);
  1310. end
  1311. else
  1312. begin
  1313. if addgenerics and
  1314. (sp_generic_dummy in sym.symoptions)
  1315. then
  1316. begin
  1317. { did we already search for a generic with that name? }
  1318. list:=tfpobjectlist(current_module.genericdummysyms.find(sym.name));
  1319. if not assigned(list) then
  1320. begin
  1321. list:=tfpobjectlist.create(true);
  1322. current_module.genericdummysyms.add(sym.name,list);
  1323. end;
  1324. { is the dummy sym still "dummy"? }
  1325. if (sym.typ=typesym) and
  1326. (
  1327. { dummy sym defined in mode Delphi }
  1328. (ttypesym(sym).typedef.typ=undefineddef) or
  1329. { dummy sym defined in non-Delphi mode }
  1330. (tstoreddef(ttypesym(sym).typedef).is_generic)
  1331. ) then
  1332. begin
  1333. { do we have a non-generic type of the same name
  1334. available? }
  1335. if not searchsym_with_flags(sym.name,srsym,srsymtable,[ssf_no_addsymref]) then
  1336. srsym:=nil;
  1337. end
  1338. else
  1339. { dummy symbol is already not so dummy anymore }
  1340. srsym:=nil;
  1341. if assigned(srsym) then
  1342. begin
  1343. entry:=tgenericdummyentry.create;
  1344. entry.resolvedsym:=srsym;
  1345. entry.dummysym:=sym;
  1346. list.add(entry);
  1347. end;
  1348. end;
  1349. { add nested helpers as well }
  1350. if (def.typ in [recorddef,objectdef]) and
  1351. (sto_has_helper in tabstractrecorddef(def).symtable.tableoptions) then
  1352. add_helpers_and_generics(tabstractrecorddef(def).symtable,false);
  1353. end;
  1354. end;
  1355. end;
  1356. procedure tdefawaresymtablestack.remove_helpers_and_generics(st:tsymtable);
  1357. begin
  1358. if sto_has_helper in st.tableoptions then
  1359. remove_helpers(st);
  1360. if sto_has_generic in st.tableoptions then
  1361. remove_generics(st);
  1362. end;
  1363. procedure tdefawaresymtablestack.remove_helpers(st:TSymtable);
  1364. var
  1365. i, j: integer;
  1366. tmpst: TSymtable;
  1367. list: TFPObjectList;
  1368. begin
  1369. for i:=current_module.extendeddefs.count-1 downto 0 do
  1370. begin
  1371. list:=TFPObjectList(current_module.extendeddefs[i]);
  1372. for j:=list.count-1 downto 0 do
  1373. begin
  1374. if not (list[j] is tobjectdef) then
  1375. Internalerror(2011031501);
  1376. tmpst:=tobjectdef(list[j]).owner;
  1377. repeat
  1378. if tmpst=st then
  1379. begin
  1380. list.delete(j);
  1381. break;
  1382. end
  1383. else
  1384. begin
  1385. if assigned(tmpst.defowner) then
  1386. tmpst:=tmpst.defowner.owner
  1387. else
  1388. tmpst:=nil;
  1389. end;
  1390. until not assigned(tmpst) or (tmpst.symtabletype in [globalsymtable,staticsymtable]);
  1391. end;
  1392. if list.count=0 then
  1393. current_module.extendeddefs.delete(i);
  1394. end;
  1395. end;
  1396. procedure tdefawaresymtablestack.remove_generics(st:tsymtable);
  1397. var
  1398. i,j : longint;
  1399. entry : tgenericdummyentry;
  1400. list : tfpobjectlist;
  1401. begin
  1402. for i:=current_module.genericdummysyms.count-1 downto 0 do
  1403. begin
  1404. list:=tfpobjectlist(current_module.genericdummysyms[i]);
  1405. if not assigned(list) then
  1406. continue;
  1407. for j:=list.count-1 downto 0 do
  1408. begin
  1409. entry:=tgenericdummyentry(list[j]);
  1410. if entry.dummysym.owner=st then
  1411. list.delete(j);
  1412. end;
  1413. if list.count=0 then
  1414. current_module.genericdummysyms.delete(i);
  1415. end;
  1416. end;
  1417. procedure tdefawaresymtablestack.pushcommon(st:tsymtable);
  1418. begin
  1419. if (sto_has_generic in st.tableoptions) or
  1420. (
  1421. (st.symtabletype in [globalsymtable,staticsymtable]) and
  1422. (sto_has_helper in st.tableoptions)
  1423. ) then
  1424. { nested helpers will be added as well }
  1425. add_helpers_and_generics(st,true);
  1426. end;
  1427. procedure tdefawaresymtablestack.push(st: TSymtable);
  1428. begin
  1429. pushcommon(st);
  1430. inherited push(st);
  1431. end;
  1432. procedure tdefawaresymtablestack.pushafter(st,afterst:TSymtable);
  1433. begin
  1434. pushcommon(st);
  1435. inherited pushafter(st,afterst);
  1436. end;
  1437. procedure tdefawaresymtablestack.pop(st: TSymtable);
  1438. begin
  1439. inherited pop(st);
  1440. if (sto_has_generic in st.tableoptions) or
  1441. (
  1442. (st.symtabletype in [globalsymtable,staticsymtable]) and
  1443. (sto_has_helper in st.tableoptions)
  1444. ) then
  1445. { nested helpers will be removed as well }
  1446. remove_helpers_and_generics(st);
  1447. end;
  1448. {****************************************************************************
  1449. TDEF (base class for definitions)
  1450. ****************************************************************************}
  1451. constructor tgenericconstraintdata.create;
  1452. begin
  1453. interfaces:=tfpobjectlist.create(false);
  1454. interfacesderef:=tfplist.create;
  1455. end;
  1456. destructor tgenericconstraintdata.destroy;
  1457. var
  1458. i : longint;
  1459. begin
  1460. for i:=0 to interfacesderef.count-1 do
  1461. dispose(pderef(interfacesderef[i]));
  1462. interfacesderef.free;
  1463. interfaces.free;
  1464. inherited destroy;
  1465. end;
  1466. procedure tgenericconstraintdata.ppuload(ppufile: tcompilerppufile);
  1467. var
  1468. cnt,i : longint;
  1469. intfderef : pderef;
  1470. begin
  1471. ppufile.getsmallset(flags);
  1472. cnt:=ppufile.getlongint;
  1473. for i:=0 to cnt-1 do
  1474. begin
  1475. new(intfderef);
  1476. ppufile.getderef(intfderef^);
  1477. interfacesderef.add(intfderef);
  1478. end;
  1479. end;
  1480. procedure tgenericconstraintdata.ppuwrite(ppufile: tcompilerppufile);
  1481. var
  1482. i : longint;
  1483. begin
  1484. ppufile.putsmallset(flags);
  1485. ppufile.putlongint(interfacesderef.count);
  1486. for i:=0 to interfacesderef.count-1 do
  1487. ppufile.putderef(pderef(interfacesderef[i])^);
  1488. end;
  1489. procedure tgenericconstraintdata.buildderef;
  1490. var
  1491. intfderef : pderef;
  1492. i : longint;
  1493. begin
  1494. for i:=0 to interfaces.count-1 do
  1495. begin
  1496. new(intfderef);
  1497. intfderef^.build(tobjectdef(interfaces[i]));
  1498. interfacesderef.add(intfderef);
  1499. end;
  1500. end;
  1501. procedure tgenericconstraintdata.deref;
  1502. var
  1503. i : longint;
  1504. begin
  1505. for i:=0 to interfacesderef.count-1 do
  1506. interfaces.add(pderef(interfacesderef[i])^.resolve);
  1507. end;
  1508. procedure tstoreddef.fillgenericparas(symtable: tsymtable);
  1509. var
  1510. sym : tsym;
  1511. i : longint;
  1512. begin
  1513. if not assigned(symtable) then
  1514. internalerror(2012091201);
  1515. if [df_generic,df_specialization]*defoptions=[] then
  1516. exit;
  1517. for i:=0 to symtable.symlist.count-1 do
  1518. begin
  1519. sym:=tsym(symtable.symlist[i]);
  1520. if sp_generic_para in sym.symoptions then
  1521. begin
  1522. if not assigned(genericparas) then
  1523. genericparas:=tfphashobjectlist.create(false);
  1524. genericparas.Add(sym.name,sym);
  1525. end;
  1526. end;
  1527. end;
  1528. constructor tstoreddef.create(dt:tdeftyp);
  1529. var
  1530. insertstack : psymtablestackitem;
  1531. begin
  1532. inherited create(dt);
  1533. savesize := 0;
  1534. {$ifdef EXTDEBUG}
  1535. fileinfo := current_filepos;
  1536. {$endif}
  1537. generictokenbuf:=nil;
  1538. genericdef:=nil;
  1539. { Don't register forwarddefs, they are disposed at the
  1540. end of an type block }
  1541. if (dt=forwarddef) then
  1542. exit;
  1543. { Register in current_module }
  1544. if assigned(current_module) then
  1545. begin
  1546. current_module.deflist.Add(self);
  1547. DefId:=current_module.deflist.Count-1;
  1548. end;
  1549. { Register in symtable stack }
  1550. if assigned(symtablestack) then
  1551. begin
  1552. insertstack:=symtablestack.stack;
  1553. while assigned(insertstack) and
  1554. (insertstack^.symtable.symtabletype=withsymtable) do
  1555. insertstack:=insertstack^.next;
  1556. if not assigned(insertstack) then
  1557. internalerror(200602044);
  1558. insertstack^.symtable.insertdef(self);
  1559. end;
  1560. end;
  1561. destructor tstoreddef.destroy;
  1562. begin
  1563. { Direct calls are not allowed, use symtable.deletedef() }
  1564. if assigned(owner) then
  1565. internalerror(200612311);
  1566. if assigned(generictokenbuf) then
  1567. begin
  1568. generictokenbuf.free;
  1569. generictokenbuf:=nil;
  1570. end;
  1571. genericparas.free;
  1572. genconstraintdata.free;
  1573. stringdispose(_fullownerhierarchyname);
  1574. inherited destroy;
  1575. end;
  1576. constructor tstoreddef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  1577. var
  1578. sizeleft,i : longint;
  1579. buf : array[0..255] of byte;
  1580. begin
  1581. inherited create(dt);
  1582. DefId:=ppufile.getlongint;
  1583. current_module.deflist[DefId]:=self;
  1584. {$ifdef EXTDEBUG}
  1585. fillchar(fileinfo,sizeof(fileinfo),0);
  1586. {$endif}
  1587. { load }
  1588. ppufile.getderef(typesymderef);
  1589. ppufile.getsmallset(defoptions);
  1590. ppufile.getsmallset(defstates);
  1591. if df_genconstraint in defoptions then
  1592. begin
  1593. genconstraintdata:=tgenericconstraintdata.create;
  1594. genconstraintdata.ppuload(ppufile);
  1595. end;
  1596. if df_generic in defoptions then
  1597. begin
  1598. sizeleft:=ppufile.getlongint;
  1599. initgeneric;
  1600. while sizeleft>0 do
  1601. begin
  1602. if sizeleft>sizeof(buf) then
  1603. i:=sizeof(buf)
  1604. else
  1605. i:=sizeleft;
  1606. ppufile.getdata(buf,i);
  1607. generictokenbuf.write(buf,i);
  1608. dec(sizeleft,i);
  1609. end;
  1610. end;
  1611. if df_specialization in defoptions then
  1612. ppufile.getderef(genericdefderef);
  1613. end;
  1614. function tstoreddef.needs_separate_initrtti:boolean;
  1615. begin
  1616. result:=false;
  1617. end;
  1618. function tstoreddef.rtti_mangledname(rt : trttitype) : string;
  1619. var
  1620. prefix : string[4];
  1621. begin
  1622. if (rt=fullrtti) or (not needs_separate_initrtti) then
  1623. begin
  1624. prefix:='RTTI';
  1625. include(defstates,ds_rtti_table_used);
  1626. end
  1627. else
  1628. begin
  1629. prefix:='INIT';
  1630. include(defstates,ds_init_table_used);
  1631. end;
  1632. if assigned(typesym) and
  1633. (owner.symtabletype in [staticsymtable,globalsymtable]) then
  1634. result:=make_mangledname(prefix,owner,typesym.name)
  1635. else
  1636. result:=make_mangledname(prefix,findunitsymtable(owner),'DEF'+tostr(DefId))
  1637. end;
  1638. function tstoreddef.OwnerHierarchyName: string;
  1639. var
  1640. tmp: tdef;
  1641. begin
  1642. tmp:=self;
  1643. result:='';
  1644. repeat
  1645. { can be not assigned in case of a forwarddef }
  1646. if assigned(tmp.owner) and
  1647. (tmp.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  1648. tmp:=tdef(tmp.owner.defowner)
  1649. else
  1650. break;
  1651. result:=tabstractrecorddef(tmp).objrealname^+'.'+result;
  1652. until tmp=nil;
  1653. end;
  1654. function tstoreddef.fullownerhierarchyname: string;
  1655. var
  1656. tmp: tdef;
  1657. begin
  1658. if assigned(_fullownerhierarchyname) then
  1659. begin
  1660. result:=_fullownerhierarchyname^;
  1661. exit;
  1662. end;
  1663. { the def can only reside inside structured types or
  1664. procedures/functions/methods }
  1665. tmp:=self;
  1666. result:='';
  1667. repeat
  1668. { can be not assigned in case of a forwarddef }
  1669. if not assigned(tmp.owner) then
  1670. break
  1671. else
  1672. tmp:=tdef(tmp.owner.defowner);
  1673. if not assigned(tmp) then
  1674. break;
  1675. if tmp.typ in [recorddef,objectdef] then
  1676. result:=tabstractrecorddef(tmp).objrealname^+'.'+result
  1677. else
  1678. if tmp.typ=procdef then
  1679. result:=tprocdef(tmp).customprocname([pno_paranames,pno_proctypeoption])+'.'+result;
  1680. until tmp=nil;
  1681. _fullownerhierarchyname:=stringdup(result);
  1682. end;
  1683. function tstoreddef.in_currentunit: boolean;
  1684. var
  1685. st: tsymtable;
  1686. begin
  1687. st:=owner;
  1688. while not(st.symtabletype in [globalsymtable,staticsymtable]) do
  1689. st:=st.defowner.owner;
  1690. result:=st.iscurrentunit;
  1691. end;
  1692. function tstoreddef.getcopy : tstoreddef;
  1693. begin
  1694. Message(sym_e_cant_create_unique_type);
  1695. getcopy:=terrordef.create;
  1696. end;
  1697. procedure tstoreddef.ppuwrite(ppufile:tcompilerppufile);
  1698. var
  1699. sizeleft,i : longint;
  1700. buf : array[0..255] of byte;
  1701. oldintfcrc : boolean;
  1702. begin
  1703. ppufile.putlongint(DefId);
  1704. ppufile.putderef(typesymderef);
  1705. ppufile.putsmallset(defoptions);
  1706. oldintfcrc:=ppufile.do_crc;
  1707. ppufile.do_crc:=false;
  1708. ppufile.putsmallset(defstates);
  1709. if df_genconstraint in defoptions then
  1710. genconstraintdata.ppuwrite(ppufile);
  1711. if df_generic in defoptions then
  1712. begin
  1713. if assigned(generictokenbuf) then
  1714. begin
  1715. sizeleft:=generictokenbuf.size;
  1716. generictokenbuf.seek(0);
  1717. end
  1718. else
  1719. sizeleft:=0;
  1720. ppufile.putlongint(sizeleft);
  1721. while sizeleft>0 do
  1722. begin
  1723. if sizeleft>sizeof(buf) then
  1724. i:=sizeof(buf)
  1725. else
  1726. i:=sizeleft;
  1727. generictokenbuf.read(buf,i);
  1728. ppufile.putdata(buf,i);
  1729. dec(sizeleft,i);
  1730. end;
  1731. end;
  1732. ppufile.do_crc:=oldintfcrc;
  1733. if df_specialization in defoptions then
  1734. ppufile.putderef(genericdefderef);
  1735. end;
  1736. procedure tstoreddef.buildderef;
  1737. begin
  1738. typesymderef.build(typesym);
  1739. genericdefderef.build(genericdef);
  1740. if assigned(genconstraintdata) then
  1741. genconstraintdata.buildderef;
  1742. end;
  1743. procedure tstoreddef.buildderefimpl;
  1744. begin
  1745. end;
  1746. procedure tstoreddef.deref;
  1747. begin
  1748. typesym:=ttypesym(typesymderef.resolve);
  1749. if df_specialization in defoptions then
  1750. genericdef:=tstoreddef(genericdefderef.resolve);
  1751. if assigned(genconstraintdata) then
  1752. genconstraintdata.deref;
  1753. end;
  1754. procedure tstoreddef.derefimpl;
  1755. begin
  1756. end;
  1757. function tstoreddef.size : asizeint;
  1758. begin
  1759. size:=savesize;
  1760. end;
  1761. function tstoreddef.getvardef:longint;
  1762. begin
  1763. result:=varUndefined;
  1764. end;
  1765. function tstoreddef.alignment : shortint;
  1766. begin
  1767. { natural alignment by default }
  1768. alignment:=size_2_align(savesize);
  1769. { can happen if savesize = 0, e.g. for voiddef or
  1770. an empty record
  1771. }
  1772. if (alignment=0) then
  1773. alignment:=1;
  1774. end;
  1775. { returns true, if the definition can be published }
  1776. function tstoreddef.is_publishable : boolean;
  1777. begin
  1778. is_publishable:=false;
  1779. end;
  1780. { needs an init table }
  1781. function tstoreddef.needs_inittable : boolean;
  1782. begin
  1783. needs_inittable:=false;
  1784. end;
  1785. function tstoreddef.is_intregable : boolean;
  1786. var
  1787. recsize,temp: longint;
  1788. begin
  1789. is_intregable:=false;
  1790. case typ of
  1791. orddef,
  1792. pointerdef,
  1793. enumdef,
  1794. classrefdef:
  1795. is_intregable:=true;
  1796. procvardef :
  1797. is_intregable:=tprocvardef(self).is_addressonly or (po_methodpointer in tprocvardef(self).procoptions);
  1798. objectdef:
  1799. is_intregable:=(is_implicit_pointer_object_type(self)) and not needs_inittable;
  1800. setdef:
  1801. is_intregable:=is_smallset(self);
  1802. recorddef:
  1803. begin
  1804. recsize:=size;
  1805. is_intregable:=
  1806. ispowerof2(recsize,temp) and
  1807. { sizeof(asizeint)*2 records in int registers is currently broken for endian_big targets }
  1808. (((recsize <= sizeof(asizeint)*2) and (target_info.endian=endian_little)
  1809. { records cannot go into registers on 16 bit targets for now }
  1810. and (sizeof(asizeint)>2)
  1811. and not trecorddef(self).contains_float_field) or
  1812. (recsize <= sizeof(asizeint)))
  1813. and not needs_inittable;
  1814. end;
  1815. end;
  1816. end;
  1817. function tstoreddef.is_fpuregable : boolean;
  1818. begin
  1819. {$ifdef x86}
  1820. result:=use_vectorfpu(self);
  1821. {$else x86}
  1822. result:=(typ=floatdef) and not(cs_fp_emulation in current_settings.moduleswitches);
  1823. {$endif x86}
  1824. end;
  1825. function tstoreddef.is_const_intregable : boolean;
  1826. begin
  1827. case typ of
  1828. stringdef:
  1829. result:=tstringdef(self).stringtype in [st_ansistring,st_unicodestring,st_widestring];
  1830. arraydef:
  1831. result:=is_dynamic_array(self);
  1832. objectdef:
  1833. result:=is_interface(self);
  1834. else
  1835. result:=false;
  1836. end;
  1837. end;
  1838. procedure tstoreddef.initgeneric;
  1839. begin
  1840. if assigned(generictokenbuf) then
  1841. internalerror(200512131);
  1842. generictokenbuf:=tdynamicarray.create(256);
  1843. end;
  1844. function tstoreddef.is_generic: boolean;
  1845. begin
  1846. result:=assigned(genericparas) and
  1847. (genericparas.count>0) and
  1848. (df_generic in defoptions);
  1849. end;
  1850. function tstoreddef.is_specialization: boolean;
  1851. begin
  1852. result:=assigned(genericparas) and
  1853. (genericparas.count>0) and
  1854. (df_specialization in defoptions);
  1855. end;
  1856. {****************************************************************************
  1857. Tstringdef
  1858. ****************************************************************************}
  1859. constructor tstringdef.createshort(l : byte);
  1860. begin
  1861. inherited create(stringdef);
  1862. stringtype:=st_shortstring;
  1863. encoding:=0;
  1864. len:=l;
  1865. savesize:=len+1;
  1866. end;
  1867. constructor tstringdef.loadshort(ppufile:tcompilerppufile);
  1868. begin
  1869. inherited ppuload(stringdef,ppufile);
  1870. stringtype:=st_shortstring;
  1871. encoding:=0;
  1872. len:=ppufile.getbyte;
  1873. savesize:=len+1;
  1874. end;
  1875. constructor tstringdef.createlong(l : asizeint);
  1876. begin
  1877. inherited create(stringdef);
  1878. stringtype:=st_longstring;
  1879. encoding:=0;
  1880. len:=l;
  1881. savesize:=sizeof(pint);
  1882. end;
  1883. constructor tstringdef.loadlong(ppufile:tcompilerppufile);
  1884. begin
  1885. inherited ppuload(stringdef,ppufile);
  1886. stringtype:=st_longstring;
  1887. encoding:=0;
  1888. len:=ppufile.getasizeint;
  1889. savesize:=sizeof(pint);
  1890. end;
  1891. constructor tstringdef.createansi(aencoding:tstringencoding);
  1892. begin
  1893. inherited create(stringdef);
  1894. stringtype:=st_ansistring;
  1895. encoding:=aencoding;
  1896. len:=-1;
  1897. savesize:=sizeof(pint);
  1898. end;
  1899. constructor tstringdef.loadansi(ppufile:tcompilerppufile);
  1900. begin
  1901. inherited ppuload(stringdef,ppufile);
  1902. stringtype:=st_ansistring;
  1903. len:=ppufile.getaint;
  1904. encoding:=ppufile.getword;
  1905. savesize:=sizeof(pint);
  1906. end;
  1907. constructor tstringdef.createwide;
  1908. begin
  1909. inherited create(stringdef);
  1910. stringtype:=st_widestring;
  1911. if target_info.endian=endian_little then
  1912. encoding:=CP_UTF16LE
  1913. else
  1914. encoding:=CP_UTF16BE;
  1915. len:=-1;
  1916. savesize:=sizeof(pint);
  1917. end;
  1918. constructor tstringdef.loadwide(ppufile:tcompilerppufile);
  1919. begin
  1920. inherited ppuload(stringdef,ppufile);
  1921. stringtype:=st_widestring;
  1922. if target_info.endian=endian_little then
  1923. encoding:=CP_UTF16LE
  1924. else
  1925. encoding:=CP_UTF16BE;
  1926. len:=ppufile.getaint;
  1927. savesize:=sizeof(pint);
  1928. end;
  1929. constructor tstringdef.createunicode;
  1930. begin
  1931. inherited create(stringdef);
  1932. stringtype:=st_unicodestring;
  1933. if target_info.endian=endian_little then
  1934. encoding:=CP_UTF16LE
  1935. else
  1936. encoding:=CP_UTF16BE;
  1937. len:=-1;
  1938. savesize:=sizeof(pint);
  1939. end;
  1940. constructor tstringdef.loadunicode(ppufile:tcompilerppufile);
  1941. begin
  1942. inherited ppuload(stringdef,ppufile);
  1943. stringtype:=st_unicodestring;
  1944. len:=ppufile.getaint;
  1945. encoding:=ppufile.getword;
  1946. savesize:=sizeof(pint);
  1947. end;
  1948. function tstringdef.getcopy : tstoreddef;
  1949. begin
  1950. result:=tstringdef.create(typ);
  1951. result.typ:=stringdef;
  1952. tstringdef(result).stringtype:=stringtype;
  1953. tstringdef(result).encoding:=encoding;
  1954. tstringdef(result).len:=len;
  1955. tstringdef(result).savesize:=savesize;
  1956. end;
  1957. function tstringdef.stringtypname:string;
  1958. const
  1959. typname:array[tstringtype] of string[10]=(
  1960. 'shortstr','longstr','ansistr','widestr','unicodestr'
  1961. );
  1962. begin
  1963. stringtypname:=typname[stringtype];
  1964. end;
  1965. procedure tstringdef.ppuwrite(ppufile:tcompilerppufile);
  1966. begin
  1967. inherited ppuwrite(ppufile);
  1968. if stringtype=st_shortstring then
  1969. begin
  1970. {$ifdef extdebug}
  1971. if len > 255 then internalerror(12122002);
  1972. {$endif}
  1973. ppufile.putbyte(byte(len))
  1974. end
  1975. else
  1976. ppufile.putaint(len);
  1977. if stringtype in [st_ansistring,st_unicodestring] then
  1978. ppufile.putword(encoding);
  1979. case stringtype of
  1980. st_shortstring : ppufile.writeentry(ibshortstringdef);
  1981. st_longstring : ppufile.writeentry(iblongstringdef);
  1982. st_ansistring : ppufile.writeentry(ibansistringdef);
  1983. st_widestring : ppufile.writeentry(ibwidestringdef);
  1984. st_unicodestring : ppufile.writeentry(ibunicodestringdef);
  1985. end;
  1986. end;
  1987. function tstringdef.needs_inittable : boolean;
  1988. begin
  1989. needs_inittable:=stringtype in [st_ansistring,st_widestring,st_unicodestring];
  1990. end;
  1991. function tstringdef.GetTypeName : string;
  1992. const
  1993. names : array[tstringtype] of string[15] = (
  1994. 'ShortString','LongString','AnsiString','WideString','UnicodeString');
  1995. begin
  1996. GetTypeName:=names[stringtype];
  1997. end;
  1998. function tstringdef.getvardef : longint;
  1999. const
  2000. vardef : array[tstringtype] of longint = (
  2001. varUndefined,varUndefined,varString,varOleStr,varUString);
  2002. begin
  2003. result:=vardef[stringtype];
  2004. end;
  2005. function tstringdef.alignment : shortint;
  2006. begin
  2007. case stringtype of
  2008. st_unicodestring,
  2009. st_widestring,
  2010. st_ansistring:
  2011. alignment:=size_2_align(savesize);
  2012. st_longstring,
  2013. st_shortstring:
  2014. { char to string accesses byte 0 and 1 with one word access }
  2015. if (tf_requires_proper_alignment in target_info.flags) or
  2016. { macpas needs an alignment of 2 (MetroWerks compatible) }
  2017. (m_mac in current_settings.modeswitches) then
  2018. alignment:=size_2_align(2)
  2019. else
  2020. alignment:=size_2_align(1);
  2021. else
  2022. internalerror(200412301);
  2023. end;
  2024. end;
  2025. function tstringdef.getmangledparaname : TSymStr;
  2026. begin
  2027. getmangledparaname:='STRING';
  2028. end;
  2029. function tstringdef.is_publishable : boolean;
  2030. begin
  2031. is_publishable:=true;
  2032. end;
  2033. {****************************************************************************
  2034. TENUMDEF
  2035. ****************************************************************************}
  2036. constructor tenumdef.create;
  2037. begin
  2038. inherited create(enumdef);
  2039. minval:=0;
  2040. maxval:=0;
  2041. calcsavesize;
  2042. has_jumps:=false;
  2043. basedef:=nil;
  2044. symtable:=tenumsymtable.create(self);
  2045. end;
  2046. constructor tenumdef.create_subrange(_basedef:tenumdef;_min,_max:asizeint);
  2047. begin
  2048. inherited create(enumdef);
  2049. minval:=_min;
  2050. maxval:=_max;
  2051. basedef:=_basedef;
  2052. calcsavesize;
  2053. has_jumps:=false;
  2054. symtable:=basedef.symtable.getcopy;
  2055. include(defoptions, df_copied_def);
  2056. end;
  2057. constructor tenumdef.ppuload(ppufile:tcompilerppufile);
  2058. begin
  2059. inherited ppuload(enumdef,ppufile);
  2060. minval:=ppufile.getaint;
  2061. maxval:=ppufile.getaint;
  2062. savesize:=ppufile.getaint;
  2063. has_jumps:=false;
  2064. {$ifdef jvm}
  2065. ppufile.getderef(classdefderef);
  2066. {$endif}
  2067. if df_copied_def in defoptions then
  2068. begin
  2069. symtable:=nil;
  2070. ppufile.getderef(basedefderef);
  2071. end
  2072. else
  2073. begin
  2074. // create with nil defowner first to prevent values changes on insert
  2075. symtable:=tenumsymtable.create(nil);
  2076. tenumsymtable(symtable).ppuload(ppufile);
  2077. symtable.defowner:=self;
  2078. end;
  2079. end;
  2080. destructor tenumdef.destroy;
  2081. begin
  2082. symtable.free;
  2083. symtable:=nil;
  2084. inherited destroy;
  2085. end;
  2086. function tenumdef.getcopy : tstoreddef;
  2087. begin
  2088. if assigned(basedef) then
  2089. result:=tenumdef.create_subrange(basedef,minval,maxval)
  2090. else
  2091. begin
  2092. result:=tenumdef.create;
  2093. tenumdef(result).minval:=minval;
  2094. tenumdef(result).maxval:=maxval;
  2095. tenumdef(result).symtable.free;
  2096. tenumdef(result).symtable:=symtable.getcopy;
  2097. tenumdef(result).basedef:=self;
  2098. end;
  2099. {$ifdef jvm}
  2100. tenumdef(result).classdef:=classdef;
  2101. {$endif}
  2102. tenumdef(result).has_jumps:=has_jumps;
  2103. tenumdef(result).basedefderef:=basedefderef;
  2104. include(tenumdef(result).defoptions,df_copied_def);
  2105. end;
  2106. procedure tenumdef.calcsavesize;
  2107. begin
  2108. {$IFNDEF cpu64bitaddr} {$push}{$warnings off} {$ENDIF} //comparison always false warning
  2109. if (current_settings.packenum=8) or (min<low(longint)) or (int64(max)>high(cardinal)) then
  2110. savesize:=8
  2111. {$IFDEF not cpu64bitaddr} {$pop} {$ENDIF}
  2112. else
  2113. if (current_settings.packenum=4) or (min<low(smallint)) or (max>high(word)) then
  2114. savesize:=4
  2115. else
  2116. if (current_settings.packenum=2) or (min<low(shortint)) or (max>high(byte)) then
  2117. savesize:=2
  2118. else
  2119. savesize:=1;
  2120. end;
  2121. function tenumdef.packedbitsize: asizeint;
  2122. var
  2123. sizeval: tconstexprint;
  2124. power: longint;
  2125. begin
  2126. result := 0;
  2127. if (minval >= 0) and
  2128. (maxval <= 1) then
  2129. result := 1
  2130. else
  2131. begin
  2132. if (minval>=0) then
  2133. sizeval:=maxval
  2134. else
  2135. { don't count 0 twice }
  2136. sizeval:=(cutils.max(-minval,maxval)*2)-1;
  2137. { 256 must become 512 etc. }
  2138. nextpowerof2(sizeval+1,power);
  2139. result := power;
  2140. end;
  2141. end;
  2142. procedure tenumdef.setmax(_max:asizeint);
  2143. begin
  2144. maxval:=_max;
  2145. calcsavesize;
  2146. end;
  2147. procedure tenumdef.setmin(_min:asizeint);
  2148. begin
  2149. minval:=_min;
  2150. calcsavesize;
  2151. end;
  2152. function tenumdef.min:asizeint;
  2153. begin
  2154. min:=minval;
  2155. end;
  2156. function tenumdef.max:asizeint;
  2157. begin
  2158. max:=maxval;
  2159. end;
  2160. function tenumdef.getfirstsym: tsym;
  2161. var
  2162. i:integer;
  2163. begin
  2164. for i := 0 to symtable.SymList.Count - 1 do
  2165. begin
  2166. result:=tsym(symtable.SymList[i]);
  2167. if tenumsym(result).value=minval then
  2168. exit;
  2169. end;
  2170. result:=nil;
  2171. end;
  2172. function tenumdef.int2enumsym(l: asizeint): tsym;
  2173. var
  2174. i: longint;
  2175. sym: tsym;
  2176. bdef: tenumdef;
  2177. begin
  2178. result:=nil;
  2179. if (l<minval) or
  2180. (l>maxval) then
  2181. exit;
  2182. bdef:=getbasedef;
  2183. for i:=0 to bdef.symtable.symlist.count-1 do
  2184. begin
  2185. sym:=tsym(bdef.symtable.symlist[i]);
  2186. if (sym.typ=enumsym) and
  2187. (tenumsym(sym).value=l) then
  2188. begin
  2189. result:=sym;
  2190. exit;
  2191. end;
  2192. end;
  2193. end;
  2194. function tenumdef.getbasedef: tenumdef;
  2195. begin
  2196. if not assigned(basedef) then
  2197. result:=self
  2198. else
  2199. result:=basedef;
  2200. end;
  2201. procedure tenumdef.buildderef;
  2202. begin
  2203. inherited buildderef;
  2204. if df_copied_def in defoptions then
  2205. basedefderef.build(basedef)
  2206. else
  2207. tenumsymtable(symtable).buildderef;
  2208. {$ifdef jvm}
  2209. classdefderef.build(classdef);
  2210. {$endif}
  2211. end;
  2212. procedure tenumdef.deref;
  2213. begin
  2214. inherited deref;
  2215. if df_copied_def in defoptions then
  2216. begin
  2217. basedef:=tenumdef(basedefderef.resolve);
  2218. symtable:=basedef.symtable.getcopy;
  2219. end
  2220. else
  2221. tenumsymtable(symtable).deref;
  2222. {$ifdef jvm}
  2223. classdef:=tobjectdef(classdefderef.resolve);
  2224. {$endif}
  2225. end;
  2226. procedure tenumdef.ppuwrite(ppufile:tcompilerppufile);
  2227. begin
  2228. inherited ppuwrite(ppufile);
  2229. ppufile.putaint(min);
  2230. ppufile.putaint(max);
  2231. ppufile.putaint(savesize);
  2232. {$ifdef jvm}
  2233. ppufile.putderef(classdefderef);
  2234. {$endif}
  2235. if df_copied_def in defoptions then
  2236. ppufile.putderef(basedefderef);
  2237. ppufile.writeentry(ibenumdef);
  2238. if not (df_copied_def in defoptions) then
  2239. tenumsymtable(symtable).ppuwrite(ppufile);
  2240. end;
  2241. function tenumdef.is_publishable : boolean;
  2242. begin
  2243. is_publishable:=true;
  2244. end;
  2245. function tenumdef.GetTypeName : string;
  2246. begin
  2247. GetTypeName:='<enumeration type>';
  2248. end;
  2249. {****************************************************************************
  2250. TORDDEF
  2251. ****************************************************************************}
  2252. constructor torddef.create(t : tordtype;v,b : TConstExprInt);
  2253. begin
  2254. inherited create(orddef);
  2255. low:=v;
  2256. high:=b;
  2257. ordtype:=t;
  2258. setsize;
  2259. end;
  2260. constructor torddef.ppuload(ppufile:tcompilerppufile);
  2261. begin
  2262. inherited ppuload(orddef,ppufile);
  2263. ordtype:=tordtype(ppufile.getbyte);
  2264. low:=ppufile.getexprint;
  2265. high:=ppufile.getexprint;
  2266. setsize;
  2267. end;
  2268. function torddef.getcopy : tstoreddef;
  2269. begin
  2270. result:=torddef.create(ordtype,low,high);
  2271. result.typ:=orddef;
  2272. torddef(result).low:=low;
  2273. torddef(result).high:=high;
  2274. torddef(result).ordtype:=ordtype;
  2275. torddef(result).savesize:=savesize;
  2276. end;
  2277. function torddef.alignment:shortint;
  2278. begin
  2279. if (target_info.system in [system_i386_darwin,system_i386_iphonesim,system_arm_darwin]) and
  2280. (ordtype in [s64bit,u64bit]) then
  2281. result := 4
  2282. else
  2283. result := inherited alignment;
  2284. end;
  2285. procedure torddef.setsize;
  2286. const
  2287. sizetbl : array[tordtype] of longint = (
  2288. 0,
  2289. 1,2,4,8,
  2290. 1,2,4,8,
  2291. 1,2,4,8,
  2292. 1,2,4,8,
  2293. 1,2,8
  2294. );
  2295. begin
  2296. savesize:=sizetbl[ordtype];
  2297. end;
  2298. function torddef.packedbitsize: asizeint;
  2299. var
  2300. sizeval: tconstexprint;
  2301. power: longint;
  2302. begin
  2303. result := 0;
  2304. if ordtype = uvoid then
  2305. exit;
  2306. {$ifndef cpu64bitalu}
  2307. if (ordtype in [s64bit,u64bit]) then
  2308. {$else not cpu64bitalu}
  2309. if (ordtype = u64bit) or
  2310. ((ordtype = s64bit) and
  2311. ((low <= (system.low(int64) div 2)) or
  2312. (high > (system.high(int64) div 2)))) then
  2313. {$endif cpu64bitalu}
  2314. result := 64
  2315. else if (low >= 0) and
  2316. (high <= 1) then
  2317. result := 1
  2318. else
  2319. begin
  2320. if (low>=0) then
  2321. sizeval:=high
  2322. else
  2323. { don't count 0 twice }
  2324. sizeval:=(cutils.max(-low,high)*2)-1;
  2325. { 256 must become 512 etc. }
  2326. nextpowerof2(sizeval+1,power);
  2327. result := power;
  2328. end;
  2329. end;
  2330. function torddef.getvardef : longint;
  2331. const
  2332. basetype2vardef : array[tordtype] of longint = (
  2333. varUndefined,
  2334. varbyte,varword,varlongword,varqword,
  2335. varshortint,varsmallint,varinteger,varint64,
  2336. varboolean,varboolean,varboolean,varboolean,
  2337. varboolean,varboolean,varUndefined,varUndefined,
  2338. varUndefined,varUndefined,varCurrency);
  2339. begin
  2340. result:=basetype2vardef[ordtype];
  2341. end;
  2342. procedure torddef.ppuwrite(ppufile:tcompilerppufile);
  2343. begin
  2344. inherited ppuwrite(ppufile);
  2345. ppufile.putbyte(byte(ordtype));
  2346. ppufile.putexprint(low);
  2347. ppufile.putexprint(high);
  2348. ppufile.writeentry(iborddef);
  2349. end;
  2350. function torddef.is_publishable : boolean;
  2351. begin
  2352. is_publishable:=(ordtype<>uvoid);
  2353. end;
  2354. function torddef.GetTypeName : string;
  2355. const
  2356. names : array[tordtype] of string[20] = (
  2357. 'untyped',
  2358. 'Byte','Word','DWord','QWord',
  2359. 'ShortInt','SmallInt','LongInt','Int64',
  2360. 'Boolean','Boolean16','Boolean32','Boolean64',
  2361. 'ByteBool','WordBool','LongBool','QWordBool',
  2362. 'Char','WideChar','Currency');
  2363. begin
  2364. GetTypeName:=names[ordtype];
  2365. end;
  2366. {****************************************************************************
  2367. TFLOATDEF
  2368. ****************************************************************************}
  2369. constructor tfloatdef.create(t : tfloattype);
  2370. begin
  2371. inherited create(floatdef);
  2372. floattype:=t;
  2373. setsize;
  2374. end;
  2375. constructor tfloatdef.ppuload(ppufile:tcompilerppufile);
  2376. begin
  2377. inherited ppuload(floatdef,ppufile);
  2378. floattype:=tfloattype(ppufile.getbyte);
  2379. setsize;
  2380. end;
  2381. function tfloatdef.getcopy : tstoreddef;
  2382. begin
  2383. result:=tfloatdef.create(floattype);
  2384. result.typ:=floatdef;
  2385. tfloatdef(result).savesize:=savesize;
  2386. end;
  2387. function tfloatdef.alignment:shortint;
  2388. begin
  2389. if (target_info.system in [system_i386_darwin,system_i386_iphonesim,system_arm_darwin]) then
  2390. case floattype of
  2391. sc80real,
  2392. s80real: result:=16;
  2393. s64real,
  2394. s64currency,
  2395. s64comp : result:=4;
  2396. else
  2397. result := inherited alignment;
  2398. end
  2399. else
  2400. result := inherited alignment;
  2401. end;
  2402. function tfloatdef.structalignment: shortint;
  2403. begin
  2404. { aix is really annoying: the recommended scalar alignment for both
  2405. int64 and double is 64 bits, but in structs int64 has to be aligned
  2406. to 8 bytes and double to 4 bytes }
  2407. if (target_info.system in systems_aix) and
  2408. (floattype=s64real) then
  2409. result:=4
  2410. else
  2411. result:=alignment;
  2412. end;
  2413. procedure tfloatdef.setsize;
  2414. begin
  2415. case floattype of
  2416. s32real : savesize:=4;
  2417. s80real : savesize:=10;
  2418. sc80real:
  2419. if target_info.system in [system_i386_darwin,system_i386_iphonesim,system_x86_64_darwin,
  2420. system_x86_64_linux,system_x86_64_freebsd,
  2421. system_x86_64_openbsd,system_x86_64_netbsd,
  2422. system_x86_64_solaris,system_x86_64_embedded] then
  2423. savesize:=16
  2424. else
  2425. savesize:=12;
  2426. s64real,
  2427. s64currency,
  2428. s64comp : savesize:=8;
  2429. else
  2430. savesize:=0;
  2431. end;
  2432. end;
  2433. function tfloatdef.getvardef : longint;
  2434. const
  2435. floattype2vardef : array[tfloattype] of longint = (
  2436. varSingle,varDouble,varUndefined,varUndefined,
  2437. varUndefined,varCurrency,varUndefined);
  2438. begin
  2439. if (upper(typename)='TDATETIME') and
  2440. assigned(owner) and
  2441. assigned(owner.name) and
  2442. (owner.name^='SYSTEM') then
  2443. result:=varDate
  2444. else
  2445. result:=floattype2vardef[floattype];
  2446. end;
  2447. procedure tfloatdef.ppuwrite(ppufile:tcompilerppufile);
  2448. begin
  2449. inherited ppuwrite(ppufile);
  2450. ppufile.putbyte(byte(floattype));
  2451. ppufile.writeentry(ibfloatdef);
  2452. end;
  2453. function tfloatdef.is_publishable : boolean;
  2454. begin
  2455. is_publishable:=true;
  2456. end;
  2457. function tfloatdef.GetTypeName : string;
  2458. const
  2459. names : array[tfloattype] of string[20] = (
  2460. 'Single','Double','Extended','CExtended','Comp','Currency','Float128');
  2461. begin
  2462. GetTypeName:=names[floattype];
  2463. end;
  2464. {****************************************************************************
  2465. TFILEDEF
  2466. ****************************************************************************}
  2467. constructor tfiledef.createtext;
  2468. begin
  2469. inherited create(filedef);
  2470. filetyp:=ft_text;
  2471. typedfiledef:=nil;
  2472. end;
  2473. constructor tfiledef.createuntyped;
  2474. begin
  2475. inherited create(filedef);
  2476. filetyp:=ft_untyped;
  2477. typedfiledef:=nil;
  2478. end;
  2479. constructor tfiledef.createtyped(def:tdef);
  2480. begin
  2481. inherited create(filedef);
  2482. filetyp:=ft_typed;
  2483. typedfiledef:=def;
  2484. end;
  2485. constructor tfiledef.ppuload(ppufile:tcompilerppufile);
  2486. begin
  2487. inherited ppuload(filedef,ppufile);
  2488. filetyp:=tfiletyp(ppufile.getbyte);
  2489. if filetyp=ft_typed then
  2490. ppufile.getderef(typedfiledefderef)
  2491. else
  2492. typedfiledef:=nil;
  2493. end;
  2494. function tfiledef.getcopy : tstoreddef;
  2495. begin
  2496. case filetyp of
  2497. ft_typed:
  2498. result:=tfiledef.createtyped(typedfiledef);
  2499. ft_untyped:
  2500. result:=tfiledef.createuntyped;
  2501. ft_text:
  2502. result:=tfiledef.createtext;
  2503. else
  2504. internalerror(2004121201);
  2505. end;
  2506. end;
  2507. procedure tfiledef.buildderef;
  2508. begin
  2509. inherited buildderef;
  2510. if filetyp=ft_typed then
  2511. typedfiledefderef.build(typedfiledef);
  2512. end;
  2513. procedure tfiledef.deref;
  2514. begin
  2515. inherited deref;
  2516. if filetyp=ft_typed then
  2517. typedfiledef:=tdef(typedfiledefderef.resolve);
  2518. end;
  2519. function tfiledef.size:asizeint;
  2520. begin
  2521. if savesize=0 then
  2522. setsize;
  2523. size:=savesize;
  2524. end;
  2525. procedure tfiledef.setsize;
  2526. begin
  2527. case filetyp of
  2528. ft_text:
  2529. savesize:=search_system_type('TEXTREC').typedef.size;
  2530. ft_typed:
  2531. begin
  2532. savesize:=search_system_type('FILEREC').typedef.size;
  2533. { allocate put/get buffer in iso mode }
  2534. if m_iso in current_settings.modeswitches then
  2535. inc(savesize,typedfiledef.size);
  2536. end;
  2537. ft_untyped:
  2538. savesize:=search_system_type('FILEREC').typedef.size;
  2539. else
  2540. internalerror(2013113001);
  2541. end;
  2542. end;
  2543. procedure tfiledef.ppuwrite(ppufile:tcompilerppufile);
  2544. begin
  2545. inherited ppuwrite(ppufile);
  2546. ppufile.putbyte(byte(filetyp));
  2547. if filetyp=ft_typed then
  2548. ppufile.putderef(typedfiledefderef);
  2549. ppufile.writeentry(ibfiledef);
  2550. end;
  2551. function tfiledef.GetTypeName : string;
  2552. begin
  2553. case filetyp of
  2554. ft_untyped:
  2555. GetTypeName:='File';
  2556. ft_typed:
  2557. GetTypeName:='File Of '+typedfiledef.typename;
  2558. ft_text:
  2559. GetTypeName:='Text'
  2560. else
  2561. internalerror(2013113002);
  2562. end;
  2563. end;
  2564. function tfiledef.getmangledparaname : TSymStr;
  2565. begin
  2566. case filetyp of
  2567. ft_untyped:
  2568. getmangledparaname:='FILE';
  2569. ft_typed:
  2570. getmangledparaname:='FILE$OF$'+typedfiledef.mangledparaname;
  2571. ft_text:
  2572. getmangledparaname:='TEXT'
  2573. else
  2574. internalerror(2013113003);
  2575. end;
  2576. end;
  2577. {****************************************************************************
  2578. TVARIANTDEF
  2579. ****************************************************************************}
  2580. constructor tvariantdef.create(v : tvarianttype);
  2581. begin
  2582. inherited create(variantdef);
  2583. varianttype:=v;
  2584. setsize;
  2585. end;
  2586. constructor tvariantdef.ppuload(ppufile:tcompilerppufile);
  2587. begin
  2588. inherited ppuload(variantdef,ppufile);
  2589. varianttype:=tvarianttype(ppufile.getbyte);
  2590. setsize;
  2591. end;
  2592. function tvariantdef.getcopy : tstoreddef;
  2593. begin
  2594. result:=tvariantdef.create(varianttype);
  2595. end;
  2596. procedure tvariantdef.ppuwrite(ppufile:tcompilerppufile);
  2597. begin
  2598. inherited ppuwrite(ppufile);
  2599. ppufile.putbyte(byte(varianttype));
  2600. ppufile.writeentry(ibvariantdef);
  2601. end;
  2602. function tvariantdef.getvardef : longint;
  2603. begin
  2604. Result:=varVariant;
  2605. end;
  2606. procedure tvariantdef.setsize;
  2607. begin
  2608. {$ifdef cpu64bitaddr}
  2609. savesize:=24;
  2610. {$else cpu64bitaddr}
  2611. savesize:=16;
  2612. {$endif cpu64bitaddr}
  2613. end;
  2614. function tvariantdef.GetTypeName : string;
  2615. begin
  2616. case varianttype of
  2617. vt_normalvariant:
  2618. GetTypeName:='Variant';
  2619. vt_olevariant:
  2620. GetTypeName:='OleVariant';
  2621. else
  2622. internalerror(2013113004);
  2623. end;
  2624. end;
  2625. function tvariantdef.needs_inittable : boolean;
  2626. begin
  2627. needs_inittable:=true;
  2628. end;
  2629. function tvariantdef.is_publishable : boolean;
  2630. begin
  2631. is_publishable:=true;
  2632. end;
  2633. {****************************************************************************
  2634. TABSTRACtpointerdef
  2635. ****************************************************************************}
  2636. constructor tabstractpointerdef.create(dt:tdeftyp;def:tdef);
  2637. begin
  2638. inherited create(dt);
  2639. pointeddef:=def;
  2640. savesize:=sizeof(pint);
  2641. end;
  2642. constructor tabstractpointerdef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  2643. begin
  2644. inherited ppuload(dt,ppufile);
  2645. ppufile.getderef(pointeddefderef);
  2646. savesize:=sizeof(pint);
  2647. end;
  2648. procedure tabstractpointerdef.buildderef;
  2649. begin
  2650. inherited buildderef;
  2651. pointeddefderef.build(pointeddef);
  2652. end;
  2653. procedure tabstractpointerdef.deref;
  2654. begin
  2655. inherited deref;
  2656. pointeddef:=tdef(pointeddefderef.resolve);
  2657. end;
  2658. procedure tabstractpointerdef.ppuwrite(ppufile:tcompilerppufile);
  2659. begin
  2660. inherited ppuwrite(ppufile);
  2661. ppufile.putderef(pointeddefderef);
  2662. end;
  2663. {****************************************************************************
  2664. tpointerdef
  2665. ****************************************************************************}
  2666. constructor tpointerdef.create(def:tdef);
  2667. begin
  2668. inherited create(pointerdef,def);
  2669. {$ifdef x86}
  2670. x86pointertyp := default_x86_data_pointer_type;
  2671. {$endif x86}
  2672. has_pointer_math:=cs_pointermath in current_settings.localswitches;
  2673. end;
  2674. {$ifdef x86}
  2675. constructor tpointerdef.createx86(def: tdef; x86typ: tx86pointertyp);
  2676. begin
  2677. inherited create(pointerdef,def);
  2678. x86pointertyp := x86typ;
  2679. has_pointer_math:=cs_pointermath in current_settings.localswitches;
  2680. end;
  2681. {$endif x86}
  2682. function tpointerdef.size: asizeint;
  2683. begin
  2684. {$ifdef x86}
  2685. if x86pointertyp in [x86pt_far,x86pt_huge] then
  2686. result:=sizeof(pint)+2
  2687. else
  2688. {$endif x86}
  2689. result:=sizeof(pint);
  2690. end;
  2691. constructor tpointerdef.ppuload(ppufile:tcompilerppufile);
  2692. begin
  2693. inherited ppuload(pointerdef,ppufile);
  2694. {$ifdef x86}
  2695. x86pointertyp:=tx86pointertyp(ppufile.getbyte);
  2696. {$endif x86}
  2697. has_pointer_math:=(ppufile.getbyte<>0);
  2698. end;
  2699. function tpointerdef.getcopy : tstoreddef;
  2700. begin
  2701. { don't use direct pointeddef if it is a forwarddef because in other case
  2702. one of them will be destroyed on forward type resolve and the second will
  2703. point to garbage }
  2704. if pointeddef.typ=forwarddef then
  2705. result:=tpointerdef.create(tforwarddef(pointeddef).getcopy)
  2706. else
  2707. result:=tpointerdef.create(pointeddef);
  2708. {$ifdef x86}
  2709. tpointerdef(result).x86pointertyp:=x86pointertyp;
  2710. {$endif x86}
  2711. tpointerdef(result).has_pointer_math:=has_pointer_math;
  2712. tpointerdef(result).savesize:=savesize;
  2713. end;
  2714. procedure tpointerdef.ppuwrite(ppufile:tcompilerppufile);
  2715. begin
  2716. inherited ppuwrite(ppufile);
  2717. {$ifdef x86}
  2718. ppufile.putbyte(byte(x86pointertyp));
  2719. {$endif x86}
  2720. ppufile.putbyte(byte(has_pointer_math));
  2721. ppufile.writeentry(ibpointerdef);
  2722. end;
  2723. function tpointerdef.GetTypeName : string;
  2724. begin
  2725. { parameter types and the resultdef of a procvardef can contain a
  2726. pointer to this procvardef itself, resulting in endless recursion ->
  2727. use the typesym's name instead if it exists (if it doesn't, such as
  2728. for anynonymous procedure types in macpas/iso mode, then there cannot
  2729. be any recursive references to it either) }
  2730. if (pointeddef.typ<>procvardef) or
  2731. not assigned(pointeddef.typesym) then
  2732. GetTypeName:='^'+pointeddef.typename
  2733. else
  2734. GetTypeName:='^'+pointeddef.typesym.realname;
  2735. {$ifdef x86}
  2736. if x86pointertyp<>default_x86_data_pointer_type then
  2737. begin
  2738. case x86pointertyp of
  2739. x86pt_near:
  2740. GetTypeName:=Result+';near';
  2741. x86pt_near_cs:
  2742. GetTypeName:=Result+';near ''CS''';
  2743. x86pt_near_ds:
  2744. GetTypeName:=Result+';near ''DS''';
  2745. x86pt_near_ss:
  2746. GetTypeName:=Result+';near ''SS''';
  2747. x86pt_near_es:
  2748. GetTypeName:=Result+';near ''ES''';
  2749. x86pt_near_fs:
  2750. GetTypeName:=Result+';near ''FS''';
  2751. x86pt_near_gs:
  2752. GetTypeName:=Result+';near ''GS''';
  2753. x86pt_far:
  2754. GetTypeName:=Result+';far';
  2755. x86pt_huge:
  2756. GetTypeName:=Result+';huge';
  2757. else
  2758. internalerror(2013050301);
  2759. end;
  2760. end;
  2761. {$endif x86}
  2762. end;
  2763. {****************************************************************************
  2764. TCLASSREFDEF
  2765. ****************************************************************************}
  2766. constructor tclassrefdef.create(def:tdef);
  2767. begin
  2768. inherited create(classrefdef,def);
  2769. end;
  2770. constructor tclassrefdef.ppuload(ppufile:tcompilerppufile);
  2771. begin
  2772. inherited ppuload(classrefdef,ppufile);
  2773. end;
  2774. procedure tclassrefdef.ppuwrite(ppufile:tcompilerppufile);
  2775. begin
  2776. inherited ppuwrite(ppufile);
  2777. ppufile.writeentry(ibclassrefdef);
  2778. end;
  2779. function tclassrefdef.getcopy:tstoreddef;
  2780. begin
  2781. if pointeddef.typ=forwarddef then
  2782. result:=tclassrefdef.create(tforwarddef(pointeddef).getcopy)
  2783. else
  2784. result:=tclassrefdef.create(pointeddef);
  2785. tclassrefdef(result).savesize:=savesize;
  2786. end;
  2787. function tclassrefdef.GetTypeName : string;
  2788. begin
  2789. GetTypeName:='Class Of '+pointeddef.typename;
  2790. end;
  2791. function tclassrefdef.is_publishable : boolean;
  2792. begin
  2793. result:=true;
  2794. end;
  2795. function tclassrefdef.rtti_mangledname(rt: trttitype): string;
  2796. begin
  2797. if (tobjectdef(pointeddef).objecttype<>odt_objcclass) then
  2798. result:=inherited rtti_mangledname(rt)
  2799. else
  2800. result:=tobjectdef(pointeddef).rtti_mangledname(objcmetartti);
  2801. end;
  2802. procedure tclassrefdef.register_created_object_type;
  2803. begin
  2804. tobjectdef(pointeddef).register_created_classref_type;
  2805. end;
  2806. {***************************************************************************
  2807. TSETDEF
  2808. ***************************************************************************}
  2809. constructor tsetdef.create(def:tdef;low, high : asizeint);
  2810. var
  2811. setallocbits: aint;
  2812. packedsavesize: aint;
  2813. begin
  2814. inherited create(setdef);
  2815. elementdef:=def;
  2816. setmax:=high;
  2817. if (current_settings.setalloc=0) then
  2818. begin
  2819. setbase:=0;
  2820. if (high<32) then
  2821. savesize:=Sizeof(longint)
  2822. else if (high<256) then
  2823. savesize:=32
  2824. else
  2825. savesize:=(high+7) div 8
  2826. end
  2827. else
  2828. begin
  2829. setallocbits:=current_settings.setalloc*8;
  2830. setbase:=low and not(setallocbits-1);
  2831. packedsavesize:=current_settings.setalloc*((((high+setallocbits)-setbase)) DIV setallocbits);
  2832. savesize:=packedsavesize;
  2833. if savesize=3 then
  2834. savesize:=4;
  2835. end;
  2836. end;
  2837. constructor tsetdef.ppuload(ppufile:tcompilerppufile);
  2838. begin
  2839. inherited ppuload(setdef,ppufile);
  2840. ppufile.getderef(elementdefderef);
  2841. savesize:=ppufile.getaint;
  2842. setbase:=ppufile.getaint;
  2843. setmax:=ppufile.getaint;
  2844. end;
  2845. function tsetdef.getcopy : tstoreddef;
  2846. begin
  2847. result:=tsetdef.create(elementdef,setbase,setmax);
  2848. { the copy might have been created with a different setalloc setting }
  2849. tsetdef(result).savesize:=savesize;
  2850. end;
  2851. procedure tsetdef.ppuwrite(ppufile:tcompilerppufile);
  2852. begin
  2853. inherited ppuwrite(ppufile);
  2854. ppufile.putderef(elementdefderef);
  2855. ppufile.putaint(savesize);
  2856. ppufile.putaint(setbase);
  2857. ppufile.putaint(setmax);
  2858. ppufile.writeentry(ibsetdef);
  2859. end;
  2860. procedure tsetdef.buildderef;
  2861. begin
  2862. inherited buildderef;
  2863. elementdefderef.build(elementdef);
  2864. end;
  2865. procedure tsetdef.deref;
  2866. begin
  2867. inherited deref;
  2868. elementdef:=tdef(elementdefderef.resolve);
  2869. end;
  2870. function tsetdef.is_publishable : boolean;
  2871. begin
  2872. is_publishable:=savesize in [1,2,4];
  2873. end;
  2874. function tsetdef.GetTypeName : string;
  2875. begin
  2876. if assigned(elementdef) then
  2877. GetTypeName:='Set Of '+elementdef.typename
  2878. else
  2879. GetTypeName:='Empty Set';
  2880. end;
  2881. {***************************************************************************
  2882. TFORMALDEF
  2883. ***************************************************************************}
  2884. constructor tformaldef.create(Atyped:boolean);
  2885. begin
  2886. inherited create(formaldef);
  2887. typed:=Atyped;
  2888. savesize:=0;
  2889. end;
  2890. constructor tformaldef.ppuload(ppufile:tcompilerppufile);
  2891. begin
  2892. inherited ppuload(formaldef,ppufile);
  2893. typed:=boolean(ppufile.getbyte);
  2894. savesize:=0;
  2895. end;
  2896. procedure tformaldef.ppuwrite(ppufile:tcompilerppufile);
  2897. begin
  2898. inherited ppuwrite(ppufile);
  2899. ppufile.putbyte(byte(typed));
  2900. ppufile.writeentry(ibformaldef);
  2901. end;
  2902. function tformaldef.GetTypeName : string;
  2903. begin
  2904. if typed then
  2905. GetTypeName:='<Typed formal type>'
  2906. else
  2907. GetTypeName:='<Formal type>';
  2908. end;
  2909. {***************************************************************************
  2910. TARRAYDEF
  2911. ***************************************************************************}
  2912. constructor tarraydef.create(l,h:asizeint;def:tdef);
  2913. begin
  2914. inherited create(arraydef);
  2915. lowrange:=l;
  2916. highrange:=h;
  2917. rangedef:=def;
  2918. _elementdef:=nil;
  2919. arrayoptions:=[];
  2920. symtable:=tarraysymtable.create(self);
  2921. end;
  2922. destructor tarraydef.destroy;
  2923. begin
  2924. symtable.free;
  2925. symtable:=nil;
  2926. inherited;
  2927. end;
  2928. constructor tarraydef.create_from_pointer(def:tdef);
  2929. begin
  2930. { use -1 so that the elecount will not overflow }
  2931. self.create(0,high(asizeint)-1,ptrsinttype);
  2932. arrayoptions:=[ado_IsConvertedPointer];
  2933. setelementdef(def);
  2934. end;
  2935. constructor tarraydef.ppuload(ppufile:tcompilerppufile);
  2936. begin
  2937. inherited ppuload(arraydef,ppufile);
  2938. { the addresses are calculated later }
  2939. ppufile.getderef(_elementdefderef);
  2940. ppufile.getderef(rangedefderef);
  2941. lowrange:=ppufile.getasizeint;
  2942. highrange:=ppufile.getasizeint;
  2943. ppufile.getsmallset(arrayoptions);
  2944. symtable:=tarraysymtable.create(self);
  2945. tarraysymtable(symtable).ppuload(ppufile)
  2946. end;
  2947. function tarraydef.getcopy : tstoreddef;
  2948. begin
  2949. result:=tarraydef.create(lowrange,highrange,rangedef);
  2950. tarraydef(result).arrayoptions:=arrayoptions;
  2951. tarraydef(result)._elementdef:=_elementdef;
  2952. end;
  2953. procedure tarraydef.buildderef;
  2954. begin
  2955. inherited buildderef;
  2956. tarraysymtable(symtable).buildderef;
  2957. _elementdefderef.build(_elementdef);
  2958. rangedefderef.build(rangedef);
  2959. end;
  2960. procedure tarraydef.deref;
  2961. begin
  2962. inherited deref;
  2963. tarraysymtable(symtable).deref;
  2964. _elementdef:=tdef(_elementdefderef.resolve);
  2965. rangedef:=tdef(rangedefderef.resolve);
  2966. fillgenericparas(symtable);
  2967. end;
  2968. procedure tarraydef.ppuwrite(ppufile:tcompilerppufile);
  2969. begin
  2970. inherited ppuwrite(ppufile);
  2971. ppufile.putderef(_elementdefderef);
  2972. ppufile.putderef(rangedefderef);
  2973. ppufile.putasizeint(lowrange);
  2974. ppufile.putasizeint(highrange);
  2975. ppufile.putsmallset(arrayoptions);
  2976. ppufile.writeentry(ibarraydef);
  2977. tarraysymtable(symtable).ppuwrite(ppufile);
  2978. end;
  2979. function tarraydef.elesize : asizeint;
  2980. begin
  2981. if (ado_IsBitPacked in arrayoptions) then
  2982. internalerror(2006080101);
  2983. if assigned(_elementdef) then
  2984. result:=_elementdef.size
  2985. else
  2986. result:=0;
  2987. end;
  2988. function tarraydef.elepackedbitsize : asizeint;
  2989. begin
  2990. if not(ado_IsBitPacked in arrayoptions) then
  2991. internalerror(2006080102);
  2992. if assigned(_elementdef) then
  2993. result:=_elementdef.packedbitsize
  2994. else
  2995. result:=0;
  2996. end;
  2997. function tarraydef.elecount : asizeuint;
  2998. var
  2999. qhigh,qlow : qword;
  3000. begin
  3001. if ado_IsDynamicArray in arrayoptions then
  3002. begin
  3003. result:=0;
  3004. exit;
  3005. end;
  3006. if (highrange>0) and (lowrange<0) then
  3007. begin
  3008. qhigh:=highrange;
  3009. qlow:=qword(-lowrange);
  3010. { prevent overflow, return 0 to indicate overflow }
  3011. if qhigh+qlow>qword(high(asizeint)-1) then
  3012. result:=0
  3013. else
  3014. result:=qhigh+qlow+1;
  3015. end
  3016. else
  3017. result:=int64(highrange)-lowrange+1;
  3018. end;
  3019. function tarraydef.size : asizeint;
  3020. var
  3021. cachedelecount : asizeuint;
  3022. cachedelesize : asizeint;
  3023. begin
  3024. if ado_IsDynamicArray in arrayoptions then
  3025. begin
  3026. size:=sizeof(pint);
  3027. exit;
  3028. end;
  3029. { Tarraydef.size may never be called for an open array! }
  3030. if highrange<lowrange then
  3031. internalerror(99080501);
  3032. if not (ado_IsBitPacked in arrayoptions) then
  3033. cachedelesize:=elesize
  3034. else
  3035. cachedelesize := elepackedbitsize;
  3036. cachedelecount:=elecount;
  3037. if (cachedelesize = 0) then
  3038. begin
  3039. size := 0;
  3040. exit;
  3041. end;
  3042. if (cachedelecount = 0) then
  3043. begin
  3044. size := -1;
  3045. exit;
  3046. end;
  3047. { prevent overflow, return -1 to indicate overflow }
  3048. { also make sure we don't need 64/128 bit arithmetic to calculate offsets }
  3049. if (cachedelecount > asizeuint(high(asizeint))) or
  3050. ((high(asizeint) div cachedelesize) < asizeint(cachedelecount)) or
  3051. { also lowrange*elesize must be < high(asizeint) to prevent overflow when
  3052. accessing the array, see ncgmem (PFV) }
  3053. ((high(asizeint) div cachedelesize) < abs(lowrange)) then
  3054. begin
  3055. result:=-1;
  3056. exit;
  3057. end;
  3058. result:=cachedelesize*asizeint(cachedelecount);
  3059. if (ado_IsBitPacked in arrayoptions) then
  3060. { can't just add 7 and divide by 8, because that may overflow }
  3061. result:=result div 8 + ord((result mod 8)<>0);
  3062. end;
  3063. procedure tarraydef.setelementdef(def:tdef);
  3064. begin
  3065. _elementdef:=def;
  3066. if not(
  3067. (ado_IsDynamicArray in arrayoptions) or
  3068. (ado_IsConvertedPointer in arrayoptions) or
  3069. (highrange<lowrange)
  3070. ) and
  3071. (size=-1) then
  3072. Message(sym_e_segment_too_large);
  3073. end;
  3074. function tarraydef.alignment : shortint;
  3075. begin
  3076. { alignment of dyn. arrays doesn't depend on the element size }
  3077. if (ado_IsDynamicArray in arrayoptions) then
  3078. alignment:=size_2_align(sizeof(pint))
  3079. { alignment is the target alignment for the used load size }
  3080. else if (ado_IsBitPacked in arrayoptions) and
  3081. (elementdef.typ in [enumdef,orddef]) then
  3082. alignment:=cgsize_orddef(int_cgsize(packedbitsloadsize(elepackedbitsize))).alignment
  3083. { alignment is the alignment of the elements }
  3084. else
  3085. alignment:=elementdef.alignment
  3086. end;
  3087. function tarraydef.needs_inittable : boolean;
  3088. begin
  3089. needs_inittable:=(ado_IsDynamicArray in arrayoptions) or elementdef.needs_inittable;
  3090. end;
  3091. function tarraydef.needs_separate_initrtti : boolean;
  3092. begin
  3093. if ado_IsBitPacked in arrayoptions then
  3094. result:=false
  3095. else
  3096. result:=elementdef.needs_separate_initrtti;
  3097. end;
  3098. function tarraydef.GetTypeName : string;
  3099. begin
  3100. if (ado_IsConstString in arrayoptions) then
  3101. result:='Constant String'
  3102. else if (ado_isarrayofconst in arrayoptions) or
  3103. (ado_isConstructor in arrayoptions) then
  3104. begin
  3105. if (ado_isvariant in arrayoptions) or ((highrange=-1) and (lowrange=0)) then
  3106. GetTypeName:='Array Of Const'
  3107. else
  3108. GetTypeName:='{Array Of Const/Constant Open} Array of '+elementdef.typename;
  3109. end
  3110. else if (ado_IsDynamicArray in arrayoptions) then
  3111. GetTypeName:='{Dynamic} Array Of '+elementdef.typename
  3112. else if ((highrange=-1) and (lowrange=0)) then
  3113. GetTypeName:='{Open} Array Of '+elementdef.typename
  3114. else
  3115. begin
  3116. result := '';
  3117. if (ado_IsBitPacked in arrayoptions) then
  3118. result:='BitPacked ';
  3119. if rangedef.typ=enumdef then
  3120. result:=result+'Array['+rangedef.typename+'] Of '+elementdef.typename
  3121. else
  3122. result:=result+'Array['+tostr(lowrange)+'..'+
  3123. tostr(highrange)+'] Of '+elementdef.typename
  3124. end;
  3125. end;
  3126. function tarraydef.getmangledparaname : TSymStr;
  3127. begin
  3128. if ado_isarrayofconst in arrayoptions then
  3129. getmangledparaname:='array_of_const'
  3130. else
  3131. if ((highrange=-1) and (lowrange=0)) then
  3132. getmangledparaname:='array_of_'+elementdef.mangledparaname
  3133. else
  3134. internalerror(200204176);
  3135. end;
  3136. function tarraydef.is_publishable : boolean;
  3137. begin
  3138. Result:=ado_IsDynamicArray in arrayoptions;
  3139. end;
  3140. {***************************************************************************
  3141. tabstractrecorddef
  3142. ***************************************************************************}
  3143. constructor tabstractrecorddef.create(const n:string; dt:tdeftyp);
  3144. begin
  3145. inherited create(dt);
  3146. objname:=stringdup(upper(n));
  3147. objrealname:=stringdup(n);
  3148. objectoptions:=[];
  3149. if assigned(current_module.namespace) then
  3150. begin
  3151. import_lib:=stringdup(current_module.namespace^);
  3152. replace(import_lib^,'.','/');
  3153. end;
  3154. end;
  3155. constructor tabstractrecorddef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  3156. begin
  3157. inherited ppuload(dt,ppufile);
  3158. objrealname:=stringdup(ppufile.getstring);
  3159. objname:=stringdup(upper(objrealname^));
  3160. import_lib:=stringdup(ppufile.getstring);
  3161. { only used for external C++ classes and Java classes/records }
  3162. if (import_lib^='') then
  3163. stringdispose(import_lib);
  3164. ppufile.getsmallset(objectoptions);
  3165. end;
  3166. procedure tabstractrecorddef.ppuwrite(ppufile: tcompilerppufile);
  3167. begin
  3168. inherited ppuwrite(ppufile);
  3169. ppufile.putstring(objrealname^);
  3170. if assigned(import_lib) then
  3171. ppufile.putstring(import_lib^)
  3172. else
  3173. ppufile.putstring('');
  3174. ppufile.putsmallset(objectoptions);
  3175. end;
  3176. destructor tabstractrecorddef.destroy;
  3177. begin
  3178. stringdispose(objname);
  3179. stringdispose(objrealname);
  3180. stringdispose(import_lib);
  3181. tcinitcode.free;
  3182. inherited destroy;
  3183. end;
  3184. procedure tabstractrecorddef.check_forwards;
  3185. begin
  3186. { the defs of a copied def are defined for the original type only }
  3187. if not(df_copied_def in defoptions) then
  3188. tstoredsymtable(symtable).check_forwards;
  3189. end;
  3190. function tabstractrecorddef.find_procdef_bytype(pt:tproctypeoption): tprocdef;
  3191. var
  3192. i: longint;
  3193. sym: tsym;
  3194. begin
  3195. for i:=0 to symtable.SymList.Count-1 do
  3196. begin
  3197. sym:=tsym(symtable.SymList[i]);
  3198. if sym.typ=procsym then
  3199. begin
  3200. result:=tprocsym(sym).find_procdef_bytype(pt);
  3201. if assigned(result) then
  3202. exit;
  3203. end;
  3204. end;
  3205. result:=nil;
  3206. end;
  3207. function tabstractrecorddef.GetSymtable(t:tGetSymtable):TSymtable;
  3208. begin
  3209. if t=gs_record then
  3210. GetSymtable:=symtable
  3211. else
  3212. GetSymtable:=nil;
  3213. end;
  3214. function tabstractrecorddef.is_packed:boolean;
  3215. begin
  3216. result:=tabstractrecordsymtable(symtable).is_packed;
  3217. end;
  3218. function tabstractrecorddef.RttiName: string;
  3219. begin
  3220. Result:=OwnerHierarchyName+objrealname^;
  3221. end;
  3222. function tabstractrecorddef.search_enumerator_get: tprocdef;
  3223. var
  3224. sym : tsym;
  3225. i : integer;
  3226. pd : tprocdef;
  3227. hashedid : THashedIDString;
  3228. begin
  3229. result:=nil;
  3230. hashedid.id:='GETENUMERATOR';
  3231. sym:=tsym(symtable.FindWithHash(hashedid));
  3232. if assigned(sym) and (sym.typ=procsym) then
  3233. begin
  3234. for i := 0 to Tprocsym(sym).ProcdefList.Count - 1 do
  3235. begin
  3236. pd := tprocdef(Tprocsym(sym).ProcdefList[i]);
  3237. if (pd.proctypeoption = potype_function) and
  3238. (is_class_or_interface_or_object(pd.returndef) or is_record(pd.returndef)) and
  3239. (pd.visibility >= vis_public) then
  3240. begin
  3241. result:=pd;
  3242. exit;
  3243. end;
  3244. end;
  3245. end;
  3246. end;
  3247. function tabstractrecorddef.search_enumerator_move: tprocdef;
  3248. var
  3249. sym : tsym;
  3250. i : integer;
  3251. pd : tprocdef;
  3252. hashedid : THashedIDString;
  3253. begin
  3254. result:=nil;
  3255. // first search for po_enumerator_movenext method modifier
  3256. // then search for public function MoveNext: Boolean
  3257. for i:=0 to symtable.SymList.Count-1 do
  3258. begin
  3259. sym:=TSym(symtable.SymList[i]);
  3260. if (sym.typ=procsym) then
  3261. begin
  3262. pd:=Tprocsym(sym).find_procdef_byoptions([po_enumerator_movenext]);
  3263. if assigned(pd) then
  3264. begin
  3265. result:=pd;
  3266. exit;
  3267. end;
  3268. end;
  3269. end;
  3270. hashedid.id:='MOVENEXT';
  3271. sym:=tsym(symtable.FindWithHash(hashedid));
  3272. if assigned(sym) and (sym.typ=procsym) then
  3273. begin
  3274. for i:=0 to Tprocsym(sym).ProcdefList.Count-1 do
  3275. begin
  3276. pd := tprocdef(Tprocsym(sym).ProcdefList[i]);
  3277. if (pd.proctypeoption = potype_function) and
  3278. is_boolean(pd.returndef) and
  3279. (pd.minparacount = 0) and
  3280. (pd.visibility >= vis_public) then
  3281. begin
  3282. result:=pd;
  3283. exit;
  3284. end;
  3285. end;
  3286. end;
  3287. end;
  3288. function tabstractrecorddef.search_enumerator_current: tsym;
  3289. var
  3290. sym: tsym;
  3291. i: integer;
  3292. hashedid : THashedIDString;
  3293. begin
  3294. result:=nil;
  3295. // first search for ppo_enumerator_current property modifier
  3296. // then search for public property Current
  3297. for i:=0 to symtable.SymList.Count-1 do
  3298. begin
  3299. sym:=TSym(symtable.SymList[i]);
  3300. if (sym.typ=propertysym) and (ppo_enumerator_current in tpropertysym(sym).propoptions) then
  3301. begin
  3302. result:=sym;
  3303. exit;
  3304. end;
  3305. end;
  3306. hashedid.id:='CURRENT';
  3307. sym:=tsym(symtable.FindWithHash(hashedid));
  3308. if assigned(sym) and (sym.typ=propertysym) and
  3309. (sym.visibility >= vis_public) and not tpropertysym(sym).propaccesslist[palt_read].empty then
  3310. begin
  3311. result:=sym;
  3312. exit;
  3313. end;
  3314. end;
  3315. function tabstractrecorddef.jvm_full_typename(with_package_name: boolean): string;
  3316. var
  3317. st: tsymtable;
  3318. enclosingdef: tdef;
  3319. begin
  3320. if typ=objectdef then
  3321. result:=tobjectdef(self).objextname^
  3322. else if assigned(typesym) then
  3323. result:=typesym.realname
  3324. { have to generate anonymous nested type in current unit/class/record }
  3325. else
  3326. internalerror(2011032601);
  3327. { in case of specializations, add some extras to prevent name conflicts
  3328. with nested classes }
  3329. if df_specialization in defoptions then
  3330. result:='$'+result+'$specialization$';
  3331. st:=owner;
  3332. while assigned(st) and
  3333. (st.symtabletype in [objectsymtable,recordsymtable,localsymtable]) do
  3334. begin
  3335. { nested classes are named as "OuterClass$InnerClass" }
  3336. enclosingdef:=tdef(st.defowner);
  3337. if enclosingdef.typ=procdef then
  3338. result:=result+tprocdef(enclosingdef).procsym.realname+'$$'+tostr(tprocdef(enclosingdef).procsym.symid)+'$'
  3339. else if enclosingdef.typ=objectdef then
  3340. result:=tobjectdef(enclosingdef).objextname^+'$'+result
  3341. else if assigned(enclosingdef.typesym) then
  3342. result:=enclosingdef.typesym.realname+'$'+result
  3343. else
  3344. internalerror(2011060305);
  3345. st:=enclosingdef.owner;
  3346. end;
  3347. if with_package_name and
  3348. assigned(import_lib) then
  3349. result:=import_lib^+'/'+result;
  3350. end;
  3351. function tabstractrecorddef.contains_float_field: boolean;
  3352. var
  3353. i : longint;
  3354. begin
  3355. result:=true;
  3356. for i:=0 to symtable.symlist.count-1 do
  3357. begin
  3358. if tsym(symtable.symlist[i]).typ<>fieldvarsym then
  3359. continue;
  3360. if assigned(tfieldvarsym(symtable.symlist[i]).vardef) and
  3361. tstoreddef(tfieldvarsym(symtable.symlist[i]).vardef).is_fpuregable then
  3362. exit;
  3363. end;
  3364. result:=false;
  3365. end;
  3366. {***************************************************************************
  3367. trecorddef
  3368. ***************************************************************************}
  3369. constructor trecorddef.create(const n:string; p:TSymtable);
  3370. begin
  3371. inherited create(n,recorddef);
  3372. symtable:=p;
  3373. { we can own the symtable only if nobody else owns a copy so far }
  3374. if symtable.refcount=1 then
  3375. symtable.defowner:=self;
  3376. isunion:=false;
  3377. end;
  3378. constructor trecorddef.ppuload(ppufile:tcompilerppufile);
  3379. procedure readvariantrecdesc(var variantrecdesc : pvariantrecdesc);
  3380. var
  3381. i,j : longint;
  3382. begin
  3383. if ppufile.getbyte=1 then
  3384. begin
  3385. new(variantrecdesc);
  3386. ppufile.getderef(variantrecdesc^.variantselectorderef);
  3387. SetLength(variantrecdesc^.branches,ppufile.getasizeint);
  3388. for i:=0 to high(variantrecdesc^.branches) do
  3389. begin
  3390. SetLength(variantrecdesc^.branches[i].values,ppufile.getasizeint);
  3391. for j:=0 to high(variantrecdesc^.branches[i].values) do
  3392. variantrecdesc^.branches[i].values[j]:=ppufile.getexprint;
  3393. readvariantrecdesc(variantrecdesc^.branches[i].nestedvariant);
  3394. end;
  3395. end
  3396. else
  3397. variantrecdesc:=nil;
  3398. end;
  3399. begin
  3400. inherited ppuload(recorddef,ppufile);
  3401. if df_copied_def in defoptions then
  3402. ppufile.getderef(cloneddefderef)
  3403. else
  3404. begin
  3405. symtable:=trecordsymtable.create(objrealname^,0);
  3406. trecordsymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  3407. trecordsymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  3408. trecordsymtable(symtable).padalignment:=shortint(ppufile.getbyte);
  3409. trecordsymtable(symtable).usefieldalignment:=shortint(ppufile.getbyte);
  3410. trecordsymtable(symtable).datasize:=ppufile.getasizeint;
  3411. trecordsymtable(symtable).paddingsize:=ppufile.getword;
  3412. trecordsymtable(symtable).ppuload(ppufile);
  3413. { the variantrecdesc is needed only for iso-like new statements new(prec,1,2,3 ...);
  3414. but because iso mode supports no units, there is no need to store the variantrecdesc
  3415. in the ppu
  3416. }
  3417. // readvariantrecdesc(variantrecdesc);
  3418. { requires usefieldalignment to be set }
  3419. symtable.defowner:=self;
  3420. end;
  3421. isunion:=false;
  3422. end;
  3423. destructor trecorddef.destroy;
  3424. begin
  3425. if assigned(symtable) then
  3426. begin
  3427. symtable.free;
  3428. symtable:=nil;
  3429. end;
  3430. inherited destroy;
  3431. end;
  3432. function trecorddef.getcopy : tstoreddef;
  3433. begin
  3434. result:=trecorddef.create(objrealname^,symtable.getcopy);
  3435. trecorddef(result).isunion:=isunion;
  3436. include(trecorddef(result).defoptions,df_copied_def);
  3437. if assigned(tcinitcode) then
  3438. trecorddef(result).tcinitcode:=tcinitcode.getcopy;
  3439. if assigned(import_lib) then
  3440. trecorddef(result).import_lib:=stringdup(import_lib^);
  3441. end;
  3442. function trecorddef.needs_inittable : boolean;
  3443. begin
  3444. needs_inittable:=trecordsymtable(symtable).needs_init_final
  3445. end;
  3446. function trecorddef.needs_separate_initrtti : boolean;
  3447. begin
  3448. result:=true;
  3449. end;
  3450. procedure trecorddef.buildderef;
  3451. begin
  3452. inherited buildderef;
  3453. if df_copied_def in defoptions then
  3454. cloneddefderef.build(symtable.defowner)
  3455. else
  3456. tstoredsymtable(symtable).buildderef;
  3457. end;
  3458. procedure trecorddef.buildderefimpl;
  3459. begin
  3460. inherited buildderefimpl;
  3461. if not (df_copied_def in defoptions) then
  3462. tstoredsymtable(symtable).buildderefimpl;
  3463. end;
  3464. procedure trecorddef.deref;
  3465. begin
  3466. inherited deref;
  3467. { now dereference the definitions }
  3468. if df_copied_def in defoptions then
  3469. begin
  3470. cloneddef:=trecorddef(cloneddefderef.resolve);
  3471. symtable:=cloneddef.symtable.getcopy;
  3472. end
  3473. else
  3474. tstoredsymtable(symtable).deref;
  3475. fillgenericparas(symtable);
  3476. { assign TGUID? load only from system unit }
  3477. if not(assigned(rec_tguid)) and
  3478. (upper(typename)='TGUID') and
  3479. assigned(owner) and
  3480. assigned(owner.name) and
  3481. (owner.name^='SYSTEM') then
  3482. rec_tguid:=self;
  3483. { assign JMP_BUF? load only from system unit }
  3484. if not(assigned(rec_jmp_buf)) and
  3485. (upper(typename)='JMP_BUF') and
  3486. assigned(owner) and
  3487. assigned(owner.name) and
  3488. (owner.name^='SYSTEM') then
  3489. rec_jmp_buf:=self;
  3490. end;
  3491. procedure trecorddef.ppuwrite(ppufile:tcompilerppufile);
  3492. procedure writevariantrecdesc(variantrecdesc : pvariantrecdesc);
  3493. var
  3494. i,j : longint;
  3495. begin
  3496. if assigned(variantrecdesc) then
  3497. begin
  3498. ppufile.putbyte(1);
  3499. ppufile.putderef(variantrecdesc^.variantselectorderef);
  3500. ppufile.putasizeint(length(variantrecdesc^.branches));
  3501. for i:=0 to high(variantrecdesc^.branches) do
  3502. begin
  3503. ppufile.putasizeint(length(variantrecdesc^.branches[i].values));
  3504. for j:=0 to high(variantrecdesc^.branches[i].values) do
  3505. ppufile.putexprint(variantrecdesc^.branches[i].values[j]);
  3506. writevariantrecdesc(variantrecdesc^.branches[i].nestedvariant);
  3507. end;
  3508. end
  3509. else
  3510. ppufile.putbyte(0);
  3511. end;
  3512. begin
  3513. inherited ppuwrite(ppufile);
  3514. if df_copied_def in defoptions then
  3515. ppufile.putderef(cloneddefderef)
  3516. else
  3517. begin
  3518. ppufile.putbyte(byte(trecordsymtable(symtable).fieldalignment));
  3519. ppufile.putbyte(byte(trecordsymtable(symtable).recordalignment));
  3520. ppufile.putbyte(byte(trecordsymtable(symtable).padalignment));
  3521. ppufile.putbyte(byte(trecordsymtable(symtable).usefieldalignment));
  3522. ppufile.putasizeint(trecordsymtable(symtable).datasize);
  3523. ppufile.putword(trecordsymtable(symtable).paddingsize);
  3524. { the variantrecdesc is needed only for iso-like new statements new(prec,1,2,3 ...);
  3525. but because iso mode supports no units, there is no need to store the variantrecdesc
  3526. in the ppu
  3527. }
  3528. // writevariantrecdesc(variantrecdesc);
  3529. end;
  3530. ppufile.writeentry(ibrecorddef);
  3531. if not(df_copied_def in defoptions) then
  3532. trecordsymtable(symtable).ppuwrite(ppufile);
  3533. end;
  3534. function trecorddef.size:asizeint;
  3535. begin
  3536. result:=trecordsymtable(symtable).datasize;
  3537. end;
  3538. function trecorddef.alignment:shortint;
  3539. begin
  3540. alignment:=trecordsymtable(symtable).recordalignment;
  3541. end;
  3542. function trecorddef.padalignment:shortint;
  3543. begin
  3544. padalignment := trecordsymtable(symtable).padalignment;
  3545. end;
  3546. function trecorddef.GetTypeName : string;
  3547. begin
  3548. GetTypeName:='<record type>'
  3549. end;
  3550. {***************************************************************************
  3551. TABSTRACTPROCDEF
  3552. ***************************************************************************}
  3553. constructor tabstractprocdef.create(dt:tdeftyp;level:byte);
  3554. begin
  3555. inherited create(dt);
  3556. parast:=tparasymtable.create(self,level);
  3557. paras:=nil;
  3558. minparacount:=0;
  3559. maxparacount:=0;
  3560. proctypeoption:=potype_none;
  3561. proccalloption:=pocall_none;
  3562. procoptions:=[];
  3563. {$ifdef i8086}
  3564. if current_settings.x86memorymodel in x86_far_code_models then
  3565. procoptions:=procoptions+[po_far];
  3566. {$endif i8086}
  3567. returndef:=voidtype;
  3568. savesize:=sizeof(pint);
  3569. callerargareasize:=0;
  3570. calleeargareasize:=0;
  3571. has_paraloc_info:=callnoside;
  3572. funcretloc[callerside].init;
  3573. funcretloc[calleeside].init;
  3574. check_mark_as_nested;
  3575. end;
  3576. destructor tabstractprocdef.destroy;
  3577. begin
  3578. if assigned(paras) then
  3579. begin
  3580. {$ifdef MEMDEBUG}
  3581. memprocpara.start;
  3582. {$endif MEMDEBUG}
  3583. paras.free;
  3584. paras:=nil;
  3585. {$ifdef MEMDEBUG}
  3586. memprocpara.stop;
  3587. {$endif MEMDEBUG}
  3588. end;
  3589. if assigned(parast) then
  3590. begin
  3591. {$ifdef MEMDEBUG}
  3592. memprocparast.start;
  3593. {$endif MEMDEBUG}
  3594. parast.free;
  3595. parast:=nil;
  3596. {$ifdef MEMDEBUG}
  3597. memprocparast.stop;
  3598. {$endif MEMDEBUG}
  3599. end;
  3600. funcretloc[callerside].done;
  3601. funcretloc[calleeside].done;
  3602. inherited destroy;
  3603. end;
  3604. procedure tabstractprocdef.count_para(p:TObject;arg:pointer);
  3605. begin
  3606. if (tsym(p).typ<>paravarsym) then
  3607. exit;
  3608. inc(plongint(arg)^);
  3609. if not(vo_is_hidden_para in tparavarsym(p).varoptions) then
  3610. begin
  3611. if not assigned(tparavarsym(p).defaultconstsym) then
  3612. inc(minparacount);
  3613. inc(maxparacount);
  3614. end;
  3615. end;
  3616. procedure tabstractprocdef.insert_para(p:TObject;arg:pointer);
  3617. begin
  3618. if (tsym(p).typ<>paravarsym) then
  3619. exit;
  3620. paras.add(p);
  3621. end;
  3622. procedure tabstractprocdef.calcparas;
  3623. var
  3624. paracount : longint;
  3625. begin
  3626. { This can already be assigned when
  3627. we need to reresolve this unit (PFV) }
  3628. if assigned(paras) then
  3629. paras.free;
  3630. paras:=tparalist.create(false);
  3631. paracount:=0;
  3632. minparacount:=0;
  3633. maxparacount:=0;
  3634. parast.SymList.ForEachCall(@count_para,@paracount);
  3635. paras.capacity:=paracount;
  3636. { Insert parameters in table }
  3637. parast.SymList.ForEachCall(@insert_para,nil);
  3638. { Order parameters }
  3639. paras.sortparas;
  3640. end;
  3641. procedure tabstractprocdef.buildderef;
  3642. begin
  3643. { released procdef? }
  3644. if not assigned(parast) then
  3645. exit;
  3646. inherited buildderef;
  3647. returndefderef.build(returndef);
  3648. if po_explicitparaloc in procoptions then
  3649. funcretloc[callerside].buildderef;
  3650. { parast }
  3651. tparasymtable(parast).buildderef;
  3652. end;
  3653. procedure tabstractprocdef.deref;
  3654. begin
  3655. inherited deref;
  3656. returndef:=tdef(returndefderef.resolve);
  3657. if po_explicitparaloc in procoptions then
  3658. begin
  3659. funcretloc[callerside].deref;
  3660. has_paraloc_info:=callerside;
  3661. end
  3662. else
  3663. begin
  3664. { deref is called after loading from a ppu, but also after another
  3665. unit has been reloaded/recompiled and all references must be
  3666. re-resolved. Since the funcretloc contains a reference to a tdef,
  3667. reset it so that we won't try to access the stale def }
  3668. funcretloc[callerside].init;
  3669. has_paraloc_info:=callnoside;
  3670. end;
  3671. { parast }
  3672. tparasymtable(parast).deref;
  3673. { recalculated parameters }
  3674. calcparas;
  3675. fillgenericparas(parast);
  3676. end;
  3677. constructor tabstractprocdef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  3678. begin
  3679. inherited ppuload(dt,ppufile);
  3680. parast:=nil;
  3681. Paras:=nil;
  3682. minparacount:=0;
  3683. maxparacount:=0;
  3684. ppufile.getderef(returndefderef);
  3685. { TODO: remove fpu_used loading}
  3686. ppufile.getbyte;
  3687. proctypeoption:=tproctypeoption(ppufile.getbyte);
  3688. proccalloption:=tproccalloption(ppufile.getbyte);
  3689. ppufile.getnormalset(procoptions);
  3690. funcretloc[callerside].init;
  3691. if po_explicitparaloc in procoptions then
  3692. funcretloc[callerside].ppuload(ppufile);
  3693. savesize:=sizeof(pint);
  3694. if (po_explicitparaloc in procoptions) then
  3695. has_paraloc_info:=callerside;
  3696. end;
  3697. procedure tabstractprocdef.ppuwrite(ppufile:tcompilerppufile);
  3698. var
  3699. oldintfcrc : boolean;
  3700. begin
  3701. { released procdef? }
  3702. if not assigned(parast) then
  3703. exit;
  3704. inherited ppuwrite(ppufile);
  3705. ppufile.putderef(returndefderef);
  3706. oldintfcrc:=ppufile.do_interface_crc;
  3707. ppufile.do_interface_crc:=false;
  3708. ppufile.putbyte(0);
  3709. ppufile.putbyte(ord(proctypeoption));
  3710. ppufile.putbyte(ord(proccalloption));
  3711. ppufile.putnormalset(procoptions);
  3712. ppufile.do_interface_crc:=oldintfcrc;
  3713. if (po_explicitparaloc in procoptions) then
  3714. funcretloc[callerside].ppuwrite(ppufile);
  3715. end;
  3716. function tabstractprocdef.typename_paras(pno: tprocnameoptions) : ansistring;
  3717. var
  3718. hs,s : ansistring;
  3719. hp : TParavarsym;
  3720. hpc : tconstsym;
  3721. first : boolean;
  3722. i : integer;
  3723. begin
  3724. s:='';
  3725. first:=true;
  3726. for i:=0 to paras.count-1 do
  3727. begin
  3728. hp:=tparavarsym(paras[i]);
  3729. if not(vo_is_hidden_para in hp.varoptions) or
  3730. (pno_showhidden in pno) then
  3731. begin
  3732. if first then
  3733. begin
  3734. s:=s+'(';
  3735. first:=false;
  3736. end
  3737. else
  3738. s:=s+';';
  3739. if vo_is_hidden_para in hp.varoptions then
  3740. s:=s+'<';
  3741. case hp.varspez of
  3742. vs_var :
  3743. s:=s+'var ';
  3744. vs_const :
  3745. s:=s+'const ';
  3746. vs_out :
  3747. s:=s+'out ';
  3748. vs_constref :
  3749. s:=s+'constref ';
  3750. end;
  3751. if (pno_paranames in pno) then
  3752. s:=s+hp.realname+':';
  3753. if hp.univpara then
  3754. s:=s+'univ ';
  3755. if assigned(hp.vardef.typesym) then
  3756. begin
  3757. hs:=hp.vardef.typesym.realname;
  3758. if hs[1]<>'$' then
  3759. s:=s+hp.vardef.OwnerHierarchyName+hs
  3760. else
  3761. s:=s+hp.vardef.GetTypeName;
  3762. end
  3763. else
  3764. s:=s+hp.vardef.GetTypeName;
  3765. { default value }
  3766. if assigned(hp.defaultconstsym) then
  3767. begin
  3768. hpc:=tconstsym(hp.defaultconstsym);
  3769. hs:='';
  3770. case hpc.consttyp of
  3771. conststring,
  3772. constresourcestring :
  3773. begin
  3774. If hpc.value.len>0 then
  3775. begin
  3776. setLength(hs,hpc.value.len);
  3777. { don't write past the end of hs if the constant
  3778. is > 255 chars }
  3779. move(hpc.value.valueptr^,hs[1],length(hs));
  3780. { make sure that constant strings with newline chars
  3781. don't create a linebreak in the assembler code,
  3782. since comments are line-based. Also remove nulls
  3783. because the comments are written as a pchar. }
  3784. ReplaceCase(hs,#0,'.');
  3785. ReplaceCase(hs,#10,'.');
  3786. ReplaceCase(hs,#13,'.');
  3787. end;
  3788. end;
  3789. constreal :
  3790. str(pbestreal(hpc.value.valueptr)^,hs);
  3791. constpointer :
  3792. hs:=tostr(hpc.value.valueordptr);
  3793. constord :
  3794. begin
  3795. if is_boolean(hpc.constdef) then
  3796. begin
  3797. if hpc.value.valueord<>0 then
  3798. hs:='TRUE'
  3799. else
  3800. hs:='FALSE';
  3801. end
  3802. else
  3803. hs:=tostr(hpc.value.valueord);
  3804. end;
  3805. constnil :
  3806. hs:='nil';
  3807. constset :
  3808. hs:='<set>';
  3809. end;
  3810. if hs<>'' then
  3811. s:=s+'="'+hs+'"';
  3812. end;
  3813. if vo_is_hidden_para in hp.varoptions then
  3814. s:=s+'>';
  3815. end;
  3816. end;
  3817. if not first then
  3818. s:=s+')';
  3819. if (po_varargs in procoptions) then
  3820. s:=s+';VarArgs';
  3821. typename_paras:=s;
  3822. end;
  3823. function tabstractprocdef.is_methodpointer:boolean;
  3824. begin
  3825. result:=false;
  3826. end;
  3827. function tabstractprocdef.is_addressonly:boolean;
  3828. begin
  3829. result:=true;
  3830. end;
  3831. function tabstractprocdef.no_self_node: boolean;
  3832. begin
  3833. Result:=([po_staticmethod,po_classmethod]<=procoptions)or
  3834. (proctypeoption in [potype_class_constructor,potype_class_destructor,potype_operator]);
  3835. end;
  3836. function tabstractprocdef.getcopyas(newtyp:tdeftyp;copytyp:tproccopytyp): tstoreddef;
  3837. var
  3838. j, nestinglevel: longint;
  3839. pvs, npvs: tparavarsym;
  3840. begin
  3841. nestinglevel:=parast.symtablelevel;
  3842. if newtyp=procdef then
  3843. begin
  3844. if (copytyp<>pc_bareproc) then
  3845. result:=tprocdef.create(nestinglevel)
  3846. else
  3847. result:=tprocdef.create(normal_function_level);
  3848. tprocdef(result).visibility:=vis_public;
  3849. end
  3850. else
  3851. begin
  3852. result:=tprocvardef.create(nestinglevel);
  3853. end;
  3854. tabstractprocdef(result).returndef:=returndef;
  3855. tabstractprocdef(result).returndefderef:=returndefderef;
  3856. pvs:=nil;
  3857. npvs:=nil;
  3858. for j:=0 to parast.symlist.count-1 do
  3859. begin
  3860. case tsym(parast.symlist[j]).typ of
  3861. paravarsym:
  3862. begin
  3863. pvs:=tparavarsym(parast.symlist[j]);
  3864. { in case of bare proc, don't copy self, vmt or framepointer
  3865. parameters }
  3866. if (copytyp=pc_bareproc) and
  3867. (([vo_is_self,vo_is_vmt,vo_is_parentfp,vo_is_result]*pvs.varoptions)<>[]) then
  3868. continue;
  3869. npvs:=tparavarsym.create(pvs.realname,pvs.paranr,pvs.varspez,
  3870. pvs.vardef,pvs.varoptions);
  3871. npvs.defaultconstsym:=pvs.defaultconstsym;
  3872. tabstractprocdef(result).parast.insert(npvs);
  3873. end;
  3874. constsym:
  3875. begin
  3876. // ignore, reuse original constym. Should also be duplicated
  3877. // be safe though
  3878. end;
  3879. symconst.typesym:
  3880. begin
  3881. // reuse original, part of generic declaration
  3882. end
  3883. else
  3884. internalerror(201160604);
  3885. end;
  3886. end;
  3887. tabstractprocdef(result).savesize:=savesize;
  3888. tabstractprocdef(result).proctypeoption:=proctypeoption;
  3889. tabstractprocdef(result).proccalloption:=proccalloption;
  3890. tabstractprocdef(result).procoptions:=procoptions;
  3891. if (copytyp=pc_bareproc) then
  3892. tabstractprocdef(result).procoptions:=tabstractprocdef(result).procoptions*[po_explicitparaloc,po_hascallingconvention,po_varargs,po_iocheck,po_has_importname,po_has_importdll];
  3893. if newtyp=procvardef then
  3894. tabstractprocdef(result).procoptions:=tabstractprocdef(result).procoptions-[po_has_importname,po_has_importdll];
  3895. tabstractprocdef(result).callerargareasize:=callerargareasize;
  3896. tabstractprocdef(result).calleeargareasize:=calleeargareasize;
  3897. tabstractprocdef(result).maxparacount:=maxparacount;
  3898. tabstractprocdef(result).minparacount:=minparacount;
  3899. if po_explicitparaloc in procoptions then
  3900. tabstractprocdef(result).funcretloc[callerside]:=funcretloc[callerside].getcopy;
  3901. { recalculate parameter info }
  3902. tabstractprocdef(result).has_paraloc_info:=callnoside;
  3903. {$ifdef m68k}
  3904. tabstractprocdef(result).exp_funcretloc:=exp_funcretloc;
  3905. {$endif}
  3906. if (typ=procdef) and
  3907. (newtyp=procvardef) and
  3908. (owner.symtabletype=ObjectSymtable) then
  3909. include(tprocvardef(result).procoptions,po_methodpointer);
  3910. end;
  3911. procedure tabstractprocdef.check_mark_as_nested;
  3912. begin
  3913. { nested procvars require that nested functions use the Delphi-style
  3914. nested procedure calling convention }
  3915. if (parast.symtablelevel>normal_function_level) and
  3916. (m_nested_procvars in current_settings.modeswitches) then
  3917. include(procoptions,po_delphi_nested_cc);
  3918. end;
  3919. procedure tabstractprocdef.init_paraloc_info(side: tcallercallee);
  3920. begin
  3921. if (side in [callerside,callbothsides]) and
  3922. not(has_paraloc_info in [callerside,callbothsides]) then
  3923. begin
  3924. callerargareasize:=paramanager.create_paraloc_info(self,callerside);
  3925. if has_paraloc_info in [calleeside,callbothsides] then
  3926. has_paraloc_info:=callbothsides
  3927. else
  3928. has_paraloc_info:=callerside;
  3929. end;
  3930. if (side in [calleeside,callbothsides]) and
  3931. not(has_paraloc_info in [calleeside,callbothsides]) then
  3932. begin
  3933. calleeargareasize:=paramanager.create_paraloc_info(self,calleeside);
  3934. if has_paraloc_info in [callerside,callbothsides] then
  3935. has_paraloc_info:=callbothsides
  3936. else
  3937. has_paraloc_info:=calleeside;
  3938. end;
  3939. end;
  3940. function tabstractprocdef.stack_tainting_parameter(side: tcallercallee): boolean;
  3941. var
  3942. p: tparavarsym;
  3943. ploc: PCGParalocation;
  3944. i: longint;
  3945. begin
  3946. result:=false;
  3947. init_paraloc_info(side);
  3948. for i:=0 to parast.SymList.Count-1 do
  3949. if tsym(parast.SymList[i]).typ=paravarsym then
  3950. begin
  3951. p:=tparavarsym(parast.SymList[i]);
  3952. { check if no parameter is located on the stack }
  3953. if is_open_array(p.vardef) or
  3954. is_array_of_const(p.vardef) then
  3955. begin
  3956. result:=true;
  3957. exit;
  3958. end;
  3959. ploc:=p.paraloc[side].location;
  3960. while assigned(ploc) do
  3961. begin
  3962. if (ploc^.loc=LOC_REFERENCE) then
  3963. begin
  3964. result:=true;
  3965. exit
  3966. end;
  3967. ploc:=ploc^.next;
  3968. end;
  3969. end;
  3970. end;
  3971. function tabstractprocdef.is_pushleftright: boolean;
  3972. begin
  3973. {$if defined(i8086) or defined(i386)}
  3974. result:=proccalloption in pushleftright_pocalls;
  3975. {$else}
  3976. result:=false;
  3977. {$endif}
  3978. end;
  3979. function tabstractprocdef.address_type: tdef;
  3980. begin
  3981. {$ifdef i8086}
  3982. if po_far in procoptions then
  3983. result:=voidfarpointertype
  3984. else
  3985. result:=voidnearpointertype;
  3986. {$else i8086}
  3987. result:=voidpointertype;
  3988. {$endif i8086}
  3989. end;
  3990. {***************************************************************************
  3991. TPROCDEF
  3992. ***************************************************************************}
  3993. function tprocdef.GetResultName: PShortString;
  3994. begin
  3995. if not assigned(implprocdefinfo) then
  3996. internalerror(2014010301);
  3997. result:=implprocdefinfo^.resultname;
  3998. end;
  3999. procedure tprocdef.SetResultName(AValue: PShortString);
  4000. begin
  4001. if not assigned(implprocdefinfo) then
  4002. internalerror(2014010302);
  4003. implprocdefinfo^.resultname:=AValue;
  4004. end;
  4005. function tprocdef.GetParentFPInitBlock: tnode;
  4006. begin
  4007. if not assigned(implprocdefinfo) then
  4008. internalerror(2014010303);
  4009. result:=implprocdefinfo^.parentfpinitblock;
  4010. end;
  4011. function tprocdef.GetParentFPStruct: tsym;
  4012. begin
  4013. if not assigned(implprocdefinfo) then
  4014. internalerror(2014010304);
  4015. result:=implprocdefinfo^.parentfpstruct;
  4016. end;
  4017. function tprocdef.GetParentFPStructPtrType: tdef;
  4018. begin
  4019. if not assigned(implprocdefinfo) then
  4020. internalerror(2014010305);
  4021. result:=implprocdefinfo^.parentfpstructptrtype;
  4022. end;
  4023. procedure tprocdef.SetParentFPInitBlock(AValue: tnode);
  4024. begin
  4025. if not assigned(implprocdefinfo) then
  4026. internalerror(2014010306);
  4027. implprocdefinfo^.parentfpinitblock:=AValue;
  4028. end;
  4029. function tprocdef.Getprocendtai: tai;
  4030. begin
  4031. if not assigned(implprocdefinfo) then
  4032. internalerror(2014010307);
  4033. result:=implprocdefinfo^.procendtai;
  4034. end;
  4035. function tprocdef.Getprocstarttai: tai;
  4036. begin
  4037. if not assigned(implprocdefinfo) then
  4038. internalerror(2014010308);
  4039. result:=implprocdefinfo^.procstarttai;
  4040. end;
  4041. procedure tprocdef.Setprocendtai(AValue: tai);
  4042. begin
  4043. if not assigned(implprocdefinfo) then
  4044. internalerror(2014010309);
  4045. implprocdefinfo^.procendtai:=AValue;
  4046. end;
  4047. function tprocdef.Getskpara: pointer;
  4048. begin
  4049. if not assigned(implprocdefinfo) then
  4050. internalerror(2014010310);
  4051. result:=implprocdefinfo^.skpara;
  4052. end;
  4053. procedure tprocdef.Setskpara(AValue: pointer);
  4054. begin
  4055. if not assigned(implprocdefinfo) then
  4056. internalerror(2014010311);
  4057. implprocdefinfo^.skpara:=AValue;
  4058. end;
  4059. function tprocdef.Getforwarddef: boolean;
  4060. begin
  4061. if not assigned(implprocdefinfo) then
  4062. internalerror(2014010312);
  4063. result:=implprocdefinfo^.forwarddef;
  4064. end;
  4065. function tprocdef.Gethasforward: boolean;
  4066. begin
  4067. if not assigned(implprocdefinfo) then
  4068. internalerror(2014010313);
  4069. result:=implprocdefinfo^.hasforward;
  4070. end;
  4071. function tprocdef.Getinterfacedef: boolean;
  4072. begin
  4073. if not assigned(implprocdefinfo) then
  4074. internalerror(2014010314);
  4075. result:=implprocdefinfo^.interfacedef;
  4076. end;
  4077. procedure tprocdef.Setforwarddef(AValue: boolean);
  4078. begin
  4079. if not assigned(implprocdefinfo) then
  4080. internalerror(2014010315);
  4081. implprocdefinfo^.forwarddef:=AValue;
  4082. end;
  4083. procedure tprocdef.Sethasforward(AValue: boolean);
  4084. begin
  4085. if not assigned(implprocdefinfo) then
  4086. internalerror(2014010316);
  4087. implprocdefinfo^.hasforward:=AValue;
  4088. end;
  4089. procedure tprocdef.Setinterfacedef(AValue: boolean);
  4090. begin
  4091. if not assigned(implprocdefinfo) then
  4092. internalerror(2014010317);
  4093. implprocdefinfo^.interfacedef:=AValue;
  4094. end;
  4095. procedure tprocdef.Setprocstarttai(AValue: tai);
  4096. begin
  4097. if not assigned(implprocdefinfo) then
  4098. internalerror(2014010318);
  4099. implprocdefinfo^.procstarttai:=AValue;
  4100. end;
  4101. procedure tprocdef.SetParentFPStruct(AValue: tsym);
  4102. begin
  4103. if not assigned(implprocdefinfo) then
  4104. internalerror(2014010319);
  4105. implprocdefinfo^.parentfpstruct:=AValue;
  4106. end;
  4107. procedure tprocdef.SetParentFPStructPtrType(AValue: tdef);
  4108. begin
  4109. if not assigned(implprocdefinfo) then
  4110. internalerror(2014010320);
  4111. implprocdefinfo^.parentfpstructptrtype:=AValue;
  4112. end;
  4113. constructor tprocdef.create(level:byte);
  4114. begin
  4115. inherited create(procdef,level);
  4116. implprocdefinfo:=allocmem(sizeof(implprocdefinfo^));
  4117. localst:=tlocalsymtable.create(self,parast.symtablelevel);
  4118. {$ifdef symansistr}
  4119. _mangledname:='';
  4120. {$else symansistr}
  4121. _mangledname:=nil;
  4122. {$endif symansistr}
  4123. fileinfo:=current_filepos;
  4124. extnumber:=$ffff;
  4125. aliasnames:=TCmdStrList.create;
  4126. funcretsym:=nil;
  4127. forwarddef:=true;
  4128. interfacedef:=false;
  4129. hasforward:=false;
  4130. struct := nil;
  4131. import_dll:=nil;
  4132. import_name:=nil;
  4133. import_nr:=0;
  4134. inlininginfo:=nil;
  4135. deprecatedmsg:=nil;
  4136. {$if defined(i386) or defined(i8086)}
  4137. fpu_used:=maxfpuregs;
  4138. {$endif i386 or i8086}
  4139. end;
  4140. constructor tprocdef.ppuload(ppufile:tcompilerppufile);
  4141. var
  4142. i,aliasnamescount : longint;
  4143. level : byte;
  4144. begin
  4145. inherited ppuload(procdef,ppufile);
  4146. {$ifdef symansistr}
  4147. if po_has_mangledname in procoptions then
  4148. _mangledname:=ppufile.getansistring
  4149. else
  4150. _mangledname:='';
  4151. {$else symansistr}
  4152. if po_has_mangledname in procoptions then
  4153. _mangledname:=stringdup(ppufile.getstring)
  4154. else
  4155. _mangledname:=nil;
  4156. {$endif symansistr}
  4157. extnumber:=ppufile.getword;
  4158. level:=ppufile.getbyte;
  4159. ppufile.getderef(structderef);
  4160. ppufile.getderef(procsymderef);
  4161. ppufile.getposinfo(fileinfo);
  4162. visibility:=tvisibility(ppufile.getbyte);
  4163. ppufile.getsmallset(symoptions);
  4164. if sp_has_deprecated_msg in symoptions then
  4165. deprecatedmsg:=stringdup(ppufile.getstring)
  4166. else
  4167. deprecatedmsg:=nil;
  4168. synthetickind:=tsynthetickind(ppufile.getbyte);
  4169. {$ifdef powerpc}
  4170. { library symbol for AmigaOS/MorphOS }
  4171. ppufile.getderef(libsymderef);
  4172. {$endif powerpc}
  4173. { import stuff }
  4174. if po_has_importdll in procoptions then
  4175. import_dll:=stringdup(ppufile.getstring)
  4176. else
  4177. import_dll:=nil;
  4178. if po_has_importname in procoptions then
  4179. import_name:=stringdup(ppufile.getstring)
  4180. else
  4181. import_name:=nil;
  4182. import_nr:=ppufile.getword;
  4183. if (po_msgint in procoptions) then
  4184. messageinf.i:=ppufile.getlongint;
  4185. if (po_msgstr in procoptions) then
  4186. messageinf.str:=stringdup(ppufile.getstring);
  4187. if (po_dispid in procoptions) then
  4188. dispid:=ppufile.getlongint;
  4189. { inline stuff }
  4190. if (po_has_inlininginfo in procoptions) then
  4191. begin
  4192. ppufile.getderef(funcretsymderef);
  4193. new(inlininginfo);
  4194. ppufile.getsmallset(inlininginfo^.flags);
  4195. end
  4196. else
  4197. begin
  4198. inlininginfo:=nil;
  4199. funcretsym:=nil;
  4200. end;
  4201. aliasnames:=TCmdStrList.create;
  4202. { count alias names }
  4203. aliasnamescount:=ppufile.getbyte;
  4204. for i:=1 to aliasnamescount do
  4205. aliasnames.insert(ppufile.getstring);
  4206. isempty:=ppufile.getbyte<>0;
  4207. { load para symtable }
  4208. parast:=tparasymtable.create(self,level);
  4209. tparasymtable(parast).ppuload(ppufile);
  4210. { load local symtable }
  4211. if (po_has_inlininginfo in procoptions) then
  4212. begin
  4213. localst:=tlocalsymtable.create(self,level);
  4214. tlocalsymtable(localst).ppuload(ppufile);
  4215. end
  4216. else
  4217. localst:=nil;
  4218. { inline stuff }
  4219. if (po_has_inlininginfo in procoptions) then
  4220. inlininginfo^.code:=ppuloadnodetree(ppufile);
  4221. { default values for no persistent data }
  4222. if (cs_link_deffile in current_settings.globalswitches) and
  4223. (tf_need_export in target_info.flags) and
  4224. (po_exports in procoptions) then
  4225. deffile.AddExport(mangledname);
  4226. { Disable po_has_inlining until the derefimpl is done }
  4227. exclude(procoptions,po_has_inlininginfo);
  4228. {$ifdef i386}
  4229. fpu_used:=maxfpuregs;
  4230. {$endif i386}
  4231. end;
  4232. destructor tprocdef.destroy;
  4233. begin
  4234. aliasnames.free;
  4235. aliasnames:=nil;
  4236. if assigned(localst) and
  4237. (localst.symtabletype<>staticsymtable) then
  4238. begin
  4239. {$ifdef MEMDEBUG}
  4240. memproclocalst.start;
  4241. {$endif MEMDEBUG}
  4242. localst.free;
  4243. localst:=nil;
  4244. {$ifdef MEMDEBUG}
  4245. memproclocalst.start;
  4246. {$endif MEMDEBUG}
  4247. end;
  4248. if assigned(inlininginfo) then
  4249. begin
  4250. {$ifdef MEMDEBUG}
  4251. memprocnodetree.start;
  4252. {$endif MEMDEBUG}
  4253. tnode(inlininginfo^.code).free;
  4254. {$ifdef MEMDEBUG}
  4255. memprocnodetree.start;
  4256. {$endif MEMDEBUG}
  4257. dispose(inlininginfo);
  4258. inlininginfo:=nil;
  4259. end;
  4260. {$ifdef jvm}
  4261. exprasmlist.free;
  4262. {$endif}
  4263. if assigned(implprocdefinfo) then
  4264. begin
  4265. stringdispose(implprocdefinfo^.resultname);
  4266. freemem(implprocdefinfo);
  4267. implprocdefinfo:=nil;
  4268. end;
  4269. stringdispose(import_dll);
  4270. stringdispose(import_name);
  4271. stringdispose(deprecatedmsg);
  4272. if (po_msgstr in procoptions) then
  4273. stringdispose(messageinf.str);
  4274. {$ifndef symansistr}
  4275. if assigned(_mangledname) then
  4276. begin
  4277. {$ifdef MEMDEBUG}
  4278. memmanglednames.start;
  4279. {$endif MEMDEBUG}
  4280. stringdispose(_mangledname);
  4281. {$ifdef MEMDEBUG}
  4282. memmanglednames.stop;
  4283. {$endif MEMDEBUG}
  4284. end;
  4285. {$endif symansistr}
  4286. inherited destroy;
  4287. end;
  4288. procedure tprocdef.ppuwrite(ppufile:tcompilerppufile);
  4289. var
  4290. oldintfcrc : boolean;
  4291. aliasnamescount : longint;
  4292. item : TCmdStrListItem;
  4293. begin
  4294. { released procdef? }
  4295. if not assigned(parast) then
  4296. exit;
  4297. inherited ppuwrite(ppufile);
  4298. {$ifdef symansistr}
  4299. if po_has_mangledname in procoptions then
  4300. ppufile.putansistring(_mangledname);
  4301. {$else symansistr}
  4302. if po_has_mangledname in procoptions then
  4303. ppufile.putstring(_mangledname^);
  4304. {$endif symansistr}
  4305. ppufile.putword(extnumber);
  4306. ppufile.putbyte(parast.symtablelevel);
  4307. ppufile.putderef(structderef);
  4308. ppufile.putderef(procsymderef);
  4309. ppufile.putposinfo(fileinfo);
  4310. ppufile.putbyte(byte(visibility));
  4311. ppufile.putsmallset(symoptions);
  4312. if sp_has_deprecated_msg in symoptions then
  4313. ppufile.putstring(deprecatedmsg^);
  4314. ppufile.putbyte(byte(synthetickind));
  4315. {$ifdef powerpc}
  4316. { library symbol for AmigaOS/MorphOS }
  4317. ppufile.putderef(libsymderef);
  4318. {$endif powerpc}
  4319. { import }
  4320. if po_has_importdll in procoptions then
  4321. ppufile.putstring(import_dll^);
  4322. if po_has_importname in procoptions then
  4323. ppufile.putstring(import_name^);
  4324. ppufile.putword(import_nr);
  4325. if (po_msgint in procoptions) then
  4326. ppufile.putlongint(messageinf.i);
  4327. if (po_msgstr in procoptions) then
  4328. ppufile.putstring(messageinf.str^);
  4329. if (po_dispid in procoptions) then
  4330. ppufile.putlongint(dispid);
  4331. { inline stuff }
  4332. oldintfcrc:=ppufile.do_crc;
  4333. ppufile.do_crc:=false;
  4334. if (po_has_inlininginfo in procoptions) then
  4335. begin
  4336. ppufile.putderef(funcretsymderef);
  4337. ppufile.putsmallset(inlininginfo^.flags);
  4338. end;
  4339. { count alias names }
  4340. aliasnamescount:=0;
  4341. item:=TCmdStrListItem(aliasnames.first);
  4342. while assigned(item) do
  4343. begin
  4344. inc(aliasnamescount);
  4345. item:=TCmdStrListItem(item.next);
  4346. end;
  4347. if aliasnamescount>255 then
  4348. internalerror(200711021);
  4349. ppufile.putbyte(aliasnamescount);
  4350. item:=TCmdStrListItem(aliasnames.first);
  4351. while assigned(item) do
  4352. begin
  4353. ppufile.putstring(item.str);
  4354. item:=TCmdStrListItem(item.next);
  4355. end;
  4356. ppufile.putbyte(ord(isempty));
  4357. ppufile.do_crc:=oldintfcrc;
  4358. { write this entry }
  4359. ppufile.writeentry(ibprocdef);
  4360. { Save the para symtable, this is taken from the interface }
  4361. tparasymtable(parast).ppuwrite(ppufile);
  4362. { save localsymtable for inline procedures or when local
  4363. browser info is requested, this has no influence on the crc }
  4364. if (po_has_inlininginfo in procoptions) then
  4365. begin
  4366. oldintfcrc:=ppufile.do_crc;
  4367. ppufile.do_crc:=false;
  4368. tlocalsymtable(localst).ppuwrite(ppufile);
  4369. ppufile.do_crc:=oldintfcrc;
  4370. end;
  4371. { node tree for inlining }
  4372. oldintfcrc:=ppufile.do_crc;
  4373. ppufile.do_crc:=false;
  4374. if (po_has_inlininginfo in procoptions) then
  4375. ppuwritenodetree(ppufile,inlininginfo^.code);
  4376. ppufile.do_crc:=oldintfcrc;
  4377. end;
  4378. function tprocdef.fullprocname(showhidden:boolean):string;
  4379. var
  4380. pno: tprocnameoptions;
  4381. begin
  4382. pno:=[];
  4383. if showhidden then
  4384. include(pno,pno_showhidden);
  4385. result:=customprocname(pno);
  4386. end;
  4387. function tprocdef.customprocname(pno: tprocnameoptions):ansistring;
  4388. var
  4389. s, rn : ansistring;
  4390. t : ttoken;
  4391. begin
  4392. {$ifdef EXTDEBUG}
  4393. include(pno,pno_showhidden);
  4394. {$endif EXTDEBUG}
  4395. s:='';
  4396. if proctypeoption=potype_operator then
  4397. begin
  4398. for t:=NOTOKEN to last_overloaded do
  4399. if procsym.realname='$'+overloaded_names[t] then
  4400. begin
  4401. s:='operator ';
  4402. if (pno_ownername in pno) and
  4403. assigned(struct) then
  4404. s:=s+struct.RttiName+'.';
  4405. s:=s+arraytokeninfo[t].str+typename_paras(pno);
  4406. break;
  4407. end;
  4408. end
  4409. else
  4410. begin
  4411. if (po_classmethod in procoptions) and
  4412. not(pno_noclassmarker in pno) then
  4413. s:='class ';
  4414. case proctypeoption of
  4415. potype_constructor,
  4416. potype_class_constructor:
  4417. s:=s+'constructor ';
  4418. potype_class_destructor,
  4419. potype_destructor:
  4420. s:=s+'destructor ';
  4421. else
  4422. if (pno_proctypeoption in pno) then
  4423. begin
  4424. if assigned(returndef) and
  4425. not(is_void(returndef)) then
  4426. s:=s+'function '
  4427. else
  4428. s:=s+'procedure ';
  4429. end;
  4430. end;
  4431. if (pno_ownername in pno) and
  4432. (owner.symtabletype in [recordsymtable,objectsymtable]) then
  4433. s:=s+tabstractrecorddef(owner.defowner).RttiName+'.';
  4434. rn:=procsym.realname;
  4435. if (pno_noleadingdollar in pno) and
  4436. (rn[1]='$') then
  4437. delete(rn,1,1);
  4438. s:=s+rn+typename_paras(pno);
  4439. end;
  4440. if not(proctypeoption in [potype_constructor,potype_destructor,
  4441. potype_class_constructor,potype_class_destructor]) and
  4442. assigned(returndef) and
  4443. not(is_void(returndef)) then
  4444. s:=s+':'+returndef.GetTypeName;
  4445. if owner.symtabletype=localsymtable then
  4446. s:=s+' is nested';
  4447. s:=s+';';
  4448. { forced calling convention? }
  4449. if (po_hascallingconvention in procoptions) then
  4450. s:=s+' '+ProcCallOptionStr[proccalloption]+';';
  4451. if (po_staticmethod in procoptions) and
  4452. not (proctypeoption in [potype_class_constructor,potype_class_destructor]) then
  4453. s:=s+' Static;';
  4454. customprocname:=s;
  4455. end;
  4456. function tprocdef.is_methodpointer:boolean;
  4457. begin
  4458. { don't check assigned(_class), that's also the case for nested
  4459. procedures inside methods }
  4460. result:=(owner.symtabletype=ObjectSymtable)and not no_self_node;
  4461. end;
  4462. function tprocdef.is_addressonly:boolean;
  4463. begin
  4464. result:=assigned(owner) and
  4465. not is_methodpointer and
  4466. (not(m_nested_procvars in current_settings.modeswitches) or
  4467. not is_nested_pd(self));
  4468. end;
  4469. procedure tprocdef.make_external;
  4470. begin
  4471. include(procoptions,po_external);
  4472. forwarddef:=false;
  4473. end;
  4474. function tprocdef.GetSymtable(t:tGetSymtable):TSymtable;
  4475. begin
  4476. case t of
  4477. gs_local :
  4478. GetSymtable:=localst;
  4479. gs_para :
  4480. GetSymtable:=parast;
  4481. else
  4482. GetSymtable:=nil;
  4483. end;
  4484. end;
  4485. function tprocdef.getcopyas(newtyp: tdeftyp; copytyp: tproccopytyp): tstoreddef;
  4486. var
  4487. j : longint;
  4488. begin
  4489. result:=inherited getcopyas(newtyp,copytyp);
  4490. if newtyp=procvardef then
  4491. exit;
  4492. { don't copy mangled name, can be different }
  4493. tprocdef(result).messageinf:=messageinf;
  4494. tprocdef(result).dispid:=dispid;
  4495. if po_msgstr in procoptions then
  4496. tprocdef(result).messageinf.str:=stringdup(messageinf.str^);
  4497. tprocdef(result).symoptions:=symoptions;
  4498. if assigned(deprecatedmsg) then
  4499. tprocdef(result).deprecatedmsg:=stringdup(deprecatedmsg^);
  4500. { will have to be associated with appropriate procsym }
  4501. tprocdef(result).procsym:=nil;
  4502. if copytyp<>pc_bareproc then
  4503. tprocdef(result).aliasnames.concatListcopy(aliasnames);
  4504. if assigned(funcretsym) then
  4505. begin
  4506. if funcretsym.owner=parast then
  4507. begin
  4508. j:=parast.symlist.indexof(funcretsym);
  4509. if j<0 then
  4510. internalerror(2011040606);
  4511. tprocdef(result).funcretsym:=tsym(tprocdef(result).parast.symlist[j]);
  4512. end
  4513. else if funcretsym.owner=localst then
  4514. begin
  4515. { nothing to do, will be inserted for the new procdef while
  4516. parsing its body (by pdecsub.insert_funcret_local) }
  4517. end
  4518. else
  4519. internalerror(2011040605);
  4520. end;
  4521. { will have to be associated with a new struct }
  4522. tprocdef(result).struct:=nil;
  4523. {$if defined(powerpc) or defined(m68k)}
  4524. tprocdef(result).libsym:=libsym;
  4525. {$endif powerpc or m68k}
  4526. if assigned(implprocdefinfo) then
  4527. begin
  4528. if assigned(resultname) then
  4529. tprocdef(result).resultname:=stringdup(resultname^);
  4530. end;
  4531. if assigned(import_dll) then
  4532. tprocdef(result).import_dll:=stringdup(import_dll^);
  4533. if assigned(import_name) then
  4534. tprocdef(result).import_name:=stringdup(import_name^);
  4535. tprocdef(result).import_nr:=import_nr;
  4536. tprocdef(result).extnumber:=$ffff;
  4537. {$if defined(i386) or defined(i8086)}
  4538. tprocdef(result).fpu_used:=fpu_used;
  4539. {$endif i386 or i8086}
  4540. tprocdef(result).visibility:=visibility;
  4541. tprocdef(result).synthetickind:=synthetickind;
  4542. { we need a separate implementation for the copied def }
  4543. tprocdef(result).forwarddef:=true;
  4544. tprocdef(result).interfacedef:=true;
  4545. { create new paralist }
  4546. tprocdef(result).calcparas;
  4547. end;
  4548. function tprocdef.getcopy: tstoreddef;
  4549. begin
  4550. result:=getcopyas(procdef,pc_normal);
  4551. end;
  4552. procedure tprocdef.buildderef;
  4553. begin
  4554. inherited buildderef;
  4555. structderef.build(struct);
  4556. { procsym that originaly defined this definition, should be in the
  4557. same symtable }
  4558. procsymderef.build(procsym);
  4559. {$ifdef powerpc}
  4560. { library symbol for AmigaOS/MorphOS }
  4561. libsymderef.build(libsym);
  4562. {$endif powerpc}
  4563. end;
  4564. procedure tprocdef.buildderefimpl;
  4565. begin
  4566. inherited buildderefimpl;
  4567. { inline tree }
  4568. if (po_has_inlininginfo in procoptions) then
  4569. begin
  4570. { Localst is not available for main/unit init }
  4571. if assigned(localst) then
  4572. begin
  4573. tlocalsymtable(localst).buildderef;
  4574. tlocalsymtable(localst).buildderefimpl;
  4575. end;
  4576. funcretsymderef.build(funcretsym);
  4577. inlininginfo^.code.buildderefimpl;
  4578. end;
  4579. end;
  4580. procedure tprocdef.deref;
  4581. begin
  4582. inherited deref;
  4583. struct:=tabstractrecorddef(structderef.resolve);
  4584. { procsym that originaly defined this definition, should be in the
  4585. same symtable }
  4586. procsym:=tprocsym(procsymderef.resolve);
  4587. {$ifdef powerpc}
  4588. { library symbol for AmigaOS/MorphOS }
  4589. libsym:=tsym(libsymderef.resolve);
  4590. {$endif powerpc}
  4591. end;
  4592. procedure tprocdef.derefimpl;
  4593. begin
  4594. { Enable has_inlininginfo when the inlininginfo
  4595. structure is available. The has_inlininginfo was disabled
  4596. after the load, since the data was invalid }
  4597. if assigned(inlininginfo) then
  4598. include(procoptions,po_has_inlininginfo);
  4599. { Inline }
  4600. if (po_has_inlininginfo in procoptions) then
  4601. begin
  4602. { Locals }
  4603. if assigned(localst) then
  4604. begin
  4605. tlocalsymtable(localst).deref;
  4606. tlocalsymtable(localst).derefimpl;
  4607. end;
  4608. inlininginfo^.code.derefimpl;
  4609. { funcretsym, this is always located in the localst }
  4610. funcretsym:=tsym(funcretsymderef.resolve);
  4611. end
  4612. else
  4613. begin
  4614. { safety }
  4615. { Not safe! A unit may be reresolved after its interface has been
  4616. parsed but before its implementation has been parsed, and in that
  4617. case the funcretsym is still required!
  4618. funcretsym:=nil; }
  4619. end;
  4620. end;
  4621. function tprocdef.GetTypeName : string;
  4622. begin
  4623. GetTypeName := FullProcName(false);
  4624. end;
  4625. function tprocdef.mangledname : TSymStr;
  4626. begin
  4627. {$ifdef symansistr}
  4628. if _mangledname<>'' then
  4629. {$else symansistr}
  4630. if assigned(_mangledname) then
  4631. {$endif symansistr}
  4632. begin
  4633. {$ifdef compress}
  4634. {$error add support for ansistrings in case of symansistr}
  4635. mangledname:=minilzw_decode(_mangledname^);
  4636. {$else}
  4637. {$ifdef symansistr}
  4638. mangledname:=_mangledname;
  4639. {$else symansistr}
  4640. mangledname:=_mangledname^;
  4641. {$endif symansistr}
  4642. {$endif}
  4643. exit;
  4644. end;
  4645. {$ifndef jvm}
  4646. mangledname:=defaultmangledname;
  4647. {$else not jvm}
  4648. mangledname:=jvmmangledbasename(false);
  4649. if (po_has_importdll in procoptions) then
  4650. begin
  4651. { import_dll comes from "external 'import_dll_name' name 'external_name'" }
  4652. if assigned(import_dll) then
  4653. mangledname:=import_dll^+'/'+mangledname
  4654. else
  4655. internalerror(2010122607);
  4656. end
  4657. else
  4658. jvmaddtypeownerprefix(owner,mangledname);
  4659. {$endif not jvm}
  4660. {$ifdef compress}
  4661. {$error add support for ansistrings in case of symansistr}
  4662. _mangledname:=stringdup(minilzw_encode(mangledname));
  4663. {$else}
  4664. {$ifdef symansistr}
  4665. _mangledname:=mangledname;
  4666. {$else symansistr}
  4667. _mangledname:=stringdup(mangledname);
  4668. {$endif symansistr}
  4669. {$endif}
  4670. end;
  4671. function tprocdef.defaultmangledname: TSymStr;
  4672. var
  4673. hp : TParavarsym;
  4674. hs : TSymStr;
  4675. crc : dword;
  4676. newlen,
  4677. oldlen,
  4678. i : integer;
  4679. begin
  4680. hp:=nil;
  4681. { we need to use the symtable where the procsym is inserted,
  4682. because that is visible to the world }
  4683. defaultmangledname:=make_mangledname('',procsym.owner,procsym.name);
  4684. oldlen:=length(defaultmangledname);
  4685. { add parameter types }
  4686. for i:=0 to paras.count-1 do
  4687. begin
  4688. hp:=tparavarsym(paras[i]);
  4689. if not(vo_is_hidden_para in hp.varoptions) then
  4690. defaultmangledname:=defaultmangledname+'$'+hp.vardef.mangledparaname;
  4691. end;
  4692. { add resultdef, add $$ as separator to make it unique from a
  4693. parameter separator }
  4694. if not is_void(returndef) then
  4695. defaultmangledname:=defaultmangledname+'$$'+returndef.mangledparaname;
  4696. newlen:=length(defaultmangledname);
  4697. { Replace with CRC if the parameter line is very long }
  4698. if (newlen-oldlen>12) and
  4699. ((newlen>100) or (newlen-oldlen>64)) then
  4700. begin
  4701. crc:=0;
  4702. for i:=0 to paras.count-1 do
  4703. begin
  4704. hp:=tparavarsym(paras[i]);
  4705. if not(vo_is_hidden_para in hp.varoptions) then
  4706. begin
  4707. hs:=hp.vardef.mangledparaname;
  4708. crc:=UpdateCrc32(crc,hs[1],length(hs));
  4709. end;
  4710. end;
  4711. hs:=hp.vardef.mangledparaname;
  4712. crc:=UpdateCrc32(crc,hs[1],length(hs));
  4713. defaultmangledname:=Copy(defaultmangledname,1,oldlen)+'$crc'+hexstr(crc,8);
  4714. end;
  4715. end;
  4716. function tprocdef.cplusplusmangledname : TSymStr;
  4717. function getcppparaname(p : tdef) : TSymStr;
  4718. const
  4719. {$ifdef NAMEMANGLING_GCC2}
  4720. ordtype2str : array[tordtype] of string[2] = (
  4721. '',
  4722. 'Uc','Us','Ui','Us',
  4723. 'Sc','s','i','x',
  4724. 'b','b','b','b','b',
  4725. 'c','w','x');
  4726. {$else NAMEMANGLING_GCC2}
  4727. ordtype2str : array[tordtype] of string[1] = (
  4728. 'v',
  4729. 'h','t','j','y',
  4730. 'a','s','i','x',
  4731. 'b','b','b','b',
  4732. 'b','b','b','b',
  4733. 'c','w','x');
  4734. floattype2str : array[tfloattype] of string[1] = (
  4735. 'f','d','e','e',
  4736. 'd','d','g');
  4737. {$endif NAMEMANGLING_GCC2}
  4738. var
  4739. s : TSymStr;
  4740. begin
  4741. case p.typ of
  4742. orddef:
  4743. s:=ordtype2str[torddef(p).ordtype];
  4744. pointerdef:
  4745. s:='P'+getcppparaname(tpointerdef(p).pointeddef);
  4746. {$ifndef NAMEMANGLING_GCC2}
  4747. floatdef:
  4748. s:=floattype2str[tfloatdef(p).floattype];
  4749. {$endif NAMEMANGLING_GCC2}
  4750. else
  4751. internalerror(2103001);
  4752. end;
  4753. getcppparaname:=s;
  4754. end;
  4755. var
  4756. s,s2 : TSymStr;
  4757. hp : TParavarsym;
  4758. i : integer;
  4759. begin
  4760. {$ifdef NAMEMANGLING_GCC2}
  4761. { outdated gcc 2.x name mangling scheme }
  4762. s := procsym.realname;
  4763. if procsym.owner.symtabletype=ObjectSymtable then
  4764. begin
  4765. s2:=upper(tobjectdef(procsym.owner.defowner).objrealname^);
  4766. case proctypeoption of
  4767. potype_destructor:
  4768. s:='_$_'+tostr(length(s2))+s2;
  4769. potype_constructor:
  4770. s:='___'+tostr(length(s2))+s2;
  4771. else
  4772. s:='_'+s+'__'+tostr(length(s2))+s2;
  4773. end;
  4774. end
  4775. else s:=s+'__';
  4776. s:=s+'F';
  4777. { concat modifiers }
  4778. { !!!!! }
  4779. { now we handle the parameters }
  4780. if maxparacount>0 then
  4781. begin
  4782. for i:=0 to paras.count-1 do
  4783. begin
  4784. hp:=tparavarsym(paras[i]);
  4785. { no hidden parameters form part of a C++ mangled name:
  4786. a) self is not included
  4787. b) there are no "high" or other hidden parameters
  4788. }
  4789. if vo_is_hidden_para in hp.varoptions then
  4790. continue;
  4791. s2:=getcppparaname(hp.vardef);
  4792. if hp.varspez in [vs_var,vs_out] then
  4793. s2:='R'+s2;
  4794. s:=s+s2;
  4795. end;
  4796. end
  4797. else
  4798. s:=s+'v';
  4799. cplusplusmangledname:=s;
  4800. {$else NAMEMANGLING_GCC2}
  4801. { gcc 3.x and 4.x name mangling scheme }
  4802. { see http://www.codesourcery.com/public/cxx-abi/abi.html#mangling }
  4803. if procsym.owner.symtabletype=ObjectSymtable then
  4804. begin
  4805. s:='_ZN';
  4806. s2:=tobjectdef(procsym.owner.defowner).objextname^;
  4807. s:=s+tostr(length(s2))+s2;
  4808. case proctypeoption of
  4809. potype_constructor:
  4810. s:=s+'C1';
  4811. potype_destructor:
  4812. s:=s+'D1';
  4813. else
  4814. s:=s+tostr(length(procsym.realname))+procsym.realname;
  4815. end;
  4816. s:=s+'E';
  4817. end
  4818. else
  4819. s:=procsym.realname;
  4820. { now we handle the parameters }
  4821. if maxparacount>0 then
  4822. begin
  4823. for i:=0 to paras.count-1 do
  4824. begin
  4825. hp:=tparavarsym(paras[i]);
  4826. { no hidden parameters form part of a C++ mangled name:
  4827. a) self is not included
  4828. b) there are no "high" or other hidden parameters
  4829. }
  4830. if vo_is_hidden_para in hp.varoptions then
  4831. continue;
  4832. s2:=getcppparaname(hp.vardef);
  4833. if hp.varspez in [vs_var,vs_out] then
  4834. s2:='R'+s2;
  4835. s:=s+s2;
  4836. end;
  4837. end
  4838. else
  4839. s:=s+'v';
  4840. cplusplusmangledname:=s;
  4841. {$endif NAMEMANGLING_GCC2}
  4842. end;
  4843. function tprocdef.objcmangledname : TSymStr;
  4844. var
  4845. manglednamelen: longint;
  4846. iscatmethod : boolean;
  4847. begin
  4848. if not (po_msgstr in procoptions) then
  4849. internalerror(2009030901);
  4850. { we may very well need longer strings to handle these... }
  4851. manglednamelen:=length(tobjectdef(procsym.owner.defowner).objextname^)+
  4852. length('+"[ ]"')+length(messageinf.str^);
  4853. iscatmethod:=oo_is_classhelper in tobjectdef(procsym.owner.defowner).objectoptions;
  4854. if (iscatmethod) then
  4855. inc(manglednamelen,length(tobjectdef(procsym.owner.defowner).childof.objextname^)+length('()'));
  4856. if manglednamelen>255 then
  4857. Message1(parser_e_objc_message_name_too_long,messageinf.str^);
  4858. if not(po_classmethod in procoptions) then
  4859. result:='"-['
  4860. else
  4861. result:='"+[';
  4862. { quotes are necessary because the +/- otherwise confuse the assembler
  4863. into expecting a number
  4864. }
  4865. if iscatmethod then
  4866. result:=result+tobjectdef(procsym.owner.defowner).childof.objextname^+'(';
  4867. result:=result+tobjectdef(procsym.owner.defowner).objextname^;
  4868. if iscatmethod then
  4869. result:=result+')';
  4870. result:=result+' '+messageinf.str^+']"';
  4871. end;
  4872. {$ifdef jvm}
  4873. function tprocdef.jvmmangledbasename(signature: boolean): TSymStr;
  4874. var
  4875. vs: tparavarsym;
  4876. i: longint;
  4877. founderror: tdef;
  4878. tmpresult: TSymStr;
  4879. container: tsymtable;
  4880. begin
  4881. { format:
  4882. * method definition (in Jasmin):
  4883. (private|protected|public) [static] method(parametertypes)returntype
  4884. * method invocation
  4885. package/class/method(parametertypes)returntype
  4886. -> store common part: method(parametertypes)returntype and
  4887. adorn as required when using it.
  4888. }
  4889. if not signature then
  4890. begin
  4891. { method name }
  4892. { special names for constructors and class constructors }
  4893. if proctypeoption=potype_constructor then
  4894. tmpresult:='<init>'
  4895. else if proctypeoption in [potype_class_constructor,potype_unitinit] then
  4896. tmpresult:='<clinit>'
  4897. else if po_has_importname in procoptions then
  4898. begin
  4899. if assigned(import_name) then
  4900. tmpresult:=import_name^
  4901. else
  4902. internalerror(2010122608);
  4903. end
  4904. else
  4905. begin
  4906. tmpresult:=procsym.realname;
  4907. if tmpresult[1]='$' then
  4908. tmpresult:=copy(tmpresult,2,length(tmpresult)-1);
  4909. { nested functions }
  4910. container:=owner;
  4911. while container.symtabletype=localsymtable do
  4912. begin
  4913. tmpresult:='$'+tprocdef(owner.defowner).procsym.realname+'$'+tostr(tprocdef(owner.defowner).procsym.symid)+'$'+tmpresult;
  4914. container:=container.defowner.owner;
  4915. end;
  4916. end;
  4917. end
  4918. else
  4919. tmpresult:='';
  4920. { parameter types }
  4921. tmpresult:=tmpresult+'(';
  4922. { not the case for the main program (not required for defaultmangledname
  4923. because setmangledname() is called for the main program; in case of
  4924. the JVM, this only sets the importname, however) }
  4925. if assigned(paras) then
  4926. begin
  4927. init_paraloc_info(callerside);
  4928. for i:=0 to paras.count-1 do
  4929. begin
  4930. vs:=tparavarsym(paras[i]);
  4931. { function result is not part of the mangled name }
  4932. if vo_is_funcret in vs.varoptions then
  4933. continue;
  4934. { self pointer neither, except for class methods (the JVM only
  4935. supports static class methods natively, so the self pointer
  4936. here is a regular parameter as far as the JVM is concerned }
  4937. if not(po_classmethod in procoptions) and
  4938. (vo_is_self in vs.varoptions) then
  4939. continue;
  4940. { passing by reference is emulated by passing an array of one
  4941. element containing the value; for types that aren't pointers
  4942. in regular Pascal, simply passing the underlying pointer type
  4943. does achieve regular call-by-reference semantics though;
  4944. formaldefs always have to be passed like that because their
  4945. contents can be replaced }
  4946. if paramanager.push_copyout_param(vs.varspez,vs.vardef,proccalloption) then
  4947. tmpresult:=tmpresult+'[';
  4948. { Add the parameter type. }
  4949. if not jvmaddencodedtype(vs.vardef,false,tmpresult,signature,founderror) then
  4950. { an internalerror here is also triggered in case of errors in the source code }
  4951. tmpresult:='<error>';
  4952. end;
  4953. end;
  4954. tmpresult:=tmpresult+')';
  4955. { And the type of the function result (void in case of a procedure and
  4956. constructor). }
  4957. if (proctypeoption in [potype_constructor,potype_class_constructor]) then
  4958. jvmaddencodedtype(voidtype,false,tmpresult,signature,founderror)
  4959. else if not jvmaddencodedtype(returndef,false,tmpresult,signature,founderror) then
  4960. { an internalerror here is also triggered in case of errors in the source code }
  4961. tmpresult:='<error>';
  4962. result:=tmpresult;
  4963. end;
  4964. {$endif jvm}
  4965. procedure tprocdef.setmangledname(const s : TSymStr);
  4966. begin
  4967. { This is not allowed anymore, the forward declaration
  4968. already needs to create the correct mangledname, no changes
  4969. afterwards are allowed (PFV) }
  4970. { Exception: interface definitions in mode macpas, since in that }
  4971. { case no reference to the old name can exist yet (JM) }
  4972. {$ifdef symansistr}
  4973. if _mangledname<>'' then
  4974. if ((m_mac in current_settings.modeswitches) and
  4975. (interfacedef)) then
  4976. _mangledname:=''
  4977. else
  4978. internalerror(200411171);
  4979. {$else symansistr}
  4980. if assigned(_mangledname) then
  4981. if ((m_mac in current_settings.modeswitches) and
  4982. (interfacedef)) then
  4983. stringdispose(_mangledname)
  4984. else
  4985. internalerror(200411171);
  4986. {$endif symansistr}
  4987. {$ifdef jvm}
  4988. { this routine can be called for compilerproces. can't set mangled
  4989. name since it must be calculated, but it uses import_name when set
  4990. -> set that one }
  4991. import_name:=stringdup(s);
  4992. include(procoptions,po_has_importname);
  4993. include(procoptions,po_has_mangledname);
  4994. {$else}
  4995. {$ifdef compress}
  4996. {$error add support for symansistr}
  4997. _mangledname:=stringdup(minilzw_encode(s));
  4998. {$else}
  4999. {$ifdef symansistr}
  5000. _mangledname:=s;
  5001. {$else symansistr}
  5002. _mangledname:=stringdup(s);
  5003. {$endif symansistr}
  5004. {$endif}
  5005. {$endif jvm}
  5006. include(procoptions,po_has_mangledname);
  5007. end;
  5008. {***************************************************************************
  5009. TPROCVARDEF
  5010. ***************************************************************************}
  5011. constructor tprocvardef.create(level:byte);
  5012. begin
  5013. inherited create(procvardef,level);
  5014. end;
  5015. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  5016. begin
  5017. inherited ppuload(procvardef,ppufile);
  5018. { load para symtable }
  5019. parast:=tparasymtable.create(self,ppufile.getbyte);
  5020. {$ifdef jvm}
  5021. ppufile.getderef(classdefderef);
  5022. {$endif}
  5023. tparasymtable(parast).ppuload(ppufile);
  5024. end;
  5025. function tprocvardef.getcopy : tstoreddef;
  5026. var
  5027. i : tcallercallee;
  5028. j : longint;
  5029. begin
  5030. result:=tprocvardef.create(parast.symtablelevel);
  5031. tprocvardef(result).returndef:=returndef;
  5032. tprocvardef(result).returndefderef:=returndefderef;
  5033. tprocvardef(result).parast:=parast.getcopy;
  5034. tprocvardef(result).savesize:=savesize;
  5035. { create paralist copy }
  5036. calcparas;
  5037. tprocvardef(result).paras:=tparalist.create(false);
  5038. tprocvardef(result).paras.count:=paras.count;
  5039. for j:=0 to paras.count-1 do
  5040. tprocvardef(result).paras[j]:=paras[j];
  5041. tprocvardef(result).proctypeoption:=proctypeoption;
  5042. tprocvardef(result).proccalloption:=proccalloption;
  5043. tprocvardef(result).procoptions:=procoptions;
  5044. tprocvardef(result).callerargareasize:=callerargareasize;
  5045. tprocvardef(result).calleeargareasize:=calleeargareasize;
  5046. tprocvardef(result).maxparacount:=maxparacount;
  5047. tprocvardef(result).minparacount:=minparacount;
  5048. for i:=low(tcallercallee) to high(tcallercallee) do
  5049. tprocvardef(result).funcretloc[i]:=funcretloc[i].getcopy;
  5050. tprocvardef(result).has_paraloc_info:=has_paraloc_info;
  5051. {$ifdef m68k}
  5052. tprocvardef(result).exp_funcretloc:=exp_funcretloc;
  5053. {$endif}
  5054. {$ifdef jvm}
  5055. tprocvardef(result).classdef:=classdef;
  5056. {$endif}
  5057. end;
  5058. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  5059. begin
  5060. inherited ppuwrite(ppufile);
  5061. { Save the para symtable level (necessary to distinguish nested
  5062. procvars) }
  5063. ppufile.putbyte(parast.symtablelevel);
  5064. {$ifdef jvm}
  5065. ppufile.putderef(classdefderef);
  5066. {$endif}
  5067. { Write this entry }
  5068. ppufile.writeentry(ibprocvardef);
  5069. { Save the para symtable, this is taken from the interface }
  5070. tparasymtable(parast).ppuwrite(ppufile);
  5071. end;
  5072. {$ifdef jvm}
  5073. procedure tprocvardef.buildderef;
  5074. begin
  5075. inherited buildderef;
  5076. classdefderef.build(classdef);
  5077. end;
  5078. procedure tprocvardef.deref;
  5079. begin
  5080. inherited deref;
  5081. classdef:=tobjectdef(classdefderef.resolve);
  5082. end;
  5083. {$endif}
  5084. function tprocvardef.GetSymtable(t:tGetSymtable):TSymtable;
  5085. begin
  5086. case t of
  5087. gs_para :
  5088. GetSymtable:=parast;
  5089. else
  5090. GetSymtable:=nil;
  5091. end;
  5092. end;
  5093. function tprocvardef.size : asizeint;
  5094. var
  5095. far_code_extra_bytes: integer = 0;
  5096. far_data_extra_bytes: integer = 0;
  5097. begin
  5098. {$ifdef i8086}
  5099. if po_far in procoptions then
  5100. far_code_extra_bytes:=2;
  5101. if current_settings.x86memorymodel in x86_far_data_models then
  5102. far_data_extra_bytes:=2;
  5103. {$endif i8086}
  5104. if ((po_methodpointer in procoptions) or
  5105. is_nested_pd(self)) and
  5106. not(po_addressonly in procoptions) then
  5107. size:=2*sizeof(pint)+far_code_extra_bytes+far_data_extra_bytes
  5108. else
  5109. size:=sizeof(pint)+far_code_extra_bytes;
  5110. end;
  5111. function tprocvardef.is_methodpointer:boolean;
  5112. begin
  5113. result:=(po_methodpointer in procoptions);
  5114. end;
  5115. function tprocvardef.is_addressonly:boolean;
  5116. begin
  5117. result:=(not(po_methodpointer in procoptions) and
  5118. not is_nested_pd(self)) or
  5119. (po_addressonly in procoptions);
  5120. end;
  5121. function tprocvardef.getmangledparaname:TSymStr;
  5122. begin
  5123. if not(po_methodpointer in procoptions) then
  5124. if not is_nested_pd(self) then
  5125. result:='procvar'
  5126. else
  5127. result:='nestedprovar'
  5128. else
  5129. result:='procvarofobj'
  5130. end;
  5131. function tprocvardef.is_publishable : boolean;
  5132. begin
  5133. is_publishable:=(po_methodpointer in procoptions);
  5134. end;
  5135. function tprocvardef.GetTypeName : string;
  5136. var
  5137. s: string;
  5138. pno : tprocnameoptions;
  5139. begin
  5140. {$ifdef EXTDEBUG}
  5141. pno:=[pno_showhidden];
  5142. {$else EXTDEBUG}
  5143. pno:=[];
  5144. {$endif EXTDEBUG}
  5145. s:='<';
  5146. if po_classmethod in procoptions then
  5147. s := s+'class method type of'
  5148. else
  5149. if po_addressonly in procoptions then
  5150. s := s+'address of'
  5151. else
  5152. s := s+'procedure variable type of';
  5153. if assigned(returndef) and
  5154. (returndef<>voidtype) then
  5155. s:=s+' function'+typename_paras(pno)+':'+returndef.GetTypeName
  5156. else
  5157. s:=s+' procedure'+typename_paras(pno);
  5158. if po_methodpointer in procoptions then
  5159. s := s+' of object';
  5160. if is_nested_pd(self) then
  5161. s := s+' is nested';
  5162. GetTypeName := s+';'+ProcCallOptionStr[proccalloption]+'>';
  5163. end;
  5164. {***************************************************************************
  5165. TOBJECTDEF
  5166. ***************************************************************************}
  5167. constructor tobjectdef.create(ot:tobjecttyp;const n:string;c:tobjectdef);
  5168. begin
  5169. inherited create(n,objectdef);
  5170. fcurrent_dispid:=0;
  5171. objecttype:=ot;
  5172. childof:=nil;
  5173. if objecttype=odt_helper then
  5174. owner.includeoption(sto_has_helper);
  5175. symtable:=tObjectSymtable.create(self,n,current_settings.packrecords);
  5176. { create space for vmt !! }
  5177. vmtentries:=TFPList.Create;
  5178. vmt_offset:=0;
  5179. set_parent(c);
  5180. if objecttype in [odt_interfacecorba,odt_interfacecom,odt_dispinterface] then
  5181. prepareguid;
  5182. { setup implemented interfaces }
  5183. if objecttype in [odt_class,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  5184. ImplementedInterfaces:=TFPObjectList.Create(true)
  5185. else
  5186. ImplementedInterfaces:=nil;
  5187. writing_class_record_dbginfo:=false;
  5188. end;
  5189. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  5190. var
  5191. i,
  5192. implintfcount : longint;
  5193. d, getterd : tderef;
  5194. ImplIntf : TImplementedInterface;
  5195. vmtentry : pvmtentry;
  5196. begin
  5197. inherited ppuload(objectdef,ppufile);
  5198. objecttype:=tobjecttyp(ppufile.getbyte);
  5199. objextname:=stringdup(ppufile.getstring);
  5200. { only used for external Objective-C classes/protocols }
  5201. if (objextname^='') then
  5202. stringdispose(objextname);
  5203. symtable:=tObjectSymtable.create(self,objrealname^,0);
  5204. tObjectSymtable(symtable).datasize:=ppufile.getasizeint;
  5205. tObjectSymtable(symtable).paddingsize:=ppufile.getword;
  5206. tObjectSymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  5207. tObjectSymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  5208. vmt_offset:=ppufile.getlongint;
  5209. ppufile.getderef(childofderef);
  5210. { load guid }
  5211. iidstr:=nil;
  5212. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  5213. begin
  5214. new(iidguid);
  5215. ppufile.getguid(iidguid^);
  5216. iidstr:=stringdup(ppufile.getstring);
  5217. end;
  5218. abstractcnt:=ppufile.getlongint;
  5219. if objecttype=odt_helper then
  5220. ppufile.getderef(extendeddefderef);
  5221. vmtentries:=TFPList.Create;
  5222. vmtentries.count:=ppufile.getlongint;
  5223. for i:=0 to vmtentries.count-1 do
  5224. begin
  5225. ppufile.getderef(d);
  5226. new(vmtentry);
  5227. vmtentry^.procdef:=nil;
  5228. vmtentry^.procdefderef:=d;
  5229. vmtentry^.visibility:=tvisibility(ppufile.getbyte);
  5230. vmtentries[i]:=vmtentry;
  5231. end;
  5232. { load implemented interfaces }
  5233. if objecttype in [odt_class,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  5234. begin
  5235. ImplementedInterfaces:=TFPObjectList.Create(true);
  5236. implintfcount:=ppufile.getlongint;
  5237. for i:=0 to implintfcount-1 do
  5238. begin
  5239. ppufile.getderef(d);
  5240. ppufile.getderef(getterd);
  5241. ImplIntf:=TImplementedInterface.Create_deref(d,getterd);
  5242. ImplIntf.IOffset:=ppufile.getlongint;
  5243. byte(ImplIntf.IType):=ppufile.getbyte;
  5244. ImplementedInterfaces.Add(ImplIntf);
  5245. end;
  5246. end
  5247. else
  5248. ImplementedInterfaces:=nil;
  5249. if df_copied_def in defoptions then
  5250. ppufile.getderef(cloneddefderef)
  5251. else
  5252. tObjectSymtable(symtable).ppuload(ppufile);
  5253. { handles the predefined class tobject }
  5254. { the last TOBJECT which is loaded gets }
  5255. { it ! }
  5256. if (childof=nil) and
  5257. (objecttype in [odt_class,odt_javaclass]) and
  5258. (objname^='TOBJECT') then
  5259. class_tobject:=self;
  5260. if (childof=nil) and
  5261. (objecttype=odt_interfacecom) then
  5262. if (objname^='IUNKNOWN') then
  5263. interface_iunknown:=self
  5264. else
  5265. if (objname^='IDISPATCH') then
  5266. interface_idispatch:=self;
  5267. if (childof=nil) and
  5268. (objecttype=odt_objcclass) and
  5269. (objname^='PROTOCOL') then
  5270. objc_protocoltype:=self;
  5271. if (objecttype=odt_javaclass) and
  5272. not(oo_is_formal in objectoptions) then
  5273. begin
  5274. if (objname^='JLOBJECT') then
  5275. java_jlobject:=self
  5276. else if (objname^='JLTHROWABLE') then
  5277. java_jlthrowable:=self
  5278. else if (objname^='FPCBASERECORDTYPE') then
  5279. java_fpcbaserecordtype:=self
  5280. else if (objname^='JLSTRING') then
  5281. java_jlstring:=self
  5282. else if (objname^='ANSISTRINGCLASS') then
  5283. java_ansistring:=self
  5284. else if (objname^='SHORTSTRINGCLASS') then
  5285. java_shortstring:=self
  5286. else if (objname^='JLENUM') then
  5287. java_jlenum:=self
  5288. else if (objname^='JUENUMSET') then
  5289. java_juenumset:=self
  5290. else if (objname^='FPCBITSET') then
  5291. java_jubitset:=self
  5292. else if (objname^='FPCBASEPROCVARTYPE') then
  5293. java_procvarbase:=self;
  5294. end;
  5295. writing_class_record_dbginfo:=false;
  5296. end;
  5297. destructor tobjectdef.destroy;
  5298. begin
  5299. if assigned(symtable) then
  5300. begin
  5301. symtable.free;
  5302. symtable:=nil;
  5303. end;
  5304. stringdispose(objextname);
  5305. stringdispose(iidstr);
  5306. if assigned(ImplementedInterfaces) then
  5307. begin
  5308. ImplementedInterfaces.free;
  5309. ImplementedInterfaces:=nil;
  5310. end;
  5311. if assigned(iidguid) then
  5312. begin
  5313. dispose(iidguid);
  5314. iidguid:=nil;
  5315. end;
  5316. if assigned(vmtentries) then
  5317. begin
  5318. resetvmtentries;
  5319. vmtentries.free;
  5320. vmtentries:=nil;
  5321. end;
  5322. if assigned(vmcallstaticinfo) then
  5323. begin
  5324. freemem(vmcallstaticinfo);
  5325. vmcallstaticinfo:=nil;
  5326. end;
  5327. inherited destroy;
  5328. end;
  5329. function tobjectdef.getcopy : tstoreddef;
  5330. var
  5331. i : longint;
  5332. begin
  5333. result:=tobjectdef.create(objecttype,objrealname^,childof);
  5334. { the constructor allocates a symtable which we release to avoid memory leaks }
  5335. tobjectdef(result).symtable.free;
  5336. tobjectdef(result).symtable:=symtable.getcopy;
  5337. if assigned(objextname) then
  5338. tobjectdef(result).objextname:=stringdup(objextname^);
  5339. if assigned(import_lib) then
  5340. tobjectdef(result).import_lib:=stringdup(import_lib^);
  5341. tobjectdef(result).objectoptions:=objectoptions;
  5342. include(tobjectdef(result).defoptions,df_copied_def);
  5343. tobjectdef(result).extendeddef:=extendeddef;
  5344. if assigned(tcinitcode) then
  5345. tobjectdef(result).tcinitcode:=tcinitcode.getcopy;
  5346. tobjectdef(result).vmt_offset:=vmt_offset;
  5347. if assigned(iidguid) then
  5348. begin
  5349. new(tobjectdef(result).iidguid);
  5350. move(iidguid^,tobjectdef(result).iidguid^,sizeof(iidguid^));
  5351. end;
  5352. if assigned(iidstr) then
  5353. tobjectdef(result).iidstr:=stringdup(iidstr^);
  5354. tobjectdef(result).abstractcnt:=abstractcnt;
  5355. if assigned(ImplementedInterfaces) then
  5356. begin
  5357. for i:=0 to ImplementedInterfaces.count-1 do
  5358. tobjectdef(result).ImplementedInterfaces.Add(TImplementedInterface(ImplementedInterfaces[i]).Getcopy);
  5359. end;
  5360. if assigned(vmtentries) then
  5361. begin
  5362. tobjectdef(result).vmtentries:=TFPList.Create;
  5363. tobjectdef(result).copyvmtentries(self);
  5364. end;
  5365. end;
  5366. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  5367. var
  5368. i : longint;
  5369. vmtentry : pvmtentry;
  5370. ImplIntf : TImplementedInterface;
  5371. old_do_indirect_crc: boolean;
  5372. begin
  5373. { if class1 in unit A changes, and class2 in unit B inherits from it
  5374. (so unit B uses unit A), then unit B with class2 will be recompiled.
  5375. However, if there is also a class3 in unit C that only depends on
  5376. unit B, then unit C will not be recompiled because nothing changed
  5377. to the interface of unit B. Nevertheless, unit C can indirectly
  5378. depend on unit A via derefs, and these must be updated -> the
  5379. indirect crc keeps track of such changes. }
  5380. old_do_indirect_crc:=ppufile.do_indirect_crc;
  5381. ppufile.do_indirect_crc:=true;
  5382. inherited ppuwrite(ppufile);
  5383. ppufile.putbyte(byte(objecttype));
  5384. if assigned(objextname) then
  5385. ppufile.putstring(objextname^)
  5386. else
  5387. ppufile.putstring('');
  5388. ppufile.putasizeint(tObjectSymtable(symtable).datasize);
  5389. ppufile.putword(tObjectSymtable(symtable).paddingsize);
  5390. ppufile.putbyte(byte(tObjectSymtable(symtable).fieldalignment));
  5391. ppufile.putbyte(byte(tObjectSymtable(symtable).recordalignment));
  5392. ppufile.putlongint(vmt_offset);
  5393. ppufile.putderef(childofderef);
  5394. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  5395. begin
  5396. ppufile.putguid(iidguid^);
  5397. ppufile.putstring(iidstr^);
  5398. end;
  5399. ppufile.putlongint(abstractcnt);
  5400. if objecttype=odt_helper then
  5401. ppufile.putderef(extendeddefderef);
  5402. ppufile.putlongint(vmtentries.count);
  5403. for i:=0 to vmtentries.count-1 do
  5404. begin
  5405. vmtentry:=pvmtentry(vmtentries[i]);
  5406. ppufile.putderef(vmtentry^.procdefderef);
  5407. ppufile.putbyte(byte(vmtentry^.visibility));
  5408. end;
  5409. if assigned(ImplementedInterfaces) then
  5410. begin
  5411. ppufile.putlongint(ImplementedInterfaces.Count);
  5412. for i:=0 to ImplementedInterfaces.Count-1 do
  5413. begin
  5414. ImplIntf:=TImplementedInterface(ImplementedInterfaces[i]);
  5415. ppufile.putderef(ImplIntf.intfdefderef);
  5416. ppufile.putderef(ImplIntf.ImplementsGetterDeref);
  5417. ppufile.putlongint(ImplIntf.Ioffset);
  5418. ppufile.putbyte(byte(ImplIntf.IType));
  5419. end;
  5420. end;
  5421. if df_copied_def in defoptions then
  5422. ppufile.putderef(cloneddefderef);
  5423. ppufile.writeentry(ibobjectdef);
  5424. if not(df_copied_def in defoptions) then
  5425. tObjectSymtable(symtable).ppuwrite(ppufile);
  5426. ppufile.do_indirect_crc:=old_do_indirect_crc;
  5427. end;
  5428. function tobjectdef.GetTypeName:string;
  5429. begin
  5430. { in this case we will go in endless recursion, because then }
  5431. { there is no tsym associated yet with the def. It can occur }
  5432. { (tests/webtbf/tw4757.pp), so for now give a generic name }
  5433. { instead of the actual type name }
  5434. if not assigned(typesym) then
  5435. result:='<Currently Parsed Class>'
  5436. else
  5437. result:=typesymbolprettyname;
  5438. end;
  5439. procedure tobjectdef.buildderef;
  5440. var
  5441. i : longint;
  5442. vmtentry : pvmtentry;
  5443. begin
  5444. inherited buildderef;
  5445. childofderef.build(childof);
  5446. if df_copied_def in defoptions then
  5447. cloneddefderef.build(symtable.defowner)
  5448. else
  5449. tstoredsymtable(symtable).buildderef;
  5450. if objecttype=odt_helper then
  5451. extendeddefderef.build(extendeddef);
  5452. for i:=0 to vmtentries.count-1 do
  5453. begin
  5454. vmtentry:=pvmtentry(vmtentries[i]);
  5455. vmtentry^.procdefderef.build(vmtentry^.procdef);
  5456. end;
  5457. if assigned(ImplementedInterfaces) then
  5458. begin
  5459. for i:=0 to ImplementedInterfaces.count-1 do
  5460. TImplementedInterface(ImplementedInterfaces[i]).buildderef;
  5461. end;
  5462. end;
  5463. procedure tobjectdef.deref;
  5464. var
  5465. i : longint;
  5466. vmtentry : pvmtentry;
  5467. begin
  5468. inherited deref;
  5469. childof:=tobjectdef(childofderef.resolve);
  5470. if df_copied_def in defoptions then
  5471. begin
  5472. cloneddef:=tobjectdef(cloneddefderef.resolve);
  5473. symtable:=cloneddef.symtable.getcopy;
  5474. end
  5475. else
  5476. tstoredsymtable(symtable).deref;
  5477. fillgenericparas(symtable);
  5478. if objecttype=odt_helper then
  5479. extendeddef:=tdef(extendeddefderef.resolve);
  5480. for i:=0 to vmtentries.count-1 do
  5481. begin
  5482. vmtentry:=pvmtentry(vmtentries[i]);
  5483. vmtentry^.procdef:=tprocdef(vmtentry^.procdefderef.resolve);
  5484. end;
  5485. if assigned(ImplementedInterfaces) then
  5486. begin
  5487. for i:=0 to ImplementedInterfaces.count-1 do
  5488. TImplementedInterface(ImplementedInterfaces[i]).deref;
  5489. end;
  5490. end;
  5491. procedure create_class_helper_for_procdef(def: tobject; arg: pointer);
  5492. var
  5493. pd: tprocdef absolute def;
  5494. st: tsymtable;
  5495. psym: tsym;
  5496. nname: TIDString;
  5497. begin
  5498. if (tdef(def).typ<>procdef) then
  5499. exit;
  5500. { pd.owner = objcclass symtable -> defowner = objcclassdef ->
  5501. owner = symtable in which objcclassdef is defined
  5502. }
  5503. st:=pd.owner.defowner.owner;
  5504. nname:=class_helper_prefix+tprocsym(pd.procsym).name;
  5505. { check for an existing procsym with our special name }
  5506. psym:=tsym(st.find(nname));
  5507. if not assigned(psym) then
  5508. begin
  5509. psym:=tprocsym.create(nname);
  5510. { avoid warning about this symbol being unused }
  5511. psym.IncRefCount;
  5512. { don't check for duplicates:
  5513. a) we checked above
  5514. b) in case we are in the implementation section of a unit, this
  5515. will also check for this symbol in the interface section
  5516. (since you normally cannot have symbols with the same name
  5517. both interface and implementation), and it's possible to
  5518. have class helpers for the same class in the interface and
  5519. in the implementation, and they cannot be merged since only
  5520. the once in the interface must be saved to the ppu/visible
  5521. from other units }
  5522. st.insert(psym,false);
  5523. end
  5524. else if (psym.typ<>procsym) then
  5525. internalerror(2009111501);
  5526. { add ourselves to this special procsym }
  5527. tprocsym(psym).procdeflist.add(def);
  5528. end;
  5529. procedure tobjectdef.buildderefimpl;
  5530. begin
  5531. inherited buildderefimpl;
  5532. if not (df_copied_def in defoptions) then
  5533. tstoredsymtable(symtable).buildderefimpl;
  5534. end;
  5535. procedure tobjectdef.derefimpl;
  5536. begin
  5537. inherited derefimpl;
  5538. if not (df_copied_def in defoptions) then
  5539. tstoredsymtable(symtable).derefimpl;
  5540. { the procdefs are not owned by the class helper procsyms, so they
  5541. are not stored/restored either -> re-add them here }
  5542. if (objecttype=odt_objcclass) or
  5543. (oo_is_classhelper in objectoptions) then
  5544. symtable.DefList.ForEachCall(@create_class_helper_for_procdef,nil);
  5545. end;
  5546. procedure tobjectdef.resetvmtentries;
  5547. var
  5548. i : longint;
  5549. begin
  5550. for i:=0 to vmtentries.Count-1 do
  5551. Dispose(pvmtentry(vmtentries[i]));
  5552. vmtentries.clear;
  5553. end;
  5554. procedure tobjectdef.copyvmtentries(objdef:tobjectdef);
  5555. var
  5556. i : longint;
  5557. vmtentry : pvmtentry;
  5558. begin
  5559. resetvmtentries;
  5560. vmtentries.count:=objdef.vmtentries.count;
  5561. for i:=0 to objdef.vmtentries.count-1 do
  5562. begin
  5563. new(vmtentry);
  5564. vmtentry^:=pvmtentry(objdef.vmtentries[i])^;
  5565. vmtentries[i]:=vmtentry;
  5566. end;
  5567. end;
  5568. function tobjectdef.getparentdef:tdef;
  5569. begin
  5570. { TODO: Remove getparentdef hack}
  5571. { With 2 forward declared classes with the child class before the
  5572. parent class the child class is written earlier to the ppu. Leaving it
  5573. possible to have a reference to the parent class for property overriding,
  5574. but the parent class still has the childof not resolved yet (PFV) }
  5575. if childof=nil then
  5576. childof:=tobjectdef(childofderef.resolve);
  5577. result:=childof;
  5578. end;
  5579. procedure tobjectdef.prepareguid;
  5580. begin
  5581. { set up guid }
  5582. if not assigned(iidguid) then
  5583. begin
  5584. new(iidguid);
  5585. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  5586. end;
  5587. { setup iidstring }
  5588. if not assigned(iidstr) then
  5589. iidstr:=stringdup(''); { default is empty string }
  5590. end;
  5591. procedure tobjectdef.set_parent( c : tobjectdef);
  5592. begin
  5593. if assigned(childof) then
  5594. exit;
  5595. childof:=c;
  5596. if not assigned(c) then
  5597. exit;
  5598. { inherit options and status }
  5599. objectoptions:=objectoptions+(c.objectoptions*inherited_objectoptions);
  5600. { initially has the same number of abstract methods as the parent }
  5601. abstractcnt:=c.abstractcnt;
  5602. { add the data of the anchestor class/object }
  5603. if (objecttype in [odt_class,odt_object,odt_objcclass,odt_javaclass]) then
  5604. begin
  5605. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize+tObjectSymtable(c.symtable).datasize;
  5606. { inherit recordalignment }
  5607. tObjectSymtable(symtable).recordalignment:=tObjectSymtable(c.symtable).recordalignment;
  5608. { if both the parent and this record use C-alignment, also inherit
  5609. the current field alignment }
  5610. if (tObjectSymtable(c.symtable).usefieldalignment=C_alignment) and
  5611. (tObjectSymtable(symtable).usefieldalignment=C_alignment) then
  5612. tObjectSymtable(symtable).fieldalignment:=tObjectSymtable(c.symtable).fieldalignment;
  5613. { the padding is not inherited for Objective-C classes (maybe not
  5614. for cppclass either?) }
  5615. if objecttype=odt_objcclass then
  5616. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize-tObjectSymtable(c.symtable).paddingsize;
  5617. if (oo_has_vmt in objectoptions) and
  5618. (oo_has_vmt in c.objectoptions) then
  5619. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize-sizeof(pint);
  5620. { if parent has a vmt field then the offset is the same for the child PM }
  5621. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  5622. begin
  5623. vmt_offset:=c.vmt_offset;
  5624. include(objectoptions,oo_has_vmt);
  5625. end;
  5626. end;
  5627. end;
  5628. procedure tobjectdef.insertvmt;
  5629. var
  5630. vs: tfieldvarsym;
  5631. begin
  5632. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  5633. exit;
  5634. if (oo_has_vmt in objectoptions) then
  5635. internalerror(12345)
  5636. else
  5637. begin
  5638. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,
  5639. tObjectSymtable(symtable).fieldalignment);
  5640. if (tf_requires_proper_alignment in target_info.flags) then
  5641. begin
  5642. { Align VMT pointer and whole object instance if target CPU requires alignment. }
  5643. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,sizeof(pint));
  5644. tObjectSymtable(symtable).alignrecord(tObjectSymtable(symtable).datasize,sizeof(pint));
  5645. end;
  5646. vs:=tfieldvarsym.create('_vptr$'+objname^,vs_value,voidpointertype,[]);
  5647. hidesym(vs);
  5648. tObjectSymtable(symtable).insert(vs);
  5649. tObjectSymtable(symtable).addfield(vs,vis_hidden);
  5650. if (tObjectSymtable(symtable).usefieldalignment<>bit_alignment) then
  5651. vmt_offset:=vs.fieldoffset
  5652. else
  5653. vmt_offset:=vs.fieldoffset div 8;
  5654. include(objectoptions,oo_has_vmt);
  5655. end;
  5656. end;
  5657. procedure tobjectdef.check_forwards;
  5658. begin
  5659. if not(objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcprotocol,odt_interfacejava]) then
  5660. inherited;
  5661. if (oo_is_forward in objectoptions) then
  5662. begin
  5663. { ok, in future, the forward can be resolved }
  5664. Message1(sym_e_class_forward_not_resolved,objrealname^);
  5665. exclude(objectoptions,oo_is_forward);
  5666. end;
  5667. end;
  5668. function tobjectdef.find_destructor: tprocdef;
  5669. var
  5670. objdef: tobjectdef;
  5671. begin
  5672. objdef:=self;
  5673. while assigned(objdef) do
  5674. begin
  5675. result:=objdef.find_procdef_bytype(potype_destructor);
  5676. if assigned(result) then
  5677. exit;
  5678. objdef:=objdef.childof;
  5679. end;
  5680. result:=nil;
  5681. end;
  5682. function tobjectdef.implements_any_interfaces: boolean;
  5683. begin
  5684. result := (ImplementedInterfaces.Count > 0) or
  5685. (assigned(childof) and childof.implements_any_interfaces);
  5686. end;
  5687. function tobjectdef.size : asizeint;
  5688. begin
  5689. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava] then
  5690. result:=sizeof(pint)
  5691. else
  5692. result:=tObjectSymtable(symtable).datasize;
  5693. end;
  5694. function tobjectdef.alignment:shortint;
  5695. begin
  5696. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava] then
  5697. alignment:=sizeof(pint)
  5698. else
  5699. alignment:=tObjectSymtable(symtable).recordalignment;
  5700. end;
  5701. function tobjectdef.vmtmethodoffset(index:longint):longint;
  5702. var
  5703. codeptrsize: Integer;
  5704. begin
  5705. {$ifdef i8086}
  5706. if current_settings.x86memorymodel in x86_far_code_models then
  5707. codeptrsize:=4
  5708. else
  5709. codeptrsize:=2;
  5710. {$else i8086}
  5711. codeptrsize:=sizeof(pint);
  5712. {$endif i8086}
  5713. { for offset of methods for classes, see rtl/inc/objpash.inc }
  5714. case objecttype of
  5715. odt_class:
  5716. { the +2*sizeof(pint) is size and -size }
  5717. vmtmethodoffset:=index*codeptrsize+10*sizeof(pint)+2*sizeof(pint);
  5718. odt_helper,
  5719. odt_objcclass,
  5720. odt_objcprotocol:
  5721. vmtmethodoffset:=0;
  5722. odt_interfacecom,odt_interfacecorba,odt_dispinterface:
  5723. vmtmethodoffset:=index*codeptrsize;
  5724. odt_javaclass,
  5725. odt_interfacejava:
  5726. { invalid }
  5727. vmtmethodoffset:=-1;
  5728. else
  5729. {$ifdef WITHDMT}
  5730. vmtmethodoffset:=index*codeptrsize+4*sizeof(pint);
  5731. {$else WITHDMT}
  5732. vmtmethodoffset:=index*codeptrsize+3*sizeof(pint);
  5733. {$endif WITHDMT}
  5734. end;
  5735. end;
  5736. function tobjectdef.vmt_mangledname : TSymStr;
  5737. begin
  5738. if not(oo_has_vmt in objectoptions) then
  5739. Message1(parser_n_object_has_no_vmt,objrealname^);
  5740. vmt_mangledname:=make_mangledname('VMT',owner,objname^);
  5741. end;
  5742. function tobjectdef.needs_inittable : boolean;
  5743. var
  5744. hp : tobjectdef;
  5745. begin
  5746. case objecttype of
  5747. odt_helper,
  5748. odt_class :
  5749. needs_inittable:=false;
  5750. odt_dispinterface,
  5751. odt_interfacecom:
  5752. needs_inittable:=true;
  5753. odt_interfacecorba:
  5754. begin
  5755. hp:=childof;
  5756. while assigned(hp) do
  5757. begin
  5758. if hp=interface_iunknown then
  5759. begin
  5760. needs_inittable:=true;
  5761. exit;
  5762. end;
  5763. hp:=hp.childof;
  5764. end;
  5765. needs_inittable:=false;
  5766. end;
  5767. odt_object:
  5768. needs_inittable:=
  5769. tObjectSymtable(symtable).needs_init_final or
  5770. (assigned(childof) and
  5771. childof.needs_inittable);
  5772. odt_cppclass,
  5773. odt_objcclass,
  5774. odt_objcprotocol,
  5775. odt_javaclass,
  5776. odt_interfacejava:
  5777. needs_inittable:=false;
  5778. else
  5779. internalerror(200108267);
  5780. end;
  5781. end;
  5782. function tobjectdef.needs_separate_initrtti : boolean;
  5783. begin
  5784. result:=not (objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface]);
  5785. end;
  5786. function tobjectdef.rtti_mangledname(rt: trttitype): string;
  5787. begin
  5788. if not(objecttype in [odt_objcclass,odt_objcprotocol]) then
  5789. result:=inherited rtti_mangledname(rt)
  5790. else
  5791. begin
  5792. { necessary in case of a dynamic array of nsobject, or
  5793. if an nsobject field appears in a record that needs
  5794. init/finalisation }
  5795. if rt=initrtti then
  5796. begin
  5797. result:=voidpointertype.rtti_mangledname(rt);
  5798. exit;
  5799. end;
  5800. if not(target_info.system in systems_objc_nfabi) then
  5801. begin
  5802. result:=target_asm.labelprefix;
  5803. case objecttype of
  5804. odt_objcclass:
  5805. begin
  5806. case rt of
  5807. objcclassrtti:
  5808. if not(oo_is_classhelper in objectoptions) then
  5809. result:=result+'_OBJC_CLASS_'
  5810. else
  5811. result:=result+'_OBJC_CATEGORY_';
  5812. objcmetartti:
  5813. if not(oo_is_classhelper in objectoptions) then
  5814. result:=result+'_OBJC_METACLASS_'
  5815. else
  5816. internalerror(2009111511);
  5817. else
  5818. internalerror(2009092302);
  5819. end;
  5820. end;
  5821. odt_objcprotocol:
  5822. result:=result+'_OBJC_PROTOCOL_';
  5823. end;
  5824. end
  5825. else
  5826. begin
  5827. case objecttype of
  5828. odt_objcclass:
  5829. begin
  5830. if (oo_is_classhelper in objectoptions) and
  5831. (rt<>objcclassrtti) then
  5832. internalerror(2009111512);
  5833. case rt of
  5834. objcclassrtti:
  5835. if not(oo_is_classhelper in objectoptions) then
  5836. result:='_OBJC_CLASS_$_'
  5837. else
  5838. result:='_OBJC_$_CATEGORY_';
  5839. objcmetartti:
  5840. result:='_OBJC_METACLASS_$_';
  5841. objcclassrortti:
  5842. result:=lower(target_asm.labelprefix)+'_OBJC_CLASS_RO_$_';
  5843. objcmetarortti:
  5844. result:=lower(target_asm.labelprefix)+'_OBJC_METACLASS_RO_$_';
  5845. else
  5846. internalerror(2009092303);
  5847. end;
  5848. end;
  5849. odt_objcprotocol:
  5850. begin
  5851. result:=lower(target_asm.labelprefix);
  5852. case rt of
  5853. objcclassrtti:
  5854. result:=result+'_OBJC_PROTOCOL_$_';
  5855. objcmetartti:
  5856. result:=result+'_OBJC_LABEL_PROTOCOL_$_';
  5857. else
  5858. internalerror(2009092501);
  5859. end;
  5860. end;
  5861. else
  5862. internalerror(2013113005);
  5863. end;
  5864. end;
  5865. result:=result+objextname^;
  5866. end;
  5867. end;
  5868. function tobjectdef.members_need_inittable : boolean;
  5869. begin
  5870. members_need_inittable:=tObjectSymtable(symtable).needs_init_final;
  5871. end;
  5872. function tobjectdef.is_publishable : boolean;
  5873. begin
  5874. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface];
  5875. end;
  5876. function tobjectdef.get_next_dispid: longint;
  5877. begin
  5878. inc(fcurrent_dispid);
  5879. result:=fcurrent_dispid;
  5880. end;
  5881. function tobjectdef.search_enumerator_get: tprocdef;
  5882. begin
  5883. result:=inherited;
  5884. if not assigned(result) and assigned(childof) then
  5885. result:=childof.search_enumerator_get;
  5886. end;
  5887. function tobjectdef.search_enumerator_move: tprocdef;
  5888. begin
  5889. result:=inherited;
  5890. if not assigned(result) and assigned(childof) then
  5891. result:=childof.search_enumerator_move;
  5892. end;
  5893. function tobjectdef.search_enumerator_current: tsym;
  5894. begin
  5895. result:=inherited;
  5896. if not assigned(result) and assigned(childof) then
  5897. result:=childof.search_enumerator_current;
  5898. end;
  5899. procedure tobjectdef.register_created_classref_type;
  5900. begin
  5901. if not classref_created_in_current_module then
  5902. begin
  5903. classref_created_in_current_module:=true;
  5904. current_module.wpoinfo.addcreatedobjtypeforclassref(self);
  5905. end;
  5906. end;
  5907. procedure tobjectdef.register_created_object_type;
  5908. begin
  5909. if not created_in_current_module then
  5910. begin
  5911. created_in_current_module:=true;
  5912. current_module.wpoinfo.addcreatedobjtype(self);
  5913. end;
  5914. end;
  5915. procedure tobjectdef.register_maybe_created_object_type;
  5916. begin
  5917. { if we know it has been created for sure, no need
  5918. to also record that it maybe can be created in
  5919. this module
  5920. }
  5921. if not (created_in_current_module) and
  5922. not (maybe_created_in_current_module) then
  5923. begin
  5924. maybe_created_in_current_module:=true;
  5925. current_module.wpoinfo.addmaybecreatedbyclassref(self);
  5926. end;
  5927. end;
  5928. procedure tobjectdef.register_vmt_call(index: longint);
  5929. begin
  5930. if (is_object(self) or is_class(self)) then
  5931. current_module.wpoinfo.addcalledvmtentry(self,index);
  5932. end;
  5933. procedure check_and_finish_msg(data: tobject; arg: pointer);
  5934. var
  5935. def: tdef absolute data;
  5936. pd: tprocdef absolute data;
  5937. i,
  5938. paracount: longint;
  5939. begin
  5940. if (def.typ=procdef) then
  5941. begin
  5942. { add all messages also under a dummy name to the symtable in
  5943. which the objcclass/protocol/category is declared, so they can
  5944. be called via id.<name>
  5945. }
  5946. create_class_helper_for_procdef(pd,nil);
  5947. { we have to wait until now to set the mangled name because it
  5948. depends on the (possibly external) class name, which is defined
  5949. at the very end. }
  5950. if not(po_msgstr in pd.procoptions) then
  5951. begin
  5952. CGMessagePos(pd.fileinfo,parser_e_objc_requires_msgstr);
  5953. { recover to avoid internalerror later on }
  5954. include(pd.procoptions,po_msgstr);
  5955. pd.messageinf.str:=stringdup('MissingDeclaration');
  5956. end;
  5957. { Mangled name is already set in case this is a copy of
  5958. another type. }
  5959. if not(po_has_mangledname in pd.procoptions) then
  5960. begin
  5961. { check whether the number of formal parameters is correct,
  5962. and whether they have valid Objective-C types }
  5963. paracount:=0;
  5964. for i:=1 to length(pd.messageinf.str^) do
  5965. if pd.messageinf.str^[i]=':' then
  5966. inc(paracount);
  5967. for i:=0 to pd.paras.count-1 do
  5968. if not(vo_is_hidden_para in tparavarsym(pd.paras[i]).varoptions) and
  5969. not is_array_of_const(tparavarsym(pd.paras[i]).vardef) then
  5970. dec(paracount);
  5971. if (paracount<>0) then
  5972. MessagePos(pd.fileinfo,sym_e_objc_para_mismatch);
  5973. pd.setmangledname(pd.objcmangledname);
  5974. end
  5975. else
  5976. { all checks already done }
  5977. exit;
  5978. if not(oo_is_external in pd.struct.objectoptions) then
  5979. begin
  5980. if (po_varargs in pd.procoptions) then
  5981. MessagePos(pd.fileinfo,parser_e_varargs_need_cdecl_and_external)
  5982. else
  5983. begin
  5984. { check for "array of const" parameters }
  5985. for i:=0 to pd.parast.symlist.count-1 do
  5986. begin
  5987. if (tsym(pd.parast.symlist[i]).typ=paravarsym) and
  5988. is_array_of_const(tparavarsym(pd.parast.symlist[i]).vardef) then
  5989. MessagePos(pd.fileinfo,parser_e_varargs_need_cdecl_and_external);
  5990. end;
  5991. end;
  5992. end;
  5993. end;
  5994. end;
  5995. procedure mark_private_fields_used(data: tobject; arg: pointer);
  5996. var
  5997. sym: tsym absolute data;
  5998. begin
  5999. if (sym.typ=fieldvarsym) and
  6000. (tfieldvarsym(sym).visibility in [vis_private,vis_strictprivate]) then
  6001. sym.IncRefCount;
  6002. end;
  6003. procedure tobjectdef.finish_objc_data;
  6004. begin
  6005. self.symtable.DefList.foreachcall(@check_and_finish_msg,nil);
  6006. if (oo_is_external in objectoptions) then
  6007. self.symtable.SymList.ForEachCall(@mark_private_fields_used,nil);
  6008. end;
  6009. procedure verify_objc_vardef(data: tobject; arg: pointer);
  6010. var
  6011. sym: tabstractvarsym absolute data;
  6012. res: pboolean absolute arg;
  6013. founderrordef: tdef;
  6014. begin
  6015. if not(tsym(data).typ in [paravarsym,fieldvarsym]) then
  6016. exit;
  6017. if (sym.typ=paravarsym) and
  6018. ((vo_is_hidden_para in tparavarsym(sym).varoptions) or
  6019. is_array_of_const(tparavarsym(sym).vardef)) then
  6020. exit;
  6021. if not objcchecktype(sym.vardef,founderrordef) then
  6022. begin
  6023. MessagePos1(sym.fileinfo,type_e_objc_type_unsupported,founderrordef.typename);
  6024. res^:=false;
  6025. end;
  6026. end;
  6027. procedure verify_objc_procdef_paras(data: tobject; arg: pointer);
  6028. var
  6029. def: tdef absolute data;
  6030. res: pboolean absolute arg;
  6031. founderrordef: tdef;
  6032. begin
  6033. if (def.typ<>procdef) then
  6034. exit;
  6035. { check parameter types for validity }
  6036. tprocdef(def).paras.foreachcall(@verify_objc_vardef,arg);
  6037. { check the result type for validity }
  6038. if not objcchecktype(tprocdef(def).returndef,founderrordef) then
  6039. begin
  6040. MessagePos1(tprocdef(def).funcretsym.fileinfo,type_e_objc_type_unsupported,founderrordef.typename);
  6041. res^:=false;
  6042. end;
  6043. end;
  6044. function tobjectdef.check_objc_types: boolean;
  6045. begin
  6046. { done in separate step from finish_objc_data, because when
  6047. finish_objc_data is called, not all forwarddefs have been resolved
  6048. yet and we need to know all types here }
  6049. result:=true;
  6050. self.symtable.symlist.foreachcall(@verify_objc_vardef,@result);
  6051. self.symtable.deflist.foreachcall(@verify_objc_procdef_paras,@result);
  6052. end;
  6053. procedure do_cpp_import_info(data: tobject; arg: pointer);
  6054. var
  6055. def: tdef absolute data;
  6056. pd: tprocdef absolute data;
  6057. begin
  6058. if (def.typ=procdef) then
  6059. begin
  6060. pd.setmangledname(target_info.Cprefix+pd.cplusplusmangledname);
  6061. if (oo_is_external in pd.struct.objectoptions) then
  6062. begin
  6063. { copied from psub.read_proc }
  6064. if assigned(tobjectdef(pd.struct).import_lib) then
  6065. current_module.AddExternalImport(tobjectdef(pd.struct).import_lib^,pd.mangledname,pd.mangledname,0,false,false)
  6066. else
  6067. begin
  6068. { add import name to external list for DLL scanning }
  6069. if tf_has_dllscanner in target_info.flags then
  6070. current_module.dllscannerinputlist.Add(pd.mangledname,pd);
  6071. end;
  6072. end;
  6073. end;
  6074. end;
  6075. procedure tobjectdef.finish_cpp_data;
  6076. begin
  6077. self.symtable.DefList.ForEachCall(@do_cpp_import_info,nil);
  6078. end;
  6079. {****************************************************************************
  6080. TImplementedInterface
  6081. ****************************************************************************}
  6082. function TImplementedInterface.GetIOffset: longint;
  6083. begin
  6084. if (fIOffset=-1) and
  6085. (IType in [etFieldValue,etFieldValueClass]) then
  6086. result:=tfieldvarsym(ImplementsField).fieldoffset
  6087. else
  6088. result:=fIOffset;
  6089. end;
  6090. constructor TImplementedInterface.create(aintf: tobjectdef);
  6091. begin
  6092. inherited create;
  6093. intfdef:=aintf;
  6094. IOffset:=-1;
  6095. IType:=etStandard;
  6096. NameMappings:=nil;
  6097. procdefs:=nil;
  6098. end;
  6099. constructor TImplementedInterface.create_deref(intfd,getterd:tderef);
  6100. begin
  6101. inherited create;
  6102. intfdef:=nil;
  6103. intfdefderef:=intfd;
  6104. ImplementsGetterDeref:=getterd;
  6105. IOffset:=-1;
  6106. IType:=etStandard;
  6107. NameMappings:=nil;
  6108. procdefs:=nil;
  6109. end;
  6110. destructor TImplementedInterface.destroy;
  6111. var
  6112. i : longint;
  6113. mappedname : pshortstring;
  6114. begin
  6115. if assigned(NameMappings) then
  6116. begin
  6117. for i:=0 to NameMappings.Count-1 do
  6118. begin
  6119. mappedname:=pshortstring(NameMappings[i]);
  6120. stringdispose(mappedname);
  6121. end;
  6122. NameMappings.free;
  6123. NameMappings:=nil;
  6124. end;
  6125. if assigned(procdefs) then
  6126. begin
  6127. procdefs.free;
  6128. procdefs:=nil;
  6129. end;
  6130. inherited destroy;
  6131. end;
  6132. procedure TImplementedInterface.buildderef;
  6133. begin
  6134. intfdefderef.build(intfdef);
  6135. ImplementsGetterDeref.build(ImplementsGetter);
  6136. end;
  6137. procedure TImplementedInterface.deref;
  6138. begin
  6139. intfdef:=tobjectdef(intfdefderef.resolve);
  6140. ImplementsGetter:=tsym(ImplementsGetterDeref.resolve);
  6141. end;
  6142. procedure TImplementedInterface.AddMapping(const origname,newname: string);
  6143. begin
  6144. if not assigned(NameMappings) then
  6145. NameMappings:=TFPHashList.Create;
  6146. NameMappings.Add(origname,stringdup(newname));
  6147. end;
  6148. function TImplementedInterface.GetMapping(const origname: string):string;
  6149. var
  6150. mappedname : pshortstring;
  6151. begin
  6152. result:='';
  6153. if not assigned(NameMappings) then
  6154. exit;
  6155. mappedname:=PShortstring(NameMappings.Find(origname));
  6156. if assigned(mappedname) then
  6157. result:=mappedname^;
  6158. end;
  6159. procedure TImplementedInterface.AddImplProc(pd:tprocdef);
  6160. begin
  6161. if not assigned(procdefs) then
  6162. procdefs:=TFPObjectList.Create(false);
  6163. { duplicate entries must be stored, because multiple }
  6164. { interfaces can declare methods with the same name }
  6165. { and all of these get their own VMT entry }
  6166. procdefs.Add(pd);
  6167. end;
  6168. function TImplementedInterface.IsImplMergePossible(MergingIntf:TImplementedInterface;out weight: longint): boolean;
  6169. var
  6170. i : longint;
  6171. begin
  6172. result:=false;
  6173. { interfaces being implemented through delegation are not mergable (FK) }
  6174. if (IType<>etStandard) or (MergingIntf.IType<>etStandard) or not(assigned(ProcDefs)) or not(assigned(MergingIntf.ProcDefs)) then
  6175. exit;
  6176. weight:=0;
  6177. { empty interface is mergeable }
  6178. if ProcDefs.Count=0 then
  6179. begin
  6180. result:=true;
  6181. exit;
  6182. end;
  6183. { The interface to merge must at least the number of
  6184. procedures of this interface }
  6185. if MergingIntf.ProcDefs.Count<ProcDefs.Count then
  6186. exit;
  6187. for i:=0 to ProcDefs.Count-1 do
  6188. begin
  6189. if MergingIntf.ProcDefs[i]<>ProcDefs[i] then
  6190. exit;
  6191. end;
  6192. weight:=ProcDefs.Count;
  6193. result:=true;
  6194. end;
  6195. function TImplementedInterface.getcopy:TImplementedInterface;
  6196. begin
  6197. Result:=TImplementedInterface.Create(nil);
  6198. { 1) the procdefs list will be freed once for each copy
  6199. 2) since the procdefs list owns its elements, those will also be freed for each copy
  6200. 3) idem for the name mappings
  6201. }
  6202. { warning: this is completely wrong on so many levels...
  6203. Move(pointer(self)^,pointer(result)^,InstanceSize);
  6204. We need to make clean copies of the different fields
  6205. this is not implemented yet, and thus we generate an internal
  6206. error instead PM 2011-06-14 }
  6207. internalerror(2011061401);
  6208. end;
  6209. {****************************************************************************
  6210. TFORWARDDEF
  6211. ****************************************************************************}
  6212. constructor tforwarddef.create(const s:string;const pos:tfileposinfo);
  6213. begin
  6214. inherited create(forwarddef);
  6215. tosymname:=stringdup(s);
  6216. forwardpos:=pos;
  6217. end;
  6218. function tforwarddef.GetTypeName:string;
  6219. begin
  6220. GetTypeName:='unresolved forward to '+tosymname^;
  6221. end;
  6222. destructor tforwarddef.destroy;
  6223. begin
  6224. stringdispose(tosymname);
  6225. inherited destroy;
  6226. end;
  6227. function tforwarddef.getcopy:tstoreddef;
  6228. begin
  6229. result:=tforwarddef.create(tosymname^, forwardpos);
  6230. end;
  6231. {****************************************************************************
  6232. TUNDEFINEDDEF
  6233. ****************************************************************************}
  6234. constructor tundefineddef.create;
  6235. begin
  6236. inherited create(undefineddef);
  6237. end;
  6238. constructor tundefineddef.ppuload(ppufile:tcompilerppufile);
  6239. begin
  6240. inherited ppuload(undefineddef,ppufile);
  6241. end;
  6242. function tundefineddef.GetTypeName:string;
  6243. begin
  6244. GetTypeName:='<undefined type>';
  6245. end;
  6246. procedure tundefineddef.ppuwrite(ppufile:tcompilerppufile);
  6247. begin
  6248. inherited ppuwrite(ppufile);
  6249. ppufile.writeentry(ibundefineddef);
  6250. end;
  6251. {****************************************************************************
  6252. TERRORDEF
  6253. ****************************************************************************}
  6254. constructor terrordef.create;
  6255. begin
  6256. inherited create(errordef);
  6257. { prevent consecutive faults }
  6258. savesize:=1;
  6259. end;
  6260. procedure terrordef.ppuwrite(ppufile:tcompilerppufile);
  6261. begin
  6262. { Can't write errordefs to ppu }
  6263. internalerror(200411063);
  6264. end;
  6265. function terrordef.GetTypeName:string;
  6266. begin
  6267. GetTypeName:='<erroneous type>';
  6268. end;
  6269. function terrordef.getmangledparaname:TSymStr;
  6270. begin
  6271. getmangledparaname:='error';
  6272. end;
  6273. {****************************************************************************
  6274. Definition Helpers
  6275. ****************************************************************************}
  6276. function is_interfacecom(def: tdef): boolean;
  6277. begin
  6278. is_interfacecom:=
  6279. assigned(def) and
  6280. (def.typ=objectdef) and
  6281. (tobjectdef(def).objecttype=odt_interfacecom);
  6282. end;
  6283. function is_interfacecom_or_dispinterface(def: tdef): boolean;
  6284. begin
  6285. is_interfacecom_or_dispinterface:=
  6286. assigned(def) and
  6287. (def.typ=objectdef) and
  6288. (tobjectdef(def).objecttype in [odt_interfacecom,odt_dispinterface]);
  6289. end;
  6290. function is_any_interface_kind(def: tdef): boolean;
  6291. begin
  6292. result:=
  6293. assigned(def) and
  6294. (def.typ=objectdef) and
  6295. ((tobjectdef(def).objecttype in [odt_interfacecom,odt_dispinterface,odt_interfacecorba,odt_interfacejava,odt_objcprotocol]) or
  6296. is_objccategory(def));
  6297. end;
  6298. function is_interfacecorba(def: tdef): boolean;
  6299. begin
  6300. is_interfacecorba:=
  6301. assigned(def) and
  6302. (def.typ=objectdef) and
  6303. (tobjectdef(def).objecttype=odt_interfacecorba);
  6304. end;
  6305. function is_interface(def: tdef): boolean;
  6306. begin
  6307. is_interface:=
  6308. assigned(def) and
  6309. (def.typ=objectdef) and
  6310. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  6311. end;
  6312. function is_dispinterface(def: tdef): boolean;
  6313. begin
  6314. result:=
  6315. assigned(def) and
  6316. (def.typ=objectdef) and
  6317. (tobjectdef(def).objecttype=odt_dispinterface);
  6318. end;
  6319. function is_class(def: tdef): boolean;
  6320. begin
  6321. is_class:=
  6322. assigned(def) and
  6323. (def.typ=objectdef) and
  6324. (tobjectdef(def).objecttype=odt_class);
  6325. end;
  6326. function is_object(def: tdef): boolean;
  6327. begin
  6328. is_object:=
  6329. assigned(def) and
  6330. (def.typ=objectdef) and
  6331. (tobjectdef(def).objecttype=odt_object);
  6332. end;
  6333. function is_cppclass(def: tdef): boolean;
  6334. begin
  6335. is_cppclass:=
  6336. assigned(def) and
  6337. (def.typ=objectdef) and
  6338. (tobjectdef(def).objecttype=odt_cppclass);
  6339. end;
  6340. function is_objcclass(def: tdef): boolean;
  6341. begin
  6342. is_objcclass:=
  6343. assigned(def) and
  6344. (def.typ=objectdef) and
  6345. (tobjectdef(def).objecttype=odt_objcclass);
  6346. end;
  6347. function is_objectpascal_helper(def: tdef): boolean;
  6348. begin
  6349. result:=
  6350. assigned(def) and
  6351. (def.typ=objectdef) and
  6352. (tobjectdef(def).objecttype=odt_helper);
  6353. end;
  6354. function is_objcclassref(def: tdef): boolean;
  6355. begin
  6356. is_objcclassref:=
  6357. assigned(def) and
  6358. (def.typ=classrefdef) and
  6359. is_objcclass(tclassrefdef(def).pointeddef);
  6360. end;
  6361. function is_objcprotocol(def: tdef): boolean;
  6362. begin
  6363. result:=
  6364. assigned(def) and
  6365. (def.typ=objectdef) and
  6366. (tobjectdef(def).objecttype=odt_objcprotocol);
  6367. end;
  6368. function is_objccategory(def: tdef): boolean;
  6369. begin
  6370. result:=
  6371. assigned(def) and
  6372. (def.typ=objectdef) and
  6373. { if used as a forward type }
  6374. ((tobjectdef(def).objecttype=odt_objccategory) or
  6375. { if used as after it has been resolved }
  6376. ((tobjectdef(def).objecttype=odt_objcclass) and
  6377. (oo_is_classhelper in tobjectdef(def).objectoptions)));
  6378. end;
  6379. function is_objc_class_or_protocol(def: tdef): boolean;
  6380. begin
  6381. result:=
  6382. assigned(def) and
  6383. (def.typ=objectdef) and
  6384. (tobjectdef(def).objecttype in [odt_objcclass,odt_objcprotocol]);
  6385. end;
  6386. function is_objc_protocol_or_category(def: tdef): boolean;
  6387. begin
  6388. result:=
  6389. assigned(def) and
  6390. (def.typ=objectdef) and
  6391. ((tobjectdef(def).objecttype = odt_objcprotocol) or
  6392. ((tobjectdef(def).objecttype = odt_objcclass) and
  6393. (oo_is_classhelper in tobjectdef(def).objectoptions)));
  6394. end;
  6395. function is_classhelper(def: tdef): boolean;
  6396. begin
  6397. result:=
  6398. is_objectpascal_helper(def) or
  6399. is_objccategory(def);
  6400. end;
  6401. function is_class_or_interface(def: tdef): boolean;
  6402. begin
  6403. result:=
  6404. assigned(def) and
  6405. (def.typ=objectdef) and
  6406. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  6407. end;
  6408. function is_class_or_interface_or_objc(def: tdef): boolean;
  6409. begin
  6410. result:=
  6411. assigned(def) and
  6412. (def.typ=objectdef) and
  6413. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_objcclass,odt_objcprotocol]);
  6414. end;
  6415. function is_class_or_interface_or_objc_or_java(def: tdef): boolean;
  6416. begin
  6417. result:=
  6418. assigned(def) and
  6419. (def.typ=objectdef) and
  6420. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava]);
  6421. end;
  6422. function is_class_or_interface_or_dispinterface_or_objc_or_java(def: tdef): boolean;
  6423. begin
  6424. result:=
  6425. assigned(def) and
  6426. (def.typ=objectdef) and
  6427. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava]);
  6428. end;
  6429. function is_class_or_interface_or_object(def: tdef): boolean;
  6430. begin
  6431. result:=
  6432. assigned(def) and
  6433. (def.typ=objectdef) and
  6434. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_object]);
  6435. end;
  6436. function is_class_or_interface_or_dispinterface(def: tdef): boolean;
  6437. begin
  6438. result:=
  6439. assigned(def) and
  6440. (def.typ=objectdef) and
  6441. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface]);
  6442. end;
  6443. function is_implicit_pointer_object_type(def: tdef): boolean;
  6444. begin
  6445. result:=
  6446. assigned(def) and
  6447. (((def.typ=objectdef) and
  6448. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava])) or
  6449. ((target_info.system in systems_jvm) and
  6450. (def.typ=recorddef)));
  6451. end;
  6452. function is_implicit_array_pointer(def: tdef): boolean;
  6453. begin
  6454. result:=is_dynamic_array(def) or is_dynamicstring(def);
  6455. end;
  6456. function is_class_or_object(def: tdef): boolean;
  6457. begin
  6458. result:=
  6459. assigned(def) and
  6460. (def.typ=objectdef) and
  6461. (tobjectdef(def).objecttype in [odt_class,odt_object]);
  6462. end;
  6463. function is_record(def: tdef): boolean;
  6464. begin
  6465. result:=
  6466. assigned(def) and
  6467. (def.typ=recorddef);
  6468. end;
  6469. function is_javaclass(def: tdef): boolean;
  6470. begin
  6471. result:=
  6472. assigned(def) and
  6473. (def.typ=objectdef) and
  6474. (tobjectdef(def).objecttype=odt_javaclass);
  6475. end;
  6476. function is_javaclassref(def: tdef): boolean;
  6477. begin
  6478. is_javaclassref:=
  6479. assigned(def) and
  6480. (def.typ=classrefdef) and
  6481. is_javaclass(tclassrefdef(def).pointeddef);
  6482. end;
  6483. function is_javainterface(def: tdef): boolean;
  6484. begin
  6485. result:=
  6486. assigned(def) and
  6487. (def.typ=objectdef) and
  6488. (tobjectdef(def).objecttype=odt_interfacejava);
  6489. end;
  6490. function is_java_class_or_interface(def: tdef): boolean;
  6491. begin
  6492. result:=
  6493. assigned(def) and
  6494. (def.typ=objectdef) and
  6495. (tobjectdef(def).objecttype in [odt_javaclass,odt_interfacejava]);
  6496. end;
  6497. procedure loadobjctypes;
  6498. begin
  6499. objc_metaclasstype:=tpointerdef(search_named_unit_globaltype('OBJC','POBJC_CLASS',true).typedef);
  6500. objc_superclasstype:=tpointerdef(search_named_unit_globaltype('OBJC','POBJC_SUPER',true).typedef);
  6501. objc_idtype:=tpointerdef(search_named_unit_globaltype('OBJC','ID',true).typedef);
  6502. objc_seltype:=tpointerdef(search_named_unit_globaltype('OBJC','SEL',true).typedef);
  6503. objc_objecttype:=trecorddef(search_named_unit_globaltype('OBJC','OBJC_OBJECT',true).typedef);
  6504. end;
  6505. procedure maybeloadcocoatypes;
  6506. var
  6507. tsym: ttypesym;
  6508. cocoaunit: string[15];
  6509. begin
  6510. if assigned(objc_fastenumeration) then
  6511. exit;
  6512. if not(target_info.system in [system_arm_darwin,system_i386_iphonesim]) then
  6513. cocoaunit:='COCOAALL'
  6514. else
  6515. cocoaunit:='IPHONEALL';
  6516. tsym:=search_named_unit_globaltype(cocoaunit,'NSFASTENUMERATIONPROTOCOL',false);
  6517. if assigned(tsym) then
  6518. objc_fastenumeration:=tobjectdef(tsym.typedef)
  6519. else
  6520. objc_fastenumeration:=nil;
  6521. tsym:=search_named_unit_globaltype(cocoaunit,'NSFASTENUMERATIONSTATE',false);
  6522. if assigned(tsym) then
  6523. objc_fastenumerationstate:=trecorddef(tsym.typedef)
  6524. else
  6525. objc_fastenumerationstate:=nil;
  6526. end;
  6527. function use_vectorfpu(def : tdef) : boolean;
  6528. begin
  6529. {$ifdef x86}
  6530. {$define use_vectorfpuimplemented}
  6531. use_vectorfpu:=(is_single(def) and (current_settings.fputype in sse_singlescalar)) or
  6532. (is_double(def) and (current_settings.fputype in sse_doublescalar));
  6533. {$endif x86}
  6534. {$ifdef arm}
  6535. {$define use_vectorfpuimplemented}
  6536. use_vectorfpu:=(current_settings.fputype in vfp_scalar);
  6537. {$endif arm}
  6538. {$ifndef use_vectorfpuimplemented}
  6539. use_vectorfpu:=false;
  6540. {$endif}
  6541. end;
  6542. function getpointerdef(def: tdef): tpointerdef;
  6543. var
  6544. res: PHashSetItem;
  6545. oldsymtablestack: tsymtablestack;
  6546. begin
  6547. if not assigned(current_module) then
  6548. internalerror(2011071101);
  6549. res:=current_module.ptrdefs.FindOrAdd(@def,sizeof(def));
  6550. if not assigned(res^.Data) then
  6551. begin
  6552. { since these pointerdefs can be reused anywhere in the current
  6553. unit, add them to the global/staticsymtable }
  6554. oldsymtablestack:=symtablestack;
  6555. { do not simply push/pop current_module.localsymtable, because
  6556. that can have side-effects (e.g., it removes helpers) }
  6557. symtablestack:=nil;
  6558. res^.Data:=tpointerdef.create(def);
  6559. if assigned(current_module.localsymtable) then
  6560. current_module.localsymtable.insertdef(tdef(res^.Data))
  6561. else
  6562. current_module.globalsymtable.insertdef(tdef(res^.Data));
  6563. symtablestack:=oldsymtablestack;
  6564. end;
  6565. result:=tpointerdef(res^.Data);
  6566. end;
  6567. function getsingletonarraydef(def: tdef): tarraydef;
  6568. begin
  6569. result:=getarraydef(def,1);
  6570. end;
  6571. function getarraydef(def: tdef; elecount: asizeint): tarraydef;
  6572. var
  6573. res: PHashSetItem;
  6574. oldsymtablestack: tsymtablestack;
  6575. arrdesc: packed record
  6576. def: tdef;
  6577. elecount: asizeint;
  6578. end;
  6579. begin
  6580. if not assigned(current_module) then
  6581. internalerror(2011081301);
  6582. arrdesc.def:=def;
  6583. arrdesc.elecount:=elecount;
  6584. res:=current_module.arraydefs.FindOrAdd(@arrdesc,sizeof(arrdesc));
  6585. if not assigned(res^.Data) then
  6586. begin
  6587. { since these arraydef can be reused anywhere in the current
  6588. unit, add them to the global/staticsymtable }
  6589. oldsymtablestack:=symtablestack;
  6590. symtablestack:=nil;
  6591. res^.Data:=tarraydef.create(0,elecount-1,ptrsinttype);
  6592. tarraydef(res^.Data).elementdef:=def;
  6593. if assigned(current_module.localsymtable) then
  6594. current_module.localsymtable.insertdef(tdef(res^.Data))
  6595. else
  6596. current_module.globalsymtable.insertdef(tdef(res^.Data));
  6597. symtablestack:=oldsymtablestack;
  6598. end;
  6599. result:=tarraydef(res^.Data);
  6600. end;
  6601. {$ifdef x86}
  6602. function default_x86_data_pointer_type: tx86pointertyp;
  6603. begin
  6604. {$ifdef i8086}
  6605. if current_settings.x86memorymodel in x86_far_data_models then
  6606. result:=x86pt_far
  6607. else
  6608. {$endif i8086}
  6609. result:=x86pt_near;
  6610. end;
  6611. {$endif x86}
  6612. end.