symdef.pas 186 KB

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