symdef.pas 241 KB

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