symdef.pas 175 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl, Pierre Muller
  4. Symbol table implementation for the definitions
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit symdef;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. { common }
  23. cutils,cclasses,
  24. { global }
  25. globtype,globals,tokens,
  26. { symtable }
  27. symconst,symbase,symtype,
  28. { ppu }
  29. symppu,ppu,
  30. { node }
  31. node,
  32. { aasm }
  33. aasmbase,aasmtai,cpubase,cpuinfo
  34. {$ifdef Delphi}
  35. ,dmisc
  36. {$endif}
  37. ;
  38. type
  39. {************************************************
  40. TDef
  41. ************************************************}
  42. tstoreddef = class(tdef)
  43. { persistent (available across units) rtti and init tables }
  44. rttitablesym,
  45. inittablesym : tsym; {trttisym}
  46. { local (per module) rtti and init tables }
  47. localrttilab : array[trttitype] of tasmlabel;
  48. { linked list of global definitions }
  49. nextglobal,
  50. previousglobal : tstoreddef;
  51. {$ifdef EXTDEBUG}
  52. fileinfo : tfileposinfo;
  53. {$endif}
  54. {$ifdef GDB}
  55. globalnb : word;
  56. is_def_stab_written : tdefstabstatus;
  57. {$endif GDB}
  58. constructor create;
  59. constructor ppuloaddef(ppufile:tcompilerppufile);
  60. destructor destroy;override;
  61. procedure ppuwritedef(ppufile:tcompilerppufile);
  62. procedure ppuwrite(ppufile:tcompilerppufile);virtual;abstract;
  63. procedure deref;override;
  64. procedure derefimpl;override;
  65. function size:longint;override;
  66. function alignment:longint;override;
  67. function is_publishable : boolean;override;
  68. function needs_inittable : boolean;override;
  69. { debug }
  70. {$ifdef GDB}
  71. function stabstring : pchar;virtual;
  72. procedure concatstabto(asmlist : taasmoutput);virtual;
  73. function NumberString:string;
  74. procedure set_globalnb;virtual;
  75. function allstabstring : pchar;virtual;
  76. {$endif GDB}
  77. { rtti generation }
  78. procedure write_rtti_name;
  79. procedure write_rtti_data(rt:trttitype);virtual;
  80. procedure write_child_rtti_data(rt:trttitype);virtual;
  81. function get_rtti_label(rt:trttitype):tasmsymbol;
  82. { regvars }
  83. function is_intregable : boolean;
  84. function is_fpuregable : boolean;
  85. private
  86. savesize : longint;
  87. end;
  88. tparaitem = class(TLinkedListItem)
  89. paratype : ttype;
  90. parasym : tsym;
  91. paratyp : tvarspez;
  92. paraloc : tparalocation;
  93. argconvtyp : targconvtyp;
  94. convertlevel : byte;
  95. defaultvalue : tsym; { tconstsym }
  96. end;
  97. { this is only here to override the count method,
  98. which can't be used }
  99. tparalinkedlist = class(tlinkedlist)
  100. function count:longint;
  101. end;
  102. tfiletyp = (ft_text,ft_typed,ft_untyped);
  103. tfiledef = class(tstoreddef)
  104. filetyp : tfiletyp;
  105. typedfiletype : ttype;
  106. constructor createtext;
  107. constructor createuntyped;
  108. constructor createtyped(const tt : ttype);
  109. constructor ppuload(ppufile:tcompilerppufile);
  110. procedure ppuwrite(ppufile:tcompilerppufile);override;
  111. procedure deref;override;
  112. function gettypename:string;override;
  113. function getmangledparaname:string;override;
  114. procedure setsize;
  115. { debug }
  116. {$ifdef GDB}
  117. function stabstring : pchar;override;
  118. procedure concatstabto(asmlist : taasmoutput);override;
  119. {$endif GDB}
  120. end;
  121. tvariantdef = class(tstoreddef)
  122. constructor create;
  123. constructor ppuload(ppufile:tcompilerppufile);
  124. function gettypename:string;override;
  125. procedure ppuwrite(ppufile:tcompilerppufile);override;
  126. procedure setsize;
  127. function needs_inittable : boolean;override;
  128. procedure write_rtti_data(rt:trttitype);override;
  129. end;
  130. tformaldef = class(tstoreddef)
  131. constructor create;
  132. constructor ppuload(ppufile:tcompilerppufile);
  133. procedure ppuwrite(ppufile:tcompilerppufile);override;
  134. function gettypename:string;override;
  135. {$ifdef GDB}
  136. function stabstring : pchar;override;
  137. procedure concatstabto(asmlist : taasmoutput);override;
  138. {$endif GDB}
  139. end;
  140. tforwarddef = class(tstoreddef)
  141. tosymname : string;
  142. forwardpos : tfileposinfo;
  143. constructor create(const s:string;const pos : tfileposinfo);
  144. function gettypename:string;override;
  145. end;
  146. terrordef = class(tstoreddef)
  147. constructor create;
  148. function gettypename:string;override;
  149. function getmangledparaname : string;override;
  150. { debug }
  151. {$ifdef GDB}
  152. function stabstring : pchar;override;
  153. {$endif GDB}
  154. end;
  155. { tpointerdef and tclassrefdef should get a common
  156. base class, but I derived tclassrefdef from tpointerdef
  157. to avoid problems with bugs (FK)
  158. }
  159. tpointerdef = class(tstoreddef)
  160. pointertype : ttype;
  161. is_far : boolean;
  162. constructor create(const tt : ttype);
  163. constructor createfar(const tt : ttype);
  164. constructor ppuload(ppufile:tcompilerppufile);
  165. procedure ppuwrite(ppufile:tcompilerppufile);override;
  166. procedure deref;override;
  167. function gettypename:string;override;
  168. { debug }
  169. {$ifdef GDB}
  170. function stabstring : pchar;override;
  171. procedure concatstabto(asmlist : taasmoutput);override;
  172. {$endif GDB}
  173. end;
  174. tabstractrecorddef = class(tstoreddef)
  175. private
  176. Count : integer;
  177. FRTTIType : trttitype;
  178. {$ifdef GDB}
  179. StabRecString : pchar;
  180. StabRecSize : Integer;
  181. RecOffset : Integer;
  182. procedure addname(p : tnamedindexitem;arg:pointer);
  183. {$endif}
  184. procedure count_field_rtti(sym : tnamedindexitem;arg:pointer);
  185. procedure write_field_rtti(sym : tnamedindexitem;arg:pointer);
  186. procedure generate_field_rtti(sym : tnamedindexitem;arg:pointer);
  187. public
  188. symtable : tsymtable;
  189. function getsymtable(t:tgetsymtable):tsymtable;override;
  190. end;
  191. trecorddef = class(tabstractrecorddef)
  192. public
  193. isunion : boolean;
  194. constructor create(p : tsymtable);
  195. constructor ppuload(ppufile:tcompilerppufile);
  196. destructor destroy;override;
  197. procedure ppuwrite(ppufile:tcompilerppufile);override;
  198. procedure deref;override;
  199. function size:longint;override;
  200. function alignment : longint;override;
  201. function gettypename:string;override;
  202. { debug }
  203. {$ifdef GDB}
  204. function stabstring : pchar;override;
  205. procedure concatstabto(asmlist : taasmoutput);override;
  206. {$endif GDB}
  207. function needs_inittable : boolean;override;
  208. { rtti }
  209. procedure write_child_rtti_data(rt:trttitype);override;
  210. procedure write_rtti_data(rt:trttitype);override;
  211. end;
  212. tprocdef = class;
  213. timplementedinterfaces = class;
  214. tobjectdef = class(tabstractrecorddef)
  215. private
  216. sd : tprocdef;
  217. procedure _searchdestructor(sym : tnamedindexitem;arg:pointer);
  218. {$ifdef GDB}
  219. procedure addprocname(p :tnamedindexitem;arg:pointer);
  220. {$endif GDB}
  221. procedure count_published_properties(sym:tnamedindexitem;arg:pointer);
  222. procedure write_property_info(sym : tnamedindexitem;arg:pointer);
  223. procedure generate_published_child_rtti(sym : tnamedindexitem;arg:pointer);
  224. procedure count_published_fields(sym:tnamedindexitem;arg:pointer);
  225. procedure writefields(sym:tnamedindexitem;arg:pointer);
  226. public
  227. childof : tobjectdef;
  228. objname,
  229. objrealname : pstring;
  230. objectoptions : tobjectoptions;
  231. { to be able to have a variable vmt position }
  232. { and no vmt field for objects without virtuals }
  233. vmt_offset : longint;
  234. {$ifdef GDB}
  235. writing_class_record_stab : boolean;
  236. {$endif GDB}
  237. objecttype : tobjectdeftype;
  238. isiidguidvalid: boolean;
  239. iidguid: TGUID;
  240. iidstr: pstring;
  241. lastvtableindex: longint;
  242. { store implemented interfaces defs and name mappings }
  243. implementedinterfaces: timplementedinterfaces;
  244. constructor create(ot : tobjectdeftype;const n : string;c : tobjectdef);
  245. constructor ppuload(ppufile:tcompilerppufile);
  246. destructor destroy;override;
  247. procedure ppuwrite(ppufile:tcompilerppufile);override;
  248. procedure deref;override;
  249. function size : longint;override;
  250. function alignment:longint;override;
  251. function vmtmethodoffset(index:longint):longint;
  252. function members_need_inittable : boolean;
  253. function is_publishable : boolean;override;
  254. function needs_inittable : boolean;override;
  255. function vmt_mangledname : string;
  256. function rtti_name : string;
  257. procedure check_forwards;
  258. function is_related(d : tobjectdef) : boolean;
  259. function next_free_name_index : longint;
  260. procedure insertvmt;
  261. procedure set_parent(c : tobjectdef);
  262. function searchdestructor : tprocdef;
  263. { debug }
  264. {$ifdef GDB}
  265. function stabstring : pchar;override;
  266. procedure set_globalnb;override;
  267. function classnumberstring : string;
  268. procedure concatstabto(asmlist : taasmoutput);override;
  269. function allstabstring : pchar;override;
  270. {$endif GDB}
  271. { rtti }
  272. procedure write_child_rtti_data(rt:trttitype);override;
  273. procedure write_rtti_data(rt:trttitype);override;
  274. function generate_field_table : tasmlabel;
  275. end;
  276. timplementedinterfaces = class
  277. constructor create;
  278. destructor destroy; override;
  279. function count: longint;
  280. function interfaces(intfindex: longint): tobjectdef;
  281. function ioffsets(intfindex: longint): plongint;
  282. function searchintf(def: tdef): longint;
  283. procedure addintf(def: tdef);
  284. procedure deref;
  285. { add interface reference loaded from ppu }
  286. procedure addintfref(def: pointer);
  287. procedure clearmappings;
  288. procedure addmappings(intfindex: longint; const name, newname: string);
  289. function getmappings(intfindex: longint; const name: string; var nextexist: pointer): string;
  290. procedure clearimplprocs;
  291. procedure addimplproc(intfindex: longint; procdef: tprocdef);
  292. function implproccount(intfindex: longint): longint;
  293. function implprocs(intfindex: longint; procindex: longint): tprocdef;
  294. function isimplmergepossible(intfindex, remainindex: longint; var weight: longint): boolean;
  295. private
  296. finterfaces: tindexarray;
  297. procedure checkindex(intfindex: longint);
  298. end;
  299. tclassrefdef = class(tpointerdef)
  300. constructor create(const t:ttype);
  301. constructor ppuload(ppufile:tcompilerppufile);
  302. procedure ppuwrite(ppufile:tcompilerppufile);override;
  303. function gettypename:string;override;
  304. { debug }
  305. {$ifdef GDB}
  306. function stabstring : pchar;override;
  307. procedure concatstabto(asmlist : taasmoutput);override;
  308. {$endif GDB}
  309. end;
  310. tarraydef = class(tstoreddef)
  311. rangenr : longint;
  312. lowrange,
  313. highrange : longint;
  314. rangetype : ttype;
  315. IsDynamicArray,
  316. IsVariant,
  317. IsConstructor,
  318. IsArrayOfConst : boolean;
  319. protected
  320. _elementtype : ttype;
  321. public
  322. function elesize : longint;
  323. constructor create(l,h : longint;const t : ttype);
  324. constructor ppuload(ppufile:tcompilerppufile);
  325. procedure ppuwrite(ppufile:tcompilerppufile);override;
  326. function gettypename:string;override;
  327. function getmangledparaname : string;override;
  328. procedure setelementtype(t: ttype);
  329. {$ifdef GDB}
  330. function stabstring : pchar;override;
  331. procedure concatstabto(asmlist : taasmoutput);override;
  332. {$endif GDB}
  333. procedure deref;override;
  334. function size : longint;override;
  335. function alignment : longint;override;
  336. { returns the label of the range check string }
  337. function needs_inittable : boolean;override;
  338. procedure write_child_rtti_data(rt:trttitype);override;
  339. procedure write_rtti_data(rt:trttitype);override;
  340. property elementtype : ttype Read _ElementType;
  341. end;
  342. torddef = class(tstoreddef)
  343. rangenr : longint;
  344. low,high : TConstExprInt;
  345. typ : tbasetype;
  346. constructor create(t : tbasetype;v,b : TConstExprInt);
  347. constructor ppuload(ppufile:tcompilerppufile);
  348. procedure ppuwrite(ppufile:tcompilerppufile);override;
  349. function is_publishable : boolean;override;
  350. function gettypename:string;override;
  351. procedure setsize;
  352. { debug }
  353. {$ifdef GDB}
  354. function stabstring : pchar;override;
  355. {$endif GDB}
  356. { rtti }
  357. procedure write_rtti_data(rt:trttitype);override;
  358. end;
  359. tfloatdef = class(tstoreddef)
  360. typ : tfloattype;
  361. constructor create(t : tfloattype);
  362. constructor ppuload(ppufile:tcompilerppufile);
  363. procedure ppuwrite(ppufile:tcompilerppufile);override;
  364. function gettypename:string;override;
  365. function is_publishable : boolean;override;
  366. procedure setsize;
  367. { debug }
  368. {$ifdef GDB}
  369. function stabstring : pchar;override;
  370. {$endif GDB}
  371. { rtti }
  372. procedure write_rtti_data(rt:trttitype);override;
  373. end;
  374. tabstractprocdef = class(tstoreddef)
  375. { saves a definition to the return type }
  376. rettype : ttype;
  377. proctypeoption : tproctypeoption;
  378. proccalloption : tproccalloption;
  379. procoptions : tprocoptions;
  380. para : tparalinkedlist;
  381. maxparacount,
  382. minparacount : longint;
  383. symtablelevel : byte;
  384. fpu_used : byte; { how many stack fpu must be empty }
  385. constructor create;
  386. constructor ppuload(ppufile:tcompilerppufile);
  387. destructor destroy;override;
  388. procedure ppuwrite(ppufile:tcompilerppufile);override;
  389. procedure deref;override;
  390. procedure concatpara(const tt:ttype;sym : tsym;vsp : tvarspez;defval:tsym);
  391. function para_size(alignsize:longint) : longint;
  392. function typename_paras : string;
  393. procedure test_if_fpu_result;
  394. { debug }
  395. {$ifdef GDB}
  396. function stabstring : pchar;override;
  397. procedure concatstabto(asmlist : taasmoutput);override;
  398. {$endif GDB}
  399. end;
  400. tprocvardef = class(tabstractprocdef)
  401. constructor create;
  402. constructor ppuload(ppufile:tcompilerppufile);
  403. procedure ppuwrite(ppufile:tcompilerppufile);override;
  404. function size : longint;override;
  405. function gettypename:string;override;
  406. function is_publishable : boolean;override;
  407. { debug }
  408. {$ifdef GDB}
  409. function stabstring : pchar;override;
  410. procedure concatstabto(asmlist : taasmoutput); override;
  411. {$endif GDB}
  412. { rtti }
  413. procedure write_rtti_data(rt:trttitype);override;
  414. end;
  415. tmessageinf = record
  416. case integer of
  417. 0 : (str : pchar);
  418. 1 : (i : longint);
  419. end;
  420. tprocdef = class(tabstractprocdef)
  421. private
  422. _mangledname : pstring;
  423. {$ifdef GDB}
  424. isstabwritten : boolean;
  425. {$endif GDB}
  426. public
  427. extnumber : word;
  428. overloadnumber : word;
  429. messageinf : tmessageinf;
  430. {$ifndef EXTDEBUG}
  431. { where is this function defined, needed here because there
  432. is only one symbol for all overloaded functions
  433. EXTDEBUG has fileinfo in tdef (PFV) }
  434. fileinfo : tfileposinfo;
  435. {$endif}
  436. { symbol owning this definition }
  437. procsym : tsym;
  438. { alias names }
  439. aliasnames : tstringlist;
  440. { symtables }
  441. parast,
  442. localst : tsymtable;
  443. funcretsym : tsym;
  444. { next is only used to check if RESULT is accessed,
  445. not stored in a tnode }
  446. resultfuncretsym : tsym;
  447. { browser info }
  448. lastref,
  449. defref,
  450. crossref,
  451. lastwritten : tref;
  452. refcount : longint;
  453. _class : tobjectdef;
  454. { it's a tree, but this not easy to handle }
  455. { used for inlined procs }
  456. code : tnode;
  457. { info about register variables (JM) }
  458. regvarinfo: pointer;
  459. { true, if the procedure is only declared }
  460. { (forward procedure) }
  461. forwarddef,
  462. { true if the procedure is declared in the interface }
  463. interfacedef : boolean;
  464. { true if the procedure has a forward declaration }
  465. hasforward : boolean;
  466. { check the problems of manglednames }
  467. has_mangledname : boolean;
  468. { small set which contains the modified registers }
  469. usedregisters : tregisterset;
  470. constructor create;
  471. constructor ppuload(ppufile:tcompilerppufile);
  472. destructor destroy;override;
  473. procedure ppuwrite(ppufile:tcompilerppufile);override;
  474. procedure deref;override;
  475. procedure derefimpl;override;
  476. function getsymtable(t:tgetsymtable):tsymtable;override;
  477. function haspara:boolean;
  478. function mangledname : string;
  479. procedure setmangledname(const s : string);
  480. procedure load_references(ppufile:tcompilerppufile;locals:boolean);
  481. function write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  482. function fullprocname:string;
  483. function fullprocnamewithret:string;
  484. function cplusplusmangledname : string;
  485. { debug }
  486. {$ifdef GDB}
  487. function stabstring : pchar;override;
  488. procedure concatstabto(asmlist : taasmoutput);override;
  489. {$endif GDB}
  490. end;
  491. { single linked list of overloaded procs }
  492. pprocdeflist = ^tprocdeflist;
  493. tprocdeflist = record
  494. def : tprocdef;
  495. next : pprocdeflist;
  496. end;
  497. tstringdef = class(tstoreddef)
  498. string_typ : tstringtype;
  499. len : longint;
  500. constructor createshort(l : byte);
  501. constructor loadshort(ppufile:tcompilerppufile);
  502. constructor createlong(l : longint);
  503. constructor loadlong(ppufile:tcompilerppufile);
  504. constructor createansi(l : longint);
  505. constructor loadansi(ppufile:tcompilerppufile);
  506. constructor createwide(l : longint);
  507. constructor loadwide(ppufile:tcompilerppufile);
  508. function stringtypname:string;
  509. function size : longint;override;
  510. procedure ppuwrite(ppufile:tcompilerppufile);override;
  511. function gettypename:string;override;
  512. function getmangledparaname:string;override;
  513. function is_publishable : boolean;override;
  514. { debug }
  515. {$ifdef GDB}
  516. function stabstring : pchar;override;
  517. procedure concatstabto(asmlist : taasmoutput);override;
  518. {$endif GDB}
  519. { init/final }
  520. function needs_inittable : boolean;override;
  521. { rtti }
  522. procedure write_rtti_data(rt:trttitype);override;
  523. end;
  524. tenumdef = class(tstoreddef)
  525. rangenr,
  526. minval,
  527. maxval : longint;
  528. has_jumps : boolean;
  529. firstenum : tsym; {tenumsym}
  530. basedef : tenumdef;
  531. constructor create;
  532. constructor create_subrange(_basedef:tenumdef;_min,_max:longint);
  533. constructor ppuload(ppufile:tcompilerppufile);
  534. destructor destroy;override;
  535. procedure ppuwrite(ppufile:tcompilerppufile);override;
  536. procedure deref;override;
  537. function gettypename:string;override;
  538. function is_publishable : boolean;override;
  539. procedure calcsavesize;
  540. procedure setmax(_max:longint);
  541. procedure setmin(_min:longint);
  542. function min:longint;
  543. function max:longint;
  544. { debug }
  545. {$ifdef GDB}
  546. function stabstring : pchar;override;
  547. {$endif GDB}
  548. { rtti }
  549. procedure write_rtti_data(rt:trttitype);override;
  550. procedure write_child_rtti_data(rt:trttitype);override;
  551. private
  552. procedure correct_owner_symtable;
  553. end;
  554. tsetdef = class(tstoreddef)
  555. elementtype : ttype;
  556. settype : tsettype;
  557. constructor create(const t:ttype;high : longint);
  558. constructor ppuload(ppufile:tcompilerppufile);
  559. destructor destroy;override;
  560. procedure ppuwrite(ppufile:tcompilerppufile);override;
  561. procedure deref;override;
  562. function gettypename:string;override;
  563. function is_publishable : boolean;override;
  564. procedure changesettype(s:tsettype);
  565. { debug }
  566. {$ifdef GDB}
  567. function stabstring : pchar;override;
  568. procedure concatstabto(asmlist : taasmoutput);override;
  569. {$endif GDB}
  570. { rtti }
  571. procedure write_rtti_data(rt:trttitype);override;
  572. procedure write_child_rtti_data(rt:trttitype);override;
  573. end;
  574. Tdefmatch=(dm_exact,dm_equal,dm_convertl1);
  575. var
  576. aktobjectdef : tobjectdef; { used for private functions check !! }
  577. firstglobaldef, { linked list of all globals defs }
  578. lastglobaldef : tstoreddef; { used to reset stabs/ranges }
  579. {$ifdef GDB}
  580. { for STAB debugging }
  581. globaltypecount : word;
  582. pglobaltypecount : pword;
  583. {$endif GDB}
  584. { default types }
  585. generrortype, { error in definition }
  586. voidpointertype, { pointer for Void-Pointerdef }
  587. charpointertype, { pointer for Char-Pointerdef }
  588. voidfarpointertype,
  589. cformaltype, { unique formal definition }
  590. voidtype, { Pointer to Void (procedure) }
  591. cchartype, { Pointer to Char }
  592. cwidechartype, { Pointer to WideChar }
  593. booltype, { pointer to boolean type }
  594. u8bittype, { Pointer to 8-Bit unsigned }
  595. u16bittype, { Pointer to 16-Bit unsigned }
  596. u32bittype, { Pointer to 32-Bit unsigned }
  597. s32bittype, { Pointer to 32-Bit signed }
  598. cu64bittype, { pointer to 64 bit unsigned def }
  599. cs64bittype, { pointer to 64 bit signed def, }
  600. s32floattype, { pointer for realconstn }
  601. s64floattype, { pointer for realconstn }
  602. s80floattype, { pointer to type of temp. floats }
  603. s64currencytype, { pointer to a currency type }
  604. s32fixedtype, { pointer to type of temp. fixed }
  605. cshortstringtype, { pointer to type of short string const }
  606. clongstringtype, { pointer to type of long string const }
  607. cansistringtype, { pointer to type of ansi string const }
  608. cwidestringtype, { pointer to type of wide string const }
  609. openshortstringtype, { pointer to type of an open shortstring,
  610. needed for readln() }
  611. openchararraytype, { pointer to type of an open array of char,
  612. needed for readln() }
  613. cfiletype, { get the same definition for all file }
  614. { used for stabs }
  615. { we use only one variant def }
  616. cvarianttype,
  617. { unsigned ord type with the same size as a pointer }
  618. ordpointertype,
  619. pvmttype : ttype; { type of classrefs, used for stabs }
  620. class_tobject : tobjectdef; { pointer to the anchestor of all classes }
  621. interface_iunknown : tobjectdef; { KAZ: pointer to the ancestor }
  622. rec_tguid : trecorddef; { KAZ: pointer to the TGUID type }
  623. { of all interfaces }
  624. const
  625. {$ifdef i386}
  626. pbestrealtype : ^ttype = @s80floattype;
  627. {$endif}
  628. {$ifdef m68k}
  629. pbestrealtype : ^ttype = @s64floattype;
  630. {$endif}
  631. {$ifdef alpha}
  632. pbestrealtype : ^ttype = @s64floattype;
  633. {$endif}
  634. {$ifdef powerpc}
  635. pbestrealtype : ^ttype = @s64floattype;
  636. {$endif}
  637. {$ifdef ia64}
  638. pbestrealtype : ^ttype = @s64floattype;
  639. {$endif}
  640. {$ifdef SPARC}
  641. pbestrealtype : ^ttype = @s64floattype;
  642. {$endif SPARC}
  643. function mangledname_prefix(typeprefix:string;st:tsymtable):string;
  644. {$ifdef GDB}
  645. { GDB Helpers }
  646. function typeglobalnumber(const s : string) : string;
  647. {$endif GDB}
  648. { should be in the types unit, but the types unit uses the node stuff :( }
  649. function is_interfacecom(def: tdef): boolean;
  650. function is_interfacecorba(def: tdef): boolean;
  651. function is_interface(def: tdef): boolean;
  652. function is_object(def: tdef): boolean;
  653. function is_class(def: tdef): boolean;
  654. function is_cppclass(def: tdef): boolean;
  655. function is_class_or_interface(def: tdef): boolean;
  656. procedure reset_global_defs;
  657. implementation
  658. uses
  659. {$ifdef Delphi}
  660. sysutils,
  661. {$else Delphi}
  662. strings,
  663. {$endif Delphi}
  664. { global }
  665. verbose,
  666. { target }
  667. aasmcpu,
  668. systems,
  669. { symtable }
  670. symsym,symtable,paramgr,
  671. defbase,
  672. { module }
  673. {$ifdef GDB}
  674. gdb,
  675. {$endif GDB}
  676. fmodule,
  677. { other }
  678. gendef
  679. ;
  680. {****************************************************************************
  681. Helpers
  682. ****************************************************************************}
  683. function mangledname_prefix(typeprefix:string;st:tsymtable):string;
  684. var
  685. s,
  686. prefix : string;
  687. begin
  688. prefix:='';
  689. if not assigned(st) then
  690. internalerror(200204212);
  691. { sub procedures }
  692. while (st.symtabletype=localsymtable) do
  693. begin
  694. if st.defowner.deftype<>procdef then
  695. internalerror(200204173);
  696. s:=tprocdef(st.defowner).procsym.name;
  697. if tprocdef(st.defowner).overloadnumber>0 then
  698. s:=s+'$'+tostr(tprocdef(st.defowner).overloadnumber);
  699. prefix:=s+'$'+prefix;
  700. st:=st.defowner.owner;
  701. end;
  702. { object/classes symtable }
  703. if (st.symtabletype=objectsymtable) then
  704. begin
  705. if st.defowner.deftype<>objectdef then
  706. internalerror(200204174);
  707. prefix:=tobjectdef(st.defowner).objname^+'_$_'+prefix;
  708. st:=st.defowner.owner;
  709. end;
  710. { symtable must now be static or global }
  711. if not(st.symtabletype in [staticsymtable,globalsymtable]) then
  712. internalerror(200204175);
  713. mangledname_prefix:=typeprefix+'_'+st.name^+'_'+prefix;
  714. end;
  715. {$ifdef GDB}
  716. procedure forcestabto(asmlist : taasmoutput; pd : tdef);
  717. begin
  718. if tstoreddef(pd).is_def_stab_written = not_written then
  719. begin
  720. if assigned(pd.typesym) then
  721. ttypesym(pd.typesym).isusedinstab := true;
  722. tstoreddef(pd).concatstabto(asmlist);
  723. end;
  724. end;
  725. {$endif GDB}
  726. {****************************************************************************
  727. TDEF (base class for definitions)
  728. ****************************************************************************}
  729. constructor tstoreddef.create;
  730. begin
  731. inherited create;
  732. savesize := 0;
  733. {$ifdef EXTDEBUG}
  734. fileinfo := aktfilepos;
  735. {$endif}
  736. if registerdef then
  737. symtablestack.registerdef(self);
  738. {$ifdef GDB}
  739. is_def_stab_written := not_written;
  740. globalnb := 0;
  741. {$endif GDB}
  742. if assigned(lastglobaldef) then
  743. begin
  744. lastglobaldef.nextglobal := self;
  745. previousglobal:=lastglobaldef;
  746. end
  747. else
  748. begin
  749. firstglobaldef := self;
  750. previousglobal := nil;
  751. end;
  752. lastglobaldef := self;
  753. nextglobal := nil;
  754. fillchar(localrttilab,sizeof(localrttilab),0);
  755. end;
  756. constructor tstoreddef.ppuloaddef(ppufile:tcompilerppufile);
  757. begin
  758. inherited create;
  759. {$ifdef EXTDEBUG}
  760. fillchar(fileinfo,sizeof(fileinfo),0);
  761. {$endif}
  762. {$ifdef GDB}
  763. is_def_stab_written := not_written;
  764. globalnb := 0;
  765. {$endif GDB}
  766. if assigned(lastglobaldef) then
  767. begin
  768. lastglobaldef.nextglobal := self;
  769. previousglobal:=lastglobaldef;
  770. end
  771. else
  772. begin
  773. firstglobaldef := self;
  774. previousglobal:=nil;
  775. end;
  776. lastglobaldef := self;
  777. nextglobal := nil;
  778. fillchar(localrttilab,sizeof(localrttilab),0);
  779. { load }
  780. indexnr:=ppufile.getword;
  781. typesym:=ttypesym(pointer(ppufile.getderef));
  782. ppufile.getsmallset(defoptions);
  783. if df_has_rttitable in defoptions then
  784. rttitablesym:=tsym(ppufile.getderef);
  785. if df_has_inittable in defoptions then
  786. inittablesym:=tsym(ppufile.getderef);
  787. end;
  788. destructor tstoreddef.destroy;
  789. begin
  790. { first element ? }
  791. if not(assigned(previousglobal)) then
  792. begin
  793. firstglobaldef := nextglobal;
  794. if assigned(firstglobaldef) then
  795. firstglobaldef.previousglobal:=nil;
  796. end
  797. else
  798. begin
  799. { remove reference in the element before }
  800. previousglobal.nextglobal:=nextglobal;
  801. end;
  802. { last element ? }
  803. if not(assigned(nextglobal)) then
  804. begin
  805. lastglobaldef := previousglobal;
  806. if assigned(lastglobaldef) then
  807. lastglobaldef.nextglobal:=nil;
  808. end
  809. else
  810. nextglobal.previousglobal:=previousglobal;
  811. previousglobal:=nil;
  812. nextglobal:=nil;
  813. end;
  814. procedure tstoreddef.ppuwritedef(ppufile:tcompilerppufile);
  815. begin
  816. ppufile.putword(indexnr);
  817. ppufile.putderef(typesym);
  818. ppufile.putsmallset(defoptions);
  819. if df_has_rttitable in defoptions then
  820. ppufile.putderef(rttitablesym);
  821. if df_has_inittable in defoptions then
  822. ppufile.putderef(inittablesym);
  823. {$ifdef GDB}
  824. if globalnb = 0 then
  825. begin
  826. if assigned(owner) then
  827. globalnb := owner.getnewtypecount
  828. else
  829. begin
  830. globalnb := PGlobalTypeCount^;
  831. Inc(PGlobalTypeCount^);
  832. end;
  833. end;
  834. {$endif GDB}
  835. end;
  836. procedure tstoreddef.deref;
  837. begin
  838. resolvesym(pointer(typesym));
  839. resolvesym(pointer(rttitablesym));
  840. resolvesym(pointer(inittablesym));
  841. end;
  842. procedure tstoreddef.derefimpl;
  843. begin
  844. end;
  845. function tstoreddef.size : longint;
  846. begin
  847. size:=savesize;
  848. end;
  849. function tstoreddef.alignment : longint;
  850. begin
  851. { normal alignment by default }
  852. alignment:=0;
  853. end;
  854. {$ifdef GDB}
  855. procedure tstoreddef.set_globalnb;
  856. begin
  857. globalnb :=PGlobalTypeCount^;
  858. inc(PglobalTypeCount^);
  859. end;
  860. function tstoreddef.stabstring : pchar;
  861. begin
  862. stabstring := strpnew('t'+numberstring+';');
  863. end;
  864. function tstoreddef.numberstring : string;
  865. var table : tsymtable;
  866. begin
  867. {formal def have no type !}
  868. if deftype = formaldef then
  869. begin
  870. numberstring := tstoreddef(voidtype.def).numberstring;
  871. exit;
  872. end;
  873. if (not assigned(typesym)) or (not ttypesym(typesym).isusedinstab) then
  874. begin
  875. {set even if debuglist is not defined}
  876. if assigned(typesym) then
  877. ttypesym(typesym).isusedinstab := true;
  878. if assigned(debuglist) and (is_def_stab_written = not_written) then
  879. concatstabto(debuglist);
  880. end;
  881. if not (cs_gdb_dbx in aktglobalswitches) then
  882. begin
  883. if globalnb = 0 then
  884. set_globalnb;
  885. numberstring := tostr(globalnb);
  886. end
  887. else
  888. begin
  889. if globalnb = 0 then
  890. begin
  891. if assigned(owner) then
  892. globalnb := owner.getnewtypecount
  893. else
  894. begin
  895. globalnb := PGlobalTypeCount^;
  896. Inc(PGlobalTypeCount^);
  897. end;
  898. end;
  899. if assigned(typesym) then
  900. begin
  901. table := ttypesym(typesym).owner;
  902. if table.unitid > 0 then
  903. numberstring := '('+tostr(table.unitid)+','+tostr(tstoreddef(ttypesym(typesym).restype.def).globalnb)+')'
  904. else
  905. numberstring := tostr(globalnb);
  906. exit;
  907. end;
  908. numberstring := tostr(globalnb);
  909. end;
  910. end;
  911. function tstoreddef.allstabstring : pchar;
  912. var stabchar : string[2];
  913. ss,st : pchar;
  914. sname : string;
  915. sym_line_no : longint;
  916. begin
  917. ss := stabstring;
  918. getmem(st,strlen(ss)+512);
  919. stabchar := 't';
  920. if deftype in tagtypes then
  921. stabchar := 'Tt';
  922. if assigned(typesym) then
  923. begin
  924. sname := ttypesym(typesym).name;
  925. sym_line_no:=ttypesym(typesym).fileinfo.line;
  926. end
  927. else
  928. begin
  929. sname := ' ';
  930. sym_line_no:=0;
  931. end;
  932. strpcopy(st,'"'+sname+':'+stabchar+numberstring+'=');
  933. strpcopy(strecopy(strend(st),ss),'",'+tostr(N_LSYM)+',0,'+tostr(sym_line_no)+',0');
  934. allstabstring := strnew(st);
  935. freemem(st,strlen(ss)+512);
  936. strdispose(ss);
  937. end;
  938. procedure tstoreddef.concatstabto(asmlist : taasmoutput);
  939. var stab_str : pchar;
  940. begin
  941. if ((typesym = nil) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches))
  942. and (is_def_stab_written = not_written) then
  943. begin
  944. If cs_gdb_dbx in aktglobalswitches then
  945. begin
  946. { otherwise you get two of each def }
  947. If assigned(typesym) then
  948. begin
  949. if ttypesym(typesym).typ=symconst.typesym then
  950. ttypesym(typesym).isusedinstab:=true;
  951. if (ttypesym(typesym).owner = nil) or
  952. ((ttypesym(typesym).owner.symtabletype = globalsymtable) and
  953. tglobalsymtable(ttypesym(typesym).owner).dbx_count_ok) then
  954. begin
  955. {with DBX we get the definition from the other objects }
  956. is_def_stab_written := written;
  957. exit;
  958. end;
  959. end;
  960. end;
  961. { to avoid infinite loops }
  962. is_def_stab_written := being_written;
  963. stab_str := allstabstring;
  964. asmList.concat(Tai_stabs.Create(stab_str));
  965. is_def_stab_written := written;
  966. end;
  967. end;
  968. {$endif GDB}
  969. procedure tstoreddef.write_rtti_name;
  970. var
  971. str : string;
  972. begin
  973. { name }
  974. if assigned(typesym) then
  975. begin
  976. str:=ttypesym(typesym).realname;
  977. rttiList.concat(Tai_string.Create(chr(length(str))+str));
  978. end
  979. else
  980. rttiList.concat(Tai_string.Create(#0))
  981. end;
  982. procedure tstoreddef.write_rtti_data(rt:trttitype);
  983. begin
  984. rttilist.concat(tai_const.create_8bit(tkUnknown));
  985. write_rtti_name;
  986. end;
  987. procedure tstoreddef.write_child_rtti_data(rt:trttitype);
  988. begin
  989. end;
  990. function tstoreddef.get_rtti_label(rt:trttitype) : tasmsymbol;
  991. begin
  992. { try to reuse persistent rtti data }
  993. if (rt=fullrtti) and (df_has_rttitable in defoptions) then
  994. get_rtti_label:=trttisym(rttitablesym).get_label
  995. else
  996. if (rt=initrtti) and (df_has_inittable in defoptions) then
  997. get_rtti_label:=trttisym(inittablesym).get_label
  998. else
  999. begin
  1000. if not assigned(localrttilab[rt]) then
  1001. begin
  1002. objectlibrary.getdatalabel(localrttilab[rt]);
  1003. write_child_rtti_data(rt);
  1004. if (cs_create_smart in aktmoduleswitches) then
  1005. rttiList.concat(Tai_cut.Create);
  1006. rttiList.concat(Tai_align.create(const_align(pointer_size)));
  1007. rttiList.concat(Tai_symbol.Create(localrttilab[rt],0));
  1008. write_rtti_data(rt);
  1009. rttiList.concat(Tai_symbol_end.Create(localrttilab[rt]));
  1010. end;
  1011. get_rtti_label:=localrttilab[rt];
  1012. end;
  1013. end;
  1014. { returns true, if the definition can be published }
  1015. function tstoreddef.is_publishable : boolean;
  1016. begin
  1017. is_publishable:=false;
  1018. end;
  1019. { needs an init table }
  1020. function tstoreddef.needs_inittable : boolean;
  1021. begin
  1022. needs_inittable:=false;
  1023. end;
  1024. function tstoreddef.is_intregable : boolean;
  1025. begin
  1026. is_intregable:=false;
  1027. case deftype of
  1028. pointerdef,
  1029. enumdef:
  1030. is_intregable:=true;
  1031. procvardef :
  1032. is_intregable:=not(po_methodpointer in tprocvardef(self).procoptions);
  1033. orddef :
  1034. case torddef(self).typ of
  1035. bool8bit,bool16bit,bool32bit,
  1036. u8bit,u16bit,u32bit,
  1037. s8bit,s16bit,s32bit:
  1038. is_intregable:=true;
  1039. end;
  1040. setdef:
  1041. is_intregable:=(tsetdef(self).settype=smallset);
  1042. end;
  1043. end;
  1044. function tstoreddef.is_fpuregable : boolean;
  1045. begin
  1046. is_fpuregable:=(deftype=floatdef);
  1047. end;
  1048. {****************************************************************************
  1049. TPARALINKEDLIST
  1050. ****************************************************************************}
  1051. function tparalinkedlist.count:longint;
  1052. begin
  1053. { You must use tabstractprocdef.minparacount and .maxparacount instead }
  1054. internalerror(432432978);
  1055. count:=0;
  1056. end;
  1057. {****************************************************************************
  1058. Tstringdef
  1059. ****************************************************************************}
  1060. constructor tstringdef.createshort(l : byte);
  1061. begin
  1062. inherited create;
  1063. string_typ:=st_shortstring;
  1064. deftype:=stringdef;
  1065. len:=l;
  1066. savesize:=len+1;
  1067. end;
  1068. constructor tstringdef.loadshort(ppufile:tcompilerppufile);
  1069. begin
  1070. inherited ppuloaddef(ppufile);
  1071. string_typ:=st_shortstring;
  1072. deftype:=stringdef;
  1073. len:=ppufile.getbyte;
  1074. savesize:=len+1;
  1075. end;
  1076. constructor tstringdef.createlong(l : longint);
  1077. begin
  1078. inherited create;
  1079. string_typ:=st_longstring;
  1080. deftype:=stringdef;
  1081. len:=l;
  1082. savesize:=POINTER_SIZE;
  1083. end;
  1084. constructor tstringdef.loadlong(ppufile:tcompilerppufile);
  1085. begin
  1086. inherited ppuloaddef(ppufile);
  1087. deftype:=stringdef;
  1088. string_typ:=st_longstring;
  1089. len:=ppufile.getlongint;
  1090. savesize:=POINTER_SIZE;
  1091. end;
  1092. constructor tstringdef.createansi(l : longint);
  1093. begin
  1094. inherited create;
  1095. string_typ:=st_ansistring;
  1096. deftype:=stringdef;
  1097. len:=l;
  1098. savesize:=POINTER_SIZE;
  1099. end;
  1100. constructor tstringdef.loadansi(ppufile:tcompilerppufile);
  1101. begin
  1102. inherited ppuloaddef(ppufile);
  1103. deftype:=stringdef;
  1104. string_typ:=st_ansistring;
  1105. len:=ppufile.getlongint;
  1106. savesize:=POINTER_SIZE;
  1107. end;
  1108. constructor tstringdef.createwide(l : longint);
  1109. begin
  1110. inherited create;
  1111. string_typ:=st_widestring;
  1112. deftype:=stringdef;
  1113. len:=l;
  1114. savesize:=POINTER_SIZE;
  1115. end;
  1116. constructor tstringdef.loadwide(ppufile:tcompilerppufile);
  1117. begin
  1118. inherited ppuloaddef(ppufile);
  1119. deftype:=stringdef;
  1120. string_typ:=st_widestring;
  1121. len:=ppufile.getlongint;
  1122. savesize:=POINTER_SIZE;
  1123. end;
  1124. function tstringdef.stringtypname:string;
  1125. const
  1126. typname:array[tstringtype] of string[8]=('',
  1127. 'shortstr','longstr','ansistr','widestr'
  1128. );
  1129. begin
  1130. stringtypname:=typname[string_typ];
  1131. end;
  1132. function tstringdef.size : longint;
  1133. begin
  1134. size:=savesize;
  1135. end;
  1136. procedure tstringdef.ppuwrite(ppufile:tcompilerppufile);
  1137. begin
  1138. inherited ppuwritedef(ppufile);
  1139. if string_typ=st_shortstring then
  1140. ppufile.putbyte(len)
  1141. else
  1142. ppufile.putlongint(len);
  1143. case string_typ of
  1144. st_shortstring : ppufile.writeentry(ibshortstringdef);
  1145. st_longstring : ppufile.writeentry(iblongstringdef);
  1146. st_ansistring : ppufile.writeentry(ibansistringdef);
  1147. st_widestring : ppufile.writeentry(ibwidestringdef);
  1148. end;
  1149. end;
  1150. {$ifdef GDB}
  1151. function tstringdef.stabstring : pchar;
  1152. var
  1153. bytest,charst,longst : string;
  1154. begin
  1155. case string_typ of
  1156. st_shortstring:
  1157. begin
  1158. charst := typeglobalnumber('char');
  1159. { this is what I found in stabs.texinfo but
  1160. gdb 4.12 for go32 doesn't understand that !! }
  1161. {$IfDef GDBknowsstrings}
  1162. stabstring := strpnew('n'+charst+';'+tostr(len));
  1163. {$else}
  1164. bytest := typeglobalnumber('byte');
  1165. stabstring := strpnew('s'+tostr(len+1)+'length:'+bytest
  1166. +',0,8;st:ar'+bytest
  1167. +';1;'+tostr(len)+';'+charst+',8,'+tostr(len*8)+';;');
  1168. {$EndIf}
  1169. end;
  1170. st_longstring:
  1171. begin
  1172. charst := typeglobalnumber('char');
  1173. { this is what I found in stabs.texinfo but
  1174. gdb 4.12 for go32 doesn't understand that !! }
  1175. {$IfDef GDBknowsstrings}
  1176. stabstring := strpnew('n'+charst+';'+tostr(len));
  1177. {$else}
  1178. bytest := typeglobalnumber('byte');
  1179. longst := typeglobalnumber('longint');
  1180. stabstring := strpnew('s'+tostr(len+5)+'length:'+longst
  1181. +',0,32;dummy:'+bytest+',32,8;st:ar'+bytest
  1182. +';1;'+tostr(len)+';'+charst+',40,'+tostr(len*8)+';;');
  1183. {$EndIf}
  1184. end;
  1185. st_ansistring:
  1186. begin
  1187. { an ansi string looks like a pchar easy !! }
  1188. stabstring:=strpnew('*'+typeglobalnumber('char'));
  1189. end;
  1190. st_widestring:
  1191. begin
  1192. { an ansi string looks like a pwidechar easy !! }
  1193. stabstring:=strpnew('*'+typeglobalnumber('widechar'));
  1194. end;
  1195. end;
  1196. end;
  1197. procedure tstringdef.concatstabto(asmlist : taasmoutput);
  1198. begin
  1199. inherited concatstabto(asmlist);
  1200. end;
  1201. {$endif GDB}
  1202. function tstringdef.needs_inittable : boolean;
  1203. begin
  1204. needs_inittable:=string_typ in [st_ansistring,st_widestring];
  1205. end;
  1206. function tstringdef.gettypename : string;
  1207. const
  1208. names : array[tstringtype] of string[20] = ('',
  1209. 'ShortString','LongString','AnsiString','WideString');
  1210. begin
  1211. gettypename:=names[string_typ];
  1212. end;
  1213. procedure tstringdef.write_rtti_data(rt:trttitype);
  1214. begin
  1215. case string_typ of
  1216. st_ansistring:
  1217. begin
  1218. rttiList.concat(Tai_const.Create_8bit(tkAString));
  1219. write_rtti_name;
  1220. end;
  1221. st_widestring:
  1222. begin
  1223. rttiList.concat(Tai_const.Create_8bit(tkWString));
  1224. write_rtti_name;
  1225. end;
  1226. st_longstring:
  1227. begin
  1228. rttiList.concat(Tai_const.Create_8bit(tkLString));
  1229. write_rtti_name;
  1230. end;
  1231. st_shortstring:
  1232. begin
  1233. rttiList.concat(Tai_const.Create_8bit(tkSString));
  1234. write_rtti_name;
  1235. rttiList.concat(Tai_const.Create_8bit(len));
  1236. end;
  1237. end;
  1238. end;
  1239. function tstringdef.getmangledparaname : string;
  1240. begin
  1241. getmangledparaname:='STRING';
  1242. end;
  1243. function tstringdef.is_publishable : boolean;
  1244. begin
  1245. is_publishable:=true;
  1246. end;
  1247. {****************************************************************************
  1248. TENUMDEF
  1249. ****************************************************************************}
  1250. constructor tenumdef.create;
  1251. begin
  1252. inherited create;
  1253. deftype:=enumdef;
  1254. minval:=0;
  1255. maxval:=0;
  1256. calcsavesize;
  1257. has_jumps:=false;
  1258. basedef:=nil;
  1259. rangenr:=0;
  1260. firstenum:=nil;
  1261. correct_owner_symtable;
  1262. end;
  1263. constructor tenumdef.create_subrange(_basedef:tenumdef;_min,_max:longint);
  1264. begin
  1265. inherited create;
  1266. deftype:=enumdef;
  1267. minval:=_min;
  1268. maxval:=_max;
  1269. basedef:=_basedef;
  1270. calcsavesize;
  1271. has_jumps:=false;
  1272. rangenr:=0;
  1273. firstenum:=basedef.firstenum;
  1274. while assigned(firstenum) and (tenumsym(firstenum).value<>minval) do
  1275. firstenum:=tenumsym(firstenum).nextenum;
  1276. correct_owner_symtable;
  1277. end;
  1278. constructor tenumdef.ppuload(ppufile:tcompilerppufile);
  1279. begin
  1280. inherited ppuloaddef(ppufile);
  1281. deftype:=enumdef;
  1282. basedef:=tenumdef(ppufile.getderef);
  1283. minval:=ppufile.getlongint;
  1284. maxval:=ppufile.getlongint;
  1285. savesize:=ppufile.getlongint;
  1286. has_jumps:=false;
  1287. firstenum:=Nil;
  1288. end;
  1289. procedure tenumdef.calcsavesize;
  1290. begin
  1291. if (aktpackenum=4) or (min<0) or (max>65535) then
  1292. savesize:=4
  1293. else
  1294. if (aktpackenum=2) or (min<0) or (max>255) then
  1295. savesize:=2
  1296. else
  1297. savesize:=1;
  1298. end;
  1299. procedure tenumdef.setmax(_max:longint);
  1300. begin
  1301. maxval:=_max;
  1302. calcsavesize;
  1303. end;
  1304. procedure tenumdef.setmin(_min:longint);
  1305. begin
  1306. minval:=_min;
  1307. calcsavesize;
  1308. end;
  1309. function tenumdef.min:longint;
  1310. begin
  1311. min:=minval;
  1312. end;
  1313. function tenumdef.max:longint;
  1314. begin
  1315. max:=maxval;
  1316. end;
  1317. procedure tenumdef.deref;
  1318. begin
  1319. inherited deref;
  1320. resolvedef(pointer(basedef));
  1321. end;
  1322. destructor tenumdef.destroy;
  1323. begin
  1324. inherited destroy;
  1325. end;
  1326. procedure tenumdef.ppuwrite(ppufile:tcompilerppufile);
  1327. begin
  1328. inherited ppuwritedef(ppufile);
  1329. ppufile.putderef(basedef);
  1330. ppufile.putlongint(min);
  1331. ppufile.putlongint(max);
  1332. ppufile.putlongint(savesize);
  1333. ppufile.writeentry(ibenumdef);
  1334. end;
  1335. { used for enumdef because the symbols are
  1336. inserted in the owner symtable }
  1337. procedure tenumdef.correct_owner_symtable;
  1338. var
  1339. st : tsymtable;
  1340. begin
  1341. if assigned(owner) and
  1342. (owner.symtabletype in [recordsymtable,objectsymtable]) then
  1343. begin
  1344. owner.defindex.deleteindex(self);
  1345. st:=owner;
  1346. while (st.symtabletype in [recordsymtable,objectsymtable]) do
  1347. st:=st.next;
  1348. st.registerdef(self);
  1349. end;
  1350. end;
  1351. {$ifdef GDB}
  1352. function tenumdef.stabstring : pchar;
  1353. var st,st2 : pchar;
  1354. p : tenumsym;
  1355. s : string;
  1356. memsize : word;
  1357. begin
  1358. memsize := memsizeinc;
  1359. getmem(st,memsize);
  1360. { we can specify the size with @s<size>; prefix PM }
  1361. if savesize <> std_param_align then
  1362. strpcopy(st,'@s'+tostr(savesize*8)+';e')
  1363. else
  1364. strpcopy(st,'e');
  1365. p := tenumsym(firstenum);
  1366. while assigned(p) do
  1367. begin
  1368. s :=p.name+':'+tostr(p.value)+',';
  1369. { place for the ending ';' also }
  1370. if (strlen(st)+length(s)+1<memsize) then
  1371. strpcopy(strend(st),s)
  1372. else
  1373. begin
  1374. getmem(st2,memsize+memsizeinc);
  1375. strcopy(st2,st);
  1376. freemem(st,memsize);
  1377. st := st2;
  1378. memsize := memsize+memsizeinc;
  1379. strpcopy(strend(st),s);
  1380. end;
  1381. p := p.nextenum;
  1382. end;
  1383. strpcopy(strend(st),';');
  1384. stabstring := strnew(st);
  1385. freemem(st,memsize);
  1386. end;
  1387. {$endif GDB}
  1388. procedure tenumdef.write_child_rtti_data(rt:trttitype);
  1389. begin
  1390. if assigned(basedef) then
  1391. basedef.get_rtti_label(rt);
  1392. end;
  1393. procedure tenumdef.write_rtti_data(rt:trttitype);
  1394. var
  1395. hp : tenumsym;
  1396. begin
  1397. rttiList.concat(Tai_const.Create_8bit(tkEnumeration));
  1398. write_rtti_name;
  1399. case savesize of
  1400. 1:
  1401. rttiList.concat(Tai_const.Create_8bit(otUByte));
  1402. 2:
  1403. rttiList.concat(Tai_const.Create_8bit(otUWord));
  1404. 4:
  1405. rttiList.concat(Tai_const.Create_8bit(otULong));
  1406. end;
  1407. rttiList.concat(Tai_const.Create_32bit(min));
  1408. rttiList.concat(Tai_const.Create_32bit(max));
  1409. if assigned(basedef) then
  1410. rttiList.concat(Tai_const_symbol.Create(basedef.get_rtti_label(rt)))
  1411. else
  1412. rttiList.concat(Tai_const.Create_32bit(0));
  1413. hp:=tenumsym(firstenum);
  1414. while assigned(hp) do
  1415. begin
  1416. rttiList.concat(Tai_const.Create_8bit(length(hp.name)));
  1417. rttiList.concat(Tai_string.Create(lower(hp.name)));
  1418. hp:=hp.nextenum;
  1419. end;
  1420. rttiList.concat(Tai_const.Create_8bit(0));
  1421. end;
  1422. function tenumdef.is_publishable : boolean;
  1423. begin
  1424. is_publishable:=true;
  1425. end;
  1426. function tenumdef.gettypename : string;
  1427. begin
  1428. gettypename:='<enumeration type>';
  1429. end;
  1430. {****************************************************************************
  1431. TORDDEF
  1432. ****************************************************************************}
  1433. constructor torddef.create(t : tbasetype;v,b : TConstExprInt);
  1434. begin
  1435. inherited create;
  1436. deftype:=orddef;
  1437. low:=v;
  1438. high:=b;
  1439. typ:=t;
  1440. rangenr:=0;
  1441. setsize;
  1442. end;
  1443. constructor torddef.ppuload(ppufile:tcompilerppufile);
  1444. var
  1445. l1,l2 : longint;
  1446. begin
  1447. inherited ppuloaddef(ppufile);
  1448. deftype:=orddef;
  1449. typ:=tbasetype(ppufile.getbyte);
  1450. if sizeof(TConstExprInt)=8 then
  1451. begin
  1452. l1:=ppufile.getlongint;
  1453. l2:=ppufile.getlongint;
  1454. {$ifopt R+}
  1455. {$define Range_check_on}
  1456. {$endif opt R+}
  1457. {$R- needed here }
  1458. low:=qword(l1)+(int64(l2) shl 32);
  1459. {$ifdef Range_check_on}
  1460. {$R+}
  1461. {$undef Range_check_on}
  1462. {$endif Range_check_on}
  1463. end
  1464. else
  1465. low:=ppufile.getlongint;
  1466. if sizeof(TConstExprInt)=8 then
  1467. begin
  1468. l1:=ppufile.getlongint;
  1469. l2:=ppufile.getlongint;
  1470. {$ifopt R+}
  1471. {$define Range_check_on}
  1472. {$endif opt R+}
  1473. {$R- needed here }
  1474. high:=qword(l1)+(int64(l2) shl 32);
  1475. {$ifdef Range_check_on}
  1476. {$R+}
  1477. {$undef Range_check_on}
  1478. {$endif Range_check_on}
  1479. end
  1480. else
  1481. high:=ppufile.getlongint;
  1482. rangenr:=0;
  1483. setsize;
  1484. end;
  1485. procedure torddef.setsize;
  1486. begin
  1487. case typ of
  1488. u8bit,s8bit,
  1489. uchar,bool8bit:
  1490. savesize:=1;
  1491. u16bit,s16bit,
  1492. bool16bit,uwidechar:
  1493. savesize:=2;
  1494. s32bit,u32bit,
  1495. bool32bit:
  1496. savesize:=4;
  1497. u64bit,s64bit:
  1498. savesize:=8;
  1499. else
  1500. savesize:=0;
  1501. end;
  1502. { there are no entrys for range checking }
  1503. rangenr:=0;
  1504. end;
  1505. procedure torddef.ppuwrite(ppufile:tcompilerppufile);
  1506. begin
  1507. inherited ppuwritedef(ppufile);
  1508. ppufile.putbyte(byte(typ));
  1509. if sizeof(TConstExprInt)=8 then
  1510. begin
  1511. ppufile.putlongint(longint(lo(low)));
  1512. ppufile.putlongint(longint(hi(low)));
  1513. end
  1514. else
  1515. ppufile.putlongint(low);
  1516. if sizeof(TConstExprInt)=8 then
  1517. begin
  1518. ppufile.putlongint(longint(lo(high)));
  1519. ppufile.putlongint(longint(hi(high)));
  1520. end
  1521. else
  1522. ppufile.putlongint(high);
  1523. ppufile.writeentry(iborddef);
  1524. end;
  1525. {$ifdef GDB}
  1526. function torddef.stabstring : pchar;
  1527. begin
  1528. case typ of
  1529. uvoid : stabstring := strpnew(numberstring+';');
  1530. {GDB 4.12 for go32 doesn't like boolean as range for 0 to 1 !!!}
  1531. {$ifdef Use_integer_types_for_boolean}
  1532. bool8bit,
  1533. bool16bit,
  1534. bool32bit : stabstring := strpnew('r'+numberstring+';0;255;');
  1535. {$else : not Use_integer_types_for_boolean}
  1536. uchar : stabstring := strpnew('-20;');
  1537. uwidechar : stabstring := strpnew('-30;');
  1538. bool8bit : stabstring := strpnew('-21;');
  1539. bool16bit : stabstring := strpnew('-22;');
  1540. bool32bit : stabstring := strpnew('-23;');
  1541. u64bit : stabstring := strpnew('-32;');
  1542. s64bit : stabstring := strpnew('-31;');
  1543. {$endif not Use_integer_types_for_boolean}
  1544. {u32bit : stabstring := tstoreddef(s32bittype.def).numberstring+';0;-1;'); }
  1545. else
  1546. stabstring := strpnew('r'+tstoreddef(s32bittype.def).numberstring+';'+tostr(longint(low))+';'+tostr(longint(high))+';');
  1547. end;
  1548. end;
  1549. {$endif GDB}
  1550. procedure torddef.write_rtti_data(rt:trttitype);
  1551. procedure dointeger;
  1552. const
  1553. trans : array[tbasetype] of byte =
  1554. (otUByte{otNone},
  1555. otUByte,otUWord,otULong,otUByte{otNone},
  1556. otSByte,otSWord,otSLong,otUByte{otNone},
  1557. otUByte,otUWord,otULong,
  1558. otUByte,otUWord);
  1559. begin
  1560. write_rtti_name;
  1561. rttiList.concat(Tai_const.Create_8bit(byte(trans[typ])));
  1562. rttiList.concat(Tai_const.Create_32bit(longint(low)));
  1563. rttiList.concat(Tai_const.Create_32bit(longint(high)));
  1564. end;
  1565. begin
  1566. case typ of
  1567. s64bit :
  1568. begin
  1569. rttiList.concat(Tai_const.Create_8bit(tkInt64));
  1570. write_rtti_name;
  1571. if target_info.endian=endian_little then
  1572. begin
  1573. { low }
  1574. rttiList.concat(Tai_const.Create_32bit($0));
  1575. rttiList.concat(Tai_const.Create_32bit(longint($80000000)));
  1576. { high }
  1577. rttiList.concat(Tai_const.Create_32bit(longint($ffffffff)));
  1578. rttiList.concat(Tai_const.Create_32bit($7fffffff));
  1579. end
  1580. else
  1581. begin
  1582. { low }
  1583. rttiList.concat(Tai_const.Create_32bit(longint($80000000)));
  1584. rttiList.concat(Tai_const.Create_32bit($0));
  1585. { high }
  1586. rttiList.concat(Tai_const.Create_32bit($7fffffff));
  1587. rttiList.concat(Tai_const.Create_32bit(longint($ffffffff)));
  1588. end;
  1589. end;
  1590. u64bit :
  1591. begin
  1592. rttiList.concat(Tai_const.Create_8bit(tkQWord));
  1593. write_rtti_name;
  1594. { low }
  1595. rttiList.concat(Tai_const.Create_32bit($0));
  1596. rttiList.concat(Tai_const.Create_32bit($0));
  1597. { high }
  1598. rttiList.concat(Tai_const.Create_32bit(longint($ffffffff)));
  1599. rttiList.concat(Tai_const.Create_32bit(longint($ffffffff)));
  1600. end;
  1601. bool8bit:
  1602. begin
  1603. rttiList.concat(Tai_const.Create_8bit(tkBool));
  1604. dointeger;
  1605. end;
  1606. uchar:
  1607. begin
  1608. rttiList.concat(Tai_const.Create_8bit(tkChar));
  1609. dointeger;
  1610. end;
  1611. uwidechar:
  1612. begin
  1613. rttiList.concat(Tai_const.Create_8bit(tkWChar));
  1614. dointeger;
  1615. end;
  1616. else
  1617. begin
  1618. rttiList.concat(Tai_const.Create_8bit(tkInteger));
  1619. dointeger;
  1620. end;
  1621. end;
  1622. end;
  1623. function torddef.is_publishable : boolean;
  1624. begin
  1625. is_publishable:=(typ<>uvoid);
  1626. end;
  1627. function torddef.gettypename : string;
  1628. const
  1629. names : array[tbasetype] of string[20] = (
  1630. 'untyped',
  1631. 'Byte','Word','DWord','QWord',
  1632. 'ShortInt','SmallInt','LongInt','Int64',
  1633. 'Boolean','WordBool','LongBool',
  1634. 'Char','WideChar');
  1635. begin
  1636. gettypename:=names[typ];
  1637. end;
  1638. {****************************************************************************
  1639. TFLOATDEF
  1640. ****************************************************************************}
  1641. constructor tfloatdef.create(t : tfloattype);
  1642. begin
  1643. inherited create;
  1644. deftype:=floatdef;
  1645. typ:=t;
  1646. setsize;
  1647. end;
  1648. constructor tfloatdef.ppuload(ppufile:tcompilerppufile);
  1649. begin
  1650. inherited ppuloaddef(ppufile);
  1651. deftype:=floatdef;
  1652. typ:=tfloattype(ppufile.getbyte);
  1653. setsize;
  1654. end;
  1655. procedure tfloatdef.setsize;
  1656. begin
  1657. case typ of
  1658. s32real : savesize:=4;
  1659. s80real : savesize:=extended_size;
  1660. s64real,
  1661. s64currency,
  1662. s64comp : savesize:=8;
  1663. else
  1664. savesize:=0;
  1665. end;
  1666. end;
  1667. procedure tfloatdef.ppuwrite(ppufile:tcompilerppufile);
  1668. begin
  1669. inherited ppuwritedef(ppufile);
  1670. ppufile.putbyte(byte(typ));
  1671. ppufile.writeentry(ibfloatdef);
  1672. end;
  1673. {$ifdef GDB}
  1674. function tfloatdef.stabstring : pchar;
  1675. begin
  1676. case typ of
  1677. s32real,
  1678. s64real : stabstring := strpnew('r'+
  1679. tstoreddef(s32bittype.def).numberstring+';'+tostr(savesize)+';0;');
  1680. { found this solution in stabsread.c from GDB v4.16 }
  1681. s64currency,
  1682. s64comp : stabstring := strpnew('r'+
  1683. tstoreddef(s32bittype.def).numberstring+';-'+tostr(savesize)+';0;');
  1684. { under dos at least you must give a size of twelve instead of 10 !! }
  1685. { this is probably do to the fact that in gcc all is pushed in 4 bytes size }
  1686. s80real : stabstring := strpnew('r'+tstoreddef(s32bittype.def).numberstring+';12;0;');
  1687. else
  1688. internalerror(10005);
  1689. end;
  1690. end;
  1691. {$endif GDB}
  1692. procedure tfloatdef.write_rtti_data(rt:trttitype);
  1693. const
  1694. {tfloattype = (s32real,s64real,s80real,s64bit);}
  1695. translate : array[tfloattype] of byte =
  1696. (ftSingle,ftDouble,ftExtended,ftComp,ftCurr);
  1697. begin
  1698. rttiList.concat(Tai_const.Create_8bit(tkFloat));
  1699. write_rtti_name;
  1700. rttiList.concat(Tai_const.Create_8bit(translate[typ]));
  1701. end;
  1702. function tfloatdef.is_publishable : boolean;
  1703. begin
  1704. is_publishable:=true;
  1705. end;
  1706. function tfloatdef.gettypename : string;
  1707. const
  1708. names : array[tfloattype] of string[20] = (
  1709. 'Single','Double','Extended','Comp','Currency');
  1710. begin
  1711. gettypename:=names[typ];
  1712. end;
  1713. {****************************************************************************
  1714. TFILEDEF
  1715. ****************************************************************************}
  1716. constructor tfiledef.createtext;
  1717. begin
  1718. inherited create;
  1719. deftype:=filedef;
  1720. filetyp:=ft_text;
  1721. typedfiletype.reset;
  1722. setsize;
  1723. end;
  1724. constructor tfiledef.createuntyped;
  1725. begin
  1726. inherited create;
  1727. deftype:=filedef;
  1728. filetyp:=ft_untyped;
  1729. typedfiletype.reset;
  1730. setsize;
  1731. end;
  1732. constructor tfiledef.createtyped(const tt : ttype);
  1733. begin
  1734. inherited create;
  1735. deftype:=filedef;
  1736. filetyp:=ft_typed;
  1737. typedfiletype:=tt;
  1738. setsize;
  1739. end;
  1740. constructor tfiledef.ppuload(ppufile:tcompilerppufile);
  1741. begin
  1742. inherited ppuloaddef(ppufile);
  1743. deftype:=filedef;
  1744. filetyp:=tfiletyp(ppufile.getbyte);
  1745. if filetyp=ft_typed then
  1746. ppufile.gettype(typedfiletype)
  1747. else
  1748. typedfiletype.reset;
  1749. setsize;
  1750. end;
  1751. procedure tfiledef.deref;
  1752. begin
  1753. inherited deref;
  1754. if filetyp=ft_typed then
  1755. typedfiletype.resolve;
  1756. end;
  1757. procedure tfiledef.setsize;
  1758. begin
  1759. case filetyp of
  1760. ft_text :
  1761. savesize:=572;
  1762. ft_typed,
  1763. ft_untyped :
  1764. savesize:=316;
  1765. end;
  1766. end;
  1767. procedure tfiledef.ppuwrite(ppufile:tcompilerppufile);
  1768. begin
  1769. inherited ppuwritedef(ppufile);
  1770. ppufile.putbyte(byte(filetyp));
  1771. if filetyp=ft_typed then
  1772. ppufile.puttype(typedfiletype);
  1773. ppufile.writeentry(ibfiledef);
  1774. end;
  1775. {$ifdef GDB}
  1776. function tfiledef.stabstring : pchar;
  1777. begin
  1778. {$IfDef GDBknowsfiles}
  1779. case filetyp of
  1780. ft_typed :
  1781. stabstring := strpnew('d'+typedfiletype.def.numberstring{+';'});
  1782. ft_untyped :
  1783. stabstring := strpnew('d'+voiddef.numberstring{+';'});
  1784. ft_text :
  1785. stabstring := strpnew('d'+cchartype^.numberstring{+';'});
  1786. end;
  1787. {$Else}
  1788. {based on
  1789. FileRec = Packed Record
  1790. Handle,
  1791. Mode,
  1792. RecSize : longint;
  1793. _private : array[1..32] of byte;
  1794. UserData : array[1..16] of byte;
  1795. name : array[0..255] of char;
  1796. End; }
  1797. { the buffer part is still missing !! (PM) }
  1798. { but the string could become too long !! }
  1799. stabstring := strpnew('s'+tostr(savesize)+
  1800. 'HANDLE:'+typeglobalnumber('longint')+',0,32;'+
  1801. 'MODE:'+typeglobalnumber('longint')+',32,32;'+
  1802. 'RECSIZE:'+typeglobalnumber('longint')+',64,32;'+
  1803. '_PRIVATE:ar'+typeglobalnumber('word')+';1;32;'+typeglobalnumber('byte')
  1804. +',96,256;'+
  1805. 'USERDATA:ar'+typeglobalnumber('word')+';1;16;'+typeglobalnumber('byte')
  1806. +',352,128;'+
  1807. 'NAME:ar'+typeglobalnumber('word')+';0;255;'+typeglobalnumber('char')
  1808. +',480,2048;;');
  1809. {$EndIf}
  1810. end;
  1811. procedure tfiledef.concatstabto(asmlist : taasmoutput);
  1812. begin
  1813. { most file defs are unnamed !!! }
  1814. if ((typesym = nil) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches)) and
  1815. (is_def_stab_written = not_written) then
  1816. begin
  1817. if assigned(typedfiletype.def) then
  1818. forcestabto(asmlist,typedfiletype.def);
  1819. inherited concatstabto(asmlist);
  1820. end;
  1821. end;
  1822. {$endif GDB}
  1823. function tfiledef.gettypename : string;
  1824. begin
  1825. case filetyp of
  1826. ft_untyped:
  1827. gettypename:='File';
  1828. ft_typed:
  1829. gettypename:='File Of '+typedfiletype.def.typename;
  1830. ft_text:
  1831. gettypename:='Text'
  1832. end;
  1833. end;
  1834. function tfiledef.getmangledparaname : string;
  1835. begin
  1836. case filetyp of
  1837. ft_untyped:
  1838. getmangledparaname:='FILE';
  1839. ft_typed:
  1840. getmangledparaname:='FILE$OF$'+typedfiletype.def.mangledparaname;
  1841. ft_text:
  1842. getmangledparaname:='TEXT'
  1843. end;
  1844. end;
  1845. {****************************************************************************
  1846. TVARIANTDEF
  1847. ****************************************************************************}
  1848. constructor tvariantdef.create;
  1849. begin
  1850. inherited create;
  1851. deftype:=variantdef;
  1852. setsize;
  1853. end;
  1854. constructor tvariantdef.ppuload(ppufile:tcompilerppufile);
  1855. begin
  1856. inherited ppuloaddef(ppufile);
  1857. deftype:=variantdef;
  1858. setsize;
  1859. end;
  1860. procedure tvariantdef.ppuwrite(ppufile:tcompilerppufile);
  1861. begin
  1862. inherited ppuwritedef(ppufile);
  1863. ppufile.writeentry(ibvariantdef);
  1864. end;
  1865. procedure tvariantdef.setsize;
  1866. begin
  1867. savesize:=16;
  1868. end;
  1869. function tvariantdef.gettypename : string;
  1870. begin
  1871. gettypename:='Variant';
  1872. end;
  1873. procedure tvariantdef.write_rtti_data(rt:trttitype);
  1874. begin
  1875. rttiList.concat(Tai_const.Create_8bit(tkVariant));
  1876. end;
  1877. function tvariantdef.needs_inittable : boolean;
  1878. begin
  1879. needs_inittable:=true;
  1880. end;
  1881. {****************************************************************************
  1882. TPOINTERDEF
  1883. ****************************************************************************}
  1884. constructor tpointerdef.create(const tt : ttype);
  1885. begin
  1886. inherited create;
  1887. deftype:=pointerdef;
  1888. pointertype:=tt;
  1889. is_far:=false;
  1890. savesize:=POINTER_SIZE;
  1891. end;
  1892. constructor tpointerdef.createfar(const tt : ttype);
  1893. begin
  1894. inherited create;
  1895. deftype:=pointerdef;
  1896. pointertype:=tt;
  1897. is_far:=true;
  1898. savesize:=POINTER_SIZE;
  1899. end;
  1900. constructor tpointerdef.ppuload(ppufile:tcompilerppufile);
  1901. begin
  1902. inherited ppuloaddef(ppufile);
  1903. deftype:=pointerdef;
  1904. ppufile.gettype(pointertype);
  1905. is_far:=(ppufile.getbyte<>0);
  1906. savesize:=POINTER_SIZE;
  1907. end;
  1908. procedure tpointerdef.deref;
  1909. begin
  1910. inherited deref;
  1911. pointertype.resolve;
  1912. end;
  1913. procedure tpointerdef.ppuwrite(ppufile:tcompilerppufile);
  1914. begin
  1915. inherited ppuwritedef(ppufile);
  1916. ppufile.puttype(pointertype);
  1917. ppufile.putbyte(byte(is_far));
  1918. ppufile.writeentry(ibpointerdef);
  1919. end;
  1920. {$ifdef GDB}
  1921. function tpointerdef.stabstring : pchar;
  1922. begin
  1923. stabstring := strpnew('*'+tstoreddef(pointertype.def).numberstring);
  1924. end;
  1925. procedure tpointerdef.concatstabto(asmlist : taasmoutput);
  1926. var st,nb : string;
  1927. sym_line_no : longint;
  1928. begin
  1929. if assigned(pointertype.def) and
  1930. (pointertype.def.deftype=forwarddef) then
  1931. exit;
  1932. if ( (typesym=nil) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches)) and
  1933. (is_def_stab_written = not_written) then
  1934. begin
  1935. is_def_stab_written := being_written;
  1936. if assigned(pointertype.def) and
  1937. (pointertype.def.deftype in [recorddef,objectdef]) then
  1938. begin
  1939. nb:=tstoreddef(pointertype.def).numberstring;
  1940. {to avoid infinite recursion in record with next-like fields }
  1941. if tstoreddef(pointertype.def).is_def_stab_written = being_written then
  1942. begin
  1943. if assigned(pointertype.def.typesym) then
  1944. begin
  1945. if assigned(typesym) then
  1946. begin
  1947. st := ttypesym(typesym).name;
  1948. sym_line_no:=ttypesym(typesym).fileinfo.line;
  1949. end
  1950. else
  1951. begin
  1952. st := ' ';
  1953. sym_line_no:=0;
  1954. end;
  1955. st := '"'+st+':t'+numberstring+'=*'+nb
  1956. +'=xs'+pointertype.def.typesym.name+':",'+tostr(N_LSYM)+',0,'+tostr(sym_line_no)+',0';
  1957. asmList.concat(Tai_stabs.Create(strpnew(st)));
  1958. end;
  1959. end
  1960. else
  1961. begin
  1962. is_def_stab_written := not_written;
  1963. inherited concatstabto(asmlist);
  1964. end;
  1965. is_def_stab_written := written;
  1966. end
  1967. else
  1968. begin
  1969. if assigned(pointertype.def) then
  1970. forcestabto(asmlist,pointertype.def);
  1971. is_def_stab_written := not_written;
  1972. inherited concatstabto(asmlist);
  1973. end;
  1974. end;
  1975. end;
  1976. {$endif GDB}
  1977. function tpointerdef.gettypename : string;
  1978. begin
  1979. if is_far then
  1980. gettypename:='^'+pointertype.def.typename+';far'
  1981. else
  1982. gettypename:='^'+pointertype.def.typename;
  1983. end;
  1984. {****************************************************************************
  1985. TCLASSREFDEF
  1986. ****************************************************************************}
  1987. constructor tclassrefdef.create(const t:ttype);
  1988. begin
  1989. inherited create(t);
  1990. deftype:=classrefdef;
  1991. end;
  1992. constructor tclassrefdef.ppuload(ppufile:tcompilerppufile);
  1993. begin
  1994. { be careful, tclassdefref inherits from tpointerdef }
  1995. inherited ppuloaddef(ppufile);
  1996. deftype:=classrefdef;
  1997. ppufile.gettype(pointertype);
  1998. is_far:=false;
  1999. savesize:=POINTER_SIZE;
  2000. end;
  2001. procedure tclassrefdef.ppuwrite(ppufile:tcompilerppufile);
  2002. begin
  2003. { be careful, tclassdefref inherits from tpointerdef }
  2004. inherited ppuwritedef(ppufile);
  2005. ppufile.puttype(pointertype);
  2006. ppufile.writeentry(ibclassrefdef);
  2007. end;
  2008. {$ifdef GDB}
  2009. function tclassrefdef.stabstring : pchar;
  2010. begin
  2011. stabstring:=strpnew(tstoreddef(pvmttype.def).numberstring+';');
  2012. end;
  2013. procedure tclassrefdef.concatstabto(asmlist : taasmoutput);
  2014. begin
  2015. inherited concatstabto(asmlist);
  2016. end;
  2017. {$endif GDB}
  2018. function tclassrefdef.gettypename : string;
  2019. begin
  2020. gettypename:='Class Of '+pointertype.def.typename;
  2021. end;
  2022. {***************************************************************************
  2023. TSETDEF
  2024. ***************************************************************************}
  2025. constructor tsetdef.create(const t:ttype;high : longint);
  2026. begin
  2027. inherited create;
  2028. deftype:=setdef;
  2029. elementtype:=t;
  2030. if high<32 then
  2031. begin
  2032. settype:=smallset;
  2033. {$ifdef testvarsets}
  2034. if aktsetalloc=0 THEN { $PACKSET Fixed?}
  2035. {$endif}
  2036. savesize:=Sizeof(longint)
  2037. {$ifdef testvarsets}
  2038. else {No, use $PACKSET VALUE for rounding}
  2039. savesize:=aktsetalloc*((high+aktsetalloc*8-1) DIV (aktsetalloc*8))
  2040. {$endif}
  2041. ;
  2042. end
  2043. else
  2044. if high<256 then
  2045. begin
  2046. settype:=normset;
  2047. savesize:=32;
  2048. end
  2049. else
  2050. {$ifdef testvarsets}
  2051. if high<$10000 then
  2052. begin
  2053. settype:=varset;
  2054. savesize:=4*((high+31) div 32);
  2055. end
  2056. else
  2057. {$endif testvarsets}
  2058. Message(sym_e_ill_type_decl_set);
  2059. end;
  2060. constructor tsetdef.ppuload(ppufile:tcompilerppufile);
  2061. begin
  2062. inherited ppuloaddef(ppufile);
  2063. deftype:=setdef;
  2064. ppufile.gettype(elementtype);
  2065. settype:=tsettype(ppufile.getbyte);
  2066. case settype of
  2067. normset : savesize:=32;
  2068. varset : savesize:=ppufile.getlongint;
  2069. smallset : savesize:=Sizeof(longint);
  2070. end;
  2071. end;
  2072. destructor tsetdef.destroy;
  2073. begin
  2074. inherited destroy;
  2075. end;
  2076. procedure tsetdef.ppuwrite(ppufile:tcompilerppufile);
  2077. begin
  2078. inherited ppuwritedef(ppufile);
  2079. ppufile.puttype(elementtype);
  2080. ppufile.putbyte(byte(settype));
  2081. if settype=varset then
  2082. ppufile.putlongint(savesize);
  2083. ppufile.writeentry(ibsetdef);
  2084. end;
  2085. procedure tsetdef.changesettype(s:tsettype);
  2086. begin
  2087. case s of
  2088. smallset :
  2089. savesize:=sizeof(longint);
  2090. normset :
  2091. savesize:=32;
  2092. varset :
  2093. internalerror(200110201);
  2094. end;
  2095. settype:=s;
  2096. end;
  2097. {$ifdef GDB}
  2098. function tsetdef.stabstring : pchar;
  2099. begin
  2100. { For small sets write a longint, which can at least be seen
  2101. in the current GDB's (PFV)
  2102. this is obsolete with GDBPAS !!
  2103. and anyhow creates problems with version 4.18!! PM
  2104. if settype=smallset then
  2105. stabstring := strpnew('r'+s32bittype^.numberstring+';0;0xffffffff;')
  2106. else }
  2107. stabstring := strpnew('S'+tstoreddef(elementtype.def).numberstring);
  2108. end;
  2109. procedure tsetdef.concatstabto(asmlist : taasmoutput);
  2110. begin
  2111. if ( not assigned(typesym) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches)) and
  2112. (is_def_stab_written = not_written) then
  2113. begin
  2114. if assigned(elementtype.def) then
  2115. forcestabto(asmlist,elementtype.def);
  2116. inherited concatstabto(asmlist);
  2117. end;
  2118. end;
  2119. {$endif GDB}
  2120. procedure tsetdef.deref;
  2121. begin
  2122. inherited deref;
  2123. elementtype.resolve;
  2124. end;
  2125. procedure tsetdef.write_child_rtti_data(rt:trttitype);
  2126. begin
  2127. tstoreddef(elementtype.def).get_rtti_label(rt);
  2128. end;
  2129. procedure tsetdef.write_rtti_data(rt:trttitype);
  2130. begin
  2131. rttiList.concat(Tai_const.Create_8bit(tkSet));
  2132. write_rtti_name;
  2133. rttiList.concat(Tai_const.Create_8bit(otULong));
  2134. rttiList.concat(Tai_const_symbol.Create(tstoreddef(elementtype.def).get_rtti_label(rt)));
  2135. end;
  2136. function tsetdef.is_publishable : boolean;
  2137. begin
  2138. is_publishable:=(settype=smallset);
  2139. end;
  2140. function tsetdef.gettypename : string;
  2141. begin
  2142. if assigned(elementtype.def) then
  2143. gettypename:='Set Of '+elementtype.def.typename
  2144. else
  2145. gettypename:='Empty Set';
  2146. end;
  2147. {***************************************************************************
  2148. TFORMALDEF
  2149. ***************************************************************************}
  2150. constructor tformaldef.create;
  2151. var
  2152. stregdef : boolean;
  2153. begin
  2154. stregdef:=registerdef;
  2155. registerdef:=false;
  2156. inherited create;
  2157. deftype:=formaldef;
  2158. registerdef:=stregdef;
  2159. { formaldef must be registered at unit level !! }
  2160. if registerdef and assigned(current_module) then
  2161. if assigned(current_module.localsymtable) then
  2162. tsymtable(current_module.localsymtable).registerdef(self)
  2163. else if assigned(current_module.globalsymtable) then
  2164. tsymtable(current_module.globalsymtable).registerdef(self);
  2165. savesize:=POINTER_SIZE;
  2166. end;
  2167. constructor tformaldef.ppuload(ppufile:tcompilerppufile);
  2168. begin
  2169. inherited ppuloaddef(ppufile);
  2170. deftype:=formaldef;
  2171. savesize:=POINTER_SIZE;
  2172. end;
  2173. procedure tformaldef.ppuwrite(ppufile:tcompilerppufile);
  2174. begin
  2175. inherited ppuwritedef(ppufile);
  2176. ppufile.writeentry(ibformaldef);
  2177. end;
  2178. {$ifdef GDB}
  2179. function tformaldef.stabstring : pchar;
  2180. begin
  2181. stabstring := strpnew('formal'+numberstring+';');
  2182. end;
  2183. procedure tformaldef.concatstabto(asmlist : taasmoutput);
  2184. begin
  2185. { formaldef can't be stab'ed !}
  2186. end;
  2187. {$endif GDB}
  2188. function tformaldef.gettypename : string;
  2189. begin
  2190. gettypename:='<Formal type>';
  2191. end;
  2192. {***************************************************************************
  2193. TARRAYDEF
  2194. ***************************************************************************}
  2195. constructor tarraydef.create(l,h : longint;const t : ttype);
  2196. begin
  2197. inherited create;
  2198. deftype:=arraydef;
  2199. lowrange:=l;
  2200. highrange:=h;
  2201. rangetype:=t;
  2202. elementtype.reset;
  2203. IsVariant:=false;
  2204. IsConstructor:=false;
  2205. IsArrayOfConst:=false;
  2206. IsDynamicArray:=false;
  2207. rangenr:=0;
  2208. end;
  2209. constructor tarraydef.ppuload(ppufile:tcompilerppufile);
  2210. begin
  2211. inherited ppuloaddef(ppufile);
  2212. deftype:=arraydef;
  2213. { the addresses are calculated later }
  2214. ppufile.gettype(_elementtype);
  2215. ppufile.gettype(rangetype);
  2216. lowrange:=ppufile.getlongint;
  2217. highrange:=ppufile.getlongint;
  2218. IsArrayOfConst:=boolean(ppufile.getbyte);
  2219. IsDynamicArray:=boolean(ppufile.getbyte);
  2220. IsVariant:=false;
  2221. IsConstructor:=false;
  2222. rangenr:=0;
  2223. end;
  2224. procedure tarraydef.deref;
  2225. begin
  2226. inherited deref;
  2227. _elementtype.resolve;
  2228. rangetype.resolve;
  2229. end;
  2230. procedure tarraydef.ppuwrite(ppufile:tcompilerppufile);
  2231. begin
  2232. inherited ppuwritedef(ppufile);
  2233. ppufile.puttype(_elementtype);
  2234. ppufile.puttype(rangetype);
  2235. ppufile.putlongint(lowrange);
  2236. ppufile.putlongint(highrange);
  2237. ppufile.putbyte(byte(IsArrayOfConst));
  2238. ppufile.putbyte(byte(IsDynamicArray));
  2239. ppufile.writeentry(ibarraydef);
  2240. end;
  2241. {$ifdef GDB}
  2242. function tarraydef.stabstring : pchar;
  2243. begin
  2244. stabstring := strpnew('ar'+tstoreddef(rangetype.def).numberstring+';'
  2245. +tostr(lowrange)+';'+tostr(highrange)+';'+tstoreddef(_elementtype.def).numberstring);
  2246. end;
  2247. procedure tarraydef.concatstabto(asmlist : taasmoutput);
  2248. begin
  2249. if (not assigned(typesym) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches))
  2250. and (is_def_stab_written = not_written) then
  2251. begin
  2252. {when array are inserted they have no definition yet !!}
  2253. if assigned(_elementtype.def) then
  2254. inherited concatstabto(asmlist);
  2255. end;
  2256. end;
  2257. {$endif GDB}
  2258. function tarraydef.elesize : longint;
  2259. begin
  2260. elesize:=_elementtype.def.size;
  2261. end;
  2262. function tarraydef.size : longint;
  2263. var
  2264. _resultsize,
  2265. newsize,
  2266. cachedsize: TConstExprInt;
  2267. begin
  2268. if IsDynamicArray then
  2269. begin
  2270. size:=POINTER_SIZE;
  2271. exit;
  2272. end;
  2273. cachedsize := elesize;
  2274. {Tarraydef.size may never be called for an open array!}
  2275. if highrange<lowrange then
  2276. internalerror(99080501);
  2277. newsize:=(int64(highrange)-int64(lowrange)+1)*cachedsize;
  2278. if (cachedsize>0) and
  2279. (
  2280. (TConstExprInt(highrange)-TConstExprInt(lowrange) > $7fffffff) or
  2281. { () are needed around elesize-1 to avoid a possible
  2282. integer overflow for elesize=1 !! PM }
  2283. (($7fffffff div cachedsize + (cachedsize -1)) < (int64(highrange) - int64(lowrange)))
  2284. ) Then
  2285. begin
  2286. Message(sym_e_segment_too_large);
  2287. _resultsize := 4
  2288. end
  2289. else
  2290. begin
  2291. { prevent an overflow }
  2292. if newsize>high(longint) then
  2293. _resultsize:=high(longint)
  2294. else
  2295. _resultsize:=newsize;
  2296. end;
  2297. {$ifdef m68k}
  2298. { 68000 (only) CPU's only accept 32K arrays }
  2299. if (_resultsize > 32767) and
  2300. (aktoptprocessor = MC68000) then
  2301. Message(sym_w_segment_too_large);
  2302. {$endif}
  2303. size := _resultsize;
  2304. end;
  2305. procedure tarraydef.setelementtype(t: ttype);
  2306. begin
  2307. _elementtype:=t;
  2308. If IsDynamicArray then
  2309. exit;
  2310. if (TConstExprInt(highrange)-TConstExprInt(lowrange) > $7fffffff) then
  2311. Message(sym_e_segment_too_large);
  2312. end;
  2313. function tarraydef.alignment : longint;
  2314. begin
  2315. { alignment is the size of the elements }
  2316. if elementtype.def.deftype=recorddef then
  2317. alignment:=elementtype.def.alignment
  2318. else
  2319. alignment:=elesize;
  2320. end;
  2321. function tarraydef.needs_inittable : boolean;
  2322. begin
  2323. needs_inittable:=IsDynamicArray or elementtype.def.needs_inittable;
  2324. end;
  2325. procedure tarraydef.write_child_rtti_data(rt:trttitype);
  2326. begin
  2327. tstoreddef(elementtype.def).get_rtti_label(rt);
  2328. end;
  2329. procedure tarraydef.write_rtti_data(rt:trttitype);
  2330. begin
  2331. if IsDynamicArray then
  2332. rttiList.concat(Tai_const.Create_8bit(tkdynarray))
  2333. else
  2334. rttiList.concat(Tai_const.Create_8bit(tkarray));
  2335. write_rtti_name;
  2336. { size of elements }
  2337. rttiList.concat(Tai_const.Create_32bit(elesize));
  2338. { count of elements }
  2339. if not(IsDynamicArray) then
  2340. rttiList.concat(Tai_const.Create_32bit(highrange-lowrange+1));
  2341. { element type }
  2342. rttiList.concat(Tai_const_symbol.Create(tstoreddef(elementtype.def).get_rtti_label(rt)));
  2343. { variant type }
  2344. // !!!!!!!!!!!!!!!!
  2345. end;
  2346. function tarraydef.gettypename : string;
  2347. begin
  2348. if isarrayofconst or isConstructor then
  2349. begin
  2350. if isvariant or ((highrange=-1) and (lowrange=0)) then
  2351. gettypename:='Array Of Const'
  2352. else
  2353. gettypename:='Array Of '+elementtype.def.typename;
  2354. end
  2355. else if ((highrange=-1) and (lowrange=0)) or IsDynamicArray then
  2356. gettypename:='Array Of '+elementtype.def.typename
  2357. else
  2358. begin
  2359. if rangetype.def.deftype=enumdef then
  2360. gettypename:='Array['+rangetype.def.typename+'] Of '+elementtype.def.typename
  2361. else
  2362. gettypename:='Array['+tostr(lowrange)+'..'+
  2363. tostr(highrange)+'] Of '+elementtype.def.typename
  2364. end;
  2365. end;
  2366. function tarraydef.getmangledparaname : string;
  2367. begin
  2368. if isarrayofconst then
  2369. getmangledparaname:='array_of_const'
  2370. else
  2371. if ((highrange=-1) and (lowrange=0)) then
  2372. getmangledparaname:='array_of_'+elementtype.def.mangledparaname
  2373. else
  2374. internalerror(200204176);
  2375. end;
  2376. {***************************************************************************
  2377. tabstractrecorddef
  2378. ***************************************************************************}
  2379. function tabstractrecorddef.getsymtable(t:tgetsymtable):tsymtable;
  2380. begin
  2381. if t=gs_record then
  2382. getsymtable:=symtable
  2383. else
  2384. getsymtable:=nil;
  2385. end;
  2386. {$ifdef GDB}
  2387. procedure tabstractrecorddef.addname(p : tnamedindexitem;arg:pointer);
  2388. var
  2389. news, newrec : pchar;
  2390. spec : string[3];
  2391. varsize : longint;
  2392. begin
  2393. { static variables from objects are like global objects }
  2394. if (sp_static in tsym(p).symoptions) then
  2395. exit;
  2396. If tsym(p).typ = varsym then
  2397. begin
  2398. if (sp_protected in tsym(p).symoptions) then
  2399. spec:='/1'
  2400. else if (sp_private in tsym(p).symoptions) then
  2401. spec:='/0'
  2402. else
  2403. spec:='';
  2404. if not assigned(tvarsym(p).vartype.def) then
  2405. writeln(tvarsym(p).name);
  2406. { class fields are pointers PM, obsolete now PM }
  2407. {if (tvarsym(p).vartype.def.deftype=objectdef) and
  2408. tobjectdef(tvarsym(p).vartype.def).is_class then
  2409. spec:=spec+'*'; }
  2410. varsize:=tvarsym(p).vartype.def.size;
  2411. { open arrays made overflows !! }
  2412. if varsize>$fffffff then
  2413. varsize:=$fffffff;
  2414. newrec := strpnew(p.name+':'+spec+tstoreddef(tvarsym(p).vartype.def).numberstring
  2415. +','+tostr(tvarsym(p).address*8)+','
  2416. +tostr(varsize*8)+';');
  2417. if strlen(StabRecString) + strlen(newrec) >= StabRecSize-256 then
  2418. begin
  2419. getmem(news,stabrecsize+memsizeinc);
  2420. strcopy(news,stabrecstring);
  2421. freemem(stabrecstring,stabrecsize);
  2422. stabrecsize:=stabrecsize+memsizeinc;
  2423. stabrecstring:=news;
  2424. end;
  2425. strcat(StabRecstring,newrec);
  2426. strdispose(newrec);
  2427. {This should be used for case !!}
  2428. inc(RecOffset,tvarsym(p).vartype.def.size);
  2429. end;
  2430. end;
  2431. {$endif GDB}
  2432. procedure tabstractrecorddef.count_field_rtti(sym : tnamedindexitem;arg:pointer);
  2433. begin
  2434. if (FRTTIType=fullrtti) or
  2435. ((tsym(sym).typ=varsym) and
  2436. tvarsym(sym).vartype.def.needs_inittable) then
  2437. inc(Count);
  2438. end;
  2439. procedure tabstractrecorddef.generate_field_rtti(sym:tnamedindexitem;arg:pointer);
  2440. begin
  2441. if (FRTTIType=fullrtti) or
  2442. ((tsym(sym).typ=varsym) and
  2443. tvarsym(sym).vartype.def.needs_inittable) then
  2444. tstoreddef(tvarsym(sym).vartype.def).get_rtti_label(FRTTIType);
  2445. end;
  2446. procedure tabstractrecorddef.write_field_rtti(sym : tnamedindexitem;arg:pointer);
  2447. begin
  2448. if (FRTTIType=fullrtti) or
  2449. ((tsym(sym).typ=varsym) and
  2450. tvarsym(sym).vartype.def.needs_inittable) then
  2451. begin
  2452. rttiList.concat(Tai_const_symbol.Create(tstoreddef(tvarsym(sym).vartype.def).get_rtti_label(FRTTIType)));
  2453. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym).address));
  2454. end;
  2455. end;
  2456. {***************************************************************************
  2457. trecorddef
  2458. ***************************************************************************}
  2459. constructor trecorddef.create(p : tsymtable);
  2460. begin
  2461. inherited create;
  2462. deftype:=recorddef;
  2463. symtable:=p;
  2464. symtable.defowner:=self;
  2465. { recordalign -1 means C record packing, that starts
  2466. with an alignment of 1 }
  2467. if aktalignment.recordalignmax=-1 then
  2468. symtable.dataalignment:=1
  2469. else
  2470. symtable.dataalignment:=aktalignment.recordalignmax;
  2471. isunion:=false;
  2472. end;
  2473. constructor trecorddef.ppuload(ppufile:tcompilerppufile);
  2474. var
  2475. oldread_member : boolean;
  2476. begin
  2477. inherited ppuloaddef(ppufile);
  2478. deftype:=recorddef;
  2479. savesize:=ppufile.getlongint;
  2480. oldread_member:=read_member;
  2481. read_member:=true;
  2482. symtable:=trecordsymtable.create;
  2483. trecordsymtable(symtable).ppuload(ppufile);
  2484. read_member:=oldread_member;
  2485. symtable.defowner:=self;
  2486. isunion:=false;
  2487. end;
  2488. destructor trecorddef.destroy;
  2489. begin
  2490. if assigned(symtable) then
  2491. symtable.free;
  2492. inherited destroy;
  2493. end;
  2494. function trecorddef.needs_inittable : boolean;
  2495. begin
  2496. needs_inittable:=trecordsymtable(symtable).needs_init_final
  2497. end;
  2498. procedure trecorddef.deref;
  2499. var
  2500. oldrecsyms : tsymtable;
  2501. begin
  2502. inherited deref;
  2503. oldrecsyms:=aktrecordsymtable;
  2504. aktrecordsymtable:=symtable;
  2505. { now dereference the definitions }
  2506. tstoredsymtable(symtable).deref;
  2507. aktrecordsymtable:=oldrecsyms;
  2508. { assign TGUID? load only from system unit (unitid=1) }
  2509. if not(assigned(rec_tguid)) and
  2510. (upper(typename)='TGUID') and
  2511. assigned(owner) and
  2512. assigned(owner.name) and
  2513. (owner.name^='SYSTEM') then
  2514. rec_tguid:=self;
  2515. end;
  2516. procedure trecorddef.ppuwrite(ppufile:tcompilerppufile);
  2517. var
  2518. oldread_member : boolean;
  2519. begin
  2520. oldread_member:=read_member;
  2521. read_member:=true;
  2522. inherited ppuwritedef(ppufile);
  2523. ppufile.putlongint(savesize);
  2524. ppufile.writeentry(ibrecorddef);
  2525. trecordsymtable(symtable).ppuwrite(ppufile);
  2526. read_member:=oldread_member;
  2527. end;
  2528. function trecorddef.size:longint;
  2529. var
  2530. _resultsize : longint;
  2531. begin
  2532. _resultsize:=symtable.datasize;
  2533. {$ifdef m68k}
  2534. { 68000 (only) CPU's only accept 32K arrays }
  2535. if (_resultsize > 32767) and
  2536. (aktoptprocessor = MC68000) then
  2537. Message(sym_w_segment_too_large);
  2538. {$endif}
  2539. size:=_resultsize;
  2540. end;
  2541. function trecorddef.alignment:longint;
  2542. var
  2543. l : longint;
  2544. hp : tvarsym;
  2545. begin
  2546. { also check the first symbol for it's size, because a
  2547. packed record has dataalignment of 1, but the first
  2548. sym could be a longint which should be aligned on 4 bytes,
  2549. this is compatible with C record packing (PFV) }
  2550. hp:=tvarsym(symtable.symindex.first);
  2551. if assigned(hp) then
  2552. begin
  2553. if hp.vartype.def.deftype in [recorddef,arraydef] then
  2554. l:=hp.vartype.def.alignment
  2555. else
  2556. l:=hp.vartype.def.size;
  2557. if l>symtable.dataalignment then
  2558. begin
  2559. if l>=4 then
  2560. alignment:=4
  2561. else
  2562. if l>=2 then
  2563. alignment:=2
  2564. else
  2565. alignment:=1;
  2566. end
  2567. else
  2568. alignment:=symtable.dataalignment;
  2569. end
  2570. else
  2571. alignment:=symtable.dataalignment;
  2572. end;
  2573. {$ifdef GDB}
  2574. function trecorddef.stabstring : pchar;
  2575. begin
  2576. GetMem(stabrecstring,memsizeinc);
  2577. stabrecsize:=memsizeinc;
  2578. strpcopy(stabRecString,'s'+tostr(size));
  2579. RecOffset := 0;
  2580. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}addname,nil);
  2581. strpcopy(strend(StabRecString),';');
  2582. stabstring := strnew(StabRecString);
  2583. Freemem(stabrecstring,stabrecsize);
  2584. end;
  2585. procedure trecorddef.concatstabto(asmlist : taasmoutput);
  2586. begin
  2587. if (not assigned(typesym) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches)) and
  2588. (is_def_stab_written = not_written) then
  2589. inherited concatstabto(asmlist);
  2590. end;
  2591. {$endif GDB}
  2592. procedure trecorddef.write_child_rtti_data(rt:trttitype);
  2593. begin
  2594. FRTTIType:=rt;
  2595. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}generate_field_rtti,nil);
  2596. end;
  2597. procedure trecorddef.write_rtti_data(rt:trttitype);
  2598. begin
  2599. rttiList.concat(Tai_const.Create_8bit(tkrecord));
  2600. write_rtti_name;
  2601. rttiList.concat(Tai_const.Create_32bit(size));
  2602. Count:=0;
  2603. FRTTIType:=rt;
  2604. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_field_rtti,nil);
  2605. rttiList.concat(Tai_const.Create_32bit(Count));
  2606. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}write_field_rtti,nil);
  2607. end;
  2608. function trecorddef.gettypename : string;
  2609. begin
  2610. gettypename:='<record type>'
  2611. end;
  2612. {***************************************************************************
  2613. TABSTRACTPROCDEF
  2614. ***************************************************************************}
  2615. constructor tabstractprocdef.create;
  2616. begin
  2617. inherited create;
  2618. para:=TParaLinkedList.Create;
  2619. minparacount:=0;
  2620. maxparacount:=0;
  2621. proctypeoption:=potype_none;
  2622. proccalloption:=pocall_none;
  2623. procoptions:=[];
  2624. rettype:=voidtype;
  2625. symtablelevel:=0;
  2626. fpu_used:=0;
  2627. savesize:=POINTER_SIZE;
  2628. end;
  2629. destructor tabstractprocdef.destroy;
  2630. begin
  2631. Para.Free;
  2632. inherited destroy;
  2633. end;
  2634. procedure tabstractprocdef.concatpara(const tt:ttype;sym : tsym;vsp : tvarspez;defval:tsym);
  2635. var
  2636. hp : TParaItem;
  2637. begin
  2638. hp:=TParaItem.Create;
  2639. hp.paratyp:=vsp;
  2640. hp.parasym:=sym;
  2641. hp.paratype:=tt;
  2642. hp.defaultvalue:=defval;
  2643. Para.insert(hp);
  2644. if not assigned(defval) then
  2645. inc(minparacount);
  2646. inc(maxparacount);
  2647. end;
  2648. { all functions returning in FPU are
  2649. assume to use 2 FPU registers
  2650. until the function implementation
  2651. is processed PM }
  2652. procedure tabstractprocdef.test_if_fpu_result;
  2653. begin
  2654. if assigned(rettype.def) and
  2655. (rettype.def.deftype=floatdef) then
  2656. {$ifdef FAST_FPU}
  2657. fpu_used:=3;
  2658. {$else : not FAST_FPU, i.e. SAFE_FPU}
  2659. fpu_used:={2}maxfpuregs;
  2660. {$endif FAST_FPU}
  2661. end;
  2662. procedure tabstractprocdef.deref;
  2663. var
  2664. hp : TParaItem;
  2665. begin
  2666. inherited deref;
  2667. rettype.resolve;
  2668. hp:=TParaItem(Para.first);
  2669. while assigned(hp) do
  2670. begin
  2671. hp.paratype.resolve;
  2672. resolvesym(pointer(hp.defaultvalue));
  2673. resolvesym(pointer(hp.parasym));
  2674. hp:=TParaItem(hp.next);
  2675. end;
  2676. end;
  2677. constructor tabstractprocdef.ppuload(ppufile:tcompilerppufile);
  2678. var
  2679. hp : TParaItem;
  2680. count,i : word;
  2681. begin
  2682. inherited ppuloaddef(ppufile);
  2683. Para:=TParaLinkedList.Create;
  2684. minparacount:=0;
  2685. maxparacount:=0;
  2686. ppufile.gettype(rettype);
  2687. fpu_used:=ppufile.getbyte;
  2688. proctypeoption:=tproctypeoption(ppufile.getbyte);
  2689. proccalloption:=tproccalloption(ppufile.getbyte);
  2690. ppufile.getsmallset(procoptions);
  2691. count:=ppufile.getword;
  2692. savesize:=POINTER_SIZE;
  2693. for i:=1 to count do
  2694. begin
  2695. hp:=TParaItem.Create;
  2696. hp.paratyp:=tvarspez(ppufile.getbyte);
  2697. { hp.register:=tregister(ppufile.getbyte); }
  2698. ppufile.gettype(hp.paratype);
  2699. hp.defaultvalue:=tsym(ppufile.getderef);
  2700. hp.parasym:=tsym(ppufile.getderef);
  2701. { later, we'll gerate this on the fly (FK) }
  2702. ppufile.getdata(hp.paraloc,sizeof(tparalocation));
  2703. if not assigned(hp.defaultvalue) then
  2704. inc(minparacount);
  2705. inc(maxparacount);
  2706. Para.concat(hp);
  2707. end;
  2708. end;
  2709. procedure tabstractprocdef.ppuwrite(ppufile:tcompilerppufile);
  2710. var
  2711. hp : TParaItem;
  2712. oldintfcrc : boolean;
  2713. begin
  2714. inherited ppuwritedef(ppufile);
  2715. ppufile.puttype(rettype);
  2716. oldintfcrc:=ppufile.do_interface_crc;
  2717. ppufile.do_interface_crc:=false;
  2718. if simplify_ppu then
  2719. fpu_used:=0;
  2720. ppufile.putbyte(fpu_used);
  2721. ppufile.putbyte(ord(proctypeoption));
  2722. ppufile.putbyte(ord(proccalloption));
  2723. ppufile.putsmallset(procoptions);
  2724. ppufile.do_interface_crc:=oldintfcrc;
  2725. ppufile.putword(maxparacount);
  2726. hp:=TParaItem(Para.first);
  2727. while assigned(hp) do
  2728. begin
  2729. ppufile.putbyte(byte(hp.paratyp));
  2730. { ppufile.putbyte(byte(hp.register)); }
  2731. ppufile.puttype(hp.paratype);
  2732. ppufile.putderef(hp.defaultvalue);
  2733. ppufile.putderef(hp.parasym);
  2734. ppufile.putdata(hp.paraloc,sizeof(tparalocation));
  2735. hp:=TParaItem(hp.next);
  2736. end;
  2737. end;
  2738. function tabstractprocdef.para_size(alignsize:longint) : longint;
  2739. var
  2740. pdc : TParaItem;
  2741. l : longint;
  2742. is_cdecl : boolean;
  2743. begin
  2744. l:=0;
  2745. is_cdecl:=(proccalloption in [pocall_cdecl,pocall_cppdecl]);
  2746. pdc:=TParaItem(Para.first);
  2747. while assigned(pdc) do
  2748. begin
  2749. case pdc.paratyp of
  2750. vs_out,
  2751. vs_var :
  2752. inc(l,POINTER_SIZE);
  2753. vs_value,
  2754. vs_const :
  2755. begin
  2756. if paramanager.push_addr_param(pdc.paratype.def,is_cdecl) then
  2757. inc(l,POINTER_SIZE)
  2758. else
  2759. inc(l,pdc.paratype.def.size);
  2760. end;
  2761. end;
  2762. l:=align(l,alignsize);
  2763. if assigned(pdc.paratype.def) and
  2764. is_special_array(pdc.paratype.def) then
  2765. begin
  2766. inc(l,POINTER_SIZE);
  2767. l:=align(l,alignsize);
  2768. end;
  2769. pdc:=TParaItem(pdc.next);
  2770. end;
  2771. para_size:=l;
  2772. end;
  2773. function tabstractprocdef.typename_paras : string;
  2774. var
  2775. hs,s : string;
  2776. hp : TParaItem;
  2777. hpc : tconstsym;
  2778. begin
  2779. hp:=TParaItem(Para.last);
  2780. if not(assigned(hp)) then
  2781. begin
  2782. typename_paras:='';
  2783. exit;
  2784. end;
  2785. s:='(';
  2786. while assigned(hp) do
  2787. begin
  2788. if hp.paratyp=vs_var then
  2789. s:=s+'var'
  2790. else if hp.paratyp=vs_const then
  2791. s:=s+'const'
  2792. else if hp.paratyp=vs_out then
  2793. s:=s+'out';
  2794. if assigned(hp.paratype.def.typesym) then
  2795. begin
  2796. if hp.paratyp in [vs_var,vs_const,vs_out] then
  2797. s := s + ' ';
  2798. hs:=hp.paratype.def.typesym.realname;
  2799. if hs[1]<>'$' then
  2800. s:=s+hp.paratype.def.typesym.realname
  2801. else
  2802. s:=s+hp.paratype.def.gettypename;
  2803. end;
  2804. { default value }
  2805. if assigned(hp.defaultvalue) then
  2806. begin
  2807. hpc:=tconstsym(hp.defaultvalue);
  2808. hs:='';
  2809. case hpc.consttyp of
  2810. conststring,
  2811. constresourcestring :
  2812. hs:=strpas(pchar(hpc.valueptr));
  2813. constreal :
  2814. str(pbestreal(hpc.valueptr)^,hs);
  2815. constord :
  2816. hs:=tostr(hpc.valueord);
  2817. constpointer :
  2818. hs:=tostr(hpc.valueordptr);
  2819. constbool :
  2820. begin
  2821. if hpc.valueord<>0 then
  2822. hs:='TRUE'
  2823. else
  2824. hs:='FALSE';
  2825. end;
  2826. constnil :
  2827. hs:='nil';
  2828. constchar :
  2829. hs:=chr(hpc.valueord);
  2830. constset :
  2831. hs:='<set>';
  2832. end;
  2833. if hs<>'' then
  2834. s:=s+'="'+hs+'"';
  2835. end;
  2836. hp:=TParaItem(hp.previous);
  2837. if assigned(hp) then
  2838. s:=s+',';
  2839. end;
  2840. s:=s+')';
  2841. if (po_varargs in procoptions) then
  2842. s:=s+';VarArgs';
  2843. typename_paras:=s;
  2844. end;
  2845. {$ifdef GDB}
  2846. function tabstractprocdef.stabstring : pchar;
  2847. begin
  2848. stabstring := strpnew('abstractproc'+numberstring+';');
  2849. end;
  2850. procedure tabstractprocdef.concatstabto(asmlist : taasmoutput);
  2851. begin
  2852. if (not assigned(typesym) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches))
  2853. and (is_def_stab_written = not_written) then
  2854. begin
  2855. if assigned(rettype.def) then forcestabto(asmlist,rettype.def);
  2856. inherited concatstabto(asmlist);
  2857. end;
  2858. end;
  2859. {$endif GDB}
  2860. {***************************************************************************
  2861. TPROCDEF
  2862. ***************************************************************************}
  2863. constructor tprocdef.create;
  2864. begin
  2865. inherited create;
  2866. deftype:=procdef;
  2867. has_mangledname:=false;
  2868. _mangledname:=nil;
  2869. fileinfo:=aktfilepos;
  2870. extnumber:=$ffff;
  2871. aliasnames:=tstringlist.create;
  2872. localst:=tlocalsymtable.create;
  2873. parast:=tparasymtable.create;
  2874. funcretsym:=nil;
  2875. localst.defowner:=self;
  2876. parast.defowner:=self;
  2877. { this is used by insert
  2878. to check same names in parast and localst }
  2879. localst.next:=parast;
  2880. defref:=nil;
  2881. crossref:=nil;
  2882. lastwritten:=nil;
  2883. refcount:=0;
  2884. if (cs_browser in aktmoduleswitches) and make_ref then
  2885. begin
  2886. defref:=tref.create(defref,@akttokenpos);
  2887. inc(refcount);
  2888. end;
  2889. lastref:=defref;
  2890. { first, we assume that all registers are used }
  2891. usedregisters:=ALL_REGISTERS;
  2892. forwarddef:=true;
  2893. interfacedef:=false;
  2894. hasforward:=false;
  2895. _class := nil;
  2896. code:=nil;
  2897. regvarinfo := nil;
  2898. overloadnumber:=0;
  2899. {$ifdef GDB}
  2900. isstabwritten := false;
  2901. {$endif GDB}
  2902. end;
  2903. constructor tprocdef.ppuload(ppufile:tcompilerppufile);
  2904. begin
  2905. inherited ppuload(ppufile);
  2906. deftype:=procdef;
  2907. ppufile.getnormalset(usedregisters);
  2908. has_mangledname:=boolean(ppufile.getbyte);
  2909. if has_mangledname then
  2910. _mangledname:=stringdup(ppufile.getstring)
  2911. else
  2912. _mangledname:=nil;
  2913. overloadnumber:=ppufile.getword;
  2914. extnumber:=ppufile.getword;
  2915. _class := tobjectdef(ppufile.getderef);
  2916. procsym := tsym(ppufile.getderef);
  2917. ppufile.getposinfo(fileinfo);
  2918. { inline stuff }
  2919. if proccalloption=pocall_inline then
  2920. begin
  2921. funcretsym:=tsym(ppufile.getderef);
  2922. code:=ppuloadnode(ppufile);
  2923. end
  2924. else
  2925. begin
  2926. code := nil;
  2927. funcretsym:=nil;
  2928. end;
  2929. { load para and local symtables }
  2930. parast:=tparasymtable.create;
  2931. tparasymtable(parast).ppuload(ppufile);
  2932. parast.defowner:=self;
  2933. if (proccalloption=pocall_inline) or
  2934. ((current_module.flags and uf_local_browser)<>0) then
  2935. begin
  2936. localst:=tlocalsymtable.create;
  2937. tlocalsymtable(localst).ppuload(ppufile);
  2938. localst.defowner:=self;
  2939. end
  2940. else
  2941. localst:=nil;
  2942. { default values for no persistent data }
  2943. if (cs_link_deffile in aktglobalswitches) and
  2944. (tf_need_export in target_info.flags) and
  2945. (po_exports in procoptions) then
  2946. deffile.AddExport(mangledname);
  2947. aliasnames:=tstringlist.create;
  2948. forwarddef:=false;
  2949. interfacedef:=false;
  2950. hasforward:=false;
  2951. regvarinfo := nil;
  2952. lastref:=nil;
  2953. lastwritten:=nil;
  2954. defref:=nil;
  2955. refcount:=0;
  2956. {$ifdef GDB}
  2957. isstabwritten := false;
  2958. {$endif GDB}
  2959. end;
  2960. destructor tprocdef.destroy;
  2961. begin
  2962. if assigned(defref) then
  2963. begin
  2964. defref.freechain;
  2965. defref.free;
  2966. end;
  2967. aliasnames.free;
  2968. if assigned(parast) then
  2969. begin
  2970. {$ifdef MEMDEBUG}
  2971. memprocparast.start;
  2972. {$endif MEMDEBUG}
  2973. parast.free;
  2974. {$ifdef MEMDEBUG}
  2975. memprocparast.stop;
  2976. {$endif MEMDEBUG}
  2977. end;
  2978. if assigned(localst) and (localst.symtabletype<>staticsymtable) then
  2979. begin
  2980. {$ifdef MEMDEBUG}
  2981. memproclocalst.start;
  2982. {$endif MEMDEBUG}
  2983. localst.free;
  2984. {$ifdef MEMDEBUG}
  2985. memproclocalst.start;
  2986. {$endif MEMDEBUG}
  2987. end;
  2988. if (proccalloption=pocall_inline) and assigned(code) then
  2989. begin
  2990. {$ifdef MEMDEBUG}
  2991. memprocnodetree.start;
  2992. {$endif MEMDEBUG}
  2993. tnode(code).free;
  2994. {$ifdef MEMDEBUG}
  2995. memprocnodetree.start;
  2996. {$endif MEMDEBUG}
  2997. end;
  2998. if assigned(regvarinfo) then
  2999. dispose(pregvarinfo(regvarinfo));
  3000. if (po_msgstr in procoptions) then
  3001. strdispose(messageinf.str);
  3002. if assigned(_mangledname) then
  3003. begin
  3004. {$ifdef MEMDEBUG}
  3005. memmanglednames.start;
  3006. {$endif MEMDEBUG}
  3007. stringdispose(_mangledname);
  3008. {$ifdef MEMDEBUG}
  3009. memmanglednames.stop;
  3010. {$endif MEMDEBUG}
  3011. end;
  3012. inherited destroy;
  3013. end;
  3014. procedure tprocdef.ppuwrite(ppufile:tcompilerppufile);
  3015. var
  3016. oldintfcrc : boolean;
  3017. begin
  3018. inherited ppuwrite(ppufile);
  3019. oldintfcrc:=ppufile.do_interface_crc;
  3020. ppufile.do_interface_crc:=false;
  3021. { set all registers to used for simplified compilation PM }
  3022. if simplify_ppu then
  3023. begin
  3024. usedregisters:=ALL_REGISTERS;
  3025. end;
  3026. ppufile.putnormalset(usedregisters);
  3027. ppufile.do_interface_crc:=oldintfcrc;
  3028. ppufile.putbyte(byte(has_mangledname));
  3029. if has_mangledname then
  3030. ppufile.putstring(mangledname);
  3031. ppufile.putword(overloadnumber);
  3032. ppufile.putword(extnumber);
  3033. ppufile.putderef(_class);
  3034. ppufile.putderef(procsym);
  3035. ppufile.putposinfo(fileinfo);
  3036. { inline stuff references to localsymtable, no influence
  3037. on the crc }
  3038. oldintfcrc:=ppufile.do_crc;
  3039. ppufile.do_crc:=false;
  3040. { inline stuff }
  3041. if proccalloption=pocall_inline then
  3042. begin
  3043. ppufile.putderef(funcretsym);
  3044. ppuwritenode(ppufile,code);
  3045. end;
  3046. ppufile.do_crc:=oldintfcrc;
  3047. { write this entry }
  3048. ppufile.writeentry(ibprocdef);
  3049. { Save the para symtable, this is taken from the interface }
  3050. if not assigned(parast) then
  3051. begin
  3052. parast:=tparasymtable.create;
  3053. parast.defowner:=self;
  3054. end;
  3055. tparasymtable(parast).ppuwrite(ppufile);
  3056. { save localsymtable for inline procedures or when local
  3057. browser info is requested, this has no influence on the crc }
  3058. if (proccalloption=pocall_inline) or
  3059. ((current_module.flags and uf_local_browser)<>0) then
  3060. begin
  3061. oldintfcrc:=ppufile.do_crc;
  3062. ppufile.do_crc:=false;
  3063. if not assigned(localst) then
  3064. begin
  3065. localst:=tlocalsymtable.create;
  3066. localst.defowner:=self;
  3067. end;
  3068. tlocalsymtable(localst).ppuwrite(ppufile);
  3069. ppufile.do_crc:=oldintfcrc;
  3070. end;
  3071. end;
  3072. function tprocdef.fullprocname:string;
  3073. var
  3074. s : string;
  3075. begin
  3076. s:='';
  3077. if assigned(_class) then
  3078. s:=_class.objrealname^+'.';
  3079. s:=s+procsym.realname+typename_paras;
  3080. fullprocname:=s;
  3081. end;
  3082. function tprocdef.fullprocnamewithret:string;
  3083. var
  3084. s : string;
  3085. begin
  3086. s:=fullprocname;
  3087. if assigned(rettype.def) and
  3088. not(is_equal(rettype.def,voidtype.def)) then
  3089. s:=s+' : '+rettype.def.gettypename;
  3090. fullprocnamewithret:=s;
  3091. end;
  3092. function tprocdef.getsymtable(t:tgetsymtable):tsymtable;
  3093. begin
  3094. case t of
  3095. gs_local :
  3096. getsymtable:=localst;
  3097. gs_para :
  3098. getsymtable:=parast;
  3099. else
  3100. getsymtable:=nil;
  3101. end;
  3102. end;
  3103. procedure tprocdef.load_references(ppufile:tcompilerppufile;locals:boolean);
  3104. var
  3105. pos : tfileposinfo;
  3106. move_last : boolean;
  3107. begin
  3108. move_last:=lastwritten=lastref;
  3109. while (not ppufile.endofentry) do
  3110. begin
  3111. ppufile.getposinfo(pos);
  3112. inc(refcount);
  3113. lastref:=tref.create(lastref,@pos);
  3114. lastref.is_written:=true;
  3115. if refcount=1 then
  3116. defref:=lastref;
  3117. end;
  3118. if move_last then
  3119. lastwritten:=lastref;
  3120. if ((current_module.flags and uf_local_browser)<>0) and
  3121. locals then
  3122. begin
  3123. tparasymtable(parast).load_references(ppufile,locals);
  3124. tlocalsymtable(localst).load_references(ppufile,locals);
  3125. end;
  3126. end;
  3127. Const
  3128. local_symtable_index : longint = $8001;
  3129. function tprocdef.write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  3130. var
  3131. ref : tref;
  3132. pdo : tobjectdef;
  3133. move_last : boolean;
  3134. begin
  3135. move_last:=lastwritten=lastref;
  3136. if move_last and
  3137. (((current_module.flags and uf_local_browser)=0) or
  3138. not locals) then
  3139. exit;
  3140. { write address of this symbol }
  3141. ppufile.putderef(self);
  3142. { write refs }
  3143. if assigned(lastwritten) then
  3144. ref:=lastwritten
  3145. else
  3146. ref:=defref;
  3147. while assigned(ref) do
  3148. begin
  3149. if ref.moduleindex=current_module.unit_index then
  3150. begin
  3151. ppufile.putposinfo(ref.posinfo);
  3152. ref.is_written:=true;
  3153. if move_last then
  3154. lastwritten:=ref;
  3155. end
  3156. else if not ref.is_written then
  3157. move_last:=false
  3158. else if move_last then
  3159. lastwritten:=ref;
  3160. ref:=ref.nextref;
  3161. end;
  3162. ppufile.writeentry(ibdefref);
  3163. write_references:=true;
  3164. if ((current_module.flags and uf_local_browser)<>0) and
  3165. locals then
  3166. begin
  3167. pdo:=_class;
  3168. if (owner.symtabletype<>localsymtable) then
  3169. while assigned(pdo) do
  3170. begin
  3171. if pdo.symtable<>aktrecordsymtable then
  3172. begin
  3173. pdo.symtable.unitid:=local_symtable_index;
  3174. inc(local_symtable_index);
  3175. end;
  3176. pdo:=pdo.childof;
  3177. end;
  3178. parast.unitid:=local_symtable_index;
  3179. inc(local_symtable_index);
  3180. localst.unitid:=local_symtable_index;
  3181. inc(local_symtable_index);
  3182. tstoredsymtable(parast).write_references(ppufile,locals);
  3183. tstoredsymtable(localst).write_references(ppufile,locals);
  3184. { decrement for }
  3185. local_symtable_index:=local_symtable_index-2;
  3186. pdo:=_class;
  3187. if (owner.symtabletype<>localsymtable) then
  3188. while assigned(pdo) do
  3189. begin
  3190. if pdo.symtable<>aktrecordsymtable then
  3191. dec(local_symtable_index);
  3192. pdo:=pdo.childof;
  3193. end;
  3194. end;
  3195. end;
  3196. function tprocdef.haspara:boolean;
  3197. begin
  3198. haspara:=assigned(parast.symindex.first);
  3199. end;
  3200. {$ifdef GDB}
  3201. {$ifdef unused}
  3202. { procedure addparaname(p : tsym);
  3203. var vs : char;
  3204. begin
  3205. if tvarsym(p).varspez = vs_value then vs := '1'
  3206. else vs := '0';
  3207. strpcopy(strend(StabRecString),p^.name+':'+tstoreddef(tvarsym(p).vartype.def).numberstring+','+vs+';');
  3208. end; }
  3209. function tprocdef.stabstring : pchar;
  3210. var
  3211. i : longint;
  3212. stabrecstring : pchar;
  3213. begin
  3214. getmem(StabRecString,1024);
  3215. strpcopy(StabRecString,'f'+tstoreddef(rettype.def).numberstring);
  3216. i:=maxparacount;
  3217. if i>0 then
  3218. begin
  3219. strpcopy(strend(StabRecString),','+tostr(i)+';');
  3220. (* confuse gdb !! PM
  3221. if assigned(parast) then
  3222. parast.foreach({$ifdef FPCPROCVAR}@{$endif}addparaname)
  3223. else
  3224. begin
  3225. param := para1;
  3226. i := 0;
  3227. while assigned(param) do
  3228. begin
  3229. inc(i);
  3230. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  3231. {Here we have lost the parameter names !!}
  3232. {using lower case parameters }
  3233. strpcopy(strend(stabrecstring),'p'+tostr(i)
  3234. +':'+param^.paratype.def.numberstring+','+vartyp+';');
  3235. param := param^.next;
  3236. end;
  3237. end; *)
  3238. {strpcopy(strend(StabRecString),';');}
  3239. end;
  3240. stabstring := strnew(stabrecstring);
  3241. freemem(stabrecstring,1024);
  3242. end;
  3243. {$endif unused}
  3244. function tprocdef.stabstring: pchar;
  3245. Var RType : Char;
  3246. Obj,Info : String;
  3247. stabsstr : string;
  3248. p : pchar;
  3249. begin
  3250. obj := procsym.name;
  3251. info := '';
  3252. if tprocsym(procsym).is_global then
  3253. RType := 'F'
  3254. else
  3255. RType := 'f';
  3256. if assigned(owner) then
  3257. begin
  3258. if (owner.symtabletype = objectsymtable) then
  3259. obj := upper(owner.name^)+'__'+procsym.name;
  3260. { this code was correct only as long as the local symboltable
  3261. of the parent had the same name as the function
  3262. but this is no true anymore !! PM
  3263. if (owner.symtabletype=localsymtable) and assigned(owner.name) then
  3264. info := ','+name+','+owner.name^; }
  3265. if (owner.symtabletype=localsymtable) and
  3266. assigned(owner.defowner) and
  3267. assigned(tprocdef(owner.defowner).procsym) then
  3268. info := ','+procsym.name+','+tprocdef(owner.defowner).procsym.name;
  3269. end;
  3270. stabsstr:=mangledname;
  3271. getmem(p,length(stabsstr)+255);
  3272. strpcopy(p,'"'+obj+':'+RType
  3273. +tstoreddef(rettype.def).numberstring+info+'",'+tostr(n_function)
  3274. +',0,'+
  3275. tostr(fileinfo.line)
  3276. +',');
  3277. strpcopy(strend(p),stabsstr);
  3278. stabstring:=strnew(p);
  3279. freemem(p,length(stabsstr)+255);
  3280. end;
  3281. procedure tprocdef.concatstabto(asmlist : taasmoutput);
  3282. begin
  3283. if (proccalloption=pocall_internproc) then
  3284. exit;
  3285. if not isstabwritten then
  3286. asmList.concat(Tai_stabs.Create(stabstring));
  3287. isstabwritten := true;
  3288. if assigned(parast) then
  3289. tstoredsymtable(parast).concatstabto(asmlist);
  3290. { local type defs and vars should not be written
  3291. inside the main proc stab }
  3292. if assigned(localst) and
  3293. (lexlevel>main_program_level) then
  3294. tstoredsymtable(localst).concatstabto(asmlist);
  3295. is_def_stab_written := written;
  3296. end;
  3297. {$endif GDB}
  3298. procedure tprocdef.deref;
  3299. var
  3300. oldlocalsymtable : tsymtable;
  3301. begin
  3302. inherited deref;
  3303. resolvedef(pointer(_class));
  3304. { parast }
  3305. oldlocalsymtable:=aktlocalsymtable;
  3306. aktlocalsymtable:=parast;
  3307. tparasymtable(parast).deref;
  3308. aktlocalsymtable:=oldlocalsymtable;
  3309. { procsym that originaly defined this definition, should be in the
  3310. same symtable }
  3311. resolvesym(pointer(procsym));
  3312. end;
  3313. procedure tprocdef.derefimpl;
  3314. var
  3315. oldlocalsymtable : tsymtable;
  3316. begin
  3317. { locals }
  3318. if assigned(localst) then
  3319. begin
  3320. { localst }
  3321. oldlocalsymtable:=aktlocalsymtable;
  3322. aktlocalsymtable:=localst;
  3323. { we can deref both interface and implementation parts }
  3324. tlocalsymtable(localst).deref;
  3325. tlocalsymtable(localst).derefimpl;
  3326. aktlocalsymtable:=oldlocalsymtable;
  3327. { funcretsym, this is always located in the localst }
  3328. resolvesym(pointer(funcretsym));
  3329. end
  3330. else
  3331. begin
  3332. { safety }
  3333. funcretsym:=nil;
  3334. end;
  3335. { inline tree }
  3336. if (proccalloption=pocall_inline) then
  3337. code.derefimpl;
  3338. end;
  3339. function tprocdef.mangledname : string;
  3340. var
  3341. s : string;
  3342. hp : TParaItem;
  3343. begin
  3344. if assigned(_mangledname) then
  3345. begin
  3346. mangledname:=_mangledname^;
  3347. exit;
  3348. end;
  3349. { we need to use the symtable where the procsym is inserted,
  3350. because that is visible to the world }
  3351. s:=mangledname_prefix('',procsym.owner)+procsym.name+'$';
  3352. if overloadnumber>0 then
  3353. s:=s+tostr(overloadnumber)+'$';
  3354. { add parameter types }
  3355. hp:=TParaItem(Para.last);
  3356. while assigned(hp) do
  3357. begin
  3358. s:=s+hp.paratype.def.mangledparaname;
  3359. hp:=TParaItem(hp.previous);
  3360. if assigned(hp) then
  3361. s:=s+'$';
  3362. end;
  3363. _mangledname:=stringdup(s);
  3364. mangledname:=_mangledname^;
  3365. end;
  3366. function tprocdef.cplusplusmangledname : string;
  3367. function getcppparaname(p : tdef) : string;
  3368. const
  3369. ordtype2str : array[tbasetype] of string[2] = (
  3370. '',
  3371. 'Uc','Us','Ui','Us',
  3372. 'Sc','s','i','x',
  3373. 'b','b','b',
  3374. 'c','w');
  3375. var
  3376. s : string;
  3377. begin
  3378. case p.deftype of
  3379. orddef:
  3380. s:=ordtype2str[torddef(p).typ];
  3381. pointerdef:
  3382. s:='P'+getcppparaname(tpointerdef(p).pointertype.def);
  3383. else
  3384. internalerror(2103001);
  3385. end;
  3386. getcppparaname:=s;
  3387. end;
  3388. var
  3389. s,s2 : string;
  3390. param : TParaItem;
  3391. begin
  3392. s := procsym.realname;
  3393. if procsym.owner.symtabletype=objectsymtable then
  3394. begin
  3395. s2:=upper(tobjectdef(procsym.owner.defowner).typesym.realname);
  3396. case proctypeoption of
  3397. potype_destructor:
  3398. s:='_$_'+tostr(length(s2))+s2;
  3399. potype_constructor:
  3400. s:='___'+tostr(length(s2))+s2;
  3401. else
  3402. s:='_'+s+'__'+tostr(length(s2))+s2;
  3403. end;
  3404. end
  3405. else s:=s+'__';
  3406. s:=s+'F';
  3407. { concat modifiers }
  3408. { !!!!! }
  3409. { now we handle the parameters }
  3410. param := TParaItem(Para.first);
  3411. if assigned(param) then
  3412. while assigned(param) do
  3413. begin
  3414. s2:=getcppparaname(param.paratype.def);
  3415. if param.paratyp in [vs_var,vs_out] then
  3416. s2:='R'+s2;
  3417. s:=s+s2;
  3418. param:=TParaItem(param.next);
  3419. end
  3420. else
  3421. s:=s+'v';
  3422. cplusplusmangledname:=s;
  3423. end;
  3424. procedure tprocdef.setmangledname(const s : string);
  3425. begin
  3426. stringdispose(_mangledname);
  3427. _mangledname:=stringdup(s);
  3428. has_mangledname:=true;
  3429. end;
  3430. {***************************************************************************
  3431. TPROCVARDEF
  3432. ***************************************************************************}
  3433. constructor tprocvardef.create;
  3434. begin
  3435. inherited create;
  3436. deftype:=procvardef;
  3437. end;
  3438. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  3439. begin
  3440. inherited ppuload(ppufile);
  3441. deftype:=procvardef;
  3442. end;
  3443. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  3444. begin
  3445. { here we cannot get a real good value so just give something }
  3446. { plausible (PM) }
  3447. { a more secure way would be
  3448. to allways store in a temp }
  3449. if is_fpu(rettype.def) then
  3450. {$ifdef FAST_FPU}
  3451. fpu_used:=3
  3452. {$else : not FAST_FPU, i.e. SAFE_FPU}
  3453. fpu_used:={2}maxfpuregs
  3454. {$endif FAST_FPU}
  3455. else
  3456. fpu_used:=0;
  3457. inherited ppuwrite(ppufile);
  3458. ppufile.writeentry(ibprocvardef);
  3459. end;
  3460. function tprocvardef.size : longint;
  3461. begin
  3462. if (po_methodpointer in procoptions) then
  3463. size:=2*POINTER_SIZE
  3464. else
  3465. size:=POINTER_SIZE;
  3466. end;
  3467. {$ifdef GDB}
  3468. function tprocvardef.stabstring : pchar;
  3469. var
  3470. nss : pchar;
  3471. { i : longint; }
  3472. begin
  3473. { i := maxparacount; }
  3474. getmem(nss,1024);
  3475. { it is not a function but a function pointer !! (PM) }
  3476. strpcopy(nss,'*f'+tstoreddef(rettype.def).numberstring{+','+tostr(i)}+';');
  3477. { this confuses gdb !!
  3478. we should use 'F' instead of 'f' but
  3479. as we use c++ language mode
  3480. it does not like that either
  3481. Please do not remove this part
  3482. might be used once
  3483. gdb for pascal is ready PM }
  3484. (*
  3485. param := para1;
  3486. i := 0;
  3487. while assigned(param) do
  3488. begin
  3489. inc(i);
  3490. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  3491. {Here we have lost the parameter names !!}
  3492. pst := strpnew('p'+tostr(i)+':'+param^.paratype.def.numberstring+','+vartyp+';');
  3493. strcat(nss,pst);
  3494. strdispose(pst);
  3495. param := param^.next;
  3496. end; *)
  3497. {strpcopy(strend(nss),';');}
  3498. stabstring := strnew(nss);
  3499. freemem(nss,1024);
  3500. end;
  3501. procedure tprocvardef.concatstabto(asmlist : taasmoutput);
  3502. begin
  3503. if ( not assigned(typesym) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches))
  3504. and (is_def_stab_written = not_written) then
  3505. inherited concatstabto(asmlist);
  3506. is_def_stab_written:=written;
  3507. end;
  3508. {$endif GDB}
  3509. procedure tprocvardef.write_rtti_data(rt:trttitype);
  3510. var
  3511. pdc : TParaItem;
  3512. methodkind, paraspec : byte;
  3513. begin
  3514. if po_methodpointer in procoptions then
  3515. begin
  3516. { write method id and name }
  3517. rttiList.concat(Tai_const.Create_8bit(tkmethod));
  3518. write_rtti_name;
  3519. { write kind of method (can only be function or procedure)}
  3520. if rettype.def = voidtype.def then
  3521. methodkind := mkProcedure
  3522. else
  3523. methodkind := mkFunction;
  3524. rttiList.concat(Tai_const.Create_8bit(methodkind));
  3525. { get # of parameters }
  3526. rttiList.concat(Tai_const.Create_8bit(maxparacount));
  3527. { write parameter info. The parameters must be written in reverse order
  3528. if this method uses right to left parameter pushing! }
  3529. if (po_leftright in procoptions) then
  3530. pdc:=TParaItem(Para.last)
  3531. else
  3532. pdc:=TParaItem(Para.first);
  3533. while assigned(pdc) do
  3534. begin
  3535. case pdc.paratyp of
  3536. vs_value: paraspec := 0;
  3537. vs_const: paraspec := pfConst;
  3538. vs_var : paraspec := pfVar;
  3539. vs_out : paraspec := pfOut;
  3540. end;
  3541. { write flags for current parameter }
  3542. rttiList.concat(Tai_const.Create_8bit(paraspec));
  3543. { write name of current parameter ### how can I get this??? (sg)}
  3544. rttiList.concat(Tai_const.Create_8bit(0));
  3545. { write name of type of current parameter }
  3546. tstoreddef(pdc.paratype.def).write_rtti_name;
  3547. if (po_leftright in procoptions) then
  3548. pdc:=TParaItem(pdc.previous)
  3549. else
  3550. pdc:=TParaItem(pdc.next);
  3551. end;
  3552. { write name of result type }
  3553. tstoreddef(rettype.def).write_rtti_name;
  3554. end;
  3555. end;
  3556. function tprocvardef.is_publishable : boolean;
  3557. begin
  3558. is_publishable:=(po_methodpointer in procoptions);
  3559. end;
  3560. function tprocvardef.gettypename : string;
  3561. var
  3562. s: string;
  3563. begin
  3564. if assigned(rettype.def) and
  3565. (rettype.def<>voidtype.def) then
  3566. s:='<procedure variable type of function'+typename_paras+
  3567. ':'+rettype.def.gettypename
  3568. else
  3569. s:='<procedure variable type of procedure'+typename_paras;
  3570. if po_methodpointer in procoptions then
  3571. s := s+' of object';
  3572. gettypename := s+';'+ProcCallOptionStr[proccalloption]+'>';
  3573. end;
  3574. {***************************************************************************
  3575. TOBJECTDEF
  3576. ***************************************************************************}
  3577. {$ifdef GDB}
  3578. const
  3579. vtabletype : word = 0;
  3580. vtableassigned : boolean = false;
  3581. {$endif GDB}
  3582. constructor tobjectdef.create(ot : tobjectdeftype;const n : string;c : tobjectdef);
  3583. begin
  3584. inherited create;
  3585. objecttype:=ot;
  3586. deftype:=objectdef;
  3587. objectoptions:=[];
  3588. childof:=nil;
  3589. symtable:=tobjectsymtable.create(n);
  3590. { create space for vmt !! }
  3591. vmt_offset:=0;
  3592. symtable.datasize:=0;
  3593. symtable.defowner:=self;
  3594. { recordalign -1 means C record packing, that starts
  3595. with an alignment of 1 }
  3596. if aktalignment.recordalignmax=-1 then
  3597. symtable.dataalignment:=1
  3598. else
  3599. symtable.dataalignment:=aktalignment.recordalignmax;
  3600. lastvtableindex:=0;
  3601. set_parent(c);
  3602. objname:=stringdup(upper(n));
  3603. objrealname:=stringdup(n);
  3604. { set up guid }
  3605. isiidguidvalid:=true; { default null guid }
  3606. fillchar(iidguid,sizeof(iidguid),0); { default null guid }
  3607. iidstr:=stringdup(''); { default is empty string }
  3608. { setup implemented interfaces }
  3609. if objecttype in [odt_class,odt_interfacecorba] then
  3610. implementedinterfaces:=timplementedinterfaces.create
  3611. else
  3612. implementedinterfaces:=nil;
  3613. {$ifdef GDB}
  3614. writing_class_record_stab:=false;
  3615. {$endif GDB}
  3616. end;
  3617. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  3618. var
  3619. oldread_member : boolean;
  3620. i,implintfcount: longint;
  3621. begin
  3622. inherited ppuloaddef(ppufile);
  3623. deftype:=objectdef;
  3624. objecttype:=tobjectdeftype(ppufile.getbyte);
  3625. savesize:=ppufile.getlongint;
  3626. vmt_offset:=ppufile.getlongint;
  3627. objrealname:=stringdup(ppufile.getstring);
  3628. objname:=stringdup(upper(objrealname^));
  3629. childof:=tobjectdef(ppufile.getderef);
  3630. ppufile.getsmallset(objectoptions);
  3631. { load guid }
  3632. iidstr:=nil;
  3633. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  3634. begin
  3635. isiidguidvalid:=boolean(ppufile.getbyte);
  3636. ppufile.getguid(iidguid);
  3637. iidstr:=stringdup(ppufile.getstring);
  3638. lastvtableindex:=ppufile.getlongint;
  3639. end;
  3640. { load implemented interfaces }
  3641. if objecttype in [odt_class,odt_interfacecorba] then
  3642. begin
  3643. implementedinterfaces:=timplementedinterfaces.create;
  3644. implintfcount:=ppufile.getlongint;
  3645. for i:=1 to implintfcount do
  3646. begin
  3647. implementedinterfaces.addintfref(ppufile.getderef);
  3648. implementedinterfaces.ioffsets(i)^:=ppufile.getlongint;
  3649. end;
  3650. end
  3651. else
  3652. implementedinterfaces:=nil;
  3653. oldread_member:=read_member;
  3654. read_member:=true;
  3655. symtable:=tobjectsymtable.create(objrealname^);
  3656. tobjectsymtable(symtable).ppuload(ppufile);
  3657. read_member:=oldread_member;
  3658. symtable.defowner:=self;
  3659. { handles the predefined class tobject }
  3660. { the last TOBJECT which is loaded gets }
  3661. { it ! }
  3662. if (childof=nil) and
  3663. (objecttype=odt_class) and
  3664. (objname^='TOBJECT') then
  3665. class_tobject:=self;
  3666. if (childof=nil) and
  3667. (objecttype=odt_interfacecom) and
  3668. (objname^='IUNKNOWN') then
  3669. interface_iunknown:=self;
  3670. {$ifdef GDB}
  3671. writing_class_record_stab:=false;
  3672. {$endif GDB}
  3673. end;
  3674. destructor tobjectdef.destroy;
  3675. begin
  3676. if assigned(symtable) then
  3677. symtable.free;
  3678. stringdispose(objname);
  3679. stringdispose(objrealname);
  3680. stringdispose(iidstr);
  3681. if assigned(implementedinterfaces) then
  3682. implementedinterfaces.free;
  3683. inherited destroy;
  3684. end;
  3685. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  3686. var
  3687. oldread_member : boolean;
  3688. implintfcount : longint;
  3689. i : longint;
  3690. begin
  3691. inherited ppuwritedef(ppufile);
  3692. ppufile.putbyte(byte(objecttype));
  3693. ppufile.putlongint(size);
  3694. ppufile.putlongint(vmt_offset);
  3695. ppufile.putstring(objrealname^);
  3696. ppufile.putderef(childof);
  3697. ppufile.putsmallset(objectoptions);
  3698. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  3699. begin
  3700. ppufile.putbyte(byte(isiidguidvalid));
  3701. ppufile.putguid(iidguid);
  3702. ppufile.putstring(iidstr^);
  3703. ppufile.putlongint(lastvtableindex);
  3704. end;
  3705. if objecttype in [odt_class,odt_interfacecorba] then
  3706. begin
  3707. implintfcount:=implementedinterfaces.count;
  3708. ppufile.putlongint(implintfcount);
  3709. for i:=1 to implintfcount do
  3710. begin
  3711. ppufile.putderef(implementedinterfaces.interfaces(i));
  3712. ppufile.putlongint(implementedinterfaces.ioffsets(i)^);
  3713. end;
  3714. end;
  3715. ppufile.writeentry(ibobjectdef);
  3716. oldread_member:=read_member;
  3717. read_member:=true;
  3718. tobjectsymtable(symtable).ppuwrite(ppufile);
  3719. read_member:=oldread_member;
  3720. end;
  3721. procedure tobjectdef.deref;
  3722. var
  3723. oldrecsyms : tsymtable;
  3724. begin
  3725. inherited deref;
  3726. resolvedef(pointer(childof));
  3727. oldrecsyms:=aktrecordsymtable;
  3728. aktrecordsymtable:=symtable;
  3729. tstoredsymtable(symtable).deref;
  3730. aktrecordsymtable:=oldrecsyms;
  3731. if objecttype in [odt_class,odt_interfacecorba] then
  3732. implementedinterfaces.deref;
  3733. end;
  3734. procedure tobjectdef.set_parent( c : tobjectdef);
  3735. begin
  3736. { nothing to do if the parent was not forward !}
  3737. if assigned(childof) then
  3738. exit;
  3739. childof:=c;
  3740. { some options are inherited !! }
  3741. if assigned(c) then
  3742. begin
  3743. { only important for classes }
  3744. lastvtableindex:=c.lastvtableindex;
  3745. objectoptions:=objectoptions+(c.objectoptions*
  3746. [oo_has_virtual,oo_has_private,oo_has_protected,
  3747. oo_has_constructor,oo_has_destructor]);
  3748. if not (objecttype in [odt_interfacecom,odt_interfacecorba]) then
  3749. begin
  3750. { add the data of the anchestor class }
  3751. inc(symtable.datasize,c.symtable.datasize);
  3752. if (oo_has_vmt in objectoptions) and
  3753. (oo_has_vmt in c.objectoptions) then
  3754. dec(symtable.datasize,POINTER_SIZE);
  3755. { if parent has a vmt field then
  3756. the offset is the same for the child PM }
  3757. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  3758. begin
  3759. vmt_offset:=c.vmt_offset;
  3760. include(objectoptions,oo_has_vmt);
  3761. end;
  3762. end;
  3763. end;
  3764. savesize := symtable.datasize;
  3765. end;
  3766. procedure tobjectdef.insertvmt;
  3767. begin
  3768. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  3769. exit;
  3770. if (oo_has_vmt in objectoptions) then
  3771. internalerror(12345)
  3772. else
  3773. begin
  3774. symtable.datasize:=align(symtable.datasize,symtable.dataalignment);
  3775. vmt_offset:=symtable.datasize;
  3776. inc(symtable.datasize,POINTER_SIZE);
  3777. include(objectoptions,oo_has_vmt);
  3778. end;
  3779. end;
  3780. procedure tobjectdef.check_forwards;
  3781. begin
  3782. if not(objecttype in [odt_interfacecom,odt_interfacecorba]) then
  3783. tstoredsymtable(symtable).check_forwards;
  3784. if (oo_is_forward in objectoptions) then
  3785. begin
  3786. { ok, in future, the forward can be resolved }
  3787. Message1(sym_e_class_forward_not_resolved,objrealname^);
  3788. exclude(objectoptions,oo_is_forward);
  3789. end;
  3790. end;
  3791. { true, if self inherits from d (or if they are equal) }
  3792. function tobjectdef.is_related(d : tobjectdef) : boolean;
  3793. var
  3794. hp : tobjectdef;
  3795. begin
  3796. hp:=self;
  3797. while assigned(hp) do
  3798. begin
  3799. if hp=d then
  3800. begin
  3801. is_related:=true;
  3802. exit;
  3803. end;
  3804. hp:=hp.childof;
  3805. end;
  3806. is_related:=false;
  3807. end;
  3808. (* procedure tobjectdef._searchdestructor(sym : tnamedindexitem;arg:pointer);
  3809. var
  3810. p : pprocdeflist;
  3811. begin
  3812. { if we found already a destructor, then we exit }
  3813. if assigned(sd) then
  3814. exit;
  3815. if tsym(sym).typ=procsym then
  3816. begin
  3817. p:=tprocsym(sym).defs;
  3818. while assigned(p) do
  3819. begin
  3820. if p^.def.proctypeoption=potype_destructor then
  3821. begin
  3822. sd:=p^.def;
  3823. exit;
  3824. end;
  3825. p:=p^.next;
  3826. end;
  3827. end;
  3828. end;*)
  3829. procedure Tobjectdef._searchdestructor(sym:Tnamedindexitem;arg:pointer);
  3830. begin
  3831. { if we found already a destructor, then we exit }
  3832. if (sd=nil) and (Tsym(sym).typ=procsym) then
  3833. sd:=Tprocsym(sym).search_procdef_bytype(potype_destructor);
  3834. end;
  3835. function tobjectdef.searchdestructor : tprocdef;
  3836. var
  3837. o : tobjectdef;
  3838. begin
  3839. searchdestructor:=nil;
  3840. o:=self;
  3841. sd:=nil;
  3842. while assigned(o) do
  3843. begin
  3844. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}_searchdestructor,nil);
  3845. if assigned(sd) then
  3846. begin
  3847. searchdestructor:=sd;
  3848. exit;
  3849. end;
  3850. o:=o.childof;
  3851. end;
  3852. end;
  3853. function tobjectdef.size : longint;
  3854. var
  3855. _resultsize : longint;
  3856. begin
  3857. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba] then
  3858. _resultsize:=POINTER_SIZE
  3859. else
  3860. _resultsize:=symtable.datasize;
  3861. {$ifdef m68k}
  3862. { 68000 (only) CPU's only accept 32K arrays }
  3863. if (_resultsize > 32767) and (aktoptprocessor = MC68000) then
  3864. Message(sym_w_segment_too_large);
  3865. {$endif}
  3866. size := _resultsize;
  3867. end;
  3868. function tobjectdef.alignment:longint;
  3869. begin
  3870. alignment:=symtable.dataalignment;
  3871. end;
  3872. function tobjectdef.vmtmethodoffset(index:longint):longint;
  3873. begin
  3874. { for offset of methods for classes, see rtl/inc/objpash.inc }
  3875. case objecttype of
  3876. odt_class:
  3877. vmtmethodoffset:=(index+12)*POINTER_SIZE;
  3878. odt_interfacecom,odt_interfacecorba:
  3879. vmtmethodoffset:=index*POINTER_SIZE;
  3880. else
  3881. {$ifdef WITHDMT}
  3882. vmtmethodoffset:=(index+4)*POINTER_SIZE;
  3883. {$else WITHDMT}
  3884. vmtmethodoffset:=(index+3)*POINTER_SIZE;
  3885. {$endif WITHDMT}
  3886. end;
  3887. end;
  3888. function tobjectdef.vmt_mangledname : string;
  3889. begin
  3890. if not(oo_has_vmt in objectoptions) then
  3891. Message1(parser_object_has_no_vmt,objrealname^);
  3892. vmt_mangledname:=mangledname_prefix('VMT',owner)+objname^;
  3893. end;
  3894. function tobjectdef.rtti_name : string;
  3895. begin
  3896. rtti_name:=mangledname_prefix('RTTI',owner)+objname^;
  3897. end;
  3898. {$ifdef GDB}
  3899. procedure tobjectdef.addprocname(p :tnamedindexitem;arg:pointer);
  3900. var virtualind,argnames : string;
  3901. news, newrec : pchar;
  3902. pd,ipd : tprocdef;
  3903. lindex : longint;
  3904. para : TParaItem;
  3905. arglength : byte;
  3906. sp : char;
  3907. begin
  3908. If tsym(p).typ = procsym then
  3909. begin
  3910. pd := tprocsym(p).first_procdef;
  3911. { this will be used for full implementation of object stabs
  3912. not yet done }
  3913. ipd := Tprocsym(p).last_procdef;
  3914. if (po_virtualmethod in pd.procoptions) then
  3915. begin
  3916. lindex := pd.extnumber;
  3917. {doesnt seem to be necessary
  3918. lindex := lindex or $80000000;}
  3919. virtualind := '*'+tostr(lindex)+';'+ipd._class.classnumberstring+';'
  3920. end
  3921. else
  3922. virtualind := '.';
  3923. { used by gdbpas to recognize constructor and destructors }
  3924. if (pd.proctypeoption=potype_constructor) then
  3925. argnames:='__ct__'
  3926. else if (pd.proctypeoption=potype_destructor) then
  3927. argnames:='__dt__'
  3928. else
  3929. argnames := '';
  3930. { arguments are not listed here }
  3931. {we don't need another definition}
  3932. para := TParaItem(pd.Para.first);
  3933. while assigned(para) do
  3934. begin
  3935. if Para.paratype.def.deftype = formaldef then
  3936. begin
  3937. if Para.paratyp=vs_var then
  3938. argnames := argnames+'3var'
  3939. else if Para.paratyp=vs_const then
  3940. argnames:=argnames+'5const'
  3941. else if Para.paratyp=vs_out then
  3942. argnames:=argnames+'3out';
  3943. end
  3944. else
  3945. begin
  3946. { if the arg definition is like (v: ^byte;..
  3947. there is no sym attached to data !!! }
  3948. if assigned(Para.paratype.def.typesym) then
  3949. begin
  3950. arglength := length(Para.paratype.def.typesym.name);
  3951. argnames := argnames + tostr(arglength)+Para.paratype.def.typesym.name;
  3952. end
  3953. else
  3954. begin
  3955. argnames:=argnames+'11unnamedtype';
  3956. end;
  3957. end;
  3958. para := TParaItem(Para.next);
  3959. end;
  3960. ipd.is_def_stab_written := written;
  3961. { here 2A must be changed for private and protected }
  3962. { 0 is private 1 protected and 2 public }
  3963. if (sp_private in tsym(p).symoptions) then sp:='0'
  3964. else if (sp_protected in tsym(p).symoptions) then sp:='1'
  3965. else sp:='2';
  3966. newrec := strpnew(p.name+'::'+ipd.numberstring
  3967. +'=##'+tstoreddef(pd.rettype.def).numberstring+';:'+argnames+';'+sp+'A'
  3968. +virtualind+';');
  3969. { get spare place for a string at the end }
  3970. if strlen(StabRecString) + strlen(newrec) >= StabRecSize-256 then
  3971. begin
  3972. getmem(news,stabrecsize+memsizeinc);
  3973. strcopy(news,stabrecstring);
  3974. freemem(stabrecstring,stabrecsize);
  3975. stabrecsize:=stabrecsize+memsizeinc;
  3976. stabrecstring:=news;
  3977. end;
  3978. strcat(StabRecstring,newrec);
  3979. {freemem(newrec,memsizeinc); }
  3980. strdispose(newrec);
  3981. {This should be used for case !!
  3982. RecOffset := RecOffset + pd.size;}
  3983. end;
  3984. end;
  3985. function tobjectdef.stabstring : pchar;
  3986. var anc : tobjectdef;
  3987. oldrec : pchar;
  3988. oldrecsize,oldrecoffset : longint;
  3989. str_end : string;
  3990. begin
  3991. if not (objecttype=odt_class) or writing_class_record_stab then
  3992. begin
  3993. oldrec := stabrecstring;
  3994. oldrecsize:=stabrecsize;
  3995. stabrecsize:=memsizeinc;
  3996. GetMem(stabrecstring,stabrecsize);
  3997. strpcopy(stabRecString,'s'+tostr(symtable.datasize));
  3998. if assigned(childof) then
  3999. begin
  4000. {only one ancestor not virtual, public, at base offset 0 }
  4001. { !1 , 0 2 0 , }
  4002. strpcopy(strend(stabrecstring),'!1,020,'+childof.classnumberstring+';');
  4003. end;
  4004. {virtual table to implement yet}
  4005. OldRecOffset:=RecOffset;
  4006. RecOffset := 0;
  4007. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}addname,nil);
  4008. RecOffset:=OldRecOffset;
  4009. if (oo_has_vmt in objectoptions) then
  4010. if not assigned(childof) or not(oo_has_vmt in childof.objectoptions) then
  4011. begin
  4012. strpcopy(strend(stabrecstring),'$vf'+classnumberstring+':'+typeglobalnumber('vtblarray')
  4013. +','+tostr(vmt_offset*8)+';');
  4014. end;
  4015. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}addprocname,nil);
  4016. if (oo_has_vmt in objectoptions) then
  4017. begin
  4018. anc := self;
  4019. while assigned(anc.childof) and (oo_has_vmt in anc.childof.objectoptions) do
  4020. anc := anc.childof;
  4021. { just in case anc = self }
  4022. str_end:=';~%'+anc.classnumberstring+';';
  4023. end
  4024. else
  4025. str_end:=';';
  4026. strpcopy(strend(stabrecstring),str_end);
  4027. stabstring := strnew(StabRecString);
  4028. freemem(stabrecstring,stabrecsize);
  4029. stabrecstring := oldrec;
  4030. stabrecsize:=oldrecsize;
  4031. end
  4032. else
  4033. begin
  4034. stabstring:=strpnew('*'+classnumberstring);
  4035. end;
  4036. end;
  4037. procedure tobjectdef.set_globalnb;
  4038. begin
  4039. globalnb:=PglobalTypeCount^;
  4040. inc(PglobalTypeCount^);
  4041. { classes need two type numbers, the globalnb is set to the ptr }
  4042. if objecttype=odt_class then
  4043. begin
  4044. globalnb:=PGlobalTypeCount^;
  4045. inc(PglobalTypeCount^);
  4046. end;
  4047. end;
  4048. function tobjectdef.classnumberstring : string;
  4049. begin
  4050. { write stabs again if needed }
  4051. numberstring;
  4052. if objecttype=odt_class then
  4053. begin
  4054. dec(globalnb);
  4055. classnumberstring:=numberstring;
  4056. inc(globalnb);
  4057. end
  4058. else
  4059. classnumberstring:=numberstring;
  4060. end;
  4061. function tobjectdef.allstabstring : pchar;
  4062. var stabchar : string[2];
  4063. ss,st : pchar;
  4064. sname : string;
  4065. sym_line_no : longint;
  4066. begin
  4067. ss := stabstring;
  4068. getmem(st,strlen(ss)+512);
  4069. stabchar := 't';
  4070. if deftype in tagtypes then
  4071. stabchar := 'Tt';
  4072. if assigned(typesym) then
  4073. begin
  4074. sname := typesym.name;
  4075. sym_line_no:=typesym.fileinfo.line;
  4076. end
  4077. else
  4078. begin
  4079. sname := ' ';
  4080. sym_line_no:=0;
  4081. end;
  4082. if writing_class_record_stab then
  4083. strpcopy(st,'"'+sname+':'+stabchar+classnumberstring+'=')
  4084. else
  4085. strpcopy(st,'"'+sname+':'+stabchar+numberstring+'=');
  4086. strpcopy(strecopy(strend(st),ss),'",'+tostr(N_LSYM)+',0,'+tostr(sym_line_no)+',0');
  4087. allstabstring := strnew(st);
  4088. freemem(st,strlen(ss)+512);
  4089. strdispose(ss);
  4090. end;
  4091. procedure tobjectdef.concatstabto(asmlist : taasmoutput);
  4092. var st : pstring;
  4093. begin
  4094. if objecttype<>odt_class then
  4095. begin
  4096. inherited concatstabto(asmlist);
  4097. exit;
  4098. end;
  4099. if ((typesym=nil) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches)) and
  4100. (is_def_stab_written = not_written) then
  4101. begin
  4102. if globalnb=0 then
  4103. set_globalnb;
  4104. { Write the record class itself }
  4105. writing_class_record_stab:=true;
  4106. inherited concatstabto(asmlist);
  4107. writing_class_record_stab:=false;
  4108. { Write the invisible pointer class }
  4109. is_def_stab_written:=not_written;
  4110. if assigned(typesym) then
  4111. begin
  4112. st:=typesym.FName;
  4113. typesym.FName:=stringdup(' ');
  4114. end;
  4115. inherited concatstabto(asmlist);
  4116. if assigned(typesym) then
  4117. begin
  4118. stringdispose(typesym.FName);
  4119. typesym.FName:=st;
  4120. end;
  4121. end;
  4122. end;
  4123. {$endif GDB}
  4124. function tobjectdef.needs_inittable : boolean;
  4125. begin
  4126. case objecttype of
  4127. odt_class :
  4128. needs_inittable:=false;
  4129. odt_interfacecom:
  4130. needs_inittable:=true;
  4131. odt_interfacecorba:
  4132. needs_inittable:=is_related(interface_iunknown);
  4133. odt_object:
  4134. needs_inittable:=tobjectsymtable(symtable).needs_init_final;
  4135. else
  4136. internalerror(200108267);
  4137. end;
  4138. end;
  4139. function tobjectdef.members_need_inittable : boolean;
  4140. begin
  4141. members_need_inittable:=tobjectsymtable(symtable).needs_init_final;
  4142. end;
  4143. procedure tobjectdef.count_published_properties(sym:tnamedindexitem;arg:pointer);
  4144. begin
  4145. if needs_prop_entry(tsym(sym)) and
  4146. (tsym(sym).typ<>varsym) then
  4147. inc(count);
  4148. end;
  4149. procedure tobjectdef.write_property_info(sym : tnamedindexitem;arg:pointer);
  4150. var
  4151. proctypesinfo : byte;
  4152. procedure writeproc(proc : tsymlist; shiftvalue : byte);
  4153. var
  4154. typvalue : byte;
  4155. hp : psymlistitem;
  4156. address : longint;
  4157. begin
  4158. if not(assigned(proc) and assigned(proc.firstsym)) then
  4159. begin
  4160. rttiList.concat(Tai_const.Create_32bit(1));
  4161. typvalue:=3;
  4162. end
  4163. else if proc.firstsym^.sym.typ=varsym then
  4164. begin
  4165. address:=0;
  4166. hp:=proc.firstsym;
  4167. while assigned(hp) do
  4168. begin
  4169. inc(address,tvarsym(hp^.sym).address);
  4170. hp:=hp^.next;
  4171. end;
  4172. rttiList.concat(Tai_const.Create_32bit(address));
  4173. typvalue:=0;
  4174. end
  4175. else
  4176. begin
  4177. if not(po_virtualmethod in tprocdef(proc.def).procoptions) then
  4178. begin
  4179. rttiList.concat(Tai_const_symbol.Createname(tprocdef(proc.def).mangledname));
  4180. typvalue:=1;
  4181. end
  4182. else
  4183. begin
  4184. { virtual method, write vmt offset }
  4185. rttiList.concat(Tai_const.Create_32bit(
  4186. tprocdef(proc.def)._class.vmtmethodoffset(tprocdef(proc.def).extnumber)));
  4187. typvalue:=2;
  4188. end;
  4189. end;
  4190. proctypesinfo:=proctypesinfo or (typvalue shl shiftvalue);
  4191. end;
  4192. begin
  4193. if needs_prop_entry(tsym(sym)) then
  4194. case tsym(sym).typ of
  4195. varsym:
  4196. begin
  4197. {$ifdef dummy}
  4198. if not(tvarsym(sym).vartype.def.deftype=objectdef) or
  4199. not(tobjectdef(tvarsym(sym).vartype.def).is_class) then
  4200. internalerror(1509992);
  4201. { access to implicit class property as field }
  4202. proctypesinfo:=(0 shl 0) or (0 shl 2) or (0 shl 4);
  4203. rttiList.concat(Tai_const_symbol.Createname(tvarsym(sym.vartype.def.get_rtti_label)));
  4204. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym.address)));
  4205. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym.address)));
  4206. { per default stored }
  4207. rttiList.concat(Tai_const.Create_32bit(1));
  4208. { index as well as ... }
  4209. rttiList.concat(Tai_const.Create_32bit(0));
  4210. { default value are zero }
  4211. rttiList.concat(Tai_const.Create_32bit(0));
  4212. rttiList.concat(Tai_const.Create_16bit(count));
  4213. inc(count);
  4214. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  4215. rttiList.concat(Tai_const.Create_8bit(length(tvarsym(sym.realname))));
  4216. rttiList.concat(Tai_string.Create(tvarsym(sym.realname)));
  4217. {$endif dummy}
  4218. end;
  4219. propertysym:
  4220. begin
  4221. if ppo_indexed in tpropertysym(sym).propoptions then
  4222. proctypesinfo:=$40
  4223. else
  4224. proctypesinfo:=0;
  4225. rttiList.concat(Tai_const_symbol.Create(tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti)));
  4226. writeproc(tpropertysym(sym).readaccess,0);
  4227. writeproc(tpropertysym(sym).writeaccess,2);
  4228. { isn't it stored ? }
  4229. if not(ppo_stored in tpropertysym(sym).propoptions) then
  4230. begin
  4231. rttiList.concat(Tai_const.Create_32bit(0));
  4232. proctypesinfo:=proctypesinfo or (3 shl 4);
  4233. end
  4234. else
  4235. writeproc(tpropertysym(sym).storedaccess,4);
  4236. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).index));
  4237. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).default));
  4238. rttiList.concat(Tai_const.Create_16bit(count));
  4239. inc(count);
  4240. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  4241. rttiList.concat(Tai_const.Create_8bit(length(tpropertysym(sym).realname)));
  4242. rttiList.concat(Tai_string.Create(tpropertysym(sym).realname));
  4243. end;
  4244. else internalerror(1509992);
  4245. end;
  4246. end;
  4247. procedure tobjectdef.generate_published_child_rtti(sym : tnamedindexitem;arg:pointer);
  4248. begin
  4249. if needs_prop_entry(tsym(sym)) then
  4250. begin
  4251. case tsym(sym).typ of
  4252. propertysym:
  4253. tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti);
  4254. varsym:
  4255. tstoreddef(tvarsym(sym).vartype.def).get_rtti_label(fullrtti);
  4256. else
  4257. internalerror(1509991);
  4258. end;
  4259. end;
  4260. end;
  4261. procedure tobjectdef.write_child_rtti_data(rt:trttitype);
  4262. begin
  4263. FRTTIType:=rt;
  4264. case rt of
  4265. initrtti :
  4266. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}generate_field_rtti,nil);
  4267. fullrtti :
  4268. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}generate_published_child_rtti,nil);
  4269. else
  4270. internalerror(200108301);
  4271. end;
  4272. end;
  4273. type
  4274. tclasslistitem = class(TLinkedListItem)
  4275. index : longint;
  4276. p : tobjectdef;
  4277. end;
  4278. var
  4279. classtablelist : tlinkedlist;
  4280. tablecount : longint;
  4281. function searchclasstablelist(p : tobjectdef) : tclasslistitem;
  4282. var
  4283. hp : tclasslistitem;
  4284. begin
  4285. hp:=tclasslistitem(classtablelist.first);
  4286. while assigned(hp) do
  4287. if hp.p=p then
  4288. begin
  4289. searchclasstablelist:=hp;
  4290. exit;
  4291. end
  4292. else
  4293. hp:=tclasslistitem(hp.next);
  4294. searchclasstablelist:=nil;
  4295. end;
  4296. procedure tobjectdef.count_published_fields(sym:tnamedindexitem;arg:pointer);
  4297. var
  4298. hp : tclasslistitem;
  4299. begin
  4300. if needs_prop_entry(tsym(sym)) and
  4301. (tsym(sym).typ=varsym) then
  4302. begin
  4303. if tvarsym(sym).vartype.def.deftype<>objectdef then
  4304. internalerror(0206001);
  4305. hp:=searchclasstablelist(tobjectdef(tvarsym(sym).vartype.def));
  4306. if not(assigned(hp)) then
  4307. begin
  4308. hp:=tclasslistitem.create;
  4309. hp.p:=tobjectdef(tvarsym(sym).vartype.def);
  4310. hp.index:=tablecount;
  4311. classtablelist.concat(hp);
  4312. inc(tablecount);
  4313. end;
  4314. inc(count);
  4315. end;
  4316. end;
  4317. procedure tobjectdef.writefields(sym:tnamedindexitem;arg:pointer);
  4318. var
  4319. hp : tclasslistitem;
  4320. begin
  4321. if needs_prop_entry(tsym(sym)) and
  4322. (tsym(sym).typ=varsym) then
  4323. begin
  4324. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym).address));
  4325. hp:=searchclasstablelist(tobjectdef(tvarsym(sym).vartype.def));
  4326. if not(assigned(hp)) then
  4327. internalerror(0206002);
  4328. rttiList.concat(Tai_const.Create_16bit(hp.index));
  4329. rttiList.concat(Tai_const.Create_8bit(length(tvarsym(sym).realname)));
  4330. rttiList.concat(Tai_string.Create(tvarsym(sym).realname));
  4331. end;
  4332. end;
  4333. function tobjectdef.generate_field_table : tasmlabel;
  4334. var
  4335. fieldtable,
  4336. classtable : tasmlabel;
  4337. hp : tclasslistitem;
  4338. begin
  4339. classtablelist:=TLinkedList.Create;
  4340. objectlibrary.getdatalabel(fieldtable);
  4341. objectlibrary.getdatalabel(classtable);
  4342. count:=0;
  4343. tablecount:=0;
  4344. symtable.foreach({$ifdef FPC}@{$endif}count_published_fields,nil);
  4345. if (cs_create_smart in aktmoduleswitches) then
  4346. rttiList.concat(Tai_cut.Create);
  4347. rttilist.concat(tai_align.create(const_align(pointer_size)));
  4348. rttiList.concat(Tai_label.Create(fieldtable));
  4349. rttiList.concat(Tai_const.Create_16bit(count));
  4350. rttiList.concat(Tai_const_symbol.Create(classtable));
  4351. symtable.foreach({$ifdef FPC}@{$endif}writefields,nil);
  4352. { generate the class table }
  4353. rttilist.concat(tai_align.create(const_align(pointer_size)));
  4354. rttiList.concat(Tai_label.Create(classtable));
  4355. rttiList.concat(Tai_const.Create_16bit(tablecount));
  4356. hp:=tclasslistitem(classtablelist.first);
  4357. while assigned(hp) do
  4358. begin
  4359. rttiList.concat(Tai_const_symbol.Createname(tobjectdef(hp.p).vmt_mangledname));
  4360. hp:=tclasslistitem(hp.next);
  4361. end;
  4362. generate_field_table:=fieldtable;
  4363. classtablelist.free;
  4364. end;
  4365. function tobjectdef.next_free_name_index : longint;
  4366. var
  4367. i : longint;
  4368. begin
  4369. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4370. i:=childof.next_free_name_index
  4371. else
  4372. i:=0;
  4373. count:=0;
  4374. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  4375. next_free_name_index:=i+count;
  4376. end;
  4377. procedure tobjectdef.write_rtti_data(rt:trttitype);
  4378. begin
  4379. case objecttype of
  4380. odt_class:
  4381. rttiList.concat(Tai_const.Create_8bit(tkclass));
  4382. odt_object:
  4383. rttiList.concat(Tai_const.Create_8bit(tkobject));
  4384. odt_interfacecom:
  4385. rttiList.concat(Tai_const.Create_8bit(tkinterface));
  4386. odt_interfacecorba:
  4387. rttiList.concat(Tai_const.Create_8bit(tkinterfaceCorba));
  4388. else
  4389. exit;
  4390. end;
  4391. { generate the name }
  4392. rttiList.concat(Tai_const.Create_8bit(length(objrealname^)));
  4393. rttiList.concat(Tai_string.Create(objrealname^));
  4394. case rt of
  4395. initrtti :
  4396. begin
  4397. rttiList.concat(Tai_const.Create_32bit(size));
  4398. if objecttype in [odt_class,odt_object] then
  4399. begin
  4400. count:=0;
  4401. FRTTIType:=rt;
  4402. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_field_rtti,nil);
  4403. rttiList.concat(Tai_const.Create_32bit(count));
  4404. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}write_field_rtti,nil);
  4405. end;
  4406. end;
  4407. fullrtti :
  4408. begin
  4409. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4410. rttiList.concat(Tai_const.Create_32bit(0))
  4411. else
  4412. rttiList.concat(Tai_const_symbol.Createname(vmt_mangledname));
  4413. { write owner typeinfo }
  4414. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4415. rttiList.concat(Tai_const_symbol.Create(childof.get_rtti_label(fullrtti)))
  4416. else
  4417. rttiList.concat(Tai_const.Create_32bit(0));
  4418. { count total number of properties }
  4419. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4420. count:=childof.next_free_name_index
  4421. else
  4422. count:=0;
  4423. { write it }
  4424. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  4425. rttiList.concat(Tai_const.Create_16bit(count));
  4426. { write unit name }
  4427. rttiList.concat(Tai_const.Create_8bit(length(current_module.realmodulename^)));
  4428. rttiList.concat(Tai_string.Create(current_module.realmodulename^));
  4429. { write published properties count }
  4430. count:=0;
  4431. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  4432. rttiList.concat(Tai_const.Create_16bit(count));
  4433. { count is used to write nameindex }
  4434. { but we need an offset of the owner }
  4435. { to give each property an own slot }
  4436. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4437. count:=childof.next_free_name_index
  4438. else
  4439. count:=0;
  4440. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}write_property_info,nil);
  4441. end;
  4442. end;
  4443. end;
  4444. function tobjectdef.is_publishable : boolean;
  4445. begin
  4446. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba];
  4447. end;
  4448. {****************************************************************************
  4449. TIMPLEMENTEDINTERFACES
  4450. ****************************************************************************}
  4451. type
  4452. tnamemap = class(TNamedIndexItem)
  4453. newname: pstring;
  4454. constructor create(const aname, anewname: string);
  4455. destructor destroy; override;
  4456. end;
  4457. constructor tnamemap.create(const aname, anewname: string);
  4458. begin
  4459. inherited createname(name);
  4460. newname:=stringdup(anewname);
  4461. end;
  4462. destructor tnamemap.destroy;
  4463. begin
  4464. stringdispose(newname);
  4465. inherited destroy;
  4466. end;
  4467. type
  4468. tprocdefstore = class(TNamedIndexItem)
  4469. procdef: tprocdef;
  4470. constructor create(aprocdef: tprocdef);
  4471. end;
  4472. constructor tprocdefstore.create(aprocdef: tprocdef);
  4473. begin
  4474. inherited create;
  4475. procdef:=aprocdef;
  4476. end;
  4477. type
  4478. timplintfentry = class(TNamedIndexItem)
  4479. intf: tobjectdef;
  4480. ioffs: longint;
  4481. namemappings: tdictionary;
  4482. procdefs: TIndexArray;
  4483. constructor create(aintf: tobjectdef);
  4484. destructor destroy; override;
  4485. end;
  4486. constructor timplintfentry.create(aintf: tobjectdef);
  4487. begin
  4488. inherited create;
  4489. intf:=aintf;
  4490. ioffs:=-1;
  4491. namemappings:=nil;
  4492. procdefs:=nil;
  4493. end;
  4494. destructor timplintfentry.destroy;
  4495. begin
  4496. if assigned(namemappings) then
  4497. namemappings.free;
  4498. if assigned(procdefs) then
  4499. procdefs.free;
  4500. inherited destroy;
  4501. end;
  4502. constructor timplementedinterfaces.create;
  4503. begin
  4504. finterfaces:=tindexarray.create(1);
  4505. end;
  4506. destructor timplementedinterfaces.destroy;
  4507. begin
  4508. finterfaces.destroy;
  4509. end;
  4510. function timplementedinterfaces.count: longint;
  4511. begin
  4512. count:=finterfaces.count;
  4513. end;
  4514. procedure timplementedinterfaces.checkindex(intfindex: longint);
  4515. begin
  4516. if (intfindex<1) or (intfindex>count) then
  4517. InternalError(200006123);
  4518. end;
  4519. function timplementedinterfaces.interfaces(intfindex: longint): tobjectdef;
  4520. begin
  4521. checkindex(intfindex);
  4522. interfaces:=timplintfentry(finterfaces.search(intfindex)).intf;
  4523. end;
  4524. function timplementedinterfaces.ioffsets(intfindex: longint): plongint;
  4525. begin
  4526. checkindex(intfindex);
  4527. ioffsets:=@timplintfentry(finterfaces.search(intfindex)).ioffs;
  4528. end;
  4529. function timplementedinterfaces.searchintf(def: tdef): longint;
  4530. var
  4531. i: longint;
  4532. begin
  4533. i:=1;
  4534. while (i<=count) and (tdef(interfaces(i))<>def) do inc(i);
  4535. if i<=count then
  4536. searchintf:=i
  4537. else
  4538. searchintf:=-1;
  4539. end;
  4540. procedure timplementedinterfaces.deref;
  4541. var
  4542. i: longint;
  4543. begin
  4544. for i:=1 to count do
  4545. with timplintfentry(finterfaces.search(i)) do
  4546. resolvedef(pointer(intf));
  4547. end;
  4548. procedure timplementedinterfaces.addintfref(def: pointer);
  4549. begin
  4550. finterfaces.insert(timplintfentry.create(tobjectdef(def)));
  4551. end;
  4552. procedure timplementedinterfaces.addintf(def: tdef);
  4553. begin
  4554. if not assigned(def) or (searchintf(def)<>-1) or (def.deftype<>objectdef) or
  4555. not (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4556. internalerror(200006124);
  4557. finterfaces.insert(timplintfentry.create(tobjectdef(def)));
  4558. end;
  4559. procedure timplementedinterfaces.clearmappings;
  4560. var
  4561. i: longint;
  4562. begin
  4563. for i:=1 to count do
  4564. with timplintfentry(finterfaces.search(i)) do
  4565. begin
  4566. if assigned(namemappings) then
  4567. namemappings.free;
  4568. namemappings:=nil;
  4569. end;
  4570. end;
  4571. procedure timplementedinterfaces.addmappings(intfindex: longint; const name, newname: string);
  4572. begin
  4573. checkindex(intfindex);
  4574. with timplintfentry(finterfaces.search(intfindex)) do
  4575. begin
  4576. if not assigned(namemappings) then
  4577. namemappings:=tdictionary.create;
  4578. namemappings.insert(tnamemap.create(name,newname));
  4579. end;
  4580. end;
  4581. function timplementedinterfaces.getmappings(intfindex: longint; const name: string; var nextexist: pointer): string;
  4582. begin
  4583. checkindex(intfindex);
  4584. if not assigned(nextexist) then
  4585. with timplintfentry(finterfaces.search(intfindex)) do
  4586. begin
  4587. if assigned(namemappings) then
  4588. nextexist:=namemappings.search(name)
  4589. else
  4590. nextexist:=nil;
  4591. end;
  4592. if assigned(nextexist) then
  4593. begin
  4594. getmappings:=tnamemap(nextexist).newname^;
  4595. nextexist:=tnamemap(nextexist).listnext;
  4596. end
  4597. else
  4598. getmappings:='';
  4599. end;
  4600. procedure timplementedinterfaces.clearimplprocs;
  4601. var
  4602. i: longint;
  4603. begin
  4604. for i:=1 to count do
  4605. with timplintfentry(finterfaces.search(i)) do
  4606. begin
  4607. if assigned(procdefs) then
  4608. procdefs.free;
  4609. procdefs:=nil;
  4610. end;
  4611. end;
  4612. procedure timplementedinterfaces.addimplproc(intfindex: longint; procdef: tprocdef);
  4613. begin
  4614. checkindex(intfindex);
  4615. with timplintfentry(finterfaces.search(intfindex)) do
  4616. begin
  4617. if not assigned(procdefs) then
  4618. procdefs:=tindexarray.create(4);
  4619. procdefs.insert(tprocdefstore.create(procdef));
  4620. end;
  4621. end;
  4622. function timplementedinterfaces.implproccount(intfindex: longint): longint;
  4623. begin
  4624. checkindex(intfindex);
  4625. with timplintfentry(finterfaces.search(intfindex)) do
  4626. if assigned(procdefs) then
  4627. implproccount:=procdefs.count
  4628. else
  4629. implproccount:=0;
  4630. end;
  4631. function timplementedinterfaces.implprocs(intfindex: longint; procindex: longint): tprocdef;
  4632. begin
  4633. checkindex(intfindex);
  4634. with timplintfentry(finterfaces.search(intfindex)) do
  4635. if assigned(procdefs) then
  4636. implprocs:=tprocdefstore(procdefs.search(procindex)).procdef
  4637. else
  4638. internalerror(200006131);
  4639. end;
  4640. function timplementedinterfaces.isimplmergepossible(intfindex, remainindex: longint; var weight: longint): boolean;
  4641. var
  4642. possible: boolean;
  4643. i: longint;
  4644. iiep1: TIndexArray;
  4645. iiep2: TIndexArray;
  4646. begin
  4647. checkindex(intfindex);
  4648. checkindex(remainindex);
  4649. iiep1:=timplintfentry(finterfaces.search(intfindex)).procdefs;
  4650. iiep2:=timplintfentry(finterfaces.search(remainindex)).procdefs;
  4651. if not assigned(iiep1) then { empty interface is mergeable :-) }
  4652. begin
  4653. possible:=true;
  4654. weight:=0;
  4655. end
  4656. else
  4657. begin
  4658. possible:=assigned(iiep2) and (iiep1.count<=iiep2.count);
  4659. i:=1;
  4660. while (possible) and (i<=iiep1.count) do
  4661. begin
  4662. possible:=
  4663. (tprocdefstore(iiep1.search(i)).procdef=tprocdefstore(iiep2.search(i)).procdef);
  4664. inc(i);
  4665. end;
  4666. if possible then
  4667. weight:=iiep1.count;
  4668. end;
  4669. isimplmergepossible:=possible;
  4670. end;
  4671. {****************************************************************************
  4672. TFORWARDDEF
  4673. ****************************************************************************}
  4674. constructor tforwarddef.create(const s:string;const pos : tfileposinfo);
  4675. var
  4676. oldregisterdef : boolean;
  4677. begin
  4678. { never register the forwarddefs, they are disposed at the
  4679. end of the type declaration block }
  4680. oldregisterdef:=registerdef;
  4681. registerdef:=false;
  4682. inherited create;
  4683. registerdef:=oldregisterdef;
  4684. deftype:=forwarddef;
  4685. tosymname:=s;
  4686. forwardpos:=pos;
  4687. end;
  4688. function tforwarddef.gettypename:string;
  4689. begin
  4690. gettypename:='unresolved forward to '+tosymname;
  4691. end;
  4692. {****************************************************************************
  4693. TERRORDEF
  4694. ****************************************************************************}
  4695. constructor terrordef.create;
  4696. begin
  4697. inherited create;
  4698. deftype:=errordef;
  4699. end;
  4700. {$ifdef GDB}
  4701. function terrordef.stabstring : pchar;
  4702. begin
  4703. stabstring:=strpnew('error'+numberstring);
  4704. end;
  4705. {$endif GDB}
  4706. function terrordef.gettypename:string;
  4707. begin
  4708. gettypename:='<erroneous type>';
  4709. end;
  4710. function terrordef.getmangledparaname:string;
  4711. begin
  4712. getmangledparaname:='error';
  4713. end;
  4714. {****************************************************************************
  4715. GDB Helpers
  4716. ****************************************************************************}
  4717. {$ifdef GDB}
  4718. function typeglobalnumber(const s : string) : string;
  4719. var st : string;
  4720. symt : tsymtable;
  4721. srsym : tsym;
  4722. srsymtable : tsymtable;
  4723. old_make_ref : boolean;
  4724. begin
  4725. old_make_ref:=make_ref;
  4726. make_ref:=false;
  4727. typeglobalnumber := '0';
  4728. srsym := nil;
  4729. if pos('.',s) > 0 then
  4730. begin
  4731. st := copy(s,1,pos('.',s)-1);
  4732. searchsym(st,srsym,srsymtable);
  4733. st := copy(s,pos('.',s)+1,255);
  4734. if assigned(srsym) then
  4735. begin
  4736. if srsym.typ = unitsym then
  4737. begin
  4738. symt := tunitsym(srsym).unitsymtable;
  4739. srsym := tsym(symt.search(st));
  4740. end else srsym := nil;
  4741. end;
  4742. end else st := s;
  4743. if srsym = nil then
  4744. searchsym(st,srsym,srsymtable);
  4745. if (srsym=nil) or
  4746. (srsym.typ<>typesym) then
  4747. begin
  4748. Message(type_e_type_id_expected);
  4749. exit;
  4750. end;
  4751. typeglobalnumber := tstoreddef(ttypesym(srsym).restype.def).numberstring;
  4752. make_ref:=old_make_ref;
  4753. end;
  4754. {$endif GDB}
  4755. {****************************************************************************
  4756. Definition Helpers
  4757. ****************************************************************************}
  4758. procedure reset_global_defs;
  4759. var
  4760. def : tstoreddef;
  4761. {$ifdef debug}
  4762. prevdef : tstoreddef;
  4763. {$endif debug}
  4764. begin
  4765. {$ifdef debug}
  4766. prevdef:=nil;
  4767. {$endif debug}
  4768. {$ifdef GDB}
  4769. pglobaltypecount:=@globaltypecount;
  4770. {$endif GDB}
  4771. def:=firstglobaldef;
  4772. while assigned(def) do
  4773. begin
  4774. {$ifdef GDB}
  4775. if assigned(def.typesym) then
  4776. ttypesym(def.typesym).isusedinstab:=false;
  4777. def.is_def_stab_written:=not_written;
  4778. {$endif GDB}
  4779. { reset rangenr's }
  4780. case def.deftype of
  4781. orddef : torddef(def).rangenr:=0;
  4782. enumdef : tenumdef(def).rangenr:=0;
  4783. arraydef : tarraydef(def).rangenr:=0;
  4784. end;
  4785. if assigned(def.rttitablesym) then
  4786. trttisym(def.rttitablesym).lab := nil;
  4787. if assigned(def.inittablesym) then
  4788. trttisym(def.inittablesym).lab := nil;
  4789. def.localrttilab[initrtti]:=nil;
  4790. def.localrttilab[fullrtti]:=nil;
  4791. {$ifdef debug}
  4792. prevdef:=def;
  4793. {$endif debug}
  4794. def:=def.nextglobal;
  4795. end;
  4796. end;
  4797. function is_interfacecom(def: tdef): boolean;
  4798. begin
  4799. is_interfacecom:=
  4800. assigned(def) and
  4801. (def.deftype=objectdef) and
  4802. (tobjectdef(def).objecttype=odt_interfacecom);
  4803. end;
  4804. function is_interfacecorba(def: tdef): boolean;
  4805. begin
  4806. is_interfacecorba:=
  4807. assigned(def) and
  4808. (def.deftype=objectdef) and
  4809. (tobjectdef(def).objecttype=odt_interfacecorba);
  4810. end;
  4811. function is_interface(def: tdef): boolean;
  4812. begin
  4813. is_interface:=
  4814. assigned(def) and
  4815. (def.deftype=objectdef) and
  4816. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  4817. end;
  4818. function is_class(def: tdef): boolean;
  4819. begin
  4820. is_class:=
  4821. assigned(def) and
  4822. (def.deftype=objectdef) and
  4823. (tobjectdef(def).objecttype=odt_class);
  4824. end;
  4825. function is_object(def: tdef): boolean;
  4826. begin
  4827. is_object:=
  4828. assigned(def) and
  4829. (def.deftype=objectdef) and
  4830. (tobjectdef(def).objecttype=odt_object);
  4831. end;
  4832. function is_cppclass(def: tdef): boolean;
  4833. begin
  4834. is_cppclass:=
  4835. assigned(def) and
  4836. (def.deftype=objectdef) and
  4837. (tobjectdef(def).objecttype=odt_cppclass);
  4838. end;
  4839. function is_class_or_interface(def: tdef): boolean;
  4840. begin
  4841. is_class_or_interface:=
  4842. assigned(def) and
  4843. (def.deftype=objectdef) and
  4844. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  4845. end;
  4846. end.
  4847. {
  4848. $Log$
  4849. Revision 1.104 2002-11-16 19:53:18 carl
  4850. * avoid Range check errors
  4851. Revision 1.103 2002/11/15 16:29:09 peter
  4852. * fixed rtti for int64 (merged)
  4853. Revision 1.102 2002/11/15 01:58:54 peter
  4854. * merged changes from 1.0.7 up to 04-11
  4855. - -V option for generating bug report tracing
  4856. - more tracing for option parsing
  4857. - errors for cdecl and high()
  4858. - win32 import stabs
  4859. - win32 records<=8 are returned in eax:edx (turned off by default)
  4860. - heaptrc update
  4861. - more info for temp management in .s file with EXTDEBUG
  4862. Revision 1.101 2002/11/09 15:31:02 carl
  4863. + align RTTI tables
  4864. Revision 1.100 2002/10/19 15:09:25 peter
  4865. + tobjectdef.members_need_inittable that is used to generate only the
  4866. inittable when it is really used. This saves a lot of useless calls
  4867. to fpc_finalize when destroying classes
  4868. Revision 1.99 2002/10/07 21:30:27 peter
  4869. * removed obsolete rangecheck stuff
  4870. Revision 1.98 2002/10/05 15:14:26 peter
  4871. * getparamangeldname for errordef
  4872. Revision 1.97 2002/10/05 12:43:28 carl
  4873. * fixes for Delphi 6 compilation
  4874. (warning : Some features do not work under Delphi)
  4875. Revision 1.96 2002/09/27 21:13:29 carl
  4876. * low-highval always checked if limit ober 2GB is reached (to avoid overflow)
  4877. Revision 1.95 2002/09/16 09:31:10 florian
  4878. * fixed currency size
  4879. Revision 1.94 2002/09/09 17:34:15 peter
  4880. * tdicationary.replace added to replace and item in a dictionary. This
  4881. is only allowed for the same name
  4882. * varsyms are inserted in symtable before the types are parsed. This
  4883. fixes the long standing "var longint : longint" bug
  4884. - consume_idlist and idstringlist removed. The loops are inserted
  4885. at the callers place and uses the symtable for duplicate id checking
  4886. Revision 1.93 2002/09/07 15:25:07 peter
  4887. * old logs removed and tabs fixed
  4888. Revision 1.92 2002/09/05 19:29:42 peter
  4889. * memdebug enhancements
  4890. Revision 1.91 2002/08/25 19:25:20 peter
  4891. * sym.insert_in_data removed
  4892. * symtable.insertvardata/insertconstdata added
  4893. * removed insert_in_data call from symtable.insert, it needs to be
  4894. called separatly. This allows to deref the address calculation
  4895. * procedures now calculate the parast addresses after the procedure
  4896. directives are parsed. This fixes the cdecl parast problem
  4897. * push_addr_param has an extra argument that specifies if cdecl is used
  4898. or not
  4899. Revision 1.90 2002/08/18 20:06:25 peter
  4900. * inlining is now also allowed in interface
  4901. * renamed write/load to ppuwrite/ppuload
  4902. * tnode storing in ppu
  4903. * nld,ncon,nbas are already updated for storing in ppu
  4904. Revision 1.89 2002/08/11 15:28:00 florian
  4905. + support of explicit type case <any ordinal type>->pointer
  4906. (delphi mode only)
  4907. Revision 1.88 2002/08/11 14:32:28 peter
  4908. * renamed current_library to objectlibrary
  4909. Revision 1.87 2002/08/11 13:24:13 peter
  4910. * saving of asmsymbols in ppu supported
  4911. * asmsymbollist global is removed and moved into a new class
  4912. tasmlibrarydata that will hold the info of a .a file which
  4913. corresponds with a single module. Added librarydata to tmodule
  4914. to keep the library info stored for the module. In the future the
  4915. objectfiles will also be stored to the tasmlibrarydata class
  4916. * all getlabel/newasmsymbol and friends are moved to the new class
  4917. Revision 1.86 2002/08/09 07:33:03 florian
  4918. * a couple of interface related fixes
  4919. Revision 1.85 2002/07/23 09:51:24 daniel
  4920. * Tried to make Tprocsym.defs protected. I didn't succeed but the cleanups
  4921. are worth comitting.
  4922. Revision 1.84 2002/07/20 11:57:57 florian
  4923. * types.pas renamed to defbase.pas because D6 contains a types
  4924. unit so this would conflicts if D6 programms are compiled
  4925. + Willamette/SSE2 instructions to assembler added
  4926. Revision 1.83 2002/07/11 14:41:30 florian
  4927. * start of the new generic parameter handling
  4928. Revision 1.82 2002/07/07 09:52:32 florian
  4929. * powerpc target fixed, very simple units can be compiled
  4930. * some basic stuff for better callparanode handling, far from being finished
  4931. Revision 1.81 2002/07/01 18:46:26 peter
  4932. * internal linker
  4933. * reorganized aasm layer
  4934. Revision 1.80 2002/07/01 16:23:54 peter
  4935. * cg64 patch
  4936. * basics for currency
  4937. * asnode updates for class and interface (not finished)
  4938. Revision 1.79 2002/05/18 13:34:18 peter
  4939. * readded missing revisions
  4940. Revision 1.78 2002/05/16 19:46:44 carl
  4941. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  4942. + try to fix temp allocation (still in ifdef)
  4943. + generic constructor calls
  4944. + start of tassembler / tmodulebase class cleanup
  4945. Revision 1.76 2002/05/12 16:53:10 peter
  4946. * moved entry and exitcode to ncgutil and cgobj
  4947. * foreach gets extra argument for passing local data to the
  4948. iterator function
  4949. * -CR checks also class typecasts at runtime by changing them
  4950. into as
  4951. * fixed compiler to cycle with the -CR option
  4952. * fixed stabs with elf writer, finally the global variables can
  4953. be watched
  4954. * removed a lot of routines from cga unit and replaced them by
  4955. calls to cgobj
  4956. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  4957. u32bit then the other is typecasted also to u32bit without giving
  4958. a rangecheck warning/error.
  4959. * fixed pascal calling method with reversing also the high tree in
  4960. the parast, detected by tcalcst3 test
  4961. Revision 1.75 2002/04/25 20:16:39 peter
  4962. * moved more routines from cga/n386util
  4963. Revision 1.74 2002/04/23 19:16:35 peter
  4964. * add pinline unit that inserts compiler supported functions using
  4965. one or more statements
  4966. * moved finalize and setlength from ninl to pinline
  4967. Revision 1.73 2002/04/21 19:02:05 peter
  4968. * removed newn and disposen nodes, the code is now directly
  4969. inlined from pexpr
  4970. * -an option that will write the secondpass nodes to the .s file, this
  4971. requires EXTDEBUG define to actually write the info
  4972. * fixed various internal errors and crashes due recent code changes
  4973. Revision 1.72 2002/04/20 21:32:25 carl
  4974. + generic FPC_CHECKPOINTER
  4975. + first parameter offset in stack now portable
  4976. * rename some constants
  4977. + move some cpu stuff to other units
  4978. - remove unused constents
  4979. * fix stacksize for some targets
  4980. * fix generic size problems which depend now on EXTEND_SIZE constant
  4981. }