symdef.pas 174 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702
  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 in [uchar..bool8bit,u64bit,s64bit,uwidechar];
  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. if (oo_is_forward in objectoptions) then
  3638. Message1(sym_e_class_forward_not_resolved,objname^);
  3639. stringdispose(objname);
  3640. stringdispose(iidstr);
  3641. if assigned(implementedinterfaces) then
  3642. implementedinterfaces.free;
  3643. inherited destroy;
  3644. end;
  3645. procedure tobjectdef.write(ppufile:tcompilerppufile);
  3646. var
  3647. oldread_member : boolean;
  3648. implintfcount : longint;
  3649. i : longint;
  3650. begin
  3651. inherited writedef(ppufile);
  3652. ppufile.putbyte(byte(objecttype));
  3653. ppufile.putlongint(size);
  3654. ppufile.putlongint(vmt_offset);
  3655. ppufile.putstring(objname^);
  3656. ppufile.putderef(childof);
  3657. ppufile.putsmallset(objectoptions);
  3658. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  3659. begin
  3660. ppufile.putbyte(byte(isiidguidvalid));
  3661. ppufile.putguid(iidguid);
  3662. ppufile.putstring(iidstr^);
  3663. ppufile.putlongint(lastvtableindex);
  3664. end;
  3665. if objecttype in [odt_class,odt_interfacecorba] then
  3666. begin
  3667. implintfcount:=implementedinterfaces.count;
  3668. ppufile.putlongint(implintfcount);
  3669. for i:=1 to implintfcount do
  3670. begin
  3671. ppufile.putderef(implementedinterfaces.interfaces(i));
  3672. ppufile.putlongint(implementedinterfaces.ioffsets(i)^);
  3673. end;
  3674. end;
  3675. ppufile.writeentry(ibobjectdef);
  3676. oldread_member:=read_member;
  3677. read_member:=true;
  3678. tobjectsymtable(symtable).write(ppufile);
  3679. read_member:=oldread_member;
  3680. end;
  3681. procedure tobjectdef.deref;
  3682. var
  3683. oldrecsyms : tsymtable;
  3684. begin
  3685. inherited deref;
  3686. resolvedef(tdef(childof));
  3687. oldrecsyms:=aktrecordsymtable;
  3688. aktrecordsymtable:=symtable;
  3689. tstoredsymtable(symtable).deref;
  3690. aktrecordsymtable:=oldrecsyms;
  3691. if objecttype in [odt_class,odt_interfacecorba] then
  3692. implementedinterfaces.deref;
  3693. end;
  3694. procedure tobjectdef.set_parent( c : tobjectdef);
  3695. begin
  3696. { nothing to do if the parent was not forward !}
  3697. if assigned(childof) then
  3698. exit;
  3699. childof:=c;
  3700. { some options are inherited !! }
  3701. if assigned(c) then
  3702. begin
  3703. { only important for classes }
  3704. lastvtableindex:=c.lastvtableindex;
  3705. objectoptions:=objectoptions+(c.objectoptions*
  3706. [oo_has_virtual,oo_has_private,oo_has_protected,
  3707. oo_has_constructor,oo_has_destructor]);
  3708. if not (objecttype in [odt_interfacecom,odt_interfacecorba]) then
  3709. begin
  3710. { add the data of the anchestor class }
  3711. inc(symtable.datasize,c.symtable.datasize);
  3712. if (oo_has_vmt in objectoptions) and
  3713. (oo_has_vmt in c.objectoptions) then
  3714. dec(symtable.datasize,target_info.size_of_pointer);
  3715. { if parent has a vmt field then
  3716. the offset is the same for the child PM }
  3717. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  3718. begin
  3719. vmt_offset:=c.vmt_offset;
  3720. include(objectoptions,oo_has_vmt);
  3721. end;
  3722. end;
  3723. end;
  3724. savesize := symtable.datasize;
  3725. end;
  3726. procedure tobjectdef.insertvmt;
  3727. begin
  3728. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  3729. exit;
  3730. if (oo_has_vmt in objectoptions) then
  3731. internalerror(12345)
  3732. else
  3733. begin
  3734. symtable.datasize:=align(symtable.datasize,symtable.dataalignment);
  3735. vmt_offset:=symtable.datasize;
  3736. inc(symtable.datasize,target_info.size_of_pointer);
  3737. include(objectoptions,oo_has_vmt);
  3738. end;
  3739. end;
  3740. procedure tobjectdef.check_forwards;
  3741. begin
  3742. if not(objecttype in [odt_interfacecom,odt_interfacecorba]) then
  3743. tstoredsymtable(symtable).check_forwards;
  3744. if (oo_is_forward in objectoptions) then
  3745. begin
  3746. { ok, in future, the forward can be resolved }
  3747. Message1(sym_e_class_forward_not_resolved,objname^);
  3748. exclude(objectoptions,oo_is_forward);
  3749. end;
  3750. end;
  3751. { true, if self inherits from d (or if they are equal) }
  3752. function tobjectdef.is_related(d : tobjectdef) : boolean;
  3753. var
  3754. hp : tobjectdef;
  3755. begin
  3756. hp:=self;
  3757. while assigned(hp) do
  3758. begin
  3759. if hp=d then
  3760. begin
  3761. is_related:=true;
  3762. exit;
  3763. end;
  3764. hp:=hp.childof;
  3765. end;
  3766. is_related:=false;
  3767. end;
  3768. procedure tobjectdef._searchdestructor(sym : tnamedindexitem);
  3769. var
  3770. p : pprocdeflist;
  3771. begin
  3772. { if we found already a destructor, then we exit }
  3773. if assigned(sd) then
  3774. exit;
  3775. if tsym(sym).typ=procsym then
  3776. begin
  3777. p:=tprocsym(sym).defs;
  3778. while assigned(p) do
  3779. begin
  3780. if p^.def.proctypeoption=potype_destructor then
  3781. begin
  3782. sd:=p^.def;
  3783. exit;
  3784. end;
  3785. p:=p^.next;
  3786. end;
  3787. end;
  3788. end;
  3789. function tobjectdef.searchdestructor : tprocdef;
  3790. var
  3791. o : tobjectdef;
  3792. begin
  3793. searchdestructor:=nil;
  3794. o:=self;
  3795. sd:=nil;
  3796. while assigned(o) do
  3797. begin
  3798. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}_searchdestructor);
  3799. if assigned(sd) then
  3800. begin
  3801. searchdestructor:=sd;
  3802. exit;
  3803. end;
  3804. o:=o.childof;
  3805. end;
  3806. end;
  3807. function tobjectdef.size : longint;
  3808. begin
  3809. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba] then
  3810. size:=target_info.size_of_pointer
  3811. else
  3812. size:=symtable.datasize;
  3813. end;
  3814. function tobjectdef.alignment:longint;
  3815. begin
  3816. alignment:=symtable.dataalignment;
  3817. end;
  3818. function tobjectdef.vmtmethodoffset(index:longint):longint;
  3819. begin
  3820. { for offset of methods for classes, see rtl/inc/objpash.inc }
  3821. case objecttype of
  3822. odt_class:
  3823. vmtmethodoffset:=(index+12)*target_info.size_of_pointer;
  3824. odt_interfacecom,odt_interfacecorba:
  3825. vmtmethodoffset:=index*target_info.size_of_pointer;
  3826. else
  3827. {$ifdef WITHDMT}
  3828. vmtmethodoffset:=(index+4)*target_info.size_of_pointer;
  3829. {$else WITHDMT}
  3830. vmtmethodoffset:=(index+3)*target_info.size_of_pointer;
  3831. {$endif WITHDMT}
  3832. end;
  3833. end;
  3834. function tobjectdef.vmt_mangledname : string;
  3835. {DM: I get a nil pointer on the owner name. I don't know if this
  3836. may happen, and I have therefore fixed the problem by doing nil pointer
  3837. checks.}
  3838. var
  3839. s1,s2:string;
  3840. begin
  3841. if not(oo_has_vmt in objectoptions) then
  3842. Message1(parser_object_has_no_vmt,objname^);
  3843. if owner.name=nil then
  3844. s1:=''
  3845. else
  3846. s1:=upper(owner.name^);
  3847. if objname=nil then
  3848. s2:=''
  3849. else
  3850. s2:=Upper(objname^);
  3851. vmt_mangledname:='VMT_'+s1+'$_'+s2;
  3852. end;
  3853. function tobjectdef.rtti_name : string;
  3854. var
  3855. s1,s2:string;
  3856. begin
  3857. if owner.name=nil then
  3858. s1:=''
  3859. else
  3860. s1:=upper(owner.name^);
  3861. if objname=nil then
  3862. s2:=''
  3863. else
  3864. s2:=Upper(objname^);
  3865. rtti_name:='RTTI_'+s1+'$_'+s2;
  3866. end;
  3867. {$ifdef GDB}
  3868. procedure tobjectdef.addprocname(p :tnamedindexitem);
  3869. var virtualind,argnames : string;
  3870. news, newrec : pchar;
  3871. pd,ipd : tprocdef;
  3872. lindex : longint;
  3873. para : TParaItem;
  3874. arglength : byte;
  3875. sp : char;
  3876. pdl : pprocdeflist;
  3877. begin
  3878. If tsym(p).typ = procsym then
  3879. begin
  3880. pd := tprocsym(p).defs^.def;
  3881. { this will be used for full implementation of object stabs
  3882. not yet done }
  3883. pdl:=tprocsym(p).defs;
  3884. while assigned(pdl) do
  3885. begin
  3886. ipd:=pdl^.def;
  3887. pdl:=pdl^.next;
  3888. end;
  3889. if (po_virtualmethod in pd.procoptions) then
  3890. begin
  3891. lindex := pd.extnumber;
  3892. {doesnt seem to be necessary
  3893. lindex := lindex or $80000000;}
  3894. virtualind := '*'+tostr(lindex)+';'+ipd._class.classnumberstring+';'
  3895. end
  3896. else
  3897. virtualind := '.';
  3898. { used by gdbpas to recognize constructor and destructors }
  3899. if (pd.proctypeoption=potype_constructor) then
  3900. argnames:='__ct__'
  3901. else if (pd.proctypeoption=potype_destructor) then
  3902. argnames:='__dt__'
  3903. else
  3904. argnames := '';
  3905. { arguments are not listed here }
  3906. {we don't need another definition}
  3907. para := TParaItem(pd.Para.first);
  3908. while assigned(para) do
  3909. begin
  3910. if Para.paratype.def.deftype = formaldef then
  3911. begin
  3912. if Para.paratyp=vs_var then
  3913. argnames := argnames+'3var'
  3914. else if Para.paratyp=vs_const then
  3915. argnames:=argnames+'5const'
  3916. else if Para.paratyp=vs_out then
  3917. argnames:=argnames+'3out';
  3918. end
  3919. else
  3920. begin
  3921. { if the arg definition is like (v: ^byte;..
  3922. there is no sym attached to data !!! }
  3923. if assigned(Para.paratype.def.typesym) then
  3924. begin
  3925. arglength := length(Para.paratype.def.typesym.name);
  3926. argnames := argnames + tostr(arglength)+Para.paratype.def.typesym.name;
  3927. end
  3928. else
  3929. begin
  3930. argnames:=argnames+'11unnamedtype';
  3931. end;
  3932. end;
  3933. para := TParaItem(Para.next);
  3934. end;
  3935. ipd.is_def_stab_written := written;
  3936. { here 2A must be changed for private and protected }
  3937. { 0 is private 1 protected and 2 public }
  3938. if (sp_private in tsym(p).symoptions) then sp:='0'
  3939. else if (sp_protected in tsym(p).symoptions) then sp:='1'
  3940. else sp:='2';
  3941. newrec := strpnew(p.name+'::'+ipd.numberstring
  3942. +'=##'+tstoreddef(pd.rettype.def).numberstring+';:'+argnames+';'+sp+'A'
  3943. +virtualind+';');
  3944. { get spare place for a string at the end }
  3945. if strlen(StabRecString) + strlen(newrec) >= StabRecSize-256 then
  3946. begin
  3947. getmem(news,stabrecsize+memsizeinc);
  3948. strcopy(news,stabrecstring);
  3949. freemem(stabrecstring,stabrecsize);
  3950. stabrecsize:=stabrecsize+memsizeinc;
  3951. stabrecstring:=news;
  3952. end;
  3953. strcat(StabRecstring,newrec);
  3954. {freemem(newrec,memsizeinc); }
  3955. strdispose(newrec);
  3956. {This should be used for case !!
  3957. RecOffset := RecOffset + pd.size;}
  3958. end;
  3959. end;
  3960. function tobjectdef.stabstring : pchar;
  3961. var anc : tobjectdef;
  3962. oldrec : pchar;
  3963. oldrecsize,oldrecoffset : longint;
  3964. str_end : string;
  3965. begin
  3966. if not (objecttype=odt_class) or writing_class_record_stab then
  3967. begin
  3968. oldrec := stabrecstring;
  3969. oldrecsize:=stabrecsize;
  3970. stabrecsize:=memsizeinc;
  3971. GetMem(stabrecstring,stabrecsize);
  3972. strpcopy(stabRecString,'s'+tostr(symtable.datasize));
  3973. if assigned(childof) then
  3974. begin
  3975. {only one ancestor not virtual, public, at base offset 0 }
  3976. { !1 , 0 2 0 , }
  3977. strpcopy(strend(stabrecstring),'!1,020,'+childof.classnumberstring+';');
  3978. end;
  3979. {virtual table to implement yet}
  3980. OldRecOffset:=RecOffset;
  3981. RecOffset := 0;
  3982. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}addname);
  3983. RecOffset:=OldRecOffset;
  3984. if (oo_has_vmt in objectoptions) then
  3985. if not assigned(childof) or not(oo_has_vmt in childof.objectoptions) then
  3986. begin
  3987. strpcopy(strend(stabrecstring),'$vf'+classnumberstring+':'+typeglobalnumber('vtblarray')
  3988. +','+tostr(vmt_offset*8)+';');
  3989. end;
  3990. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}addprocname);
  3991. if (oo_has_vmt in objectoptions) then
  3992. begin
  3993. anc := self;
  3994. while assigned(anc.childof) and (oo_has_vmt in anc.childof.objectoptions) do
  3995. anc := anc.childof;
  3996. { just in case anc = self }
  3997. str_end:=';~%'+anc.classnumberstring+';';
  3998. end
  3999. else
  4000. str_end:=';';
  4001. strpcopy(strend(stabrecstring),str_end);
  4002. stabstring := strnew(StabRecString);
  4003. freemem(stabrecstring,stabrecsize);
  4004. stabrecstring := oldrec;
  4005. stabrecsize:=oldrecsize;
  4006. end
  4007. else
  4008. begin
  4009. stabstring:=strpnew('*'+classnumberstring);
  4010. end;
  4011. end;
  4012. procedure tobjectdef.set_globalnb;
  4013. begin
  4014. globalnb:=PglobalTypeCount^;
  4015. inc(PglobalTypeCount^);
  4016. { classes need two type numbers, the globalnb is set to the ptr }
  4017. if objecttype=odt_class then
  4018. begin
  4019. globalnb:=PGlobalTypeCount^;
  4020. inc(PglobalTypeCount^);
  4021. end;
  4022. end;
  4023. function tobjectdef.classnumberstring : string;
  4024. begin
  4025. { write stabs again if needed }
  4026. numberstring;
  4027. if objecttype=odt_class then
  4028. begin
  4029. dec(globalnb);
  4030. classnumberstring:=numberstring;
  4031. inc(globalnb);
  4032. end
  4033. else
  4034. classnumberstring:=numberstring;
  4035. end;
  4036. function tobjectdef.allstabstring : pchar;
  4037. var stabchar : string[2];
  4038. ss,st : pchar;
  4039. sname : string;
  4040. sym_line_no : longint;
  4041. begin
  4042. ss := stabstring;
  4043. getmem(st,strlen(ss)+512);
  4044. stabchar := 't';
  4045. if deftype in tagtypes then
  4046. stabchar := 'Tt';
  4047. if assigned(typesym) then
  4048. begin
  4049. sname := typesym.name;
  4050. sym_line_no:=typesym.fileinfo.line;
  4051. end
  4052. else
  4053. begin
  4054. sname := ' ';
  4055. sym_line_no:=0;
  4056. end;
  4057. if writing_class_record_stab then
  4058. strpcopy(st,'"'+sname+':'+stabchar+classnumberstring+'=')
  4059. else
  4060. strpcopy(st,'"'+sname+':'+stabchar+numberstring+'=');
  4061. strpcopy(strecopy(strend(st),ss),'",'+tostr(N_LSYM)+',0,'+tostr(sym_line_no)+',0');
  4062. allstabstring := strnew(st);
  4063. freemem(st,strlen(ss)+512);
  4064. strdispose(ss);
  4065. end;
  4066. procedure tobjectdef.concatstabto(asmlist : taasmoutput);
  4067. var st : pstring;
  4068. begin
  4069. if objecttype<>odt_class then
  4070. begin
  4071. inherited concatstabto(asmlist);
  4072. exit;
  4073. end;
  4074. if ((typesym=nil) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches)) and
  4075. (is_def_stab_written = not_written) then
  4076. begin
  4077. if globalnb=0 then
  4078. set_globalnb;
  4079. { Write the record class itself }
  4080. writing_class_record_stab:=true;
  4081. inherited concatstabto(asmlist);
  4082. writing_class_record_stab:=false;
  4083. { Write the invisible pointer class }
  4084. is_def_stab_written:=not_written;
  4085. if assigned(typesym) then
  4086. begin
  4087. st:=typesym.FName;
  4088. typesym.FName:=stringdup(' ');
  4089. end;
  4090. inherited concatstabto(asmlist);
  4091. if assigned(typesym) then
  4092. begin
  4093. stringdispose(typesym.FName);
  4094. typesym.FName:=st;
  4095. end;
  4096. end;
  4097. end;
  4098. {$endif GDB}
  4099. function tobjectdef.needs_inittable : boolean;
  4100. begin
  4101. case objecttype of
  4102. odt_class :
  4103. needs_inittable:=false;
  4104. odt_interfacecom:
  4105. needs_inittable:=true;
  4106. odt_interfacecorba:
  4107. needs_inittable:=is_related(interface_iunknown);
  4108. odt_object:
  4109. needs_inittable:=tobjectsymtable(symtable).needs_init_final;
  4110. else
  4111. internalerror(200108267);
  4112. end;
  4113. end;
  4114. procedure tobjectdef.count_published_properties(sym:tnamedindexitem);
  4115. begin
  4116. if needs_prop_entry(tsym(sym)) and
  4117. (tsym(sym).typ<>varsym) then
  4118. inc(count);
  4119. end;
  4120. procedure tobjectdef.write_property_info(sym : tnamedindexitem);
  4121. var
  4122. proctypesinfo : byte;
  4123. procedure writeproc(proc : tsymlist; shiftvalue : byte);
  4124. var
  4125. typvalue : byte;
  4126. hp : psymlistitem;
  4127. address : longint;
  4128. begin
  4129. if not(assigned(proc) and assigned(proc.firstsym)) then
  4130. begin
  4131. rttiList.concat(Tai_const.Create_32bit(1));
  4132. typvalue:=3;
  4133. end
  4134. else if proc.firstsym^.sym.typ=varsym then
  4135. begin
  4136. address:=0;
  4137. hp:=proc.firstsym;
  4138. while assigned(hp) do
  4139. begin
  4140. inc(address,tvarsym(hp^.sym).address);
  4141. hp:=hp^.next;
  4142. end;
  4143. rttiList.concat(Tai_const.Create_32bit(address));
  4144. typvalue:=0;
  4145. end
  4146. else
  4147. begin
  4148. if not(po_virtualmethod in tprocdef(proc.def).procoptions) then
  4149. begin
  4150. rttiList.concat(Tai_const_symbol.Createname(tprocdef(proc.def).mangledname));
  4151. typvalue:=1;
  4152. end
  4153. else
  4154. begin
  4155. { virtual method, write vmt offset }
  4156. rttiList.concat(Tai_const.Create_32bit(
  4157. tprocdef(proc.def)._class.vmtmethodoffset(tprocdef(proc.def).extnumber)));
  4158. typvalue:=2;
  4159. end;
  4160. end;
  4161. proctypesinfo:=proctypesinfo or (typvalue shl shiftvalue);
  4162. end;
  4163. begin
  4164. if needs_prop_entry(tsym(sym)) then
  4165. case tsym(sym).typ of
  4166. varsym:
  4167. begin
  4168. {$ifdef dummy}
  4169. if not(tvarsym(sym).vartype.def.deftype=objectdef) or
  4170. not(tobjectdef(tvarsym(sym).vartype.def).is_class) then
  4171. internalerror(1509992);
  4172. { access to implicit class property as field }
  4173. proctypesinfo:=(0 shl 0) or (0 shl 2) or (0 shl 4);
  4174. rttiList.concat(Tai_const_symbol.Createname(tvarsym(sym.vartype.def.get_rtti_label)));
  4175. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym.address)));
  4176. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym.address)));
  4177. { per default stored }
  4178. rttiList.concat(Tai_const.Create_32bit(1));
  4179. { index as well as ... }
  4180. rttiList.concat(Tai_const.Create_32bit(0));
  4181. { default value are zero }
  4182. rttiList.concat(Tai_const.Create_32bit(0));
  4183. rttiList.concat(Tai_const.Create_16bit(count));
  4184. inc(count);
  4185. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  4186. rttiList.concat(Tai_const.Create_8bit(length(tvarsym(sym.realname))));
  4187. rttiList.concat(Tai_string.Create(tvarsym(sym.realname)));
  4188. {$endif dummy}
  4189. end;
  4190. propertysym:
  4191. begin
  4192. if ppo_indexed in tpropertysym(sym).propoptions then
  4193. proctypesinfo:=$40
  4194. else
  4195. proctypesinfo:=0;
  4196. rttiList.concat(Tai_const_symbol.Create(tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti)));
  4197. writeproc(tpropertysym(sym).readaccess,0);
  4198. writeproc(tpropertysym(sym).writeaccess,2);
  4199. { isn't it stored ? }
  4200. if not(ppo_stored in tpropertysym(sym).propoptions) then
  4201. begin
  4202. rttiList.concat(Tai_const.Create_32bit(0));
  4203. proctypesinfo:=proctypesinfo or (3 shl 4);
  4204. end
  4205. else
  4206. writeproc(tpropertysym(sym).storedaccess,4);
  4207. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).index));
  4208. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).default));
  4209. rttiList.concat(Tai_const.Create_16bit(count));
  4210. inc(count);
  4211. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  4212. rttiList.concat(Tai_const.Create_8bit(length(tpropertysym(sym).realname)));
  4213. rttiList.concat(Tai_string.Create(tpropertysym(sym).realname));
  4214. end;
  4215. else internalerror(1509992);
  4216. end;
  4217. end;
  4218. procedure tobjectdef.generate_published_child_rtti(sym : tnamedindexitem);
  4219. begin
  4220. if needs_prop_entry(tsym(sym)) then
  4221. begin
  4222. case tsym(sym).typ of
  4223. propertysym:
  4224. tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti);
  4225. varsym:
  4226. tstoreddef(tvarsym(sym).vartype.def).get_rtti_label(fullrtti);
  4227. else
  4228. internalerror(1509991);
  4229. end;
  4230. end;
  4231. end;
  4232. procedure tobjectdef.write_child_rtti_data(rt:trttitype);
  4233. begin
  4234. FRTTIType:=rt;
  4235. case rt of
  4236. initrtti :
  4237. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}generate_field_rtti);
  4238. fullrtti :
  4239. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}generate_published_child_rtti);
  4240. else
  4241. internalerror(200108301);
  4242. end;
  4243. end;
  4244. type
  4245. tclasslistitem = class(tlinkedlistitem)
  4246. index : longint;
  4247. p : tobjectdef;
  4248. end;
  4249. var
  4250. classtablelist : tlinkedlist;
  4251. tablecount : longint;
  4252. function searchclasstablelist(p : tobjectdef) : tclasslistitem;
  4253. var
  4254. hp : tclasslistitem;
  4255. begin
  4256. hp:=tclasslistitem(classtablelist.first);
  4257. while assigned(hp) do
  4258. if hp.p=p then
  4259. begin
  4260. searchclasstablelist:=hp;
  4261. exit;
  4262. end
  4263. else
  4264. hp:=tclasslistitem(hp.next);
  4265. searchclasstablelist:=nil;
  4266. end;
  4267. procedure tobjectdef.count_published_fields(sym:tnamedindexitem);
  4268. var
  4269. hp : tclasslistitem;
  4270. begin
  4271. if needs_prop_entry(tsym(sym)) and
  4272. (tsym(sym).typ=varsym) then
  4273. begin
  4274. if tvarsym(sym).vartype.def.deftype<>objectdef then
  4275. internalerror(0206001);
  4276. hp:=searchclasstablelist(tobjectdef(tvarsym(sym).vartype.def));
  4277. if not(assigned(hp)) then
  4278. begin
  4279. hp:=tclasslistitem.create;
  4280. hp.p:=tobjectdef(tvarsym(sym).vartype.def);
  4281. hp.index:=tablecount;
  4282. classtablelist.concat(hp);
  4283. inc(tablecount);
  4284. end;
  4285. inc(count);
  4286. end;
  4287. end;
  4288. procedure tobjectdef.writefields(sym:tnamedindexitem);
  4289. var
  4290. hp : tclasslistitem;
  4291. begin
  4292. if needs_prop_entry(tsym(sym)) and
  4293. (tsym(sym).typ=varsym) then
  4294. begin
  4295. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym).address));
  4296. hp:=searchclasstablelist(tobjectdef(tvarsym(sym).vartype.def));
  4297. if not(assigned(hp)) then
  4298. internalerror(0206002);
  4299. rttiList.concat(Tai_const.Create_16bit(hp.index));
  4300. rttiList.concat(Tai_const.Create_8bit(length(tvarsym(sym).realname)));
  4301. rttiList.concat(Tai_string.Create(tvarsym(sym).realname));
  4302. end;
  4303. end;
  4304. function tobjectdef.generate_field_table : tasmlabel;
  4305. var
  4306. fieldtable,
  4307. classtable : tasmlabel;
  4308. hp : tclasslistitem;
  4309. begin
  4310. classtablelist:=TLinkedList.Create;
  4311. getdatalabel(fieldtable);
  4312. getdatalabel(classtable);
  4313. count:=0;
  4314. tablecount:=0;
  4315. symtable.foreach({$ifdef FPC}@{$endif}count_published_fields);
  4316. if (cs_create_smart in aktmoduleswitches) then
  4317. rttiList.concat(Tai_cut.Create);
  4318. rttiList.concat(Tai_label.Create(fieldtable));
  4319. rttiList.concat(Tai_const.Create_16bit(count));
  4320. rttiList.concat(Tai_const_symbol.Create(classtable));
  4321. symtable.foreach({$ifdef FPC}@{$endif}writefields);
  4322. { generate the class table }
  4323. rttiList.concat(Tai_label.Create(classtable));
  4324. rttiList.concat(Tai_const.Create_16bit(tablecount));
  4325. hp:=tclasslistitem(classtablelist.first);
  4326. while assigned(hp) do
  4327. begin
  4328. rttiList.concat(Tai_const_symbol.Createname(tobjectdef(hp.p).vmt_mangledname));
  4329. hp:=tclasslistitem(hp.next);
  4330. end;
  4331. generate_field_table:=fieldtable;
  4332. classtablelist.free;
  4333. end;
  4334. function tobjectdef.next_free_name_index : longint;
  4335. var
  4336. i : longint;
  4337. begin
  4338. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4339. i:=childof.next_free_name_index
  4340. else
  4341. i:=0;
  4342. count:=0;
  4343. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties);
  4344. next_free_name_index:=i+count;
  4345. end;
  4346. procedure tobjectdef.write_rtti_data(rt:trttitype);
  4347. begin
  4348. case objecttype of
  4349. odt_class:
  4350. rttiList.concat(Tai_const.Create_8bit(tkclass));
  4351. odt_object:
  4352. rttiList.concat(Tai_const.Create_8bit(tkobject));
  4353. odt_interfacecom:
  4354. rttiList.concat(Tai_const.Create_8bit(tkinterface));
  4355. odt_interfacecorba:
  4356. rttiList.concat(Tai_const.Create_8bit(tkinterfaceCorba));
  4357. else
  4358. exit;
  4359. end;
  4360. { generate the name }
  4361. rttiList.concat(Tai_const.Create_8bit(length(objname^)));
  4362. rttiList.concat(Tai_string.Create(objname^));
  4363. case rt of
  4364. initrtti :
  4365. begin
  4366. rttiList.concat(Tai_const.Create_32bit(size));
  4367. if objecttype in [odt_class,odt_object] then
  4368. begin
  4369. count:=0;
  4370. FRTTIType:=rt;
  4371. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_field_rtti);
  4372. rttiList.concat(Tai_const.Create_32bit(count));
  4373. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}write_field_rtti);
  4374. end;
  4375. end;
  4376. fullrtti :
  4377. begin
  4378. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4379. rttiList.concat(Tai_const.Create_32bit(0))
  4380. else
  4381. rttiList.concat(Tai_const_symbol.Createname(vmt_mangledname));
  4382. { write owner typeinfo }
  4383. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4384. rttiList.concat(Tai_const_symbol.Create(childof.get_rtti_label(fullrtti)))
  4385. else
  4386. rttiList.concat(Tai_const.Create_32bit(0));
  4387. { count total number of properties }
  4388. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4389. count:=childof.next_free_name_index
  4390. else
  4391. count:=0;
  4392. { write it }
  4393. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties);
  4394. rttiList.concat(Tai_const.Create_16bit(count));
  4395. { write unit name }
  4396. rttiList.concat(Tai_const.Create_8bit(length(current_module.realmodulename^)));
  4397. rttiList.concat(Tai_string.Create(current_module.realmodulename^));
  4398. { write published properties count }
  4399. count:=0;
  4400. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties);
  4401. rttiList.concat(Tai_const.Create_16bit(count));
  4402. { count is used to write nameindex }
  4403. { but we need an offset of the owner }
  4404. { to give each property an own slot }
  4405. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4406. count:=childof.next_free_name_index
  4407. else
  4408. count:=0;
  4409. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}write_property_info);
  4410. end;
  4411. end;
  4412. end;
  4413. function tobjectdef.is_publishable : boolean;
  4414. begin
  4415. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba];
  4416. end;
  4417. {****************************************************************************
  4418. TIMPLEMENTEDINTERFACES
  4419. ****************************************************************************}
  4420. type
  4421. tnamemap = class(TNamedIndexItem)
  4422. newname: pstring;
  4423. constructor create(const aname, anewname: string);
  4424. destructor destroy; override;
  4425. end;
  4426. constructor tnamemap.create(const aname, anewname: string);
  4427. begin
  4428. inherited createname(name);
  4429. newname:=stringdup(anewname);
  4430. end;
  4431. destructor tnamemap.destroy;
  4432. begin
  4433. stringdispose(newname);
  4434. inherited destroy;
  4435. end;
  4436. type
  4437. tprocdefstore = class(TNamedIndexItem)
  4438. procdef: tprocdef;
  4439. constructor create(aprocdef: tprocdef);
  4440. end;
  4441. constructor tprocdefstore.create(aprocdef: tprocdef);
  4442. begin
  4443. inherited create;
  4444. procdef:=aprocdef;
  4445. end;
  4446. type
  4447. timplintfentry = class(TNamedIndexItem)
  4448. intf: tobjectdef;
  4449. ioffs: longint;
  4450. namemappings: tdictionary;
  4451. procdefs: TIndexArray;
  4452. constructor create(aintf: tobjectdef);
  4453. destructor destroy; override;
  4454. end;
  4455. constructor timplintfentry.create(aintf: tobjectdef);
  4456. begin
  4457. inherited create;
  4458. intf:=aintf;
  4459. ioffs:=-1;
  4460. namemappings:=nil;
  4461. procdefs:=nil;
  4462. end;
  4463. destructor timplintfentry.destroy;
  4464. begin
  4465. if assigned(namemappings) then
  4466. namemappings.free;
  4467. if assigned(procdefs) then
  4468. procdefs.free;
  4469. inherited destroy;
  4470. end;
  4471. constructor timplementedinterfaces.create;
  4472. begin
  4473. finterfaces:=tindexarray.create(1);
  4474. end;
  4475. destructor timplementedinterfaces.destroy;
  4476. begin
  4477. finterfaces.destroy;
  4478. end;
  4479. function timplementedinterfaces.count: longint;
  4480. begin
  4481. count:=finterfaces.count;
  4482. end;
  4483. procedure timplementedinterfaces.checkindex(intfindex: longint);
  4484. begin
  4485. if (intfindex<1) or (intfindex>count) then
  4486. InternalError(200006123);
  4487. end;
  4488. function timplementedinterfaces.interfaces(intfindex: longint): tobjectdef;
  4489. begin
  4490. checkindex(intfindex);
  4491. interfaces:=timplintfentry(finterfaces.search(intfindex)).intf;
  4492. end;
  4493. function timplementedinterfaces.ioffsets(intfindex: longint): plongint;
  4494. begin
  4495. checkindex(intfindex);
  4496. ioffsets:=@timplintfentry(finterfaces.search(intfindex)).ioffs;
  4497. end;
  4498. function timplementedinterfaces.searchintf(def: tdef): longint;
  4499. var
  4500. i: longint;
  4501. begin
  4502. i:=1;
  4503. while (i<=count) and (tdef(interfaces(i))<>def) do inc(i);
  4504. if i<=count then
  4505. searchintf:=i
  4506. else
  4507. searchintf:=-1;
  4508. end;
  4509. procedure timplementedinterfaces.deref;
  4510. var
  4511. i: longint;
  4512. begin
  4513. for i:=1 to count do
  4514. with timplintfentry(finterfaces.search(i)) do
  4515. resolvedef(tdef(intf));
  4516. end;
  4517. procedure timplementedinterfaces.addintfref(def: tdef);
  4518. begin
  4519. finterfaces.insert(timplintfentry.create(tobjectdef(def)));
  4520. end;
  4521. procedure timplementedinterfaces.addintf(def: tdef);
  4522. begin
  4523. if not assigned(def) or (searchintf(def)<>-1) or (def.deftype<>objectdef) or
  4524. not (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4525. internalerror(200006124);
  4526. finterfaces.insert(timplintfentry.create(tobjectdef(def)));
  4527. end;
  4528. procedure timplementedinterfaces.clearmappings;
  4529. var
  4530. i: longint;
  4531. begin
  4532. for i:=1 to count do
  4533. with timplintfentry(finterfaces.search(i)) do
  4534. begin
  4535. if assigned(namemappings) then
  4536. namemappings.free;
  4537. namemappings:=nil;
  4538. end;
  4539. end;
  4540. procedure timplementedinterfaces.addmappings(intfindex: longint; const name, newname: string);
  4541. begin
  4542. checkindex(intfindex);
  4543. with timplintfentry(finterfaces.search(intfindex)) do
  4544. begin
  4545. if not assigned(namemappings) then
  4546. namemappings:=tdictionary.create;
  4547. namemappings.insert(tnamemap.create(name,newname));
  4548. end;
  4549. end;
  4550. function timplementedinterfaces.getmappings(intfindex: longint; const name: string; var nextexist: pointer): string;
  4551. begin
  4552. checkindex(intfindex);
  4553. if not assigned(nextexist) then
  4554. with timplintfentry(finterfaces.search(intfindex)) do
  4555. begin
  4556. if assigned(namemappings) then
  4557. nextexist:=namemappings.search(name)
  4558. else
  4559. nextexist:=nil;
  4560. end;
  4561. if assigned(nextexist) then
  4562. begin
  4563. getmappings:=tnamemap(nextexist).newname^;
  4564. nextexist:=tnamemap(nextexist).listnext;
  4565. end
  4566. else
  4567. getmappings:='';
  4568. end;
  4569. procedure timplementedinterfaces.clearimplprocs;
  4570. var
  4571. i: longint;
  4572. begin
  4573. for i:=1 to count do
  4574. with timplintfentry(finterfaces.search(i)) do
  4575. begin
  4576. if assigned(procdefs) then
  4577. procdefs.free;
  4578. procdefs:=nil;
  4579. end;
  4580. end;
  4581. procedure timplementedinterfaces.addimplproc(intfindex: longint; procdef: tprocdef);
  4582. begin
  4583. checkindex(intfindex);
  4584. with timplintfentry(finterfaces.search(intfindex)) do
  4585. begin
  4586. if not assigned(procdefs) then
  4587. procdefs:=tindexarray.create(4);
  4588. procdefs.insert(tprocdefstore.create(procdef));
  4589. end;
  4590. end;
  4591. function timplementedinterfaces.implproccount(intfindex: longint): longint;
  4592. begin
  4593. checkindex(intfindex);
  4594. with timplintfentry(finterfaces.search(intfindex)) do
  4595. if assigned(procdefs) then
  4596. implproccount:=procdefs.count
  4597. else
  4598. implproccount:=0;
  4599. end;
  4600. function timplementedinterfaces.implprocs(intfindex: longint; procindex: longint): tprocdef;
  4601. begin
  4602. checkindex(intfindex);
  4603. with timplintfentry(finterfaces.search(intfindex)) do
  4604. if assigned(procdefs) then
  4605. implprocs:=tprocdefstore(procdefs.search(procindex)).procdef
  4606. else
  4607. internalerror(200006131);
  4608. end;
  4609. function timplementedinterfaces.isimplmergepossible(intfindex, remainindex: longint; var weight: longint): boolean;
  4610. var
  4611. possible: boolean;
  4612. i: longint;
  4613. iiep1: TIndexArray;
  4614. iiep2: TIndexArray;
  4615. begin
  4616. checkindex(intfindex);
  4617. checkindex(remainindex);
  4618. iiep1:=timplintfentry(finterfaces.search(intfindex)).procdefs;
  4619. iiep2:=timplintfentry(finterfaces.search(remainindex)).procdefs;
  4620. if not assigned(iiep1) then { empty interface is mergeable :-) }
  4621. begin
  4622. possible:=true;
  4623. weight:=0;
  4624. end
  4625. else
  4626. begin
  4627. possible:=assigned(iiep2) and (iiep1.count<=iiep2.count);
  4628. i:=1;
  4629. while (possible) and (i<=iiep1.count) do
  4630. begin
  4631. possible:=
  4632. (tprocdefstore(iiep1.search(i)).procdef=tprocdefstore(iiep2.search(i)).procdef);
  4633. inc(i);
  4634. end;
  4635. if possible then
  4636. weight:=iiep1.count;
  4637. end;
  4638. isimplmergepossible:=possible;
  4639. end;
  4640. {****************************************************************************
  4641. TFORWARDDEF
  4642. ****************************************************************************}
  4643. constructor tforwarddef.create(const s:string;const pos : tfileposinfo);
  4644. var
  4645. oldregisterdef : boolean;
  4646. begin
  4647. { never register the forwarddefs, they are disposed at the
  4648. end of the type declaration block }
  4649. oldregisterdef:=registerdef;
  4650. registerdef:=false;
  4651. inherited create;
  4652. registerdef:=oldregisterdef;
  4653. deftype:=forwarddef;
  4654. tosymname:=s;
  4655. forwardpos:=pos;
  4656. end;
  4657. function tforwarddef.gettypename:string;
  4658. begin
  4659. gettypename:='unresolved forward to '+tosymname;
  4660. end;
  4661. {****************************************************************************
  4662. TERRORDEF
  4663. ****************************************************************************}
  4664. constructor terrordef.create;
  4665. begin
  4666. inherited create;
  4667. deftype:=errordef;
  4668. end;
  4669. {$ifdef GDB}
  4670. function terrordef.stabstring : pchar;
  4671. begin
  4672. stabstring:=strpnew('error'+numberstring);
  4673. end;
  4674. {$endif GDB}
  4675. function terrordef.gettypename:string;
  4676. begin
  4677. gettypename:='<erroneous type>';
  4678. end;
  4679. {****************************************************************************
  4680. GDB Helpers
  4681. ****************************************************************************}
  4682. {$ifdef GDB}
  4683. function typeglobalnumber(const s : string) : string;
  4684. var st : string;
  4685. symt : tsymtable;
  4686. srsym : tsym;
  4687. srsymtable : tsymtable;
  4688. old_make_ref : boolean;
  4689. begin
  4690. old_make_ref:=make_ref;
  4691. make_ref:=false;
  4692. typeglobalnumber := '0';
  4693. srsym := nil;
  4694. if pos('.',s) > 0 then
  4695. begin
  4696. st := copy(s,1,pos('.',s)-1);
  4697. searchsym(st,srsym,srsymtable);
  4698. st := copy(s,pos('.',s)+1,255);
  4699. if assigned(srsym) then
  4700. begin
  4701. if srsym.typ = unitsym then
  4702. begin
  4703. symt := tunitsym(srsym).unitsymtable;
  4704. srsym := tsym(symt.search(st));
  4705. end else srsym := nil;
  4706. end;
  4707. end else st := s;
  4708. if srsym = nil then
  4709. searchsym(st,srsym,srsymtable);
  4710. if (srsym=nil) or
  4711. (srsym.typ<>typesym) then
  4712. begin
  4713. Message(type_e_type_id_expected);
  4714. exit;
  4715. end;
  4716. typeglobalnumber := tstoreddef(ttypesym(srsym).restype.def).numberstring;
  4717. make_ref:=old_make_ref;
  4718. end;
  4719. {$endif GDB}
  4720. {****************************************************************************
  4721. Definition Helpers
  4722. ****************************************************************************}
  4723. procedure reset_global_defs;
  4724. var
  4725. def : tstoreddef;
  4726. {$ifdef debug}
  4727. prevdef : tstoreddef;
  4728. {$endif debug}
  4729. begin
  4730. {$ifdef debug}
  4731. prevdef:=nil;
  4732. {$endif debug}
  4733. {$ifdef GDB}
  4734. pglobaltypecount:=@globaltypecount;
  4735. {$endif GDB}
  4736. def:=firstglobaldef;
  4737. while assigned(def) do
  4738. begin
  4739. {$ifdef GDB}
  4740. if assigned(def.typesym) then
  4741. ttypesym(def.typesym).isusedinstab:=false;
  4742. def.is_def_stab_written:=not_written;
  4743. {$endif GDB}
  4744. { reset rangenr's }
  4745. case def.deftype of
  4746. orddef : torddef(def).rangenr:=0;
  4747. enumdef : tenumdef(def).rangenr:=0;
  4748. arraydef : tarraydef(def).rangenr:=0;
  4749. end;
  4750. if assigned(def.rttitablesym) then
  4751. trttisym(def.rttitablesym).lab := nil;
  4752. if assigned(def.inittablesym) then
  4753. trttisym(def.inittablesym).lab := nil;
  4754. def.localrttilab[initrtti]:=nil;
  4755. def.localrttilab[fullrtti]:=nil;
  4756. {$ifdef debug}
  4757. prevdef:=def;
  4758. {$endif debug}
  4759. def:=def.nextglobal;
  4760. end;
  4761. end;
  4762. function is_interfacecom(def: tdef): boolean;
  4763. begin
  4764. is_interfacecom:=
  4765. assigned(def) and
  4766. (def.deftype=objectdef) and
  4767. (tobjectdef(def).objecttype=odt_interfacecom);
  4768. end;
  4769. function is_interfacecorba(def: tdef): boolean;
  4770. begin
  4771. is_interfacecorba:=
  4772. assigned(def) and
  4773. (def.deftype=objectdef) and
  4774. (tobjectdef(def).objecttype=odt_interfacecorba);
  4775. end;
  4776. function is_interface(def: tdef): boolean;
  4777. begin
  4778. is_interface:=
  4779. assigned(def) and
  4780. (def.deftype=objectdef) and
  4781. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  4782. end;
  4783. function is_class(def: tdef): boolean;
  4784. begin
  4785. is_class:=
  4786. assigned(def) and
  4787. (def.deftype=objectdef) and
  4788. (tobjectdef(def).objecttype=odt_class);
  4789. end;
  4790. function is_object(def: tdef): boolean;
  4791. begin
  4792. is_object:=
  4793. assigned(def) and
  4794. (def.deftype=objectdef) and
  4795. (tobjectdef(def).objecttype=odt_object);
  4796. end;
  4797. function is_cppclass(def: tdef): boolean;
  4798. begin
  4799. is_cppclass:=
  4800. assigned(def) and
  4801. (def.deftype=objectdef) and
  4802. (tobjectdef(def).objecttype=odt_cppclass);
  4803. end;
  4804. function is_class_or_interface(def: tdef): boolean;
  4805. begin
  4806. is_class_or_interface:=
  4807. assigned(def) and
  4808. (def.deftype=objectdef) and
  4809. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  4810. end;
  4811. end.
  4812. {
  4813. $Log$
  4814. Revision 1.62 2002-01-06 12:08:15 peter
  4815. * removed uauto from orddef, use new range_to_basetype generating
  4816. the correct ordinal type for a range
  4817. Revision 1.61 2001/12/19 09:34:51 florian
  4818. * publishing of publishable classes fixed
  4819. Revision 1.60 2001/12/06 17:57:39 florian
  4820. + parasym to tparaitem added
  4821. Revision 1.59 2001/12/03 21:48:42 peter
  4822. * freemem change to value parameter
  4823. * torddef low/high range changed to int64
  4824. Revision 1.58 2001/11/30 15:01:51 jonas
  4825. * tarraydef.size returns target_info.size_of_pointer instead of 4 for
  4826. dynamic arrays
  4827. Revision 1.57 2001/11/18 18:43:14 peter
  4828. * overloading supported in child classes
  4829. * fixed parsing of classes with private and virtual and overloaded
  4830. so it is compatible with delphi
  4831. Revision 1.56 2001/11/18 18:27:57 florian
  4832. * publishing of qword, int64 and widechar properties is now possible
  4833. Revision 1.55 2001/11/02 22:58:06 peter
  4834. * procsym definition rewrite
  4835. Revision 1.54 2001/10/25 21:22:37 peter
  4836. * calling convention rewrite
  4837. Revision 1.53 2001/10/20 17:21:54 peter
  4838. * fixed size of constset when change from small to normalset
  4839. Revision 1.52 2001/10/15 13:16:26 jonas
  4840. * better size checking of data (now an error is returned for
  4841. "array[longint] of longint") ("merged")
  4842. Revision 1.51 2001/09/19 11:04:42 michael
  4843. * Smartlinking with interfaces fixed
  4844. * Better smartlinking for rtti and init tables
  4845. Revision 1.50 2001/09/17 21:29:12 peter
  4846. * merged netbsd, fpu-overflow from fixes branch
  4847. Revision 1.49 2001/09/10 10:26:27 jonas
  4848. * fixed web bug 1593
  4849. * writing of procvar headers is more complete (mention var/const/out for
  4850. paras, add "of object" if applicable)
  4851. + error if declaring explicit self para as var/const
  4852. * fixed mangled name of procedures which contain an explicit self para
  4853. * parsing para's should be slightly faster because mangled name of
  4854. procedure is only updated once instead of after parsing each para
  4855. (all merged from fixes)
  4856. Revision 1.48 2001/09/03 15:18:38 jonas
  4857. * aded missing reset of labels of rttitablesym and inittablesym labels
  4858. Revision 1.47 2001/09/02 21:18:28 peter
  4859. * split constsym.value in valueord,valueordptr,valueptr. The valueordptr
  4860. is used for holding target platform pointer values. As those can be
  4861. bigger than the source platform.
  4862. Revision 1.46 2001/08/30 20:13:54 peter
  4863. * rtti/init table updates
  4864. * rttisym for reusable global rtti/init info
  4865. * support published for interfaces
  4866. Revision 1.45 2001/08/26 13:36:49 florian
  4867. * some cg reorganisation
  4868. * some PPC updates
  4869. Revision 1.44 2001/08/22 21:16:22 florian
  4870. * some interfaces related problems regarding
  4871. mapping of interface implementions fixed
  4872. Revision 1.43 2001/08/19 09:39:27 peter
  4873. * local browser support fixed
  4874. Revision 1.41 2001/08/12 20:04:33 peter
  4875. * fpu_used=0 when simplify_ppu is used
  4876. * small crc updating fixes for tprocdef
  4877. Revision 1.40 2001/08/06 21:40:48 peter
  4878. * funcret moved from tprocinfo to tprocdef
  4879. Revision 1.39 2001/08/01 21:47:48 peter
  4880. * fixed passing of array of record or shortstring to open array
  4881. Revision 1.38 2001/07/30 20:59:27 peter
  4882. * m68k updates from v10 merged
  4883. Revision 1.37 2001/07/30 11:52:57 jonas
  4884. * fixed web bugs 1563/1564: procvars of object can't be regvars (merged)
  4885. Revision 1.36 2001/07/01 20:16:16 peter
  4886. * alignmentinfo record added
  4887. * -Oa argument supports more alignment settings that can be specified
  4888. per type: PROC,LOOP,VARMIN,VARMAX,CONSTMIN,CONSTMAX,RECORDMIN
  4889. RECORDMAX,LOCALMIN,LOCALMAX. It is possible to set the mimimum
  4890. required alignment and the maximum usefull alignment. The final
  4891. alignment will be choosen per variable size dependent on these
  4892. settings
  4893. Revision 1.35 2001/06/27 21:37:36 peter
  4894. * v10 merges
  4895. Revision 1.34 2001/06/04 18:05:39 peter
  4896. * procdef demangling fixed
  4897. Revision 1.33 2001/06/04 11:53:13 peter
  4898. + varargs directive
  4899. Revision 1.32 2001/05/09 19:58:45 peter
  4900. * m68k doesn't support double (merged)
  4901. Revision 1.31 2001/05/06 14:49:17 peter
  4902. * ppu object to class rewrite
  4903. * move ppu read and write stuff to fppu
  4904. Revision 1.30 2001/04/22 22:46:49 florian
  4905. * more variant support
  4906. Revision 1.29 2001/04/21 12:03:12 peter
  4907. * m68k updates merged from fixes branch
  4908. Revision 1.28 2001/04/18 22:01:58 peter
  4909. * registration of targets and assemblers
  4910. Revision 1.27 2001/04/13 01:22:15 peter
  4911. * symtable change to classes
  4912. * range check generation and errors fixed, make cycle DEBUG=1 works
  4913. * memory leaks fixed
  4914. Revision 1.26 2001/04/05 21:32:22 peter
  4915. * enum stabs fix (merged)
  4916. Revision 1.25 2001/04/04 21:30:45 florian
  4917. * applied several fixes to get the DD8 Delphi Unit compiled
  4918. e.g. "forward"-interfaces are working now
  4919. Revision 1.24 2001/04/02 21:20:34 peter
  4920. * resulttype rewrite
  4921. Revision 1.23 2001/03/22 23:28:39 florian
  4922. * correct initialisation of rec_tguid when loading the system unit
  4923. Revision 1.22 2001/03/22 00:10:58 florian
  4924. + basic variant type support in the compiler
  4925. Revision 1.21 2001/03/11 22:58:50 peter
  4926. * getsym redesign, removed the globals srsym,srsymtable
  4927. Revision 1.20 2001/01/06 20:11:29 peter
  4928. * merged c packrecords fix
  4929. Revision 1.19 2000/12/25 00:07:29 peter
  4930. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  4931. tlinkedlist objects)
  4932. Revision 1.18 2000/12/24 12:20:45 peter
  4933. * classes, enum stabs fixes merged from 1.0.x
  4934. Revision 1.17 2000/12/07 17:19:43 jonas
  4935. * new constant handling: from now on, hex constants >$7fffffff are
  4936. parsed as unsigned constants (otherwise, $80000000 got sign extended
  4937. and became $ffffffff80000000), all constants in the longint range
  4938. become longints, all constants >$7fffffff and <=cardinal($ffffffff)
  4939. are cardinals and the rest are int64's.
  4940. * added lots of longint typecast to prevent range check errors in the
  4941. compiler and rtl
  4942. * type casts of symbolic ordinal constants are now preserved
  4943. * fixed bug where the original resulttype.def wasn't restored correctly
  4944. after doing a 64bit rangecheck
  4945. Revision 1.16 2000/11/30 23:12:57 florian
  4946. * if raw interfaces inherit from IUnknown they are ref. counted too
  4947. Revision 1.15 2000/11/29 00:30:40 florian
  4948. * unused units removed from uses clause
  4949. * some changes for widestrings
  4950. Revision 1.14 2000/11/28 00:28:06 pierre
  4951. * stabs fixing
  4952. Revision 1.13 2000/11/26 18:09:40 florian
  4953. * fixed rtti for chars
  4954. Revision 1.12 2000/11/19 16:23:35 florian
  4955. *** empty log message ***
  4956. Revision 1.11 2000/11/12 23:24:12 florian
  4957. * interfaces are basically running
  4958. Revision 1.10 2000/11/11 16:12:38 peter
  4959. * add far; to typename for far pointer
  4960. Revision 1.9 2000/11/07 20:01:57 peter
  4961. * fix vmt index for classes
  4962. Revision 1.8 2000/11/06 23:13:53 peter
  4963. * uppercase manglednames
  4964. Revision 1.7 2000/11/06 23:11:38 florian
  4965. * writeln debugger uninstalled ;)
  4966. Revision 1.6 2000/11/06 23:05:52 florian
  4967. * more fixes
  4968. Revision 1.5 2000/11/06 20:30:55 peter
  4969. * more fixes to get make cycle working
  4970. Revision 1.4 2000/11/04 14:25:22 florian
  4971. + merged Attila's changes for interfaces, not tested yet
  4972. Revision 1.3 2000/11/02 12:04:10 pierre
  4973. * remove RecOffset code, that created problems
  4974. Revision 1.2 2000/11/01 23:04:38 peter
  4975. * tprocdef.fullprocname added for better casesensitve writing of
  4976. procedures
  4977. Revision 1.1 2000/10/31 22:02:52 peter
  4978. * symtable splitted, no real code changes
  4979. }