symdef.pas 233 KB

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