symdef.pas 238 KB

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