symdef.pas 173 KB

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