symdef.pas 174 KB

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