symdef.pas 241 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442
  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. proctypeoption:=tproctypeoption(ppufile.getbyte);
  3738. proccalloption:=tproccalloption(ppufile.getbyte);
  3739. ppufile.getnormalset(procoptions);
  3740. funcretloc[callerside].init;
  3741. if po_explicitparaloc in procoptions then
  3742. funcretloc[callerside].ppuload(ppufile);
  3743. savesize:=sizeof(pint);
  3744. if (po_explicitparaloc in procoptions) then
  3745. has_paraloc_info:=callerside;
  3746. end;
  3747. procedure tabstractprocdef.ppuwrite(ppufile:tcompilerppufile);
  3748. var
  3749. oldintfcrc : boolean;
  3750. begin
  3751. { released procdef? }
  3752. if not assigned(parast) then
  3753. exit;
  3754. inherited ppuwrite(ppufile);
  3755. ppufile.putderef(returndefderef);
  3756. oldintfcrc:=ppufile.do_interface_crc;
  3757. ppufile.do_interface_crc:=false;
  3758. ppufile.putbyte(ord(proctypeoption));
  3759. ppufile.putbyte(ord(proccalloption));
  3760. ppufile.putnormalset(procoptions);
  3761. ppufile.do_interface_crc:=oldintfcrc;
  3762. if (po_explicitparaloc in procoptions) then
  3763. funcretloc[callerside].ppuwrite(ppufile);
  3764. end;
  3765. function tabstractprocdef.typename_paras(pno: tprocnameoptions) : ansistring;
  3766. var
  3767. hs,s : ansistring;
  3768. hp : TParavarsym;
  3769. hpc : tconstsym;
  3770. first : boolean;
  3771. i : integer;
  3772. begin
  3773. s:='';
  3774. first:=true;
  3775. for i:=0 to paras.count-1 do
  3776. begin
  3777. hp:=tparavarsym(paras[i]);
  3778. if not(vo_is_hidden_para in hp.varoptions) or
  3779. (pno_showhidden in pno) then
  3780. begin
  3781. if first then
  3782. begin
  3783. s:=s+'(';
  3784. first:=false;
  3785. end
  3786. else
  3787. s:=s+';';
  3788. if vo_is_hidden_para in hp.varoptions then
  3789. s:=s+'<';
  3790. case hp.varspez of
  3791. vs_var :
  3792. s:=s+'var ';
  3793. vs_const :
  3794. s:=s+'const ';
  3795. vs_out :
  3796. s:=s+'out ';
  3797. vs_constref :
  3798. s:=s+'constref ';
  3799. end;
  3800. if (pno_paranames in pno) then
  3801. s:=s+hp.realname+':';
  3802. if hp.univpara then
  3803. s:=s+'univ ';
  3804. if assigned(hp.vardef.typesym) then
  3805. begin
  3806. hs:=hp.vardef.typesym.realname;
  3807. if hs[1]<>'$' then
  3808. s:=s+hp.vardef.OwnerHierarchyName+hs
  3809. else
  3810. s:=s+hp.vardef.GetTypeName;
  3811. end
  3812. else
  3813. s:=s+hp.vardef.GetTypeName;
  3814. { default value }
  3815. if assigned(hp.defaultconstsym) then
  3816. begin
  3817. hpc:=tconstsym(hp.defaultconstsym);
  3818. hs:='';
  3819. case hpc.consttyp of
  3820. conststring,
  3821. constresourcestring :
  3822. begin
  3823. If hpc.value.len>0 then
  3824. begin
  3825. setLength(hs,hpc.value.len);
  3826. { don't write past the end of hs if the constant
  3827. is > 255 chars }
  3828. move(hpc.value.valueptr^,hs[1],length(hs));
  3829. { make sure that constant strings with newline chars
  3830. don't create a linebreak in the assembler code,
  3831. since comments are line-based. Also remove nulls
  3832. because the comments are written as a pchar. }
  3833. ReplaceCase(hs,#0,'.');
  3834. ReplaceCase(hs,#10,'.');
  3835. ReplaceCase(hs,#13,'.');
  3836. end;
  3837. end;
  3838. constreal :
  3839. str(pbestreal(hpc.value.valueptr)^,hs);
  3840. constpointer :
  3841. hs:=tostr(hpc.value.valueordptr);
  3842. constord :
  3843. begin
  3844. if is_boolean(hpc.constdef) then
  3845. begin
  3846. if hpc.value.valueord<>0 then
  3847. hs:='TRUE'
  3848. else
  3849. hs:='FALSE';
  3850. end
  3851. else
  3852. hs:=tostr(hpc.value.valueord);
  3853. end;
  3854. constnil :
  3855. hs:='nil';
  3856. constset :
  3857. hs:='<set>';
  3858. end;
  3859. if hs<>'' then
  3860. s:=s+'="'+hs+'"';
  3861. end;
  3862. if vo_is_hidden_para in hp.varoptions then
  3863. s:=s+'>';
  3864. end;
  3865. end;
  3866. if not first then
  3867. s:=s+')';
  3868. if (po_varargs in procoptions) then
  3869. s:=s+';VarArgs';
  3870. typename_paras:=s;
  3871. end;
  3872. function tabstractprocdef.is_methodpointer:boolean;
  3873. begin
  3874. result:=false;
  3875. end;
  3876. function tabstractprocdef.is_addressonly:boolean;
  3877. begin
  3878. result:=true;
  3879. end;
  3880. function tabstractprocdef.no_self_node: boolean;
  3881. begin
  3882. Result:=([po_staticmethod,po_classmethod]<=procoptions)or
  3883. (proctypeoption in [potype_class_constructor,potype_class_destructor,potype_operator]);
  3884. end;
  3885. function tabstractprocdef.getcopyas(newtyp:tdeftyp;copytyp:tproccopytyp): tstoreddef;
  3886. var
  3887. j, nestinglevel: longint;
  3888. pvs, npvs: tparavarsym;
  3889. begin
  3890. nestinglevel:=parast.symtablelevel;
  3891. if newtyp=procdef then
  3892. begin
  3893. if (copytyp<>pc_bareproc) then
  3894. result:=cprocdef.create(nestinglevel)
  3895. else
  3896. result:=cprocdef.create(normal_function_level);
  3897. tprocdef(result).visibility:=vis_public;
  3898. end
  3899. else
  3900. begin
  3901. result:=cprocvardef.create(nestinglevel);
  3902. end;
  3903. tabstractprocdef(result).returndef:=returndef;
  3904. tabstractprocdef(result).returndefderef:=returndefderef;
  3905. pvs:=nil;
  3906. npvs:=nil;
  3907. for j:=0 to parast.symlist.count-1 do
  3908. begin
  3909. case tsym(parast.symlist[j]).typ of
  3910. paravarsym:
  3911. begin
  3912. pvs:=tparavarsym(parast.symlist[j]);
  3913. { in case of bare proc, don't copy self, vmt or framepointer
  3914. parameters }
  3915. if (copytyp=pc_bareproc) and
  3916. (([vo_is_self,vo_is_vmt,vo_is_parentfp,vo_is_result]*pvs.varoptions)<>[]) then
  3917. continue;
  3918. npvs:=cparavarsym.create(pvs.realname,pvs.paranr,pvs.varspez,
  3919. pvs.vardef,pvs.varoptions);
  3920. npvs.defaultconstsym:=pvs.defaultconstsym;
  3921. tabstractprocdef(result).parast.insert(npvs);
  3922. end;
  3923. constsym:
  3924. begin
  3925. // ignore, reuse original constym. Should also be duplicated
  3926. // be safe though
  3927. end;
  3928. symconst.typesym:
  3929. begin
  3930. // reuse original, part of generic declaration
  3931. end
  3932. else
  3933. internalerror(201160604);
  3934. end;
  3935. end;
  3936. tabstractprocdef(result).savesize:=savesize;
  3937. tabstractprocdef(result).proctypeoption:=proctypeoption;
  3938. tabstractprocdef(result).proccalloption:=proccalloption;
  3939. tabstractprocdef(result).procoptions:=procoptions;
  3940. if (copytyp=pc_bareproc) then
  3941. tabstractprocdef(result).procoptions:=tabstractprocdef(result).procoptions*[po_explicitparaloc,po_hascallingconvention,po_varargs,po_iocheck,po_has_importname,po_has_importdll];
  3942. if newtyp=procvardef then
  3943. tabstractprocdef(result).procoptions:=tabstractprocdef(result).procoptions-[po_has_importname,po_has_importdll];
  3944. tabstractprocdef(result).callerargareasize:=callerargareasize;
  3945. tabstractprocdef(result).calleeargareasize:=calleeargareasize;
  3946. tabstractprocdef(result).maxparacount:=maxparacount;
  3947. tabstractprocdef(result).minparacount:=minparacount;
  3948. if po_explicitparaloc in procoptions then
  3949. tabstractprocdef(result).funcretloc[callerside]:=funcretloc[callerside].getcopy;
  3950. { recalculate parameter info }
  3951. tabstractprocdef(result).has_paraloc_info:=callnoside;
  3952. {$ifdef m68k}
  3953. tabstractprocdef(result).exp_funcretloc:=exp_funcretloc;
  3954. {$endif}
  3955. if (typ=procdef) and
  3956. (newtyp=procvardef) and
  3957. (owner.symtabletype=ObjectSymtable) then
  3958. include(tprocvardef(result).procoptions,po_methodpointer);
  3959. end;
  3960. procedure tabstractprocdef.check_mark_as_nested;
  3961. begin
  3962. { nested procvars require that nested functions use the Delphi-style
  3963. nested procedure calling convention }
  3964. if (parast.symtablelevel>normal_function_level) and
  3965. (m_nested_procvars in current_settings.modeswitches) then
  3966. include(procoptions,po_delphi_nested_cc);
  3967. end;
  3968. procedure tabstractprocdef.init_paraloc_info(side: tcallercallee);
  3969. begin
  3970. if (side in [callerside,callbothsides]) and
  3971. not(has_paraloc_info in [callerside,callbothsides]) then
  3972. begin
  3973. callerargareasize:=paramanager.create_paraloc_info(self,callerside);
  3974. if has_paraloc_info in [calleeside,callbothsides] then
  3975. has_paraloc_info:=callbothsides
  3976. else
  3977. has_paraloc_info:=callerside;
  3978. end;
  3979. if (side in [calleeside,callbothsides]) and
  3980. not(has_paraloc_info in [calleeside,callbothsides]) then
  3981. begin
  3982. calleeargareasize:=paramanager.create_paraloc_info(self,calleeside);
  3983. if has_paraloc_info in [callerside,callbothsides] then
  3984. has_paraloc_info:=callbothsides
  3985. else
  3986. has_paraloc_info:=calleeside;
  3987. end;
  3988. end;
  3989. function tabstractprocdef.stack_tainting_parameter(side: tcallercallee): boolean;
  3990. var
  3991. p: tparavarsym;
  3992. ploc: PCGParalocation;
  3993. i: longint;
  3994. begin
  3995. result:=false;
  3996. init_paraloc_info(side);
  3997. for i:=0 to parast.SymList.Count-1 do
  3998. if tsym(parast.SymList[i]).typ=paravarsym then
  3999. begin
  4000. p:=tparavarsym(parast.SymList[i]);
  4001. { check if no parameter is located on the stack }
  4002. if is_open_array(p.vardef) or
  4003. is_array_of_const(p.vardef) then
  4004. begin
  4005. result:=true;
  4006. exit;
  4007. end;
  4008. ploc:=p.paraloc[side].location;
  4009. while assigned(ploc) do
  4010. begin
  4011. if (ploc^.loc=LOC_REFERENCE) then
  4012. begin
  4013. result:=true;
  4014. exit
  4015. end;
  4016. ploc:=ploc^.next;
  4017. end;
  4018. end;
  4019. end;
  4020. function tabstractprocdef.is_pushleftright: boolean;
  4021. begin
  4022. {$if defined(i8086) or defined(i386)}
  4023. result:=proccalloption in pushleftright_pocalls;
  4024. {$else}
  4025. result:=false;
  4026. {$endif}
  4027. end;
  4028. function tabstractprocdef.address_type: tdef;
  4029. begin
  4030. {$ifdef i8086}
  4031. if po_far in procoptions then
  4032. result:=voidfarpointertype
  4033. else
  4034. result:=voidnearpointertype;
  4035. {$else i8086}
  4036. result:=voidpointertype;
  4037. {$endif i8086}
  4038. end;
  4039. {***************************************************************************
  4040. TPROCDEF
  4041. ***************************************************************************}
  4042. function tprocdef.GetResultName: PShortString;
  4043. begin
  4044. if not assigned(implprocdefinfo) then
  4045. internalerror(2014010301);
  4046. result:=implprocdefinfo^.resultname;
  4047. end;
  4048. procedure tprocdef.SetResultName(AValue: PShortString);
  4049. begin
  4050. if not assigned(implprocdefinfo) then
  4051. internalerror(2014010302);
  4052. implprocdefinfo^.resultname:=AValue;
  4053. end;
  4054. function tprocdef.GetParentFPInitBlock: tnode;
  4055. begin
  4056. if not assigned(implprocdefinfo) then
  4057. internalerror(2014010303);
  4058. result:=implprocdefinfo^.parentfpinitblock;
  4059. end;
  4060. function tprocdef.GetParentFPStruct: tsym;
  4061. begin
  4062. if not assigned(implprocdefinfo) then
  4063. internalerror(2014010304);
  4064. result:=implprocdefinfo^.parentfpstruct;
  4065. end;
  4066. function tprocdef.GetParentFPStructPtrType: tdef;
  4067. begin
  4068. if not assigned(implprocdefinfo) then
  4069. internalerror(2014010305);
  4070. result:=implprocdefinfo^.parentfpstructptrtype;
  4071. end;
  4072. procedure tprocdef.SetParentFPInitBlock(AValue: tnode);
  4073. begin
  4074. if not assigned(implprocdefinfo) then
  4075. internalerror(2014010306);
  4076. implprocdefinfo^.parentfpinitblock:=AValue;
  4077. end;
  4078. function tprocdef.Getprocendtai: tai;
  4079. begin
  4080. if not assigned(implprocdefinfo) then
  4081. internalerror(2014010307);
  4082. result:=implprocdefinfo^.procendtai;
  4083. end;
  4084. function tprocdef.Getprocstarttai: tai;
  4085. begin
  4086. if not assigned(implprocdefinfo) then
  4087. internalerror(2014010308);
  4088. result:=implprocdefinfo^.procstarttai;
  4089. end;
  4090. procedure tprocdef.Setprocendtai(AValue: tai);
  4091. begin
  4092. if not assigned(implprocdefinfo) then
  4093. internalerror(2014010309);
  4094. implprocdefinfo^.procendtai:=AValue;
  4095. end;
  4096. function tprocdef.Getskpara: pointer;
  4097. begin
  4098. if not assigned(implprocdefinfo) then
  4099. internalerror(2014010310);
  4100. result:=implprocdefinfo^.skpara;
  4101. end;
  4102. procedure tprocdef.Setskpara(AValue: pointer);
  4103. begin
  4104. if not assigned(implprocdefinfo) then
  4105. internalerror(2014010311);
  4106. implprocdefinfo^.skpara:=AValue;
  4107. end;
  4108. function tprocdef.Getforwarddef: boolean;
  4109. begin
  4110. if not assigned(implprocdefinfo) then
  4111. internalerror(2014010312);
  4112. result:=implprocdefinfo^.forwarddef;
  4113. end;
  4114. function tprocdef.Gethasforward: boolean;
  4115. begin
  4116. if not assigned(implprocdefinfo) then
  4117. internalerror(2014010313);
  4118. result:=implprocdefinfo^.hasforward;
  4119. end;
  4120. function tprocdef.Getinterfacedef: boolean;
  4121. begin
  4122. if not assigned(implprocdefinfo) then
  4123. internalerror(2014010314);
  4124. result:=implprocdefinfo^.interfacedef;
  4125. end;
  4126. procedure tprocdef.Setforwarddef(AValue: boolean);
  4127. begin
  4128. if not assigned(implprocdefinfo) then
  4129. internalerror(2014010315);
  4130. implprocdefinfo^.forwarddef:=AValue;
  4131. end;
  4132. procedure tprocdef.Sethasforward(AValue: boolean);
  4133. begin
  4134. if not assigned(implprocdefinfo) then
  4135. internalerror(2014010316);
  4136. implprocdefinfo^.hasforward:=AValue;
  4137. end;
  4138. function tprocdef.GetIsEmpty: boolean;
  4139. begin
  4140. result:=pio_empty in implprocoptions;
  4141. end;
  4142. procedure tprocdef.SetIsEmpty(AValue: boolean);
  4143. begin
  4144. if AValue then
  4145. include(implprocoptions,pio_empty)
  4146. else
  4147. include(implprocoptions,pio_empty);
  4148. end;
  4149. function tprocdef.GetHasInliningInfo: boolean;
  4150. begin
  4151. result:=pio_has_inlininginfo in implprocoptions;
  4152. end;
  4153. procedure tprocdef.SetHasInliningInfo(AValue: boolean);
  4154. begin
  4155. if AValue then
  4156. include(implprocoptions,pio_has_inlininginfo)
  4157. else
  4158. exclude(implprocoptions,pio_has_inlininginfo);
  4159. end;
  4160. procedure tprocdef.Setinterfacedef(AValue: boolean);
  4161. begin
  4162. if not assigned(implprocdefinfo) then
  4163. internalerror(2014010317);
  4164. implprocdefinfo^.interfacedef:=AValue;
  4165. end;
  4166. procedure tprocdef.Setprocstarttai(AValue: tai);
  4167. begin
  4168. if not assigned(implprocdefinfo) then
  4169. internalerror(2014010318);
  4170. implprocdefinfo^.procstarttai:=AValue;
  4171. end;
  4172. procedure tprocdef.SetParentFPStruct(AValue: tsym);
  4173. begin
  4174. if not assigned(implprocdefinfo) then
  4175. internalerror(2014010319);
  4176. implprocdefinfo^.parentfpstruct:=AValue;
  4177. end;
  4178. procedure tprocdef.SetParentFPStructPtrType(AValue: tdef);
  4179. begin
  4180. if not assigned(implprocdefinfo) then
  4181. internalerror(2014010320);
  4182. implprocdefinfo^.parentfpstructptrtype:=AValue;
  4183. end;
  4184. constructor tprocdef.create(level:byte);
  4185. begin
  4186. inherited create(procdef,level);
  4187. implprocdefinfo:=allocmem(sizeof(implprocdefinfo^));
  4188. localst:=tlocalsymtable.create(self,parast.symtablelevel);
  4189. {$ifdef symansistr}
  4190. _mangledname:='';
  4191. {$else symansistr}
  4192. _mangledname:=nil;
  4193. {$endif symansistr}
  4194. fileinfo:=current_filepos;
  4195. extnumber:=$ffff;
  4196. aliasnames:=TCmdStrList.create;
  4197. funcretsym:=nil;
  4198. forwarddef:=true;
  4199. interfacedef:=false;
  4200. hasforward:=false;
  4201. struct := nil;
  4202. import_dll:=nil;
  4203. import_name:=nil;
  4204. import_nr:=0;
  4205. inlininginfo:=nil;
  4206. deprecatedmsg:=nil;
  4207. {$if defined(i386) or defined(i8086)}
  4208. fpu_used:=maxfpuregs;
  4209. {$endif i386 or i8086}
  4210. end;
  4211. constructor tprocdef.ppuload(ppufile:tcompilerppufile);
  4212. var
  4213. i,aliasnamescount : longint;
  4214. level : byte;
  4215. begin
  4216. inherited ppuload(procdef,ppufile);
  4217. {$ifdef symansistr}
  4218. if po_has_mangledname in procoptions then
  4219. _mangledname:=ppufile.getansistring
  4220. else
  4221. _mangledname:='';
  4222. {$else symansistr}
  4223. if po_has_mangledname in procoptions then
  4224. _mangledname:=stringdup(ppufile.getstring)
  4225. else
  4226. _mangledname:=nil;
  4227. {$endif symansistr}
  4228. extnumber:=ppufile.getword;
  4229. level:=ppufile.getbyte;
  4230. ppufile.getderef(structderef);
  4231. ppufile.getderef(procsymderef);
  4232. ppufile.getposinfo(fileinfo);
  4233. visibility:=tvisibility(ppufile.getbyte);
  4234. ppufile.getsmallset(symoptions);
  4235. if sp_has_deprecated_msg in symoptions then
  4236. deprecatedmsg:=stringdup(ppufile.getstring)
  4237. else
  4238. deprecatedmsg:=nil;
  4239. synthetickind:=tsynthetickind(ppufile.getbyte);
  4240. {$if defined(powerpc) or defined(m68k)}
  4241. { library symbol for AmigaOS/MorphOS }
  4242. ppufile.getderef(libsymderef);
  4243. {$endif powerpc or m68k}
  4244. { import stuff }
  4245. if po_has_importdll in procoptions then
  4246. import_dll:=stringdup(ppufile.getstring)
  4247. else
  4248. import_dll:=nil;
  4249. if po_has_importname in procoptions then
  4250. import_name:=stringdup(ppufile.getstring)
  4251. else
  4252. import_name:=nil;
  4253. import_nr:=ppufile.getword;
  4254. if (po_msgint in procoptions) then
  4255. messageinf.i:=ppufile.getlongint;
  4256. if (po_msgstr in procoptions) then
  4257. messageinf.str:=stringdup(ppufile.getstring);
  4258. if (po_dispid in procoptions) then
  4259. dispid:=ppufile.getlongint;
  4260. { inline stuff }
  4261. ppufile.getsmallset(implprocoptions);
  4262. if has_inlininginfo then
  4263. begin
  4264. ppufile.getderef(funcretsymderef);
  4265. new(inlininginfo);
  4266. ppufile.getsmallset(inlininginfo^.flags);
  4267. end
  4268. else
  4269. begin
  4270. inlininginfo:=nil;
  4271. funcretsym:=nil;
  4272. end;
  4273. aliasnames:=TCmdStrList.create;
  4274. { count alias names }
  4275. aliasnamescount:=ppufile.getbyte;
  4276. for i:=1 to aliasnamescount do
  4277. aliasnames.insert(ppufile.getstring);
  4278. ppuload_platform(ppufile);
  4279. { load para symtable }
  4280. parast:=tparasymtable.create(self,level);
  4281. tparasymtable(parast).ppuload(ppufile);
  4282. { load local symtable }
  4283. if has_inlininginfo then
  4284. begin
  4285. localst:=tlocalsymtable.create(self,level);
  4286. tlocalsymtable(localst).ppuload(ppufile);
  4287. end
  4288. else
  4289. localst:=nil;
  4290. { inline stuff }
  4291. if has_inlininginfo then
  4292. inlininginfo^.code:=ppuloadnodetree(ppufile);
  4293. { default values for no persistent data }
  4294. if (cs_link_deffile in current_settings.globalswitches) and
  4295. (tf_need_export in target_info.flags) and
  4296. (po_exports in procoptions) then
  4297. deffile.AddExport(mangledname);
  4298. { Disable po_has_inlining until the derefimpl is done }
  4299. has_inlininginfo:=false;
  4300. {$ifdef i386}
  4301. fpu_used:=maxfpuregs;
  4302. {$endif i386}
  4303. end;
  4304. destructor tprocdef.destroy;
  4305. begin
  4306. aliasnames.free;
  4307. aliasnames:=nil;
  4308. if assigned(localst) and
  4309. (localst.symtabletype<>staticsymtable) then
  4310. begin
  4311. {$ifdef MEMDEBUG}
  4312. memproclocalst.start;
  4313. {$endif MEMDEBUG}
  4314. localst.free;
  4315. localst:=nil;
  4316. {$ifdef MEMDEBUG}
  4317. memproclocalst.start;
  4318. {$endif MEMDEBUG}
  4319. end;
  4320. if assigned(inlininginfo) then
  4321. begin
  4322. {$ifdef MEMDEBUG}
  4323. memprocnodetree.start;
  4324. {$endif MEMDEBUG}
  4325. tnode(inlininginfo^.code).free;
  4326. {$ifdef MEMDEBUG}
  4327. memprocnodetree.start;
  4328. {$endif MEMDEBUG}
  4329. dispose(inlininginfo);
  4330. inlininginfo:=nil;
  4331. end;
  4332. if assigned(implprocdefinfo) then
  4333. begin
  4334. stringdispose(implprocdefinfo^.resultname);
  4335. freemem(implprocdefinfo);
  4336. implprocdefinfo:=nil;
  4337. end;
  4338. stringdispose(import_dll);
  4339. stringdispose(import_name);
  4340. stringdispose(deprecatedmsg);
  4341. if (po_msgstr in procoptions) then
  4342. stringdispose(messageinf.str);
  4343. {$ifndef symansistr}
  4344. if assigned(_mangledname) then
  4345. begin
  4346. {$ifdef MEMDEBUG}
  4347. memmanglednames.start;
  4348. {$endif MEMDEBUG}
  4349. stringdispose(_mangledname);
  4350. {$ifdef MEMDEBUG}
  4351. memmanglednames.stop;
  4352. {$endif MEMDEBUG}
  4353. end;
  4354. {$endif symansistr}
  4355. inherited destroy;
  4356. end;
  4357. procedure tprocdef.ppuwrite(ppufile:tcompilerppufile);
  4358. var
  4359. oldintfcrc : boolean;
  4360. aliasnamescount : longint;
  4361. item : TCmdStrListItem;
  4362. begin
  4363. { released procdef? }
  4364. if not assigned(parast) then
  4365. exit;
  4366. inherited ppuwrite(ppufile);
  4367. {$ifdef symansistr}
  4368. if po_has_mangledname in procoptions then
  4369. ppufile.putansistring(_mangledname);
  4370. {$else symansistr}
  4371. if po_has_mangledname in procoptions then
  4372. ppufile.putstring(_mangledname^);
  4373. {$endif symansistr}
  4374. ppufile.putword(extnumber);
  4375. ppufile.putbyte(parast.symtablelevel);
  4376. ppufile.putderef(structderef);
  4377. ppufile.putderef(procsymderef);
  4378. ppufile.putposinfo(fileinfo);
  4379. ppufile.putbyte(byte(visibility));
  4380. ppufile.putsmallset(symoptions);
  4381. if sp_has_deprecated_msg in symoptions then
  4382. ppufile.putstring(deprecatedmsg^);
  4383. ppufile.putbyte(byte(synthetickind));
  4384. {$if defined(powerpc) or defined(m68k)}
  4385. { library symbol for AmigaOS/MorphOS }
  4386. ppufile.putderef(libsymderef);
  4387. {$endif powerpc or m68k}
  4388. { import }
  4389. if po_has_importdll in procoptions then
  4390. ppufile.putstring(import_dll^);
  4391. if po_has_importname in procoptions then
  4392. ppufile.putstring(import_name^);
  4393. ppufile.putword(import_nr);
  4394. if (po_msgint in procoptions) then
  4395. ppufile.putlongint(messageinf.i);
  4396. if (po_msgstr in procoptions) then
  4397. ppufile.putstring(messageinf.str^);
  4398. if (po_dispid in procoptions) then
  4399. ppufile.putlongint(dispid);
  4400. { inline stuff }
  4401. oldintfcrc:=ppufile.do_crc;
  4402. ppufile.do_crc:=false;
  4403. ppufile.putsmallset(implprocoptions);
  4404. if has_inlininginfo then
  4405. begin
  4406. ppufile.putderef(funcretsymderef);
  4407. ppufile.putsmallset(inlininginfo^.flags);
  4408. end;
  4409. { count alias names }
  4410. aliasnamescount:=0;
  4411. item:=TCmdStrListItem(aliasnames.first);
  4412. while assigned(item) do
  4413. begin
  4414. inc(aliasnamescount);
  4415. item:=TCmdStrListItem(item.next);
  4416. end;
  4417. if aliasnamescount>255 then
  4418. internalerror(200711021);
  4419. ppufile.putbyte(aliasnamescount);
  4420. item:=TCmdStrListItem(aliasnames.first);
  4421. while assigned(item) do
  4422. begin
  4423. ppufile.putstring(item.str);
  4424. item:=TCmdStrListItem(item.next);
  4425. end;
  4426. ppufile.do_crc:=oldintfcrc;
  4427. { write this entry }
  4428. writeentry(ppufile,ibprocdef);
  4429. { Save the para symtable, this is taken from the interface }
  4430. tparasymtable(parast).ppuwrite(ppufile);
  4431. { save localsymtable for inline procedures or when local
  4432. browser info is requested, this has no influence on the crc }
  4433. if has_inlininginfo then
  4434. begin
  4435. oldintfcrc:=ppufile.do_crc;
  4436. ppufile.do_crc:=false;
  4437. tlocalsymtable(localst).ppuwrite(ppufile);
  4438. ppufile.do_crc:=oldintfcrc;
  4439. end;
  4440. { node tree for inlining }
  4441. oldintfcrc:=ppufile.do_crc;
  4442. ppufile.do_crc:=false;
  4443. if has_inlininginfo then
  4444. ppuwritenodetree(ppufile,inlininginfo^.code);
  4445. ppufile.do_crc:=oldintfcrc;
  4446. end;
  4447. function tprocdef.fullprocname(showhidden:boolean):string;
  4448. var
  4449. pno: tprocnameoptions;
  4450. begin
  4451. pno:=[];
  4452. if showhidden then
  4453. include(pno,pno_showhidden);
  4454. result:=customprocname(pno);
  4455. end;
  4456. function tprocdef.customprocname(pno: tprocnameoptions):ansistring;
  4457. var
  4458. s, rn : ansistring;
  4459. t : ttoken;
  4460. begin
  4461. {$ifdef EXTDEBUG}
  4462. include(pno,pno_showhidden);
  4463. {$endif EXTDEBUG}
  4464. s:='';
  4465. if proctypeoption=potype_operator then
  4466. begin
  4467. for t:=NOTOKEN to last_overloaded do
  4468. if procsym.realname='$'+overloaded_names[t] then
  4469. begin
  4470. s:='operator ';
  4471. if (pno_ownername in pno) and
  4472. assigned(struct) then
  4473. s:=s+struct.RttiName+'.';
  4474. s:=s+arraytokeninfo[t].str+typename_paras(pno);
  4475. break;
  4476. end;
  4477. end
  4478. else
  4479. begin
  4480. if (po_classmethod in procoptions) and
  4481. not(pno_noclassmarker in pno) then
  4482. s:='class ';
  4483. case proctypeoption of
  4484. potype_constructor,
  4485. potype_class_constructor:
  4486. s:=s+'constructor ';
  4487. potype_class_destructor,
  4488. potype_destructor:
  4489. s:=s+'destructor ';
  4490. else
  4491. if (pno_proctypeoption in pno) then
  4492. begin
  4493. if assigned(returndef) and
  4494. not(is_void(returndef)) then
  4495. s:=s+'function '
  4496. else
  4497. s:=s+'procedure ';
  4498. end;
  4499. end;
  4500. if (pno_ownername in pno) and
  4501. (owner.symtabletype in [recordsymtable,objectsymtable]) then
  4502. s:=s+tabstractrecorddef(owner.defowner).RttiName+'.';
  4503. rn:=procsym.realname;
  4504. if (pno_noleadingdollar in pno) and
  4505. (rn[1]='$') then
  4506. delete(rn,1,1);
  4507. s:=s+rn+typename_paras(pno);
  4508. end;
  4509. if not(proctypeoption in [potype_constructor,potype_destructor,
  4510. potype_class_constructor,potype_class_destructor]) and
  4511. assigned(returndef) and
  4512. not(is_void(returndef)) then
  4513. s:=s+':'+returndef.GetTypeName;
  4514. if owner.symtabletype=localsymtable then
  4515. s:=s+' is nested';
  4516. s:=s+';';
  4517. { forced calling convention? }
  4518. if (po_hascallingconvention in procoptions) then
  4519. s:=s+' '+ProcCallOptionStr[proccalloption]+';';
  4520. if (po_staticmethod in procoptions) and
  4521. not (proctypeoption in [potype_class_constructor,potype_class_destructor]) then
  4522. s:=s+' Static;';
  4523. customprocname:=s;
  4524. end;
  4525. function tprocdef.is_methodpointer:boolean;
  4526. begin
  4527. { don't check assigned(_class), that's also the case for nested
  4528. procedures inside methods }
  4529. result:=(owner.symtabletype=ObjectSymtable)and not no_self_node;
  4530. end;
  4531. function tprocdef.is_addressonly:boolean;
  4532. begin
  4533. result:=assigned(owner) and
  4534. not is_methodpointer and
  4535. (not(m_nested_procvars in current_settings.modeswitches) or
  4536. not is_nested_pd(self));
  4537. end;
  4538. procedure tprocdef.make_external;
  4539. begin
  4540. include(procoptions,po_external);
  4541. forwarddef:=false;
  4542. end;
  4543. function tprocdef.GetSymtable(t:tGetSymtable):TSymtable;
  4544. begin
  4545. case t of
  4546. gs_local :
  4547. GetSymtable:=localst;
  4548. gs_para :
  4549. GetSymtable:=parast;
  4550. else
  4551. GetSymtable:=nil;
  4552. end;
  4553. end;
  4554. function tprocdef.getcopyas(newtyp: tdeftyp; copytyp: tproccopytyp): tstoreddef;
  4555. var
  4556. j : longint;
  4557. begin
  4558. result:=inherited getcopyas(newtyp,copytyp);
  4559. if newtyp=procvardef then
  4560. exit;
  4561. { don't copy mangled name, can be different }
  4562. tprocdef(result).messageinf:=messageinf;
  4563. tprocdef(result).dispid:=dispid;
  4564. if po_msgstr in procoptions then
  4565. tprocdef(result).messageinf.str:=stringdup(messageinf.str^);
  4566. tprocdef(result).symoptions:=symoptions;
  4567. if assigned(deprecatedmsg) then
  4568. tprocdef(result).deprecatedmsg:=stringdup(deprecatedmsg^);
  4569. { will have to be associated with appropriate procsym }
  4570. tprocdef(result).procsym:=nil;
  4571. if copytyp<>pc_bareproc then
  4572. tprocdef(result).aliasnames.concatListcopy(aliasnames);
  4573. if assigned(funcretsym) then
  4574. begin
  4575. if funcretsym.owner=parast then
  4576. begin
  4577. j:=parast.symlist.indexof(funcretsym);
  4578. if j<0 then
  4579. internalerror(2011040606);
  4580. tprocdef(result).funcretsym:=tsym(tprocdef(result).parast.symlist[j]);
  4581. end
  4582. else if funcretsym.owner=localst then
  4583. begin
  4584. { nothing to do, will be inserted for the new procdef while
  4585. parsing its body (by pdecsub.insert_funcret_local) }
  4586. end
  4587. else
  4588. internalerror(2011040605);
  4589. end;
  4590. { will have to be associated with a new struct }
  4591. tprocdef(result).struct:=nil;
  4592. {$if defined(powerpc) or defined(m68k)}
  4593. tprocdef(result).libsym:=libsym;
  4594. {$endif powerpc or m68k}
  4595. if assigned(implprocdefinfo) then
  4596. begin
  4597. if assigned(resultname) then
  4598. tprocdef(result).resultname:=stringdup(resultname^);
  4599. end;
  4600. if assigned(import_dll) then
  4601. tprocdef(result).import_dll:=stringdup(import_dll^);
  4602. if assigned(import_name) then
  4603. tprocdef(result).import_name:=stringdup(import_name^);
  4604. tprocdef(result).import_nr:=import_nr;
  4605. tprocdef(result).extnumber:=$ffff;
  4606. {$if defined(i386) or defined(i8086)}
  4607. tprocdef(result).fpu_used:=fpu_used;
  4608. {$endif i386 or i8086}
  4609. tprocdef(result).visibility:=visibility;
  4610. tprocdef(result).synthetickind:=synthetickind;
  4611. { we need a separate implementation for the copied def }
  4612. tprocdef(result).forwarddef:=true;
  4613. tprocdef(result).interfacedef:=true;
  4614. { create new paralist }
  4615. tprocdef(result).calcparas;
  4616. end;
  4617. function tprocdef.getcopy: tstoreddef;
  4618. begin
  4619. result:=getcopyas(procdef,pc_normal);
  4620. end;
  4621. procedure tprocdef.buildderef;
  4622. begin
  4623. inherited buildderef;
  4624. structderef.build(struct);
  4625. { procsym that originaly defined this definition, should be in the
  4626. same symtable }
  4627. procsymderef.build(procsym);
  4628. {$if defined(powerpc) or defined(m68k)}
  4629. { library symbol for AmigaOS/MorphOS }
  4630. libsymderef.build(libsym);
  4631. {$endif powerpc or m68k}
  4632. end;
  4633. procedure tprocdef.buildderefimpl;
  4634. begin
  4635. inherited buildderefimpl;
  4636. { inline tree }
  4637. if has_inlininginfo then
  4638. begin
  4639. { Localst is not available for main/unit init }
  4640. if assigned(localst) then
  4641. begin
  4642. tlocalsymtable(localst).buildderef;
  4643. tlocalsymtable(localst).buildderefimpl;
  4644. end;
  4645. funcretsymderef.build(funcretsym);
  4646. inlininginfo^.code.buildderefimpl;
  4647. end;
  4648. end;
  4649. procedure tprocdef.deref;
  4650. begin
  4651. inherited deref;
  4652. struct:=tabstractrecorddef(structderef.resolve);
  4653. { procsym that originaly defined this definition, should be in the
  4654. same symtable }
  4655. procsym:=tprocsym(procsymderef.resolve);
  4656. {$if defined(powerpc) or defined(m68k)}
  4657. { library symbol for AmigaOS/MorphOS }
  4658. libsym:=tsym(libsymderef.resolve);
  4659. {$endif powerpc or m68k}
  4660. end;
  4661. procedure tprocdef.derefimpl;
  4662. begin
  4663. { Enable has_inlininginfo when the inlininginfo
  4664. structure is available. The has_inlininginfo was disabled
  4665. after the load, since the data was invalid }
  4666. if assigned(inlininginfo) then
  4667. has_inlininginfo:=true;
  4668. { Inline }
  4669. if has_inlininginfo then
  4670. begin
  4671. { Locals }
  4672. if assigned(localst) then
  4673. begin
  4674. tlocalsymtable(localst).deref;
  4675. tlocalsymtable(localst).derefimpl;
  4676. end;
  4677. inlininginfo^.code.derefimpl;
  4678. { funcretsym, this is always located in the localst }
  4679. funcretsym:=tsym(funcretsymderef.resolve);
  4680. end
  4681. else
  4682. begin
  4683. { safety }
  4684. { Not safe! A unit may be reresolved after its interface has been
  4685. parsed but before its implementation has been parsed, and in that
  4686. case the funcretsym is still required!
  4687. funcretsym:=nil; }
  4688. end;
  4689. end;
  4690. function tprocdef.GetTypeName : string;
  4691. begin
  4692. GetTypeName := FullProcName(false);
  4693. end;
  4694. function tprocdef.mangledname : TSymStr;
  4695. begin
  4696. {$ifdef symansistr}
  4697. if _mangledname='' then
  4698. begin
  4699. result:=defaultmangledname;
  4700. _mangledname:=result;
  4701. end
  4702. else
  4703. result:=_mangledname;
  4704. {$else symansistr}
  4705. if not assigned(_mangledname) then
  4706. begin
  4707. result:=defaultmangledname;
  4708. _mangledname:=stringdup(mangledname);
  4709. end
  4710. else
  4711. result:=_mangledname^;
  4712. {$endif symansistr}
  4713. end;
  4714. function tprocdef.defaultmangledname: TSymStr;
  4715. var
  4716. hp : TParavarsym;
  4717. hs : TSymStr;
  4718. crc : dword;
  4719. newlen,
  4720. oldlen,
  4721. i : integer;
  4722. begin
  4723. hp:=nil;
  4724. { we need to use the symtable where the procsym is inserted,
  4725. because that is visible to the world }
  4726. defaultmangledname:=make_mangledname('',procsym.owner,procsym.name);
  4727. oldlen:=length(defaultmangledname);
  4728. { add parameter types }
  4729. for i:=0 to paras.count-1 do
  4730. begin
  4731. hp:=tparavarsym(paras[i]);
  4732. if not(vo_is_hidden_para in hp.varoptions) then
  4733. defaultmangledname:=defaultmangledname+'$'+hp.vardef.mangledparaname;
  4734. end;
  4735. { add resultdef, add $$ as separator to make it unique from a
  4736. parameter separator }
  4737. if not is_void(returndef) then
  4738. defaultmangledname:=defaultmangledname+'$$'+returndef.mangledparaname;
  4739. newlen:=length(defaultmangledname);
  4740. { Replace with CRC if the parameter line is very long }
  4741. if (newlen-oldlen>12) and
  4742. ((newlen>100) or (newlen-oldlen>64)) then
  4743. begin
  4744. crc:=0;
  4745. for i:=0 to paras.count-1 do
  4746. begin
  4747. hp:=tparavarsym(paras[i]);
  4748. if not(vo_is_hidden_para in hp.varoptions) then
  4749. begin
  4750. hs:=hp.vardef.mangledparaname;
  4751. crc:=UpdateCrc32(crc,hs[1],length(hs));
  4752. end;
  4753. end;
  4754. hs:=hp.vardef.mangledparaname;
  4755. crc:=UpdateCrc32(crc,hs[1],length(hs));
  4756. defaultmangledname:=Copy(defaultmangledname,1,oldlen)+'$crc'+hexstr(crc,8);
  4757. end;
  4758. end;
  4759. function tprocdef.cplusplusmangledname : TSymStr;
  4760. function getcppparaname(p : tdef) : TSymStr;
  4761. const
  4762. {$ifdef NAMEMANGLING_GCC2}
  4763. ordtype2str : array[tordtype] of string[2] = (
  4764. '',
  4765. 'Uc','Us','Ui','Us',
  4766. 'Sc','s','i','x',
  4767. 'b','b','b','b','b',
  4768. 'c','w','x');
  4769. {$else NAMEMANGLING_GCC2}
  4770. ordtype2str : array[tordtype] of string[1] = (
  4771. 'v',
  4772. 'h','t','j','y',
  4773. 'a','s','i','x',
  4774. 'b','b','b','b',
  4775. 'b','b','b','b',
  4776. 'c','w','x');
  4777. floattype2str : array[tfloattype] of string[1] = (
  4778. 'f','d','e','e',
  4779. 'd','d','g');
  4780. {$endif NAMEMANGLING_GCC2}
  4781. var
  4782. s : TSymStr;
  4783. begin
  4784. case p.typ of
  4785. orddef:
  4786. s:=ordtype2str[torddef(p).ordtype];
  4787. pointerdef:
  4788. s:='P'+getcppparaname(tpointerdef(p).pointeddef);
  4789. {$ifndef NAMEMANGLING_GCC2}
  4790. floatdef:
  4791. s:=floattype2str[tfloatdef(p).floattype];
  4792. {$endif NAMEMANGLING_GCC2}
  4793. else
  4794. internalerror(2103001);
  4795. end;
  4796. getcppparaname:=s;
  4797. end;
  4798. var
  4799. s,s2 : TSymStr;
  4800. hp : TParavarsym;
  4801. i : integer;
  4802. begin
  4803. {$ifdef NAMEMANGLING_GCC2}
  4804. { outdated gcc 2.x name mangling scheme }
  4805. s := procsym.realname;
  4806. if procsym.owner.symtabletype=ObjectSymtable then
  4807. begin
  4808. s2:=upper(tobjectdef(procsym.owner.defowner).objrealname^);
  4809. case proctypeoption of
  4810. potype_destructor:
  4811. s:='_$_'+tostr(length(s2))+s2;
  4812. potype_constructor:
  4813. s:='___'+tostr(length(s2))+s2;
  4814. else
  4815. s:='_'+s+'__'+tostr(length(s2))+s2;
  4816. end;
  4817. end
  4818. else s:=s+'__';
  4819. s:=s+'F';
  4820. { concat modifiers }
  4821. { !!!!! }
  4822. { now we handle the parameters }
  4823. if maxparacount>0 then
  4824. begin
  4825. for i:=0 to paras.count-1 do
  4826. begin
  4827. hp:=tparavarsym(paras[i]);
  4828. { no hidden parameters form part of a C++ mangled name:
  4829. a) self is not included
  4830. b) there are no "high" or other hidden parameters
  4831. }
  4832. if vo_is_hidden_para in hp.varoptions then
  4833. continue;
  4834. s2:=getcppparaname(hp.vardef);
  4835. if hp.varspez in [vs_var,vs_out] then
  4836. s2:='R'+s2;
  4837. s:=s+s2;
  4838. end;
  4839. end
  4840. else
  4841. s:=s+'v';
  4842. cplusplusmangledname:=s;
  4843. {$else NAMEMANGLING_GCC2}
  4844. { gcc 3.x and 4.x name mangling scheme }
  4845. { see http://www.codesourcery.com/public/cxx-abi/abi.html#mangling }
  4846. if procsym.owner.symtabletype=ObjectSymtable then
  4847. begin
  4848. s:='_ZN';
  4849. s2:=tobjectdef(procsym.owner.defowner).objextname^;
  4850. s:=s+tostr(length(s2))+s2;
  4851. case proctypeoption of
  4852. potype_constructor:
  4853. s:=s+'C1';
  4854. potype_destructor:
  4855. s:=s+'D1';
  4856. else
  4857. s:=s+tostr(length(procsym.realname))+procsym.realname;
  4858. end;
  4859. s:=s+'E';
  4860. end
  4861. else
  4862. s:=procsym.realname;
  4863. { now we handle the parameters }
  4864. if maxparacount>0 then
  4865. begin
  4866. for i:=0 to paras.count-1 do
  4867. begin
  4868. hp:=tparavarsym(paras[i]);
  4869. { no hidden parameters form part of a C++ mangled name:
  4870. a) self is not included
  4871. b) there are no "high" or other hidden parameters
  4872. }
  4873. if vo_is_hidden_para in hp.varoptions then
  4874. continue;
  4875. s2:=getcppparaname(hp.vardef);
  4876. if hp.varspez in [vs_var,vs_out] then
  4877. s2:='R'+s2;
  4878. s:=s+s2;
  4879. end;
  4880. end
  4881. else
  4882. s:=s+'v';
  4883. cplusplusmangledname:=s;
  4884. {$endif NAMEMANGLING_GCC2}
  4885. end;
  4886. function tprocdef.objcmangledname : TSymStr;
  4887. var
  4888. manglednamelen: longint;
  4889. iscatmethod : boolean;
  4890. begin
  4891. if not (po_msgstr in procoptions) then
  4892. internalerror(2009030901);
  4893. { we may very well need longer strings to handle these... }
  4894. manglednamelen:=length(tobjectdef(procsym.owner.defowner).objextname^)+
  4895. length('+"[ ]"')+length(messageinf.str^);
  4896. iscatmethod:=oo_is_classhelper in tobjectdef(procsym.owner.defowner).objectoptions;
  4897. if (iscatmethod) then
  4898. inc(manglednamelen,length(tobjectdef(procsym.owner.defowner).childof.objextname^)+length('()'));
  4899. if manglednamelen>255 then
  4900. Message1(parser_e_objc_message_name_too_long,messageinf.str^);
  4901. if not(po_classmethod in procoptions) then
  4902. result:='"-['
  4903. else
  4904. result:='"+[';
  4905. { quotes are necessary because the +/- otherwise confuse the assembler
  4906. into expecting a number
  4907. }
  4908. if iscatmethod then
  4909. result:=result+tobjectdef(procsym.owner.defowner).childof.objextname^+'(';
  4910. result:=result+tobjectdef(procsym.owner.defowner).objextname^;
  4911. if iscatmethod then
  4912. result:=result+')';
  4913. result:=result+' '+messageinf.str^+']"';
  4914. end;
  4915. procedure tprocdef.setmangledname(const s : TSymStr);
  4916. begin
  4917. { This is not allowed anymore, the forward declaration
  4918. already needs to create the correct mangledname, no changes
  4919. afterwards are allowed (PFV) }
  4920. { Exception: interface definitions in mode macpas, since in that }
  4921. { case no reference to the old name can exist yet (JM) }
  4922. {$ifdef symansistr}
  4923. if _mangledname<>'' then
  4924. if ((m_mac in current_settings.modeswitches) and
  4925. (interfacedef)) then
  4926. _mangledname:=''
  4927. else
  4928. internalerror(200411171);
  4929. {$else symansistr}
  4930. if assigned(_mangledname) then
  4931. if ((m_mac in current_settings.modeswitches) and
  4932. (interfacedef)) then
  4933. stringdispose(_mangledname)
  4934. else
  4935. internalerror(200411171);
  4936. {$endif symansistr}
  4937. {$ifdef jvm}
  4938. { this routine can be called for compilerproces. can't set mangled
  4939. name since it must be calculated, but it uses import_name when set
  4940. -> set that one }
  4941. import_name:=stringdup(s);
  4942. include(procoptions,po_has_importname);
  4943. include(procoptions,po_has_mangledname);
  4944. {$else}
  4945. {$ifdef symansistr}
  4946. _mangledname:=s;
  4947. {$else symansistr}
  4948. _mangledname:=stringdup(s);
  4949. {$endif symansistr}
  4950. {$endif jvm}
  4951. include(procoptions,po_has_mangledname);
  4952. end;
  4953. {***************************************************************************
  4954. TPROCVARDEF
  4955. ***************************************************************************}
  4956. constructor tprocvardef.create(level:byte);
  4957. begin
  4958. inherited create(procvardef,level);
  4959. end;
  4960. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  4961. begin
  4962. inherited ppuload(procvardef,ppufile);
  4963. { load para symtable }
  4964. parast:=tparasymtable.create(self,ppufile.getbyte);
  4965. ppuload_platform(ppufile);
  4966. tparasymtable(parast).ppuload(ppufile);
  4967. end;
  4968. function tprocvardef.getcopy : tstoreddef;
  4969. var
  4970. i : tcallercallee;
  4971. j : longint;
  4972. begin
  4973. result:=cprocvardef.create(parast.symtablelevel);
  4974. tprocvardef(result).returndef:=returndef;
  4975. tprocvardef(result).returndefderef:=returndefderef;
  4976. tprocvardef(result).parast:=parast.getcopy;
  4977. tprocvardef(result).savesize:=savesize;
  4978. { create paralist copy }
  4979. calcparas;
  4980. tprocvardef(result).paras:=tparalist.create(false);
  4981. tprocvardef(result).paras.count:=paras.count;
  4982. for j:=0 to paras.count-1 do
  4983. tprocvardef(result).paras[j]:=paras[j];
  4984. tprocvardef(result).proctypeoption:=proctypeoption;
  4985. tprocvardef(result).proccalloption:=proccalloption;
  4986. tprocvardef(result).procoptions:=procoptions;
  4987. tprocvardef(result).callerargareasize:=callerargareasize;
  4988. tprocvardef(result).calleeargareasize:=calleeargareasize;
  4989. tprocvardef(result).maxparacount:=maxparacount;
  4990. tprocvardef(result).minparacount:=minparacount;
  4991. for i:=low(tcallercallee) to high(tcallercallee) do
  4992. tprocvardef(result).funcretloc[i]:=funcretloc[i].getcopy;
  4993. tprocvardef(result).has_paraloc_info:=has_paraloc_info;
  4994. {$ifdef m68k}
  4995. tprocvardef(result).exp_funcretloc:=exp_funcretloc;
  4996. {$endif}
  4997. end;
  4998. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  4999. begin
  5000. inherited ppuwrite(ppufile);
  5001. { Save the para symtable level (necessary to distinguish nested
  5002. procvars) }
  5003. ppufile.putbyte(parast.symtablelevel);
  5004. { Write this entry }
  5005. writeentry(ppufile,ibprocvardef);
  5006. { Save the para symtable, this is taken from the interface }
  5007. tparasymtable(parast).ppuwrite(ppufile);
  5008. end;
  5009. function tprocvardef.GetSymtable(t:tGetSymtable):TSymtable;
  5010. begin
  5011. case t of
  5012. gs_para :
  5013. GetSymtable:=parast;
  5014. else
  5015. GetSymtable:=nil;
  5016. end;
  5017. end;
  5018. function tprocvardef.size : asizeint;
  5019. var
  5020. far_code_extra_bytes: integer = 0;
  5021. begin
  5022. {$ifdef i8086}
  5023. if po_far in procoptions then
  5024. far_code_extra_bytes:=2;
  5025. {$endif i8086}
  5026. if ((po_methodpointer in procoptions) or
  5027. is_nested_pd(self)) and
  5028. not(po_addressonly in procoptions) then
  5029. size:=sizeof(pint)+far_code_extra_bytes+voidpointertype.size
  5030. else
  5031. size:=sizeof(pint)+far_code_extra_bytes;
  5032. end;
  5033. function tprocvardef.is_methodpointer:boolean;
  5034. begin
  5035. result:=(po_methodpointer in procoptions);
  5036. end;
  5037. function tprocvardef.is_addressonly:boolean;
  5038. begin
  5039. result:=(not(po_methodpointer in procoptions) and
  5040. not is_nested_pd(self)) or
  5041. (po_addressonly in procoptions);
  5042. end;
  5043. function tprocvardef.getmangledparaname:TSymStr;
  5044. begin
  5045. if not(po_methodpointer in procoptions) then
  5046. if not is_nested_pd(self) then
  5047. result:='procvar'
  5048. else
  5049. result:='nestedprovar'
  5050. else
  5051. result:='procvarofobj'
  5052. end;
  5053. function tprocvardef.is_publishable : boolean;
  5054. begin
  5055. is_publishable:=(po_methodpointer in procoptions);
  5056. end;
  5057. function tprocvardef.GetTypeName : string;
  5058. var
  5059. s: string;
  5060. pno : tprocnameoptions;
  5061. begin
  5062. {$ifdef EXTDEBUG}
  5063. pno:=[pno_showhidden];
  5064. {$else EXTDEBUG}
  5065. pno:=[];
  5066. {$endif EXTDEBUG}
  5067. s:='<';
  5068. if po_classmethod in procoptions then
  5069. s := s+'class method type of'
  5070. else
  5071. if po_addressonly in procoptions then
  5072. s := s+'address of'
  5073. else
  5074. s := s+'procedure variable type of';
  5075. if assigned(returndef) and
  5076. (returndef<>voidtype) then
  5077. s:=s+' function'+typename_paras(pno)+':'+returndef.GetTypeName
  5078. else
  5079. s:=s+' procedure'+typename_paras(pno);
  5080. if po_methodpointer in procoptions then
  5081. s := s+' of object';
  5082. if is_nested_pd(self) then
  5083. s := s+' is nested';
  5084. GetTypeName := s+';'+ProcCallOptionStr[proccalloption]+'>';
  5085. end;
  5086. {***************************************************************************
  5087. TOBJECTDEF
  5088. ***************************************************************************}
  5089. constructor tobjectdef.create(ot:tobjecttyp;const n:string;c:tobjectdef);
  5090. begin
  5091. inherited create(n,objectdef);
  5092. fcurrent_dispid:=0;
  5093. objecttype:=ot;
  5094. childof:=nil;
  5095. if objecttype=odt_helper then
  5096. owner.includeoption(sto_has_helper);
  5097. symtable:=tObjectSymtable.create(self,n,current_settings.packrecords);
  5098. { create space for vmt !! }
  5099. vmtentries:=TFPList.Create;
  5100. vmt_offset:=0;
  5101. set_parent(c);
  5102. if objecttype in [odt_interfacecorba,odt_interfacecom,odt_dispinterface] then
  5103. prepareguid;
  5104. { setup implemented interfaces }
  5105. if objecttype in [odt_class,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  5106. ImplementedInterfaces:=TFPObjectList.Create(true)
  5107. else
  5108. ImplementedInterfaces:=nil;
  5109. writing_class_record_dbginfo:=false;
  5110. end;
  5111. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  5112. var
  5113. i,
  5114. implintfcount : longint;
  5115. d, getterd : tderef;
  5116. ImplIntf : TImplementedInterface;
  5117. vmtentry : pvmtentry;
  5118. begin
  5119. inherited ppuload(objectdef,ppufile);
  5120. objecttype:=tobjecttyp(ppufile.getbyte);
  5121. objextname:=stringdup(ppufile.getstring);
  5122. { only used for external Objective-C classes/protocols }
  5123. if (objextname^='') then
  5124. stringdispose(objextname);
  5125. symtable:=tObjectSymtable.create(self,objrealname^,0);
  5126. tObjectSymtable(symtable).datasize:=ppufile.getasizeint;
  5127. tObjectSymtable(symtable).paddingsize:=ppufile.getword;
  5128. tObjectSymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  5129. tObjectSymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  5130. vmt_offset:=ppufile.getlongint;
  5131. ppufile.getderef(childofderef);
  5132. { load guid }
  5133. iidstr:=nil;
  5134. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  5135. begin
  5136. new(iidguid);
  5137. ppufile.getguid(iidguid^);
  5138. iidstr:=stringdup(ppufile.getstring);
  5139. end;
  5140. abstractcnt:=ppufile.getlongint;
  5141. if objecttype=odt_helper then
  5142. ppufile.getderef(extendeddefderef);
  5143. vmtentries:=TFPList.Create;
  5144. vmtentries.count:=ppufile.getlongint;
  5145. for i:=0 to vmtentries.count-1 do
  5146. begin
  5147. ppufile.getderef(d);
  5148. new(vmtentry);
  5149. vmtentry^.procdef:=nil;
  5150. vmtentry^.procdefderef:=d;
  5151. vmtentry^.visibility:=tvisibility(ppufile.getbyte);
  5152. vmtentries[i]:=vmtentry;
  5153. end;
  5154. { load implemented interfaces }
  5155. if objecttype in [odt_class,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  5156. begin
  5157. ImplementedInterfaces:=TFPObjectList.Create(true);
  5158. implintfcount:=ppufile.getlongint;
  5159. for i:=0 to implintfcount-1 do
  5160. begin
  5161. ppufile.getderef(d);
  5162. ppufile.getderef(getterd);
  5163. ImplIntf:=TImplementedInterface.Create_deref(d,getterd);
  5164. ImplIntf.IOffset:=ppufile.getlongint;
  5165. byte(ImplIntf.IType):=ppufile.getbyte;
  5166. ImplementedInterfaces.Add(ImplIntf);
  5167. end;
  5168. end
  5169. else
  5170. ImplementedInterfaces:=nil;
  5171. if df_copied_def in defoptions then
  5172. begin
  5173. ppufile.getderef(cloneddefderef);
  5174. ppuload_platform(ppufile);
  5175. end
  5176. else
  5177. begin
  5178. ppuload_platform(ppufile);
  5179. tObjectSymtable(symtable).ppuload(ppufile);
  5180. end;
  5181. { handles the predefined class tobject }
  5182. { the last TOBJECT which is loaded gets }
  5183. { it ! }
  5184. if (childof=nil) and
  5185. (objecttype in [odt_class,odt_javaclass]) and
  5186. (objname^='TOBJECT') then
  5187. class_tobject:=self;
  5188. if (childof=nil) and
  5189. (objecttype=odt_interfacecom) then
  5190. if (objname^='IUNKNOWN') then
  5191. interface_iunknown:=self
  5192. else
  5193. if (objname^='IDISPATCH') then
  5194. interface_idispatch:=self;
  5195. if (childof=nil) and
  5196. (objecttype=odt_objcclass) and
  5197. (objname^='PROTOCOL') then
  5198. objc_protocoltype:=self;
  5199. if (objecttype=odt_javaclass) and
  5200. not(oo_is_formal in objectoptions) then
  5201. begin
  5202. if (objname^='JLOBJECT') then
  5203. java_jlobject:=self
  5204. else if (objname^='JLTHROWABLE') then
  5205. java_jlthrowable:=self
  5206. else if (objname^='FPCBASERECORDTYPE') then
  5207. java_fpcbaserecordtype:=self
  5208. else if (objname^='JLSTRING') then
  5209. java_jlstring:=self
  5210. else if (objname^='ANSISTRINGCLASS') then
  5211. java_ansistring:=self
  5212. else if (objname^='SHORTSTRINGCLASS') then
  5213. java_shortstring:=self
  5214. else if (objname^='JLENUM') then
  5215. java_jlenum:=self
  5216. else if (objname^='JUENUMSET') then
  5217. java_juenumset:=self
  5218. else if (objname^='FPCBITSET') then
  5219. java_jubitset:=self
  5220. else if (objname^='FPCBASEPROCVARTYPE') then
  5221. java_procvarbase:=self;
  5222. end;
  5223. writing_class_record_dbginfo:=false;
  5224. end;
  5225. destructor tobjectdef.destroy;
  5226. begin
  5227. if assigned(symtable) then
  5228. begin
  5229. symtable.free;
  5230. symtable:=nil;
  5231. end;
  5232. stringdispose(objextname);
  5233. stringdispose(iidstr);
  5234. if assigned(ImplementedInterfaces) then
  5235. begin
  5236. ImplementedInterfaces.free;
  5237. ImplementedInterfaces:=nil;
  5238. end;
  5239. if assigned(iidguid) then
  5240. begin
  5241. dispose(iidguid);
  5242. iidguid:=nil;
  5243. end;
  5244. if assigned(vmtentries) then
  5245. begin
  5246. resetvmtentries;
  5247. vmtentries.free;
  5248. vmtentries:=nil;
  5249. end;
  5250. if assigned(vmcallstaticinfo) then
  5251. begin
  5252. freemem(vmcallstaticinfo);
  5253. vmcallstaticinfo:=nil;
  5254. end;
  5255. inherited destroy;
  5256. end;
  5257. function tobjectdef.getcopy : tstoreddef;
  5258. var
  5259. i : longint;
  5260. begin
  5261. result:=cobjectdef.create(objecttype,objrealname^,childof);
  5262. { the constructor allocates a symtable which we release to avoid memory leaks }
  5263. tobjectdef(result).symtable.free;
  5264. tobjectdef(result).symtable:=symtable.getcopy;
  5265. if assigned(objextname) then
  5266. tobjectdef(result).objextname:=stringdup(objextname^);
  5267. if assigned(import_lib) then
  5268. tobjectdef(result).import_lib:=stringdup(import_lib^);
  5269. tobjectdef(result).objectoptions:=objectoptions;
  5270. include(tobjectdef(result).defoptions,df_copied_def);
  5271. tobjectdef(result).extendeddef:=extendeddef;
  5272. if assigned(tcinitcode) then
  5273. tobjectdef(result).tcinitcode:=tcinitcode.getcopy;
  5274. tobjectdef(result).vmt_offset:=vmt_offset;
  5275. if assigned(iidguid) then
  5276. begin
  5277. new(tobjectdef(result).iidguid);
  5278. move(iidguid^,tobjectdef(result).iidguid^,sizeof(iidguid^));
  5279. end;
  5280. if assigned(iidstr) then
  5281. tobjectdef(result).iidstr:=stringdup(iidstr^);
  5282. tobjectdef(result).abstractcnt:=abstractcnt;
  5283. if assigned(ImplementedInterfaces) then
  5284. begin
  5285. for i:=0 to ImplementedInterfaces.count-1 do
  5286. tobjectdef(result).ImplementedInterfaces.Add(TImplementedInterface(ImplementedInterfaces[i]).Getcopy);
  5287. end;
  5288. if assigned(vmtentries) then
  5289. begin
  5290. tobjectdef(result).vmtentries:=TFPList.Create;
  5291. tobjectdef(result).copyvmtentries(self);
  5292. end;
  5293. end;
  5294. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  5295. var
  5296. i : longint;
  5297. vmtentry : pvmtentry;
  5298. ImplIntf : TImplementedInterface;
  5299. old_do_indirect_crc: boolean;
  5300. begin
  5301. { if class1 in unit A changes, and class2 in unit B inherits from it
  5302. (so unit B uses unit A), then unit B with class2 will be recompiled.
  5303. However, if there is also a class3 in unit C that only depends on
  5304. unit B, then unit C will not be recompiled because nothing changed
  5305. to the interface of unit B. Nevertheless, unit C can indirectly
  5306. depend on unit A via derefs, and these must be updated -> the
  5307. indirect crc keeps track of such changes. }
  5308. old_do_indirect_crc:=ppufile.do_indirect_crc;
  5309. ppufile.do_indirect_crc:=true;
  5310. inherited ppuwrite(ppufile);
  5311. ppufile.putbyte(byte(objecttype));
  5312. if assigned(objextname) then
  5313. ppufile.putstring(objextname^)
  5314. else
  5315. ppufile.putstring('');
  5316. ppufile.putasizeint(tObjectSymtable(symtable).datasize);
  5317. ppufile.putword(tObjectSymtable(symtable).paddingsize);
  5318. ppufile.putbyte(byte(tObjectSymtable(symtable).fieldalignment));
  5319. ppufile.putbyte(byte(tObjectSymtable(symtable).recordalignment));
  5320. ppufile.putlongint(vmt_offset);
  5321. ppufile.putderef(childofderef);
  5322. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  5323. begin
  5324. ppufile.putguid(iidguid^);
  5325. ppufile.putstring(iidstr^);
  5326. end;
  5327. ppufile.putlongint(abstractcnt);
  5328. if objecttype=odt_helper then
  5329. ppufile.putderef(extendeddefderef);
  5330. ppufile.putlongint(vmtentries.count);
  5331. for i:=0 to vmtentries.count-1 do
  5332. begin
  5333. vmtentry:=pvmtentry(vmtentries[i]);
  5334. ppufile.putderef(vmtentry^.procdefderef);
  5335. ppufile.putbyte(byte(vmtentry^.visibility));
  5336. end;
  5337. if assigned(ImplementedInterfaces) then
  5338. begin
  5339. ppufile.putlongint(ImplementedInterfaces.Count);
  5340. for i:=0 to ImplementedInterfaces.Count-1 do
  5341. begin
  5342. ImplIntf:=TImplementedInterface(ImplementedInterfaces[i]);
  5343. ppufile.putderef(ImplIntf.intfdefderef);
  5344. ppufile.putderef(ImplIntf.ImplementsGetterDeref);
  5345. ppufile.putlongint(ImplIntf.Ioffset);
  5346. ppufile.putbyte(byte(ImplIntf.IType));
  5347. end;
  5348. end;
  5349. if df_copied_def in defoptions then
  5350. ppufile.putderef(cloneddefderef);
  5351. writeentry(ppufile,ibobjectdef);
  5352. if not(df_copied_def in defoptions) then
  5353. tObjectSymtable(symtable).ppuwrite(ppufile);
  5354. ppufile.do_indirect_crc:=old_do_indirect_crc;
  5355. end;
  5356. function tobjectdef.GetTypeName:string;
  5357. begin
  5358. { in this case we will go in endless recursion, because then }
  5359. { there is no tsym associated yet with the def. It can occur }
  5360. { (tests/webtbf/tw4757.pp), so for now give a generic name }
  5361. { instead of the actual type name }
  5362. if not assigned(typesym) then
  5363. result:='<Currently Parsed Class>'
  5364. else
  5365. result:=typesymbolprettyname;
  5366. end;
  5367. procedure tobjectdef.buildderef;
  5368. var
  5369. i : longint;
  5370. vmtentry : pvmtentry;
  5371. begin
  5372. inherited buildderef;
  5373. childofderef.build(childof);
  5374. if df_copied_def in defoptions then
  5375. cloneddefderef.build(symtable.defowner)
  5376. else
  5377. tstoredsymtable(symtable).buildderef;
  5378. if objecttype=odt_helper then
  5379. extendeddefderef.build(extendeddef);
  5380. for i:=0 to vmtentries.count-1 do
  5381. begin
  5382. vmtentry:=pvmtentry(vmtentries[i]);
  5383. vmtentry^.procdefderef.build(vmtentry^.procdef);
  5384. end;
  5385. if assigned(ImplementedInterfaces) then
  5386. begin
  5387. for i:=0 to ImplementedInterfaces.count-1 do
  5388. TImplementedInterface(ImplementedInterfaces[i]).buildderef;
  5389. end;
  5390. end;
  5391. procedure tobjectdef.deref;
  5392. var
  5393. i : longint;
  5394. vmtentry : pvmtentry;
  5395. begin
  5396. inherited deref;
  5397. childof:=tobjectdef(childofderef.resolve);
  5398. if df_copied_def in defoptions then
  5399. begin
  5400. cloneddef:=tobjectdef(cloneddefderef.resolve);
  5401. symtable:=cloneddef.symtable.getcopy;
  5402. end
  5403. else
  5404. tstoredsymtable(symtable).deref;
  5405. fillgenericparas(symtable);
  5406. if objecttype=odt_helper then
  5407. extendeddef:=tdef(extendeddefderef.resolve);
  5408. for i:=0 to vmtentries.count-1 do
  5409. begin
  5410. vmtentry:=pvmtentry(vmtentries[i]);
  5411. vmtentry^.procdef:=tprocdef(vmtentry^.procdefderef.resolve);
  5412. end;
  5413. if assigned(ImplementedInterfaces) then
  5414. begin
  5415. for i:=0 to ImplementedInterfaces.count-1 do
  5416. TImplementedInterface(ImplementedInterfaces[i]).deref;
  5417. end;
  5418. end;
  5419. procedure create_class_helper_for_procdef(def: tobject; arg: pointer);
  5420. var
  5421. pd: tprocdef absolute def;
  5422. st: tsymtable;
  5423. psym: tsym;
  5424. nname: TIDString;
  5425. begin
  5426. if (tdef(def).typ<>procdef) then
  5427. exit;
  5428. { pd.owner = objcclass symtable -> defowner = objcclassdef ->
  5429. owner = symtable in which objcclassdef is defined
  5430. }
  5431. st:=pd.owner.defowner.owner;
  5432. nname:=class_helper_prefix+tprocsym(pd.procsym).name;
  5433. { check for an existing procsym with our special name }
  5434. psym:=tsym(st.find(nname));
  5435. if not assigned(psym) then
  5436. begin
  5437. psym:=cprocsym.create(nname);
  5438. { avoid warning about this symbol being unused }
  5439. psym.IncRefCount;
  5440. { don't check for duplicates:
  5441. a) we checked above
  5442. b) in case we are in the implementation section of a unit, this
  5443. will also check for this symbol in the interface section
  5444. (since you normally cannot have symbols with the same name
  5445. both interface and implementation), and it's possible to
  5446. have class helpers for the same class in the interface and
  5447. in the implementation, and they cannot be merged since only
  5448. the once in the interface must be saved to the ppu/visible
  5449. from other units }
  5450. st.insert(psym,false);
  5451. end
  5452. else if (psym.typ<>procsym) then
  5453. internalerror(2009111501);
  5454. { add ourselves to this special procsym }
  5455. tprocsym(psym).procdeflist.add(def);
  5456. end;
  5457. procedure tobjectdef.buildderefimpl;
  5458. begin
  5459. inherited buildderefimpl;
  5460. if not (df_copied_def in defoptions) then
  5461. tstoredsymtable(symtable).buildderefimpl;
  5462. end;
  5463. procedure tobjectdef.derefimpl;
  5464. begin
  5465. inherited derefimpl;
  5466. if not (df_copied_def in defoptions) then
  5467. tstoredsymtable(symtable).derefimpl;
  5468. { the procdefs are not owned by the class helper procsyms, so they
  5469. are not stored/restored either -> re-add them here }
  5470. if (objecttype=odt_objcclass) or
  5471. (oo_is_classhelper in objectoptions) then
  5472. symtable.DefList.ForEachCall(@create_class_helper_for_procdef,nil);
  5473. end;
  5474. procedure tobjectdef.resetvmtentries;
  5475. var
  5476. i : longint;
  5477. begin
  5478. for i:=0 to vmtentries.Count-1 do
  5479. Dispose(pvmtentry(vmtentries[i]));
  5480. vmtentries.clear;
  5481. end;
  5482. procedure tobjectdef.copyvmtentries(objdef:tobjectdef);
  5483. var
  5484. i : longint;
  5485. vmtentry : pvmtentry;
  5486. begin
  5487. resetvmtentries;
  5488. vmtentries.count:=objdef.vmtentries.count;
  5489. for i:=0 to objdef.vmtentries.count-1 do
  5490. begin
  5491. new(vmtentry);
  5492. vmtentry^:=pvmtentry(objdef.vmtentries[i])^;
  5493. vmtentries[i]:=vmtentry;
  5494. end;
  5495. end;
  5496. function tobjectdef.getparentdef:tdef;
  5497. begin
  5498. { TODO: Remove getparentdef hack}
  5499. { With 2 forward declared classes with the child class before the
  5500. parent class the child class is written earlier to the ppu. Leaving it
  5501. possible to have a reference to the parent class for property overriding,
  5502. but the parent class still has the childof not resolved yet (PFV) }
  5503. if childof=nil then
  5504. childof:=tobjectdef(childofderef.resolve);
  5505. result:=childof;
  5506. end;
  5507. procedure tobjectdef.prepareguid;
  5508. begin
  5509. { set up guid }
  5510. if not assigned(iidguid) then
  5511. begin
  5512. new(iidguid);
  5513. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  5514. end;
  5515. { setup iidstring }
  5516. if not assigned(iidstr) then
  5517. iidstr:=stringdup(''); { default is empty string }
  5518. end;
  5519. procedure tobjectdef.set_parent( c : tobjectdef);
  5520. begin
  5521. if assigned(childof) then
  5522. exit;
  5523. childof:=c;
  5524. if not assigned(c) then
  5525. exit;
  5526. { inherit options and status }
  5527. objectoptions:=objectoptions+(c.objectoptions*inherited_objectoptions);
  5528. { initially has the same number of abstract methods as the parent }
  5529. abstractcnt:=c.abstractcnt;
  5530. { add the data of the anchestor class/object }
  5531. if (objecttype in [odt_class,odt_object,odt_objcclass,odt_javaclass]) then
  5532. begin
  5533. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize+tObjectSymtable(c.symtable).datasize;
  5534. { inherit recordalignment }
  5535. tObjectSymtable(symtable).recordalignment:=tObjectSymtable(c.symtable).recordalignment;
  5536. { if both the parent and this record use C-alignment, also inherit
  5537. the current field alignment }
  5538. if (tObjectSymtable(c.symtable).usefieldalignment=C_alignment) and
  5539. (tObjectSymtable(symtable).usefieldalignment=C_alignment) then
  5540. tObjectSymtable(symtable).fieldalignment:=tObjectSymtable(c.symtable).fieldalignment;
  5541. { the padding is not inherited for Objective-C classes (maybe not
  5542. for cppclass either?) }
  5543. if objecttype=odt_objcclass then
  5544. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize-tObjectSymtable(c.symtable).paddingsize;
  5545. if (oo_has_vmt in objectoptions) and
  5546. (oo_has_vmt in c.objectoptions) then
  5547. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize-sizeof(pint);
  5548. { if parent has a vmt field then the offset is the same for the child PM }
  5549. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  5550. begin
  5551. vmt_offset:=c.vmt_offset;
  5552. include(objectoptions,oo_has_vmt);
  5553. end;
  5554. end;
  5555. end;
  5556. procedure tobjectdef.insertvmt;
  5557. var
  5558. vs: tfieldvarsym;
  5559. begin
  5560. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  5561. exit;
  5562. if (oo_has_vmt in objectoptions) then
  5563. internalerror(12345)
  5564. else
  5565. begin
  5566. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,
  5567. tObjectSymtable(symtable).fieldalignment);
  5568. if (tf_requires_proper_alignment in target_info.flags) then
  5569. begin
  5570. { Align VMT pointer and whole object instance if target CPU requires alignment. }
  5571. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,sizeof(pint));
  5572. tObjectSymtable(symtable).alignrecord(tObjectSymtable(symtable).datasize,sizeof(pint));
  5573. end;
  5574. vs:=cfieldvarsym.create('_vptr$'+objname^,vs_value,voidpointertype,[]);
  5575. hidesym(vs);
  5576. tObjectSymtable(symtable).insert(vs);
  5577. tObjectSymtable(symtable).addfield(vs,vis_hidden);
  5578. if (tObjectSymtable(symtable).usefieldalignment<>bit_alignment) then
  5579. vmt_offset:=vs.fieldoffset
  5580. else
  5581. vmt_offset:=vs.fieldoffset div 8;
  5582. include(objectoptions,oo_has_vmt);
  5583. end;
  5584. end;
  5585. procedure tobjectdef.check_forwards;
  5586. begin
  5587. if not(objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcprotocol,odt_interfacejava]) then
  5588. inherited;
  5589. if (oo_is_forward in objectoptions) then
  5590. begin
  5591. { ok, in future, the forward can be resolved }
  5592. Message1(sym_e_class_forward_not_resolved,objrealname^);
  5593. exclude(objectoptions,oo_is_forward);
  5594. end;
  5595. end;
  5596. function tobjectdef.find_destructor: tprocdef;
  5597. var
  5598. objdef: tobjectdef;
  5599. begin
  5600. objdef:=self;
  5601. while assigned(objdef) do
  5602. begin
  5603. result:=objdef.find_procdef_bytype(potype_destructor);
  5604. if assigned(result) then
  5605. exit;
  5606. objdef:=objdef.childof;
  5607. end;
  5608. result:=nil;
  5609. end;
  5610. function tobjectdef.implements_any_interfaces: boolean;
  5611. begin
  5612. result := (ImplementedInterfaces.Count > 0) or
  5613. (assigned(childof) and childof.implements_any_interfaces);
  5614. end;
  5615. function tobjectdef.size : asizeint;
  5616. begin
  5617. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava] then
  5618. result:=voidpointertype.size
  5619. else
  5620. result:=tObjectSymtable(symtable).datasize;
  5621. end;
  5622. function tobjectdef.alignment:shortint;
  5623. begin
  5624. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava] then
  5625. alignment:=voidpointertype.size
  5626. else
  5627. alignment:=tObjectSymtable(symtable).recordalignment;
  5628. end;
  5629. function tobjectdef.vmtmethodoffset(index:longint):longint;
  5630. var
  5631. codeptrsize: Integer;
  5632. begin
  5633. {$ifdef i8086}
  5634. if current_settings.x86memorymodel in x86_far_code_models then
  5635. codeptrsize:=4
  5636. else
  5637. codeptrsize:=2;
  5638. {$else i8086}
  5639. codeptrsize:=sizeof(pint);
  5640. {$endif i8086}
  5641. { for offset of methods for classes, see rtl/inc/objpash.inc }
  5642. case objecttype of
  5643. odt_class:
  5644. { the +2*sizeof(pint) is size and -size }
  5645. vmtmethodoffset:=index*codeptrsize+10*sizeof(pint)+2*sizeof(pint);
  5646. odt_helper,
  5647. odt_objcclass,
  5648. odt_objcprotocol:
  5649. vmtmethodoffset:=0;
  5650. odt_interfacecom,odt_interfacecorba,odt_dispinterface:
  5651. vmtmethodoffset:=index*codeptrsize;
  5652. odt_javaclass,
  5653. odt_interfacejava:
  5654. { invalid }
  5655. vmtmethodoffset:=-1;
  5656. else
  5657. {$ifdef WITHDMT}
  5658. vmtmethodoffset:=index*codeptrsize+4*sizeof(pint);
  5659. {$else WITHDMT}
  5660. vmtmethodoffset:=index*codeptrsize+3*sizeof(pint);
  5661. {$endif WITHDMT}
  5662. end;
  5663. end;
  5664. function tobjectdef.vmt_mangledname : TSymStr;
  5665. begin
  5666. if not(oo_has_vmt in objectoptions) then
  5667. Message1(parser_n_object_has_no_vmt,objrealname^);
  5668. vmt_mangledname:=make_mangledname('VMT',owner,objname^);
  5669. end;
  5670. function tobjectdef.needs_inittable : boolean;
  5671. var
  5672. hp : tobjectdef;
  5673. begin
  5674. case objecttype of
  5675. odt_helper,
  5676. odt_class :
  5677. needs_inittable:=false;
  5678. odt_dispinterface,
  5679. odt_interfacecom:
  5680. needs_inittable:=true;
  5681. odt_interfacecorba:
  5682. begin
  5683. hp:=childof;
  5684. while assigned(hp) do
  5685. begin
  5686. if hp=interface_iunknown then
  5687. begin
  5688. needs_inittable:=true;
  5689. exit;
  5690. end;
  5691. hp:=hp.childof;
  5692. end;
  5693. needs_inittable:=false;
  5694. end;
  5695. odt_object:
  5696. needs_inittable:=
  5697. tObjectSymtable(symtable).needs_init_final or
  5698. (assigned(childof) and
  5699. childof.needs_inittable);
  5700. odt_cppclass,
  5701. odt_objcclass,
  5702. odt_objcprotocol,
  5703. odt_javaclass,
  5704. odt_interfacejava:
  5705. needs_inittable:=false;
  5706. else
  5707. internalerror(200108267);
  5708. end;
  5709. end;
  5710. function tobjectdef.needs_separate_initrtti : boolean;
  5711. begin
  5712. result:=not (objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface]);
  5713. end;
  5714. function tobjectdef.rtti_mangledname(rt: trttitype): string;
  5715. begin
  5716. if not(objecttype in [odt_objcclass,odt_objcprotocol]) then
  5717. result:=inherited rtti_mangledname(rt)
  5718. else
  5719. begin
  5720. { necessary in case of a dynamic array of nsobject, or
  5721. if an nsobject field appears in a record that needs
  5722. init/finalisation }
  5723. if rt=initrtti then
  5724. begin
  5725. result:=voidpointertype.rtti_mangledname(rt);
  5726. exit;
  5727. end;
  5728. if not(target_info.system in systems_objc_nfabi) then
  5729. begin
  5730. result:=target_asm.labelprefix;
  5731. case objecttype of
  5732. odt_objcclass:
  5733. begin
  5734. case rt of
  5735. objcclassrtti:
  5736. if not(oo_is_classhelper in objectoptions) then
  5737. result:=result+'_OBJC_CLASS_'
  5738. else
  5739. result:=result+'_OBJC_CATEGORY_';
  5740. objcmetartti:
  5741. if not(oo_is_classhelper in objectoptions) then
  5742. result:=result+'_OBJC_METACLASS_'
  5743. else
  5744. internalerror(2009111511);
  5745. else
  5746. internalerror(2009092302);
  5747. end;
  5748. end;
  5749. odt_objcprotocol:
  5750. result:=result+'_OBJC_PROTOCOL_';
  5751. end;
  5752. end
  5753. else
  5754. begin
  5755. case objecttype of
  5756. odt_objcclass:
  5757. begin
  5758. if (oo_is_classhelper in objectoptions) and
  5759. (rt<>objcclassrtti) then
  5760. internalerror(2009111512);
  5761. case rt of
  5762. objcclassrtti:
  5763. if not(oo_is_classhelper in objectoptions) then
  5764. result:='_OBJC_CLASS_$_'
  5765. else
  5766. result:='_OBJC_$_CATEGORY_';
  5767. objcmetartti:
  5768. result:='_OBJC_METACLASS_$_';
  5769. objcclassrortti:
  5770. result:=lower(target_asm.labelprefix)+'_OBJC_CLASS_RO_$_';
  5771. objcmetarortti:
  5772. result:=lower(target_asm.labelprefix)+'_OBJC_METACLASS_RO_$_';
  5773. else
  5774. internalerror(2009092303);
  5775. end;
  5776. end;
  5777. odt_objcprotocol:
  5778. begin
  5779. result:=lower(target_asm.labelprefix);
  5780. case rt of
  5781. objcclassrtti:
  5782. result:=result+'_OBJC_PROTOCOL_$_';
  5783. objcmetartti:
  5784. result:=result+'_OBJC_LABEL_PROTOCOL_$_';
  5785. else
  5786. internalerror(2009092501);
  5787. end;
  5788. end;
  5789. else
  5790. internalerror(2013113005);
  5791. end;
  5792. end;
  5793. result:=result+objextname^;
  5794. end;
  5795. end;
  5796. function tobjectdef.members_need_inittable : boolean;
  5797. begin
  5798. members_need_inittable:=tObjectSymtable(symtable).needs_init_final;
  5799. end;
  5800. function tobjectdef.is_publishable : boolean;
  5801. begin
  5802. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface];
  5803. end;
  5804. function tobjectdef.get_next_dispid: longint;
  5805. begin
  5806. inc(fcurrent_dispid);
  5807. result:=fcurrent_dispid;
  5808. end;
  5809. function tobjectdef.search_enumerator_get: tprocdef;
  5810. begin
  5811. result:=inherited;
  5812. if not assigned(result) and assigned(childof) then
  5813. result:=childof.search_enumerator_get;
  5814. end;
  5815. function tobjectdef.search_enumerator_move: tprocdef;
  5816. begin
  5817. result:=inherited;
  5818. if not assigned(result) and assigned(childof) then
  5819. result:=childof.search_enumerator_move;
  5820. end;
  5821. function tobjectdef.search_enumerator_current: tsym;
  5822. begin
  5823. result:=inherited;
  5824. if not assigned(result) and assigned(childof) then
  5825. result:=childof.search_enumerator_current;
  5826. end;
  5827. procedure tobjectdef.register_created_classref_type;
  5828. begin
  5829. if not classref_created_in_current_module then
  5830. begin
  5831. classref_created_in_current_module:=true;
  5832. current_module.wpoinfo.addcreatedobjtypeforclassref(self);
  5833. end;
  5834. end;
  5835. procedure tobjectdef.register_created_object_type;
  5836. begin
  5837. if not created_in_current_module then
  5838. begin
  5839. created_in_current_module:=true;
  5840. current_module.wpoinfo.addcreatedobjtype(self);
  5841. end;
  5842. end;
  5843. procedure tobjectdef.register_maybe_created_object_type;
  5844. begin
  5845. { if we know it has been created for sure, no need
  5846. to also record that it maybe can be created in
  5847. this module
  5848. }
  5849. if not (created_in_current_module) and
  5850. not (maybe_created_in_current_module) then
  5851. begin
  5852. maybe_created_in_current_module:=true;
  5853. current_module.wpoinfo.addmaybecreatedbyclassref(self);
  5854. end;
  5855. end;
  5856. procedure tobjectdef.register_vmt_call(index: longint);
  5857. begin
  5858. if (is_object(self) or is_class(self)) then
  5859. current_module.wpoinfo.addcalledvmtentry(self,index);
  5860. end;
  5861. procedure check_and_finish_msg(data: tobject; arg: pointer);
  5862. var
  5863. def: tdef absolute data;
  5864. pd: tprocdef absolute data;
  5865. i,
  5866. paracount: longint;
  5867. begin
  5868. if (def.typ=procdef) then
  5869. begin
  5870. { add all messages also under a dummy name to the symtable in
  5871. which the objcclass/protocol/category is declared, so they can
  5872. be called via id.<name>
  5873. }
  5874. create_class_helper_for_procdef(pd,nil);
  5875. { we have to wait until now to set the mangled name because it
  5876. depends on the (possibly external) class name, which is defined
  5877. at the very end. }
  5878. if not(po_msgstr in pd.procoptions) then
  5879. begin
  5880. CGMessagePos(pd.fileinfo,parser_e_objc_requires_msgstr);
  5881. { recover to avoid internalerror later on }
  5882. include(pd.procoptions,po_msgstr);
  5883. pd.messageinf.str:=stringdup('MissingDeclaration');
  5884. end;
  5885. { Mangled name is already set in case this is a copy of
  5886. another type. }
  5887. if not(po_has_mangledname in pd.procoptions) then
  5888. begin
  5889. { check whether the number of formal parameters is correct,
  5890. and whether they have valid Objective-C types }
  5891. paracount:=0;
  5892. for i:=1 to length(pd.messageinf.str^) do
  5893. if pd.messageinf.str^[i]=':' then
  5894. inc(paracount);
  5895. for i:=0 to pd.paras.count-1 do
  5896. if not(vo_is_hidden_para in tparavarsym(pd.paras[i]).varoptions) and
  5897. not is_array_of_const(tparavarsym(pd.paras[i]).vardef) then
  5898. dec(paracount);
  5899. if (paracount<>0) then
  5900. MessagePos(pd.fileinfo,sym_e_objc_para_mismatch);
  5901. pd.setmangledname(pd.objcmangledname);
  5902. end
  5903. else
  5904. { all checks already done }
  5905. exit;
  5906. if not(oo_is_external in pd.struct.objectoptions) then
  5907. begin
  5908. if (po_varargs in pd.procoptions) then
  5909. MessagePos(pd.fileinfo,parser_e_varargs_need_cdecl_and_external)
  5910. else
  5911. begin
  5912. { check for "array of const" parameters }
  5913. for i:=0 to pd.parast.symlist.count-1 do
  5914. begin
  5915. if (tsym(pd.parast.symlist[i]).typ=paravarsym) and
  5916. is_array_of_const(tparavarsym(pd.parast.symlist[i]).vardef) then
  5917. MessagePos(pd.fileinfo,parser_e_varargs_need_cdecl_and_external);
  5918. end;
  5919. end;
  5920. end;
  5921. end;
  5922. end;
  5923. procedure mark_private_fields_used(data: tobject; arg: pointer);
  5924. var
  5925. sym: tsym absolute data;
  5926. begin
  5927. if (sym.typ=fieldvarsym) and
  5928. (tfieldvarsym(sym).visibility in [vis_private,vis_strictprivate]) then
  5929. sym.IncRefCount;
  5930. end;
  5931. procedure tobjectdef.finish_objc_data;
  5932. begin
  5933. self.symtable.DefList.foreachcall(@check_and_finish_msg,nil);
  5934. if (oo_is_external in objectoptions) then
  5935. self.symtable.SymList.ForEachCall(@mark_private_fields_used,nil);
  5936. end;
  5937. procedure verify_objc_vardef(data: tobject; arg: pointer);
  5938. var
  5939. sym: tabstractvarsym absolute data;
  5940. res: pboolean absolute arg;
  5941. founderrordef: tdef;
  5942. begin
  5943. if not(tsym(data).typ in [paravarsym,fieldvarsym]) then
  5944. exit;
  5945. if (sym.typ=paravarsym) and
  5946. ((vo_is_hidden_para in tparavarsym(sym).varoptions) or
  5947. is_array_of_const(tparavarsym(sym).vardef)) then
  5948. exit;
  5949. if not objcchecktype(sym.vardef,founderrordef) then
  5950. begin
  5951. MessagePos1(sym.fileinfo,type_e_objc_type_unsupported,founderrordef.typename);
  5952. res^:=false;
  5953. end;
  5954. end;
  5955. procedure verify_objc_procdef_paras(data: tobject; arg: pointer);
  5956. var
  5957. def: tdef absolute data;
  5958. res: pboolean absolute arg;
  5959. founderrordef: tdef;
  5960. begin
  5961. if (def.typ<>procdef) then
  5962. exit;
  5963. { check parameter types for validity }
  5964. tprocdef(def).paras.foreachcall(@verify_objc_vardef,arg);
  5965. { check the result type for validity }
  5966. if not objcchecktype(tprocdef(def).returndef,founderrordef) then
  5967. begin
  5968. MessagePos1(tprocdef(def).funcretsym.fileinfo,type_e_objc_type_unsupported,founderrordef.typename);
  5969. res^:=false;
  5970. end;
  5971. end;
  5972. function tobjectdef.check_objc_types: boolean;
  5973. begin
  5974. { done in separate step from finish_objc_data, because when
  5975. finish_objc_data is called, not all forwarddefs have been resolved
  5976. yet and we need to know all types here }
  5977. result:=true;
  5978. self.symtable.symlist.foreachcall(@verify_objc_vardef,@result);
  5979. self.symtable.deflist.foreachcall(@verify_objc_procdef_paras,@result);
  5980. end;
  5981. procedure do_cpp_import_info(data: tobject; arg: pointer);
  5982. var
  5983. def: tdef absolute data;
  5984. pd: tprocdef absolute data;
  5985. begin
  5986. if (def.typ=procdef) then
  5987. begin
  5988. pd.setmangledname(target_info.Cprefix+pd.cplusplusmangledname);
  5989. if (oo_is_external in pd.struct.objectoptions) then
  5990. begin
  5991. { copied from psub.read_proc }
  5992. if assigned(tobjectdef(pd.struct).import_lib) then
  5993. current_module.AddExternalImport(tobjectdef(pd.struct).import_lib^,pd.mangledname,pd.mangledname,0,false,false)
  5994. else
  5995. begin
  5996. { add import name to external list for DLL scanning }
  5997. if tf_has_dllscanner in target_info.flags then
  5998. current_module.dllscannerinputlist.Add(pd.mangledname,pd);
  5999. end;
  6000. end;
  6001. end;
  6002. end;
  6003. procedure tobjectdef.finish_cpp_data;
  6004. begin
  6005. self.symtable.DefList.ForEachCall(@do_cpp_import_info,nil);
  6006. end;
  6007. {****************************************************************************
  6008. TImplementedInterface
  6009. ****************************************************************************}
  6010. function TImplementedInterface.GetIOffset: longint;
  6011. begin
  6012. if (fIOffset=-1) and
  6013. (IType in [etFieldValue,etFieldValueClass]) then
  6014. result:=tfieldvarsym(ImplementsField).fieldoffset
  6015. else
  6016. result:=fIOffset;
  6017. end;
  6018. constructor TImplementedInterface.create(aintf: tobjectdef);
  6019. begin
  6020. inherited create;
  6021. intfdef:=aintf;
  6022. IOffset:=-1;
  6023. IType:=etStandard;
  6024. NameMappings:=nil;
  6025. procdefs:=nil;
  6026. end;
  6027. constructor TImplementedInterface.create_deref(intfd,getterd:tderef);
  6028. begin
  6029. inherited create;
  6030. intfdef:=nil;
  6031. intfdefderef:=intfd;
  6032. ImplementsGetterDeref:=getterd;
  6033. IOffset:=-1;
  6034. IType:=etStandard;
  6035. NameMappings:=nil;
  6036. procdefs:=nil;
  6037. end;
  6038. destructor TImplementedInterface.destroy;
  6039. var
  6040. i : longint;
  6041. mappedname : pshortstring;
  6042. begin
  6043. if assigned(NameMappings) then
  6044. begin
  6045. for i:=0 to NameMappings.Count-1 do
  6046. begin
  6047. mappedname:=pshortstring(NameMappings[i]);
  6048. stringdispose(mappedname);
  6049. end;
  6050. NameMappings.free;
  6051. NameMappings:=nil;
  6052. end;
  6053. if assigned(procdefs) then
  6054. begin
  6055. procdefs.free;
  6056. procdefs:=nil;
  6057. end;
  6058. inherited destroy;
  6059. end;
  6060. procedure TImplementedInterface.buildderef;
  6061. begin
  6062. intfdefderef.build(intfdef);
  6063. ImplementsGetterDeref.build(ImplementsGetter);
  6064. end;
  6065. procedure TImplementedInterface.deref;
  6066. begin
  6067. intfdef:=tobjectdef(intfdefderef.resolve);
  6068. ImplementsGetter:=tsym(ImplementsGetterDeref.resolve);
  6069. end;
  6070. procedure TImplementedInterface.AddMapping(const origname,newname: string);
  6071. begin
  6072. if not assigned(NameMappings) then
  6073. NameMappings:=TFPHashList.Create;
  6074. NameMappings.Add(origname,stringdup(newname));
  6075. end;
  6076. function TImplementedInterface.GetMapping(const origname: string):string;
  6077. var
  6078. mappedname : pshortstring;
  6079. begin
  6080. result:='';
  6081. if not assigned(NameMappings) then
  6082. exit;
  6083. mappedname:=PShortstring(NameMappings.Find(origname));
  6084. if assigned(mappedname) then
  6085. result:=mappedname^;
  6086. end;
  6087. procedure TImplementedInterface.AddImplProc(pd:tprocdef);
  6088. begin
  6089. if not assigned(procdefs) then
  6090. procdefs:=TFPObjectList.Create(false);
  6091. { duplicate entries must be stored, because multiple }
  6092. { interfaces can declare methods with the same name }
  6093. { and all of these get their own VMT entry }
  6094. procdefs.Add(pd);
  6095. end;
  6096. function TImplementedInterface.IsImplMergePossible(MergingIntf:TImplementedInterface;out weight: longint): boolean;
  6097. var
  6098. i : longint;
  6099. begin
  6100. result:=false;
  6101. { interfaces being implemented through delegation are not mergable (FK) }
  6102. if (IType<>etStandard) or (MergingIntf.IType<>etStandard) or not(assigned(ProcDefs)) or not(assigned(MergingIntf.ProcDefs)) then
  6103. exit;
  6104. weight:=0;
  6105. { empty interface is mergeable }
  6106. if ProcDefs.Count=0 then
  6107. begin
  6108. result:=true;
  6109. exit;
  6110. end;
  6111. { The interface to merge must at least the number of
  6112. procedures of this interface }
  6113. if MergingIntf.ProcDefs.Count<ProcDefs.Count then
  6114. exit;
  6115. for i:=0 to ProcDefs.Count-1 do
  6116. begin
  6117. if MergingIntf.ProcDefs[i]<>ProcDefs[i] then
  6118. exit;
  6119. end;
  6120. weight:=ProcDefs.Count;
  6121. result:=true;
  6122. end;
  6123. function TImplementedInterface.getcopy:TImplementedInterface;
  6124. begin
  6125. Result:=TImplementedInterface.Create(nil);
  6126. { 1) the procdefs list will be freed once for each copy
  6127. 2) since the procdefs list owns its elements, those will also be freed for each copy
  6128. 3) idem for the name mappings
  6129. }
  6130. { warning: this is completely wrong on so many levels...
  6131. Move(pointer(self)^,pointer(result)^,InstanceSize);
  6132. We need to make clean copies of the different fields
  6133. this is not implemented yet, and thus we generate an internal
  6134. error instead PM 2011-06-14 }
  6135. internalerror(2011061401);
  6136. end;
  6137. {****************************************************************************
  6138. TFORWARDDEF
  6139. ****************************************************************************}
  6140. constructor tforwarddef.create(const s:string;const pos:tfileposinfo);
  6141. begin
  6142. inherited create(forwarddef);
  6143. tosymname:=stringdup(s);
  6144. forwardpos:=pos;
  6145. end;
  6146. function tforwarddef.GetTypeName:string;
  6147. begin
  6148. GetTypeName:='unresolved forward to '+tosymname^;
  6149. end;
  6150. destructor tforwarddef.destroy;
  6151. begin
  6152. stringdispose(tosymname);
  6153. inherited destroy;
  6154. end;
  6155. function tforwarddef.getcopy:tstoreddef;
  6156. begin
  6157. result:=cforwarddef.create(tosymname^, forwardpos);
  6158. end;
  6159. {****************************************************************************
  6160. TUNDEFINEDDEF
  6161. ****************************************************************************}
  6162. constructor tundefineddef.create;
  6163. begin
  6164. inherited create(undefineddef);
  6165. end;
  6166. constructor tundefineddef.ppuload(ppufile:tcompilerppufile);
  6167. begin
  6168. inherited ppuload(undefineddef,ppufile);
  6169. ppuload_platform(ppufile);
  6170. end;
  6171. function tundefineddef.GetTypeName:string;
  6172. begin
  6173. GetTypeName:='<undefined type>';
  6174. end;
  6175. procedure tundefineddef.ppuwrite(ppufile:tcompilerppufile);
  6176. begin
  6177. inherited ppuwrite(ppufile);
  6178. writeentry(ppufile,ibundefineddef);
  6179. end;
  6180. {****************************************************************************
  6181. TERRORDEF
  6182. ****************************************************************************}
  6183. constructor terrordef.create;
  6184. begin
  6185. inherited create(errordef);
  6186. { prevent consecutive faults }
  6187. savesize:=1;
  6188. end;
  6189. procedure terrordef.ppuwrite(ppufile:tcompilerppufile);
  6190. begin
  6191. { Can't write errordefs to ppu }
  6192. internalerror(200411063);
  6193. end;
  6194. function terrordef.GetTypeName:string;
  6195. begin
  6196. GetTypeName:='<erroneous type>';
  6197. end;
  6198. function terrordef.getmangledparaname:TSymStr;
  6199. begin
  6200. getmangledparaname:='error';
  6201. end;
  6202. {****************************************************************************
  6203. Definition Helpers
  6204. ****************************************************************************}
  6205. function is_interfacecom(def: tdef): boolean;
  6206. begin
  6207. is_interfacecom:=
  6208. assigned(def) and
  6209. (def.typ=objectdef) and
  6210. (tobjectdef(def).objecttype=odt_interfacecom);
  6211. end;
  6212. function is_interfacecom_or_dispinterface(def: tdef): boolean;
  6213. begin
  6214. is_interfacecom_or_dispinterface:=
  6215. assigned(def) and
  6216. (def.typ=objectdef) and
  6217. (tobjectdef(def).objecttype in [odt_interfacecom,odt_dispinterface]);
  6218. end;
  6219. function is_any_interface_kind(def: tdef): boolean;
  6220. begin
  6221. result:=
  6222. assigned(def) and
  6223. (def.typ=objectdef) and
  6224. ((tobjectdef(def).objecttype in [odt_interfacecom,odt_dispinterface,odt_interfacecorba,odt_interfacejava,odt_objcprotocol]) or
  6225. is_objccategory(def));
  6226. end;
  6227. function is_interfacecorba(def: tdef): boolean;
  6228. begin
  6229. is_interfacecorba:=
  6230. assigned(def) and
  6231. (def.typ=objectdef) and
  6232. (tobjectdef(def).objecttype=odt_interfacecorba);
  6233. end;
  6234. function is_interface(def: tdef): boolean;
  6235. begin
  6236. is_interface:=
  6237. assigned(def) and
  6238. (def.typ=objectdef) and
  6239. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  6240. end;
  6241. function is_dispinterface(def: tdef): boolean;
  6242. begin
  6243. result:=
  6244. assigned(def) and
  6245. (def.typ=objectdef) and
  6246. (tobjectdef(def).objecttype=odt_dispinterface);
  6247. end;
  6248. function is_class(def: tdef): boolean;
  6249. begin
  6250. is_class:=
  6251. assigned(def) and
  6252. (def.typ=objectdef) and
  6253. (tobjectdef(def).objecttype=odt_class);
  6254. end;
  6255. function is_object(def: tdef): boolean;
  6256. begin
  6257. is_object:=
  6258. assigned(def) and
  6259. (def.typ=objectdef) and
  6260. (tobjectdef(def).objecttype=odt_object);
  6261. end;
  6262. function is_cppclass(def: tdef): boolean;
  6263. begin
  6264. is_cppclass:=
  6265. assigned(def) and
  6266. (def.typ=objectdef) and
  6267. (tobjectdef(def).objecttype=odt_cppclass);
  6268. end;
  6269. function is_objcclass(def: tdef): boolean;
  6270. begin
  6271. is_objcclass:=
  6272. assigned(def) and
  6273. (def.typ=objectdef) and
  6274. (tobjectdef(def).objecttype=odt_objcclass);
  6275. end;
  6276. function is_objectpascal_helper(def: tdef): boolean;
  6277. begin
  6278. result:=
  6279. assigned(def) and
  6280. (def.typ=objectdef) and
  6281. (tobjectdef(def).objecttype=odt_helper);
  6282. end;
  6283. function is_objcclassref(def: tdef): boolean;
  6284. begin
  6285. is_objcclassref:=
  6286. assigned(def) and
  6287. (def.typ=classrefdef) and
  6288. is_objcclass(tclassrefdef(def).pointeddef);
  6289. end;
  6290. function is_objcprotocol(def: tdef): boolean;
  6291. begin
  6292. result:=
  6293. assigned(def) and
  6294. (def.typ=objectdef) and
  6295. (tobjectdef(def).objecttype=odt_objcprotocol);
  6296. end;
  6297. function is_objccategory(def: tdef): boolean;
  6298. begin
  6299. result:=
  6300. assigned(def) and
  6301. (def.typ=objectdef) and
  6302. { if used as a forward type }
  6303. ((tobjectdef(def).objecttype=odt_objccategory) or
  6304. { if used as after it has been resolved }
  6305. ((tobjectdef(def).objecttype=odt_objcclass) and
  6306. (oo_is_classhelper in tobjectdef(def).objectoptions)));
  6307. end;
  6308. function is_objc_class_or_protocol(def: tdef): boolean;
  6309. begin
  6310. result:=
  6311. assigned(def) and
  6312. (def.typ=objectdef) and
  6313. (tobjectdef(def).objecttype in [odt_objcclass,odt_objcprotocol]);
  6314. end;
  6315. function is_objc_protocol_or_category(def: tdef): boolean;
  6316. begin
  6317. result:=
  6318. assigned(def) and
  6319. (def.typ=objectdef) and
  6320. ((tobjectdef(def).objecttype = odt_objcprotocol) or
  6321. ((tobjectdef(def).objecttype = odt_objcclass) and
  6322. (oo_is_classhelper in tobjectdef(def).objectoptions)));
  6323. end;
  6324. function is_classhelper(def: tdef): boolean;
  6325. begin
  6326. result:=
  6327. is_objectpascal_helper(def) or
  6328. is_objccategory(def);
  6329. end;
  6330. function is_class_or_interface(def: tdef): boolean;
  6331. begin
  6332. result:=
  6333. assigned(def) and
  6334. (def.typ=objectdef) and
  6335. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  6336. end;
  6337. function is_class_or_interface_or_objc(def: tdef): boolean;
  6338. begin
  6339. result:=
  6340. assigned(def) and
  6341. (def.typ=objectdef) and
  6342. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_objcclass,odt_objcprotocol]);
  6343. end;
  6344. function is_class_or_interface_or_objc_or_java(def: tdef): boolean;
  6345. begin
  6346. result:=
  6347. assigned(def) and
  6348. (def.typ=objectdef) and
  6349. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava]);
  6350. end;
  6351. function is_class_or_interface_or_dispinterface_or_objc_or_java(def: tdef): boolean;
  6352. begin
  6353. result:=
  6354. assigned(def) and
  6355. (def.typ=objectdef) and
  6356. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava]);
  6357. end;
  6358. function is_class_or_interface_or_object(def: tdef): boolean;
  6359. begin
  6360. result:=
  6361. assigned(def) and
  6362. (def.typ=objectdef) and
  6363. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_object]);
  6364. end;
  6365. function is_class_or_interface_or_dispinterface(def: tdef): boolean;
  6366. begin
  6367. result:=
  6368. assigned(def) and
  6369. (def.typ=objectdef) and
  6370. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface]);
  6371. end;
  6372. function is_implicit_pointer_object_type(def: tdef): boolean;
  6373. begin
  6374. result:=
  6375. assigned(def) and
  6376. (((def.typ=objectdef) and
  6377. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava])) or
  6378. ((target_info.system in systems_jvm) and
  6379. (def.typ=recorddef)));
  6380. end;
  6381. function is_implicit_array_pointer(def: tdef): boolean;
  6382. begin
  6383. result:=is_dynamic_array(def) or is_dynamicstring(def);
  6384. end;
  6385. function is_class_or_object(def: tdef): boolean;
  6386. begin
  6387. result:=
  6388. assigned(def) and
  6389. (def.typ=objectdef) and
  6390. (tobjectdef(def).objecttype in [odt_class,odt_object]);
  6391. end;
  6392. function is_record(def: tdef): boolean;
  6393. begin
  6394. result:=
  6395. assigned(def) and
  6396. (def.typ=recorddef);
  6397. end;
  6398. function is_javaclass(def: tdef): boolean;
  6399. begin
  6400. result:=
  6401. assigned(def) and
  6402. (def.typ=objectdef) and
  6403. (tobjectdef(def).objecttype=odt_javaclass);
  6404. end;
  6405. function is_javaclassref(def: tdef): boolean;
  6406. begin
  6407. is_javaclassref:=
  6408. assigned(def) and
  6409. (def.typ=classrefdef) and
  6410. is_javaclass(tclassrefdef(def).pointeddef);
  6411. end;
  6412. function is_javainterface(def: tdef): boolean;
  6413. begin
  6414. result:=
  6415. assigned(def) and
  6416. (def.typ=objectdef) and
  6417. (tobjectdef(def).objecttype=odt_interfacejava);
  6418. end;
  6419. function is_java_class_or_interface(def: tdef): boolean;
  6420. begin
  6421. result:=
  6422. assigned(def) and
  6423. (def.typ=objectdef) and
  6424. (tobjectdef(def).objecttype in [odt_javaclass,odt_interfacejava]);
  6425. end;
  6426. procedure loadobjctypes;
  6427. begin
  6428. objc_metaclasstype:=tpointerdef(search_named_unit_globaltype('OBJC','POBJC_CLASS',true).typedef);
  6429. objc_superclasstype:=tpointerdef(search_named_unit_globaltype('OBJC','POBJC_SUPER',true).typedef);
  6430. objc_idtype:=tpointerdef(search_named_unit_globaltype('OBJC','ID',true).typedef);
  6431. objc_seltype:=tpointerdef(search_named_unit_globaltype('OBJC','SEL',true).typedef);
  6432. objc_objecttype:=trecorddef(search_named_unit_globaltype('OBJC','OBJC_OBJECT',true).typedef);
  6433. end;
  6434. procedure maybeloadcocoatypes;
  6435. var
  6436. tsym: ttypesym;
  6437. cocoaunit: string[15];
  6438. begin
  6439. if assigned(objc_fastenumeration) then
  6440. exit;
  6441. if not(target_info.system in [system_arm_darwin,system_i386_iphonesim]) then
  6442. cocoaunit:='COCOAALL'
  6443. else
  6444. cocoaunit:='IPHONEALL';
  6445. tsym:=search_named_unit_globaltype(cocoaunit,'NSFASTENUMERATIONPROTOCOL',false);
  6446. if assigned(tsym) then
  6447. objc_fastenumeration:=tobjectdef(tsym.typedef)
  6448. else
  6449. objc_fastenumeration:=nil;
  6450. tsym:=search_named_unit_globaltype(cocoaunit,'NSFASTENUMERATIONSTATE',false);
  6451. if assigned(tsym) then
  6452. objc_fastenumerationstate:=trecorddef(tsym.typedef)
  6453. else
  6454. objc_fastenumerationstate:=nil;
  6455. end;
  6456. function use_vectorfpu(def : tdef) : boolean;
  6457. begin
  6458. {$ifdef x86}
  6459. {$define use_vectorfpuimplemented}
  6460. use_vectorfpu:=(is_single(def) and (current_settings.fputype in sse_singlescalar)) or
  6461. (is_double(def) and (current_settings.fputype in sse_doublescalar));
  6462. {$endif x86}
  6463. {$ifdef arm}
  6464. {$define use_vectorfpuimplemented}
  6465. use_vectorfpu:=(current_settings.fputype in vfp_scalar);
  6466. {$endif arm}
  6467. {$ifndef use_vectorfpuimplemented}
  6468. use_vectorfpu:=false;
  6469. {$endif}
  6470. end;
  6471. function getpointerdef(def: tdef): tpointerdef;
  6472. var
  6473. res: PHashSetItem;
  6474. oldsymtablestack: tsymtablestack;
  6475. begin
  6476. if not assigned(current_module) then
  6477. internalerror(2011071101);
  6478. res:=current_module.ptrdefs.FindOrAdd(@def,sizeof(def));
  6479. if not assigned(res^.Data) then
  6480. begin
  6481. { since these pointerdefs can be reused anywhere in the current
  6482. unit, add them to the global/staticsymtable }
  6483. oldsymtablestack:=symtablestack;
  6484. { do not simply push/pop current_module.localsymtable, because
  6485. that can have side-effects (e.g., it removes helpers) }
  6486. symtablestack:=nil;
  6487. res^.Data:=cpointerdef.create(def);
  6488. if assigned(current_module.localsymtable) then
  6489. current_module.localsymtable.insertdef(tdef(res^.Data))
  6490. else
  6491. current_module.globalsymtable.insertdef(tdef(res^.Data));
  6492. symtablestack:=oldsymtablestack;
  6493. end;
  6494. result:=tpointerdef(res^.Data);
  6495. end;
  6496. function getsingletonarraydef(def: tdef): tarraydef;
  6497. begin
  6498. result:=getarraydef(def,1);
  6499. end;
  6500. function getarraydef(def: tdef; elecount: asizeint): tarraydef;
  6501. var
  6502. res: PHashSetItem;
  6503. oldsymtablestack: tsymtablestack;
  6504. arrdesc: packed record
  6505. def: tdef;
  6506. elecount: asizeint;
  6507. end;
  6508. begin
  6509. if not assigned(current_module) then
  6510. internalerror(2011081301);
  6511. arrdesc.def:=def;
  6512. arrdesc.elecount:=elecount;
  6513. res:=current_module.arraydefs.FindOrAdd(@arrdesc,sizeof(arrdesc));
  6514. if not assigned(res^.Data) then
  6515. begin
  6516. { since these arraydef can be reused anywhere in the current
  6517. unit, add them to the global/staticsymtable }
  6518. oldsymtablestack:=symtablestack;
  6519. symtablestack:=nil;
  6520. res^.Data:=carraydef.create(0,elecount-1,ptrsinttype);
  6521. tarraydef(res^.Data).elementdef:=def;
  6522. if assigned(current_module.localsymtable) then
  6523. current_module.localsymtable.insertdef(tdef(res^.Data))
  6524. else
  6525. current_module.globalsymtable.insertdef(tdef(res^.Data));
  6526. symtablestack:=oldsymtablestack;
  6527. end;
  6528. result:=tarraydef(res^.Data);
  6529. end;
  6530. end.