symdef.pas 179 KB

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