symdef.pas 227 KB

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