symdef.pas 178 KB

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