symdef.pas 278 KB

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