symdef.pas 253 KB

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