symdef.pas 171 KB

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