symdef.pas 175 KB

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