symdef.pas 185 KB

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