symdef.pas 176 KB

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