symdef.pas 279 KB

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