symdef.pas 278 KB

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