symdef.pas 206 KB

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