symdef.pas 189 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023
  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,aasmdata,
  33. cpubase,cpuinfo,
  34. cgbase,cgutils,
  35. parabase
  36. ;
  37. type
  38. {************************************************
  39. TDef
  40. ************************************************}
  41. { tstoreddef }
  42. tstoreddef = class(tdef)
  43. protected
  44. typesymderef : tderef;
  45. public
  46. {$ifdef EXTDEBUG}
  47. fileinfo : tfileposinfo;
  48. {$endif}
  49. { generic support }
  50. genericdef : tstoreddef;
  51. genericdefderef : tderef;
  52. generictokenbuf : tdynamicarray;
  53. constructor create(dt:tdeftyp);
  54. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  55. destructor destroy;override;
  56. function getcopy : tstoreddef;virtual;
  57. procedure ppuwrite(ppufile:tcompilerppufile);virtual;
  58. procedure buildderef;override;
  59. procedure buildderefimpl;override;
  60. procedure deref;override;
  61. procedure derefimpl;override;
  62. function size:asizeint;override;
  63. function getvardef:longint;override;
  64. function alignment:shortint;override;
  65. function is_publishable : boolean;override;
  66. function needs_inittable : boolean;override;
  67. function rtti_mangledname(rt:trttitype):string;override;
  68. function OwnerHierarchyName: string; override;
  69. function in_currentunit: boolean;
  70. { regvars }
  71. function is_intregable : boolean;
  72. function is_fpuregable : boolean;
  73. { generics }
  74. procedure initgeneric;
  75. private
  76. savesize : asizeuint;
  77. end;
  78. tfiletyp = (ft_text,ft_typed,ft_untyped);
  79. tfiledef = class(tstoreddef)
  80. filetyp : tfiletyp;
  81. typedfiledef : tdef;
  82. typedfiledefderef : tderef;
  83. constructor createtext;
  84. constructor createuntyped;
  85. constructor createtyped(def : tdef);
  86. constructor ppuload(ppufile:tcompilerppufile);
  87. function getcopy : tstoreddef;override;
  88. procedure ppuwrite(ppufile:tcompilerppufile);override;
  89. procedure buildderef;override;
  90. procedure deref;override;
  91. function GetTypeName:string;override;
  92. function getmangledparaname:string;override;
  93. procedure setsize;
  94. end;
  95. tvariantdef = class(tstoreddef)
  96. varianttype : tvarianttype;
  97. constructor create(v : tvarianttype);
  98. constructor ppuload(ppufile:tcompilerppufile);
  99. function getcopy : tstoreddef;override;
  100. function GetTypeName:string;override;
  101. procedure ppuwrite(ppufile:tcompilerppufile);override;
  102. function getvardef:longint;override;
  103. procedure setsize;
  104. function is_publishable : boolean;override;
  105. function needs_inittable : boolean;override;
  106. end;
  107. tformaldef = class(tstoreddef)
  108. typed:boolean;
  109. constructor create(Atyped:boolean);
  110. constructor ppuload(ppufile:tcompilerppufile);
  111. procedure ppuwrite(ppufile:tcompilerppufile);override;
  112. function GetTypeName:string;override;
  113. end;
  114. tforwarddef = class(tstoreddef)
  115. tosymname : pshortstring;
  116. forwardpos : tfileposinfo;
  117. constructor create(const s:string;const pos:tfileposinfo);
  118. destructor destroy;override;
  119. function getcopy:tstoreddef;override;
  120. function GetTypeName:string;override;
  121. end;
  122. tundefineddef = class(tstoreddef)
  123. constructor create;
  124. constructor ppuload(ppufile:tcompilerppufile);
  125. procedure ppuwrite(ppufile:tcompilerppufile);override;
  126. function GetTypeName:string;override;
  127. end;
  128. terrordef = class(tstoreddef)
  129. constructor create;
  130. procedure ppuwrite(ppufile:tcompilerppufile);override;
  131. function GetTypeName:string;override;
  132. function getmangledparaname : string;override;
  133. end;
  134. tabstractpointerdef = class(tstoreddef)
  135. pointeddef : tdef;
  136. pointeddefderef : tderef;
  137. constructor create(dt:tdeftyp;def:tdef);
  138. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  139. procedure ppuwrite(ppufile:tcompilerppufile);override;
  140. procedure buildderef;override;
  141. procedure deref;override;
  142. end;
  143. tpointerdef = class(tabstractpointerdef)
  144. is_far : boolean;
  145. has_pointer_math : boolean;
  146. constructor create(def:tdef);
  147. constructor createfar(def:tdef);
  148. function getcopy:tstoreddef;override;
  149. constructor ppuload(ppufile:tcompilerppufile);
  150. procedure ppuwrite(ppufile:tcompilerppufile);override;
  151. function GetTypeName:string;override;
  152. end;
  153. tprocdef = class;
  154. { tabstractrecorddef }
  155. tabstractrecorddef= class(tstoreddef)
  156. objname,
  157. objrealname : PShortString;
  158. symtable : TSymtable;
  159. cloneddef : tabstractrecorddef;
  160. cloneddefderef : tderef;
  161. objectoptions : tobjectoptions;
  162. constructor create(const n:string; dt:tdeftyp);
  163. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  164. procedure ppuwrite(ppufile:tcompilerppufile);override;
  165. destructor destroy; override;
  166. procedure check_forwards; virtual;
  167. function find_procdef_bytype(pt:tproctypeoption): tprocdef;
  168. function GetSymtable(t:tGetSymtable):TSymtable;override;
  169. function is_packed:boolean;
  170. function RttiName: string;
  171. { enumerator support }
  172. function search_enumerator_get: tprocdef; virtual;
  173. function search_enumerator_move: tprocdef; virtual;
  174. function search_enumerator_current: tsym; virtual;
  175. end;
  176. trecorddef = class(tabstractrecorddef)
  177. public
  178. isunion : boolean;
  179. constructor create(const n:string; p:TSymtable);
  180. constructor ppuload(ppufile:tcompilerppufile);
  181. destructor destroy;override;
  182. function getcopy : tstoreddef;override;
  183. procedure ppuwrite(ppufile:tcompilerppufile);override;
  184. procedure buildderef;override;
  185. procedure deref;override;
  186. function size:asizeint;override;
  187. function alignment : shortint;override;
  188. function padalignment: shortint;
  189. function GetTypeName:string;override;
  190. { debug }
  191. function needs_inittable : boolean;override;
  192. end;
  193. tobjectdef = class;
  194. { TImplementedInterface }
  195. TImplementedInterface = class
  196. IntfDef : tobjectdef;
  197. IntfDefDeref : tderef;
  198. IType : tinterfaceentrytype;
  199. IOffset : longint;
  200. VtblImplIntf : TImplementedInterface;
  201. NameMappings : TFPHashList;
  202. ProcDefs : TFPObjectList;
  203. ImplementsGetter : tsym;
  204. constructor create(aintf: tobjectdef);
  205. constructor create_deref(d:tderef);
  206. destructor destroy; override;
  207. function getcopy:TImplementedInterface;
  208. procedure buildderef;
  209. procedure deref;
  210. procedure AddMapping(const origname, newname: string);
  211. function GetMapping(const origname: string):string;
  212. procedure AddImplProc(pd:tprocdef);
  213. function IsImplMergePossible(MergingIntf:TImplementedInterface;out weight: longint): boolean;
  214. end;
  215. { tvmtentry }
  216. tvmtentry = record
  217. procdef : tprocdef;
  218. procdefderef : tderef;
  219. visibility : tvisibility;
  220. end;
  221. pvmtentry = ^tvmtentry;
  222. { tobjectdef }
  223. tvmcallstatic = (vmcs_default, vmcs_yes, vmcs_no, vmcs_unreachable);
  224. pmvcallstaticinfo = ^tmvcallstaticinfo;
  225. tmvcallstaticinfo = array[0..1024*1024-1] of tvmcallstatic;
  226. tobjectdef = class(tabstractrecorddef)
  227. private
  228. fcurrent_dispid: longint;
  229. public
  230. dwarf_struct_lab : tasmsymbol;
  231. childof : tobjectdef;
  232. childofderef : tderef;
  233. { for Object Pascal helpers }
  234. extendeddef : tabstractrecorddef;
  235. extendeddefderef: tderef;
  236. { for C++ classes: name of the library this class is imported from }
  237. import_lib,
  238. { for Objective-C: protocols and classes can have the same name there }
  239. objextname : pshortstring;
  240. { to be able to have a variable vmt position }
  241. { and no vmt field for objects without virtuals }
  242. vmtentries : TFPList;
  243. vmcallstaticinfo : pmvcallstaticinfo;
  244. vmt_offset : longint;
  245. iidguid : pguid;
  246. iidstr : pshortstring;
  247. { store implemented interfaces defs and name mappings }
  248. ImplementedInterfaces : TFPObjectList;
  249. writing_class_record_dbginfo,
  250. { a class of this type has been created in this module }
  251. created_in_current_module,
  252. { a loadvmtnode for this class has been created in this
  253. module, so if a classrefdef variable of this or a parent
  254. class is used somewhere to instantiate a class, then this
  255. class may be instantiated
  256. }
  257. maybe_created_in_current_module,
  258. { a "class of" this particular class has been created in
  259. this module
  260. }
  261. classref_created_in_current_module : boolean;
  262. objecttype : tobjecttyp;
  263. constructor create(ot:tobjecttyp;const n:string;c:tobjectdef);
  264. constructor ppuload(ppufile:tcompilerppufile);
  265. destructor destroy;override;
  266. function getcopy : tstoreddef;override;
  267. procedure ppuwrite(ppufile:tcompilerppufile);override;
  268. function GetTypeName:string;override;
  269. procedure buildderef;override;
  270. procedure deref;override;
  271. procedure buildderefimpl;override;
  272. procedure derefimpl;override;
  273. procedure resetvmtentries;
  274. procedure copyvmtentries(objdef:tobjectdef);
  275. function getparentdef:tdef;override;
  276. function size : asizeint;override;
  277. function alignment:shortint;override;
  278. function vmtmethodoffset(index:longint):longint;
  279. function members_need_inittable : boolean;
  280. function find_implemented_interface(aintfdef:tobjectdef):TImplementedInterface;
  281. { this should be called when this class implements an interface }
  282. procedure prepareguid;
  283. function is_publishable : boolean;override;
  284. function is_related(d : tdef) : boolean;override;
  285. function needs_inittable : boolean;override;
  286. function rtti_mangledname(rt:trttitype):string;override;
  287. function vmt_mangledname : string;
  288. procedure check_forwards; override;
  289. procedure insertvmt;
  290. procedure set_parent(c : tobjectdef);
  291. function find_destructor: tprocdef;
  292. function implements_any_interfaces: boolean;
  293. { dispinterface support }
  294. function get_next_dispid: longint;
  295. { enumerator support }
  296. function search_enumerator_get: tprocdef; override;
  297. function search_enumerator_move: tprocdef; override;
  298. function search_enumerator_current: tsym; override;
  299. { WPO }
  300. procedure register_created_object_type;override;
  301. procedure register_maybe_created_object_type;
  302. procedure register_created_classref_type;
  303. procedure register_vmt_call(index:longint);
  304. { ObjC }
  305. procedure finish_objc_data;
  306. function check_objc_types: boolean;
  307. { C++ }
  308. procedure finish_cpp_data;
  309. { JVM }
  310. function jvm_full_typename: string;
  311. end;
  312. tclassrefdef = class(tabstractpointerdef)
  313. constructor create(def:tdef);
  314. constructor ppuload(ppufile:tcompilerppufile);
  315. procedure ppuwrite(ppufile:tcompilerppufile);override;
  316. function getcopy:tstoreddef;override;
  317. function GetTypeName:string;override;
  318. function is_publishable : boolean;override;
  319. function rtti_mangledname(rt:trttitype):string;override;
  320. procedure register_created_object_type;override;
  321. end;
  322. tarraydef = class(tstoreddef)
  323. lowrange,
  324. highrange : asizeint;
  325. rangedef : tdef;
  326. rangedefderef : tderef;
  327. arrayoptions : tarraydefoptions;
  328. symtable : TSymtable;
  329. protected
  330. _elementdef : tdef;
  331. _elementdefderef : tderef;
  332. procedure setelementdef(def:tdef);
  333. public
  334. function elesize : asizeint;
  335. function elepackedbitsize : asizeint;
  336. function elecount : asizeuint;
  337. constructor create_from_pointer(def:tdef);
  338. constructor create(l,h:asizeint;def:tdef);
  339. constructor ppuload(ppufile:tcompilerppufile);
  340. destructor destroy; override;
  341. function getcopy : tstoreddef;override;
  342. procedure ppuwrite(ppufile:tcompilerppufile);override;
  343. function GetTypeName:string;override;
  344. function getmangledparaname : string;override;
  345. procedure buildderef;override;
  346. procedure deref;override;
  347. function size : asizeint;override;
  348. function alignment : shortint;override;
  349. { returns the label of the range check string }
  350. function needs_inittable : boolean;override;
  351. property elementdef : tdef read _elementdef write setelementdef;
  352. function is_publishable : boolean;override;
  353. end;
  354. torddef = class(tstoreddef)
  355. low,high : TConstExprInt;
  356. ordtype : tordtype;
  357. constructor create(t : tordtype;v,b : TConstExprInt);
  358. constructor ppuload(ppufile:tcompilerppufile);
  359. function getcopy : tstoreddef;override;
  360. procedure ppuwrite(ppufile:tcompilerppufile);override;
  361. function is_publishable : boolean;override;
  362. function GetTypeName:string;override;
  363. function alignment:shortint;override;
  364. procedure setsize;
  365. function packedbitsize: asizeint; override;
  366. function getvardef : longint;override;
  367. end;
  368. tfloatdef = class(tstoreddef)
  369. floattype : tfloattype;
  370. constructor create(t : tfloattype);
  371. constructor ppuload(ppufile:tcompilerppufile);
  372. function getcopy : tstoreddef;override;
  373. procedure ppuwrite(ppufile:tcompilerppufile);override;
  374. function GetTypeName:string;override;
  375. function is_publishable : boolean;override;
  376. function alignment:shortint;override;
  377. procedure setsize;
  378. function getvardef:longint;override;
  379. end;
  380. { tabstractprocdef }
  381. tabstractprocdef = class(tstoreddef)
  382. { saves a definition to the return type }
  383. returndef : tdef;
  384. returndefderef : tderef;
  385. parast : TSymtable;
  386. paras : tparalist;
  387. proctypeoption : tproctypeoption;
  388. proccalloption : tproccalloption;
  389. procoptions : tprocoptions;
  390. callerargareasize,
  391. calleeargareasize: pint;
  392. {$ifdef m68k}
  393. exp_funcretloc : tregister; { explicit funcretloc for AmigaOS }
  394. {$endif}
  395. funcretloc : array[tcallercallee] of TCGPara;
  396. has_paraloc_info : tcallercallee; { paraloc info is available }
  397. { number of user visible parameters }
  398. maxparacount,
  399. minparacount : byte;
  400. constructor create(dt:tdeftyp;level:byte);
  401. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  402. destructor destroy;override;
  403. procedure ppuwrite(ppufile:tcompilerppufile);override;
  404. procedure buildderef;override;
  405. procedure deref;override;
  406. procedure calcparas;
  407. function typename_paras(showhidden:boolean): string;
  408. function is_methodpointer:boolean;virtual;
  409. function is_addressonly:boolean;virtual;
  410. function no_self_node:boolean;
  411. procedure check_mark_as_nested;
  412. procedure init_paraloc_info(side: tcallercallee);
  413. function stack_tainting_parameter(side: tcallercallee): boolean;
  414. private
  415. procedure count_para(p:TObject;arg:pointer);
  416. procedure insert_para(p:TObject;arg:pointer);
  417. end;
  418. tprocvardef = class(tabstractprocdef)
  419. constructor create(level:byte);
  420. constructor ppuload(ppufile:tcompilerppufile);
  421. function getcopy : tstoreddef;override;
  422. procedure ppuwrite(ppufile:tcompilerppufile);override;
  423. function GetSymtable(t:tGetSymtable):TSymtable;override;
  424. function size : asizeint;override;
  425. function GetTypeName:string;override;
  426. function is_publishable : boolean;override;
  427. function is_methodpointer:boolean;override;
  428. function is_addressonly:boolean;override;
  429. function getmangledparaname:string;override;
  430. end;
  431. tmessageinf = record
  432. case integer of
  433. 0 : (str : pshortstring);
  434. 1 : (i : longint);
  435. end;
  436. tinlininginfo = record
  437. { node tree }
  438. code : tnode;
  439. flags : tprocinfoflags;
  440. end;
  441. pinlininginfo = ^tinlininginfo;
  442. {$ifdef oldregvars}
  443. { register variables }
  444. pregvarinfo = ^tregvarinfo;
  445. tregvarinfo = record
  446. regvars : array[1..maxvarregs] of tsym;
  447. regvars_para : array[1..maxvarregs] of boolean;
  448. regvars_refs : array[1..maxvarregs] of longint;
  449. fpuregvars : array[1..maxfpuvarregs] of tsym;
  450. fpuregvars_para : array[1..maxfpuvarregs] of boolean;
  451. fpuregvars_refs : array[1..maxfpuvarregs] of longint;
  452. end;
  453. {$endif oldregvars}
  454. { tprocdef }
  455. tprocdef = class(tabstractprocdef)
  456. private
  457. _mangledname : pshortstring;
  458. public
  459. messageinf : tmessageinf;
  460. dispid : longint;
  461. {$ifndef EXTDEBUG}
  462. { where is this function defined and what were the symbol
  463. flags, needed here because there
  464. is only one symbol for all overloaded functions
  465. EXTDEBUG has fileinfo in tdef (PFV) }
  466. fileinfo : tfileposinfo;
  467. {$endif}
  468. symoptions : tsymoptions;
  469. deprecatedmsg : pshortstring;
  470. { symbol owning this definition }
  471. procsym : tsym;
  472. procsymderef : tderef;
  473. { alias names }
  474. aliasnames : TCmdStrList;
  475. { symtables }
  476. localst : TSymtable;
  477. funcretsym : tsym;
  478. funcretsymderef : tderef;
  479. struct : tabstractrecorddef;
  480. structderef : tderef;
  481. {$if defined(powerpc) or defined(m68k)}
  482. { library symbol for AmigaOS/MorphOS }
  483. libsym : tsym;
  484. libsymderef : tderef;
  485. {$endif powerpc or m68k}
  486. { name of the result variable to insert in the localsymtable }
  487. resultname : pshortstring;
  488. { import info }
  489. import_dll,
  490. import_name : pshortstring;
  491. { info for inlining the subroutine, if this pointer is nil,
  492. the procedure can't be inlined }
  493. inlininginfo : pinlininginfo;
  494. {$ifdef jvm}
  495. { generated assembler code; used by JVM backend so it can afterwards
  496. easily write out all methods grouped per class }
  497. exprasmlist : TAsmList;
  498. {$endif jvm}
  499. {$ifdef oldregvars}
  500. regvarinfo: pregvarinfo;
  501. {$endif oldregvars}
  502. { interrupt vector }
  503. interruptvector : longint;
  504. { First/last assembler symbol/instruction in aasmoutput list.
  505. Note: initialised after compiling the code for the procdef, but
  506. not saved to/restored from ppu. Used when inserting debug info }
  507. procstarttai,
  508. procendtai : tai;
  509. import_nr : word;
  510. extnumber : word;
  511. {$ifdef i386}
  512. fpu_used : byte;
  513. {$endif i386}
  514. visibility : tvisibility;
  515. { true, if the procedure is only declared
  516. (forward procedure) }
  517. forwarddef,
  518. { true if the procedure is declared in the interface }
  519. interfacedef : boolean;
  520. { true if the procedure has a forward declaration }
  521. hasforward : boolean;
  522. constructor create(level:byte);
  523. constructor ppuload(ppufile:tcompilerppufile);
  524. destructor destroy;override;
  525. procedure ppuwrite(ppufile:tcompilerppufile);override;
  526. procedure buildderef;override;
  527. procedure buildderefimpl;override;
  528. procedure deref;override;
  529. procedure derefimpl;override;
  530. function GetSymtable(t:tGetSymtable):TSymtable;override;
  531. function GetTypeName : string;override;
  532. function mangledname : string;
  533. procedure setmangledname(const s : string);
  534. function fullprocname(showhidden:boolean):string;
  535. function defaultmangledname: string;
  536. function cplusplusmangledname : string;
  537. function objcmangledname : string;
  538. function jvmmangledbasename: string;
  539. function is_methodpointer:boolean;override;
  540. function is_addressonly:boolean;override;
  541. procedure make_external;
  542. end;
  543. { single linked list of overloaded procs }
  544. pprocdeflist = ^tprocdeflist;
  545. tprocdeflist = record
  546. def : tprocdef;
  547. defderef : tderef;
  548. next : pprocdeflist;
  549. end;
  550. tstringdef = class(tstoreddef)
  551. stringtype : tstringtype;
  552. len : asizeint;
  553. constructor createshort(l : byte);
  554. constructor loadshort(ppufile:tcompilerppufile);
  555. constructor createlong(l : asizeint);
  556. constructor loadlong(ppufile:tcompilerppufile);
  557. constructor createansi;
  558. constructor loadansi(ppufile:tcompilerppufile);
  559. constructor createwide;
  560. constructor loadwide(ppufile:tcompilerppufile);
  561. constructor createunicode;
  562. constructor loadunicode(ppufile:tcompilerppufile);
  563. function getcopy : tstoreddef;override;
  564. function stringtypname:string;
  565. procedure ppuwrite(ppufile:tcompilerppufile);override;
  566. function GetTypeName:string;override;
  567. function getmangledparaname:string;override;
  568. function is_publishable : boolean;override;
  569. function alignment : shortint;override;
  570. function needs_inittable : boolean;override;
  571. function getvardef:longint;override;
  572. end;
  573. { tenumdef }
  574. tenumdef = class(tstoreddef)
  575. minval,
  576. maxval : asizeint;
  577. basedef : tenumdef;
  578. basedefderef : tderef;
  579. symtable : TSymtable;
  580. has_jumps : boolean;
  581. constructor create;
  582. constructor create_subrange(_basedef:tenumdef;_min,_max:asizeint);
  583. constructor ppuload(ppufile:tcompilerppufile);
  584. destructor destroy;override;
  585. function getcopy : tstoreddef;override;
  586. procedure ppuwrite(ppufile:tcompilerppufile);override;
  587. procedure buildderef;override;
  588. procedure deref;override;
  589. function GetTypeName:string;override;
  590. function is_publishable : boolean;override;
  591. procedure calcsavesize;
  592. function packedbitsize: asizeint; override;
  593. procedure setmax(_max:asizeint);
  594. procedure setmin(_min:asizeint);
  595. function min:asizeint;
  596. function max:asizeint;
  597. function getfirstsym:tsym;
  598. end;
  599. tsetdef = class(tstoreddef)
  600. elementdef : tdef;
  601. elementdefderef : tderef;
  602. setbase,
  603. setmax : aword;
  604. constructor create(def:tdef;low, high : asizeint);
  605. constructor ppuload(ppufile:tcompilerppufile);
  606. function getcopy : tstoreddef;override;
  607. procedure ppuwrite(ppufile:tcompilerppufile);override;
  608. procedure buildderef;override;
  609. procedure deref;override;
  610. function GetTypeName:string;override;
  611. function is_publishable : boolean;override;
  612. end;
  613. tdefawaresymtablestack = class(TSymtablestack)
  614. private
  615. procedure addhelpers(st: TSymtable);
  616. procedure removehelpers(st: TSymtable);
  617. public
  618. procedure push(st: TSymtable); override;
  619. procedure pop(st: TSymtable); override;
  620. end;
  621. var
  622. current_structdef: tabstractrecorddef; { used for private functions check !! }
  623. current_genericdef: tstoreddef; { used to reject declaration of generic class inside generic class }
  624. current_specializedef: tstoreddef; { used to implement usage of generic class in itself }
  625. { default types }
  626. generrordef, { error in definition }
  627. voidpointertype, { pointer for Void-pointeddef }
  628. charpointertype, { pointer for Char-pointeddef }
  629. widecharpointertype, { pointer for WideChar-pointeddef }
  630. voidfarpointertype,
  631. cundefinedtype,
  632. cformaltype, { unique formal definition }
  633. ctypedformaltype, { unique typed formal definition }
  634. voidtype, { Void (procedure) }
  635. cchartype, { Char }
  636. cwidechartype, { WideChar }
  637. pasbool8type, { boolean type }
  638. pasbool16type,
  639. pasbool32type,
  640. pasbool64type,
  641. bool8type,
  642. bool16type,
  643. bool32type,
  644. bool64type, { implement me }
  645. u8inttype, { 8-Bit unsigned integer }
  646. s8inttype, { 8-Bit signed integer }
  647. u16inttype, { 16-Bit unsigned integer }
  648. s16inttype, { 16-Bit signed integer }
  649. u32inttype, { 32-Bit unsigned integer }
  650. s32inttype, { 32-Bit signed integer }
  651. u64inttype, { 64-bit unsigned integer }
  652. s64inttype, { 64-bit signed integer }
  653. s32floattype, { 32 bit floating point number }
  654. s64floattype, { 64 bit floating point number }
  655. s80floattype, { 80 bit floating point number }
  656. sc80floattype, { 80 bit floating point number but stored like in C }
  657. s64currencytype, { pointer to a currency type }
  658. cshortstringtype, { pointer to type of short string const }
  659. clongstringtype, { pointer to type of long string const }
  660. cansistringtype, { pointer to type of ansi string const }
  661. cwidestringtype, { pointer to type of wide string const }
  662. cunicodestringtype,
  663. openshortstringtype, { pointer to type of an open shortstring,
  664. needed for readln() }
  665. openchararraytype, { pointer to type of an open array of char,
  666. needed for readln() }
  667. cfiletype, { get the same definition for all file }
  668. { used for stabs }
  669. methodpointertype, { typecasting of methodpointers to extract self }
  670. hresultdef,
  671. { we use only one variant def for every variant class }
  672. cvarianttype,
  673. colevarianttype,
  674. { default integer type s32inttype on 32 bit systems, s64bittype on 64 bit systems }
  675. sinttype,
  676. uinttype,
  677. { unsigned and signed ord type with the same size as a pointer }
  678. ptruinttype,
  679. ptrsinttype,
  680. { several types to simulate more or less C++ objects for GDB }
  681. vmttype,
  682. vmtarraytype,
  683. pvmttype : tdef; { type of classrefs, used for stabs }
  684. { pointer to the anchestor of all classes }
  685. class_tobject : tobjectdef;
  686. { pointer to the ancestor of all COM interfaces }
  687. interface_iunknown : tobjectdef;
  688. { pointer to the ancestor of all dispinterfaces }
  689. interface_idispatch : tobjectdef;
  690. { pointer to the TGUID type
  691. of all interfaces }
  692. rec_tguid : trecorddef;
  693. { pointer to jump buffer }
  694. rec_jmp_buf : trecorddef;
  695. { Objective-C base types }
  696. objc_metaclasstype,
  697. objc_superclasstype,
  698. objc_idtype,
  699. objc_seltype : tpointerdef;
  700. objc_objecttype : trecorddef;
  701. { base type of @protocol(protocolname) Objective-C statements }
  702. objc_protocoltype : tobjectdef;
  703. { helper types for for-in "fast enumeration" support in Objective-C 2.0 }
  704. objc_fastenumeration : tobjectdef;
  705. objc_fastenumerationstate : trecorddef;
  706. { Java base types }
  707. { java.lang.Object }
  708. java_jlobject : tobjectdef;
  709. const
  710. {$ifdef i386}
  711. pbestrealtype : ^tdef = @s80floattype;
  712. {$endif}
  713. {$ifdef x86_64}
  714. pbestrealtype : ^tdef = @s80floattype;
  715. {$endif}
  716. {$ifdef m68k}
  717. pbestrealtype : ^tdef = @s64floattype;
  718. {$endif}
  719. {$ifdef alpha}
  720. pbestrealtype : ^tdef = @s64floattype;
  721. {$endif}
  722. {$ifdef powerpc}
  723. pbestrealtype : ^tdef = @s64floattype;
  724. {$endif}
  725. {$ifdef POWERPC64}
  726. pbestrealtype : ^tdef = @s64floattype;
  727. {$endif}
  728. {$ifdef ia64}
  729. pbestrealtype : ^tdef = @s64floattype;
  730. {$endif}
  731. {$ifdef SPARC}
  732. pbestrealtype : ^tdef = @s64floattype;
  733. {$endif SPARC}
  734. {$ifdef vis}
  735. pbestrealtype : ^tdef = @s64floattype;
  736. {$endif vis}
  737. {$ifdef ARM}
  738. pbestrealtype : ^tdef = @s64floattype;
  739. {$endif ARM}
  740. {$ifdef MIPS}
  741. pbestrealtype : ^tdef = @s64floattype;
  742. {$endif MIPS}
  743. {$ifdef AVR}
  744. pbestrealtype : ^tdef = @s64floattype;
  745. {$endif AVR}
  746. {$ifdef JVM}
  747. pbestrealtype : ^tdef = @s64floattype;
  748. {$endif JVM}
  749. function make_mangledname(const typeprefix:string;st:TSymtable;const suffix:string):string;
  750. function make_dllmangledname(const dllname,importname:string;
  751. import_nr : word; pco : tproccalloption):string;
  752. { should be in the types unit, but the types unit uses the node stuff :( }
  753. function is_interfacecom(def: tdef): boolean;
  754. function is_interfacecom_or_dispinterface(def: tdef): boolean;
  755. function is_interfacecorba(def: tdef): boolean;
  756. function is_interface(def: tdef): boolean;
  757. function is_dispinterface(def: tdef): boolean;
  758. function is_object(def: tdef): boolean;
  759. function is_class(def: tdef): boolean;
  760. function is_cppclass(def: tdef): boolean;
  761. function is_objectpascal_helper(def: tdef): boolean;
  762. function is_objcclass(def: tdef): boolean;
  763. function is_objcclassref(def: tdef): boolean;
  764. function is_objcprotocol(def: tdef): boolean;
  765. function is_objccategory(def: tdef): boolean;
  766. function is_objc_class_or_protocol(def: tdef): boolean;
  767. function is_objc_protocol_or_category(def: tdef): boolean;
  768. function is_classhelper(def: tdef): boolean;
  769. function is_class_or_interface(def: tdef): boolean;
  770. function is_class_or_interface_or_objc(def: tdef): boolean;
  771. function is_class_or_interface_or_object(def: tdef): boolean;
  772. function is_class_or_interface_or_dispinterface(def: tdef): boolean;
  773. function is_implicit_pointer_object_type(def: tdef): boolean;
  774. function is_class_or_object(def: tdef): boolean;
  775. function is_record(def: tdef): boolean;
  776. function is_javaclass(def: tdef): boolean;
  777. function is_javainterface(def: tdef): boolean;
  778. function is_java_class_or_interface(def: tdef): boolean;
  779. procedure loadobjctypes;
  780. procedure maybeloadcocoatypes;
  781. function use_vectorfpu(def : tdef) : boolean;
  782. implementation
  783. uses
  784. SysUtils,
  785. cutils,
  786. { global }
  787. verbose,
  788. { target }
  789. systems,aasmcpu,paramgr,
  790. { symtable }
  791. symsym,symtable,symutil,defutil,objcdef,jvmdef,
  792. { module }
  793. fmodule,
  794. { other }
  795. gendef,
  796. fpccrc
  797. ;
  798. {****************************************************************************
  799. Helpers
  800. ****************************************************************************}
  801. function make_mangledname(const typeprefix:string;st:TSymtable;const suffix:string):string;
  802. var
  803. s,hs,
  804. prefix : string;
  805. oldlen,
  806. newlen,
  807. i : longint;
  808. crc : dword;
  809. hp : tparavarsym;
  810. begin
  811. prefix:='';
  812. if not assigned(st) then
  813. internalerror(200204212);
  814. { sub procedures }
  815. while (st.symtabletype=localsymtable) do
  816. begin
  817. if st.defowner.typ<>procdef then
  818. internalerror(200204173);
  819. { Add the full mangledname of procedure to prevent
  820. conflicts with 2 overloads having both a nested procedure
  821. with the same name, see tb0314 (PFV) }
  822. s:=tprocdef(st.defowner).procsym.name;
  823. oldlen:=length(s);
  824. for i:=0 to tprocdef(st.defowner).paras.count-1 do
  825. begin
  826. hp:=tparavarsym(tprocdef(st.defowner).paras[i]);
  827. if not(vo_is_hidden_para in hp.varoptions) then
  828. s:=s+'$'+hp.vardef.mangledparaname;
  829. end;
  830. if not is_void(tprocdef(st.defowner).returndef) then
  831. s:=s+'$$'+tprocdef(st.defowner).returndef.mangledparaname;
  832. newlen:=length(s);
  833. { Replace with CRC if the parameter line is very long }
  834. if (newlen-oldlen>12) and
  835. ((newlen+length(prefix)>100) or (newlen-oldlen>32)) then
  836. begin
  837. crc:=0;
  838. for i:=0 to tprocdef(st.defowner).paras.count-1 do
  839. begin
  840. hp:=tparavarsym(tprocdef(st.defowner).paras[i]);
  841. if not(vo_is_hidden_para in hp.varoptions) then
  842. begin
  843. hs:=hp.vardef.mangledparaname;
  844. crc:=UpdateCrc32(crc,hs[1],length(hs));
  845. end;
  846. end;
  847. hs:=hp.vardef.mangledparaname;
  848. crc:=UpdateCrc32(crc,hs[1],length(hs));
  849. s:=Copy(s,1,oldlen)+'$crc'+hexstr(crc,8);
  850. end;
  851. if prefix<>'' then
  852. prefix:=s+'_'+prefix
  853. else
  854. prefix:=s;
  855. if length(prefix)>100 then
  856. begin
  857. crc:=0;
  858. crc:=UpdateCrc32(crc,prefix[1],length(prefix));
  859. prefix:='$CRC'+hexstr(crc,8);
  860. end;
  861. st:=st.defowner.owner;
  862. end;
  863. { object/classes symtable, nested type definitions in classes require the while loop }
  864. while st.symtabletype in [ObjectSymtable,recordsymtable] do
  865. begin
  866. if not (st.defowner.typ in [objectdef,recorddef]) then
  867. internalerror(200204174);
  868. prefix:=tabstractrecorddef(st.defowner).objname^+'_$_'+prefix;
  869. st:=st.defowner.owner;
  870. end;
  871. { symtable must now be static or global }
  872. if not(st.symtabletype in [staticsymtable,globalsymtable]) then
  873. internalerror(200204175);
  874. result:='';
  875. if typeprefix<>'' then
  876. result:=result+typeprefix+'_';
  877. { Add P$ for program, which can have the same name as
  878. a unit }
  879. if (TSymtable(main_module.localsymtable)=st) and
  880. (not main_module.is_unit) then
  881. result:=result+'P$'+st.name^
  882. else
  883. result:=result+st.name^;
  884. if prefix<>'' then
  885. result:=result+'_'+prefix;
  886. if suffix<>'' then
  887. result:=result+'_'+suffix;
  888. { the Darwin assembler assumes that all symbols starting with 'L' are local }
  889. { Further, the Mac OS X 10.5 linker does not consider symbols which do not }
  890. { start with '_' as regular symbols (it does not generate N_GSYM entries }
  891. { those in the debug map, leading to troubles with dsymutil). So always }
  892. { add an underscore on darwin. }
  893. if (target_info.system in systems_darwin) then
  894. result := '_' + result;
  895. end;
  896. function make_dllmangledname(const dllname,importname:string;import_nr : word; pco : tproccalloption):string;
  897. var
  898. crc : cardinal;
  899. i : longint;
  900. use_crc : boolean;
  901. dllprefix : string;
  902. begin
  903. if (target_info.system in (systems_all_windows + systems_nativent +
  904. [system_i386_emx, system_i386_os2]))
  905. and (dllname <> '') then
  906. begin
  907. dllprefix:=lower(ExtractFileName(dllname));
  908. { Remove .dll suffix if present }
  909. if copy(dllprefix,length(dllprefix)-3,length(dllprefix))='.dll' then
  910. dllprefix:=copy(dllprefix,1,length(dllprefix)-4);
  911. use_crc:=false;
  912. for i:=1 to length(dllprefix) do
  913. if not (dllprefix[i] in ['a'..'z','A'..'Z','_','0'..'9']) then
  914. begin
  915. use_crc:=true;
  916. break;
  917. end;
  918. if use_crc then
  919. begin
  920. crc:=0;
  921. crc:=UpdateCrc32(crc,dllprefix[1],length(dllprefix));
  922. dllprefix:='_$dll$crc$'+hexstr(crc,8)+'$';
  923. end
  924. else
  925. dllprefix:='_$dll$'+dllprefix+'$';
  926. if importname<>'' then
  927. result:=dllprefix+importname
  928. else
  929. result:=dllprefix+'_index_'+tostr(import_nr);
  930. { Replace ? and @ in import name, since GNU AS does not allow these characters in symbol names. }
  931. { This allows to import VC++ mangled names from DLLs. }
  932. { Do not perform replacement, if external symbol is not imported from DLL. }
  933. if (dllname<>'') then
  934. begin
  935. Replace(result,'?','__q$$');
  936. {$ifdef arm}
  937. { @ symbol is not allowed in ARM assembler only }
  938. Replace(result,'@','__a$$');
  939. {$endif arm}
  940. end;
  941. end
  942. else
  943. begin
  944. if importname<>'' then
  945. begin
  946. if not(pco in [pocall_cdecl,pocall_cppdecl]) then
  947. result:=importname
  948. else
  949. result:=target_info.Cprefix+importname;
  950. end
  951. else
  952. result:='_index_'+tostr(import_nr);
  953. end;
  954. end;
  955. {****************************************************************************
  956. TDEFAWARESYMTABLESTACK
  957. (symtablestack descendant that does some special actions on
  958. the pushed/popped symtables)
  959. ****************************************************************************}
  960. procedure tdefawaresymtablestack.addhelpers(st: TSymtable);
  961. var
  962. i: integer;
  963. s: string;
  964. list: TFPObjectList;
  965. def: tdef;
  966. begin
  967. { search the symtable from first to last; the helper to use will be the
  968. last one in the list }
  969. for i:=0 to st.symlist.count-1 do
  970. begin
  971. if not (st.symlist[i] is ttypesym) then
  972. continue;
  973. def:=ttypesym(st.SymList[i]).typedef;
  974. if is_objectpascal_helper(def) then
  975. begin
  976. s:=make_mangledname('',tobjectdef(def).extendeddef.symtable,'');
  977. list:=TFPObjectList(current_module.extendeddefs.Find(s));
  978. if not assigned(list) then
  979. begin
  980. list:=TFPObjectList.Create(false);
  981. current_module.extendeddefs.Add(s,list);
  982. end;
  983. list.Add(def);
  984. end
  985. else
  986. { add nested helpers as well }
  987. if def.typ in [recorddef,objectdef] then
  988. addhelpers(tabstractrecorddef(def).symtable);
  989. end;
  990. end;
  991. procedure tdefawaresymtablestack.removehelpers(st: TSymtable);
  992. var
  993. i, j: integer;
  994. tmpst: TSymtable;
  995. list: TFPObjectList;
  996. begin
  997. for i:=current_module.extendeddefs.count-1 downto 0 do
  998. begin
  999. list:=TFPObjectList(current_module.extendeddefs[i]);
  1000. for j:=list.count-1 downto 0 do
  1001. begin
  1002. if not (list[j] is tobjectdef) then
  1003. Internalerror(2011031501);
  1004. tmpst:=tobjectdef(list[j]).owner;
  1005. repeat
  1006. if tmpst=st then
  1007. begin
  1008. list.delete(j);
  1009. break;
  1010. end
  1011. else
  1012. begin
  1013. if assigned(tmpst.defowner) then
  1014. tmpst:=tmpst.defowner.owner
  1015. else
  1016. tmpst:=nil;
  1017. end;
  1018. until not assigned(tmpst) or (tmpst.symtabletype in [globalsymtable,staticsymtable]);
  1019. end;
  1020. if list.count=0 then
  1021. current_module.extendeddefs.delete(i);
  1022. end;
  1023. end;
  1024. procedure tdefawaresymtablestack.push(st: TSymtable);
  1025. begin
  1026. { nested helpers will be added as well }
  1027. if (st.symtabletype in [globalsymtable,staticsymtable]) and
  1028. (sto_has_helper in st.tableoptions) then
  1029. addhelpers(st);
  1030. inherited push(st);
  1031. end;
  1032. procedure tdefawaresymtablestack.pop(st: TSymtable);
  1033. begin
  1034. inherited pop(st);
  1035. { nested helpers will be removed as well }
  1036. if (st.symtabletype in [globalsymtable,staticsymtable]) and
  1037. (sto_has_helper in st.tableoptions) then
  1038. removehelpers(st);
  1039. end;
  1040. {****************************************************************************
  1041. TDEF (base class for definitions)
  1042. ****************************************************************************}
  1043. constructor tstoreddef.create(dt:tdeftyp);
  1044. var
  1045. insertstack : psymtablestackitem;
  1046. begin
  1047. inherited create(dt);
  1048. savesize := 0;
  1049. {$ifdef EXTDEBUG}
  1050. fileinfo := current_filepos;
  1051. {$endif}
  1052. generictokenbuf:=nil;
  1053. genericdef:=nil;
  1054. { Don't register forwarddefs, they are disposed at the
  1055. end of an type block }
  1056. if (dt=forwarddef) then
  1057. exit;
  1058. { Register in current_module }
  1059. if assigned(current_module) then
  1060. begin
  1061. current_module.deflist.Add(self);
  1062. DefId:=current_module.deflist.Count-1;
  1063. end;
  1064. { Register in symtable stack }
  1065. if assigned(symtablestack) then
  1066. begin
  1067. insertstack:=symtablestack.stack;
  1068. while assigned(insertstack) and
  1069. (insertstack^.symtable.symtabletype=withsymtable) do
  1070. insertstack:=insertstack^.next;
  1071. if not assigned(insertstack) then
  1072. internalerror(200602044);
  1073. insertstack^.symtable.insertdef(self);
  1074. end;
  1075. end;
  1076. destructor tstoreddef.destroy;
  1077. begin
  1078. { Direct calls are not allowed, use symtable.deletedef() }
  1079. if assigned(owner) then
  1080. internalerror(200612311);
  1081. if assigned(generictokenbuf) then
  1082. begin
  1083. generictokenbuf.free;
  1084. generictokenbuf:=nil;
  1085. end;
  1086. inherited destroy;
  1087. end;
  1088. constructor tstoreddef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  1089. var
  1090. sizeleft,i : longint;
  1091. buf : array[0..255] of byte;
  1092. begin
  1093. inherited create(dt);
  1094. DefId:=ppufile.getlongint;
  1095. current_module.deflist[DefId]:=self;
  1096. {$ifdef EXTDEBUG}
  1097. fillchar(fileinfo,sizeof(fileinfo),0);
  1098. {$endif}
  1099. { load }
  1100. ppufile.getderef(typesymderef);
  1101. ppufile.getsmallset(defoptions);
  1102. ppufile.getsmallset(defstates);
  1103. if df_generic in defoptions then
  1104. begin
  1105. sizeleft:=ppufile.getlongint;
  1106. initgeneric;
  1107. while sizeleft>0 do
  1108. begin
  1109. if sizeleft>sizeof(buf) then
  1110. i:=sizeof(buf)
  1111. else
  1112. i:=sizeleft;
  1113. ppufile.getdata(buf,i);
  1114. generictokenbuf.write(buf,i);
  1115. dec(sizeleft,i);
  1116. end;
  1117. end;
  1118. if df_specialization in defoptions then
  1119. ppufile.getderef(genericdefderef);
  1120. end;
  1121. function Tstoreddef.rtti_mangledname(rt:trttitype):string;
  1122. var
  1123. prefix : string[4];
  1124. begin
  1125. if rt=fullrtti then
  1126. begin
  1127. prefix:='RTTI';
  1128. include(defstates,ds_rtti_table_used);
  1129. end
  1130. else
  1131. begin
  1132. prefix:='INIT';
  1133. include(defstates,ds_init_table_used);
  1134. end;
  1135. if assigned(typesym) and
  1136. (owner.symtabletype in [staticsymtable,globalsymtable]) then
  1137. result:=make_mangledname(prefix,owner,typesym.name)
  1138. else
  1139. result:=make_mangledname(prefix,findunitsymtable(owner),'DEF'+tostr(DefId))
  1140. end;
  1141. function tstoreddef.OwnerHierarchyName: string;
  1142. var
  1143. tmp: tdef;
  1144. begin
  1145. tmp:=self;
  1146. result:='';
  1147. repeat
  1148. if tmp.owner.symtabletype in [ObjectSymtable,recordsymtable] then
  1149. tmp:=tdef(tmp.owner.defowner)
  1150. else
  1151. break;
  1152. result:=tabstractrecorddef(tmp).objrealname^+'.'+result;
  1153. until tmp=nil;
  1154. end;
  1155. function tstoreddef.in_currentunit: boolean;
  1156. var
  1157. st: tsymtable;
  1158. begin
  1159. st:=owner;
  1160. while not(st.symtabletype in [globalsymtable,staticsymtable]) do
  1161. st:=st.defowner.owner;
  1162. result:=st.iscurrentunit;
  1163. end;
  1164. function tstoreddef.getcopy : tstoreddef;
  1165. begin
  1166. Message(sym_e_cant_create_unique_type);
  1167. getcopy:=terrordef.create;
  1168. end;
  1169. procedure tstoreddef.ppuwrite(ppufile:tcompilerppufile);
  1170. var
  1171. sizeleft,i : longint;
  1172. buf : array[0..255] of byte;
  1173. oldintfcrc : boolean;
  1174. begin
  1175. ppufile.putlongint(DefId);
  1176. ppufile.putderef(typesymderef);
  1177. ppufile.putsmallset(defoptions);
  1178. oldintfcrc:=ppufile.do_crc;
  1179. ppufile.do_crc:=false;
  1180. ppufile.putsmallset(defstates);
  1181. if df_generic in defoptions then
  1182. begin
  1183. if assigned(generictokenbuf) then
  1184. begin
  1185. sizeleft:=generictokenbuf.size;
  1186. generictokenbuf.seek(0);
  1187. end
  1188. else
  1189. sizeleft:=0;
  1190. ppufile.putlongint(sizeleft);
  1191. while sizeleft>0 do
  1192. begin
  1193. if sizeleft>sizeof(buf) then
  1194. i:=sizeof(buf)
  1195. else
  1196. i:=sizeleft;
  1197. generictokenbuf.read(buf,i);
  1198. ppufile.putdata(buf,i);
  1199. dec(sizeleft,i);
  1200. end;
  1201. end;
  1202. ppufile.do_crc:=oldintfcrc;
  1203. if df_specialization in defoptions then
  1204. ppufile.putderef(genericdefderef);
  1205. end;
  1206. procedure tstoreddef.buildderef;
  1207. begin
  1208. typesymderef.build(typesym);
  1209. genericdefderef.build(genericdef);
  1210. end;
  1211. procedure tstoreddef.buildderefimpl;
  1212. begin
  1213. end;
  1214. procedure tstoreddef.deref;
  1215. begin
  1216. typesym:=ttypesym(typesymderef.resolve);
  1217. if df_specialization in defoptions then
  1218. genericdef:=tstoreddef(genericdefderef.resolve);
  1219. end;
  1220. procedure tstoreddef.derefimpl;
  1221. begin
  1222. end;
  1223. function tstoreddef.size : asizeint;
  1224. begin
  1225. size:=savesize;
  1226. end;
  1227. function tstoreddef.getvardef:longint;
  1228. begin
  1229. result:=varUndefined;
  1230. end;
  1231. function tstoreddef.alignment : shortint;
  1232. begin
  1233. { natural alignment by default }
  1234. alignment:=size_2_align(savesize);
  1235. { can happen if savesize = 0, e.g. for voiddef or
  1236. an empty record
  1237. }
  1238. if (alignment=0) then
  1239. alignment:=1;
  1240. end;
  1241. { returns true, if the definition can be published }
  1242. function tstoreddef.is_publishable : boolean;
  1243. begin
  1244. is_publishable:=false;
  1245. end;
  1246. { needs an init table }
  1247. function tstoreddef.needs_inittable : boolean;
  1248. begin
  1249. needs_inittable:=false;
  1250. end;
  1251. function tstoreddef.is_intregable : boolean;
  1252. var
  1253. recsize,temp: longint;
  1254. begin
  1255. is_intregable:=false;
  1256. case typ of
  1257. orddef,
  1258. pointerdef,
  1259. enumdef,
  1260. classrefdef:
  1261. is_intregable:=true;
  1262. procvardef :
  1263. is_intregable:=tprocvardef(self).is_addressonly;
  1264. objectdef:
  1265. is_intregable:=(is_implicit_pointer_object_type(self)) and not needs_inittable;
  1266. setdef:
  1267. is_intregable:=is_smallset(self);
  1268. recorddef:
  1269. begin
  1270. recsize:=size;
  1271. is_intregable:=
  1272. ispowerof2(recsize,temp) and
  1273. (recsize <= sizeof(asizeint));
  1274. end;
  1275. end;
  1276. end;
  1277. function tstoreddef.is_fpuregable : boolean;
  1278. begin
  1279. {$ifdef x86}
  1280. result:=use_vectorfpu(self);
  1281. {$else x86}
  1282. result:=(typ=floatdef) and not(cs_fp_emulation in current_settings.moduleswitches);
  1283. {$endif x86}
  1284. end;
  1285. procedure tstoreddef.initgeneric;
  1286. begin
  1287. if assigned(generictokenbuf) then
  1288. internalerror(200512131);
  1289. generictokenbuf:=tdynamicarray.create(256);
  1290. end;
  1291. {****************************************************************************
  1292. Tstringdef
  1293. ****************************************************************************}
  1294. constructor tstringdef.createshort(l : byte);
  1295. begin
  1296. inherited create(stringdef);
  1297. stringtype:=st_shortstring;
  1298. len:=l;
  1299. savesize:=len+1;
  1300. end;
  1301. constructor tstringdef.loadshort(ppufile:tcompilerppufile);
  1302. begin
  1303. inherited ppuload(stringdef,ppufile);
  1304. stringtype:=st_shortstring;
  1305. len:=ppufile.getbyte;
  1306. savesize:=len+1;
  1307. end;
  1308. constructor tstringdef.createlong(l : asizeint);
  1309. begin
  1310. inherited create(stringdef);
  1311. stringtype:=st_longstring;
  1312. len:=l;
  1313. savesize:=sizeof(pint);
  1314. end;
  1315. constructor tstringdef.loadlong(ppufile:tcompilerppufile);
  1316. begin
  1317. inherited ppuload(stringdef,ppufile);
  1318. stringtype:=st_longstring;
  1319. len:=ppufile.getasizeint;
  1320. savesize:=sizeof(pint);
  1321. end;
  1322. constructor tstringdef.createansi;
  1323. begin
  1324. inherited create(stringdef);
  1325. stringtype:=st_ansistring;
  1326. len:=-1;
  1327. savesize:=sizeof(pint);
  1328. end;
  1329. constructor tstringdef.loadansi(ppufile:tcompilerppufile);
  1330. begin
  1331. inherited ppuload(stringdef,ppufile);
  1332. stringtype:=st_ansistring;
  1333. len:=ppufile.getaint;
  1334. savesize:=sizeof(pint);
  1335. end;
  1336. constructor tstringdef.createwide;
  1337. begin
  1338. inherited create(stringdef);
  1339. stringtype:=st_widestring;
  1340. len:=-1;
  1341. savesize:=sizeof(pint);
  1342. end;
  1343. constructor tstringdef.loadwide(ppufile:tcompilerppufile);
  1344. begin
  1345. inherited ppuload(stringdef,ppufile);
  1346. stringtype:=st_widestring;
  1347. len:=ppufile.getaint;
  1348. savesize:=sizeof(pint);
  1349. end;
  1350. constructor tstringdef.createunicode;
  1351. begin
  1352. inherited create(stringdef);
  1353. stringtype:=st_unicodestring;
  1354. len:=-1;
  1355. savesize:=sizeof(pint);
  1356. end;
  1357. constructor tstringdef.loadunicode(ppufile:tcompilerppufile);
  1358. begin
  1359. inherited ppuload(stringdef,ppufile);
  1360. stringtype:=st_unicodestring;
  1361. len:=ppufile.getaint;
  1362. savesize:=sizeof(pint);
  1363. end;
  1364. function tstringdef.getcopy : tstoreddef;
  1365. begin
  1366. result:=tstringdef.create(typ);
  1367. result.typ:=stringdef;
  1368. tstringdef(result).stringtype:=stringtype;
  1369. tstringdef(result).len:=len;
  1370. tstringdef(result).savesize:=savesize;
  1371. end;
  1372. function tstringdef.stringtypname:string;
  1373. const
  1374. typname:array[tstringtype] of string[10]=(
  1375. 'shortstr','longstr','ansistr','widestr','unicodestr'
  1376. );
  1377. begin
  1378. stringtypname:=typname[stringtype];
  1379. end;
  1380. procedure tstringdef.ppuwrite(ppufile:tcompilerppufile);
  1381. begin
  1382. inherited ppuwrite(ppufile);
  1383. if stringtype=st_shortstring then
  1384. begin
  1385. {$ifdef extdebug}
  1386. if len > 255 then internalerror(12122002);
  1387. {$endif}
  1388. ppufile.putbyte(byte(len))
  1389. end
  1390. else
  1391. ppufile.putaint(len);
  1392. case stringtype of
  1393. st_shortstring : ppufile.writeentry(ibshortstringdef);
  1394. st_longstring : ppufile.writeentry(iblongstringdef);
  1395. st_ansistring : ppufile.writeentry(ibansistringdef);
  1396. st_widestring : ppufile.writeentry(ibwidestringdef);
  1397. st_unicodestring : ppufile.writeentry(ibunicodestringdef);
  1398. end;
  1399. end;
  1400. function tstringdef.needs_inittable : boolean;
  1401. begin
  1402. needs_inittable:=stringtype in [st_ansistring,st_widestring,st_unicodestring];
  1403. end;
  1404. function tstringdef.GetTypeName : string;
  1405. const
  1406. names : array[tstringtype] of string[15] = (
  1407. 'ShortString','LongString','AnsiString','WideString','UnicodeString');
  1408. begin
  1409. GetTypeName:=names[stringtype];
  1410. end;
  1411. function tstringdef.getvardef : longint;
  1412. const
  1413. vardef : array[tstringtype] of longint = (
  1414. varUndefined,varUndefined,varString,varOleStr,varUString);
  1415. begin
  1416. result:=vardef[stringtype];
  1417. end;
  1418. function tstringdef.alignment : shortint;
  1419. begin
  1420. case stringtype of
  1421. st_unicodestring,
  1422. st_widestring,
  1423. st_ansistring:
  1424. alignment:=size_2_align(savesize);
  1425. st_longstring,
  1426. st_shortstring:
  1427. { char to string accesses byte 0 and 1 with one word access }
  1428. if (tf_requires_proper_alignment in target_info.flags) or
  1429. { macpas needs an alignment of 2 (MetroWerks compatible) }
  1430. (m_mac in current_settings.modeswitches) then
  1431. alignment:=size_2_align(2)
  1432. else
  1433. alignment:=size_2_align(1);
  1434. else
  1435. internalerror(200412301);
  1436. end;
  1437. end;
  1438. function tstringdef.getmangledparaname : string;
  1439. begin
  1440. getmangledparaname:='STRING';
  1441. end;
  1442. function tstringdef.is_publishable : boolean;
  1443. begin
  1444. is_publishable:=true;
  1445. end;
  1446. {****************************************************************************
  1447. TENUMDEF
  1448. ****************************************************************************}
  1449. constructor tenumdef.create;
  1450. begin
  1451. inherited create(enumdef);
  1452. minval:=0;
  1453. maxval:=0;
  1454. calcsavesize;
  1455. has_jumps:=false;
  1456. basedef:=nil;
  1457. symtable:=tenumsymtable.create(self);
  1458. end;
  1459. constructor tenumdef.create_subrange(_basedef:tenumdef;_min,_max:asizeint);
  1460. begin
  1461. inherited create(enumdef);
  1462. minval:=_min;
  1463. maxval:=_max;
  1464. basedef:=_basedef;
  1465. calcsavesize;
  1466. has_jumps:=false;
  1467. symtable:=basedef.symtable.getcopy;
  1468. include(defoptions, df_copied_def);
  1469. end;
  1470. constructor tenumdef.ppuload(ppufile:tcompilerppufile);
  1471. begin
  1472. inherited ppuload(enumdef,ppufile);
  1473. minval:=ppufile.getaint;
  1474. maxval:=ppufile.getaint;
  1475. savesize:=ppufile.getaint;
  1476. has_jumps:=false;
  1477. if df_copied_def in defoptions then
  1478. begin
  1479. symtable:=nil;
  1480. ppufile.getderef(basedefderef);
  1481. end
  1482. else
  1483. begin
  1484. // create with nil defowner first to prevent values changes on insert
  1485. symtable:=tenumsymtable.create(nil);
  1486. tenumsymtable(symtable).ppuload(ppufile);
  1487. symtable.defowner:=self;
  1488. end;
  1489. end;
  1490. destructor tenumdef.destroy;
  1491. begin
  1492. symtable.free;
  1493. symtable:=nil;
  1494. inherited destroy;
  1495. end;
  1496. function tenumdef.getcopy : tstoreddef;
  1497. begin
  1498. if assigned(basedef) then
  1499. result:=tenumdef.create_subrange(basedef,minval,maxval)
  1500. else
  1501. begin
  1502. result:=tenumdef.create;
  1503. tenumdef(result).minval:=minval;
  1504. tenumdef(result).maxval:=maxval;
  1505. tenumdef(result).symtable.free;
  1506. tenumdef(result).symtable:=symtable.getcopy;
  1507. tenumdef(result).basedef:=self;
  1508. end;
  1509. tenumdef(result).has_jumps:=has_jumps;
  1510. tenumdef(result).basedefderef:=basedefderef;
  1511. include(tenumdef(result).defoptions,df_copied_def);
  1512. end;
  1513. procedure tenumdef.calcsavesize;
  1514. begin
  1515. if (current_settings.packenum=8) or (min<low(longint)) or (int64(max)>high(cardinal)) then
  1516. savesize:=8
  1517. else
  1518. if (current_settings.packenum=4) or (min<low(smallint)) or (max>high(word)) then
  1519. savesize:=4
  1520. else
  1521. if (current_settings.packenum=2) or (min<low(shortint)) or (max>high(byte)) then
  1522. savesize:=2
  1523. else
  1524. savesize:=1;
  1525. end;
  1526. function tenumdef.packedbitsize: asizeint;
  1527. var
  1528. sizeval: tconstexprint;
  1529. power: longint;
  1530. begin
  1531. result := 0;
  1532. if (minval >= 0) and
  1533. (maxval <= 1) then
  1534. result := 1
  1535. else
  1536. begin
  1537. if (minval>=0) then
  1538. sizeval:=maxval
  1539. else
  1540. { don't count 0 twice }
  1541. sizeval:=(cutils.max(-minval,maxval)*2)-1;
  1542. { 256 must become 512 etc. }
  1543. nextpowerof2(sizeval+1,power);
  1544. result := power;
  1545. end;
  1546. end;
  1547. procedure tenumdef.setmax(_max:asizeint);
  1548. begin
  1549. maxval:=_max;
  1550. calcsavesize;
  1551. end;
  1552. procedure tenumdef.setmin(_min:asizeint);
  1553. begin
  1554. minval:=_min;
  1555. calcsavesize;
  1556. end;
  1557. function tenumdef.min:asizeint;
  1558. begin
  1559. min:=minval;
  1560. end;
  1561. function tenumdef.max:asizeint;
  1562. begin
  1563. max:=maxval;
  1564. end;
  1565. function tenumdef.getfirstsym: tsym;
  1566. var
  1567. i:integer;
  1568. begin
  1569. for i := 0 to symtable.SymList.Count - 1 do
  1570. begin
  1571. result:=tsym(symtable.SymList[i]);
  1572. if tenumsym(result).value=minval then
  1573. exit;
  1574. end;
  1575. result:=nil;
  1576. end;
  1577. procedure tenumdef.buildderef;
  1578. begin
  1579. inherited buildderef;
  1580. if df_copied_def in defoptions then
  1581. basedefderef.build(basedef)
  1582. else
  1583. tenumsymtable(symtable).buildderef;
  1584. end;
  1585. procedure tenumdef.deref;
  1586. begin
  1587. inherited deref;
  1588. if df_copied_def in defoptions then
  1589. begin
  1590. basedef:=tenumdef(basedefderef.resolve);
  1591. symtable:=basedef.symtable.getcopy;
  1592. end
  1593. else
  1594. tenumsymtable(symtable).deref;
  1595. end;
  1596. procedure tenumdef.ppuwrite(ppufile:tcompilerppufile);
  1597. begin
  1598. inherited ppuwrite(ppufile);
  1599. ppufile.putaint(min);
  1600. ppufile.putaint(max);
  1601. ppufile.putaint(savesize);
  1602. if df_copied_def in defoptions then
  1603. ppufile.putderef(basedefderef);
  1604. ppufile.writeentry(ibenumdef);
  1605. if not (df_copied_def in defoptions) then
  1606. tenumsymtable(symtable).ppuwrite(ppufile);
  1607. end;
  1608. function tenumdef.is_publishable : boolean;
  1609. begin
  1610. is_publishable:=true;
  1611. end;
  1612. function tenumdef.GetTypeName : string;
  1613. begin
  1614. GetTypeName:='<enumeration type>';
  1615. end;
  1616. {****************************************************************************
  1617. TORDDEF
  1618. ****************************************************************************}
  1619. constructor torddef.create(t : tordtype;v,b : TConstExprInt);
  1620. begin
  1621. inherited create(orddef);
  1622. low:=v;
  1623. high:=b;
  1624. ordtype:=t;
  1625. setsize;
  1626. end;
  1627. constructor torddef.ppuload(ppufile:tcompilerppufile);
  1628. begin
  1629. inherited ppuload(orddef,ppufile);
  1630. ordtype:=tordtype(ppufile.getbyte);
  1631. low:=ppufile.getexprint;
  1632. high:=ppufile.getexprint;
  1633. setsize;
  1634. end;
  1635. function torddef.getcopy : tstoreddef;
  1636. begin
  1637. result:=torddef.create(ordtype,low,high);
  1638. result.typ:=orddef;
  1639. torddef(result).low:=low;
  1640. torddef(result).high:=high;
  1641. torddef(result).ordtype:=ordtype;
  1642. torddef(result).savesize:=savesize;
  1643. end;
  1644. function torddef.alignment:shortint;
  1645. begin
  1646. if (target_info.system in [system_i386_darwin,system_i386_iphonesim,system_arm_darwin]) and
  1647. (ordtype in [s64bit,u64bit]) then
  1648. result := 4
  1649. else
  1650. result := inherited alignment;
  1651. end;
  1652. procedure torddef.setsize;
  1653. const
  1654. sizetbl : array[tordtype] of longint = (
  1655. 0,
  1656. 1,2,4,8,
  1657. 1,2,4,8,
  1658. 1,2,4,8,
  1659. 1,2,4,8,
  1660. 1,2,8
  1661. );
  1662. begin
  1663. savesize:=sizetbl[ordtype];
  1664. end;
  1665. function torddef.packedbitsize: asizeint;
  1666. var
  1667. sizeval: tconstexprint;
  1668. power: longint;
  1669. begin
  1670. result := 0;
  1671. if ordtype = uvoid then
  1672. exit;
  1673. {$ifndef cpu64bitalu}
  1674. if (ordtype in [s64bit,u64bit]) then
  1675. {$else not cpu64bitalu}
  1676. if (ordtype = u64bit) or
  1677. ((ordtype = s64bit) and
  1678. ((low <= (system.low(int64) div 2)) or
  1679. (high > (system.high(int64) div 2)))) then
  1680. {$endif cpu64bitalu}
  1681. result := 64
  1682. else if (low >= 0) and
  1683. (high <= 1) then
  1684. result := 1
  1685. else
  1686. begin
  1687. if (low>=0) then
  1688. sizeval:=high
  1689. else
  1690. { don't count 0 twice }
  1691. sizeval:=(cutils.max(-low,high)*2)-1;
  1692. { 256 must become 512 etc. }
  1693. nextpowerof2(sizeval+1,power);
  1694. result := power;
  1695. end;
  1696. end;
  1697. function torddef.getvardef : longint;
  1698. const
  1699. basetype2vardef : array[tordtype] of longint = (
  1700. varUndefined,
  1701. varbyte,varword,varlongword,varqword,
  1702. varshortint,varsmallint,varinteger,varint64,
  1703. varboolean,varboolean,varboolean,varboolean,
  1704. varboolean,varboolean,varUndefined,varUndefined,
  1705. varUndefined,varUndefined,varCurrency);
  1706. begin
  1707. result:=basetype2vardef[ordtype];
  1708. end;
  1709. procedure torddef.ppuwrite(ppufile:tcompilerppufile);
  1710. begin
  1711. inherited ppuwrite(ppufile);
  1712. ppufile.putbyte(byte(ordtype));
  1713. ppufile.putexprint(low);
  1714. ppufile.putexprint(high);
  1715. ppufile.writeentry(iborddef);
  1716. end;
  1717. function torddef.is_publishable : boolean;
  1718. begin
  1719. is_publishable:=(ordtype<>uvoid);
  1720. end;
  1721. function torddef.GetTypeName : string;
  1722. const
  1723. names : array[tordtype] of string[20] = (
  1724. 'untyped',
  1725. 'Byte','Word','DWord','QWord',
  1726. 'ShortInt','SmallInt','LongInt','Int64',
  1727. 'Boolean','Boolean16','Boolean32','Boolean64',
  1728. 'ByteBool','WordBool','LongBool','QWordBool',
  1729. 'Char','WideChar','Currency');
  1730. begin
  1731. GetTypeName:=names[ordtype];
  1732. end;
  1733. {****************************************************************************
  1734. TFLOATDEF
  1735. ****************************************************************************}
  1736. constructor tfloatdef.create(t : tfloattype);
  1737. begin
  1738. inherited create(floatdef);
  1739. floattype:=t;
  1740. setsize;
  1741. end;
  1742. constructor tfloatdef.ppuload(ppufile:tcompilerppufile);
  1743. begin
  1744. inherited ppuload(floatdef,ppufile);
  1745. floattype:=tfloattype(ppufile.getbyte);
  1746. setsize;
  1747. end;
  1748. function tfloatdef.getcopy : tstoreddef;
  1749. begin
  1750. result:=tfloatdef.create(floattype);
  1751. result.typ:=floatdef;
  1752. tfloatdef(result).savesize:=savesize;
  1753. end;
  1754. function tfloatdef.alignment:shortint;
  1755. begin
  1756. if (target_info.system in [system_i386_darwin,system_i386_iphonesim,system_arm_darwin]) then
  1757. case floattype of
  1758. s80real: result:=16;
  1759. s64real,
  1760. s64currency,
  1761. s64comp : result:=4;
  1762. else
  1763. result := inherited alignment;
  1764. end
  1765. else
  1766. result := inherited alignment;
  1767. end;
  1768. procedure tfloatdef.setsize;
  1769. begin
  1770. case floattype of
  1771. s32real : savesize:=4;
  1772. s80real : savesize:=10;
  1773. sc80real:
  1774. if target_info.system in [system_i386_darwin,system_i386_iphonesim,system_x86_64_darwin,
  1775. system_x86_64_linux,system_x86_64_freebsd,
  1776. system_x86_64_solaris,system_x86_64_embedded] then
  1777. savesize:=16
  1778. else
  1779. savesize:=12;
  1780. s64real,
  1781. s64currency,
  1782. s64comp : savesize:=8;
  1783. else
  1784. savesize:=0;
  1785. end;
  1786. end;
  1787. function tfloatdef.getvardef : longint;
  1788. const
  1789. floattype2vardef : array[tfloattype] of longint = (
  1790. varSingle,varDouble,varUndefined,varUndefined,
  1791. varUndefined,varCurrency,varUndefined);
  1792. begin
  1793. if (upper(typename)='TDATETIME') and
  1794. assigned(owner) and
  1795. assigned(owner.name) and
  1796. (owner.name^='SYSTEM') then
  1797. result:=varDate
  1798. else
  1799. result:=floattype2vardef[floattype];
  1800. end;
  1801. procedure tfloatdef.ppuwrite(ppufile:tcompilerppufile);
  1802. begin
  1803. inherited ppuwrite(ppufile);
  1804. ppufile.putbyte(byte(floattype));
  1805. ppufile.writeentry(ibfloatdef);
  1806. end;
  1807. function tfloatdef.is_publishable : boolean;
  1808. begin
  1809. is_publishable:=true;
  1810. end;
  1811. function tfloatdef.GetTypeName : string;
  1812. const
  1813. names : array[tfloattype] of string[20] = (
  1814. 'Single','Double','Extended','CExtended','Comp','Currency','Float128');
  1815. begin
  1816. GetTypeName:=names[floattype];
  1817. end;
  1818. {****************************************************************************
  1819. TFILEDEF
  1820. ****************************************************************************}
  1821. constructor tfiledef.createtext;
  1822. begin
  1823. inherited create(filedef);
  1824. filetyp:=ft_text;
  1825. typedfiledef:=nil;
  1826. setsize;
  1827. end;
  1828. constructor tfiledef.createuntyped;
  1829. begin
  1830. inherited create(filedef);
  1831. filetyp:=ft_untyped;
  1832. typedfiledef:=nil;
  1833. setsize;
  1834. end;
  1835. constructor tfiledef.createtyped(def:tdef);
  1836. begin
  1837. inherited create(filedef);
  1838. filetyp:=ft_typed;
  1839. typedfiledef:=def;
  1840. setsize;
  1841. end;
  1842. constructor tfiledef.ppuload(ppufile:tcompilerppufile);
  1843. begin
  1844. inherited ppuload(filedef,ppufile);
  1845. filetyp:=tfiletyp(ppufile.getbyte);
  1846. if filetyp=ft_typed then
  1847. ppufile.getderef(typedfiledefderef)
  1848. else
  1849. typedfiledef:=nil;
  1850. setsize;
  1851. end;
  1852. function tfiledef.getcopy : tstoreddef;
  1853. begin
  1854. case filetyp of
  1855. ft_typed:
  1856. result:=tfiledef.createtyped(typedfiledef);
  1857. ft_untyped:
  1858. result:=tfiledef.createuntyped;
  1859. ft_text:
  1860. result:=tfiledef.createtext;
  1861. else
  1862. internalerror(2004121201);
  1863. end;
  1864. end;
  1865. procedure tfiledef.buildderef;
  1866. begin
  1867. inherited buildderef;
  1868. if filetyp=ft_typed then
  1869. typedfiledefderef.build(typedfiledef);
  1870. end;
  1871. procedure tfiledef.deref;
  1872. begin
  1873. inherited deref;
  1874. if filetyp=ft_typed then
  1875. typedfiledef:=tdef(typedfiledefderef.resolve);
  1876. end;
  1877. procedure tfiledef.setsize;
  1878. begin
  1879. {$ifdef cpu64bitaddr}
  1880. case filetyp of
  1881. ft_text :
  1882. if target_info.system in [system_x86_64_win64,system_ia64_win64] then
  1883. savesize:=632{+8}
  1884. else
  1885. savesize:=628{+8};
  1886. ft_typed,
  1887. ft_untyped :
  1888. if target_info.system in [system_x86_64_win64,system_ia64_win64] then
  1889. savesize:=372
  1890. else
  1891. savesize:=368;
  1892. end;
  1893. {$endif cpu64bitaddr}
  1894. {$ifdef cpu32bitaddr}
  1895. case filetyp of
  1896. ft_text :
  1897. savesize:=592{+4};
  1898. ft_typed,
  1899. ft_untyped :
  1900. savesize:=332;
  1901. end;
  1902. {$endif cpu32bitaddr}
  1903. {$ifdef cpu8bitaddr}
  1904. case filetyp of
  1905. ft_text :
  1906. savesize:=127;
  1907. ft_typed,
  1908. ft_untyped :
  1909. savesize:=127;
  1910. end;
  1911. {$endif cpu8bitaddr}
  1912. end;
  1913. procedure tfiledef.ppuwrite(ppufile:tcompilerppufile);
  1914. begin
  1915. inherited ppuwrite(ppufile);
  1916. ppufile.putbyte(byte(filetyp));
  1917. if filetyp=ft_typed then
  1918. ppufile.putderef(typedfiledefderef);
  1919. ppufile.writeentry(ibfiledef);
  1920. end;
  1921. function tfiledef.GetTypeName : string;
  1922. begin
  1923. case filetyp of
  1924. ft_untyped:
  1925. GetTypeName:='File';
  1926. ft_typed:
  1927. GetTypeName:='File Of '+typedfiledef.typename;
  1928. ft_text:
  1929. GetTypeName:='Text'
  1930. end;
  1931. end;
  1932. function tfiledef.getmangledparaname : string;
  1933. begin
  1934. case filetyp of
  1935. ft_untyped:
  1936. getmangledparaname:='FILE';
  1937. ft_typed:
  1938. getmangledparaname:='FILE$OF$'+typedfiledef.mangledparaname;
  1939. ft_text:
  1940. getmangledparaname:='TEXT'
  1941. end;
  1942. end;
  1943. {****************************************************************************
  1944. TVARIANTDEF
  1945. ****************************************************************************}
  1946. constructor tvariantdef.create(v : tvarianttype);
  1947. begin
  1948. inherited create(variantdef);
  1949. varianttype:=v;
  1950. setsize;
  1951. end;
  1952. constructor tvariantdef.ppuload(ppufile:tcompilerppufile);
  1953. begin
  1954. inherited ppuload(variantdef,ppufile);
  1955. varianttype:=tvarianttype(ppufile.getbyte);
  1956. setsize;
  1957. end;
  1958. function tvariantdef.getcopy : tstoreddef;
  1959. begin
  1960. result:=tvariantdef.create(varianttype);
  1961. end;
  1962. procedure tvariantdef.ppuwrite(ppufile:tcompilerppufile);
  1963. begin
  1964. inherited ppuwrite(ppufile);
  1965. ppufile.putbyte(byte(varianttype));
  1966. ppufile.writeentry(ibvariantdef);
  1967. end;
  1968. function tvariantdef.getvardef : longint;
  1969. begin
  1970. Result:=varVariant;
  1971. end;
  1972. procedure tvariantdef.setsize;
  1973. begin
  1974. {$ifdef cpu64bitaddr}
  1975. savesize:=24;
  1976. {$else cpu64bitaddr}
  1977. savesize:=16;
  1978. {$endif cpu64bitaddr}
  1979. end;
  1980. function tvariantdef.GetTypeName : string;
  1981. begin
  1982. case varianttype of
  1983. vt_normalvariant:
  1984. GetTypeName:='Variant';
  1985. vt_olevariant:
  1986. GetTypeName:='OleVariant';
  1987. end;
  1988. end;
  1989. function tvariantdef.needs_inittable : boolean;
  1990. begin
  1991. needs_inittable:=true;
  1992. end;
  1993. function tvariantdef.is_publishable : boolean;
  1994. begin
  1995. is_publishable:=true;
  1996. end;
  1997. {****************************************************************************
  1998. TABSTRACtpointerdef
  1999. ****************************************************************************}
  2000. constructor tabstractpointerdef.create(dt:tdeftyp;def:tdef);
  2001. begin
  2002. inherited create(dt);
  2003. pointeddef:=def;
  2004. savesize:=sizeof(pint);
  2005. end;
  2006. constructor tabstractpointerdef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  2007. begin
  2008. inherited ppuload(dt,ppufile);
  2009. ppufile.getderef(pointeddefderef);
  2010. savesize:=sizeof(pint);
  2011. end;
  2012. procedure tabstractpointerdef.buildderef;
  2013. begin
  2014. inherited buildderef;
  2015. pointeddefderef.build(pointeddef);
  2016. end;
  2017. procedure tabstractpointerdef.deref;
  2018. begin
  2019. inherited deref;
  2020. pointeddef:=tdef(pointeddefderef.resolve);
  2021. end;
  2022. procedure tabstractpointerdef.ppuwrite(ppufile:tcompilerppufile);
  2023. begin
  2024. inherited ppuwrite(ppufile);
  2025. ppufile.putderef(pointeddefderef);
  2026. end;
  2027. {****************************************************************************
  2028. tpointerdef
  2029. ****************************************************************************}
  2030. constructor tpointerdef.create(def:tdef);
  2031. begin
  2032. inherited create(pointerdef,def);
  2033. is_far:=false;
  2034. has_pointer_math:=cs_pointermath in current_settings.localswitches;
  2035. end;
  2036. constructor tpointerdef.createfar(def:tdef);
  2037. begin
  2038. inherited create(pointerdef,def);
  2039. is_far:=true;
  2040. has_pointer_math:=cs_pointermath in current_settings.localswitches;
  2041. end;
  2042. constructor tpointerdef.ppuload(ppufile:tcompilerppufile);
  2043. begin
  2044. inherited ppuload(pointerdef,ppufile);
  2045. is_far:=(ppufile.getbyte<>0);
  2046. has_pointer_math:=(ppufile.getbyte<>0);
  2047. end;
  2048. function tpointerdef.getcopy : tstoreddef;
  2049. begin
  2050. { don't use direct pointeddef if it is a forwarddef because in other case
  2051. one of them will be destroyed on forward type resolve and the second will
  2052. point to garbage }
  2053. if pointeddef.typ=forwarddef then
  2054. result:=tpointerdef.create(tforwarddef(pointeddef).getcopy)
  2055. else
  2056. result:=tpointerdef.create(pointeddef);
  2057. tpointerdef(result).is_far:=is_far;
  2058. tpointerdef(result).has_pointer_math:=has_pointer_math;
  2059. tpointerdef(result).savesize:=savesize;
  2060. end;
  2061. procedure tpointerdef.ppuwrite(ppufile:tcompilerppufile);
  2062. begin
  2063. inherited ppuwrite(ppufile);
  2064. ppufile.putbyte(byte(is_far));
  2065. ppufile.putbyte(byte(has_pointer_math));
  2066. ppufile.writeentry(ibpointerdef);
  2067. end;
  2068. function tpointerdef.GetTypeName : string;
  2069. begin
  2070. if is_far then
  2071. GetTypeName:='^'+pointeddef.typename+';far'
  2072. else
  2073. GetTypeName:='^'+pointeddef.typename;
  2074. end;
  2075. {****************************************************************************
  2076. TCLASSREFDEF
  2077. ****************************************************************************}
  2078. constructor tclassrefdef.create(def:tdef);
  2079. begin
  2080. inherited create(classrefdef,def);
  2081. end;
  2082. constructor tclassrefdef.ppuload(ppufile:tcompilerppufile);
  2083. begin
  2084. inherited ppuload(classrefdef,ppufile);
  2085. end;
  2086. procedure tclassrefdef.ppuwrite(ppufile:tcompilerppufile);
  2087. begin
  2088. inherited ppuwrite(ppufile);
  2089. ppufile.writeentry(ibclassrefdef);
  2090. end;
  2091. function tclassrefdef.getcopy:tstoreddef;
  2092. begin
  2093. if pointeddef.typ=forwarddef then
  2094. result:=tclassrefdef.create(tforwarddef(pointeddef).getcopy)
  2095. else
  2096. result:=tclassrefdef.create(pointeddef);
  2097. tclassrefdef(result).savesize:=savesize;
  2098. end;
  2099. function tclassrefdef.GetTypeName : string;
  2100. begin
  2101. GetTypeName:='Class Of '+pointeddef.typename;
  2102. end;
  2103. function tclassrefdef.is_publishable : boolean;
  2104. begin
  2105. result:=true;
  2106. end;
  2107. function tclassrefdef.rtti_mangledname(rt: trttitype): string;
  2108. begin
  2109. if (tobjectdef(pointeddef).objecttype<>odt_objcclass) then
  2110. result:=inherited rtti_mangledname(rt)
  2111. else
  2112. result:=tobjectdef(pointeddef).rtti_mangledname(objcmetartti);
  2113. end;
  2114. procedure tclassrefdef.register_created_object_type;
  2115. begin
  2116. tobjectdef(pointeddef).register_created_classref_type;
  2117. end;
  2118. {***************************************************************************
  2119. TSETDEF
  2120. ***************************************************************************}
  2121. constructor tsetdef.create(def:tdef;low, high : asizeint);
  2122. var
  2123. setallocbits: aint;
  2124. packedsavesize: aint;
  2125. begin
  2126. inherited create(setdef);
  2127. elementdef:=def;
  2128. setmax:=high;
  2129. if (current_settings.setalloc=0) then
  2130. begin
  2131. setbase:=0;
  2132. if (high<32) then
  2133. savesize:=Sizeof(longint)
  2134. else if (high<256) then
  2135. savesize:=32
  2136. else
  2137. savesize:=(high+7) div 8
  2138. end
  2139. else
  2140. begin
  2141. setallocbits:=current_settings.setalloc*8;
  2142. setbase:=low and not(setallocbits-1);
  2143. packedsavesize:=current_settings.setalloc*((((high+setallocbits)-setbase)) DIV setallocbits);
  2144. savesize:=packedsavesize;
  2145. if savesize=3 then
  2146. savesize:=4;
  2147. end;
  2148. end;
  2149. constructor tsetdef.ppuload(ppufile:tcompilerppufile);
  2150. begin
  2151. inherited ppuload(setdef,ppufile);
  2152. ppufile.getderef(elementdefderef);
  2153. savesize:=ppufile.getaint;
  2154. setbase:=ppufile.getaint;
  2155. setmax:=ppufile.getaint;
  2156. end;
  2157. function tsetdef.getcopy : tstoreddef;
  2158. begin
  2159. result:=tsetdef.create(elementdef,setbase,setmax);
  2160. { the copy might have been created with a different setalloc setting }
  2161. tsetdef(result).savesize:=savesize;
  2162. end;
  2163. procedure tsetdef.ppuwrite(ppufile:tcompilerppufile);
  2164. begin
  2165. inherited ppuwrite(ppufile);
  2166. ppufile.putderef(elementdefderef);
  2167. ppufile.putaint(savesize);
  2168. ppufile.putaint(setbase);
  2169. ppufile.putaint(setmax);
  2170. ppufile.writeentry(ibsetdef);
  2171. end;
  2172. procedure tsetdef.buildderef;
  2173. begin
  2174. inherited buildderef;
  2175. elementdefderef.build(elementdef);
  2176. end;
  2177. procedure tsetdef.deref;
  2178. begin
  2179. inherited deref;
  2180. elementdef:=tdef(elementdefderef.resolve);
  2181. end;
  2182. function tsetdef.is_publishable : boolean;
  2183. begin
  2184. is_publishable:=savesize in [1,2,4];
  2185. end;
  2186. function tsetdef.GetTypeName : string;
  2187. begin
  2188. if assigned(elementdef) then
  2189. GetTypeName:='Set Of '+elementdef.typename
  2190. else
  2191. GetTypeName:='Empty Set';
  2192. end;
  2193. {***************************************************************************
  2194. TFORMALDEF
  2195. ***************************************************************************}
  2196. constructor tformaldef.create(Atyped:boolean);
  2197. begin
  2198. inherited create(formaldef);
  2199. typed:=Atyped;
  2200. savesize:=0;
  2201. end;
  2202. constructor tformaldef.ppuload(ppufile:tcompilerppufile);
  2203. begin
  2204. inherited ppuload(formaldef,ppufile);
  2205. typed:=boolean(ppufile.getbyte);
  2206. savesize:=0;
  2207. end;
  2208. procedure tformaldef.ppuwrite(ppufile:tcompilerppufile);
  2209. begin
  2210. inherited ppuwrite(ppufile);
  2211. ppufile.putbyte(byte(typed));
  2212. ppufile.writeentry(ibformaldef);
  2213. end;
  2214. function tformaldef.GetTypeName : string;
  2215. begin
  2216. if typed then
  2217. GetTypeName:='<Typed formal type>'
  2218. else
  2219. GetTypeName:='<Formal type>';
  2220. end;
  2221. {***************************************************************************
  2222. TARRAYDEF
  2223. ***************************************************************************}
  2224. constructor tarraydef.create(l,h:asizeint;def:tdef);
  2225. begin
  2226. inherited create(arraydef);
  2227. lowrange:=l;
  2228. highrange:=h;
  2229. rangedef:=def;
  2230. _elementdef:=nil;
  2231. arrayoptions:=[];
  2232. symtable:=tarraysymtable.create(self);
  2233. end;
  2234. destructor tarraydef.destroy;
  2235. begin
  2236. symtable.free;
  2237. symtable:=nil;
  2238. inherited;
  2239. end;
  2240. constructor tarraydef.create_from_pointer(def:tdef);
  2241. begin
  2242. { use -1 so that the elecount will not overflow }
  2243. self.create(0,high(aint)-1,s32inttype);
  2244. arrayoptions:=[ado_IsConvertedPointer];
  2245. setelementdef(def);
  2246. end;
  2247. constructor tarraydef.ppuload(ppufile:tcompilerppufile);
  2248. begin
  2249. inherited ppuload(arraydef,ppufile);
  2250. { the addresses are calculated later }
  2251. ppufile.getderef(_elementdefderef);
  2252. ppufile.getderef(rangedefderef);
  2253. lowrange:=ppufile.getaint;
  2254. highrange:=ppufile.getaint;
  2255. ppufile.getsmallset(arrayoptions);
  2256. symtable:=tarraysymtable.create(self);
  2257. tarraysymtable(symtable).ppuload(ppufile)
  2258. end;
  2259. function tarraydef.getcopy : tstoreddef;
  2260. begin
  2261. result:=tarraydef.create(lowrange,highrange,rangedef);
  2262. tarraydef(result).arrayoptions:=arrayoptions;
  2263. tarraydef(result)._elementdef:=_elementdef;
  2264. end;
  2265. procedure tarraydef.buildderef;
  2266. begin
  2267. inherited buildderef;
  2268. tarraysymtable(symtable).buildderef;
  2269. _elementdefderef.build(_elementdef);
  2270. rangedefderef.build(rangedef);
  2271. end;
  2272. procedure tarraydef.deref;
  2273. begin
  2274. inherited deref;
  2275. tarraysymtable(symtable).deref;
  2276. _elementdef:=tdef(_elementdefderef.resolve);
  2277. rangedef:=tdef(rangedefderef.resolve);
  2278. end;
  2279. procedure tarraydef.ppuwrite(ppufile:tcompilerppufile);
  2280. begin
  2281. inherited ppuwrite(ppufile);
  2282. ppufile.putderef(_elementdefderef);
  2283. ppufile.putderef(rangedefderef);
  2284. ppufile.putaint(lowrange);
  2285. ppufile.putaint(highrange);
  2286. ppufile.putsmallset(arrayoptions);
  2287. ppufile.writeentry(ibarraydef);
  2288. tarraysymtable(symtable).ppuwrite(ppufile);
  2289. end;
  2290. function tarraydef.elesize : asizeint;
  2291. begin
  2292. if (ado_IsBitPacked in arrayoptions) then
  2293. internalerror(2006080101);
  2294. if assigned(_elementdef) then
  2295. result:=_elementdef.size
  2296. else
  2297. result:=0;
  2298. end;
  2299. function tarraydef.elepackedbitsize : asizeint;
  2300. begin
  2301. if not(ado_IsBitPacked in arrayoptions) then
  2302. internalerror(2006080102);
  2303. if assigned(_elementdef) then
  2304. result:=_elementdef.packedbitsize
  2305. else
  2306. result:=0;
  2307. end;
  2308. function tarraydef.elecount : asizeuint;
  2309. var
  2310. qhigh,qlow : qword;
  2311. begin
  2312. if ado_IsDynamicArray in arrayoptions then
  2313. begin
  2314. result:=0;
  2315. exit;
  2316. end;
  2317. if (highrange>0) and (lowrange<0) then
  2318. begin
  2319. qhigh:=highrange;
  2320. qlow:=qword(-lowrange);
  2321. { prevent overflow, return 0 to indicate overflow }
  2322. if qhigh+qlow>qword(high(asizeint)-1) then
  2323. result:=0
  2324. else
  2325. result:=qhigh+qlow+1;
  2326. end
  2327. else
  2328. result:=int64(highrange)-lowrange+1;
  2329. end;
  2330. function tarraydef.size : asizeint;
  2331. var
  2332. cachedelecount : asizeuint;
  2333. cachedelesize : asizeint;
  2334. begin
  2335. if ado_IsDynamicArray in arrayoptions then
  2336. begin
  2337. size:=sizeof(pint);
  2338. exit;
  2339. end;
  2340. { Tarraydef.size may never be called for an open array! }
  2341. if highrange<lowrange then
  2342. internalerror(99080501);
  2343. if not (ado_IsBitPacked in arrayoptions) then
  2344. cachedelesize:=elesize
  2345. else
  2346. cachedelesize := elepackedbitsize;
  2347. cachedelecount:=elecount;
  2348. if (cachedelesize = 0) then
  2349. begin
  2350. size := 0;
  2351. exit;
  2352. end;
  2353. if (cachedelecount = 0) then
  2354. begin
  2355. size := -1;
  2356. exit;
  2357. end;
  2358. { prevent overflow, return -1 to indicate overflow }
  2359. { also make sure we don't need 64/128 bit arithmetic to calculate offsets }
  2360. if (cachedelecount > asizeuint(high(asizeint))) or
  2361. ((high(asizeint) div cachedelesize) < asizeint(cachedelecount)) or
  2362. { also lowrange*elesize must be < high(asizeint) to prevent overflow when
  2363. accessing the array, see ncgmem (PFV) }
  2364. ((high(asizeint) div cachedelesize) < abs(lowrange)) then
  2365. begin
  2366. result:=-1;
  2367. exit;
  2368. end;
  2369. result:=cachedelesize*asizeint(cachedelecount);
  2370. if (ado_IsBitPacked in arrayoptions) then
  2371. { can't just add 7 and divide by 8, because that may overflow }
  2372. result:=result div 8 + ord((result mod 8)<>0);
  2373. end;
  2374. procedure tarraydef.setelementdef(def:tdef);
  2375. begin
  2376. _elementdef:=def;
  2377. if not(
  2378. (ado_IsDynamicArray in arrayoptions) or
  2379. (ado_IsConvertedPointer in arrayoptions) or
  2380. (highrange<lowrange)
  2381. ) and
  2382. (size=-1) then
  2383. Message(sym_e_segment_too_large);
  2384. end;
  2385. function tarraydef.alignment : shortint;
  2386. begin
  2387. { alignment of dyn. arrays doesn't depend on the element size }
  2388. if (ado_IsDynamicArray in arrayoptions) then
  2389. alignment:=size_2_align(sizeof(pint))
  2390. { alignment is the alignment of the elements }
  2391. else if (elementdef.typ in [arraydef,recorddef,orddef,enumdef,floatdef]) or
  2392. ((elementdef.typ=objectdef) and
  2393. is_object(elementdef)) then
  2394. alignment:=elementdef.alignment
  2395. { alignment is the size of the elements }
  2396. else if not (ado_IsBitPacked in arrayoptions) then
  2397. alignment:=size_2_align(elesize)
  2398. else
  2399. alignment:=packedbitsloadsize(elepackedbitsize);
  2400. end;
  2401. function tarraydef.needs_inittable : boolean;
  2402. begin
  2403. needs_inittable:=(ado_IsDynamicArray in arrayoptions) or elementdef.needs_inittable;
  2404. end;
  2405. function tarraydef.GetTypeName : string;
  2406. begin
  2407. if (ado_IsConstString in arrayoptions) then
  2408. result:='Constant String'
  2409. else if (ado_isarrayofconst in arrayoptions) or
  2410. (ado_isConstructor in arrayoptions) then
  2411. begin
  2412. if (ado_isvariant in arrayoptions) or ((highrange=-1) and (lowrange=0)) then
  2413. GetTypeName:='Array Of Const'
  2414. else
  2415. GetTypeName:='Array Of Const/Constant Open Array of '+elementdef.typename;
  2416. end
  2417. else if (ado_IsDynamicArray in arrayoptions) then
  2418. GetTypeName:='Dynamic Array Of '+elementdef.typename
  2419. else if ((highrange=-1) and (lowrange=0)) then
  2420. GetTypeName:='Open Array Of '+elementdef.typename
  2421. else
  2422. begin
  2423. result := '';
  2424. if (ado_IsBitPacked in arrayoptions) then
  2425. result:='Packed ';
  2426. if rangedef.typ=enumdef then
  2427. result:=result+'Array['+rangedef.typename+'] Of '+elementdef.typename
  2428. else
  2429. result:=result+'Array['+tostr(lowrange)+'..'+
  2430. tostr(highrange)+'] Of '+elementdef.typename
  2431. end;
  2432. end;
  2433. function tarraydef.getmangledparaname : string;
  2434. begin
  2435. if ado_isarrayofconst in arrayoptions then
  2436. getmangledparaname:='array_of_const'
  2437. else
  2438. if ((highrange=-1) and (lowrange=0)) then
  2439. getmangledparaname:='array_of_'+elementdef.mangledparaname
  2440. else
  2441. internalerror(200204176);
  2442. end;
  2443. function tarraydef.is_publishable : boolean;
  2444. begin
  2445. Result:=ado_IsDynamicArray in arrayoptions;
  2446. end;
  2447. {***************************************************************************
  2448. tabstractrecorddef
  2449. ***************************************************************************}
  2450. constructor tabstractrecorddef.create(const n:string; dt:tdeftyp);
  2451. begin
  2452. inherited create(dt);
  2453. objname:=stringdup(upper(n));
  2454. objrealname:=stringdup(n);
  2455. objectoptions:=[];
  2456. end;
  2457. constructor tabstractrecorddef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  2458. begin
  2459. inherited ppuload(dt,ppufile);
  2460. objrealname:=stringdup(ppufile.getstring);
  2461. objname:=stringdup(upper(objrealname^));
  2462. ppufile.getsmallset(objectoptions);
  2463. end;
  2464. procedure tabstractrecorddef.ppuwrite(ppufile: tcompilerppufile);
  2465. begin
  2466. inherited ppuwrite(ppufile);
  2467. ppufile.putstring(objrealname^);
  2468. ppufile.putsmallset(objectoptions);
  2469. end;
  2470. destructor tabstractrecorddef.destroy;
  2471. begin
  2472. stringdispose(objname);
  2473. stringdispose(objrealname);
  2474. inherited destroy;
  2475. end;
  2476. procedure tabstractrecorddef.check_forwards;
  2477. begin
  2478. tstoredsymtable(symtable).check_forwards;
  2479. end;
  2480. function tabstractrecorddef.find_procdef_bytype(pt:tproctypeoption): tprocdef;
  2481. var
  2482. i: longint;
  2483. sym: tsym;
  2484. begin
  2485. for i:=0 to symtable.SymList.Count-1 do
  2486. begin
  2487. sym:=tsym(symtable.SymList[i]);
  2488. if sym.typ=procsym then
  2489. begin
  2490. result:=tprocsym(sym).find_procdef_bytype(pt);
  2491. if assigned(result) then
  2492. exit;
  2493. end;
  2494. end;
  2495. result:=nil;
  2496. end;
  2497. function tabstractrecorddef.GetSymtable(t:tGetSymtable):TSymtable;
  2498. begin
  2499. if t=gs_record then
  2500. GetSymtable:=symtable
  2501. else
  2502. GetSymtable:=nil;
  2503. end;
  2504. function tabstractrecorddef.is_packed:boolean;
  2505. begin
  2506. result:=tabstractrecordsymtable(symtable).is_packed;
  2507. end;
  2508. function tabstractrecorddef.RttiName: string;
  2509. begin
  2510. Result:=OwnerHierarchyName+objrealname^;
  2511. end;
  2512. function tabstractrecorddef.search_enumerator_get: tprocdef;
  2513. var
  2514. sym : tsym;
  2515. i : integer;
  2516. pd : tprocdef;
  2517. hashedid : THashedIDString;
  2518. begin
  2519. result:=nil;
  2520. hashedid.id:='GETENUMERATOR';
  2521. sym:=tsym(symtable.FindWithHash(hashedid));
  2522. if assigned(sym) and (sym.typ=procsym) then
  2523. begin
  2524. for i := 0 to Tprocsym(sym).ProcdefList.Count - 1 do
  2525. begin
  2526. pd := tprocdef(Tprocsym(sym).ProcdefList[i]);
  2527. if (pd.proctypeoption = potype_function) and
  2528. (is_class_or_interface_or_object(pd.returndef) or is_record(pd.returndef)) and
  2529. (pd.visibility >= vis_public) then
  2530. begin
  2531. result:=pd;
  2532. exit;
  2533. end;
  2534. end;
  2535. end;
  2536. end;
  2537. function tabstractrecorddef.search_enumerator_move: tprocdef;
  2538. var
  2539. sym : tsym;
  2540. i : integer;
  2541. pd : tprocdef;
  2542. hashedid : THashedIDString;
  2543. begin
  2544. result:=nil;
  2545. // first search for po_enumerator_movenext method modifier
  2546. // then search for public function MoveNext: Boolean
  2547. for i:=0 to symtable.SymList.Count-1 do
  2548. begin
  2549. sym:=TSym(symtable.SymList[i]);
  2550. if (sym.typ=procsym) then
  2551. begin
  2552. pd:=Tprocsym(sym).find_procdef_byoptions([po_enumerator_movenext]);
  2553. if assigned(pd) then
  2554. begin
  2555. result:=pd;
  2556. exit;
  2557. end;
  2558. end;
  2559. end;
  2560. hashedid.id:='MOVENEXT';
  2561. sym:=tsym(symtable.FindWithHash(hashedid));
  2562. if assigned(sym) and (sym.typ=procsym) then
  2563. begin
  2564. for i:=0 to Tprocsym(sym).ProcdefList.Count-1 do
  2565. begin
  2566. pd := tprocdef(Tprocsym(sym).ProcdefList[i]);
  2567. if (pd.proctypeoption = potype_function) and
  2568. is_boolean(pd.returndef) and
  2569. (pd.minparacount = 0) and
  2570. (pd.visibility >= vis_public) then
  2571. begin
  2572. result:=pd;
  2573. exit;
  2574. end;
  2575. end;
  2576. end;
  2577. end;
  2578. function tabstractrecorddef.search_enumerator_current: tsym;
  2579. var
  2580. sym: tsym;
  2581. i: integer;
  2582. hashedid : THashedIDString;
  2583. begin
  2584. result:=nil;
  2585. // first search for ppo_enumerator_current property modifier
  2586. // then search for public property Current
  2587. for i:=0 to symtable.SymList.Count-1 do
  2588. begin
  2589. sym:=TSym(symtable.SymList[i]);
  2590. if (sym.typ=propertysym) and (ppo_enumerator_current in tpropertysym(sym).propoptions) then
  2591. begin
  2592. result:=sym;
  2593. exit;
  2594. end;
  2595. end;
  2596. hashedid.id:='CURRENT';
  2597. sym:=tsym(symtable.FindWithHash(hashedid));
  2598. if assigned(sym) and (sym.typ=propertysym) and
  2599. (sym.visibility >= vis_public) and not tpropertysym(sym).propaccesslist[palt_read].empty then
  2600. begin
  2601. result:=sym;
  2602. exit;
  2603. end;
  2604. end;
  2605. {***************************************************************************
  2606. trecorddef
  2607. ***************************************************************************}
  2608. constructor trecorddef.create(const n:string; p:TSymtable);
  2609. begin
  2610. inherited create(n,recorddef);
  2611. symtable:=p;
  2612. { we can own the symtable only if nobody else owns a copy so far }
  2613. if symtable.refcount=1 then
  2614. symtable.defowner:=self;
  2615. isunion:=false;
  2616. end;
  2617. constructor trecorddef.ppuload(ppufile:tcompilerppufile);
  2618. begin
  2619. inherited ppuload(recorddef,ppufile);
  2620. if df_copied_def in defoptions then
  2621. ppufile.getderef(cloneddefderef)
  2622. else
  2623. begin
  2624. symtable:=trecordsymtable.create(objrealname^,0);
  2625. trecordsymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  2626. trecordsymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  2627. trecordsymtable(symtable).padalignment:=shortint(ppufile.getbyte);
  2628. trecordsymtable(symtable).usefieldalignment:=shortint(ppufile.getbyte);
  2629. trecordsymtable(symtable).datasize:=ppufile.getasizeint;
  2630. trecordsymtable(symtable).paddingsize:=ppufile.getword;
  2631. trecordsymtable(symtable).ppuload(ppufile);
  2632. { requires usefieldalignment to be set }
  2633. symtable.defowner:=self;
  2634. end;
  2635. isunion:=false;
  2636. end;
  2637. destructor trecorddef.destroy;
  2638. begin
  2639. if assigned(symtable) then
  2640. begin
  2641. symtable.free;
  2642. symtable:=nil;
  2643. end;
  2644. inherited destroy;
  2645. end;
  2646. function trecorddef.getcopy : tstoreddef;
  2647. begin
  2648. result:=trecorddef.create(objrealname^,symtable.getcopy);
  2649. trecorddef(result).isunion:=isunion;
  2650. include(trecorddef(result).defoptions,df_copied_def);
  2651. end;
  2652. function trecorddef.needs_inittable : boolean;
  2653. begin
  2654. needs_inittable:=trecordsymtable(symtable).needs_init_final
  2655. end;
  2656. procedure trecorddef.buildderef;
  2657. begin
  2658. inherited buildderef;
  2659. if df_copied_def in defoptions then
  2660. cloneddefderef.build(symtable.defowner)
  2661. else
  2662. tstoredsymtable(symtable).buildderef;
  2663. end;
  2664. procedure trecorddef.deref;
  2665. begin
  2666. inherited deref;
  2667. { now dereference the definitions }
  2668. if df_copied_def in defoptions then
  2669. begin
  2670. cloneddef:=trecorddef(cloneddefderef.resolve);
  2671. symtable:=cloneddef.symtable.getcopy;
  2672. end
  2673. else
  2674. tstoredsymtable(symtable).deref;
  2675. { assign TGUID? load only from system unit }
  2676. if not(assigned(rec_tguid)) and
  2677. (upper(typename)='TGUID') and
  2678. assigned(owner) and
  2679. assigned(owner.name) and
  2680. (owner.name^='SYSTEM') then
  2681. rec_tguid:=self;
  2682. { assign JMP_BUF? load only from system unit }
  2683. if not(assigned(rec_jmp_buf)) and
  2684. (upper(typename)='JMP_BUF') and
  2685. assigned(owner) and
  2686. assigned(owner.name) and
  2687. (owner.name^='SYSTEM') then
  2688. rec_jmp_buf:=self;
  2689. end;
  2690. procedure trecorddef.ppuwrite(ppufile:tcompilerppufile);
  2691. begin
  2692. inherited ppuwrite(ppufile);
  2693. if df_copied_def in defoptions then
  2694. ppufile.putderef(cloneddefderef)
  2695. else
  2696. begin
  2697. ppufile.putbyte(byte(trecordsymtable(symtable).fieldalignment));
  2698. ppufile.putbyte(byte(trecordsymtable(symtable).recordalignment));
  2699. ppufile.putbyte(byte(trecordsymtable(symtable).padalignment));
  2700. ppufile.putbyte(byte(trecordsymtable(symtable).usefieldalignment));
  2701. ppufile.putasizeint(trecordsymtable(symtable).datasize);
  2702. ppufile.putword(trecordsymtable(symtable).paddingsize);
  2703. end;
  2704. ppufile.writeentry(ibrecorddef);
  2705. if not(df_copied_def in defoptions) then
  2706. trecordsymtable(symtable).ppuwrite(ppufile);
  2707. end;
  2708. function trecorddef.size:asizeint;
  2709. begin
  2710. result:=trecordsymtable(symtable).datasize;
  2711. end;
  2712. function trecorddef.alignment:shortint;
  2713. begin
  2714. alignment:=trecordsymtable(symtable).recordalignment;
  2715. end;
  2716. function trecorddef.padalignment:shortint;
  2717. begin
  2718. padalignment := trecordsymtable(symtable).padalignment;
  2719. end;
  2720. function trecorddef.GetTypeName : string;
  2721. begin
  2722. GetTypeName:='<record type>'
  2723. end;
  2724. {***************************************************************************
  2725. TABSTRACTPROCDEF
  2726. ***************************************************************************}
  2727. constructor tabstractprocdef.create(dt:tdeftyp;level:byte);
  2728. begin
  2729. inherited create(dt);
  2730. parast:=tparasymtable.create(self,level);
  2731. paras:=nil;
  2732. minparacount:=0;
  2733. maxparacount:=0;
  2734. proctypeoption:=potype_none;
  2735. proccalloption:=pocall_none;
  2736. procoptions:=[];
  2737. returndef:=voidtype;
  2738. savesize:=sizeof(pint);
  2739. callerargareasize:=0;
  2740. calleeargareasize:=0;
  2741. has_paraloc_info:=callnoside;
  2742. funcretloc[callerside].init;
  2743. funcretloc[calleeside].init;
  2744. check_mark_as_nested;
  2745. end;
  2746. destructor tabstractprocdef.destroy;
  2747. begin
  2748. if assigned(paras) then
  2749. begin
  2750. {$ifdef MEMDEBUG}
  2751. memprocpara.start;
  2752. {$endif MEMDEBUG}
  2753. paras.free;
  2754. paras:=nil;
  2755. {$ifdef MEMDEBUG}
  2756. memprocpara.stop;
  2757. {$endif MEMDEBUG}
  2758. end;
  2759. if assigned(parast) then
  2760. begin
  2761. {$ifdef MEMDEBUG}
  2762. memprocparast.start;
  2763. {$endif MEMDEBUG}
  2764. parast.free;
  2765. parast:=nil;
  2766. {$ifdef MEMDEBUG}
  2767. memprocparast.stop;
  2768. {$endif MEMDEBUG}
  2769. end;
  2770. funcretloc[callerside].done;
  2771. funcretloc[calleeside].done;
  2772. inherited destroy;
  2773. end;
  2774. procedure tabstractprocdef.count_para(p:TObject;arg:pointer);
  2775. begin
  2776. if (tsym(p).typ<>paravarsym) then
  2777. exit;
  2778. inc(plongint(arg)^);
  2779. if not(vo_is_hidden_para in tparavarsym(p).varoptions) then
  2780. begin
  2781. if not assigned(tparavarsym(p).defaultconstsym) then
  2782. inc(minparacount);
  2783. inc(maxparacount);
  2784. end;
  2785. end;
  2786. procedure tabstractprocdef.insert_para(p:TObject;arg:pointer);
  2787. begin
  2788. if (tsym(p).typ<>paravarsym) then
  2789. exit;
  2790. paras.add(p);
  2791. end;
  2792. procedure tabstractprocdef.calcparas;
  2793. var
  2794. paracount : longint;
  2795. begin
  2796. { This can already be assigned when
  2797. we need to reresolve this unit (PFV) }
  2798. if assigned(paras) then
  2799. paras.free;
  2800. paras:=tparalist.create(false);
  2801. paracount:=0;
  2802. minparacount:=0;
  2803. maxparacount:=0;
  2804. parast.SymList.ForEachCall(@count_para,@paracount);
  2805. paras.capacity:=paracount;
  2806. { Insert parameters in table }
  2807. parast.SymList.ForEachCall(@insert_para,nil);
  2808. { Order parameters }
  2809. paras.sortparas;
  2810. end;
  2811. procedure tabstractprocdef.buildderef;
  2812. begin
  2813. { released procdef? }
  2814. if not assigned(parast) then
  2815. exit;
  2816. inherited buildderef;
  2817. returndefderef.build(returndef);
  2818. { parast }
  2819. tparasymtable(parast).buildderef;
  2820. end;
  2821. procedure tabstractprocdef.deref;
  2822. begin
  2823. inherited deref;
  2824. returndef:=tdef(returndefderef.resolve);
  2825. { parast }
  2826. tparasymtable(parast).deref;
  2827. { recalculated parameters }
  2828. calcparas;
  2829. end;
  2830. constructor tabstractprocdef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  2831. begin
  2832. inherited ppuload(dt,ppufile);
  2833. parast:=nil;
  2834. Paras:=nil;
  2835. minparacount:=0;
  2836. maxparacount:=0;
  2837. ppufile.getderef(returndefderef);
  2838. { TODO: remove fpu_used loading}
  2839. ppufile.getbyte;
  2840. proctypeoption:=tproctypeoption(ppufile.getbyte);
  2841. proccalloption:=tproccalloption(ppufile.getbyte);
  2842. ppufile.getnormalset(procoptions);
  2843. funcretloc[callerside].init;
  2844. if po_explicitparaloc in procoptions then
  2845. funcretloc[callerside].ppuload(ppufile);
  2846. savesize:=sizeof(pint);
  2847. if (po_explicitparaloc in procoptions) then
  2848. has_paraloc_info:=callerside;
  2849. end;
  2850. procedure tabstractprocdef.ppuwrite(ppufile:tcompilerppufile);
  2851. var
  2852. oldintfcrc : boolean;
  2853. begin
  2854. { released procdef? }
  2855. if not assigned(parast) then
  2856. exit;
  2857. inherited ppuwrite(ppufile);
  2858. ppufile.putderef(returndefderef);
  2859. oldintfcrc:=ppufile.do_interface_crc;
  2860. ppufile.do_interface_crc:=false;
  2861. ppufile.putbyte(0);
  2862. ppufile.putbyte(ord(proctypeoption));
  2863. ppufile.putbyte(ord(proccalloption));
  2864. ppufile.putnormalset(procoptions);
  2865. ppufile.do_interface_crc:=oldintfcrc;
  2866. if (po_explicitparaloc in procoptions) then
  2867. funcretloc[callerside].ppuwrite(ppufile);
  2868. end;
  2869. function tabstractprocdef.typename_paras(showhidden:boolean) : string;
  2870. var
  2871. hs,s : string;
  2872. hp : TParavarsym;
  2873. hpc : tconstsym;
  2874. first : boolean;
  2875. i : integer;
  2876. begin
  2877. s:='';
  2878. first:=true;
  2879. for i:=0 to paras.count-1 do
  2880. begin
  2881. hp:=tparavarsym(paras[i]);
  2882. if not(vo_is_hidden_para in hp.varoptions) or
  2883. (showhidden) then
  2884. begin
  2885. if first then
  2886. begin
  2887. s:=s+'(';
  2888. first:=false;
  2889. end
  2890. else
  2891. s:=s+',';
  2892. if vo_is_hidden_para in hp.varoptions then
  2893. s:=s+'<';
  2894. case hp.varspez of
  2895. vs_var :
  2896. s:=s+'var ';
  2897. vs_const :
  2898. s:=s+'const ';
  2899. vs_out :
  2900. s:=s+'out ';
  2901. vs_constref :
  2902. s:=s+'constref ';
  2903. end;
  2904. if hp.univpara then
  2905. s:=s+'univ ';
  2906. if assigned(hp.vardef.typesym) then
  2907. begin
  2908. hs:=hp.vardef.typesym.realname;
  2909. if hs[1]<>'$' then
  2910. s:=s+hs
  2911. else
  2912. s:=s+hp.vardef.GetTypeName;
  2913. end
  2914. else
  2915. s:=s+hp.vardef.GetTypeName;
  2916. { default value }
  2917. if assigned(hp.defaultconstsym) then
  2918. begin
  2919. hpc:=tconstsym(hp.defaultconstsym);
  2920. hs:='';
  2921. case hpc.consttyp of
  2922. conststring,
  2923. constresourcestring :
  2924. begin
  2925. If hpc.value.len>0 then
  2926. begin
  2927. setLength(hs,hpc.value.len);
  2928. { don't write past the end of hs if the constant
  2929. is > 255 chars }
  2930. move(hpc.value.valueptr^,hs[1],length(hs));
  2931. { make sure that constant strings with newline chars
  2932. don't create a linebreak in the assembler code,
  2933. since comments are line-based. Also remove nulls
  2934. because the comments are written as a pchar. }
  2935. ReplaceCase(hs,#0,'.');
  2936. ReplaceCase(hs,#10,'.');
  2937. ReplaceCase(hs,#13,'.');
  2938. end;
  2939. end;
  2940. constreal :
  2941. str(pbestreal(hpc.value.valueptr)^,hs);
  2942. constpointer :
  2943. hs:=tostr(hpc.value.valueordptr);
  2944. constord :
  2945. begin
  2946. if is_boolean(hpc.constdef) then
  2947. begin
  2948. if hpc.value.valueord<>0 then
  2949. hs:='TRUE'
  2950. else
  2951. hs:='FALSE';
  2952. end
  2953. else
  2954. hs:=tostr(hpc.value.valueord);
  2955. end;
  2956. constnil :
  2957. hs:='nil';
  2958. constset :
  2959. hs:='<set>';
  2960. end;
  2961. if hs<>'' then
  2962. s:=s+'="'+hs+'"';
  2963. end;
  2964. if vo_is_hidden_para in hp.varoptions then
  2965. s:=s+'>';
  2966. end;
  2967. end;
  2968. if not first then
  2969. s:=s+')';
  2970. if (po_varargs in procoptions) then
  2971. s:=s+';VarArgs';
  2972. typename_paras:=s;
  2973. end;
  2974. function tabstractprocdef.is_methodpointer:boolean;
  2975. begin
  2976. result:=false;
  2977. end;
  2978. function tabstractprocdef.is_addressonly:boolean;
  2979. begin
  2980. result:=true;
  2981. end;
  2982. function tabstractprocdef.no_self_node: boolean;
  2983. begin
  2984. Result:=([po_staticmethod,po_classmethod]<=procoptions)or
  2985. (proctypeoption in [potype_class_constructor,potype_class_destructor,potype_operator]);
  2986. end;
  2987. procedure tabstractprocdef.check_mark_as_nested;
  2988. begin
  2989. { nested procvars require that nested functions use the Delphi-style
  2990. nested procedure calling convention }
  2991. if (parast.symtablelevel>normal_function_level) and
  2992. (m_nested_procvars in current_settings.modeswitches) then
  2993. include(procoptions,po_delphi_nested_cc);
  2994. end;
  2995. procedure tabstractprocdef.init_paraloc_info(side: tcallercallee);
  2996. begin
  2997. if (side in [callerside,callbothsides]) and
  2998. not(has_paraloc_info in [callerside,callbothsides]) then
  2999. begin
  3000. callerargareasize:=paramanager.create_paraloc_info(self,callerside);
  3001. if has_paraloc_info in [calleeside,callbothsides] then
  3002. has_paraloc_info:=callbothsides
  3003. else
  3004. has_paraloc_info:=callerside;
  3005. end;
  3006. if (side in [calleeside,callbothsides]) and
  3007. not(has_paraloc_info in [calleeside,callbothsides]) then
  3008. begin
  3009. calleeargareasize:=paramanager.create_paraloc_info(self,calleeside);
  3010. if has_paraloc_info in [callerside,callbothsides] then
  3011. has_paraloc_info:=callbothsides
  3012. else
  3013. has_paraloc_info:=calleeside;
  3014. end;
  3015. end;
  3016. function tabstractprocdef.stack_tainting_parameter(side: tcallercallee): boolean;
  3017. var
  3018. p: tparavarsym;
  3019. ploc: PCGParalocation;
  3020. i: longint;
  3021. begin
  3022. result:=false;
  3023. init_paraloc_info(side);
  3024. for i:=0 to parast.SymList.Count-1 do
  3025. if tsym(parast.SymList[i]).typ=paravarsym then
  3026. begin
  3027. p:=tparavarsym(parast.SymList[i]);
  3028. { check if no parameter is located on the stack }
  3029. if is_open_array(p.vardef) or
  3030. is_array_of_const(p.vardef) then
  3031. begin
  3032. result:=true;
  3033. exit;
  3034. end;
  3035. ploc:=p.paraloc[side].location;
  3036. while assigned(ploc) do
  3037. begin
  3038. if (ploc^.loc=LOC_REFERENCE) then
  3039. begin
  3040. result:=true;
  3041. exit
  3042. end;
  3043. ploc:=ploc^.next;
  3044. end;
  3045. end;
  3046. end;
  3047. {***************************************************************************
  3048. TPROCDEF
  3049. ***************************************************************************}
  3050. constructor tprocdef.create(level:byte);
  3051. begin
  3052. inherited create(procdef,level);
  3053. localst:=tlocalsymtable.create(self,parast.symtablelevel);
  3054. _mangledname:=nil;
  3055. fileinfo:=current_filepos;
  3056. extnumber:=$ffff;
  3057. aliasnames:=TCmdStrList.create;
  3058. funcretsym:=nil;
  3059. forwarddef:=true;
  3060. interfacedef:=false;
  3061. hasforward:=false;
  3062. struct := nil;
  3063. import_dll:=nil;
  3064. import_name:=nil;
  3065. import_nr:=0;
  3066. inlininginfo:=nil;
  3067. deprecatedmsg:=nil;
  3068. {$ifdef i386}
  3069. fpu_used:=maxfpuregs;
  3070. {$endif i386}
  3071. interruptvector:=-1;
  3072. end;
  3073. constructor tprocdef.ppuload(ppufile:tcompilerppufile);
  3074. var
  3075. i,aliasnamescount : longint;
  3076. level : byte;
  3077. begin
  3078. inherited ppuload(procdef,ppufile);
  3079. if po_has_mangledname in procoptions then
  3080. _mangledname:=stringdup(ppufile.getstring)
  3081. else
  3082. _mangledname:=nil;
  3083. extnumber:=ppufile.getword;
  3084. level:=ppufile.getbyte;
  3085. ppufile.getderef(structderef);
  3086. ppufile.getderef(procsymderef);
  3087. ppufile.getposinfo(fileinfo);
  3088. visibility:=tvisibility(ppufile.getbyte);
  3089. ppufile.getsmallset(symoptions);
  3090. if sp_has_deprecated_msg in symoptions then
  3091. deprecatedmsg:=stringdup(ppufile.getstring)
  3092. else
  3093. deprecatedmsg:=nil;
  3094. {$ifdef powerpc}
  3095. { library symbol for AmigaOS/MorphOS }
  3096. ppufile.getderef(libsymderef);
  3097. {$endif powerpc}
  3098. { import stuff }
  3099. if po_has_importdll in procoptions then
  3100. import_dll:=stringdup(ppufile.getstring)
  3101. else
  3102. import_dll:=nil;
  3103. if po_has_importname in procoptions then
  3104. import_name:=stringdup(ppufile.getstring)
  3105. else
  3106. import_name:=nil;
  3107. import_nr:=ppufile.getword;
  3108. {$ifdef FPC_HAS_SYSTEMS_INTERRUPT_TABLE}
  3109. if target_info.system in systems_interrupt_table then
  3110. interruptvector:=ppufile.getlongint;
  3111. {$endif FPC_HAS_SYSTEMS_INTERRUPT_TABLE}
  3112. if (po_msgint in procoptions) then
  3113. messageinf.i:=ppufile.getlongint;
  3114. if (po_msgstr in procoptions) then
  3115. messageinf.str:=stringdup(ppufile.getstring);
  3116. if (po_dispid in procoptions) then
  3117. dispid:=ppufile.getlongint;
  3118. { inline stuff }
  3119. if (po_has_inlininginfo in procoptions) then
  3120. begin
  3121. ppufile.getderef(funcretsymderef);
  3122. new(inlininginfo);
  3123. ppufile.getsmallset(inlininginfo^.flags);
  3124. end
  3125. else
  3126. begin
  3127. inlininginfo:=nil;
  3128. funcretsym:=nil;
  3129. end;
  3130. aliasnames:=TCmdStrList.create;
  3131. { count alias names }
  3132. aliasnamescount:=ppufile.getbyte;
  3133. for i:=1 to aliasnamescount do
  3134. aliasnames.insert(ppufile.getstring);
  3135. { load para symtable }
  3136. parast:=tparasymtable.create(self,level);
  3137. tparasymtable(parast).ppuload(ppufile);
  3138. { load local symtable }
  3139. if (po_has_inlininginfo in procoptions) then
  3140. begin
  3141. localst:=tlocalsymtable.create(self,level);
  3142. tlocalsymtable(localst).ppuload(ppufile);
  3143. end
  3144. else
  3145. localst:=nil;
  3146. { inline stuff }
  3147. if (po_has_inlininginfo in procoptions) then
  3148. inlininginfo^.code:=ppuloadnodetree(ppufile);
  3149. { default values for no persistent data }
  3150. if (cs_link_deffile in current_settings.globalswitches) and
  3151. (tf_need_export in target_info.flags) and
  3152. (po_exports in procoptions) then
  3153. deffile.AddExport(mangledname);
  3154. forwarddef:=false;
  3155. interfacedef:=false;
  3156. hasforward:=false;
  3157. { Disable po_has_inlining until the derefimpl is done }
  3158. exclude(procoptions,po_has_inlininginfo);
  3159. {$ifdef i386}
  3160. fpu_used:=maxfpuregs;
  3161. {$endif i386}
  3162. end;
  3163. destructor tprocdef.destroy;
  3164. begin
  3165. aliasnames.free;
  3166. aliasnames:=nil;
  3167. if assigned(localst) and
  3168. (localst.symtabletype<>staticsymtable) then
  3169. begin
  3170. {$ifdef MEMDEBUG}
  3171. memproclocalst.start;
  3172. {$endif MEMDEBUG}
  3173. localst.free;
  3174. localst:=nil;
  3175. {$ifdef MEMDEBUG}
  3176. memproclocalst.start;
  3177. {$endif MEMDEBUG}
  3178. end;
  3179. if assigned(inlininginfo) then
  3180. begin
  3181. {$ifdef MEMDEBUG}
  3182. memprocnodetree.start;
  3183. {$endif MEMDEBUG}
  3184. tnode(inlininginfo^.code).free;
  3185. {$ifdef MEMDEBUG}
  3186. memprocnodetree.start;
  3187. {$endif MEMDEBUG}
  3188. dispose(inlininginfo);
  3189. inlininginfo:=nil;
  3190. end;
  3191. {$ifdef jvm}
  3192. exprasmlist.free;
  3193. {$endif}
  3194. stringdispose(resultname);
  3195. stringdispose(import_dll);
  3196. stringdispose(import_name);
  3197. stringdispose(deprecatedmsg);
  3198. if (po_msgstr in procoptions) then
  3199. stringdispose(messageinf.str);
  3200. if assigned(_mangledname) then
  3201. begin
  3202. {$ifdef MEMDEBUG}
  3203. memmanglednames.start;
  3204. {$endif MEMDEBUG}
  3205. stringdispose(_mangledname);
  3206. {$ifdef MEMDEBUG}
  3207. memmanglednames.stop;
  3208. {$endif MEMDEBUG}
  3209. end;
  3210. inherited destroy;
  3211. end;
  3212. procedure tprocdef.ppuwrite(ppufile:tcompilerppufile);
  3213. var
  3214. oldintfcrc : boolean;
  3215. aliasnamescount : longint;
  3216. item : TCmdStrListItem;
  3217. begin
  3218. { released procdef? }
  3219. if not assigned(parast) then
  3220. exit;
  3221. inherited ppuwrite(ppufile);
  3222. if po_has_mangledname in procoptions then
  3223. ppufile.putstring(_mangledname^);
  3224. ppufile.putword(extnumber);
  3225. ppufile.putbyte(parast.symtablelevel);
  3226. ppufile.putderef(structderef);
  3227. ppufile.putderef(procsymderef);
  3228. ppufile.putposinfo(fileinfo);
  3229. ppufile.putbyte(byte(visibility));
  3230. ppufile.putsmallset(symoptions);
  3231. if sp_has_deprecated_msg in symoptions then
  3232. ppufile.putstring(deprecatedmsg^);
  3233. {$ifdef powerpc}
  3234. { library symbol for AmigaOS/MorphOS }
  3235. ppufile.putderef(libsymderef);
  3236. {$endif powerpc}
  3237. { import }
  3238. if po_has_importdll in procoptions then
  3239. ppufile.putstring(import_dll^);
  3240. if po_has_importname in procoptions then
  3241. ppufile.putstring(import_name^);
  3242. ppufile.putword(import_nr);
  3243. {$ifdef FPC_HAS_SYSTEMS_INTERRUPT_TABLE}
  3244. if target_info.system in systems_interrupt_table then
  3245. ppufile.putlongint(interruptvector);
  3246. {$endif FPC_HAS_SYSTEMS_INTERRUPT_TABLE}
  3247. if (po_msgint in procoptions) then
  3248. ppufile.putlongint(messageinf.i);
  3249. if (po_msgstr in procoptions) then
  3250. ppufile.putstring(messageinf.str^);
  3251. if (po_dispid in procoptions) then
  3252. ppufile.putlongint(dispid);
  3253. { inline stuff }
  3254. oldintfcrc:=ppufile.do_crc;
  3255. ppufile.do_crc:=false;
  3256. if (po_has_inlininginfo in procoptions) then
  3257. begin
  3258. ppufile.putderef(funcretsymderef);
  3259. ppufile.putsmallset(inlininginfo^.flags);
  3260. end;
  3261. { count alias names }
  3262. aliasnamescount:=0;
  3263. item:=TCmdStrListItem(aliasnames.first);
  3264. while assigned(item) do
  3265. begin
  3266. inc(aliasnamescount);
  3267. item:=TCmdStrListItem(item.next);
  3268. end;
  3269. if aliasnamescount>255 then
  3270. internalerror(200711021);
  3271. ppufile.putbyte(aliasnamescount);
  3272. item:=TCmdStrListItem(aliasnames.first);
  3273. while assigned(item) do
  3274. begin
  3275. ppufile.putstring(item.str);
  3276. item:=TCmdStrListItem(item.next);
  3277. end;
  3278. ppufile.do_crc:=oldintfcrc;
  3279. { write this entry }
  3280. ppufile.writeentry(ibprocdef);
  3281. { Save the para symtable, this is taken from the interface }
  3282. tparasymtable(parast).ppuwrite(ppufile);
  3283. { save localsymtable for inline procedures or when local
  3284. browser info is requested, this has no influence on the crc }
  3285. if (po_has_inlininginfo in procoptions) then
  3286. begin
  3287. oldintfcrc:=ppufile.do_crc;
  3288. ppufile.do_crc:=false;
  3289. tlocalsymtable(localst).ppuwrite(ppufile);
  3290. ppufile.do_crc:=oldintfcrc;
  3291. end;
  3292. { node tree for inlining }
  3293. oldintfcrc:=ppufile.do_crc;
  3294. ppufile.do_crc:=false;
  3295. if (po_has_inlininginfo in procoptions) then
  3296. ppuwritenodetree(ppufile,inlininginfo^.code);
  3297. ppufile.do_crc:=oldintfcrc;
  3298. end;
  3299. function tprocdef.fullprocname(showhidden:boolean):string;
  3300. var
  3301. s : string;
  3302. t : ttoken;
  3303. begin
  3304. {$ifdef EXTDEBUG}
  3305. showhidden:=true;
  3306. {$endif EXTDEBUG}
  3307. s:='';
  3308. if assigned(struct) then
  3309. begin
  3310. s:=struct.RttiName+'.';
  3311. if (po_classmethod in procoptions) and
  3312. not (proctypeoption in [potype_class_constructor,potype_class_destructor]) then
  3313. s:='class ' + s;
  3314. end;
  3315. if proctypeoption=potype_operator then
  3316. begin
  3317. for t:=NOTOKEN to last_overloaded do
  3318. if procsym.realname='$'+overloaded_names[t] then
  3319. begin
  3320. s:='operator '+arraytokeninfo[t].str+typename_paras(showhidden);
  3321. break;
  3322. end;
  3323. end
  3324. else
  3325. s:=s+procsym.realname+typename_paras(showhidden);
  3326. case proctypeoption of
  3327. potype_constructor:
  3328. s:='constructor '+s;
  3329. potype_destructor:
  3330. s:='destructor '+s;
  3331. potype_class_constructor:
  3332. s:='class constructor '+s;
  3333. potype_class_destructor:
  3334. s:='class destructor '+s;
  3335. else
  3336. if assigned(returndef) and
  3337. not(is_void(returndef)) then
  3338. s:=s+':'+returndef.GetTypeName;
  3339. end;
  3340. if owner.symtabletype=localsymtable then
  3341. s:=s+' is nested';
  3342. s:=s+';';
  3343. { forced calling convention? }
  3344. if (po_hascallingconvention in procoptions) then
  3345. s:=s+' '+ProcCallOptionStr[proccalloption]+';';
  3346. if (po_staticmethod in procoptions) and
  3347. not (proctypeoption in [potype_class_constructor,potype_class_destructor]) then
  3348. s:=s+' Static;';
  3349. fullprocname:=s;
  3350. end;
  3351. function tprocdef.is_methodpointer:boolean;
  3352. begin
  3353. { don't check assigned(_class), that's also the case for nested
  3354. procedures inside methods }
  3355. result:=owner.symtabletype=ObjectSymtable;
  3356. end;
  3357. function tprocdef.is_addressonly:boolean;
  3358. begin
  3359. result:=assigned(owner) and
  3360. (owner.symtabletype<>ObjectSymtable) and
  3361. (not(m_nested_procvars in current_settings.modeswitches) or
  3362. not is_nested_pd(self));
  3363. end;
  3364. procedure tprocdef.make_external;
  3365. begin
  3366. include(procoptions,po_external);
  3367. forwarddef:=false;
  3368. end;
  3369. function tprocdef.GetSymtable(t:tGetSymtable):TSymtable;
  3370. begin
  3371. case t of
  3372. gs_local :
  3373. GetSymtable:=localst;
  3374. gs_para :
  3375. GetSymtable:=parast;
  3376. else
  3377. GetSymtable:=nil;
  3378. end;
  3379. end;
  3380. procedure tprocdef.buildderef;
  3381. begin
  3382. inherited buildderef;
  3383. structderef.build(struct);
  3384. { procsym that originaly defined this definition, should be in the
  3385. same symtable }
  3386. procsymderef.build(procsym);
  3387. {$ifdef powerpc}
  3388. { library symbol for AmigaOS/MorphOS }
  3389. libsymderef.build(libsym);
  3390. {$endif powerpc}
  3391. end;
  3392. procedure tprocdef.buildderefimpl;
  3393. begin
  3394. inherited buildderefimpl;
  3395. { Localst is not available for main/unit init }
  3396. if assigned(localst) then
  3397. begin
  3398. tlocalsymtable(localst).buildderef;
  3399. tlocalsymtable(localst).buildderefimpl;
  3400. end;
  3401. { inline tree }
  3402. if (po_has_inlininginfo in procoptions) then
  3403. begin
  3404. funcretsymderef.build(funcretsym);
  3405. inlininginfo^.code.buildderefimpl;
  3406. end;
  3407. end;
  3408. procedure tprocdef.deref;
  3409. begin
  3410. inherited deref;
  3411. struct:=tabstractrecorddef(structderef.resolve);
  3412. { procsym that originaly defined this definition, should be in the
  3413. same symtable }
  3414. procsym:=tprocsym(procsymderef.resolve);
  3415. {$ifdef powerpc}
  3416. { library symbol for AmigaOS/MorphOS }
  3417. libsym:=tsym(libsymderef.resolve);
  3418. {$endif powerpc}
  3419. end;
  3420. procedure tprocdef.derefimpl;
  3421. begin
  3422. { Enable has_inlininginfo when the inlininginfo
  3423. structure is available. The has_inlininginfo was disabled
  3424. after the load, since the data was invalid }
  3425. if assigned(inlininginfo) then
  3426. include(procoptions,po_has_inlininginfo);
  3427. { Locals }
  3428. if assigned(localst) then
  3429. begin
  3430. tlocalsymtable(localst).deref;
  3431. tlocalsymtable(localst).derefimpl;
  3432. end;
  3433. { Inline }
  3434. if (po_has_inlininginfo in procoptions) then
  3435. begin
  3436. inlininginfo^.code.derefimpl;
  3437. { funcretsym, this is always located in the localst }
  3438. funcretsym:=tsym(funcretsymderef.resolve);
  3439. end
  3440. else
  3441. begin
  3442. { safety }
  3443. { Not safe! A unit may be reresolved after its interface has been
  3444. parsed but before its implementation has been parsed, and in that
  3445. case the funcretsym is still required!
  3446. funcretsym:=nil; }
  3447. end;
  3448. end;
  3449. function tprocdef.GetTypeName : string;
  3450. begin
  3451. GetTypeName := FullProcName(false);
  3452. end;
  3453. function tprocdef.mangledname : string;
  3454. begin
  3455. if assigned(_mangledname) then
  3456. begin
  3457. {$ifdef compress}
  3458. mangledname:=minilzw_decode(_mangledname^);
  3459. {$else}
  3460. mangledname:=_mangledname^;
  3461. {$endif}
  3462. exit;
  3463. end;
  3464. {$ifndef jvm}
  3465. mangledname:=defaultmangledname;
  3466. {$else not jvm}
  3467. mangledname:=jvmmangledbasename;
  3468. if (po_has_importdll in procoptions) then
  3469. begin
  3470. { import_dll comes from "external 'import_dll_name' name 'external_name'" }
  3471. if assigned(import_dll) then
  3472. mangledname:=import_dll^+'/'+mangledname
  3473. else
  3474. internalerror(2010122607);
  3475. end
  3476. else
  3477. jvmaddtypeownerprefix(owner,mangledname);
  3478. {$endif not jvm}
  3479. {$ifdef compress}
  3480. _mangledname:=stringdup(minilzw_encode(mangledname));
  3481. {$else}
  3482. _mangledname:=stringdup(mangledname);
  3483. {$endif}
  3484. end;
  3485. function tprocdef.defaultmangledname: string;
  3486. var
  3487. hp : TParavarsym;
  3488. hs : string;
  3489. crc : dword;
  3490. newlen,
  3491. oldlen,
  3492. i : integer;
  3493. begin
  3494. { we need to use the symtable where the procsym is inserted,
  3495. because that is visible to the world }
  3496. defaultmangledname:=make_mangledname('',procsym.owner,procsym.name);
  3497. oldlen:=length(defaultmangledname);
  3498. { add parameter types }
  3499. for i:=0 to paras.count-1 do
  3500. begin
  3501. hp:=tparavarsym(paras[i]);
  3502. if not(vo_is_hidden_para in hp.varoptions) then
  3503. defaultmangledname:=defaultmangledname+'$'+hp.vardef.mangledparaname;
  3504. end;
  3505. { add resultdef, add $$ as separator to make it unique from a
  3506. parameter separator }
  3507. if not is_void(returndef) then
  3508. defaultmangledname:=defaultmangledname+'$$'+returndef.mangledparaname;
  3509. newlen:=length(defaultmangledname);
  3510. { Replace with CRC if the parameter line is very long }
  3511. if (newlen-oldlen>12) and
  3512. ((newlen>100) or (newlen-oldlen>64)) then
  3513. begin
  3514. crc:=0;
  3515. for i:=0 to paras.count-1 do
  3516. begin
  3517. hp:=tparavarsym(paras[i]);
  3518. if not(vo_is_hidden_para in hp.varoptions) then
  3519. begin
  3520. hs:=hp.vardef.mangledparaname;
  3521. crc:=UpdateCrc32(crc,hs[1],length(hs));
  3522. end;
  3523. end;
  3524. hs:=hp.vardef.mangledparaname;
  3525. crc:=UpdateCrc32(crc,hs[1],length(hs));
  3526. defaultmangledname:=Copy(defaultmangledname,1,oldlen)+'$crc'+hexstr(crc,8);
  3527. end;
  3528. end;
  3529. function tprocdef.cplusplusmangledname : string;
  3530. function getcppparaname(p : tdef) : string;
  3531. const
  3532. {$ifdef NAMEMANGLING_GCC2}
  3533. ordtype2str : array[tordtype] of string[2] = (
  3534. '',
  3535. 'Uc','Us','Ui','Us',
  3536. 'Sc','s','i','x',
  3537. 'b','b','b','b','b',
  3538. 'c','w','x');
  3539. {$else NAMEMANGLING_GCC2}
  3540. ordtype2str : array[tordtype] of string[1] = (
  3541. 'v',
  3542. 'h','t','j','y',
  3543. 'a','s','i','x',
  3544. 'b','b','b','b',
  3545. 'b','b','b','b',
  3546. 'c','w','x');
  3547. floattype2str : array[tfloattype] of string[1] = (
  3548. 'f','d','e','e',
  3549. 'd','d','g');
  3550. {$endif NAMEMANGLING_GCC2}
  3551. var
  3552. s : string;
  3553. begin
  3554. case p.typ of
  3555. orddef:
  3556. s:=ordtype2str[torddef(p).ordtype];
  3557. pointerdef:
  3558. s:='P'+getcppparaname(tpointerdef(p).pointeddef);
  3559. {$ifndef NAMEMANGLING_GCC2}
  3560. floatdef:
  3561. s:=floattype2str[tfloatdef(p).floattype];
  3562. {$endif NAMEMANGLING_GCC2}
  3563. else
  3564. internalerror(2103001);
  3565. end;
  3566. getcppparaname:=s;
  3567. end;
  3568. var
  3569. s,s2 : string;
  3570. hp : TParavarsym;
  3571. i : integer;
  3572. begin
  3573. {$ifdef NAMEMANGLING_GCC2}
  3574. { outdated gcc 2.x name mangling scheme }
  3575. s := procsym.realname;
  3576. if procsym.owner.symtabletype=ObjectSymtable then
  3577. begin
  3578. s2:=upper(tobjectdef(procsym.owner.defowner).objrealname^);
  3579. case proctypeoption of
  3580. potype_destructor:
  3581. s:='_$_'+tostr(length(s2))+s2;
  3582. potype_constructor:
  3583. s:='___'+tostr(length(s2))+s2;
  3584. else
  3585. s:='_'+s+'__'+tostr(length(s2))+s2;
  3586. end;
  3587. end
  3588. else s:=s+'__';
  3589. s:=s+'F';
  3590. { concat modifiers }
  3591. { !!!!! }
  3592. { now we handle the parameters }
  3593. if maxparacount>0 then
  3594. begin
  3595. for i:=0 to paras.count-1 do
  3596. begin
  3597. hp:=tparavarsym(paras[i]);
  3598. { no hidden parameters form part of a C++ mangled name:
  3599. a) self is not included
  3600. b) there are no "high" or other hidden parameters
  3601. }
  3602. if vo_is_hidden_para in hp.varoptions then
  3603. continue;
  3604. s2:=getcppparaname(hp.vardef);
  3605. if hp.varspez in [vs_var,vs_out] then
  3606. s2:='R'+s2;
  3607. s:=s+s2;
  3608. end;
  3609. end
  3610. else
  3611. s:=s+'v';
  3612. cplusplusmangledname:=s;
  3613. {$else NAMEMANGLING_GCC2}
  3614. { gcc 3.x and 4.x name mangling scheme }
  3615. { see http://www.codesourcery.com/public/cxx-abi/abi.html#mangling }
  3616. if procsym.owner.symtabletype=ObjectSymtable then
  3617. begin
  3618. s:='_ZN';
  3619. s2:=tobjectdef(procsym.owner.defowner).objextname^;
  3620. s:=s+tostr(length(s2))+s2;
  3621. case proctypeoption of
  3622. potype_constructor:
  3623. s:=s+'C1';
  3624. potype_destructor:
  3625. s:=s+'D1';
  3626. else
  3627. s:=s+tostr(length(procsym.realname))+procsym.realname;
  3628. end;
  3629. s:=s+'E';
  3630. end
  3631. else
  3632. s:=procsym.realname;
  3633. { now we handle the parameters }
  3634. if maxparacount>0 then
  3635. begin
  3636. for i:=0 to paras.count-1 do
  3637. begin
  3638. hp:=tparavarsym(paras[i]);
  3639. { no hidden parameters form part of a C++ mangled name:
  3640. a) self is not included
  3641. b) there are no "high" or other hidden parameters
  3642. }
  3643. if vo_is_hidden_para in hp.varoptions then
  3644. continue;
  3645. s2:=getcppparaname(hp.vardef);
  3646. if hp.varspez in [vs_var,vs_out] then
  3647. s2:='R'+s2;
  3648. s:=s+s2;
  3649. end;
  3650. end
  3651. else
  3652. s:=s+'v';
  3653. cplusplusmangledname:=s;
  3654. {$endif NAMEMANGLING_GCC2}
  3655. end;
  3656. function tprocdef.objcmangledname : string;
  3657. var
  3658. manglednamelen: longint;
  3659. iscatmethod : boolean;
  3660. begin
  3661. if not (po_msgstr in procoptions) then
  3662. internalerror(2009030901);
  3663. { we may very well need longer strings to handle these... }
  3664. manglednamelen:=length(tobjectdef(procsym.owner.defowner).objextname^)+
  3665. length('+"[ ]"')+length(messageinf.str^);
  3666. iscatmethod:=oo_is_classhelper in tobjectdef(procsym.owner.defowner).objectoptions;
  3667. if (iscatmethod) then
  3668. inc(manglednamelen,length(tobjectdef(procsym.owner.defowner).childof.objextname^)+length('()'));
  3669. if manglednamelen>255 then
  3670. Message1(parser_e_objc_message_name_too_long,messageinf.str^);
  3671. if not(po_classmethod in procoptions) then
  3672. result:='"-['
  3673. else
  3674. result:='"+[';
  3675. { quotes are necessary because the +/- otherwise confuse the assembler
  3676. into expecting a number
  3677. }
  3678. if iscatmethod then
  3679. result:=result+tobjectdef(procsym.owner.defowner).childof.objextname^+'(';
  3680. result:=result+tobjectdef(procsym.owner.defowner).objextname^;
  3681. if iscatmethod then
  3682. result:=result+')';
  3683. result:=result+' '+messageinf.str^+']"';
  3684. end;
  3685. function tprocdef.jvmmangledbasename: string;
  3686. var
  3687. vs: tparavarsym;
  3688. i: longint;
  3689. founderror: tdef;
  3690. tmpresult: string;
  3691. begin
  3692. { format:
  3693. * method definition (in Jasmin):
  3694. (private|protected|public) [static] method(parametertypes)returntype
  3695. * method invocation
  3696. package/class/method(parametertypes)returntype
  3697. -> store common part: method(parametertypes)returntype and
  3698. adorn as required when using it.
  3699. }
  3700. { method name }
  3701. { special names for constructors and class constructors }
  3702. if proctypeoption=potype_constructor then
  3703. tmpresult:='<init>'
  3704. else if proctypeoption=potype_class_constructor then
  3705. tmpresult:='<clinit>'
  3706. else if po_has_importname in procoptions then
  3707. begin
  3708. if assigned(import_name) then
  3709. tmpresult:=import_name^
  3710. else
  3711. internalerror(2010122608);
  3712. end
  3713. else
  3714. tmpresult:=procsym.realname;
  3715. { parameter types }
  3716. tmpresult:=tmpresult+'(';
  3717. init_paraloc_info(callerside);
  3718. for i:=0 to paras.count-1 do
  3719. begin
  3720. vs:=tparavarsym(paras[i]);
  3721. { function result and self pointer are not part of the mangled
  3722. name }
  3723. if ([vo_is_funcret,vo_is_self] * vs.varoptions <> []) then
  3724. continue;
  3725. { reference parameters are not yet supported }
  3726. if (vs.varspez in [vs_var,vs_out,vs_constref]) then
  3727. internalerror(2010122603);
  3728. { Add the parameter type. }
  3729. if not jvmaddencodedtype(vs.vardef,false,tmpresult,founderror) then
  3730. { should be checked earlier on }
  3731. internalerror(2010122604);
  3732. end;
  3733. tmpresult:=tmpresult+')';
  3734. { And the type of the function result (void in case of a procedure and
  3735. constructor). }
  3736. if (proctypeoption=potype_constructor) then
  3737. jvmaddencodedtype(voidtype,false,tmpresult,founderror)
  3738. else if not jvmaddencodedtype(returndef,false,tmpresult,founderror) then
  3739. internalerror(2010122610);
  3740. result:=tmpresult;
  3741. end;
  3742. procedure tprocdef.setmangledname(const s : string);
  3743. begin
  3744. { This is not allowed anymore, the forward declaration
  3745. already needs to create the correct mangledname, no changes
  3746. afterwards are allowed (PFV) }
  3747. { Exception: interface definitions in mode macpas, since in that }
  3748. { case no reference to the old name can exist yet (JM) }
  3749. if assigned(_mangledname) then
  3750. if ((m_mac in current_settings.modeswitches) and
  3751. (interfacedef)) then
  3752. stringdispose(_mangledname)
  3753. else
  3754. internalerror(200411171);
  3755. {$ifdef compress}
  3756. _mangledname:=stringdup(minilzw_encode(s));
  3757. {$else}
  3758. _mangledname:=stringdup(s);
  3759. {$endif}
  3760. include(procoptions,po_has_mangledname);
  3761. end;
  3762. {***************************************************************************
  3763. TPROCVARDEF
  3764. ***************************************************************************}
  3765. constructor tprocvardef.create(level:byte);
  3766. begin
  3767. inherited create(procvardef,level);
  3768. end;
  3769. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  3770. begin
  3771. inherited ppuload(procvardef,ppufile);
  3772. { load para symtable }
  3773. parast:=tparasymtable.create(self,ppufile.getbyte);
  3774. tparasymtable(parast).ppuload(ppufile);
  3775. end;
  3776. function tprocvardef.getcopy : tstoreddef;
  3777. var
  3778. i : tcallercallee;
  3779. j : longint;
  3780. begin
  3781. result:=tprocvardef.create(parast.symtablelevel);
  3782. tprocvardef(result).returndef:=returndef;
  3783. tprocvardef(result).returndefderef:=returndefderef;
  3784. tprocvardef(result).parast:=parast.getcopy;
  3785. tprocvardef(result).savesize:=savesize;
  3786. { create paralist copy }
  3787. tprocvardef(result).paras:=tparalist.create(false);
  3788. tprocvardef(result).paras.count:=paras.count;
  3789. for j:=0 to paras.count-1 do
  3790. tprocvardef(result).paras[j]:=paras[j];
  3791. tprocvardef(result).proctypeoption:=proctypeoption;
  3792. tprocvardef(result).proccalloption:=proccalloption;
  3793. tprocvardef(result).procoptions:=procoptions;
  3794. tprocvardef(result).callerargareasize:=callerargareasize;
  3795. tprocvardef(result).calleeargareasize:=calleeargareasize;
  3796. tprocvardef(result).maxparacount:=maxparacount;
  3797. tprocvardef(result).minparacount:=minparacount;
  3798. for i:=low(tcallercallee) to high(tcallercallee) do
  3799. tprocvardef(result).funcretloc[i]:=funcretloc[i].getcopy;
  3800. tprocvardef(result).has_paraloc_info:=has_paraloc_info;
  3801. {$ifdef m68k}
  3802. tprocvardef(result).exp_funcretloc:=exp_funcretloc;
  3803. {$endif}
  3804. end;
  3805. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  3806. begin
  3807. inherited ppuwrite(ppufile);
  3808. { Save the para symtable level (necessary to distinguish nested
  3809. procvars) }
  3810. ppufile.putbyte(parast.symtablelevel);
  3811. { Write this entry }
  3812. ppufile.writeentry(ibprocvardef);
  3813. { Save the para symtable, this is taken from the interface }
  3814. tparasymtable(parast).ppuwrite(ppufile);
  3815. end;
  3816. function tprocvardef.GetSymtable(t:tGetSymtable):TSymtable;
  3817. begin
  3818. case t of
  3819. gs_para :
  3820. GetSymtable:=parast;
  3821. else
  3822. GetSymtable:=nil;
  3823. end;
  3824. end;
  3825. function tprocvardef.size : asizeint;
  3826. begin
  3827. if ((po_methodpointer in procoptions) or
  3828. is_nested_pd(self)) and
  3829. not(po_addressonly in procoptions) then
  3830. size:=2*sizeof(pint)
  3831. else
  3832. size:=sizeof(pint);
  3833. end;
  3834. function tprocvardef.is_methodpointer:boolean;
  3835. begin
  3836. result:=(po_methodpointer in procoptions);
  3837. end;
  3838. function tprocvardef.is_addressonly:boolean;
  3839. begin
  3840. result:=(not(po_methodpointer in procoptions) and
  3841. not is_nested_pd(self)) or
  3842. (po_addressonly in procoptions);
  3843. end;
  3844. function tprocvardef.getmangledparaname:string;
  3845. begin
  3846. if not(po_methodpointer in procoptions) then
  3847. if not is_nested_pd(self) then
  3848. result:='procvar'
  3849. else
  3850. result:='nestedprovar'
  3851. else
  3852. result:='procvarofobj'
  3853. end;
  3854. function tprocvardef.is_publishable : boolean;
  3855. begin
  3856. is_publishable:=(po_methodpointer in procoptions);
  3857. end;
  3858. function tprocvardef.GetTypeName : string;
  3859. var
  3860. s: string;
  3861. showhidden : boolean;
  3862. begin
  3863. {$ifdef EXTDEBUG}
  3864. showhidden:=true;
  3865. {$else EXTDEBUG}
  3866. showhidden:=false;
  3867. {$endif EXTDEBUG}
  3868. s:='<';
  3869. if po_classmethod in procoptions then
  3870. s := s+'class method type of'
  3871. else
  3872. if po_addressonly in procoptions then
  3873. s := s+'address of'
  3874. else
  3875. s := s+'procedure variable type of';
  3876. if assigned(returndef) and
  3877. (returndef<>voidtype) then
  3878. s:=s+' function'+typename_paras(showhidden)+':'+returndef.GetTypeName
  3879. else
  3880. s:=s+' procedure'+typename_paras(showhidden);
  3881. if po_methodpointer in procoptions then
  3882. s := s+' of object';
  3883. if is_nested_pd(self) then
  3884. s := s+' is nested';
  3885. GetTypeName := s+';'+ProcCallOptionStr[proccalloption]+'>';
  3886. end;
  3887. {***************************************************************************
  3888. TOBJECTDEF
  3889. ***************************************************************************}
  3890. constructor tobjectdef.create(ot:tobjecttyp;const n:string;c:tobjectdef);
  3891. begin
  3892. inherited create(n,objectdef);
  3893. fcurrent_dispid:=0;
  3894. objecttype:=ot;
  3895. childof:=nil;
  3896. if objecttype=odt_helper then
  3897. owner.includeoption(sto_has_helper);
  3898. symtable:=tObjectSymtable.create(self,n,current_settings.packrecords);
  3899. { create space for vmt !! }
  3900. vmtentries:=TFPList.Create;
  3901. vmt_offset:=0;
  3902. set_parent(c);
  3903. if objecttype in [odt_interfacecorba,odt_interfacecom,odt_dispinterface] then
  3904. prepareguid;
  3905. { setup implemented interfaces }
  3906. if objecttype in [odt_class,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  3907. ImplementedInterfaces:=TFPObjectList.Create(true)
  3908. else
  3909. ImplementedInterfaces:=nil;
  3910. writing_class_record_dbginfo:=false;
  3911. end;
  3912. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  3913. var
  3914. i,
  3915. implintfcount : longint;
  3916. d : tderef;
  3917. ImplIntf : TImplementedInterface;
  3918. vmtentry : pvmtentry;
  3919. begin
  3920. inherited ppuload(objectdef,ppufile);
  3921. objecttype:=tobjecttyp(ppufile.getbyte);
  3922. objextname:=stringdup(ppufile.getstring);
  3923. { only used for external Objective-C classes/protocols }
  3924. if (objextname^='') then
  3925. stringdispose(objextname);
  3926. import_lib:=stringdup(ppufile.getstring);
  3927. { only used for external C++ classes }
  3928. if (import_lib^='') then
  3929. stringdispose(import_lib);
  3930. symtable:=tObjectSymtable.create(self,objrealname^,0);
  3931. tObjectSymtable(symtable).datasize:=ppufile.getasizeint;
  3932. tObjectSymtable(symtable).paddingsize:=ppufile.getword;
  3933. tObjectSymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  3934. tObjectSymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  3935. vmt_offset:=ppufile.getlongint;
  3936. ppufile.getderef(childofderef);
  3937. { load guid }
  3938. iidstr:=nil;
  3939. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3940. begin
  3941. new(iidguid);
  3942. ppufile.getguid(iidguid^);
  3943. iidstr:=stringdup(ppufile.getstring);
  3944. end;
  3945. if objecttype=odt_helper then
  3946. ppufile.getderef(extendeddefderef);
  3947. vmtentries:=TFPList.Create;
  3948. vmtentries.count:=ppufile.getlongint;
  3949. for i:=0 to vmtentries.count-1 do
  3950. begin
  3951. ppufile.getderef(d);
  3952. new(vmtentry);
  3953. vmtentry^.procdef:=nil;
  3954. vmtentry^.procdefderef:=d;
  3955. vmtentry^.visibility:=tvisibility(ppufile.getbyte);
  3956. vmtentries[i]:=vmtentry;
  3957. end;
  3958. { load implemented interfaces }
  3959. if objecttype in [odt_class,odt_objcclass,odt_objcprotocol,odt_interfacejava] then
  3960. begin
  3961. ImplementedInterfaces:=TFPObjectList.Create(true);
  3962. implintfcount:=ppufile.getlongint;
  3963. for i:=0 to implintfcount-1 do
  3964. begin
  3965. ppufile.getderef(d);
  3966. ImplIntf:=TImplementedInterface.Create_deref(d);
  3967. ImplIntf.IOffset:=ppufile.getlongint;
  3968. ImplementedInterfaces.Add(ImplIntf);
  3969. end;
  3970. end
  3971. else
  3972. ImplementedInterfaces:=nil;
  3973. if df_copied_def in defoptions then
  3974. ppufile.getderef(cloneddefderef)
  3975. else
  3976. tObjectSymtable(symtable).ppuload(ppufile);
  3977. { handles the predefined class tobject }
  3978. { the last TOBJECT which is loaded gets }
  3979. { it ! }
  3980. if (childof=nil) and
  3981. (objecttype=odt_class) and
  3982. (objname^='TOBJECT') then
  3983. class_tobject:=self;
  3984. if (childof=nil) and
  3985. (objecttype=odt_interfacecom) then
  3986. if (objname^='IUNKNOWN') then
  3987. interface_iunknown:=self
  3988. else
  3989. if (objname^='IDISPATCH') then
  3990. interface_idispatch:=self;
  3991. if (childof=nil) and
  3992. (objecttype=odt_objcclass) and
  3993. (objname^='PROTOCOL') then
  3994. objc_protocoltype:=self;
  3995. if (childof=nil) and
  3996. (objecttype=odt_javaclass) and
  3997. (objname^='TOBJECT') then
  3998. java_jlobject:=self;
  3999. writing_class_record_dbginfo:=false;
  4000. end;
  4001. destructor tobjectdef.destroy;
  4002. begin
  4003. if assigned(symtable) then
  4004. begin
  4005. symtable.free;
  4006. symtable:=nil;
  4007. end;
  4008. stringdispose(objextname);
  4009. stringdispose(import_lib);
  4010. stringdispose(iidstr);
  4011. if assigned(ImplementedInterfaces) then
  4012. begin
  4013. ImplementedInterfaces.free;
  4014. ImplementedInterfaces:=nil;
  4015. end;
  4016. if assigned(iidguid) then
  4017. begin
  4018. dispose(iidguid);
  4019. iidguid:=nil;
  4020. end;
  4021. if assigned(vmtentries) then
  4022. begin
  4023. resetvmtentries;
  4024. vmtentries.free;
  4025. vmtentries:=nil;
  4026. end;
  4027. if assigned(vmcallstaticinfo) then
  4028. begin
  4029. freemem(vmcallstaticinfo);
  4030. vmcallstaticinfo:=nil;
  4031. end;
  4032. inherited destroy;
  4033. end;
  4034. function tobjectdef.getcopy : tstoreddef;
  4035. var
  4036. i : longint;
  4037. begin
  4038. result:=tobjectdef.create(objecttype,objrealname^,childof);
  4039. { the constructor allocates a symtable which we release to avoid memory leaks }
  4040. tobjectdef(result).symtable.free;
  4041. tobjectdef(result).symtable:=symtable.getcopy;
  4042. if assigned(objextname) then
  4043. tobjectdef(result).objextname:=stringdup(objextname^);
  4044. if assigned(import_lib) then
  4045. tobjectdef(result).import_lib:=stringdup(import_lib^);
  4046. tobjectdef(result).objectoptions:=objectoptions;
  4047. include(tobjectdef(result).defoptions,df_copied_def);
  4048. tobjectdef(result).extendeddef:=extendeddef;
  4049. tobjectdef(result).vmt_offset:=vmt_offset;
  4050. if assigned(iidguid) then
  4051. begin
  4052. new(tobjectdef(result).iidguid);
  4053. move(iidguid^,tobjectdef(result).iidguid^,sizeof(iidguid^));
  4054. end;
  4055. if assigned(iidstr) then
  4056. tobjectdef(result).iidstr:=stringdup(iidstr^);
  4057. if assigned(ImplementedInterfaces) then
  4058. begin
  4059. for i:=0 to ImplementedInterfaces.count-1 do
  4060. tobjectdef(result).ImplementedInterfaces.Add(TImplementedInterface(ImplementedInterfaces[i]).Getcopy);
  4061. end;
  4062. if assigned(vmtentries) then
  4063. begin
  4064. tobjectdef(result).vmtentries:=TFPList.Create;
  4065. tobjectdef(result).copyvmtentries(self);
  4066. end;
  4067. end;
  4068. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  4069. var
  4070. i : longint;
  4071. vmtentry : pvmtentry;
  4072. ImplIntf : TImplementedInterface;
  4073. old_do_indirect_crc: boolean;
  4074. begin
  4075. { if class1 in unit A changes, and class2 in unit B inherits from it
  4076. (so unit B uses unit A), then unit B with class2 will be recompiled.
  4077. However, if there is also a class3 in unit C that only depends on
  4078. unit B, then unit C will not be recompiled because nothing changed
  4079. to the interface of unit B. Nevertheless, unit C can indirectly
  4080. depend on unit A via derefs, and these must be updated -> the
  4081. indirect crc keeps track of such changes. }
  4082. old_do_indirect_crc:=ppufile.do_indirect_crc;
  4083. ppufile.do_indirect_crc:=true;
  4084. inherited ppuwrite(ppufile);
  4085. ppufile.putbyte(byte(objecttype));
  4086. if assigned(objextname) then
  4087. ppufile.putstring(objextname^)
  4088. else
  4089. ppufile.putstring('');
  4090. if assigned(import_lib) then
  4091. ppufile.putstring(import_lib^)
  4092. else
  4093. ppufile.putstring('');
  4094. ppufile.putasizeint(tObjectSymtable(symtable).datasize);
  4095. ppufile.putword(tObjectSymtable(symtable).paddingsize);
  4096. ppufile.putbyte(byte(tObjectSymtable(symtable).fieldalignment));
  4097. ppufile.putbyte(byte(tObjectSymtable(symtable).recordalignment));
  4098. ppufile.putlongint(vmt_offset);
  4099. ppufile.putderef(childofderef);
  4100. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  4101. begin
  4102. ppufile.putguid(iidguid^);
  4103. ppufile.putstring(iidstr^);
  4104. end;
  4105. if objecttype=odt_helper then
  4106. ppufile.putderef(extendeddefderef);
  4107. ppufile.putlongint(vmtentries.count);
  4108. for i:=0 to vmtentries.count-1 do
  4109. begin
  4110. vmtentry:=pvmtentry(vmtentries[i]);
  4111. ppufile.putderef(vmtentry^.procdefderef);
  4112. ppufile.putbyte(byte(vmtentry^.visibility));
  4113. end;
  4114. if assigned(ImplementedInterfaces) then
  4115. begin
  4116. ppufile.putlongint(ImplementedInterfaces.Count);
  4117. for i:=0 to ImplementedInterfaces.Count-1 do
  4118. begin
  4119. ImplIntf:=TImplementedInterface(ImplementedInterfaces[i]);
  4120. ppufile.putderef(ImplIntf.intfdefderef);
  4121. ppufile.putlongint(ImplIntf.Ioffset);
  4122. end;
  4123. end;
  4124. if df_copied_def in defoptions then
  4125. ppufile.putderef(cloneddefderef);
  4126. ppufile.writeentry(ibobjectdef);
  4127. if not(df_copied_def in defoptions) then
  4128. tObjectSymtable(symtable).ppuwrite(ppufile);
  4129. ppufile.do_indirect_crc:=old_do_indirect_crc;
  4130. end;
  4131. function tobjectdef.GetTypeName:string;
  4132. begin
  4133. { in this case we will go in endless recursion, because then }
  4134. { there is no tsym associated yet with the def. It can occur }
  4135. { (tests/webtbf/tw4757.pp), so for now give a generic name }
  4136. { instead of the actual type name }
  4137. if not assigned(typesym) then
  4138. result:='<Currently Parsed Class>'
  4139. else
  4140. result:=typesymbolprettyname;
  4141. end;
  4142. procedure tobjectdef.buildderef;
  4143. var
  4144. i : longint;
  4145. vmtentry : pvmtentry;
  4146. begin
  4147. inherited buildderef;
  4148. childofderef.build(childof);
  4149. if df_copied_def in defoptions then
  4150. cloneddefderef.build(symtable.defowner)
  4151. else
  4152. tstoredsymtable(symtable).buildderef;
  4153. if objecttype=odt_helper then
  4154. extendeddefderef.build(extendeddef);
  4155. for i:=0 to vmtentries.count-1 do
  4156. begin
  4157. vmtentry:=pvmtentry(vmtentries[i]);
  4158. vmtentry^.procdefderef.build(vmtentry^.procdef);
  4159. end;
  4160. if assigned(ImplementedInterfaces) then
  4161. begin
  4162. for i:=0 to ImplementedInterfaces.count-1 do
  4163. TImplementedInterface(ImplementedInterfaces[i]).buildderef;
  4164. end;
  4165. end;
  4166. procedure tobjectdef.deref;
  4167. var
  4168. i : longint;
  4169. vmtentry : pvmtentry;
  4170. begin
  4171. inherited deref;
  4172. childof:=tobjectdef(childofderef.resolve);
  4173. if df_copied_def in defoptions then
  4174. begin
  4175. cloneddef:=tobjectdef(cloneddefderef.resolve);
  4176. symtable:=cloneddef.symtable.getcopy;
  4177. end
  4178. else
  4179. tstoredsymtable(symtable).deref;
  4180. if objecttype=odt_helper then
  4181. extendeddef:=tobjectdef(extendeddefderef.resolve);
  4182. for i:=0 to vmtentries.count-1 do
  4183. begin
  4184. vmtentry:=pvmtentry(vmtentries[i]);
  4185. vmtentry^.procdef:=tprocdef(vmtentry^.procdefderef.resolve);
  4186. end;
  4187. if assigned(ImplementedInterfaces) then
  4188. begin
  4189. for i:=0 to ImplementedInterfaces.count-1 do
  4190. TImplementedInterface(ImplementedInterfaces[i]).deref;
  4191. end;
  4192. end;
  4193. procedure create_class_helper_for_procdef(def: tobject; arg: pointer);
  4194. var
  4195. pd: tprocdef absolute def;
  4196. st: tsymtable;
  4197. psym: tsym;
  4198. nname: TIDString;
  4199. begin
  4200. if (tdef(def).typ<>procdef) then
  4201. exit;
  4202. { pd.owner = objcclass symtable -> defowner = objcclassdef ->
  4203. owner = symtable in which objcclassdef is defined
  4204. }
  4205. st:=pd.owner.defowner.owner;
  4206. nname:=class_helper_prefix+tprocsym(pd.procsym).name;
  4207. { check for an existing procsym with our special name }
  4208. psym:=tsym(st.find(nname));
  4209. if not assigned(psym) then
  4210. begin
  4211. psym:=tprocsym.create(nname);
  4212. { avoid warning about this symbol being unused }
  4213. psym.IncRefCount;
  4214. { don't check for duplicates:
  4215. a) we checked above
  4216. b) in case we are in the implementation section of a unit, this
  4217. will also check for this symbol in the interface section
  4218. (since you normally cannot have symbols with the same name
  4219. both interface and implementation), and it's possible to
  4220. have class helpers for the same class in the interface and
  4221. in the implementation, and they cannot be merged since only
  4222. the once in the interface must be saved to the ppu/visible
  4223. from other units }
  4224. st.insert(psym,false);
  4225. end
  4226. else if (psym.typ<>procsym) then
  4227. internalerror(2009111501);
  4228. { add ourselves to this special procsym }
  4229. tprocsym(psym).procdeflist.add(def);
  4230. end;
  4231. procedure tobjectdef.buildderefimpl;
  4232. begin
  4233. inherited buildderefimpl;
  4234. if not (df_copied_def in defoptions) then
  4235. tstoredsymtable(symtable).buildderefimpl;
  4236. end;
  4237. procedure tobjectdef.derefimpl;
  4238. begin
  4239. inherited derefimpl;
  4240. if not (df_copied_def in defoptions) then
  4241. tstoredsymtable(symtable).derefimpl;
  4242. { the procdefs are not owned by the class helper procsyms, so they
  4243. are not stored/restored either -> re-add them here }
  4244. if (objecttype=odt_objcclass) or
  4245. (oo_is_classhelper in objectoptions) then
  4246. symtable.DefList.ForEachCall(@create_class_helper_for_procdef,nil);
  4247. end;
  4248. procedure tobjectdef.resetvmtentries;
  4249. var
  4250. i : longint;
  4251. begin
  4252. for i:=0 to vmtentries.Count-1 do
  4253. Dispose(pvmtentry(vmtentries[i]));
  4254. vmtentries.clear;
  4255. end;
  4256. procedure tobjectdef.copyvmtentries(objdef:tobjectdef);
  4257. var
  4258. i : longint;
  4259. vmtentry : pvmtentry;
  4260. begin
  4261. resetvmtentries;
  4262. vmtentries.count:=objdef.vmtentries.count;
  4263. for i:=0 to objdef.vmtentries.count-1 do
  4264. begin
  4265. new(vmtentry);
  4266. vmtentry^:=pvmtentry(objdef.vmtentries[i])^;
  4267. vmtentries[i]:=vmtentry;
  4268. end;
  4269. end;
  4270. function tobjectdef.getparentdef:tdef;
  4271. begin
  4272. { TODO: Remove getparentdef hack}
  4273. { With 2 forward declared classes with the child class before the
  4274. parent class the child class is written earlier to the ppu. Leaving it
  4275. possible to have a reference to the parent class for property overriding,
  4276. but the parent class still has the childof not resolved yet (PFV) }
  4277. if childof=nil then
  4278. childof:=tobjectdef(childofderef.resolve);
  4279. result:=childof;
  4280. end;
  4281. procedure tobjectdef.prepareguid;
  4282. begin
  4283. { set up guid }
  4284. if not assigned(iidguid) then
  4285. begin
  4286. new(iidguid);
  4287. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  4288. end;
  4289. { setup iidstring }
  4290. if not assigned(iidstr) then
  4291. iidstr:=stringdup(''); { default is empty string }
  4292. end;
  4293. procedure tobjectdef.set_parent( c : tobjectdef);
  4294. begin
  4295. if assigned(childof) then
  4296. exit;
  4297. childof:=c;
  4298. if not assigned(c) then
  4299. exit;
  4300. { inherit options and status }
  4301. objectoptions:=objectoptions+(c.objectoptions*inherited_objectoptions);
  4302. { add the data of the anchestor class/object }
  4303. if (objecttype in [odt_class,odt_object,odt_objcclass,odt_javaclass]) then
  4304. begin
  4305. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize+tObjectSymtable(c.symtable).datasize;
  4306. { inherit recordalignment }
  4307. tObjectSymtable(symtable).recordalignment:=tObjectSymtable(c.symtable).recordalignment;
  4308. { if both the parent and this record use C-alignment, also inherit
  4309. the current field alignment }
  4310. if (tObjectSymtable(c.symtable).usefieldalignment=C_alignment) and
  4311. (tObjectSymtable(symtable).usefieldalignment=C_alignment) then
  4312. tObjectSymtable(symtable).fieldalignment:=tObjectSymtable(c.symtable).fieldalignment;
  4313. { the padding is not inherited for Objective-C classes (maybe not
  4314. for cppclass either?) }
  4315. if objecttype=odt_objcclass then
  4316. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize-tObjectSymtable(c.symtable).paddingsize;
  4317. if (oo_has_vmt in objectoptions) and
  4318. (oo_has_vmt in c.objectoptions) then
  4319. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize-sizeof(pint);
  4320. { if parent has a vmt field then the offset is the same for the child PM }
  4321. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  4322. begin
  4323. vmt_offset:=c.vmt_offset;
  4324. include(objectoptions,oo_has_vmt);
  4325. end;
  4326. end;
  4327. end;
  4328. procedure tobjectdef.insertvmt;
  4329. var
  4330. vs: tfieldvarsym;
  4331. begin
  4332. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  4333. exit;
  4334. if (oo_has_vmt in objectoptions) then
  4335. internalerror(12345)
  4336. else
  4337. begin
  4338. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,
  4339. tObjectSymtable(symtable).fieldalignment);
  4340. if (tf_requires_proper_alignment in target_info.flags) then
  4341. begin
  4342. { Align VMT pointer and whole object instance if target CPU requires alignment. }
  4343. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,sizeof(pint));
  4344. tObjectSymtable(symtable).alignrecord(tObjectSymtable(symtable).datasize,sizeof(pint));
  4345. end;
  4346. vs:=tfieldvarsym.create('_vptr$'+objname^,vs_value,voidpointertype,[]);
  4347. hidesym(vs);
  4348. tObjectSymtable(symtable).insert(vs);
  4349. tObjectSymtable(symtable).addfield(vs,vis_hidden);
  4350. if (tObjectSymtable(symtable).usefieldalignment<>bit_alignment) then
  4351. vmt_offset:=vs.fieldoffset
  4352. else
  4353. vmt_offset:=vs.fieldoffset div 8;
  4354. include(objectoptions,oo_has_vmt);
  4355. end;
  4356. end;
  4357. procedure tobjectdef.check_forwards;
  4358. begin
  4359. if not(objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcprotocol,odt_interfacejava]) then
  4360. inherited;
  4361. if (oo_is_forward in objectoptions) then
  4362. begin
  4363. { ok, in future, the forward can be resolved }
  4364. Message1(sym_e_class_forward_not_resolved,objrealname^);
  4365. exclude(objectoptions,oo_is_forward);
  4366. end;
  4367. end;
  4368. { true if prot implements d (or if they are equal) }
  4369. function is_related_interface_multiple(prot: tobjectdef; d : tdef) : boolean;
  4370. var
  4371. i : longint;
  4372. begin
  4373. { objcprotocols have multiple inheritance, all protocols from which
  4374. the current protocol inherits are stored in implementedinterfaces }
  4375. result:=prot=d;
  4376. if result then
  4377. exit;
  4378. for i:=0 to prot.ImplementedInterfaces.count-1 do
  4379. begin
  4380. result:=is_related_interface_multiple(TImplementedInterface(prot.ImplementedInterfaces[i]).intfdef,d);
  4381. if result then
  4382. exit;
  4383. end;
  4384. end;
  4385. { true, if self inherits from d (or if they are equal) }
  4386. function tobjectdef.is_related(d : tdef) : boolean;
  4387. var
  4388. hp : tobjectdef;
  4389. realself: tobjectdef;
  4390. begin
  4391. if (d.typ=objectdef) then
  4392. d:=find_real_class_definition(tobjectdef(d),false);
  4393. realself:=find_real_class_definition(self,false);
  4394. if realself=d then
  4395. begin
  4396. is_related:=true;
  4397. exit;
  4398. end;
  4399. if (d.typ<>objectdef) then
  4400. begin
  4401. is_related:=false;
  4402. exit;
  4403. end;
  4404. { Objective-C protocols and Java interfaces can use multiple
  4405. inheritance }
  4406. if (objecttype in [odt_objcprotocol,odt_interfacejava]) then
  4407. begin
  4408. is_related:=is_related_interface_multiple(realself,d);
  4409. exit
  4410. end;
  4411. { formally declared Objective-C and Java classes match Objective-C/Java
  4412. classes with the same name. In case of Java, the package must also
  4413. match}
  4414. if (objecttype in [odt_objcclass,odt_javaclass]) and
  4415. (tobjectdef(d).objecttype=objecttype) and
  4416. ((oo_is_formal in objectoptions) or
  4417. (oo_is_formal in tobjectdef(d).objectoptions)) and
  4418. (objrealname^=tobjectdef(d).objrealname^) then
  4419. begin
  4420. { check package name for Java }
  4421. if objecttype=odt_objcclass then
  4422. is_related:=true
  4423. else
  4424. begin
  4425. is_related:=
  4426. assigned(import_lib)=assigned(tobjectdef(d).import_lib);
  4427. if is_related and
  4428. assigned(import_lib) then
  4429. is_related:=import_lib^=tobjectdef(d).import_lib^;
  4430. end;
  4431. exit;
  4432. end;
  4433. hp:=realself.childof;
  4434. while assigned(hp) do
  4435. begin
  4436. if hp=d then
  4437. begin
  4438. is_related:=true;
  4439. exit;
  4440. end;
  4441. hp:=hp.childof;
  4442. end;
  4443. is_related:=false;
  4444. end;
  4445. function tobjectdef.find_destructor: tprocdef;
  4446. var
  4447. objdef: tobjectdef;
  4448. begin
  4449. objdef:=self;
  4450. while assigned(objdef) do
  4451. begin
  4452. result:=objdef.find_procdef_bytype(potype_destructor);
  4453. if assigned(result) then
  4454. exit;
  4455. objdef:=objdef.childof;
  4456. end;
  4457. result:=nil;
  4458. end;
  4459. function tobjectdef.implements_any_interfaces: boolean;
  4460. begin
  4461. result := (ImplementedInterfaces.Count > 0) or
  4462. (assigned(childof) and childof.implements_any_interfaces);
  4463. end;
  4464. function tobjectdef.size : asizeint;
  4465. begin
  4466. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava] then
  4467. result:=sizeof(pint)
  4468. else
  4469. result:=tObjectSymtable(symtable).datasize;
  4470. end;
  4471. function tobjectdef.alignment:shortint;
  4472. begin
  4473. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava] then
  4474. alignment:=sizeof(pint)
  4475. else
  4476. alignment:=tObjectSymtable(symtable).recordalignment;
  4477. end;
  4478. function tobjectdef.vmtmethodoffset(index:longint):longint;
  4479. begin
  4480. { for offset of methods for classes, see rtl/inc/objpash.inc }
  4481. case objecttype of
  4482. odt_class:
  4483. { the +2*sizeof(pint) is size and -size }
  4484. vmtmethodoffset:=(index+10)*sizeof(pint)+2*sizeof(pint);
  4485. odt_helper,
  4486. odt_objcclass,
  4487. odt_objcprotocol:
  4488. vmtmethodoffset:=0;
  4489. odt_interfacecom,odt_interfacecorba,odt_dispinterface:
  4490. vmtmethodoffset:=index*sizeof(pint);
  4491. odt_javaclass,
  4492. odt_interfacejava:
  4493. { invalid }
  4494. vmtmethodoffset:=-1;
  4495. else
  4496. {$ifdef WITHDMT}
  4497. vmtmethodoffset:=(index+4)*sizeof(pint);
  4498. {$else WITHDMT}
  4499. vmtmethodoffset:=(index+3)*sizeof(pint);
  4500. {$endif WITHDMT}
  4501. end;
  4502. end;
  4503. function tobjectdef.vmt_mangledname : string;
  4504. begin
  4505. if not(oo_has_vmt in objectoptions) then
  4506. Message1(parser_n_object_has_no_vmt,objrealname^);
  4507. vmt_mangledname:=make_mangledname('VMT',owner,objname^);
  4508. end;
  4509. function tobjectdef.needs_inittable : boolean;
  4510. begin
  4511. case objecttype of
  4512. odt_helper,
  4513. odt_class :
  4514. needs_inittable:=false;
  4515. odt_dispinterface,
  4516. odt_interfacecom:
  4517. needs_inittable:=true;
  4518. odt_interfacecorba:
  4519. needs_inittable:=is_related(interface_iunknown);
  4520. odt_object:
  4521. needs_inittable:=tObjectSymtable(symtable).needs_init_final;
  4522. odt_cppclass,
  4523. odt_objcclass,
  4524. odt_objcprotocol,
  4525. odt_javaclass,
  4526. odt_interfacejava:
  4527. needs_inittable:=false;
  4528. else
  4529. internalerror(200108267);
  4530. end;
  4531. end;
  4532. function tobjectdef.rtti_mangledname(rt: trttitype): string;
  4533. begin
  4534. if not(objecttype in [odt_objcclass,odt_objcprotocol]) then
  4535. result:=inherited rtti_mangledname(rt)
  4536. else
  4537. begin
  4538. { necessary in case of a dynamic array of nsobject, or
  4539. if an nsobject field appears in a record that needs
  4540. init/finalisation }
  4541. if rt=initrtti then
  4542. begin
  4543. result:=voidpointertype.rtti_mangledname(rt);
  4544. exit;
  4545. end;
  4546. if not(target_info.system in systems_objc_nfabi) then
  4547. begin
  4548. result:=target_asm.labelprefix;
  4549. case objecttype of
  4550. odt_objcclass:
  4551. begin
  4552. case rt of
  4553. objcclassrtti:
  4554. if not(oo_is_classhelper in objectoptions) then
  4555. result:=result+'_OBJC_CLASS_'
  4556. else
  4557. result:=result+'_OBJC_CATEGORY_';
  4558. objcmetartti:
  4559. if not(oo_is_classhelper in objectoptions) then
  4560. result:=result+'_OBJC_METACLASS_'
  4561. else
  4562. internalerror(2009111511);
  4563. else
  4564. internalerror(2009092302);
  4565. end;
  4566. end;
  4567. odt_objcprotocol:
  4568. result:=result+'_OBJC_PROTOCOL_';
  4569. end;
  4570. end
  4571. else
  4572. begin
  4573. case objecttype of
  4574. odt_objcclass:
  4575. begin
  4576. if (oo_is_classhelper in objectoptions) and
  4577. (rt<>objcclassrtti) then
  4578. internalerror(2009111512);
  4579. case rt of
  4580. objcclassrtti:
  4581. if not(oo_is_classhelper in objectoptions) then
  4582. result:='_OBJC_CLASS_$_'
  4583. else
  4584. result:='_OBJC_$_CATEGORY_';
  4585. objcmetartti:
  4586. result:='_OBJC_METACLASS_$_';
  4587. objcclassrortti:
  4588. result:=lower(target_asm.labelprefix)+'_OBJC_CLASS_RO_$_';
  4589. objcmetarortti:
  4590. result:=lower(target_asm.labelprefix)+'_OBJC_METACLASS_RO_$_';
  4591. else
  4592. internalerror(2009092303);
  4593. end;
  4594. end;
  4595. odt_objcprotocol:
  4596. begin
  4597. result:=lower(target_asm.labelprefix);
  4598. case rt of
  4599. objcclassrtti:
  4600. result:=result+'_OBJC_PROTOCOL_$_';
  4601. objcmetartti:
  4602. result:=result+'_OBJC_LABEL_PROTOCOL_$_';
  4603. else
  4604. internalerror(2009092501);
  4605. end;
  4606. end;
  4607. end;
  4608. end;
  4609. result:=result+objextname^;
  4610. end;
  4611. end;
  4612. function tobjectdef.members_need_inittable : boolean;
  4613. begin
  4614. members_need_inittable:=tObjectSymtable(symtable).needs_init_final;
  4615. end;
  4616. function tobjectdef.find_implemented_interface(aintfdef:tobjectdef):TImplementedInterface;
  4617. var
  4618. ImplIntf : TImplementedInterface;
  4619. i : longint;
  4620. begin
  4621. result:=nil;
  4622. if not assigned(ImplementedInterfaces) then
  4623. exit;
  4624. for i:=0 to ImplementedInterfaces.Count-1 do
  4625. begin
  4626. ImplIntf:=TImplementedInterface(ImplementedInterfaces[i]);
  4627. if ImplIntf.intfdef=aintfdef then
  4628. begin
  4629. result:=ImplIntf;
  4630. exit;
  4631. end;
  4632. end;
  4633. end;
  4634. function tobjectdef.is_publishable : boolean;
  4635. begin
  4636. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface];
  4637. end;
  4638. function tobjectdef.get_next_dispid: longint;
  4639. begin
  4640. inc(fcurrent_dispid);
  4641. result:=fcurrent_dispid;
  4642. end;
  4643. function tobjectdef.search_enumerator_get: tprocdef;
  4644. begin
  4645. result:=inherited;
  4646. if not assigned(result) and assigned(childof) then
  4647. result:=childof.search_enumerator_get;
  4648. end;
  4649. function tobjectdef.search_enumerator_move: tprocdef;
  4650. begin
  4651. result:=inherited;
  4652. if not assigned(result) and assigned(childof) then
  4653. result:=childof.search_enumerator_move;
  4654. end;
  4655. function tobjectdef.search_enumerator_current: tsym;
  4656. begin
  4657. result:=inherited;
  4658. if not assigned(result) and assigned(childof) then
  4659. result:=childof.search_enumerator_current;
  4660. end;
  4661. procedure tobjectdef.register_created_classref_type;
  4662. begin
  4663. if not classref_created_in_current_module then
  4664. begin
  4665. classref_created_in_current_module:=true;
  4666. current_module.wpoinfo.addcreatedobjtypeforclassref(self);
  4667. end;
  4668. end;
  4669. procedure tobjectdef.register_created_object_type;
  4670. begin
  4671. if not created_in_current_module then
  4672. begin
  4673. created_in_current_module:=true;
  4674. current_module.wpoinfo.addcreatedobjtype(self);
  4675. end;
  4676. end;
  4677. procedure tobjectdef.register_maybe_created_object_type;
  4678. begin
  4679. { if we know it has been created for sure, no need
  4680. to also record that it maybe can be created in
  4681. this module
  4682. }
  4683. if not (created_in_current_module) and
  4684. not (maybe_created_in_current_module) then
  4685. begin
  4686. maybe_created_in_current_module:=true;
  4687. current_module.wpoinfo.addmaybecreatedbyclassref(self);
  4688. end;
  4689. end;
  4690. procedure tobjectdef.register_vmt_call(index: longint);
  4691. begin
  4692. if (is_object(self) or is_class(self)) then
  4693. current_module.wpoinfo.addcalledvmtentry(self,index);
  4694. end;
  4695. procedure check_and_finish_msg(data: tobject; arg: pointer);
  4696. var
  4697. def: tdef absolute data;
  4698. pd: tprocdef absolute data;
  4699. i,
  4700. paracount: longint;
  4701. begin
  4702. if (def.typ=procdef) then
  4703. begin
  4704. { add all messages also under a dummy name to the symtable in
  4705. which the objcclass/protocol/category is declared, so they can
  4706. be called via id.<name>
  4707. }
  4708. create_class_helper_for_procdef(pd,nil);
  4709. { we have to wait until now to set the mangled name because it
  4710. depends on the (possibly external) class name, which is defined
  4711. at the very end. }
  4712. if not(po_msgstr in pd.procoptions) then
  4713. begin
  4714. CGMessagePos(pd.fileinfo,parser_e_objc_requires_msgstr);
  4715. { recover to avoid internalerror later on }
  4716. include(pd.procoptions,po_msgstr);
  4717. pd.messageinf.str:=stringdup('MissingDeclaration');
  4718. end;
  4719. { Mangled name is already set in case this is a copy of
  4720. another type. }
  4721. if not(po_has_mangledname in pd.procoptions) then
  4722. begin
  4723. { check whether the number of formal parameters is correct,
  4724. and whether they have valid Objective-C types }
  4725. paracount:=0;
  4726. for i:=1 to length(pd.messageinf.str^) do
  4727. if pd.messageinf.str^[i]=':' then
  4728. inc(paracount);
  4729. for i:=0 to pd.paras.count-1 do
  4730. if not(vo_is_hidden_para in tparavarsym(pd.paras[i]).varoptions) and
  4731. not is_array_of_const(tparavarsym(pd.paras[i]).vardef) then
  4732. dec(paracount);
  4733. if (paracount<>0) then
  4734. MessagePos(pd.fileinfo,sym_e_objc_para_mismatch);
  4735. pd.setmangledname(pd.objcmangledname);
  4736. end
  4737. else
  4738. { all checks already done }
  4739. exit;
  4740. if not(oo_is_external in pd.struct.objectoptions) then
  4741. begin
  4742. if (po_varargs in pd.procoptions) then
  4743. MessagePos(pd.fileinfo,parser_e_varargs_need_cdecl_and_external)
  4744. else
  4745. begin
  4746. { check for "array of const" parameters }
  4747. for i:=0 to pd.parast.symlist.count-1 do
  4748. begin
  4749. if (tsym(pd.parast.symlist[i]).typ=paravarsym) and
  4750. is_array_of_const(tparavarsym(pd.parast.symlist[i]).vardef) then
  4751. MessagePos(pd.fileinfo,parser_e_varargs_need_cdecl_and_external);
  4752. end;
  4753. end;
  4754. end;
  4755. end;
  4756. end;
  4757. procedure mark_private_fields_used(data: tobject; arg: pointer);
  4758. var
  4759. sym: tsym absolute data;
  4760. begin
  4761. if (sym.typ=fieldvarsym) and
  4762. (tfieldvarsym(sym).visibility in [vis_private,vis_strictprivate]) then
  4763. sym.IncRefCount;
  4764. end;
  4765. procedure tobjectdef.finish_objc_data;
  4766. begin
  4767. self.symtable.DefList.foreachcall(@check_and_finish_msg,nil);
  4768. if (oo_is_external in objectoptions) then
  4769. self.symtable.SymList.ForEachCall(@mark_private_fields_used,nil);
  4770. end;
  4771. procedure verify_objc_vardef(data: tobject; arg: pointer);
  4772. var
  4773. sym: tabstractvarsym absolute data;
  4774. res: pboolean absolute arg;
  4775. founderrordef: tdef;
  4776. begin
  4777. if not(tsym(data).typ in [paravarsym,fieldvarsym]) then
  4778. exit;
  4779. if (sym.typ=paravarsym) and
  4780. ((vo_is_hidden_para in tparavarsym(sym).varoptions) or
  4781. is_array_of_const(tparavarsym(sym).vardef)) then
  4782. exit;
  4783. if not objcchecktype(sym.vardef,founderrordef) then
  4784. begin
  4785. MessagePos1(sym.fileinfo,type_e_objc_type_unsupported,founderrordef.typename);
  4786. res^:=false;
  4787. end;
  4788. end;
  4789. procedure verify_objc_procdef_paras(data: tobject; arg: pointer);
  4790. var
  4791. def: tdef absolute data;
  4792. res: pboolean absolute arg;
  4793. founderrordef: tdef;
  4794. begin
  4795. if (def.typ<>procdef) then
  4796. exit;
  4797. { check parameter types for validity }
  4798. tprocdef(def).paras.foreachcall(@verify_objc_vardef,arg);
  4799. { check the result type for validity }
  4800. if not objcchecktype(tprocdef(def).returndef,founderrordef) then
  4801. begin
  4802. MessagePos1(tprocdef(def).funcretsym.fileinfo,type_e_objc_type_unsupported,founderrordef.typename);
  4803. res^:=false;
  4804. end;
  4805. end;
  4806. function tobjectdef.check_objc_types: boolean;
  4807. begin
  4808. { done in separate step from finish_objc_data, because when
  4809. finish_objc_data is called, not all forwarddefs have been resolved
  4810. yet and we need to know all types here }
  4811. result:=true;
  4812. self.symtable.symlist.foreachcall(@verify_objc_vardef,@result);
  4813. self.symtable.deflist.foreachcall(@verify_objc_procdef_paras,@result);
  4814. end;
  4815. procedure do_cpp_import_info(data: tobject; arg: pointer);
  4816. var
  4817. def: tdef absolute data;
  4818. pd: tprocdef absolute data;
  4819. begin
  4820. if (def.typ=procdef) then
  4821. begin
  4822. pd.setmangledname(target_info.Cprefix+pd.cplusplusmangledname);
  4823. if (oo_is_external in pd.struct.objectoptions) then
  4824. begin
  4825. { copied from psub.read_proc }
  4826. if assigned(tobjectdef(pd.struct).import_lib) then
  4827. current_module.AddExternalImport(tobjectdef(pd.struct).import_lib^,pd.mangledname,pd.mangledname,0,false,false)
  4828. else
  4829. begin
  4830. { add import name to external list for DLL scanning }
  4831. if tf_has_dllscanner in target_info.flags then
  4832. current_module.dllscannerinputlist.Add(pd.mangledname,pd);
  4833. end;
  4834. end;
  4835. end;
  4836. end;
  4837. procedure tobjectdef.finish_cpp_data;
  4838. begin
  4839. self.symtable.DefList.ForEachCall(@do_cpp_import_info,nil);
  4840. end;
  4841. function tobjectdef.jvm_full_typename: string;
  4842. begin
  4843. result:='';
  4844. if assigned(import_lib) then
  4845. result:=import_lib^+'/';
  4846. result:=result+objextname^;
  4847. end;
  4848. {****************************************************************************
  4849. TImplementedInterface
  4850. ****************************************************************************}
  4851. constructor TImplementedInterface.create(aintf: tobjectdef);
  4852. begin
  4853. inherited create;
  4854. intfdef:=aintf;
  4855. IOffset:=-1;
  4856. IType:=etStandard;
  4857. NameMappings:=nil;
  4858. procdefs:=nil;
  4859. end;
  4860. constructor TImplementedInterface.create_deref(d:tderef);
  4861. begin
  4862. inherited create;
  4863. intfdef:=nil;
  4864. intfdefderef:=d;
  4865. IOffset:=-1;
  4866. IType:=etStandard;
  4867. NameMappings:=nil;
  4868. procdefs:=nil;
  4869. end;
  4870. destructor TImplementedInterface.destroy;
  4871. var
  4872. i : longint;
  4873. mappedname : pshortstring;
  4874. begin
  4875. if assigned(NameMappings) then
  4876. begin
  4877. for i:=0 to NameMappings.Count-1 do
  4878. begin
  4879. mappedname:=pshortstring(NameMappings[i]);
  4880. stringdispose(mappedname);
  4881. end;
  4882. NameMappings.free;
  4883. NameMappings:=nil;
  4884. end;
  4885. if assigned(procdefs) then
  4886. begin
  4887. procdefs.free;
  4888. procdefs:=nil;
  4889. end;
  4890. inherited destroy;
  4891. end;
  4892. procedure TImplementedInterface.buildderef;
  4893. begin
  4894. intfdefderef.build(intfdef);
  4895. end;
  4896. procedure TImplementedInterface.deref;
  4897. begin
  4898. intfdef:=tobjectdef(intfdefderef.resolve);
  4899. end;
  4900. procedure TImplementedInterface.AddMapping(const origname,newname: string);
  4901. begin
  4902. if not assigned(NameMappings) then
  4903. NameMappings:=TFPHashList.Create;
  4904. NameMappings.Add(origname,stringdup(newname));
  4905. end;
  4906. function TImplementedInterface.GetMapping(const origname: string):string;
  4907. var
  4908. mappedname : pshortstring;
  4909. begin
  4910. result:='';
  4911. if not assigned(NameMappings) then
  4912. exit;
  4913. mappedname:=PShortstring(NameMappings.Find(origname));
  4914. if assigned(mappedname) then
  4915. result:=mappedname^;
  4916. end;
  4917. procedure TImplementedInterface.AddImplProc(pd:tprocdef);
  4918. begin
  4919. if not assigned(procdefs) then
  4920. procdefs:=TFPObjectList.Create(false);
  4921. { duplicate entries must be stored, because multiple }
  4922. { interfaces can declare methods with the same name }
  4923. { and all of these get their own VMT entry }
  4924. procdefs.Add(pd);
  4925. end;
  4926. function TImplementedInterface.IsImplMergePossible(MergingIntf:TImplementedInterface;out weight: longint): boolean;
  4927. var
  4928. i : longint;
  4929. begin
  4930. result:=false;
  4931. { interfaces being implemented through delegation are not mergable (FK) }
  4932. if (IType<>etStandard) or (MergingIntf.IType<>etStandard) or not(assigned(ProcDefs)) or not(assigned(MergingIntf.ProcDefs)) then
  4933. exit;
  4934. weight:=0;
  4935. { empty interface is mergeable }
  4936. if ProcDefs.Count=0 then
  4937. begin
  4938. result:=true;
  4939. exit;
  4940. end;
  4941. { The interface to merge must at least the number of
  4942. procedures of this interface }
  4943. if MergingIntf.ProcDefs.Count<ProcDefs.Count then
  4944. exit;
  4945. for i:=0 to ProcDefs.Count-1 do
  4946. begin
  4947. if MergingIntf.ProcDefs[i]<>ProcDefs[i] then
  4948. exit;
  4949. end;
  4950. weight:=ProcDefs.Count;
  4951. result:=true;
  4952. end;
  4953. function TImplementedInterface.getcopy:TImplementedInterface;
  4954. begin
  4955. Result:=TImplementedInterface.Create(nil);
  4956. { 1) the procdefs list will be freed once for each copy
  4957. 2) since the procdefs list owns its elements, those will also be freed for each copy
  4958. 3) idem for the name mappings
  4959. }
  4960. { warning: this is completely wrong on so many levels...
  4961. Move(pointer(self)^,pointer(result)^,InstanceSize);
  4962. We need to make clean copies of the different fields
  4963. this is not implemented yet, and thus we generate an internal
  4964. error instead PM 2011-06-14 }
  4965. internalerror(2011061401);
  4966. end;
  4967. {****************************************************************************
  4968. TFORWARDDEF
  4969. ****************************************************************************}
  4970. constructor tforwarddef.create(const s:string;const pos:tfileposinfo);
  4971. begin
  4972. inherited create(forwarddef);
  4973. tosymname:=stringdup(s);
  4974. forwardpos:=pos;
  4975. end;
  4976. function tforwarddef.GetTypeName:string;
  4977. begin
  4978. GetTypeName:='unresolved forward to '+tosymname^;
  4979. end;
  4980. destructor tforwarddef.destroy;
  4981. begin
  4982. stringdispose(tosymname);
  4983. inherited destroy;
  4984. end;
  4985. function tforwarddef.getcopy:tstoreddef;
  4986. begin
  4987. result:=tforwarddef.create(tosymname^, forwardpos);
  4988. end;
  4989. {****************************************************************************
  4990. TUNDEFINEDDEF
  4991. ****************************************************************************}
  4992. constructor tundefineddef.create;
  4993. begin
  4994. inherited create(undefineddef);
  4995. end;
  4996. constructor tundefineddef.ppuload(ppufile:tcompilerppufile);
  4997. begin
  4998. inherited ppuload(undefineddef,ppufile);
  4999. end;
  5000. function tundefineddef.GetTypeName:string;
  5001. begin
  5002. GetTypeName:='<undefined type>';
  5003. end;
  5004. procedure tundefineddef.ppuwrite(ppufile:tcompilerppufile);
  5005. begin
  5006. inherited ppuwrite(ppufile);
  5007. ppufile.writeentry(ibundefineddef);
  5008. end;
  5009. {****************************************************************************
  5010. TERRORDEF
  5011. ****************************************************************************}
  5012. constructor terrordef.create;
  5013. begin
  5014. inherited create(errordef);
  5015. { prevent consecutive faults }
  5016. savesize:=1;
  5017. end;
  5018. procedure terrordef.ppuwrite(ppufile:tcompilerppufile);
  5019. begin
  5020. { Can't write errordefs to ppu }
  5021. internalerror(200411063);
  5022. end;
  5023. function terrordef.GetTypeName:string;
  5024. begin
  5025. GetTypeName:='<erroneous type>';
  5026. end;
  5027. function terrordef.getmangledparaname:string;
  5028. begin
  5029. getmangledparaname:='error';
  5030. end;
  5031. {****************************************************************************
  5032. Definition Helpers
  5033. ****************************************************************************}
  5034. function is_interfacecom(def: tdef): boolean;
  5035. begin
  5036. is_interfacecom:=
  5037. assigned(def) and
  5038. (def.typ=objectdef) and
  5039. (tobjectdef(def).objecttype=odt_interfacecom);
  5040. end;
  5041. function is_interfacecom_or_dispinterface(def: tdef): boolean;
  5042. begin
  5043. is_interfacecom_or_dispinterface:=
  5044. assigned(def) and
  5045. (def.typ=objectdef) and
  5046. (tobjectdef(def).objecttype in [odt_interfacecom,odt_dispinterface]);
  5047. end;
  5048. function is_interfacecorba(def: tdef): boolean;
  5049. begin
  5050. is_interfacecorba:=
  5051. assigned(def) and
  5052. (def.typ=objectdef) and
  5053. (tobjectdef(def).objecttype=odt_interfacecorba);
  5054. end;
  5055. function is_interface(def: tdef): boolean;
  5056. begin
  5057. is_interface:=
  5058. assigned(def) and
  5059. (def.typ=objectdef) and
  5060. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  5061. end;
  5062. function is_dispinterface(def: tdef): boolean;
  5063. begin
  5064. result:=
  5065. assigned(def) and
  5066. (def.typ=objectdef) and
  5067. (tobjectdef(def).objecttype=odt_dispinterface);
  5068. end;
  5069. function is_class(def: tdef): boolean;
  5070. begin
  5071. is_class:=
  5072. assigned(def) and
  5073. (def.typ=objectdef) and
  5074. (tobjectdef(def).objecttype=odt_class);
  5075. end;
  5076. function is_object(def: tdef): boolean;
  5077. begin
  5078. is_object:=
  5079. assigned(def) and
  5080. (def.typ=objectdef) and
  5081. (tobjectdef(def).objecttype=odt_object);
  5082. end;
  5083. function is_cppclass(def: tdef): boolean;
  5084. begin
  5085. is_cppclass:=
  5086. assigned(def) and
  5087. (def.typ=objectdef) and
  5088. (tobjectdef(def).objecttype=odt_cppclass);
  5089. end;
  5090. function is_objcclass(def: tdef): boolean;
  5091. begin
  5092. is_objcclass:=
  5093. assigned(def) and
  5094. (def.typ=objectdef) and
  5095. (tobjectdef(def).objecttype=odt_objcclass);
  5096. end;
  5097. function is_objectpascal_helper(def: tdef): boolean;
  5098. begin
  5099. result:=
  5100. assigned(def) and
  5101. (def.typ=objectdef) and
  5102. (tobjectdef(def).objecttype=odt_helper);
  5103. end;
  5104. function is_objcclassref(def: tdef): boolean;
  5105. begin
  5106. is_objcclassref:=
  5107. assigned(def) and
  5108. (def.typ=classrefdef) and
  5109. is_objcclass(tclassrefdef(def).pointeddef);
  5110. end;
  5111. function is_objcprotocol(def: tdef): boolean;
  5112. begin
  5113. result:=
  5114. assigned(def) and
  5115. (def.typ=objectdef) and
  5116. (tobjectdef(def).objecttype=odt_objcprotocol);
  5117. end;
  5118. function is_objccategory(def: tdef): boolean;
  5119. begin
  5120. result:=
  5121. assigned(def) and
  5122. (def.typ=objectdef) and
  5123. { if used as a forward type }
  5124. ((tobjectdef(def).objecttype=odt_objccategory) or
  5125. { if used as after it has been resolved }
  5126. ((tobjectdef(def).objecttype=odt_objcclass) and
  5127. (oo_is_classhelper in tobjectdef(def).objectoptions)));
  5128. end;
  5129. function is_objc_class_or_protocol(def: tdef): boolean;
  5130. begin
  5131. result:=
  5132. assigned(def) and
  5133. (def.typ=objectdef) and
  5134. (tobjectdef(def).objecttype in [odt_objcclass,odt_objcprotocol]);
  5135. end;
  5136. function is_objc_protocol_or_category(def: tdef): boolean;
  5137. begin
  5138. result:=
  5139. assigned(def) and
  5140. (def.typ=objectdef) and
  5141. ((tobjectdef(def).objecttype = odt_objcprotocol) or
  5142. ((tobjectdef(def).objecttype = odt_objcclass) and
  5143. (oo_is_classhelper in tobjectdef(def).objectoptions)));
  5144. end;
  5145. function is_classhelper(def: tdef): boolean;
  5146. begin
  5147. result:=
  5148. is_objectpascal_helper(def) or
  5149. is_objccategory(def);
  5150. end;
  5151. function is_class_or_interface(def: tdef): boolean;
  5152. begin
  5153. result:=
  5154. assigned(def) and
  5155. (def.typ=objectdef) and
  5156. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  5157. end;
  5158. function is_class_or_interface_or_objc(def: tdef): boolean;
  5159. begin
  5160. result:=
  5161. assigned(def) and
  5162. (def.typ=objectdef) and
  5163. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_objcclass,odt_objcprotocol]);
  5164. end;
  5165. function is_class_or_interface_or_object(def: tdef): boolean;
  5166. begin
  5167. result:=
  5168. assigned(def) and
  5169. (def.typ=objectdef) and
  5170. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_object]);
  5171. end;
  5172. function is_class_or_interface_or_dispinterface(def: tdef): boolean;
  5173. begin
  5174. result:=
  5175. assigned(def) and
  5176. (def.typ=objectdef) and
  5177. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface]);
  5178. end;
  5179. function is_implicit_pointer_object_type(def: tdef): boolean;
  5180. begin
  5181. result:=
  5182. assigned(def) and
  5183. (def.typ=objectdef) and
  5184. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava]);
  5185. end;
  5186. function is_class_or_object(def: tdef): boolean;
  5187. begin
  5188. result:=
  5189. assigned(def) and
  5190. (def.typ=objectdef) and
  5191. (tobjectdef(def).objecttype in [odt_class,odt_object]);
  5192. end;
  5193. function is_record(def: tdef): boolean;
  5194. begin
  5195. result:=
  5196. assigned(def) and
  5197. (def.typ=recorddef);
  5198. end;
  5199. function is_javaclass(def: tdef): boolean;
  5200. begin
  5201. result:=
  5202. assigned(def) and
  5203. (def.typ=objectdef) and
  5204. (tobjectdef(def).objecttype=odt_javaclass);
  5205. end;
  5206. function is_javainterface(def: tdef): boolean;
  5207. begin
  5208. result:=
  5209. assigned(def) and
  5210. (def.typ=objectdef) and
  5211. (tobjectdef(def).objecttype=odt_interfacejava);
  5212. end;
  5213. function is_java_class_or_interface(def: tdef): boolean;
  5214. begin
  5215. result:=
  5216. assigned(def) and
  5217. (def.typ=objectdef) and
  5218. (tobjectdef(def).objecttype in [odt_javaclass,odt_interfacejava]);
  5219. end;
  5220. procedure loadobjctypes;
  5221. begin
  5222. objc_metaclasstype:=tpointerdef(search_named_unit_globaltype('OBJC','POBJC_CLASS',true).typedef);
  5223. objc_superclasstype:=tpointerdef(search_named_unit_globaltype('OBJC','POBJC_SUPER',true).typedef);
  5224. objc_idtype:=tpointerdef(search_named_unit_globaltype('OBJC','ID',true).typedef);
  5225. objc_seltype:=tpointerdef(search_named_unit_globaltype('OBJC','SEL',true).typedef);
  5226. objc_objecttype:=trecorddef(search_named_unit_globaltype('OBJC','OBJC_OBJECT',true).typedef);
  5227. end;
  5228. procedure maybeloadcocoatypes;
  5229. var
  5230. tsym: ttypesym;
  5231. begin
  5232. if assigned(objc_fastenumeration) then
  5233. exit;
  5234. tsym:=search_named_unit_globaltype('COCOAALL','NSFASTENUMERATIONPROTOCOL',false);
  5235. if assigned(tsym) then
  5236. objc_fastenumeration:=tobjectdef(tsym.typedef)
  5237. else
  5238. objc_fastenumeration:=nil;
  5239. tsym:=search_named_unit_globaltype('COCOAALL','NSFASTENUMERATIONSTATE',false);
  5240. if assigned(tsym) then
  5241. objc_fastenumerationstate:=trecorddef(tsym.typedef)
  5242. else
  5243. objc_fastenumerationstate:=nil;
  5244. end;
  5245. function use_vectorfpu(def : tdef) : boolean;
  5246. begin
  5247. {$ifdef x86}
  5248. {$define use_vectorfpuimplemented}
  5249. use_vectorfpu:=(is_single(def) and (current_settings.fputype in sse_singlescalar)) or
  5250. (is_double(def) and (current_settings.fputype in sse_doublescalar));
  5251. {$endif x86}
  5252. {$ifdef arm}
  5253. {$define use_vectorfpuimplemented}
  5254. use_vectorfpu:=(current_settings.fputype in vfp_scalar);
  5255. {$endif arm}
  5256. {$ifndef use_vectorfpuimplemented}
  5257. use_vectorfpu:=false;
  5258. {$endif}
  5259. end;
  5260. end.