symdef.pas 298 KB

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