symdef.pas 175 KB

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