symdef.pas 203 KB

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