2
0

symdef.pas 292 KB

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