symdef.pas 171 KB

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