symdef.pas 207 KB

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