symdef.pas 319 KB

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