symdef.pas 277 KB

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