symdef.pas 298 KB

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