symdef.pas 243 KB

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