symdef.pas 296 KB

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