symdef.pas 203 KB

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