symdef.pas 174 KB

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