symdef.pas 250 KB

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