symdef.pas 275 KB

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