symdef.pas 187 KB

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