symdef.pas 241 KB

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