symdef.pas 206 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674
  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(lower(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. (TConstExprInt(highrange)-TConstExprInt(lowrange) > $7fffffff) or
  2473. { () are needed around cachedsize-1 to avoid a possible
  2474. integer overflow for cachedsize=1 !! PM }
  2475. (($7fffffff div cachedsize + (cachedsize -1)) < (int64(highrange) - int64(lowrange)))
  2476. ) Then
  2477. Message(sym_e_segment_too_large);
  2478. end;
  2479. end;
  2480. function tarraydef.alignment : longint;
  2481. begin
  2482. { alignment is the size of the elements }
  2483. if elementtype.def.deftype=recorddef then
  2484. alignment:=elementtype.def.alignment
  2485. else
  2486. alignment:=elesize;
  2487. end;
  2488. function tarraydef.needs_inittable : boolean;
  2489. begin
  2490. needs_inittable:=IsDynamicArray or elementtype.def.needs_inittable;
  2491. end;
  2492. procedure tarraydef.write_child_rtti_data(rt:trttitype);
  2493. begin
  2494. tstoreddef(elementtype.def).get_rtti_label(rt);
  2495. end;
  2496. procedure tarraydef.write_rtti_data(rt:trttitype);
  2497. begin
  2498. if IsDynamicArray then
  2499. rttiList.concat(Tai_const.Create_8bit(tkdynarray))
  2500. else
  2501. rttiList.concat(Tai_const.Create_8bit(tkarray));
  2502. write_rtti_name;
  2503. { size of elements }
  2504. rttiList.concat(Tai_const.Create_32bit(elesize));
  2505. { count of elements }
  2506. if not(IsDynamicArray) then
  2507. rttiList.concat(Tai_const.Create_32bit(highrange-lowrange+1));
  2508. { element type }
  2509. rttiList.concat(Tai_const_symbol.Create(tstoreddef(elementtype.def).get_rtti_label(rt)));
  2510. { variant type }
  2511. // !!!!!!!!!!!!!!!!
  2512. end;
  2513. function tarraydef.gettypename : string;
  2514. begin
  2515. if isarrayofconst or isConstructor then
  2516. begin
  2517. if isvariant or ((highrange=-1) and (lowrange=0)) then
  2518. gettypename:='Array Of Const'
  2519. else
  2520. gettypename:='Array Of '+elementtype.def.typename;
  2521. end
  2522. else if ((highrange=-1) and (lowrange=0)) or IsDynamicArray then
  2523. gettypename:='Array Of '+elementtype.def.typename
  2524. else
  2525. begin
  2526. if rangetype.def.deftype=enumdef then
  2527. gettypename:='Array['+rangetype.def.typename+'] Of '+elementtype.def.typename
  2528. else
  2529. gettypename:='Array['+tostr(lowrange)+'..'+
  2530. tostr(highrange)+'] Of '+elementtype.def.typename
  2531. end;
  2532. end;
  2533. function tarraydef.getmangledparaname : string;
  2534. begin
  2535. if isarrayofconst then
  2536. getmangledparaname:='array_of_const'
  2537. else
  2538. if ((highrange=-1) and (lowrange=0)) then
  2539. getmangledparaname:='array_of_'+elementtype.def.mangledparaname
  2540. else
  2541. internalerror(200204176);
  2542. end;
  2543. {***************************************************************************
  2544. tabstractrecorddef
  2545. ***************************************************************************}
  2546. function tabstractrecorddef.getsymtable(t:tgetsymtable):tsymtable;
  2547. begin
  2548. if t=gs_record then
  2549. getsymtable:=symtable
  2550. else
  2551. getsymtable:=nil;
  2552. end;
  2553. {$ifdef GDB}
  2554. procedure tabstractrecorddef.addname(p : tnamedindexitem;arg:pointer);
  2555. var
  2556. news, newrec : pchar;
  2557. spec : string[3];
  2558. varsize : longint;
  2559. begin
  2560. { static variables from objects are like global objects }
  2561. if (sp_static in tsym(p).symoptions) then
  2562. exit;
  2563. If tsym(p).typ = varsym then
  2564. begin
  2565. if (sp_protected in tsym(p).symoptions) then
  2566. spec:='/1'
  2567. else if (sp_private in tsym(p).symoptions) then
  2568. spec:='/0'
  2569. else
  2570. spec:='';
  2571. if not assigned(tvarsym(p).vartype.def) then
  2572. writeln(tvarsym(p).name);
  2573. { class fields are pointers PM, obsolete now PM }
  2574. {if (tvarsym(p).vartype.def.deftype=objectdef) and
  2575. tobjectdef(tvarsym(p).vartype.def).is_class then
  2576. spec:=spec+'*'; }
  2577. varsize:=tvarsym(p).vartype.def.size;
  2578. { open arrays made overflows !! }
  2579. if varsize>$fffffff then
  2580. varsize:=$fffffff;
  2581. newrec := strpnew(p.name+':'+spec+tstoreddef(tvarsym(p).vartype.def).numberstring
  2582. +','+tostr(tvarsym(p).fieldoffset*8)+','
  2583. +tostr(varsize*8)+';');
  2584. if strlen(StabRecString) + strlen(newrec) >= StabRecSize-256 then
  2585. begin
  2586. getmem(news,stabrecsize+memsizeinc);
  2587. strcopy(news,stabrecstring);
  2588. freemem(stabrecstring,stabrecsize);
  2589. stabrecsize:=stabrecsize+memsizeinc;
  2590. stabrecstring:=news;
  2591. end;
  2592. strcat(StabRecstring,newrec);
  2593. strdispose(newrec);
  2594. {This should be used for case !!}
  2595. inc(RecOffset,tvarsym(p).vartype.def.size);
  2596. end;
  2597. end;
  2598. {$endif GDB}
  2599. procedure tabstractrecorddef.count_field_rtti(sym : tnamedindexitem;arg:pointer);
  2600. begin
  2601. if (FRTTIType=fullrtti) or
  2602. ((tsym(sym).typ=varsym) and
  2603. tvarsym(sym).vartype.def.needs_inittable) then
  2604. inc(Count);
  2605. end;
  2606. procedure tabstractrecorddef.generate_field_rtti(sym:tnamedindexitem;arg:pointer);
  2607. begin
  2608. if (FRTTIType=fullrtti) or
  2609. ((tsym(sym).typ=varsym) and
  2610. tvarsym(sym).vartype.def.needs_inittable) then
  2611. tstoreddef(tvarsym(sym).vartype.def).get_rtti_label(FRTTIType);
  2612. end;
  2613. procedure tabstractrecorddef.write_field_rtti(sym : tnamedindexitem;arg:pointer);
  2614. begin
  2615. if (FRTTIType=fullrtti) or
  2616. ((tsym(sym).typ=varsym) and
  2617. tvarsym(sym).vartype.def.needs_inittable) then
  2618. begin
  2619. rttiList.concat(Tai_const_symbol.Create(tstoreddef(tvarsym(sym).vartype.def).get_rtti_label(FRTTIType)));
  2620. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym).fieldoffset));
  2621. end;
  2622. end;
  2623. {***************************************************************************
  2624. trecorddef
  2625. ***************************************************************************}
  2626. constructor trecorddef.create(p : tsymtable);
  2627. begin
  2628. inherited create;
  2629. deftype:=recorddef;
  2630. symtable:=p;
  2631. symtable.defowner:=self;
  2632. { recordalign -1 means C record packing, that starts
  2633. with an alignment of 1 }
  2634. if aktalignment.recordalignmax=-1 then
  2635. trecordsymtable(symtable).dataalignment:=1
  2636. else
  2637. trecordsymtable(symtable).dataalignment:=aktalignment.recordalignmax;
  2638. isunion:=false;
  2639. end;
  2640. constructor trecorddef.ppuload(ppufile:tcompilerppufile);
  2641. begin
  2642. inherited ppuloaddef(ppufile);
  2643. deftype:=recorddef;
  2644. savesize:=ppufile.getlongint;
  2645. symtable:=trecordsymtable.create;
  2646. trecordsymtable(symtable).datasize:=ppufile.getlongint;
  2647. trecordsymtable(symtable).dataalignment:=ppufile.getbyte;
  2648. trecordsymtable(symtable).ppuload(ppufile);
  2649. symtable.defowner:=self;
  2650. isunion:=false;
  2651. end;
  2652. destructor trecorddef.destroy;
  2653. begin
  2654. if assigned(symtable) then
  2655. symtable.free;
  2656. inherited destroy;
  2657. end;
  2658. function trecorddef.needs_inittable : boolean;
  2659. begin
  2660. needs_inittable:=trecordsymtable(symtable).needs_init_final
  2661. end;
  2662. procedure trecorddef.buildderef;
  2663. var
  2664. oldrecsyms : tsymtable;
  2665. begin
  2666. inherited buildderef;
  2667. oldrecsyms:=aktrecordsymtable;
  2668. aktrecordsymtable:=symtable;
  2669. { now build the definitions }
  2670. tstoredsymtable(symtable).buildderef;
  2671. aktrecordsymtable:=oldrecsyms;
  2672. end;
  2673. procedure trecorddef.deref;
  2674. var
  2675. oldrecsyms : tsymtable;
  2676. begin
  2677. inherited deref;
  2678. oldrecsyms:=aktrecordsymtable;
  2679. aktrecordsymtable:=symtable;
  2680. { now dereference the definitions }
  2681. tstoredsymtable(symtable).deref;
  2682. aktrecordsymtable:=oldrecsyms;
  2683. { assign TGUID? load only from system unit (unitid=1) }
  2684. if not(assigned(rec_tguid)) and
  2685. (upper(typename)='TGUID') and
  2686. assigned(owner) and
  2687. assigned(owner.name) and
  2688. (owner.name^='SYSTEM') then
  2689. rec_tguid:=self;
  2690. end;
  2691. procedure trecorddef.ppuwrite(ppufile:tcompilerppufile);
  2692. begin
  2693. inherited ppuwritedef(ppufile);
  2694. ppufile.putlongint(savesize);
  2695. ppufile.putlongint(trecordsymtable(symtable).datasize);
  2696. ppufile.putbyte(trecordsymtable(symtable).dataalignment);
  2697. ppufile.writeentry(ibrecorddef);
  2698. trecordsymtable(symtable).ppuwrite(ppufile);
  2699. end;
  2700. function trecorddef.size:longint;
  2701. begin
  2702. result:=trecordsymtable(symtable).datasize;
  2703. end;
  2704. function trecorddef.alignment:longint;
  2705. var
  2706. l : longint;
  2707. hp : tvarsym;
  2708. begin
  2709. { also check the first symbol for it's size, because a
  2710. packed record has dataalignment of 1, but the first
  2711. sym could be a longint which should be aligned on 4 bytes,
  2712. this is compatible with C record packing (PFV) }
  2713. hp:=tvarsym(symtable.symindex.first);
  2714. if assigned(hp) then
  2715. begin
  2716. if hp.vartype.def.deftype in [recorddef,arraydef] then
  2717. l:=hp.vartype.def.alignment
  2718. else
  2719. l:=hp.vartype.def.size;
  2720. if l>trecordsymtable(symtable).dataalignment then
  2721. begin
  2722. if l>=4 then
  2723. alignment:=4
  2724. else
  2725. if l>=2 then
  2726. alignment:=2
  2727. else
  2728. alignment:=1;
  2729. end
  2730. else
  2731. alignment:=trecordsymtable(symtable).dataalignment;
  2732. end
  2733. else
  2734. alignment:=trecordsymtable(symtable).dataalignment;
  2735. end;
  2736. {$ifdef GDB}
  2737. function trecorddef.stabstring : pchar;
  2738. begin
  2739. GetMem(stabrecstring,memsizeinc);
  2740. stabrecsize:=memsizeinc;
  2741. strpcopy(stabRecString,'s'+tostr(size));
  2742. RecOffset := 0;
  2743. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}addname,nil);
  2744. strpcopy(strend(StabRecString),';');
  2745. stabstring := strnew(StabRecString);
  2746. Freemem(stabrecstring,stabrecsize);
  2747. end;
  2748. procedure trecorddef.concatstabto(asmlist : taasmoutput);
  2749. begin
  2750. if (not assigned(typesym) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches)) and
  2751. (is_def_stab_written = not_written) then
  2752. inherited concatstabto(asmlist);
  2753. end;
  2754. {$endif GDB}
  2755. procedure trecorddef.write_child_rtti_data(rt:trttitype);
  2756. begin
  2757. FRTTIType:=rt;
  2758. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}generate_field_rtti,nil);
  2759. end;
  2760. procedure trecorddef.write_rtti_data(rt:trttitype);
  2761. begin
  2762. rttiList.concat(Tai_const.Create_8bit(tkrecord));
  2763. write_rtti_name;
  2764. rttiList.concat(Tai_const.Create_32bit(size));
  2765. Count:=0;
  2766. FRTTIType:=rt;
  2767. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_field_rtti,nil);
  2768. rttiList.concat(Tai_const.Create_32bit(Count));
  2769. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}write_field_rtti,nil);
  2770. end;
  2771. function trecorddef.gettypename : string;
  2772. begin
  2773. gettypename:='<record type>'
  2774. end;
  2775. {***************************************************************************
  2776. TABSTRACTPROCDEF
  2777. ***************************************************************************}
  2778. constructor tabstractprocdef.create(level:byte);
  2779. begin
  2780. inherited create;
  2781. parast:=tparasymtable.create(level);
  2782. parast.defowner:=self;
  2783. parast.next:=owner;
  2784. para:=TLinkedList.Create;
  2785. minparacount:=0;
  2786. maxparacount:=0;
  2787. proctypeoption:=potype_none;
  2788. proccalloption:=pocall_none;
  2789. procoptions:=[];
  2790. rettype:=voidtype;
  2791. {$ifdef i386}
  2792. fpu_used:=0;
  2793. {$endif i386}
  2794. savesize:=POINTER_SIZE;
  2795. has_paraloc_info:=false;
  2796. end;
  2797. destructor tabstractprocdef.destroy;
  2798. begin
  2799. if assigned(para) then
  2800. begin
  2801. {$ifdef MEMDEBUG}
  2802. memprocpara.start;
  2803. {$endif MEMDEBUG}
  2804. para.free;
  2805. {$ifdef MEMDEBUG}
  2806. memprocpara.stop;
  2807. {$endif MEMDEBUG}
  2808. end;
  2809. if assigned(parast) then
  2810. begin
  2811. {$ifdef MEMDEBUG}
  2812. memprocparast.start;
  2813. {$endif MEMDEBUG}
  2814. parast.free;
  2815. {$ifdef MEMDEBUG}
  2816. memprocparast.stop;
  2817. {$endif MEMDEBUG}
  2818. end;
  2819. inherited destroy;
  2820. end;
  2821. procedure tabstractprocdef.releasemem;
  2822. begin
  2823. para.free;
  2824. para:=nil;
  2825. parast.free;
  2826. parast:=nil;
  2827. end;
  2828. function tabstractprocdef.concatpara(afterpara:tparaitem;const tt:ttype;sym : tsym;defval:tsym;vhidden:boolean):tparaitem;
  2829. var
  2830. hp : TParaItem;
  2831. begin
  2832. hp:=TParaItem.Create;
  2833. hp.paratyp:=tvarsym(sym).varspez;
  2834. hp.parasym:=sym;
  2835. hp.paratype:=tt;
  2836. hp.is_hidden:=vhidden;
  2837. hp.defaultvalue:=defval;
  2838. { Parameters are stored from left to right }
  2839. if assigned(afterpara) then
  2840. Para.insertafter(hp,afterpara)
  2841. else
  2842. Para.concat(hp);
  2843. { Don't count hidden parameters }
  2844. if not vhidden then
  2845. begin
  2846. if not assigned(defval) then
  2847. inc(minparacount);
  2848. inc(maxparacount);
  2849. end;
  2850. concatpara:=hp;
  2851. end;
  2852. function tabstractprocdef.insertpara(const tt:ttype;sym : tsym;defval:tsym;vhidden:boolean):tparaitem;
  2853. var
  2854. hp : TParaItem;
  2855. begin
  2856. hp:=TParaItem.Create;
  2857. hp.paratyp:=tvarsym(sym).varspez;
  2858. hp.parasym:=sym;
  2859. hp.paratype:=tt;
  2860. hp.is_hidden:=vhidden;
  2861. hp.defaultvalue:=defval;
  2862. { Parameters are stored from left to right }
  2863. Para.insert(hp);
  2864. { Don't count hidden parameters }
  2865. if (not vhidden) then
  2866. begin
  2867. if not assigned(defval) then
  2868. inc(minparacount);
  2869. inc(maxparacount);
  2870. end;
  2871. insertpara:=hp;
  2872. end;
  2873. procedure tabstractprocdef.removepara(currpara:tparaitem);
  2874. begin
  2875. { Don't count hidden parameters }
  2876. if (not currpara.is_hidden) then
  2877. begin
  2878. if not assigned(currpara.defaultvalue) then
  2879. dec(minparacount);
  2880. dec(maxparacount);
  2881. end;
  2882. Para.Remove(currpara);
  2883. currpara.free;
  2884. end;
  2885. { all functions returning in FPU are
  2886. assume to use 2 FPU registers
  2887. until the function implementation
  2888. is processed PM }
  2889. procedure tabstractprocdef.test_if_fpu_result;
  2890. begin
  2891. {$ifdef i386}
  2892. if assigned(rettype.def) and
  2893. (rettype.def.deftype=floatdef) then
  2894. fpu_used:=maxfpuregs;
  2895. {$endif i386}
  2896. end;
  2897. procedure tabstractprocdef.buildderef;
  2898. var
  2899. hp : TParaItem;
  2900. begin
  2901. { released procdef? }
  2902. if not assigned(parast) then
  2903. exit;
  2904. inherited buildderef;
  2905. rettype.buildderef;
  2906. { parast }
  2907. tparasymtable(parast).buildderef;
  2908. { paraitems }
  2909. hp:=TParaItem(Para.first);
  2910. while assigned(hp) do
  2911. begin
  2912. hp.paratype.buildderef;
  2913. hp.defaultvaluederef.build(hp.defaultvalue);
  2914. hp.parasymderef.build(hp.parasym);
  2915. hp:=TParaItem(hp.next);
  2916. end;
  2917. end;
  2918. procedure tabstractprocdef.deref;
  2919. var
  2920. hp : TParaItem;
  2921. begin
  2922. inherited deref;
  2923. rettype.resolve;
  2924. { parast }
  2925. tparasymtable(parast).deref;
  2926. { paraitems }
  2927. minparacount:=0;
  2928. maxparacount:=0;
  2929. hp:=TParaItem(Para.first);
  2930. while assigned(hp) do
  2931. begin
  2932. hp.paratype.resolve;
  2933. hp.defaultvalue:=tsym(hp.defaultvaluederef.resolve);
  2934. hp.parasym:=tvarsym(hp.parasymderef.resolve);
  2935. { connect parasym to paraitem }
  2936. tvarsym(hp.parasym).paraitem:=hp;
  2937. { Don't count hidden parameters }
  2938. if (not hp.is_hidden) then
  2939. begin
  2940. if not assigned(hp.defaultvalue) then
  2941. inc(minparacount);
  2942. inc(maxparacount);
  2943. end;
  2944. hp:=TParaItem(hp.next);
  2945. end;
  2946. end;
  2947. constructor tabstractprocdef.ppuload(ppufile:tcompilerppufile);
  2948. var
  2949. hp : TParaItem;
  2950. count,i : word;
  2951. begin
  2952. inherited ppuloaddef(ppufile);
  2953. parast:=nil;
  2954. Para:=TLinkedList.Create;
  2955. minparacount:=0;
  2956. maxparacount:=0;
  2957. ppufile.gettype(rettype);
  2958. {$ifdef i386}
  2959. fpu_used:=ppufile.getbyte;
  2960. {$else}
  2961. ppufile.getbyte;
  2962. {$endif i386}
  2963. proctypeoption:=tproctypeoption(ppufile.getbyte);
  2964. proccalloption:=tproccalloption(ppufile.getbyte);
  2965. ppufile.getsmallset(procoptions);
  2966. { get the number of parameters }
  2967. count:=ppufile.getbyte;
  2968. savesize:=POINTER_SIZE;
  2969. has_paraloc_info:=false;
  2970. for i:=1 to count do
  2971. begin
  2972. hp:=TParaItem.Create;
  2973. hp.paratyp:=tvarspez(ppufile.getbyte);
  2974. ppufile.gettype(hp.paratype);
  2975. ppufile.getderef(hp.defaultvaluederef);
  2976. hp.defaultvalue:=nil;
  2977. ppufile.getderef(hp.parasymderef);
  2978. hp.parasym:=nil;
  2979. hp.is_hidden:=boolean(ppufile.getbyte);
  2980. { Parameters are stored left to right in both ppu and memory }
  2981. Para.concat(hp);
  2982. end;
  2983. end;
  2984. procedure tabstractprocdef.ppuwrite(ppufile:tcompilerppufile);
  2985. var
  2986. hp : TParaItem;
  2987. oldintfcrc : boolean;
  2988. begin
  2989. { released procdef? }
  2990. if not assigned(parast) then
  2991. exit;
  2992. inherited ppuwritedef(ppufile);
  2993. ppufile.puttype(rettype);
  2994. oldintfcrc:=ppufile.do_interface_crc;
  2995. ppufile.do_interface_crc:=false;
  2996. {$ifdef i386}
  2997. if simplify_ppu then
  2998. fpu_used:=0;
  2999. ppufile.putbyte(fpu_used);
  3000. {$else}
  3001. ppufile.putbyte(0);
  3002. {$endif}
  3003. ppufile.putbyte(ord(proctypeoption));
  3004. ppufile.putbyte(ord(proccalloption));
  3005. ppufile.putsmallset(procoptions);
  3006. ppufile.do_interface_crc:=oldintfcrc;
  3007. { we need to store the count including vs_hidden }
  3008. ppufile.putbyte(para.count);
  3009. hp:=TParaItem(Para.first);
  3010. while assigned(hp) do
  3011. begin
  3012. ppufile.putbyte(byte(hp.paratyp));
  3013. ppufile.puttype(hp.paratype);
  3014. ppufile.putderef(hp.defaultvaluederef);
  3015. ppufile.putderef(hp.parasymderef);
  3016. ppufile.putbyte(byte(hp.is_hidden));
  3017. hp:=TParaItem(hp.next);
  3018. end;
  3019. end;
  3020. function tabstractprocdef.typename_paras(showhidden:boolean) : string;
  3021. var
  3022. hs,s : string;
  3023. hp : TParaItem;
  3024. hpc : tconstsym;
  3025. first : boolean;
  3026. begin
  3027. hp:=TParaItem(Para.first);
  3028. s:='';
  3029. first:=true;
  3030. while assigned(hp) do
  3031. begin
  3032. if (not hp.is_hidden) or
  3033. (showhidden) then
  3034. begin
  3035. if first then
  3036. begin
  3037. s:=s+'(';
  3038. first:=false;
  3039. end
  3040. else
  3041. s:=s+',';
  3042. case hp.paratyp of
  3043. vs_var :
  3044. s:=s+'var';
  3045. vs_const :
  3046. s:=s+'const';
  3047. vs_out :
  3048. s:=s+'out';
  3049. end;
  3050. if assigned(hp.paratype.def.typesym) then
  3051. begin
  3052. if s<>'(' then
  3053. s:=s+' ';
  3054. hs:=hp.paratype.def.typesym.realname;
  3055. if hs[1]<>'$' then
  3056. s:=s+hp.paratype.def.typesym.realname
  3057. else
  3058. s:=s+hp.paratype.def.gettypename;
  3059. end
  3060. else
  3061. s:=s+hp.paratype.def.gettypename;
  3062. { default value }
  3063. if assigned(hp.defaultvalue) then
  3064. begin
  3065. hpc:=tconstsym(hp.defaultvalue);
  3066. hs:='';
  3067. case hpc.consttyp of
  3068. conststring,
  3069. constresourcestring :
  3070. hs:=strpas(pchar(hpc.value.valueptr));
  3071. constreal :
  3072. str(pbestreal(hpc.value.valueptr)^,hs);
  3073. constord :
  3074. hs:=tostr(hpc.value.valueord);
  3075. constpointer :
  3076. hs:=tostr(hpc.value.valueordptr);
  3077. constbool :
  3078. begin
  3079. if hpc.value.valueord<>0 then
  3080. hs:='TRUE'
  3081. else
  3082. hs:='FALSE';
  3083. end;
  3084. constnil :
  3085. hs:='nil';
  3086. constchar :
  3087. hs:=chr(hpc.value.valueord);
  3088. constset :
  3089. hs:='<set>';
  3090. end;
  3091. if hs<>'' then
  3092. s:=s+'="'+hs+'"';
  3093. end;
  3094. end;
  3095. hp:=TParaItem(hp.next);
  3096. end;
  3097. if not first then
  3098. s:=s+')';
  3099. if (po_varargs in procoptions) then
  3100. s:=s+';VarArgs';
  3101. typename_paras:=s;
  3102. end;
  3103. function tabstractprocdef.is_methodpointer:boolean;
  3104. begin
  3105. result:=false;
  3106. end;
  3107. function tabstractprocdef.is_addressonly:boolean;
  3108. begin
  3109. result:=true;
  3110. end;
  3111. {$ifdef GDB}
  3112. function tabstractprocdef.stabstring : pchar;
  3113. begin
  3114. stabstring := strpnew('abstractproc'+numberstring+';');
  3115. end;
  3116. procedure tabstractprocdef.concatstabto(asmlist : taasmoutput);
  3117. begin
  3118. { released procdef? }
  3119. if not assigned(parast) then
  3120. exit;
  3121. if (not assigned(typesym) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches))
  3122. and (is_def_stab_written = not_written) then
  3123. begin
  3124. if assigned(rettype.def) then forcestabto(asmlist,rettype.def);
  3125. inherited concatstabto(asmlist);
  3126. end;
  3127. end;
  3128. {$endif GDB}
  3129. {***************************************************************************
  3130. TPROCDEF
  3131. ***************************************************************************}
  3132. constructor tprocdef.create(level:byte);
  3133. begin
  3134. inherited create(level);
  3135. deftype:=procdef;
  3136. has_mangledname:=false;
  3137. _mangledname:=nil;
  3138. fileinfo:=aktfilepos;
  3139. extnumber:=$ffff;
  3140. aliasnames:=tstringlist.create;
  3141. funcretsym:=nil;
  3142. localst := nil;
  3143. defref:=nil;
  3144. lastwritten:=nil;
  3145. refcount:=0;
  3146. if (cs_browser in aktmoduleswitches) and make_ref then
  3147. begin
  3148. defref:=tref.create(defref,@akttokenpos);
  3149. inc(refcount);
  3150. end;
  3151. lastref:=defref;
  3152. forwarddef:=true;
  3153. interfacedef:=false;
  3154. hasforward:=false;
  3155. _class := nil;
  3156. { only for non inlined procedures loaded from a unit
  3157. we don't need this info
  3158. }
  3159. new(inlininginfo);
  3160. fillchar(inlininginfo^,sizeof(tinlininginfo),0);
  3161. overloadnumber:=0;
  3162. {$ifdef GDB}
  3163. isstabwritten := false;
  3164. {$endif GDB}
  3165. end;
  3166. constructor tprocdef.ppuload(ppufile:tcompilerppufile);
  3167. var
  3168. level : byte;
  3169. begin
  3170. inherited ppuload(ppufile);
  3171. deftype:=procdef;
  3172. has_mangledname:=boolean(ppufile.getbyte);
  3173. if has_mangledname then
  3174. _mangledname:=stringdup(ppufile.getstring)
  3175. else
  3176. _mangledname:=nil;
  3177. overloadnumber:=ppufile.getword;
  3178. extnumber:=ppufile.getword;
  3179. level:=ppufile.getbyte;
  3180. ppufile.getderef(_classderef);
  3181. ppufile.getderef(procsymderef);
  3182. ppufile.getposinfo(fileinfo);
  3183. ppufile.getsmallset(symoptions);
  3184. { inline stuff }
  3185. if proccalloption=pocall_inline then
  3186. ppufile.getderef(funcretsymderef)
  3187. else
  3188. funcretsym:=nil;
  3189. { load para symtable }
  3190. parast:=tparasymtable.create(level);
  3191. tparasymtable(parast).ppuload(ppufile);
  3192. parast.defowner:=self;
  3193. { load local symtable }
  3194. if (proccalloption=pocall_inline) or
  3195. ((current_module.flags and uf_local_browser)<>0) then
  3196. begin
  3197. localst:=tlocalsymtable.create(level);
  3198. tlocalsymtable(localst).ppuload(ppufile);
  3199. localst.defowner:=self;
  3200. end
  3201. else
  3202. localst:=nil;
  3203. { inline stuff }
  3204. if proccalloption=pocall_inline then
  3205. begin
  3206. new(inlininginfo);
  3207. inlininginfo^.code:=ppuloadnodetree(ppufile);
  3208. ppufile.getsmallset(inlininginfo^.flags);
  3209. end
  3210. else
  3211. inlininginfo := nil;
  3212. { default values for no persistent data }
  3213. if (cs_link_deffile in aktglobalswitches) and
  3214. (tf_need_export in target_info.flags) and
  3215. (po_exports in procoptions) then
  3216. deffile.AddExport(mangledname);
  3217. aliasnames:=tstringlist.create;
  3218. forwarddef:=false;
  3219. interfacedef:=false;
  3220. hasforward:=false;
  3221. lastref:=nil;
  3222. lastwritten:=nil;
  3223. defref:=nil;
  3224. refcount:=0;
  3225. {$ifdef GDB}
  3226. isstabwritten := false;
  3227. {$endif GDB}
  3228. end;
  3229. destructor tprocdef.destroy;
  3230. begin
  3231. if assigned(defref) then
  3232. begin
  3233. defref.freechain;
  3234. defref.free;
  3235. end;
  3236. aliasnames.free;
  3237. if assigned(localst) and (localst.symtabletype<>staticsymtable) then
  3238. begin
  3239. {$ifdef MEMDEBUG}
  3240. memproclocalst.start;
  3241. {$endif MEMDEBUG}
  3242. localst.free;
  3243. {$ifdef MEMDEBUG}
  3244. memproclocalst.start;
  3245. {$endif MEMDEBUG}
  3246. end;
  3247. if (proccalloption=pocall_inline) and assigned(inlininginfo) then
  3248. begin
  3249. {$ifdef MEMDEBUG}
  3250. memprocnodetree.start;
  3251. {$endif MEMDEBUG}
  3252. tnode(inlininginfo^.code).free;
  3253. {$ifdef MEMDEBUG}
  3254. memprocnodetree.start;
  3255. {$endif MEMDEBUG}
  3256. end;
  3257. if assigned(inlininginfo) then
  3258. dispose(inlininginfo);
  3259. if (po_msgstr in procoptions) then
  3260. strdispose(messageinf.str);
  3261. if assigned(_mangledname) then
  3262. begin
  3263. {$ifdef MEMDEBUG}
  3264. memmanglednames.start;
  3265. {$endif MEMDEBUG}
  3266. stringdispose(_mangledname);
  3267. {$ifdef MEMDEBUG}
  3268. memmanglednames.stop;
  3269. {$endif MEMDEBUG}
  3270. end;
  3271. inherited destroy;
  3272. end;
  3273. procedure tprocdef.ppuwrite(ppufile:tcompilerppufile);
  3274. var
  3275. oldintfcrc : boolean;
  3276. oldparasymtable,
  3277. oldlocalsymtable : tsymtable;
  3278. begin
  3279. { released procdef? }
  3280. if not assigned(parast) then
  3281. exit;
  3282. oldparasymtable:=aktparasymtable;
  3283. oldlocalsymtable:=aktlocalsymtable;
  3284. aktparasymtable:=parast;
  3285. aktlocalsymtable:=localst;
  3286. inherited ppuwrite(ppufile);
  3287. oldintfcrc:=ppufile.do_interface_crc;
  3288. ppufile.do_interface_crc:=false;
  3289. ppufile.do_interface_crc:=oldintfcrc;
  3290. ppufile.putbyte(byte(has_mangledname));
  3291. if has_mangledname then
  3292. ppufile.putstring(mangledname);
  3293. ppufile.putword(overloadnumber);
  3294. ppufile.putword(extnumber);
  3295. ppufile.putbyte(parast.symtablelevel);
  3296. ppufile.putderef(_classderef);
  3297. ppufile.putderef(procsymderef);
  3298. ppufile.putposinfo(fileinfo);
  3299. ppufile.putsmallset(symoptions);
  3300. { inline stuff }
  3301. oldintfcrc:=ppufile.do_crc;
  3302. ppufile.do_crc:=false;
  3303. if proccalloption=pocall_inline then
  3304. ppufile.putderef(funcretsymderef);
  3305. ppufile.do_crc:=oldintfcrc;
  3306. { write this entry }
  3307. ppufile.writeentry(ibprocdef);
  3308. { Save the para symtable, this is taken from the interface }
  3309. tparasymtable(parast).ppuwrite(ppufile);
  3310. { save localsymtable for inline procedures or when local
  3311. browser info is requested, this has no influence on the crc }
  3312. if (proccalloption=pocall_inline) or
  3313. ((current_module.flags and uf_local_browser)<>0) then
  3314. begin
  3315. oldintfcrc:=ppufile.do_crc;
  3316. ppufile.do_crc:=false;
  3317. if not assigned(localst) then
  3318. insert_localst;
  3319. tlocalsymtable(localst).ppuwrite(ppufile);
  3320. ppufile.do_crc:=oldintfcrc;
  3321. end;
  3322. { node tree for inlining }
  3323. oldintfcrc:=ppufile.do_crc;
  3324. ppufile.do_crc:=false;
  3325. if proccalloption=pocall_inline then
  3326. begin
  3327. ppuwritenodetree(ppufile,inlininginfo^.code);
  3328. ppufile.putsmallset(inlininginfo^.flags);
  3329. end;
  3330. ppufile.do_crc:=oldintfcrc;
  3331. aktparasymtable:=oldparasymtable;
  3332. aktlocalsymtable:=oldlocalsymtable;
  3333. end;
  3334. procedure tprocdef.insert_localst;
  3335. begin
  3336. localst:=tlocalsymtable.create(parast.symtablelevel);
  3337. localst.defowner:=self;
  3338. { this is used by insert
  3339. to check same names in parast and localst }
  3340. localst.next:=parast;
  3341. end;
  3342. function tprocdef.fullprocname(showhidden:boolean):string;
  3343. var
  3344. s : string;
  3345. t : ttoken;
  3346. begin
  3347. {$ifdef EXTDEBUG}
  3348. showhidden:=true;
  3349. {$endif EXTDEBUG}
  3350. s:='';
  3351. if assigned(_class) then
  3352. begin
  3353. if po_classmethod in procoptions then
  3354. s:=s+'class ';
  3355. s:=s+_class.objrealname^+'.';
  3356. end;
  3357. if proctypeoption=potype_operator then
  3358. begin
  3359. for t:=NOTOKEN to last_overloaded do
  3360. if procsym.realname='$'+overloaded_names[t] then
  3361. begin
  3362. s:='operator '+arraytokeninfo[t].str+typename_paras(showhidden);
  3363. break;
  3364. end;
  3365. end
  3366. else
  3367. s:=s+procsym.realname+typename_paras(showhidden);
  3368. case proctypeoption of
  3369. potype_constructor:
  3370. s:='constructor '+s;
  3371. potype_destructor:
  3372. s:='destructor '+s;
  3373. else
  3374. if assigned(rettype.def) and
  3375. not(is_void(rettype.def)) then
  3376. s:=s+':'+rettype.def.gettypename;
  3377. end;
  3378. { forced calling convention? }
  3379. if (po_hascallingconvention in procoptions) then
  3380. s:=s+';'+ProcCallOptionStr[proccalloption];
  3381. fullprocname:=s;
  3382. end;
  3383. function tprocdef.is_methodpointer:boolean;
  3384. begin
  3385. result:=assigned(_class);
  3386. end;
  3387. function tprocdef.is_addressonly:boolean;
  3388. begin
  3389. result:=assigned(owner) and
  3390. (owner.symtabletype<>objectsymtable);
  3391. end;
  3392. function tprocdef.is_visible_for_object(currobjdef:tobjectdef):boolean;
  3393. begin
  3394. is_visible_for_object:=false;
  3395. { private symbols are allowed when we are in the same
  3396. module as they are defined }
  3397. if (sp_private in symoptions) and
  3398. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  3399. (owner.defowner.owner.unitid<>0) then
  3400. exit;
  3401. { protected symbols are vissible in the module that defines them and
  3402. also visible to related objects. The related object must be defined
  3403. in the current module }
  3404. if (sp_protected in symoptions) and
  3405. (
  3406. (
  3407. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  3408. (owner.defowner.owner.unitid<>0)
  3409. ) and
  3410. not(
  3411. assigned(currobjdef) and
  3412. (currobjdef.owner.unitid=0) and
  3413. currobjdef.is_related(tobjectdef(owner.defowner))
  3414. )
  3415. ) then
  3416. exit;
  3417. is_visible_for_object:=true;
  3418. end;
  3419. function tprocdef.getsymtable(t:tgetsymtable):tsymtable;
  3420. begin
  3421. case t of
  3422. gs_local :
  3423. getsymtable:=localst;
  3424. gs_para :
  3425. getsymtable:=parast;
  3426. else
  3427. getsymtable:=nil;
  3428. end;
  3429. end;
  3430. procedure tprocdef.load_references(ppufile:tcompilerppufile;locals:boolean);
  3431. var
  3432. pos : tfileposinfo;
  3433. move_last : boolean;
  3434. oldparasymtable,
  3435. oldlocalsymtable : tsymtable;
  3436. begin
  3437. oldparasymtable:=aktparasymtable;
  3438. oldlocalsymtable:=aktlocalsymtable;
  3439. aktparasymtable:=parast;
  3440. aktlocalsymtable:=localst;
  3441. move_last:=lastwritten=lastref;
  3442. while (not ppufile.endofentry) do
  3443. begin
  3444. ppufile.getposinfo(pos);
  3445. inc(refcount);
  3446. lastref:=tref.create(lastref,@pos);
  3447. lastref.is_written:=true;
  3448. if refcount=1 then
  3449. defref:=lastref;
  3450. end;
  3451. if move_last then
  3452. lastwritten:=lastref;
  3453. if ((current_module.flags and uf_local_browser)<>0) and
  3454. locals then
  3455. begin
  3456. tparasymtable(parast).load_references(ppufile,locals);
  3457. tlocalsymtable(localst).load_references(ppufile,locals);
  3458. end;
  3459. aktparasymtable:=oldparasymtable;
  3460. aktlocalsymtable:=oldlocalsymtable;
  3461. end;
  3462. Const
  3463. local_symtable_index : word = $8001;
  3464. function tprocdef.write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  3465. var
  3466. ref : tref;
  3467. pdo : tobjectdef;
  3468. move_last : boolean;
  3469. d : tderef;
  3470. oldparasymtable,
  3471. oldlocalsymtable : tsymtable;
  3472. begin
  3473. d.reset;
  3474. move_last:=lastwritten=lastref;
  3475. if move_last and
  3476. (((current_module.flags and uf_local_browser)=0) or
  3477. not locals) then
  3478. exit;
  3479. oldparasymtable:=aktparasymtable;
  3480. oldlocalsymtable:=aktlocalsymtable;
  3481. aktparasymtable:=parast;
  3482. aktlocalsymtable:=localst;
  3483. { write address of this symbol }
  3484. d.build(self);
  3485. ppufile.putderef(d);
  3486. { write refs }
  3487. if assigned(lastwritten) then
  3488. ref:=lastwritten
  3489. else
  3490. ref:=defref;
  3491. while assigned(ref) do
  3492. begin
  3493. if ref.moduleindex=current_module.unit_index then
  3494. begin
  3495. ppufile.putposinfo(ref.posinfo);
  3496. ref.is_written:=true;
  3497. if move_last then
  3498. lastwritten:=ref;
  3499. end
  3500. else if not ref.is_written then
  3501. move_last:=false
  3502. else if move_last then
  3503. lastwritten:=ref;
  3504. ref:=ref.nextref;
  3505. end;
  3506. ppufile.writeentry(ibdefref);
  3507. write_references:=true;
  3508. if ((current_module.flags and uf_local_browser)<>0) and
  3509. locals then
  3510. begin
  3511. pdo:=_class;
  3512. if (owner.symtabletype<>localsymtable) then
  3513. while assigned(pdo) do
  3514. begin
  3515. if pdo.symtable<>aktrecordsymtable then
  3516. begin
  3517. pdo.symtable.unitid:=local_symtable_index;
  3518. inc(local_symtable_index);
  3519. end;
  3520. pdo:=pdo.childof;
  3521. end;
  3522. parast.unitid:=local_symtable_index;
  3523. inc(local_symtable_index);
  3524. localst.unitid:=local_symtable_index;
  3525. inc(local_symtable_index);
  3526. tstoredsymtable(parast).write_references(ppufile,locals);
  3527. tstoredsymtable(localst).write_references(ppufile,locals);
  3528. { decrement for }
  3529. local_symtable_index:=local_symtable_index-2;
  3530. pdo:=_class;
  3531. if (owner.symtabletype<>localsymtable) then
  3532. while assigned(pdo) do
  3533. begin
  3534. if pdo.symtable<>aktrecordsymtable then
  3535. dec(local_symtable_index);
  3536. pdo:=pdo.childof;
  3537. end;
  3538. end;
  3539. aktparasymtable:=oldparasymtable;
  3540. aktlocalsymtable:=oldlocalsymtable;
  3541. end;
  3542. {$ifdef GDB}
  3543. {$ifdef unused}
  3544. { procedure addparaname(p : tsym);
  3545. var vs : char;
  3546. begin
  3547. if tvarsym(p).varspez = vs_value then vs := '1'
  3548. else vs := '0';
  3549. strpcopy(strend(StabRecString),p^.name+':'+tstoreddef(tvarsym(p).vartype.def).numberstring+','+vs+';');
  3550. end; }
  3551. function tprocdef.stabstring : pchar;
  3552. var
  3553. i : longint;
  3554. stabrecstring : pchar;
  3555. begin
  3556. getmem(StabRecString,1024);
  3557. strpcopy(StabRecString,'f'+tstoreddef(rettype.def).numberstring);
  3558. i:=maxparacount;
  3559. if i>0 then
  3560. begin
  3561. strpcopy(strend(StabRecString),','+tostr(i)+';');
  3562. (* confuse gdb !! PM
  3563. if assigned(parast) then
  3564. parast.foreach({$ifdef FPCPROCVAR}@{$endif}addparaname)
  3565. else
  3566. begin
  3567. param := para1;
  3568. i := 0;
  3569. while assigned(param) do
  3570. begin
  3571. inc(i);
  3572. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  3573. {Here we have lost the parameter names !!}
  3574. {using lower case parameters }
  3575. strpcopy(strend(stabrecstring),'p'+tostr(i)
  3576. +':'+param^.paratype.def.numberstring+','+vartyp+';');
  3577. param := param^.next;
  3578. end;
  3579. end; *)
  3580. {strpcopy(strend(StabRecString),';');}
  3581. end;
  3582. stabstring := strnew(stabrecstring);
  3583. freemem(stabrecstring,1024);
  3584. end;
  3585. {$endif unused}
  3586. function tprocdef.stabstring: pchar;
  3587. Var RType : Char;
  3588. Obj,Info : String;
  3589. stabsstr : string;
  3590. p : pchar;
  3591. begin
  3592. obj := procsym.name;
  3593. info := '';
  3594. if tprocsym(procsym).is_global then
  3595. RType := 'F'
  3596. else
  3597. RType := 'f';
  3598. if assigned(owner) then
  3599. begin
  3600. if (owner.symtabletype = objectsymtable) then
  3601. obj := owner.name^+'__'+procsym.name;
  3602. { this code was correct only as long as the local symboltable
  3603. of the parent had the same name as the function
  3604. but this is no true anymore !! PM
  3605. if (owner.symtabletype=localsymtable) and assigned(owner.name) then
  3606. info := ','+name+','+owner.name^; }
  3607. if (owner.symtabletype=localsymtable) and
  3608. assigned(owner.defowner) and
  3609. assigned(tprocdef(owner.defowner).procsym) then
  3610. info := ','+procsym.name+','+tprocdef(owner.defowner).procsym.name;
  3611. end;
  3612. stabsstr:=mangledname;
  3613. getmem(p,length(stabsstr)+255);
  3614. strpcopy(p,'"'+obj+':'+RType
  3615. +tstoreddef(rettype.def).numberstring+info+'",'+tostr(n_function)
  3616. +',0,'+
  3617. tostr(fileinfo.line)
  3618. +',');
  3619. strpcopy(strend(p),stabsstr);
  3620. stabstring:=strnew(p);
  3621. freemem(p,length(stabsstr)+255);
  3622. end;
  3623. procedure tprocdef.concatstabto(asmlist : taasmoutput);
  3624. begin
  3625. { released procdef? }
  3626. if not assigned(parast) then
  3627. exit;
  3628. if (proccalloption=pocall_internproc) then
  3629. exit;
  3630. if not isstabwritten then
  3631. asmList.concat(Tai_stabs.Create(stabstring));
  3632. isstabwritten := true;
  3633. if not(po_external in procoptions) then
  3634. begin
  3635. tstoredsymtable(parast).concatstabto(asmlist);
  3636. { local type defs and vars should not be written
  3637. inside the main proc stab }
  3638. if assigned(localst) and
  3639. (localst.symtablelevel>main_program_level) then
  3640. tstoredsymtable(localst).concatstabto(asmlist);
  3641. end;
  3642. is_def_stab_written := written;
  3643. end;
  3644. {$endif GDB}
  3645. procedure tprocdef.buildderef;
  3646. var
  3647. oldparasymtable,
  3648. oldlocalsymtable : tsymtable;
  3649. begin
  3650. oldparasymtable:=aktparasymtable;
  3651. oldlocalsymtable:=aktlocalsymtable;
  3652. aktparasymtable:=parast;
  3653. aktlocalsymtable:=localst;
  3654. inherited buildderef;
  3655. _classderef.build(_class);
  3656. { procsym that originaly defined this definition, should be in the
  3657. same symtable }
  3658. procsymderef.build(procsym);
  3659. aktparasymtable:=oldparasymtable;
  3660. aktlocalsymtable:=oldlocalsymtable;
  3661. end;
  3662. procedure tprocdef.buildderefimpl;
  3663. var
  3664. oldparasymtable,
  3665. oldlocalsymtable : tsymtable;
  3666. begin
  3667. { released procdef? }
  3668. if not assigned(parast) then
  3669. exit;
  3670. oldparasymtable:=aktparasymtable;
  3671. oldlocalsymtable:=aktlocalsymtable;
  3672. aktparasymtable:=parast;
  3673. aktlocalsymtable:=localst;
  3674. inherited buildderefimpl;
  3675. { locals }
  3676. if assigned(localst) then
  3677. begin
  3678. tlocalsymtable(localst).buildderef;
  3679. tlocalsymtable(localst).buildderefimpl;
  3680. funcretsymderef.build(funcretsym);
  3681. end;
  3682. { inline tree }
  3683. if (proccalloption=pocall_inline) then
  3684. inlininginfo^.code.buildderefimpl;
  3685. aktparasymtable:=oldparasymtable;
  3686. aktlocalsymtable:=oldlocalsymtable;
  3687. end;
  3688. procedure tprocdef.deref;
  3689. var
  3690. oldparasymtable,
  3691. oldlocalsymtable : tsymtable;
  3692. begin
  3693. { released procdef? }
  3694. if not assigned(parast) then
  3695. exit;
  3696. oldparasymtable:=aktparasymtable;
  3697. oldlocalsymtable:=aktlocalsymtable;
  3698. aktparasymtable:=parast;
  3699. aktlocalsymtable:=localst;
  3700. inherited deref;
  3701. _class:=tobjectdef(_classderef.resolve);
  3702. { procsym that originaly defined this definition, should be in the
  3703. same symtable }
  3704. procsym:=tprocsym(procsymderef.resolve);
  3705. aktparasymtable:=oldparasymtable;
  3706. aktlocalsymtable:=oldlocalsymtable;
  3707. end;
  3708. procedure tprocdef.derefimpl;
  3709. var
  3710. oldparasymtable,
  3711. oldlocalsymtable : tsymtable;
  3712. begin
  3713. oldparasymtable:=aktparasymtable;
  3714. oldlocalsymtable:=aktlocalsymtable;
  3715. aktparasymtable:=parast;
  3716. aktlocalsymtable:=localst;
  3717. { locals }
  3718. if assigned(localst) then
  3719. begin
  3720. { localst }
  3721. { we can deref both interface and implementation parts }
  3722. tlocalsymtable(localst).deref;
  3723. tlocalsymtable(localst).derefimpl;
  3724. { funcretsym, this is always located in the localst }
  3725. funcretsym:=tsym(funcretsymderef.resolve);
  3726. end
  3727. else
  3728. begin
  3729. { safety }
  3730. funcretsym:=nil;
  3731. end;
  3732. { inline tree }
  3733. if (proccalloption=pocall_inline) then
  3734. inlininginfo^.code.derefimpl;
  3735. aktparasymtable:=oldparasymtable;
  3736. aktlocalsymtable:=oldlocalsymtable;
  3737. end;
  3738. function tprocdef.gettypename : string;
  3739. begin
  3740. gettypename := FullProcName(false);
  3741. end;
  3742. function tprocdef.mangledname : string;
  3743. var
  3744. s : string;
  3745. hp : TParaItem;
  3746. begin
  3747. if assigned(_mangledname) then
  3748. begin
  3749. mangledname:=_mangledname^;
  3750. exit;
  3751. end;
  3752. { we need to use the symtable where the procsym is inserted,
  3753. because that is visible to the world }
  3754. s:=make_mangledname('',procsym.owner,procsym.name);
  3755. if overloadnumber>0 then
  3756. s:=s+'$'+tostr(overloadnumber);
  3757. { add parameter types }
  3758. hp:=TParaItem(Para.first);
  3759. while assigned(hp) do
  3760. begin
  3761. if not hp.is_hidden then
  3762. s:=s+'$'+hp.paratype.def.mangledparaname;
  3763. hp:=TParaItem(hp.next);
  3764. end;
  3765. _mangledname:=stringdup(s);
  3766. mangledname:=_mangledname^;
  3767. end;
  3768. function tprocdef.cplusplusmangledname : string;
  3769. function getcppparaname(p : tdef) : string;
  3770. const
  3771. ordtype2str : array[tbasetype] of string[2] = (
  3772. '',
  3773. 'Uc','Us','Ui','Us',
  3774. 'Sc','s','i','x',
  3775. 'b','b','b',
  3776. 'c','w','x');
  3777. var
  3778. s : string;
  3779. begin
  3780. case p.deftype of
  3781. orddef:
  3782. s:=ordtype2str[torddef(p).typ];
  3783. pointerdef:
  3784. s:='P'+getcppparaname(tpointerdef(p).pointertype.def);
  3785. else
  3786. internalerror(2103001);
  3787. end;
  3788. getcppparaname:=s;
  3789. end;
  3790. var
  3791. s,s2 : string;
  3792. param : TParaItem;
  3793. begin
  3794. s := procsym.realname;
  3795. if procsym.owner.symtabletype=objectsymtable then
  3796. begin
  3797. s2:=upper(tobjectdef(procsym.owner.defowner).typesym.realname);
  3798. case proctypeoption of
  3799. potype_destructor:
  3800. s:='_$_'+tostr(length(s2))+s2;
  3801. potype_constructor:
  3802. s:='___'+tostr(length(s2))+s2;
  3803. else
  3804. s:='_'+s+'__'+tostr(length(s2))+s2;
  3805. end;
  3806. end
  3807. else s:=s+'__';
  3808. s:=s+'F';
  3809. { concat modifiers }
  3810. { !!!!! }
  3811. { now we handle the parameters }
  3812. param := TParaItem(Para.first);
  3813. if assigned(param) then
  3814. while assigned(param) do
  3815. begin
  3816. s2:=getcppparaname(param.paratype.def);
  3817. if param.paratyp in [vs_var,vs_out] then
  3818. s2:='R'+s2;
  3819. s:=s+s2;
  3820. param:=TParaItem(param.next);
  3821. end
  3822. else
  3823. s:=s+'v';
  3824. cplusplusmangledname:=s;
  3825. end;
  3826. procedure tprocdef.setmangledname(const s : string);
  3827. begin
  3828. stringdispose(_mangledname);
  3829. _mangledname:=stringdup(s);
  3830. has_mangledname:=true;
  3831. end;
  3832. {***************************************************************************
  3833. TPROCVARDEF
  3834. ***************************************************************************}
  3835. constructor tprocvardef.create(level:byte);
  3836. begin
  3837. inherited create(level);
  3838. deftype:=procvardef;
  3839. end;
  3840. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  3841. begin
  3842. inherited ppuload(ppufile);
  3843. deftype:=procvardef;
  3844. { load para symtable }
  3845. parast:=tparasymtable.create(unknown_level);
  3846. tparasymtable(parast).ppuload(ppufile);
  3847. parast.defowner:=self;
  3848. end;
  3849. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  3850. var
  3851. oldparasymtable,
  3852. oldlocalsymtable : tsymtable;
  3853. begin
  3854. oldparasymtable:=aktparasymtable;
  3855. oldlocalsymtable:=aktlocalsymtable;
  3856. aktparasymtable:=parast;
  3857. aktlocalsymtable:=nil;
  3858. { here we cannot get a real good value so just give something }
  3859. { plausible (PM) }
  3860. { a more secure way would be
  3861. to allways store in a temp }
  3862. {$ifdef i386}
  3863. if is_fpu(rettype.def) then
  3864. fpu_used:={2}maxfpuregs
  3865. else
  3866. fpu_used:=0;
  3867. {$endif i386}
  3868. inherited ppuwrite(ppufile);
  3869. { Write this entry }
  3870. ppufile.writeentry(ibprocvardef);
  3871. { Save the para symtable, this is taken from the interface }
  3872. tparasymtable(parast).ppuwrite(ppufile);
  3873. aktparasymtable:=oldparasymtable;
  3874. aktlocalsymtable:=oldlocalsymtable;
  3875. end;
  3876. procedure tprocvardef.buildderef;
  3877. var
  3878. oldparasymtable,
  3879. oldlocalsymtable : tsymtable;
  3880. begin
  3881. oldparasymtable:=aktparasymtable;
  3882. oldlocalsymtable:=aktlocalsymtable;
  3883. aktparasymtable:=parast;
  3884. aktlocalsymtable:=nil;
  3885. inherited buildderef;
  3886. aktparasymtable:=oldparasymtable;
  3887. aktlocalsymtable:=oldlocalsymtable;
  3888. end;
  3889. procedure tprocvardef.deref;
  3890. var
  3891. oldparasymtable,
  3892. oldlocalsymtable : tsymtable;
  3893. begin
  3894. oldparasymtable:=aktparasymtable;
  3895. oldlocalsymtable:=aktlocalsymtable;
  3896. aktparasymtable:=parast;
  3897. aktlocalsymtable:=nil;
  3898. inherited deref;
  3899. aktparasymtable:=oldparasymtable;
  3900. aktlocalsymtable:=oldlocalsymtable;
  3901. end;
  3902. function tprocvardef.getsymtable(t:tgetsymtable):tsymtable;
  3903. begin
  3904. case t of
  3905. gs_para :
  3906. getsymtable:=parast;
  3907. else
  3908. getsymtable:=nil;
  3909. end;
  3910. end;
  3911. function tprocvardef.size : longint;
  3912. begin
  3913. if (po_methodpointer in procoptions) and
  3914. not(po_addressonly in procoptions) then
  3915. size:=2*POINTER_SIZE
  3916. else
  3917. size:=POINTER_SIZE;
  3918. end;
  3919. function tprocvardef.is_methodpointer:boolean;
  3920. begin
  3921. result:=(po_methodpointer in procoptions);
  3922. end;
  3923. function tprocvardef.is_addressonly:boolean;
  3924. begin
  3925. result:=not(po_methodpointer in procoptions) or
  3926. (po_addressonly in procoptions);
  3927. end;
  3928. {$ifdef GDB}
  3929. function tprocvardef.stabstring : pchar;
  3930. var
  3931. nss : pchar;
  3932. { i : longint; }
  3933. begin
  3934. { i := maxparacount; }
  3935. getmem(nss,1024);
  3936. { it is not a function but a function pointer !! (PM) }
  3937. strpcopy(nss,'*f'+tstoreddef(rettype.def).numberstring{+','+tostr(i)}+';');
  3938. { this confuses gdb !!
  3939. we should use 'F' instead of 'f' but
  3940. as we use c++ language mode
  3941. it does not like that either
  3942. Please do not remove this part
  3943. might be used once
  3944. gdb for pascal is ready PM }
  3945. (*
  3946. param := para1;
  3947. i := 0;
  3948. while assigned(param) do
  3949. begin
  3950. inc(i);
  3951. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  3952. {Here we have lost the parameter names !!}
  3953. pst := strpnew('p'+tostr(i)+':'+param^.paratype.def.numberstring+','+vartyp+';');
  3954. strcat(nss,pst);
  3955. strdispose(pst);
  3956. param := param^.next;
  3957. end; *)
  3958. {strpcopy(strend(nss),';');}
  3959. stabstring := strnew(nss);
  3960. freemem(nss,1024);
  3961. end;
  3962. procedure tprocvardef.concatstabto(asmlist : taasmoutput);
  3963. begin
  3964. if ( not assigned(typesym) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches))
  3965. and (is_def_stab_written = not_written) then
  3966. inherited concatstabto(asmlist);
  3967. is_def_stab_written:=written;
  3968. end;
  3969. {$endif GDB}
  3970. procedure tprocvardef.write_rtti_data(rt:trttitype);
  3971. var
  3972. pdc : TParaItem;
  3973. methodkind, paraspec : byte;
  3974. begin
  3975. if po_methodpointer in procoptions then
  3976. begin
  3977. { write method id and name }
  3978. rttiList.concat(Tai_const.Create_8bit(tkmethod));
  3979. write_rtti_name;
  3980. { write kind of method (can only be function or procedure)}
  3981. if rettype.def = voidtype.def then
  3982. methodkind := mkProcedure
  3983. else
  3984. methodkind := mkFunction;
  3985. rttiList.concat(Tai_const.Create_8bit(methodkind));
  3986. { get # of parameters }
  3987. rttiList.concat(Tai_const.Create_8bit(maxparacount));
  3988. { write parameter info. The parameters must be written in reverse order
  3989. if this method uses right to left parameter pushing! }
  3990. if proccalloption in pushleftright_pocalls then
  3991. pdc:=TParaItem(Para.first)
  3992. else
  3993. pdc:=TParaItem(Para.last);
  3994. while assigned(pdc) do
  3995. begin
  3996. case pdc.paratyp of
  3997. vs_value: paraspec := 0;
  3998. vs_const: paraspec := pfConst;
  3999. vs_var : paraspec := pfVar;
  4000. vs_out : paraspec := pfOut;
  4001. end;
  4002. { write flags for current parameter }
  4003. rttiList.concat(Tai_const.Create_8bit(paraspec));
  4004. { write name of current parameter ### how can I get this??? (sg)}
  4005. rttiList.concat(Tai_const.Create_8bit(0));
  4006. { write name of type of current parameter }
  4007. tstoreddef(pdc.paratype.def).write_rtti_name;
  4008. if proccalloption in pushleftright_pocalls then
  4009. pdc:=TParaItem(pdc.next)
  4010. else
  4011. pdc:=TParaItem(pdc.previous);
  4012. end;
  4013. { write name of result type }
  4014. tstoreddef(rettype.def).write_rtti_name;
  4015. end;
  4016. end;
  4017. function tprocvardef.is_publishable : boolean;
  4018. begin
  4019. is_publishable:=(po_methodpointer in procoptions);
  4020. end;
  4021. function tprocvardef.gettypename : string;
  4022. var
  4023. s: string;
  4024. showhidden : boolean;
  4025. begin
  4026. {$ifdef EXTDEBUG}
  4027. showhidden:=true;
  4028. {$else EXTDEBUG}
  4029. showhidden:=false;
  4030. {$endif EXTDEBUG}
  4031. s:='<';
  4032. if po_classmethod in procoptions then
  4033. s := s+'class method type of'
  4034. else
  4035. if po_addressonly in procoptions then
  4036. s := s+'address of'
  4037. else
  4038. s := s+'procedure variable type of';
  4039. if assigned(rettype.def) and
  4040. (rettype.def<>voidtype.def) then
  4041. s:=s+' function'+typename_paras(showhidden)+':'+rettype.def.gettypename
  4042. else
  4043. s:=s+' procedure'+typename_paras(showhidden);
  4044. if po_methodpointer in procoptions then
  4045. s := s+' of object';
  4046. gettypename := s+';'+ProcCallOptionStr[proccalloption]+'>';
  4047. end;
  4048. {***************************************************************************
  4049. TOBJECTDEF
  4050. ***************************************************************************}
  4051. constructor tobjectdef.create(ot : tobjectdeftype;const n : string;c : tobjectdef);
  4052. begin
  4053. inherited create;
  4054. objecttype:=ot;
  4055. deftype:=objectdef;
  4056. objectoptions:=[];
  4057. childof:=nil;
  4058. symtable:=tobjectsymtable.create(n);
  4059. { create space for vmt !! }
  4060. vmt_offset:=0;
  4061. symtable.defowner:=self;
  4062. { recordalign -1 means C record packing, that starts
  4063. with an alignment of 1 }
  4064. if aktalignment.recordalignmax=-1 then
  4065. tobjectsymtable(symtable).dataalignment:=1
  4066. else
  4067. tobjectsymtable(symtable).dataalignment:=aktalignment.recordalignmax;
  4068. lastvtableindex:=0;
  4069. set_parent(c);
  4070. objname:=stringdup(upper(n));
  4071. objrealname:=stringdup(n);
  4072. if objecttype in [odt_interfacecorba,odt_interfacecom] then
  4073. prepareguid;
  4074. { setup implemented interfaces }
  4075. if objecttype in [odt_class,odt_interfacecorba] then
  4076. implementedinterfaces:=timplementedinterfaces.create
  4077. else
  4078. implementedinterfaces:=nil;
  4079. {$ifdef GDB}
  4080. writing_class_record_stab:=false;
  4081. {$endif GDB}
  4082. end;
  4083. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  4084. var
  4085. i,implintfcount: longint;
  4086. d : tderef;
  4087. begin
  4088. inherited ppuloaddef(ppufile);
  4089. deftype:=objectdef;
  4090. objecttype:=tobjectdeftype(ppufile.getbyte);
  4091. savesize:=ppufile.getlongint;
  4092. vmt_offset:=ppufile.getlongint;
  4093. objrealname:=stringdup(ppufile.getstring);
  4094. objname:=stringdup(upper(objrealname^));
  4095. ppufile.getderef(childofderef);
  4096. ppufile.getsmallset(objectoptions);
  4097. { load guid }
  4098. iidstr:=nil;
  4099. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4100. begin
  4101. new(iidguid);
  4102. ppufile.getguid(iidguid^);
  4103. iidstr:=stringdup(ppufile.getstring);
  4104. lastvtableindex:=ppufile.getlongint;
  4105. end;
  4106. { load implemented interfaces }
  4107. if objecttype in [odt_class,odt_interfacecorba] then
  4108. begin
  4109. implementedinterfaces:=timplementedinterfaces.create;
  4110. implintfcount:=ppufile.getlongint;
  4111. for i:=1 to implintfcount do
  4112. begin
  4113. ppufile.getderef(d);
  4114. implementedinterfaces.addintf_deref(d);
  4115. implementedinterfaces.ioffsets(i)^:=ppufile.getlongint;
  4116. end;
  4117. end
  4118. else
  4119. implementedinterfaces:=nil;
  4120. symtable:=tobjectsymtable.create(objrealname^);
  4121. tobjectsymtable(symtable).datasize:=ppufile.getlongint;
  4122. tobjectsymtable(symtable).dataalignment:=ppufile.getbyte;
  4123. tobjectsymtable(symtable).ppuload(ppufile);
  4124. symtable.defowner:=self;
  4125. { handles the predefined class tobject }
  4126. { the last TOBJECT which is loaded gets }
  4127. { it ! }
  4128. if (childof=nil) and
  4129. (objecttype=odt_class) and
  4130. (objname^='TOBJECT') then
  4131. class_tobject:=self;
  4132. if (childof=nil) and
  4133. (objecttype=odt_interfacecom) and
  4134. (objname^='IUNKNOWN') then
  4135. interface_iunknown:=self;
  4136. {$ifdef GDB}
  4137. writing_class_record_stab:=false;
  4138. {$endif GDB}
  4139. end;
  4140. destructor tobjectdef.destroy;
  4141. begin
  4142. if assigned(symtable) then
  4143. symtable.free;
  4144. stringdispose(objname);
  4145. stringdispose(objrealname);
  4146. if assigned(iidstr) then
  4147. stringdispose(iidstr);
  4148. if assigned(implementedinterfaces) then
  4149. implementedinterfaces.free;
  4150. if assigned(iidguid) then
  4151. dispose(iidguid);
  4152. inherited destroy;
  4153. end;
  4154. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  4155. var
  4156. implintfcount : longint;
  4157. i : longint;
  4158. begin
  4159. inherited ppuwritedef(ppufile);
  4160. ppufile.putbyte(byte(objecttype));
  4161. ppufile.putlongint(size);
  4162. ppufile.putlongint(vmt_offset);
  4163. ppufile.putstring(objrealname^);
  4164. ppufile.putderef(childofderef);
  4165. ppufile.putsmallset(objectoptions);
  4166. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4167. begin
  4168. ppufile.putguid(iidguid^);
  4169. ppufile.putstring(iidstr^);
  4170. ppufile.putlongint(lastvtableindex);
  4171. end;
  4172. if objecttype in [odt_class,odt_interfacecorba] then
  4173. begin
  4174. implintfcount:=implementedinterfaces.count;
  4175. ppufile.putlongint(implintfcount);
  4176. for i:=1 to implintfcount do
  4177. begin
  4178. ppufile.putderef(implementedinterfaces.interfacesderef(i));
  4179. ppufile.putlongint(implementedinterfaces.ioffsets(i)^);
  4180. end;
  4181. end;
  4182. ppufile.putlongint(tobjectsymtable(symtable).datasize);
  4183. ppufile.putbyte(tobjectsymtable(symtable).dataalignment);
  4184. ppufile.writeentry(ibobjectdef);
  4185. tobjectsymtable(symtable).ppuwrite(ppufile);
  4186. end;
  4187. function tobjectdef.gettypename:string;
  4188. begin
  4189. gettypename:=typename;
  4190. end;
  4191. procedure tobjectdef.buildderef;
  4192. var
  4193. oldrecsyms : tsymtable;
  4194. begin
  4195. inherited buildderef;
  4196. childofderef.build(childof);
  4197. oldrecsyms:=aktrecordsymtable;
  4198. aktrecordsymtable:=symtable;
  4199. tstoredsymtable(symtable).buildderef;
  4200. aktrecordsymtable:=oldrecsyms;
  4201. if objecttype in [odt_class,odt_interfacecorba] then
  4202. implementedinterfaces.buildderef;
  4203. end;
  4204. procedure tobjectdef.deref;
  4205. var
  4206. oldrecsyms : tsymtable;
  4207. begin
  4208. inherited deref;
  4209. childof:=tobjectdef(childofderef.resolve);
  4210. oldrecsyms:=aktrecordsymtable;
  4211. aktrecordsymtable:=symtable;
  4212. tstoredsymtable(symtable).deref;
  4213. aktrecordsymtable:=oldrecsyms;
  4214. if objecttype in [odt_class,odt_interfacecorba] then
  4215. implementedinterfaces.deref;
  4216. end;
  4217. function tobjectdef.getparentdef:tdef;
  4218. begin
  4219. result:=childof;
  4220. end;
  4221. procedure tobjectdef.prepareguid;
  4222. begin
  4223. { set up guid }
  4224. if not assigned(iidguid) then
  4225. begin
  4226. new(iidguid);
  4227. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  4228. end;
  4229. { setup iidstring }
  4230. if not assigned(iidstr) then
  4231. iidstr:=stringdup(''); { default is empty string }
  4232. end;
  4233. procedure tobjectdef.set_parent( c : tobjectdef);
  4234. begin
  4235. { nothing to do if the parent was not forward !}
  4236. if assigned(childof) then
  4237. exit;
  4238. childof:=c;
  4239. { some options are inherited !! }
  4240. if assigned(c) then
  4241. begin
  4242. { only important for classes }
  4243. lastvtableindex:=c.lastvtableindex;
  4244. objectoptions:=objectoptions+(c.objectoptions*
  4245. [oo_has_virtual,oo_has_private,oo_has_protected,
  4246. oo_has_constructor,oo_has_destructor]);
  4247. if not (objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4248. begin
  4249. { add the data of the anchestor class }
  4250. inc(tobjectsymtable(symtable).datasize,tobjectsymtable(c.symtable).datasize);
  4251. if (oo_has_vmt in objectoptions) and
  4252. (oo_has_vmt in c.objectoptions) then
  4253. dec(tobjectsymtable(symtable).datasize,POINTER_SIZE);
  4254. { if parent has a vmt field then
  4255. the offset is the same for the child PM }
  4256. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  4257. begin
  4258. vmt_offset:=c.vmt_offset;
  4259. include(objectoptions,oo_has_vmt);
  4260. end;
  4261. end;
  4262. end;
  4263. savesize := tobjectsymtable(symtable).datasize;
  4264. end;
  4265. procedure tobjectdef.insertvmt;
  4266. begin
  4267. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4268. exit;
  4269. if (oo_has_vmt in objectoptions) then
  4270. internalerror(12345)
  4271. else
  4272. begin
  4273. tobjectsymtable(symtable).datasize:=align(tobjectsymtable(symtable).datasize,
  4274. tobjectsymtable(symtable).dataalignment);
  4275. vmt_offset:=tobjectsymtable(symtable).datasize;
  4276. inc(tobjectsymtable(symtable).datasize,POINTER_SIZE);
  4277. include(objectoptions,oo_has_vmt);
  4278. end;
  4279. end;
  4280. procedure tobjectdef.check_forwards;
  4281. begin
  4282. if not(objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4283. tstoredsymtable(symtable).check_forwards;
  4284. if (oo_is_forward in objectoptions) then
  4285. begin
  4286. { ok, in future, the forward can be resolved }
  4287. Message1(sym_e_class_forward_not_resolved,objrealname^);
  4288. exclude(objectoptions,oo_is_forward);
  4289. end;
  4290. end;
  4291. { true, if self inherits from d (or if they are equal) }
  4292. function tobjectdef.is_related(d : tobjectdef) : boolean;
  4293. var
  4294. hp : tobjectdef;
  4295. begin
  4296. hp:=self;
  4297. while assigned(hp) do
  4298. begin
  4299. if hp=d then
  4300. begin
  4301. is_related:=true;
  4302. exit;
  4303. end;
  4304. hp:=hp.childof;
  4305. end;
  4306. is_related:=false;
  4307. end;
  4308. (* procedure tobjectdef._searchdestructor(sym : tnamedindexitem;arg:pointer);
  4309. var
  4310. p : pprocdeflist;
  4311. begin
  4312. { if we found already a destructor, then we exit }
  4313. if assigned(sd) then
  4314. exit;
  4315. if tsym(sym).typ=procsym then
  4316. begin
  4317. p:=tprocsym(sym).defs;
  4318. while assigned(p) do
  4319. begin
  4320. if p^.def.proctypeoption=potype_destructor then
  4321. begin
  4322. sd:=p^.def;
  4323. exit;
  4324. end;
  4325. p:=p^.next;
  4326. end;
  4327. end;
  4328. end;*)
  4329. procedure _searchdestructor(sym:Tnamedindexitem;sd:pointer);
  4330. begin
  4331. { if we found already a destructor, then we exit }
  4332. if (ppointer(sd)^=nil) and
  4333. (Tsym(sym).typ=procsym) then
  4334. ppointer(sd)^:=Tprocsym(sym).search_procdef_bytype(potype_destructor);
  4335. end;
  4336. function tobjectdef.searchdestructor : tprocdef;
  4337. var
  4338. o : tobjectdef;
  4339. sd : tprocdef;
  4340. begin
  4341. searchdestructor:=nil;
  4342. o:=self;
  4343. sd:=nil;
  4344. while assigned(o) do
  4345. begin
  4346. o.symtable.foreach_static({$ifdef FPCPROCVAR}@{$endif}_searchdestructor,@sd);
  4347. if assigned(sd) then
  4348. begin
  4349. searchdestructor:=sd;
  4350. exit;
  4351. end;
  4352. o:=o.childof;
  4353. end;
  4354. end;
  4355. function tobjectdef.size : longint;
  4356. begin
  4357. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba] then
  4358. result:=POINTER_SIZE
  4359. else
  4360. result:=tobjectsymtable(symtable).datasize;
  4361. end;
  4362. function tobjectdef.alignment:longint;
  4363. begin
  4364. alignment:=tobjectsymtable(symtable).dataalignment;
  4365. end;
  4366. function tobjectdef.vmtmethodoffset(index:longint):longint;
  4367. begin
  4368. { for offset of methods for classes, see rtl/inc/objpash.inc }
  4369. case objecttype of
  4370. odt_class:
  4371. vmtmethodoffset:=(index+12)*POINTER_SIZE;
  4372. odt_interfacecom,odt_interfacecorba:
  4373. vmtmethodoffset:=index*POINTER_SIZE;
  4374. else
  4375. {$ifdef WITHDMT}
  4376. vmtmethodoffset:=(index+4)*POINTER_SIZE;
  4377. {$else WITHDMT}
  4378. vmtmethodoffset:=(index+3)*POINTER_SIZE;
  4379. {$endif WITHDMT}
  4380. end;
  4381. end;
  4382. function tobjectdef.vmt_mangledname : string;
  4383. begin
  4384. if not(oo_has_vmt in objectoptions) then
  4385. Message1(parser_n_object_has_no_vmt,objrealname^);
  4386. vmt_mangledname:=make_mangledname('VMT',owner,objname^);
  4387. end;
  4388. function tobjectdef.rtti_name : string;
  4389. begin
  4390. rtti_name:=make_mangledname('RTTI',owner,objname^);
  4391. end;
  4392. {$ifdef GDB}
  4393. procedure tobjectdef.addprocname(p :tnamedindexitem;arg:pointer);
  4394. var virtualind,argnames : string;
  4395. news, newrec : pchar;
  4396. pd,ipd : tprocdef;
  4397. lindex : longint;
  4398. para : TParaItem;
  4399. arglength : byte;
  4400. sp : char;
  4401. begin
  4402. If tsym(p).typ = procsym then
  4403. begin
  4404. pd := tprocsym(p).first_procdef;
  4405. { this will be used for full implementation of object stabs
  4406. not yet done }
  4407. ipd := Tprocsym(p).last_procdef;
  4408. if (po_virtualmethod in pd.procoptions) then
  4409. begin
  4410. lindex := pd.extnumber;
  4411. {doesnt seem to be necessary
  4412. lindex := lindex or $80000000;}
  4413. virtualind := '*'+tostr(lindex)+';'+ipd._class.classnumberstring+';'
  4414. end
  4415. else
  4416. virtualind := '.';
  4417. { used by gdbpas to recognize constructor and destructors }
  4418. if (pd.proctypeoption=potype_constructor) then
  4419. argnames:='__ct__'
  4420. else if (pd.proctypeoption=potype_destructor) then
  4421. argnames:='__dt__'
  4422. else
  4423. argnames := '';
  4424. { arguments are not listed here }
  4425. {we don't need another definition}
  4426. para := TParaItem(pd.Para.first);
  4427. while assigned(para) do
  4428. begin
  4429. if Para.paratype.def.deftype = formaldef then
  4430. begin
  4431. if Para.paratyp=vs_var then
  4432. argnames := argnames+'3var'
  4433. else if Para.paratyp=vs_const then
  4434. argnames:=argnames+'5const'
  4435. else if Para.paratyp=vs_out then
  4436. argnames:=argnames+'3out';
  4437. end
  4438. else
  4439. begin
  4440. { if the arg definition is like (v: ^byte;..
  4441. there is no sym attached to data !!! }
  4442. if assigned(Para.paratype.def.typesym) then
  4443. begin
  4444. arglength := length(Para.paratype.def.typesym.name);
  4445. argnames := argnames + tostr(arglength)+Para.paratype.def.typesym.name;
  4446. end
  4447. else
  4448. begin
  4449. argnames:=argnames+'11unnamedtype';
  4450. end;
  4451. end;
  4452. para := TParaItem(Para.next);
  4453. end;
  4454. ipd.is_def_stab_written := written;
  4455. { here 2A must be changed for private and protected }
  4456. { 0 is private 1 protected and 2 public }
  4457. if (sp_private in tsym(p).symoptions) then sp:='0'
  4458. else if (sp_protected in tsym(p).symoptions) then sp:='1'
  4459. else sp:='2';
  4460. newrec := strpnew(p.name+'::'+ipd.numberstring
  4461. +'=##'+tstoreddef(pd.rettype.def).numberstring+';:'+argnames+';'+sp+'A'
  4462. +virtualind+';');
  4463. { get spare place for a string at the end }
  4464. if strlen(StabRecString) + strlen(newrec) >= StabRecSize-256 then
  4465. begin
  4466. getmem(news,stabrecsize+memsizeinc);
  4467. strcopy(news,stabrecstring);
  4468. freemem(stabrecstring,stabrecsize);
  4469. stabrecsize:=stabrecsize+memsizeinc;
  4470. stabrecstring:=news;
  4471. end;
  4472. strcat(StabRecstring,newrec);
  4473. {freemem(newrec,memsizeinc); }
  4474. strdispose(newrec);
  4475. {This should be used for case !!
  4476. RecOffset := RecOffset + pd.size;}
  4477. end;
  4478. end;
  4479. function tobjectdef.stabstring : pchar;
  4480. var anc : tobjectdef;
  4481. oldrec : pchar;
  4482. oldrecsize,oldrecoffset : longint;
  4483. str_end : string;
  4484. begin
  4485. if not (objecttype=odt_class) or writing_class_record_stab then
  4486. begin
  4487. oldrec := stabrecstring;
  4488. oldrecsize:=stabrecsize;
  4489. stabrecsize:=memsizeinc;
  4490. GetMem(stabrecstring,stabrecsize);
  4491. strpcopy(stabRecString,'s'+tostr(tobjectsymtable(symtable).datasize));
  4492. if assigned(childof) then
  4493. begin
  4494. {only one ancestor not virtual, public, at base offset 0 }
  4495. { !1 , 0 2 0 , }
  4496. strpcopy(strend(stabrecstring),'!1,020,'+childof.classnumberstring+';');
  4497. end;
  4498. {virtual table to implement yet}
  4499. OldRecOffset:=RecOffset;
  4500. RecOffset := 0;
  4501. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}addname,nil);
  4502. RecOffset:=OldRecOffset;
  4503. if (oo_has_vmt in objectoptions) then
  4504. if not assigned(childof) or not(oo_has_vmt in childof.objectoptions) then
  4505. begin
  4506. strpcopy(strend(stabrecstring),'$vf'+classnumberstring+':'+typeglobalnumber('vtblarray')
  4507. +','+tostr(vmt_offset*8)+';');
  4508. end;
  4509. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}addprocname,nil);
  4510. if (oo_has_vmt in objectoptions) then
  4511. begin
  4512. anc := self;
  4513. while assigned(anc.childof) and (oo_has_vmt in anc.childof.objectoptions) do
  4514. anc := anc.childof;
  4515. { just in case anc = self }
  4516. str_end:=';~%'+anc.classnumberstring+';';
  4517. end
  4518. else
  4519. str_end:=';';
  4520. strpcopy(strend(stabrecstring),str_end);
  4521. stabstring := strnew(StabRecString);
  4522. freemem(stabrecstring,stabrecsize);
  4523. stabrecstring := oldrec;
  4524. stabrecsize:=oldrecsize;
  4525. end
  4526. else
  4527. begin
  4528. stabstring:=strpnew('*'+classnumberstring);
  4529. end;
  4530. end;
  4531. procedure tobjectdef.set_globalnb;
  4532. begin
  4533. globalnb:=PglobalTypeCount^;
  4534. inc(PglobalTypeCount^);
  4535. { classes need two type numbers, the globalnb is set to the ptr }
  4536. if objecttype=odt_class then
  4537. begin
  4538. globalnb:=PGlobalTypeCount^;
  4539. inc(PglobalTypeCount^);
  4540. end;
  4541. end;
  4542. function tobjectdef.classnumberstring : string;
  4543. begin
  4544. { write stabs again if needed }
  4545. numberstring;
  4546. if objecttype=odt_class then
  4547. begin
  4548. dec(globalnb);
  4549. classnumberstring:=numberstring;
  4550. inc(globalnb);
  4551. end
  4552. else
  4553. classnumberstring:=numberstring;
  4554. end;
  4555. function tobjectdef.allstabstring : pchar;
  4556. var stabchar : string[2];
  4557. ss,st : pchar;
  4558. sname : string;
  4559. sym_line_no : longint;
  4560. begin
  4561. ss := stabstring;
  4562. getmem(st,strlen(ss)+512);
  4563. stabchar := 't';
  4564. if deftype in tagtypes then
  4565. stabchar := 'Tt';
  4566. if assigned(typesym) then
  4567. begin
  4568. sname := typesym.name;
  4569. sym_line_no:=typesym.fileinfo.line;
  4570. end
  4571. else
  4572. begin
  4573. sname := ' ';
  4574. sym_line_no:=0;
  4575. end;
  4576. if writing_class_record_stab then
  4577. strpcopy(st,'"'+sname+':'+stabchar+classnumberstring+'=')
  4578. else
  4579. strpcopy(st,'"'+sname+':'+stabchar+numberstring+'=');
  4580. strpcopy(strecopy(strend(st),ss),'",'+tostr(N_LSYM)+',0,'+tostr(sym_line_no)+',0');
  4581. allstabstring := strnew(st);
  4582. freemem(st,strlen(ss)+512);
  4583. strdispose(ss);
  4584. end;
  4585. procedure tobjectdef.concatstabto(asmlist : taasmoutput);
  4586. var st : pstring;
  4587. begin
  4588. if objecttype<>odt_class then
  4589. begin
  4590. inherited concatstabto(asmlist);
  4591. exit;
  4592. end;
  4593. if ((typesym=nil) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches)) and
  4594. (is_def_stab_written = not_written) then
  4595. begin
  4596. if globalnb=0 then
  4597. set_globalnb;
  4598. { Write the record class itself }
  4599. writing_class_record_stab:=true;
  4600. inherited concatstabto(asmlist);
  4601. writing_class_record_stab:=false;
  4602. { Write the invisible pointer class }
  4603. is_def_stab_written:=not_written;
  4604. if assigned(typesym) then
  4605. begin
  4606. st:=typesym.FName;
  4607. typesym.FName:=stringdup(' ');
  4608. end;
  4609. inherited concatstabto(asmlist);
  4610. if assigned(typesym) then
  4611. begin
  4612. stringdispose(typesym.FName);
  4613. typesym.FName:=st;
  4614. end;
  4615. end;
  4616. end;
  4617. {$endif GDB}
  4618. function tobjectdef.needs_inittable : boolean;
  4619. begin
  4620. case objecttype of
  4621. odt_class :
  4622. needs_inittable:=false;
  4623. odt_interfacecom:
  4624. needs_inittable:=true;
  4625. odt_interfacecorba:
  4626. needs_inittable:=is_related(interface_iunknown);
  4627. odt_object:
  4628. needs_inittable:=tobjectsymtable(symtable).needs_init_final;
  4629. else
  4630. internalerror(200108267);
  4631. end;
  4632. end;
  4633. function tobjectdef.members_need_inittable : boolean;
  4634. begin
  4635. members_need_inittable:=tobjectsymtable(symtable).needs_init_final;
  4636. end;
  4637. procedure tobjectdef.count_published_properties(sym:tnamedindexitem;arg:pointer);
  4638. begin
  4639. if needs_prop_entry(tsym(sym)) and
  4640. (tsym(sym).typ<>varsym) then
  4641. inc(count);
  4642. end;
  4643. procedure tobjectdef.write_property_info(sym : tnamedindexitem;arg:pointer);
  4644. var
  4645. proctypesinfo : byte;
  4646. procedure writeproc(proc : tsymlist; shiftvalue : byte);
  4647. var
  4648. typvalue : byte;
  4649. hp : psymlistitem;
  4650. address : longint;
  4651. begin
  4652. if not(assigned(proc) and assigned(proc.firstsym)) then
  4653. begin
  4654. rttiList.concat(Tai_const.Create_32bit(1));
  4655. typvalue:=3;
  4656. end
  4657. else if proc.firstsym^.sym.typ=varsym then
  4658. begin
  4659. address:=0;
  4660. hp:=proc.firstsym;
  4661. while assigned(hp) do
  4662. begin
  4663. inc(address,tvarsym(hp^.sym).fieldoffset);
  4664. hp:=hp^.next;
  4665. end;
  4666. rttiList.concat(Tai_const.Create_32bit(address));
  4667. typvalue:=0;
  4668. end
  4669. else
  4670. begin
  4671. { When there was an error then procdef is not assigned }
  4672. if not assigned(proc.procdef) then
  4673. exit;
  4674. if not(po_virtualmethod in tprocdef(proc.procdef).procoptions) then
  4675. begin
  4676. rttiList.concat(Tai_const_symbol.Createname(tprocdef(proc.procdef).mangledname));
  4677. typvalue:=1;
  4678. end
  4679. else
  4680. begin
  4681. { virtual method, write vmt offset }
  4682. rttiList.concat(Tai_const.Create_32bit(
  4683. tprocdef(proc.procdef)._class.vmtmethodoffset(tprocdef(proc.procdef).extnumber)));
  4684. typvalue:=2;
  4685. end;
  4686. end;
  4687. proctypesinfo:=proctypesinfo or (typvalue shl shiftvalue);
  4688. end;
  4689. begin
  4690. if needs_prop_entry(tsym(sym)) then
  4691. case tsym(sym).typ of
  4692. varsym:
  4693. begin
  4694. {$ifdef dummy}
  4695. if not(tvarsym(sym).vartype.def.deftype=objectdef) or
  4696. not(tobjectdef(tvarsym(sym).vartype.def).is_class) then
  4697. internalerror(1509992);
  4698. { access to implicit class property as field }
  4699. proctypesinfo:=(0 shl 0) or (0 shl 2) or (0 shl 4);
  4700. rttiList.concat(Tai_const_symbol.Createname(tvarsym(sym.vartype.def.get_rtti_label)));
  4701. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym.address)));
  4702. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym.address)));
  4703. { per default stored }
  4704. rttiList.concat(Tai_const.Create_32bit(1));
  4705. { index as well as ... }
  4706. rttiList.concat(Tai_const.Create_32bit(0));
  4707. { default value are zero }
  4708. rttiList.concat(Tai_const.Create_32bit(0));
  4709. rttiList.concat(Tai_const.Create_16bit(count));
  4710. inc(count);
  4711. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  4712. rttiList.concat(Tai_const.Create_8bit(length(tvarsym(sym.realname))));
  4713. rttiList.concat(Tai_string.Create(tvarsym(sym.realname)));
  4714. {$endif dummy}
  4715. end;
  4716. propertysym:
  4717. begin
  4718. if ppo_indexed in tpropertysym(sym).propoptions then
  4719. proctypesinfo:=$40
  4720. else
  4721. proctypesinfo:=0;
  4722. rttiList.concat(Tai_const_symbol.Create(tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti)));
  4723. writeproc(tpropertysym(sym).readaccess,0);
  4724. writeproc(tpropertysym(sym).writeaccess,2);
  4725. { isn't it stored ? }
  4726. if not(ppo_stored in tpropertysym(sym).propoptions) then
  4727. begin
  4728. rttiList.concat(Tai_const.Create_32bit(0));
  4729. proctypesinfo:=proctypesinfo or (3 shl 4);
  4730. end
  4731. else
  4732. writeproc(tpropertysym(sym).storedaccess,4);
  4733. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).index));
  4734. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).default));
  4735. rttiList.concat(Tai_const.Create_16bit(count));
  4736. inc(count);
  4737. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  4738. rttiList.concat(Tai_const.Create_8bit(length(tpropertysym(sym).realname)));
  4739. rttiList.concat(Tai_string.Create(tpropertysym(sym).realname));
  4740. end;
  4741. else internalerror(1509992);
  4742. end;
  4743. end;
  4744. procedure tobjectdef.generate_published_child_rtti(sym : tnamedindexitem;arg:pointer);
  4745. begin
  4746. if needs_prop_entry(tsym(sym)) then
  4747. begin
  4748. case tsym(sym).typ of
  4749. propertysym:
  4750. tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti);
  4751. varsym:
  4752. tstoreddef(tvarsym(sym).vartype.def).get_rtti_label(fullrtti);
  4753. else
  4754. internalerror(1509991);
  4755. end;
  4756. end;
  4757. end;
  4758. procedure tobjectdef.write_child_rtti_data(rt:trttitype);
  4759. begin
  4760. FRTTIType:=rt;
  4761. case rt of
  4762. initrtti :
  4763. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}generate_field_rtti,nil);
  4764. fullrtti :
  4765. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}generate_published_child_rtti,nil);
  4766. else
  4767. internalerror(200108301);
  4768. end;
  4769. end;
  4770. type
  4771. tclasslistitem = class(TLinkedListItem)
  4772. index : longint;
  4773. p : tobjectdef;
  4774. end;
  4775. var
  4776. classtablelist : tlinkedlist;
  4777. tablecount : longint;
  4778. function searchclasstablelist(p : tobjectdef) : tclasslistitem;
  4779. var
  4780. hp : tclasslistitem;
  4781. begin
  4782. hp:=tclasslistitem(classtablelist.first);
  4783. while assigned(hp) do
  4784. if hp.p=p then
  4785. begin
  4786. searchclasstablelist:=hp;
  4787. exit;
  4788. end
  4789. else
  4790. hp:=tclasslistitem(hp.next);
  4791. searchclasstablelist:=nil;
  4792. end;
  4793. procedure tobjectdef.count_published_fields(sym:tnamedindexitem;arg:pointer);
  4794. var
  4795. hp : tclasslistitem;
  4796. begin
  4797. if needs_prop_entry(tsym(sym)) and
  4798. (tsym(sym).typ=varsym) then
  4799. begin
  4800. if tvarsym(sym).vartype.def.deftype<>objectdef then
  4801. internalerror(0206001);
  4802. hp:=searchclasstablelist(tobjectdef(tvarsym(sym).vartype.def));
  4803. if not(assigned(hp)) then
  4804. begin
  4805. hp:=tclasslistitem.create;
  4806. hp.p:=tobjectdef(tvarsym(sym).vartype.def);
  4807. hp.index:=tablecount;
  4808. classtablelist.concat(hp);
  4809. inc(tablecount);
  4810. end;
  4811. inc(count);
  4812. end;
  4813. end;
  4814. procedure tobjectdef.writefields(sym:tnamedindexitem;arg:pointer);
  4815. var
  4816. hp : tclasslistitem;
  4817. begin
  4818. if needs_prop_entry(tsym(sym)) and
  4819. (tsym(sym).typ=varsym) then
  4820. begin
  4821. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym).fieldoffset));
  4822. hp:=searchclasstablelist(tobjectdef(tvarsym(sym).vartype.def));
  4823. if not(assigned(hp)) then
  4824. internalerror(0206002);
  4825. rttiList.concat(Tai_const.Create_16bit(hp.index));
  4826. rttiList.concat(Tai_const.Create_8bit(length(tvarsym(sym).realname)));
  4827. rttiList.concat(Tai_string.Create(tvarsym(sym).realname));
  4828. end;
  4829. end;
  4830. function tobjectdef.generate_field_table : tasmlabel;
  4831. var
  4832. fieldtable,
  4833. classtable : tasmlabel;
  4834. hp : tclasslistitem;
  4835. begin
  4836. classtablelist:=TLinkedList.Create;
  4837. objectlibrary.getdatalabel(fieldtable);
  4838. objectlibrary.getdatalabel(classtable);
  4839. count:=0;
  4840. tablecount:=0;
  4841. symtable.foreach({$ifdef FPC}@{$endif}count_published_fields,nil);
  4842. if (cs_create_smart in aktmoduleswitches) then
  4843. rttiList.concat(Tai_cut.Create);
  4844. rttilist.concat(tai_align.create(const_align(pointer_size)));
  4845. rttiList.concat(Tai_label.Create(fieldtable));
  4846. rttiList.concat(Tai_const.Create_16bit(count));
  4847. rttiList.concat(Tai_const_symbol.Create(classtable));
  4848. symtable.foreach({$ifdef FPC}@{$endif}writefields,nil);
  4849. { generate the class table }
  4850. rttilist.concat(tai_align.create(const_align(pointer_size)));
  4851. rttiList.concat(Tai_label.Create(classtable));
  4852. rttiList.concat(Tai_const.Create_16bit(tablecount));
  4853. hp:=tclasslistitem(classtablelist.first);
  4854. while assigned(hp) do
  4855. begin
  4856. rttiList.concat(Tai_const_symbol.Createname(tobjectdef(hp.p).vmt_mangledname));
  4857. hp:=tclasslistitem(hp.next);
  4858. end;
  4859. generate_field_table:=fieldtable;
  4860. classtablelist.free;
  4861. end;
  4862. function tobjectdef.next_free_name_index : longint;
  4863. var
  4864. i : longint;
  4865. begin
  4866. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4867. i:=childof.next_free_name_index
  4868. else
  4869. i:=0;
  4870. count:=0;
  4871. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  4872. next_free_name_index:=i+count;
  4873. end;
  4874. procedure tobjectdef.write_rtti_data(rt:trttitype);
  4875. begin
  4876. case objecttype of
  4877. odt_class:
  4878. rttiList.concat(Tai_const.Create_8bit(tkclass));
  4879. odt_object:
  4880. rttiList.concat(Tai_const.Create_8bit(tkobject));
  4881. odt_interfacecom:
  4882. rttiList.concat(Tai_const.Create_8bit(tkinterface));
  4883. odt_interfacecorba:
  4884. rttiList.concat(Tai_const.Create_8bit(tkinterfaceCorba));
  4885. else
  4886. exit;
  4887. end;
  4888. { generate the name }
  4889. rttiList.concat(Tai_const.Create_8bit(length(objrealname^)));
  4890. rttiList.concat(Tai_string.Create(objrealname^));
  4891. case rt of
  4892. initrtti :
  4893. begin
  4894. rttiList.concat(Tai_const.Create_32bit(size));
  4895. if objecttype in [odt_class,odt_object] then
  4896. begin
  4897. count:=0;
  4898. FRTTIType:=rt;
  4899. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_field_rtti,nil);
  4900. rttiList.concat(Tai_const.Create_32bit(count));
  4901. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}write_field_rtti,nil);
  4902. end;
  4903. end;
  4904. fullrtti :
  4905. begin
  4906. if (oo_has_vmt in objectoptions) and
  4907. not(objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4908. rttiList.concat(Tai_const_symbol.Createname(vmt_mangledname))
  4909. else
  4910. rttiList.concat(Tai_const.Create_32bit(0));
  4911. { write owner typeinfo }
  4912. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4913. rttiList.concat(Tai_const_symbol.Create(childof.get_rtti_label(fullrtti)))
  4914. else
  4915. rttiList.concat(Tai_const.Create_32bit(0));
  4916. { count total number of properties }
  4917. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4918. count:=childof.next_free_name_index
  4919. else
  4920. count:=0;
  4921. { write it }
  4922. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  4923. rttiList.concat(Tai_const.Create_16bit(count));
  4924. { write unit name }
  4925. rttiList.concat(Tai_const.Create_8bit(length(current_module.realmodulename^)));
  4926. rttiList.concat(Tai_string.Create(current_module.realmodulename^));
  4927. { write published properties count }
  4928. count:=0;
  4929. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  4930. rttiList.concat(Tai_const.Create_16bit(count));
  4931. { count is used to write nameindex }
  4932. { but we need an offset of the owner }
  4933. { to give each property an own slot }
  4934. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4935. count:=childof.next_free_name_index
  4936. else
  4937. count:=0;
  4938. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}write_property_info,nil);
  4939. end;
  4940. end;
  4941. end;
  4942. function tobjectdef.is_publishable : boolean;
  4943. begin
  4944. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba];
  4945. end;
  4946. {****************************************************************************
  4947. TIMPLEMENTEDINTERFACES
  4948. ****************************************************************************}
  4949. type
  4950. tnamemap = class(TNamedIndexItem)
  4951. newname: pstring;
  4952. constructor create(const aname, anewname: string);
  4953. destructor destroy; override;
  4954. end;
  4955. constructor tnamemap.create(const aname, anewname: string);
  4956. begin
  4957. inherited createname(name);
  4958. newname:=stringdup(anewname);
  4959. end;
  4960. destructor tnamemap.destroy;
  4961. begin
  4962. stringdispose(newname);
  4963. inherited destroy;
  4964. end;
  4965. type
  4966. tprocdefstore = class(TNamedIndexItem)
  4967. procdef: tprocdef;
  4968. constructor create(aprocdef: tprocdef);
  4969. end;
  4970. constructor tprocdefstore.create(aprocdef: tprocdef);
  4971. begin
  4972. inherited create;
  4973. procdef:=aprocdef;
  4974. end;
  4975. type
  4976. timplintfentry = class(TNamedIndexItem)
  4977. intf: tobjectdef;
  4978. intfderef : tderef;
  4979. ioffs: longint;
  4980. namemappings: tdictionary;
  4981. procdefs: TIndexArray;
  4982. constructor create(aintf: tobjectdef);
  4983. constructor create_deref(const d:tderef);
  4984. destructor destroy; override;
  4985. end;
  4986. constructor timplintfentry.create(aintf: tobjectdef);
  4987. begin
  4988. inherited create;
  4989. intf:=aintf;
  4990. ioffs:=-1;
  4991. namemappings:=nil;
  4992. procdefs:=nil;
  4993. end;
  4994. constructor timplintfentry.create_deref(const d:tderef);
  4995. begin
  4996. inherited create;
  4997. intf:=nil;
  4998. intfderef:=d;
  4999. ioffs:=-1;
  5000. namemappings:=nil;
  5001. procdefs:=nil;
  5002. end;
  5003. destructor timplintfentry.destroy;
  5004. begin
  5005. if assigned(namemappings) then
  5006. namemappings.free;
  5007. if assigned(procdefs) then
  5008. procdefs.free;
  5009. inherited destroy;
  5010. end;
  5011. constructor timplementedinterfaces.create;
  5012. begin
  5013. finterfaces:=tindexarray.create(1);
  5014. end;
  5015. destructor timplementedinterfaces.destroy;
  5016. begin
  5017. finterfaces.destroy;
  5018. end;
  5019. function timplementedinterfaces.count: longint;
  5020. begin
  5021. count:=finterfaces.count;
  5022. end;
  5023. procedure timplementedinterfaces.checkindex(intfindex: longint);
  5024. begin
  5025. if (intfindex<1) or (intfindex>count) then
  5026. InternalError(200006123);
  5027. end;
  5028. function timplementedinterfaces.interfaces(intfindex: longint): tobjectdef;
  5029. begin
  5030. checkindex(intfindex);
  5031. interfaces:=timplintfentry(finterfaces.search(intfindex)).intf;
  5032. end;
  5033. function timplementedinterfaces.interfacesderef(intfindex: longint): tderef;
  5034. begin
  5035. checkindex(intfindex);
  5036. interfacesderef:=timplintfentry(finterfaces.search(intfindex)).intfderef;
  5037. end;
  5038. function timplementedinterfaces.ioffsets(intfindex: longint): plongint;
  5039. begin
  5040. checkindex(intfindex);
  5041. ioffsets:=@timplintfentry(finterfaces.search(intfindex)).ioffs;
  5042. end;
  5043. function timplementedinterfaces.searchintf(def: tdef): longint;
  5044. var
  5045. i: longint;
  5046. begin
  5047. i:=1;
  5048. while (i<=count) and (tdef(interfaces(i))<>def) do inc(i);
  5049. if i<=count then
  5050. searchintf:=i
  5051. else
  5052. searchintf:=-1;
  5053. end;
  5054. procedure timplementedinterfaces.buildderef;
  5055. var
  5056. i: longint;
  5057. begin
  5058. for i:=1 to count do
  5059. with timplintfentry(finterfaces.search(i)) do
  5060. intfderef.build(intf);
  5061. end;
  5062. procedure timplementedinterfaces.deref;
  5063. var
  5064. i: longint;
  5065. begin
  5066. for i:=1 to count do
  5067. with timplintfentry(finterfaces.search(i)) do
  5068. intf:=tobjectdef(intfderef.resolve);
  5069. end;
  5070. procedure timplementedinterfaces.addintf_deref(const d:tderef);
  5071. begin
  5072. finterfaces.insert(timplintfentry.create_deref(d));
  5073. end;
  5074. procedure timplementedinterfaces.addintf(def: tdef);
  5075. begin
  5076. if not assigned(def) or (searchintf(def)<>-1) or (def.deftype<>objectdef) or
  5077. not (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]) then
  5078. internalerror(200006124);
  5079. finterfaces.insert(timplintfentry.create(tobjectdef(def)));
  5080. end;
  5081. procedure timplementedinterfaces.clearmappings;
  5082. var
  5083. i: longint;
  5084. begin
  5085. for i:=1 to count do
  5086. with timplintfentry(finterfaces.search(i)) do
  5087. begin
  5088. if assigned(namemappings) then
  5089. namemappings.free;
  5090. namemappings:=nil;
  5091. end;
  5092. end;
  5093. procedure timplementedinterfaces.addmappings(intfindex: longint; const name, newname: string);
  5094. begin
  5095. checkindex(intfindex);
  5096. with timplintfentry(finterfaces.search(intfindex)) do
  5097. begin
  5098. if not assigned(namemappings) then
  5099. namemappings:=tdictionary.create;
  5100. namemappings.insert(tnamemap.create(name,newname));
  5101. end;
  5102. end;
  5103. function timplementedinterfaces.getmappings(intfindex: longint; const name: string; var nextexist: pointer): string;
  5104. begin
  5105. checkindex(intfindex);
  5106. if not assigned(nextexist) then
  5107. with timplintfentry(finterfaces.search(intfindex)) do
  5108. begin
  5109. if assigned(namemappings) then
  5110. nextexist:=namemappings.search(name)
  5111. else
  5112. nextexist:=nil;
  5113. end;
  5114. if assigned(nextexist) then
  5115. begin
  5116. getmappings:=tnamemap(nextexist).newname^;
  5117. nextexist:=tnamemap(nextexist).listnext;
  5118. end
  5119. else
  5120. getmappings:='';
  5121. end;
  5122. procedure timplementedinterfaces.clearimplprocs;
  5123. var
  5124. i: longint;
  5125. begin
  5126. for i:=1 to count do
  5127. with timplintfentry(finterfaces.search(i)) do
  5128. begin
  5129. if assigned(procdefs) then
  5130. procdefs.free;
  5131. procdefs:=nil;
  5132. end;
  5133. end;
  5134. procedure timplementedinterfaces.addimplproc(intfindex: longint; procdef: tprocdef);
  5135. begin
  5136. checkindex(intfindex);
  5137. with timplintfentry(finterfaces.search(intfindex)) do
  5138. begin
  5139. if not assigned(procdefs) then
  5140. procdefs:=tindexarray.create(4);
  5141. procdefs.insert(tprocdefstore.create(procdef));
  5142. end;
  5143. end;
  5144. function timplementedinterfaces.implproccount(intfindex: longint): longint;
  5145. begin
  5146. checkindex(intfindex);
  5147. with timplintfentry(finterfaces.search(intfindex)) do
  5148. if assigned(procdefs) then
  5149. implproccount:=procdefs.count
  5150. else
  5151. implproccount:=0;
  5152. end;
  5153. function timplementedinterfaces.implprocs(intfindex: longint; procindex: longint): tprocdef;
  5154. begin
  5155. checkindex(intfindex);
  5156. with timplintfentry(finterfaces.search(intfindex)) do
  5157. if assigned(procdefs) then
  5158. implprocs:=tprocdefstore(procdefs.search(procindex)).procdef
  5159. else
  5160. internalerror(200006131);
  5161. end;
  5162. function timplementedinterfaces.isimplmergepossible(intfindex, remainindex: longint; var weight: longint): boolean;
  5163. var
  5164. possible: boolean;
  5165. i: longint;
  5166. iiep1: TIndexArray;
  5167. iiep2: TIndexArray;
  5168. begin
  5169. checkindex(intfindex);
  5170. checkindex(remainindex);
  5171. iiep1:=timplintfentry(finterfaces.search(intfindex)).procdefs;
  5172. iiep2:=timplintfentry(finterfaces.search(remainindex)).procdefs;
  5173. if not assigned(iiep1) then { empty interface is mergeable :-) }
  5174. begin
  5175. possible:=true;
  5176. weight:=0;
  5177. end
  5178. else
  5179. begin
  5180. possible:=assigned(iiep2) and (iiep1.count<=iiep2.count);
  5181. i:=1;
  5182. while (possible) and (i<=iiep1.count) do
  5183. begin
  5184. possible:=
  5185. (tprocdefstore(iiep1.search(i)).procdef=tprocdefstore(iiep2.search(i)).procdef);
  5186. inc(i);
  5187. end;
  5188. if possible then
  5189. weight:=iiep1.count;
  5190. end;
  5191. isimplmergepossible:=possible;
  5192. end;
  5193. {****************************************************************************
  5194. TFORWARDDEF
  5195. ****************************************************************************}
  5196. constructor tforwarddef.create(const s:string;const pos : tfileposinfo);
  5197. var
  5198. oldregisterdef : boolean;
  5199. begin
  5200. { never register the forwarddefs, they are disposed at the
  5201. end of the type declaration block }
  5202. oldregisterdef:=registerdef;
  5203. registerdef:=false;
  5204. inherited create;
  5205. registerdef:=oldregisterdef;
  5206. deftype:=forwarddef;
  5207. tosymname:=stringdup(s);
  5208. forwardpos:=pos;
  5209. end;
  5210. function tforwarddef.gettypename:string;
  5211. begin
  5212. gettypename:='unresolved forward to '+tosymname^;
  5213. end;
  5214. destructor tforwarddef.destroy;
  5215. begin
  5216. if assigned(tosymname) then
  5217. stringdispose(tosymname);
  5218. inherited destroy;
  5219. end;
  5220. {****************************************************************************
  5221. TERRORDEF
  5222. ****************************************************************************}
  5223. constructor terrordef.create;
  5224. begin
  5225. inherited create;
  5226. deftype:=errordef;
  5227. end;
  5228. {$ifdef GDB}
  5229. function terrordef.stabstring : pchar;
  5230. begin
  5231. stabstring:=strpnew('error'+numberstring);
  5232. end;
  5233. procedure terrordef.concatstabto(asmlist : taasmoutput);
  5234. begin
  5235. { No internal error needed, an normal error is already
  5236. thrown }
  5237. end;
  5238. {$endif GDB}
  5239. function terrordef.gettypename:string;
  5240. begin
  5241. gettypename:='<erroneous type>';
  5242. end;
  5243. function terrordef.getmangledparaname:string;
  5244. begin
  5245. getmangledparaname:='error';
  5246. end;
  5247. {****************************************************************************
  5248. GDB Helpers
  5249. ****************************************************************************}
  5250. {$ifdef GDB}
  5251. function typeglobalnumber(const s : string) : string;
  5252. var st : string;
  5253. symt : tsymtable;
  5254. srsym : tsym;
  5255. srsymtable : tsymtable;
  5256. old_make_ref : boolean;
  5257. begin
  5258. old_make_ref:=make_ref;
  5259. make_ref:=false;
  5260. typeglobalnumber := '0';
  5261. srsym := nil;
  5262. if pos('.',s) > 0 then
  5263. begin
  5264. st := copy(s,1,pos('.',s)-1);
  5265. searchsym(st,srsym,srsymtable);
  5266. st := copy(s,pos('.',s)+1,255);
  5267. if assigned(srsym) then
  5268. begin
  5269. if srsym.typ = unitsym then
  5270. begin
  5271. symt := tunitsym(srsym).unitsymtable;
  5272. srsym := tsym(symt.search(st));
  5273. end else srsym := nil;
  5274. end;
  5275. end else st := s;
  5276. if srsym = nil then
  5277. searchsym(st,srsym,srsymtable);
  5278. if (srsym=nil) or
  5279. (srsym.typ<>typesym) then
  5280. begin
  5281. Message(type_e_type_id_expected);
  5282. exit;
  5283. end;
  5284. typeglobalnumber := tstoreddef(ttypesym(srsym).restype.def).numberstring;
  5285. make_ref:=old_make_ref;
  5286. end;
  5287. {$endif GDB}
  5288. {****************************************************************************
  5289. Definition Helpers
  5290. ****************************************************************************}
  5291. procedure reset_global_defs;
  5292. var
  5293. def : tstoreddef;
  5294. {$ifdef debug}
  5295. prevdef : tstoreddef;
  5296. {$endif debug}
  5297. begin
  5298. {$ifdef debug}
  5299. prevdef:=nil;
  5300. {$endif debug}
  5301. {$ifdef GDB}
  5302. pglobaltypecount:=@globaltypecount;
  5303. {$endif GDB}
  5304. def:=firstglobaldef;
  5305. while assigned(def) do
  5306. begin
  5307. {$ifdef GDB}
  5308. if assigned(def.typesym) then
  5309. ttypesym(def.typesym).isusedinstab:=false;
  5310. def.is_def_stab_written:=not_written;
  5311. {$endif GDB}
  5312. if assigned(def.rttitablesym) then
  5313. trttisym(def.rttitablesym).lab := nil;
  5314. if assigned(def.inittablesym) then
  5315. trttisym(def.inittablesym).lab := nil;
  5316. def.localrttilab[initrtti]:=nil;
  5317. def.localrttilab[fullrtti]:=nil;
  5318. {$ifdef debug}
  5319. prevdef:=def;
  5320. {$endif debug}
  5321. def:=def.nextglobal;
  5322. end;
  5323. end;
  5324. function is_interfacecom(def: tdef): boolean;
  5325. begin
  5326. is_interfacecom:=
  5327. assigned(def) and
  5328. (def.deftype=objectdef) and
  5329. (tobjectdef(def).objecttype=odt_interfacecom);
  5330. end;
  5331. function is_interfacecorba(def: tdef): boolean;
  5332. begin
  5333. is_interfacecorba:=
  5334. assigned(def) and
  5335. (def.deftype=objectdef) and
  5336. (tobjectdef(def).objecttype=odt_interfacecorba);
  5337. end;
  5338. function is_interface(def: tdef): boolean;
  5339. begin
  5340. is_interface:=
  5341. assigned(def) and
  5342. (def.deftype=objectdef) and
  5343. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  5344. end;
  5345. function is_class(def: tdef): boolean;
  5346. begin
  5347. is_class:=
  5348. assigned(def) and
  5349. (def.deftype=objectdef) and
  5350. (tobjectdef(def).objecttype=odt_class);
  5351. end;
  5352. function is_object(def: tdef): boolean;
  5353. begin
  5354. is_object:=
  5355. assigned(def) and
  5356. (def.deftype=objectdef) and
  5357. (tobjectdef(def).objecttype=odt_object);
  5358. end;
  5359. function is_cppclass(def: tdef): boolean;
  5360. begin
  5361. is_cppclass:=
  5362. assigned(def) and
  5363. (def.deftype=objectdef) and
  5364. (tobjectdef(def).objecttype=odt_cppclass);
  5365. end;
  5366. function is_class_or_interface(def: tdef): boolean;
  5367. begin
  5368. is_class_or_interface:=
  5369. assigned(def) and
  5370. (def.deftype=objectdef) and
  5371. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  5372. end;
  5373. end.
  5374. {
  5375. $Log$
  5376. Revision 1.193 2003-12-16 21:29:24 florian
  5377. + inlined procedures inherit procinfo flags
  5378. Revision 1.192 2003/12/12 12:09:40 marco
  5379. * always generate RTTI patch from peter
  5380. Revision 1.191 2003/12/08 22:34:24 peter
  5381. * tai_const.create_32bit changed to cardinal
  5382. Revision 1.190 2003/11/10 22:02:52 peter
  5383. * cross unit inlining fixed
  5384. Revision 1.189 2003/11/08 23:31:27 florian
  5385. * tstoreddef.getcopy returns now an errordef instead of nil; this
  5386. allows easier error recovery
  5387. Revision 1.188 2003/11/05 14:18:03 marco
  5388. * fix from Peter arraysize warning (nav Newsgroup msg)
  5389. Revision 1.187 2003/11/01 15:50:03 peter
  5390. * fix check for valid procdef in property rtti
  5391. Revision 1.186 2003/10/29 21:56:28 peter
  5392. * procsym.deref derefs only own procdefs
  5393. * reset paracount in procdef.deref so a second deref doesn't increase
  5394. the paracounts to invalid values
  5395. Revision 1.185 2003/10/29 19:48:51 peter
  5396. * renamed mangeldname_prefix to make_mangledname and made it more
  5397. generic
  5398. * make_mangledname is now also used for internal threadvar/resstring
  5399. lists
  5400. * Add P$ in front of program modulename to prevent duplicated symbols
  5401. at assembler level, because the main program can have the same name
  5402. as a unit, see webtbs/tw1251b
  5403. Revision 1.184 2003/10/23 14:44:07 peter
  5404. * splitted buildderef and buildderefimpl to fix interface crc
  5405. calculation
  5406. Revision 1.183 2003/10/22 20:40:00 peter
  5407. * write derefdata in a separate ppu entry
  5408. Revision 1.182 2003/10/21 18:14:49 peter
  5409. * fix counting of parameters when loading ppu
  5410. Revision 1.181 2003/10/17 15:08:34 peter
  5411. * commented out more obsolete constants
  5412. Revision 1.180 2003/10/17 14:52:07 peter
  5413. * fixed ppc build
  5414. Revision 1.179 2003/10/17 14:38:32 peter
  5415. * 64k registers supported
  5416. * fixed some memory leaks
  5417. Revision 1.178 2003/10/13 14:05:12 peter
  5418. * removed is_visible_for_proc
  5419. * search also for class overloads when finding interface
  5420. implementations
  5421. Revision 1.177 2003/10/11 16:06:42 florian
  5422. * fixed some MMX<->SSE
  5423. * started to fix ppc, needs an overhaul
  5424. + stabs info improve for spilling, not sure if it works correctly/completly
  5425. - MMX_SUPPORT removed from Makefile.fpc
  5426. Revision 1.176 2003/10/10 17:48:14 peter
  5427. * old trgobj moved to x86/rgcpu and renamed to trgx86fpu
  5428. * tregisteralloctor renamed to trgobj
  5429. * removed rgobj from a lot of units
  5430. * moved location_* and reference_* to cgobj
  5431. * first things for mmx register allocation
  5432. Revision 1.175 2003/10/07 20:43:49 peter
  5433. * Add calling convention in fullprocname when it is specified
  5434. Revision 1.174 2003/10/07 16:06:30 peter
  5435. * tsymlist.def renamed to tsymlist.procdef
  5436. * tsymlist.procdef is now only used to store the procdef
  5437. Revision 1.173 2003/10/06 22:23:41 florian
  5438. + added basic olevariant support
  5439. Revision 1.172 2003/10/05 21:21:52 peter
  5440. * c style array of const generates callparanodes
  5441. * varargs paraloc fixes
  5442. Revision 1.171 2003/10/05 12:56:35 peter
  5443. * don't write procdefs that are released to ppu
  5444. Revision 1.170 2003/10/03 22:00:33 peter
  5445. * parameter alignment fixes
  5446. Revision 1.169 2003/10/02 21:19:42 peter
  5447. * protected visibility fixes
  5448. Revision 1.168 2003/10/01 20:34:49 peter
  5449. * procinfo unit contains tprocinfo
  5450. * cginfo renamed to cgbase
  5451. * moved cgmessage to verbose
  5452. * fixed ppc and sparc compiles
  5453. Revision 1.167 2003/10/01 16:49:05 florian
  5454. * para items are now reversed for pascal calling conventions
  5455. Revision 1.166 2003/10/01 15:32:58 florian
  5456. * fixed FullProcName to handle constructors, destructors and operators correctly
  5457. Revision 1.165 2003/10/01 15:00:02 peter
  5458. * don't write parast,localst debug info for externals
  5459. Revision 1.164 2003/09/23 21:03:35 peter
  5460. * connect parasym to paraitem
  5461. Revision 1.163 2003/09/23 17:56:06 peter
  5462. * locals and paras are allocated in the code generation
  5463. * tvarsym.localloc contains the location of para/local when
  5464. generating code for the current procedure
  5465. Revision 1.162 2003/09/07 22:09:35 peter
  5466. * preparations for different default calling conventions
  5467. * various RA fixes
  5468. Revision 1.161 2003/09/06 22:27:09 florian
  5469. * fixed web bug 2669
  5470. * cosmetic fix in printnode
  5471. * tobjectdef.gettypename implemented
  5472. Revision 1.160 2003/09/03 15:55:01 peter
  5473. * NEWRA branch merged
  5474. Revision 1.159 2003/09/03 11:18:37 florian
  5475. * fixed arm concatcopy
  5476. + arm support in the common compiler sources added
  5477. * moved some generic cg code around
  5478. + tfputype added
  5479. * ...
  5480. Revision 1.158.2.2 2003/08/29 17:28:59 peter
  5481. * next batch of updates
  5482. Revision 1.158.2.1 2003/08/27 19:55:54 peter
  5483. * first tregister patch
  5484. Revision 1.158 2003/08/11 21:18:20 peter
  5485. * start of sparc support for newra
  5486. Revision 1.157 2003/07/08 15:20:56 peter
  5487. * don't allow add/assignments for formaldef
  5488. * formaldef size changed to 0
  5489. Revision 1.156 2003/07/06 21:50:33 jonas
  5490. * fixed ppc compilation problems and changed VOLATILE_REGISTERS for x86
  5491. so that it doesn't include ebp and esp anymore
  5492. Revision 1.155 2003/07/06 15:31:21 daniel
  5493. * Fixed register allocator. *Lots* of fixes.
  5494. Revision 1.154 2003/07/02 22:18:04 peter
  5495. * paraloc splitted in callerparaloc,calleeparaloc
  5496. * sparc calling convention updates
  5497. Revision 1.153 2003/06/25 18:31:23 peter
  5498. * sym,def resolving partly rewritten to support also parent objects
  5499. not directly available through the uses clause
  5500. Revision 1.152 2003/06/17 16:34:44 jonas
  5501. * lots of newra fixes (need getfuncretparaloc implementation for i386)!
  5502. * renamed all_intregisters to paramanager.get_volatile_registers_int(pocall_default) and made it
  5503. processor dependent
  5504. Revision 1.151 2003/06/08 11:41:21 peter
  5505. * set parast.next to the owner of the procdef
  5506. Revision 1.150 2003/06/07 20:26:32 peter
  5507. * re-resolving added instead of reloading from ppu
  5508. * tderef object added to store deref info for resolving
  5509. Revision 1.149 2003/06/05 20:05:55 peter
  5510. * removed changesettype because that will change the definition
  5511. of the setdef forever and can result in a different between
  5512. original interface and current implementation definition
  5513. Revision 1.148 2003/06/03 13:01:59 daniel
  5514. * Register allocator finished
  5515. Revision 1.147 2003/06/02 22:55:28 florian
  5516. * classes and interfaces can be stored in integer registers
  5517. Revision 1.146 2003/05/26 21:17:18 peter
  5518. * procinlinenode removed
  5519. * aktexit2label removed, fast exit removed
  5520. + tcallnode.inlined_pass_2 added
  5521. Revision 1.145 2003/05/25 11:34:17 peter
  5522. * methodpointer self pushing fixed
  5523. Revision 1.144 2003/05/15 18:58:53 peter
  5524. * removed selfpointer_offset, vmtpointer_offset
  5525. * tvarsym.adjusted_address
  5526. * address in localsymtable is now in the real direction
  5527. * removed some obsolete globals
  5528. Revision 1.143 2003/05/13 08:13:16 jonas
  5529. * patch from Peter for rtti symbols
  5530. Revision 1.142 2003/05/11 21:37:03 peter
  5531. * moved implicit exception frame from ncgutil to psub
  5532. * constructor/destructor helpers moved from cobj/ncgutil to psub
  5533. Revision 1.141 2003/05/09 17:47:03 peter
  5534. * self moved to hidden parameter
  5535. * removed hdisposen,hnewn,selfn
  5536. Revision 1.140 2003/05/05 14:53:16 peter
  5537. * vs_hidden replaced by is_hidden boolean
  5538. Revision 1.139 2003/05/01 07:59:43 florian
  5539. * introduced defaultordconsttype to decribe the default size of ordinal constants
  5540. on 64 bit CPUs it's equal to cs64bitdef while on 32 bit CPUs it's equal to s32bitdef
  5541. + added defines CPU32 and CPU64 for 32 bit and 64 bit CPUs
  5542. * int64s/qwords are allowed as for loop counter on 64 bit CPUs
  5543. Revision 1.138 2003/04/27 11:21:34 peter
  5544. * aktprocdef renamed to current_procdef
  5545. * procinfo renamed to current_procinfo
  5546. * procinfo will now be stored in current_module so it can be
  5547. cleaned up properly
  5548. * gen_main_procsym changed to create_main_proc and release_main_proc
  5549. to also generate a tprocinfo structure
  5550. * fixed unit implicit initfinal
  5551. Revision 1.137 2003/04/27 07:29:51 peter
  5552. * current_procdef cleanup, current_procdef is now always nil when parsing
  5553. a new procdef declaration
  5554. * aktprocsym removed
  5555. * lexlevel removed, use symtable.symtablelevel instead
  5556. * implicit init/final code uses the normal genentry/genexit
  5557. * funcret state checking updated for new funcret handling
  5558. Revision 1.136 2003/04/25 20:59:35 peter
  5559. * removed funcretn,funcretsym, function result is now in varsym
  5560. and aliases for result and function name are added using absolutesym
  5561. * vs_hidden parameter for funcret passed in parameter
  5562. * vs_hidden fixes
  5563. * writenode changed to printnode and released from extdebug
  5564. * -vp option added to generate a tree.log with the nodetree
  5565. * nicer printnode for statements, callnode
  5566. Revision 1.135 2003/04/23 20:16:04 peter
  5567. + added currency support based on int64
  5568. + is_64bit for use in cg units instead of is_64bitint
  5569. * removed cgmessage from n386add, replace with internalerrors
  5570. Revision 1.134 2003/04/23 12:35:34 florian
  5571. * fixed several issues with powerpc
  5572. + applied a patch from Jonas for nested function calls (PowerPC only)
  5573. * ...
  5574. Revision 1.133 2003/04/10 17:57:53 peter
  5575. * vs_hidden released
  5576. Revision 1.132 2003/03/18 16:25:50 peter
  5577. * no itnernalerror for errordef.concatstabto()
  5578. Revision 1.131 2003/03/17 16:54:41 peter
  5579. * support DefaultHandler and anonymous inheritance fixed
  5580. for message methods
  5581. Revision 1.130 2003/03/17 15:54:22 peter
  5582. * store symoptions also for procdef
  5583. * check symoptions (private,public) when calculating possible
  5584. overload candidates
  5585. Revision 1.129 2003/02/19 22:00:14 daniel
  5586. * Code generator converted to new register notation
  5587. - Horribily outdated todo.txt removed
  5588. Revision 1.128 2003/02/02 19:25:54 carl
  5589. * Several bugfixes for m68k target (register alloc., opcode emission)
  5590. + VIS target
  5591. + Generic add more complete (still not verified)
  5592. Revision 1.127 2003/01/21 14:36:44 pierre
  5593. * set sizes needs to be passes in bits not bytes to stabs info
  5594. Revision 1.126 2003/01/16 22:11:33 peter
  5595. * fixed tprocdef.is_addressonly
  5596. Revision 1.125 2003/01/15 01:44:33 peter
  5597. * merged methodpointer fixes from 1.0.x
  5598. Revision 1.124 2003/01/09 21:52:37 peter
  5599. * merged some verbosity options.
  5600. * V_LineInfo is a verbosity flag to include line info
  5601. Revision 1.123 2003/01/06 21:16:52 peter
  5602. * po_addressonly added to retrieve the address of a methodpointer
  5603. only, this is used for @tclass.method which has no self pointer
  5604. Revision 1.122 2003/01/05 15:54:15 florian
  5605. + added proper support of type = type <type>; for simple types
  5606. Revision 1.121 2003/01/05 13:36:53 florian
  5607. * x86-64 compiles
  5608. + very basic support for float128 type (x86-64 only)
  5609. Revision 1.120 2003/01/02 19:49:00 peter
  5610. * update self parameter only for methodpointer and methods
  5611. Revision 1.119 2002/12/29 18:25:59 peter
  5612. * tprocdef.gettypename implemented
  5613. Revision 1.118 2002/12/27 15:23:09 peter
  5614. * write class methods in fullname
  5615. Revision 1.117 2002/12/15 19:34:31 florian
  5616. + some front end stuff for vs_hidden added
  5617. Revision 1.116 2002/12/15 11:26:02 peter
  5618. * ignore vs_hidden parameters when choosing overloaded proc
  5619. Revision 1.115 2002/12/07 14:27:09 carl
  5620. * 3% memory optimization
  5621. * changed some types
  5622. + added type checking with different size for call node and for
  5623. parameters
  5624. Revision 1.114 2002/12/01 22:05:27 carl
  5625. * no more warnings for structures over 32K since this is
  5626. handled correctly in this version of the compiler.
  5627. Revision 1.113 2002/11/27 20:04:09 peter
  5628. * tvarsym.get_push_size replaced by paramanager.push_size
  5629. Revision 1.112 2002/11/25 21:05:53 carl
  5630. * several mistakes fixed in message files
  5631. Revision 1.111 2002/11/25 18:43:33 carl
  5632. - removed the invalid if <> checking (Delphi is strange on this)
  5633. + implemented abstract warning on instance creation of class with
  5634. abstract methods.
  5635. * some error message cleanups
  5636. Revision 1.110 2002/11/25 17:43:24 peter
  5637. * splitted defbase in defutil,symutil,defcmp
  5638. * merged isconvertable and is_equal into compare_defs(_ext)
  5639. * made operator search faster by walking the list only once
  5640. Revision 1.109 2002/11/23 22:50:06 carl
  5641. * some small speed optimizations
  5642. + added several new warnings/hints
  5643. Revision 1.108 2002/11/22 22:48:10 carl
  5644. * memory optimization with tconstsym (1.5%)
  5645. Revision 1.107 2002/11/19 16:21:29 pierre
  5646. * correct several stabs generation problems
  5647. Revision 1.106 2002/11/18 17:31:59 peter
  5648. * pass proccalloption to ret_in_xxx and push_xxx functions
  5649. Revision 1.105 2002/11/17 16:31:57 carl
  5650. * memory optimization (3-4%) : cleanup of tai fields,
  5651. cleanup of tdef and tsym fields.
  5652. * make it work for m68k
  5653. Revision 1.104 2002/11/16 19:53:18 carl
  5654. * avoid Range check errors
  5655. Revision 1.103 2002/11/15 16:29:09 peter
  5656. * fixed rtti for int64 (merged)
  5657. Revision 1.102 2002/11/15 01:58:54 peter
  5658. * merged changes from 1.0.7 up to 04-11
  5659. - -V option for generating bug report tracing
  5660. - more tracing for option parsing
  5661. - errors for cdecl and high()
  5662. - win32 import stabs
  5663. - win32 records<=8 are returned in eax:edx (turned off by default)
  5664. - heaptrc update
  5665. - more info for temp management in .s file with EXTDEBUG
  5666. Revision 1.101 2002/11/09 15:31:02 carl
  5667. + align RTTI tables
  5668. Revision 1.100 2002/10/19 15:09:25 peter
  5669. + tobjectdef.members_need_inittable that is used to generate only the
  5670. inittable when it is really used. This saves a lot of useless calls
  5671. to fpc_finalize when destroying classes
  5672. Revision 1.99 2002/10/07 21:30:27 peter
  5673. * removed obsolete rangecheck stuff
  5674. Revision 1.98 2002/10/05 15:14:26 peter
  5675. * getparamangeldname for errordef
  5676. Revision 1.97 2002/10/05 12:43:28 carl
  5677. * fixes for Delphi 6 compilation
  5678. (warning : Some features do not work under Delphi)
  5679. Revision 1.96 2002/09/27 21:13:29 carl
  5680. * low-highval always checked if limit ober 2GB is reached (to avoid overflow)
  5681. Revision 1.95 2002/09/16 09:31:10 florian
  5682. * fixed currency size
  5683. Revision 1.94 2002/09/09 17:34:15 peter
  5684. * tdicationary.replace added to replace and item in a dictionary. This
  5685. is only allowed for the same name
  5686. * varsyms are inserted in symtable before the types are parsed. This
  5687. fixes the long standing "var longint : longint" bug
  5688. - consume_idlist and idstringlist removed. The loops are inserted
  5689. at the callers place and uses the symtable for duplicate id checking
  5690. Revision 1.93 2002/09/07 15:25:07 peter
  5691. * old logs removed and tabs fixed
  5692. Revision 1.92 2002/09/05 19:29:42 peter
  5693. * memdebug enhancements
  5694. Revision 1.91 2002/08/25 19:25:20 peter
  5695. * sym.insert_in_data removed
  5696. * symtable.insertvardata/insertconstdata added
  5697. * removed insert_in_data call from symtable.insert, it needs to be
  5698. called separatly. This allows to deref the address calculation
  5699. * procedures now calculate the parast addresses after the procedure
  5700. directives are parsed. This fixes the cdecl parast problem
  5701. * push_addr_param has an extra argument that specifies if cdecl is used
  5702. or not
  5703. Revision 1.90 2002/08/18 20:06:25 peter
  5704. * inlining is now also allowed in interface
  5705. * renamed write/load to ppuwrite/ppuload
  5706. * tnode storing in ppu
  5707. * nld,ncon,nbas are already updated for storing in ppu
  5708. Revision 1.89 2002/08/11 15:28:00 florian
  5709. + support of explicit type case <any ordinal type>->pointer
  5710. (delphi mode only)
  5711. Revision 1.88 2002/08/11 14:32:28 peter
  5712. * renamed current_library to objectlibrary
  5713. Revision 1.87 2002/08/11 13:24:13 peter
  5714. * saving of asmsymbols in ppu supported
  5715. * asmsymbollist global is removed and moved into a new class
  5716. tasmlibrarydata that will hold the info of a .a file which
  5717. corresponds with a single module. Added librarydata to tmodule
  5718. to keep the library info stored for the module. In the future the
  5719. objectfiles will also be stored to the tasmlibrarydata class
  5720. * all getlabel/newasmsymbol and friends are moved to the new class
  5721. Revision 1.86 2002/08/09 07:33:03 florian
  5722. * a couple of interface related fixes
  5723. Revision 1.85 2002/07/23 09:51:24 daniel
  5724. * Tried to make Tprocsym.defs protected. I didn't succeed but the cleanups
  5725. are worth comitting.
  5726. Revision 1.84 2002/07/20 11:57:57 florian
  5727. * types.pas renamed to defbase.pas because D6 contains a types
  5728. unit so this would conflicts if D6 programms are compiled
  5729. + Willamette/SSE2 instructions to assembler added
  5730. Revision 1.83 2002/07/11 14:41:30 florian
  5731. * start of the new generic parameter handling
  5732. Revision 1.82 2002/07/07 09:52:32 florian
  5733. * powerpc target fixed, very simple units can be compiled
  5734. * some basic stuff for better callparanode handling, far from being finished
  5735. Revision 1.81 2002/07/01 18:46:26 peter
  5736. * internal linker
  5737. * reorganized aasm layer
  5738. Revision 1.80 2002/07/01 16:23:54 peter
  5739. * cg64 patch
  5740. * basics for currency
  5741. * asnode updates for class and interface (not finished)
  5742. Revision 1.79 2002/05/18 13:34:18 peter
  5743. * readded missing revisions
  5744. Revision 1.78 2002/05/16 19:46:44 carl
  5745. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  5746. + try to fix temp allocation (still in ifdef)
  5747. + generic constructor calls
  5748. + start of tassembler / tmodulebase class cleanup
  5749. Revision 1.76 2002/05/12 16:53:10 peter
  5750. * moved entry and exitcode to ncgutil and cgobj
  5751. * foreach gets extra argument for passing local data to the
  5752. iterator function
  5753. * -CR checks also class typecasts at runtime by changing them
  5754. into as
  5755. * fixed compiler to cycle with the -CR option
  5756. * fixed stabs with elf writer, finally the global variables can
  5757. be watched
  5758. * removed a lot of routines from cga unit and replaced them by
  5759. calls to cgobj
  5760. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  5761. u32bit then the other is typecasted also to u32bit without giving
  5762. a rangecheck warning/error.
  5763. * fixed pascal calling method with reversing also the high tree in
  5764. the parast, detected by tcalcst3 test
  5765. Revision 1.75 2002/04/25 20:16:39 peter
  5766. * moved more routines from cga/n386util
  5767. Revision 1.74 2002/04/23 19:16:35 peter
  5768. * add pinline unit that inserts compiler supported functions using
  5769. one or more statements
  5770. * moved finalize and setlength from ninl to pinline
  5771. Revision 1.73 2002/04/21 19:02:05 peter
  5772. * removed newn and disposen nodes, the code is now directly
  5773. inlined from pexpr
  5774. * -an option that will write the secondpass nodes to the .s file, this
  5775. requires EXTDEBUG define to actually write the info
  5776. * fixed various internal errors and crashes due recent code changes
  5777. Revision 1.72 2002/04/20 21:32:25 carl
  5778. + generic FPC_CHECKPOINTER
  5779. + first parameter offset in stack now portable
  5780. * rename some constants
  5781. + move some cpu stuff to other units
  5782. - remove unused constents
  5783. * fix stacksize for some targets
  5784. * fix generic size problems which depend now on EXTEND_SIZE constant
  5785. }