symdef.pas 210 KB

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