symdef.pas 238 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331
  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. cclasses,
  23. { global }
  24. globtype,globals,tokens,constexp,
  25. { symtable }
  26. symconst,symbase,symtype,
  27. { ppu }
  28. ppu,
  29. { node }
  30. node,
  31. { aasm }
  32. aasmbase,aasmtai,
  33. cpubase,cpuinfo,
  34. cgbase,
  35. parabase
  36. ;
  37. type
  38. {************************************************
  39. TDef
  40. ************************************************}
  41. tgenericconstraintdata=class
  42. interfaces : tfpobjectlist;
  43. interfacesderef : tfplist;
  44. flags : tgenericconstraintflags;
  45. constructor create;
  46. destructor destroy;override;
  47. procedure ppuload(ppufile:tcompilerppufile);
  48. procedure ppuwrite(ppufile:tcompilerppufile);
  49. procedure buildderef;
  50. procedure deref;
  51. end;
  52. { tstoreddef }
  53. tstoreddef = class(tdef)
  54. private
  55. _fullownerhierarchyname : pshortstring;
  56. procedure writeentry(ppufile: tcompilerppufile; ibnr: byte);
  57. protected
  58. typesymderef : tderef;
  59. procedure fillgenericparas(symtable:tsymtable);
  60. procedure ppuwrite_platform(ppufile:tcompilerppufile);virtual;
  61. procedure ppuload_platform(ppufile:tcompilerppufile);virtual;
  62. public
  63. {$ifdef EXTDEBUG}
  64. fileinfo : tfileposinfo;
  65. {$endif}
  66. { generic support }
  67. genericdef : tstoreddef;
  68. genericdefderef : tderef;
  69. generictokenbuf : tdynamicarray;
  70. { this list contains references to the symbols that make up the
  71. generic parameters; the symbols are not owned by this list
  72. Note: this list is allocated on demand! }
  73. genericparas : tfphashobjectlist;
  74. { contains additional data if this def is a generic constraint
  75. Note: this class is allocated on demand! }
  76. genconstraintdata : tgenericconstraintdata;
  77. constructor create(dt:tdeftyp);
  78. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  79. destructor destroy;override;
  80. function getcopy : tstoreddef;virtual;
  81. procedure ppuwrite(ppufile:tcompilerppufile);virtual;
  82. procedure buildderef;override;
  83. procedure buildderefimpl;override;
  84. procedure deref;override;
  85. procedure derefimpl;override;
  86. function size:asizeint;override;
  87. function getvardef:longint;override;
  88. function alignment:shortint;override;
  89. function is_publishable : boolean;override;
  90. function needs_inittable : boolean;override;
  91. function rtti_mangledname(rt:trttitype):string;override;
  92. function OwnerHierarchyName: string; override;
  93. function fullownerhierarchyname:string;override;
  94. function needs_separate_initrtti:boolean;override;
  95. function in_currentunit: boolean;
  96. { regvars }
  97. function is_intregable : boolean;
  98. function is_fpuregable : boolean;
  99. { def can be put into a register if it is const/immutable }
  100. function is_const_intregable : boolean;
  101. { generics }
  102. procedure initgeneric;
  103. { this function can be used to determine whether a def is really a
  104. generic declaration or just a normal type declared inside another
  105. generic }
  106. function is_generic:boolean;inline;
  107. { same as above for specializations }
  108. function is_specialization:boolean;inline;
  109. private
  110. savesize : asizeuint;
  111. end;
  112. tfiletyp = (ft_text,ft_typed,ft_untyped);
  113. tfiledef = class(tstoreddef)
  114. filetyp : tfiletyp;
  115. typedfiledef : tdef;
  116. typedfiledefderef : tderef;
  117. constructor createtext;virtual;
  118. constructor createuntyped;virtual;
  119. constructor createtyped(def : tdef);virtual;
  120. constructor ppuload(ppufile:tcompilerppufile);
  121. function getcopy : tstoreddef;override;
  122. { do not override this routine in platform-specific subclasses,
  123. override ppuwrite_platform instead }
  124. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  125. procedure buildderef;override;
  126. procedure deref;override;
  127. function GetTypeName:string;override;
  128. function getmangledparaname:TSymStr;override;
  129. function size:asizeint;override;
  130. procedure setsize;
  131. end;
  132. tfiledefclass = class of tfiledef;
  133. tvariantdef = class(tstoreddef)
  134. varianttype : tvarianttype;
  135. constructor create(v : tvarianttype);virtual;
  136. constructor ppuload(ppufile:tcompilerppufile);
  137. function getcopy : tstoreddef;override;
  138. function GetTypeName:string;override;
  139. { do not override this routine in platform-specific subclasses,
  140. override ppuwrite_platform instead }
  141. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  142. function getvardef:longint;override;
  143. procedure setsize;
  144. function is_publishable : boolean;override;
  145. function needs_inittable : boolean;override;
  146. end;
  147. tvariantdefclass = class of tvariantdef;
  148. tformaldef = class(tstoreddef)
  149. typed:boolean;
  150. constructor create(Atyped:boolean);virtual;
  151. constructor ppuload(ppufile:tcompilerppufile);
  152. { do not override this routine in platform-specific subclasses,
  153. override ppuwrite_platform instead }
  154. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  155. function GetTypeName:string;override;
  156. end;
  157. tformaldefclass = class of tformaldef;
  158. tforwarddef = class(tstoreddef)
  159. tosymname : pshortstring;
  160. forwardpos : tfileposinfo;
  161. constructor create(const s:string;const pos:tfileposinfo);virtual;
  162. destructor destroy;override;
  163. function getcopy:tstoreddef;override;
  164. function GetTypeName:string;override;
  165. end;
  166. tforwarddefclass = class of tforwarddef;
  167. tundefineddef = class(tstoreddef)
  168. constructor create;virtual;
  169. constructor ppuload(ppufile:tcompilerppufile);
  170. { do not override this routine in platform-specific subclasses,
  171. override ppuwrite_platform instead }
  172. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  173. function GetTypeName:string;override;
  174. end;
  175. tundefineddefclass = class of tundefineddef;
  176. terrordef = class(tstoreddef)
  177. constructor create;virtual;
  178. { do not override this routine in platform-specific subclasses,
  179. override ppuwrite_platform instead }
  180. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  181. function GetTypeName:string;override;
  182. function getmangledparaname : TSymStr;override;
  183. end;
  184. terrordefclass = class of terrordef;
  185. tabstractpointerdef = class(tstoreddef)
  186. pointeddef : tdef;
  187. pointeddefderef : tderef;
  188. constructor create(dt:tdeftyp;def:tdef);
  189. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  190. procedure ppuwrite(ppufile:tcompilerppufile);override;
  191. procedure buildderef;override;
  192. procedure deref;override;
  193. function size:asizeint;override;
  194. function alignment:shortint;override;
  195. end;
  196. { tpointerdef }
  197. tpointerdef = class(tabstractpointerdef)
  198. has_pointer_math : boolean;
  199. constructor create(def:tdef);virtual;
  200. function size:asizeint;override;
  201. function getcopy:tstoreddef;override;
  202. constructor ppuload(ppufile:tcompilerppufile);
  203. { do not override this routine in platform-specific subclasses,
  204. override ppuwrite_platform instead }
  205. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  206. function GetTypeName:string;override;
  207. end;
  208. tpointerdefclass = class of tpointerdef;
  209. tprocdef = class;
  210. tabstractrecorddef= class(tstoreddef)
  211. objname,
  212. objrealname : PShortString;
  213. { for C++ classes: name of the library this class is imported from }
  214. { for Java classes/records: package name }
  215. import_lib : PShortString;
  216. symtable : TSymtable;
  217. cloneddef : tabstractrecorddef;
  218. cloneddefderef : tderef;
  219. objectoptions : tobjectoptions;
  220. { for targets that initialise typed constants via explicit assignments
  221. instead of by generating an initialised data sectino }
  222. tcinitcode : tnode;
  223. constructor create(const n:string; dt:tdeftyp);
  224. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  225. procedure ppuwrite(ppufile:tcompilerppufile);override;
  226. destructor destroy; override;
  227. procedure check_forwards; virtual;
  228. function find_procdef_bytype(pt:tproctypeoption): tprocdef;
  229. function GetSymtable(t:tGetSymtable):TSymtable;override;
  230. function is_packed:boolean;
  231. function RttiName: string;
  232. { enumerator support }
  233. function search_enumerator_get: tprocdef; virtual;
  234. function search_enumerator_move: tprocdef; virtual;
  235. function search_enumerator_current: tsym; virtual;
  236. { JVM }
  237. function jvm_full_typename(with_package_name: boolean): string;
  238. { check if the symtable contains a float field }
  239. function contains_float_field : boolean;
  240. end;
  241. pvariantrecdesc = ^tvariantrecdesc;
  242. tvariantrecbranch = record
  243. { we store only single values here and no ranges because tvariantrecdesc is only needed in iso mode
  244. which does not support range expressions in variant record definitions }
  245. values : array of Tconstexprint;
  246. nestedvariant : pvariantrecdesc;
  247. end;
  248. ppvariantrecdesc = ^pvariantrecdesc;
  249. tvariantrecdesc = record
  250. variantselector : tsym;
  251. variantselectorderef : tderef;
  252. branches : array of tvariantrecbranch;
  253. end;
  254. trecorddef = class(tabstractrecorddef)
  255. public
  256. variantrecdesc : pvariantrecdesc;
  257. isunion : boolean;
  258. constructor create(const n:string; p:TSymtable);virtual;
  259. constructor ppuload(ppufile:tcompilerppufile);
  260. destructor destroy;override;
  261. function getcopy : tstoreddef;override;
  262. { do not override this routine in platform-specific subclasses,
  263. override ppuwrite_platform instead }
  264. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  265. procedure buildderef;override;
  266. procedure buildderefimpl;override;
  267. procedure deref;override;
  268. function size:asizeint;override;
  269. function alignment : shortint;override;
  270. function padalignment: shortint;
  271. function GetTypeName:string;override;
  272. { debug }
  273. function needs_inittable : boolean;override;
  274. function needs_separate_initrtti:boolean;override;
  275. end;
  276. trecorddefclass = class of trecorddef;
  277. tobjectdef = class;
  278. { TImplementedInterface }
  279. TImplementedInterface = class
  280. private
  281. fIOffset : longint;
  282. function GetIOffset: longint;
  283. public
  284. IntfDef : tobjectdef;
  285. IntfDefDeref : tderef;
  286. IType : tinterfaceentrytype;
  287. VtblImplIntf : TImplementedInterface;
  288. NameMappings : TFPHashList;
  289. ProcDefs : TFPObjectList;
  290. ImplementsGetter : tsym;
  291. ImplementsGetterDeref : tderef;
  292. ImplementsField : tsym;
  293. constructor create(aintf: tobjectdef);virtual;
  294. constructor create_deref(intfd,getterd:tderef);virtual;
  295. destructor destroy; override;
  296. function getcopy:TImplementedInterface;
  297. procedure buildderef;
  298. procedure deref;
  299. procedure AddMapping(const origname, newname: string);
  300. function GetMapping(const origname: string):string;
  301. procedure AddImplProc(pd:tprocdef);
  302. function IsImplMergePossible(MergingIntf:TImplementedInterface;out weight: longint): boolean;
  303. property IOffset: longint read GetIOffset write fIOffset;
  304. end;
  305. timplementedinterfaceclass = class of timplementedinterface;
  306. { tvmtentry }
  307. tvmtentry = record
  308. procdef : tprocdef;
  309. procdefderef : tderef;
  310. visibility : tvisibility;
  311. end;
  312. pvmtentry = ^tvmtentry;
  313. { tobjectdef }
  314. tvmcallstatic = (vmcs_default, vmcs_yes, vmcs_no, vmcs_unreachable);
  315. pmvcallstaticinfo = ^tmvcallstaticinfo;
  316. tmvcallstaticinfo = array[0..1024*1024-1] of tvmcallstatic;
  317. tobjectdef = class(tabstractrecorddef)
  318. private
  319. fcurrent_dispid: longint;
  320. public
  321. dwarf_struct_lab : tasmsymbol;
  322. childof : tobjectdef;
  323. childofderef : tderef;
  324. { for Object Pascal helpers }
  325. extendeddef : tdef;
  326. extendeddefderef: tderef;
  327. { for Objective-C: protocols and classes can have the same name there }
  328. objextname : pshortstring;
  329. { to be able to have a variable vmt position }
  330. { and no vmt field for objects without virtuals }
  331. vmtentries : TFPList;
  332. vmcallstaticinfo : pmvcallstaticinfo;
  333. vmt_offset : longint;
  334. iidguid : pguid;
  335. iidstr : pshortstring;
  336. { store implemented interfaces defs and name mappings }
  337. ImplementedInterfaces : TFPObjectList;
  338. { number of abstract methods (used by JVM target to determine whether
  339. or not the class should be marked as abstract: must be done if 1 or
  340. more abstract methods) }
  341. abstractcnt : longint;
  342. writing_class_record_dbginfo,
  343. { a class of this type has been created in this module }
  344. created_in_current_module,
  345. { a loadvmtnode for this class has been created in this
  346. module, so if a classrefdef variable of this or a parent
  347. class is used somewhere to instantiate a class, then this
  348. class may be instantiated
  349. }
  350. maybe_created_in_current_module,
  351. { a "class of" this particular class has been created in
  352. this module
  353. }
  354. classref_created_in_current_module : boolean;
  355. objecttype : tobjecttyp;
  356. constructor create(ot:tobjecttyp;const n:string;c:tobjectdef);virtual;
  357. constructor ppuload(ppufile:tcompilerppufile);
  358. destructor destroy;override;
  359. function getcopy : tstoreddef;override;
  360. { do not override this routine in platform-specific subclasses,
  361. override ppuwrite_platform instead }
  362. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  363. function GetTypeName:string;override;
  364. procedure buildderef;override;
  365. procedure deref;override;
  366. procedure buildderefimpl;override;
  367. procedure derefimpl;override;
  368. procedure resetvmtentries;
  369. procedure copyvmtentries(objdef:tobjectdef);
  370. function getparentdef:tdef;override;
  371. function size : asizeint;override;
  372. function alignment:shortint;override;
  373. function vmtmethodoffset(index:longint):longint;
  374. function members_need_inittable : boolean;
  375. { this should be called when this class implements an interface }
  376. procedure prepareguid;
  377. function is_publishable : boolean;override;
  378. function needs_inittable : boolean;override;
  379. function needs_separate_initrtti : boolean;override;
  380. function rtti_mangledname(rt:trttitype):string;override;
  381. function vmt_mangledname : TSymStr;
  382. procedure check_forwards; override;
  383. procedure insertvmt;
  384. procedure set_parent(c : tobjectdef);
  385. function find_destructor: tprocdef;
  386. function implements_any_interfaces: boolean;
  387. { dispinterface support }
  388. function get_next_dispid: longint;
  389. { enumerator support }
  390. function search_enumerator_get: tprocdef; override;
  391. function search_enumerator_move: tprocdef; override;
  392. function search_enumerator_current: tsym; override;
  393. { WPO }
  394. procedure register_created_object_type;override;
  395. procedure register_maybe_created_object_type;
  396. procedure register_created_classref_type;
  397. procedure register_vmt_call(index:longint);
  398. { ObjC }
  399. procedure finish_objc_data;
  400. function check_objc_types: boolean;
  401. { C++ }
  402. procedure finish_cpp_data;
  403. end;
  404. tobjectdefclass = class of tobjectdef;
  405. tclassrefdef = class(tabstractpointerdef)
  406. constructor create(def:tdef);virtual;
  407. constructor ppuload(ppufile:tcompilerppufile);
  408. { do not override this routine in platform-specific subclasses,
  409. override ppuwrite_platform instead }
  410. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  411. function getcopy:tstoreddef;override;
  412. function GetTypeName:string;override;
  413. function is_publishable : boolean;override;
  414. function rtti_mangledname(rt:trttitype):string;override;
  415. procedure register_created_object_type;override;
  416. end;
  417. tclassrefdefclass = class of tclassrefdef;
  418. tarraydef = class(tstoreddef)
  419. lowrange,
  420. highrange : asizeint;
  421. rangedef : tdef;
  422. rangedefderef : tderef;
  423. arrayoptions : tarraydefoptions;
  424. symtable : TSymtable;
  425. protected
  426. _elementdef : tdef;
  427. _elementdefderef : tderef;
  428. procedure setelementdef(def:tdef);
  429. public
  430. function elesize : asizeint;
  431. function elepackedbitsize : asizeint;
  432. function elecount : asizeuint;
  433. constructor create_from_pointer(def:tdef);virtual;
  434. constructor create(l,h:asizeint;def:tdef);virtual;
  435. constructor ppuload(ppufile:tcompilerppufile);
  436. destructor destroy; override;
  437. function getcopy : tstoreddef;override;
  438. { do not override this routine in platform-specific subclasses,
  439. override ppuwrite_platform instead }
  440. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  441. function GetTypeName:string;override;
  442. function getmangledparaname : TSymStr;override;
  443. procedure buildderef;override;
  444. procedure deref;override;
  445. function size : asizeint;override;
  446. function alignment : shortint;override;
  447. { returns the label of the range check string }
  448. function needs_inittable : boolean;override;
  449. function needs_separate_initrtti : boolean;override;
  450. property elementdef : tdef read _elementdef write setelementdef;
  451. function is_publishable : boolean;override;
  452. end;
  453. tarraydefclass = class of tarraydef;
  454. torddef = class(tstoreddef)
  455. low,high : TConstExprInt;
  456. ordtype : tordtype;
  457. constructor create(t : tordtype;v,b : TConstExprInt);virtual;
  458. constructor ppuload(ppufile:tcompilerppufile);
  459. function getcopy : tstoreddef;override;
  460. { do not override this routine in platform-specific subclasses,
  461. override ppuwrite_platform instead }
  462. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  463. function is_publishable : boolean;override;
  464. function GetTypeName:string;override;
  465. function alignment:shortint;override;
  466. procedure setsize;
  467. function packedbitsize: asizeint; override;
  468. function getvardef : longint;override;
  469. end;
  470. torddefclass = class of torddef;
  471. tfloatdef = class(tstoreddef)
  472. floattype : tfloattype;
  473. constructor create(t : tfloattype);virtual;
  474. constructor ppuload(ppufile:tcompilerppufile);
  475. function getcopy : tstoreddef;override;
  476. { do not override this routine in platform-specific subclasses,
  477. override ppuwrite_platform instead }
  478. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  479. function GetTypeName:string;override;
  480. function is_publishable : boolean;override;
  481. function alignment:shortint;override;
  482. function structalignment: shortint;override;
  483. procedure setsize;
  484. function getvardef:longint;override;
  485. end;
  486. tfloatdefclass = class of tfloatdef;
  487. { tabstractprocdef }
  488. tprocnameoption = (pno_showhidden, pno_proctypeoption, pno_paranames,
  489. pno_ownername, pno_noclassmarker, pno_noleadingdollar,
  490. pno_mangledname);
  491. tprocnameoptions = set of tprocnameoption;
  492. tproccopytyp = (pc_normal,
  493. { always creates a top-level function, removes all
  494. special parameters (self, vmt, parentfp, ...) }
  495. pc_bareproc
  496. );
  497. tabstractprocdef = class(tstoreddef)
  498. { saves a definition to the return type }
  499. returndef : tdef;
  500. returndefderef : tderef;
  501. parast : TSymtable;
  502. paras : tparalist;
  503. proctypeoption : tproctypeoption;
  504. proccalloption : tproccalloption;
  505. procoptions : tprocoptions;
  506. callerargareasize,
  507. calleeargareasize: pint;
  508. {$ifdef m68k}
  509. exp_funcretloc : tregister; { explicit funcretloc for AmigaOS }
  510. {$endif}
  511. funcretloc : array[tcallercallee] of TCGPara;
  512. has_paraloc_info : tcallercallee; { paraloc info is available }
  513. { number of user visible parameters }
  514. maxparacount,
  515. minparacount : byte;
  516. constructor create(dt:tdeftyp;level:byte);
  517. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  518. destructor destroy;override;
  519. procedure ppuwrite(ppufile:tcompilerppufile);override;
  520. procedure buildderef;override;
  521. procedure deref;override;
  522. procedure calcparas;
  523. function typename_paras(pno: tprocnameoptions): ansistring;
  524. function is_methodpointer:boolean;virtual;
  525. function is_addressonly:boolean;virtual;
  526. function no_self_node:boolean;
  527. { get either a copy as a procdef or procvardef }
  528. function getcopyas(newtyp:tdeftyp;copytyp:tproccopytyp): tstoreddef; virtual;
  529. procedure check_mark_as_nested;
  530. procedure init_paraloc_info(side: tcallercallee);
  531. function stack_tainting_parameter(side: tcallercallee): boolean;
  532. function is_pushleftright: boolean;
  533. function address_type:tdef;
  534. private
  535. procedure count_para(p:TObject;arg:pointer);
  536. procedure insert_para(p:TObject;arg:pointer);
  537. end;
  538. tprocvardef = class(tabstractprocdef)
  539. constructor create(level:byte);virtual;
  540. constructor ppuload(ppufile:tcompilerppufile);
  541. function getcopy : tstoreddef;override;
  542. { do not override this routine in platform-specific subclasses,
  543. override ppuwrite_platform instead }
  544. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  545. function GetSymtable(t:tGetSymtable):TSymtable;override;
  546. function size : asizeint;override;
  547. function GetTypeName:string;override;
  548. function is_publishable : boolean;override;
  549. function is_methodpointer:boolean;override;
  550. function is_addressonly:boolean;override;
  551. function getmangledparaname:TSymStr;override;
  552. end;
  553. tprocvardefclass = class of tprocvardef;
  554. tmessageinf = record
  555. case integer of
  556. 0 : (str : pshortstring);
  557. 1 : (i : longint);
  558. end;
  559. tinlininginfo = record
  560. { node tree }
  561. code : tnode;
  562. flags : tprocinfoflags;
  563. end;
  564. pinlininginfo = ^tinlininginfo;
  565. {$ifdef oldregvars}
  566. { register variables }
  567. pregvarinfo = ^tregvarinfo;
  568. tregvarinfo = record
  569. regvars : array[1..maxvarregs] of tsym;
  570. regvars_para : array[1..maxvarregs] of boolean;
  571. regvars_refs : array[1..maxvarregs] of longint;
  572. fpuregvars : array[1..maxfpuvarregs] of tsym;
  573. fpuregvars_para : array[1..maxfpuvarregs] of boolean;
  574. fpuregvars_refs : array[1..maxfpuvarregs] of longint;
  575. end;
  576. {$endif oldregvars}
  577. timplprocdefinfo = record
  578. resultname : pshortstring;
  579. parentfpstruct: tsym;
  580. parentfpstructptrtype: tdef;
  581. parentfpinitblock: tnode;
  582. procstarttai,
  583. procendtai : tai;
  584. skpara: pointer;
  585. forwarddef,
  586. interfacedef : boolean;
  587. hasforward : boolean;
  588. end;
  589. pimplprocdefinfo = ^timplprocdefinfo;
  590. { tprocdef }
  591. tprocdef = class(tabstractprocdef)
  592. protected
  593. {$ifdef symansistr}
  594. _mangledname : ansistring;
  595. {$else symansistr}
  596. _mangledname : pshortstring;
  597. {$endif}
  598. { information that is only required until the implementation of the
  599. procdef has been handled }
  600. implprocdefinfo : pimplprocdefinfo;
  601. function GetResultName: PShortString;
  602. procedure SetResultName(AValue: PShortString);
  603. function GetParentFPStruct: tsym;
  604. procedure SetParentFPStruct(AValue: tsym);
  605. function GetParentFPStructPtrType: tdef;
  606. procedure SetParentFPStructPtrType(AValue: tdef);
  607. function GetParentFPInitBlock: tnode;
  608. procedure SetParentFPInitBlock(AValue: tnode);
  609. function Getprocstarttai: tai;
  610. procedure Setprocstarttai(AValue: tai);
  611. function Getprocendtai: tai;
  612. procedure Setprocendtai(AValue: tai);
  613. function Getskpara: pointer;
  614. procedure Setskpara(AValue: pointer);
  615. function Getforwarddef: boolean;
  616. procedure Setforwarddef(AValue: boolean);
  617. function Getinterfacedef: boolean;
  618. procedure Setinterfacedef(AValue: boolean);
  619. function Gethasforward: boolean;
  620. procedure Sethasforward(AValue: boolean);
  621. function GetIsEmpty: boolean;
  622. procedure SetIsEmpty(AValue: boolean);
  623. function GetHasInliningInfo: boolean;
  624. procedure SetHasInliningInfo(AValue: boolean);
  625. public
  626. messageinf : tmessageinf;
  627. dispid : longint;
  628. {$ifndef EXTDEBUG}
  629. { where is this function defined and what were the symbol
  630. flags, needed here because there
  631. is only one symbol for all overloaded functions
  632. EXTDEBUG has fileinfo in tdef (PFV) }
  633. fileinfo : tfileposinfo;
  634. {$endif}
  635. symoptions : tsymoptions;
  636. deprecatedmsg : pshortstring;
  637. { symbol owning this definition }
  638. procsym : tsym;
  639. procsymderef : tderef;
  640. { alias names }
  641. aliasnames : TCmdStrList;
  642. { symtables }
  643. localst : TSymtable;
  644. funcretsym : tsym;
  645. funcretsymderef : tderef;
  646. struct : tabstractrecorddef;
  647. structderef : tderef;
  648. implprocoptions: timplprocoptions;
  649. { import info }
  650. import_dll,
  651. import_name : pshortstring;
  652. { info for inlining the subroutine, if this pointer is nil,
  653. the procedure can't be inlined }
  654. inlininginfo : pinlininginfo;
  655. {$ifdef oldregvars}
  656. regvarinfo: pregvarinfo;
  657. {$endif oldregvars}
  658. import_nr : word;
  659. extnumber : word;
  660. visibility : tvisibility;
  661. { set to a value different from tsk_none in case this procdef is for
  662. a routine that has to be internally generated by the compiler }
  663. synthetickind : tsynthetickind;
  664. constructor create(level:byte);virtual;
  665. constructor ppuload(ppufile:tcompilerppufile);
  666. destructor destroy;override;
  667. { do not override this routine in platform-specific subclasses,
  668. override ppuwrite_platform instead }
  669. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  670. procedure buildderef;override;
  671. procedure buildderefimpl;override;
  672. procedure deref;override;
  673. procedure derefimpl;override;
  674. function GetSymtable(t:tGetSymtable):TSymtable;override;
  675. { warnings:
  676. * the symtablestack top has to be the symtable to which the copy
  677. should be added
  678. * getcopy does not create a finished/ready-to-use procdef; it
  679. needs to be finalised afterwards by calling
  680. symcreat.finish_copied_procdef() afterwards
  681. }
  682. function getcopyas(newtyp:tdeftyp;copytyp:tproccopytyp): tstoreddef; override;
  683. function getcopy: tstoreddef; override;
  684. function GetTypeName : string;override;
  685. function mangledname : TSymStr; virtual;
  686. procedure setmangledname(const s : TSymStr);
  687. function fullprocname(showhidden:boolean):string;
  688. function customprocname(pno: tprocnameoptions):ansistring;
  689. function defaultmangledname: TSymStr;
  690. function cplusplusmangledname : TSymStr;
  691. function objcmangledname : TSymStr;
  692. function is_methodpointer:boolean;override;
  693. function is_addressonly:boolean;override;
  694. procedure make_external;
  695. { aliases to fields only required when a function is implemented in
  696. the current unit }
  697. property resultname: PShortString read GetResultName write SetResultName;
  698. { temporary reference to structure containing copies of all local
  699. variables and parameters accessed by nested routines; reference to
  700. this structure is passed as "parent frame pointer" on targets that
  701. lack this concept (at least JVM and LLVM); no need to save to/
  702. restore from ppu, since nested routines are always in the same
  703. unit }
  704. property parentfpstruct: tsym read GetParentFPStruct write SetParentFPStruct;
  705. { pointer to parentfpstruct's type (not yet valid during parsing, so
  706. cannot be used for $parentfp parameter) (no need to save to ppu) }
  707. property parentfpstructptrtype: tdef read GetParentFPStructPtrType write SetParentFPStructPtrType;
  708. { code to copy the parameters accessed from nested routines into the
  709. parentfpstruct (no need to save to ppu) }
  710. property parentfpinitblock: tnode read GetParentFPInitBlock write SetParentFPInitBlock;
  711. { First/last assembler symbol/instruction in aasmoutput list.
  712. Note: initialised after compiling the code for the procdef, but
  713. not saved to/restored from ppu. Used when inserting debug info }
  714. property procstarttai: tai read Getprocstarttai write Setprocstarttai;
  715. property procendtai: tai read Getprocendtai write Setprocendtai;
  716. { optional parameter for the synthetic routine generation logic }
  717. property skpara: pointer read Getskpara write Setskpara;
  718. { true, if the procedure is only declared
  719. (forward procedure) }
  720. property forwarddef: boolean read Getforwarddef write Setforwarddef;
  721. { true if the procedure is declared in the interface }
  722. property interfacedef: boolean read Getinterfacedef write Setinterfacedef;
  723. { true if the procedure has a forward declaration }
  724. property hasforward: boolean read Gethasforward write Sethasforward;
  725. { true if the routine's body is empty }
  726. property isempty: boolean read GetIsEmpty write SetIsEmpty;
  727. { true if all information required to inline this routine is available }
  728. property has_inlininginfo: boolean read GetHasInliningInfo write SetHasInliningInfo;
  729. end;
  730. tprocdefclass = class of tprocdef;
  731. { single linked list of overloaded procs }
  732. pprocdeflist = ^tprocdeflist;
  733. tprocdeflist = record
  734. def : tprocdef;
  735. defderef : tderef;
  736. next : pprocdeflist;
  737. end;
  738. tstringdef = class(tstoreddef)
  739. encoding : tstringencoding;
  740. stringtype : tstringtype;
  741. len : asizeint;
  742. constructor createshort(l : byte);virtual;
  743. constructor loadshort(ppufile:tcompilerppufile);
  744. constructor createlong(l : asizeint);virtual;
  745. constructor loadlong(ppufile:tcompilerppufile);
  746. constructor createansi(aencoding:tstringencoding);virtual;
  747. constructor loadansi(ppufile:tcompilerppufile);
  748. constructor createwide;virtual;
  749. constructor loadwide(ppufile:tcompilerppufile);
  750. constructor createunicode;virtual;
  751. constructor loadunicode(ppufile:tcompilerppufile);virtual;
  752. function getcopy : tstoreddef;override;
  753. function stringtypname:string;
  754. { do not override this routine in platform-specific subclasses,
  755. override ppuwrite_platform instead }
  756. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  757. function GetTypeName:string;override;
  758. function getmangledparaname:TSymStr;override;
  759. function is_publishable : boolean;override;
  760. function size:asizeint;override;
  761. function alignment : shortint;override;
  762. function needs_inittable : boolean;override;
  763. function getvardef:longint;override;
  764. end;
  765. tstringdefclass = class of tstringdef;
  766. { tenumdef }
  767. tenumdef = class(tstoreddef)
  768. minval,
  769. maxval : asizeint;
  770. basedef : tenumdef;
  771. basedefderef : tderef;
  772. symtable : TSymtable;
  773. has_jumps : boolean;
  774. constructor create;virtual;
  775. constructor create_subrange(_basedef:tenumdef;_min,_max:asizeint);virtual;
  776. constructor ppuload(ppufile:tcompilerppufile);
  777. destructor destroy;override;
  778. function getcopy : tstoreddef;override;
  779. { do not override this routine in platform-specific subclasses,
  780. override ppuwrite_platform instead }
  781. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  782. procedure buildderef;override;
  783. procedure deref;override;
  784. function GetTypeName:string;override;
  785. function is_publishable : boolean;override;
  786. procedure calcsavesize;
  787. function packedbitsize: asizeint; override;
  788. procedure setmax(_max:asizeint);
  789. procedure setmin(_min:asizeint);
  790. function min:asizeint;
  791. function max:asizeint;
  792. function getfirstsym:tsym;
  793. function int2enumsym(l: asizeint): tsym;
  794. { returns basedef if assigned, otherwise self }
  795. function getbasedef: tenumdef;
  796. end;
  797. tenumdefclass = class of tenumdef;
  798. tsetdef = class(tstoreddef)
  799. elementdef : tdef;
  800. elementdefderef : tderef;
  801. setbase,
  802. setmax : aword;
  803. constructor create(def:tdef;low, high : asizeint);virtual;
  804. constructor ppuload(ppufile:tcompilerppufile);
  805. function getcopy : tstoreddef;override;
  806. { do not override this routine in platform-specific subclasses,
  807. override ppuwrite_platform instead }
  808. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  809. procedure buildderef;override;
  810. procedure deref;override;
  811. function GetTypeName:string;override;
  812. function is_publishable : boolean;override;
  813. end;
  814. tsetdefclass = class of tsetdef;
  815. tgenericdummyentry = class
  816. dummysym : tsym;
  817. resolvedsym : tsym;
  818. end;
  819. tdefawaresymtablestack = class(TSymtablestack)
  820. private
  821. procedure add_helpers_and_generics(st:tsymtable;addgenerics:boolean);
  822. procedure remove_helpers_and_generics(st:tsymtable);inline;
  823. procedure remove_helpers(st:tsymtable);
  824. procedure remove_generics(st:tsymtable);
  825. procedure pushcommon(st:tsymtable);inline;
  826. public
  827. procedure push(st: TSymtable); override;
  828. procedure pushafter(st,afterst:TSymtable); override;
  829. procedure pop(st: TSymtable); override;
  830. end;
  831. var
  832. current_structdef: tabstractrecorddef; { used for private functions check !! }
  833. current_genericdef: tstoreddef; { used to reject declaration of generic class inside generic class }
  834. current_specializedef: tstoreddef; { used to implement usage of generic class in itself }
  835. cfiledef: tfiledefclass;
  836. cvariantdef: tvariantdefclass;
  837. cformaldef: tformaldefclass;
  838. cforwarddef: tforwarddefclass;
  839. cundefineddef: tundefineddefclass;
  840. cerrordef: terrordefclass;
  841. cpointerdef: tpointerdefclass;
  842. crecorddef: trecorddefclass;
  843. cimplementedinterface: timplementedinterfaceclass;
  844. cobjectdef: tobjectdefclass;
  845. cclassrefdef: tclassrefdefclass;
  846. carraydef: tarraydefclass;
  847. corddef: torddefclass;
  848. cfloatdef: tfloatdefclass;
  849. cprocvardef: tprocvardefclass;
  850. cprocdef: tprocdefclass;
  851. cstringdef: tstringdefclass;
  852. cenumdef: tenumdefclass;
  853. csetdef: tsetdefclass;
  854. { default types }
  855. generrordef, { error in definition }
  856. voidpointertype, { pointer for Void-pointeddef }
  857. charpointertype, { pointer for Char-pointeddef }
  858. widecharpointertype, { pointer for WideChar-pointeddef }
  859. voidcodepointertype, { pointer to code; corresponds to System.CodePointer }
  860. voidstackpointertype, { the pointer type used for accessing parameters and local vars on the stack }
  861. parentfpvoidpointertype, { void pointer with the size of the hidden parentfp parameter, passed to nested functions }
  862. {$ifdef x86}
  863. voidnearpointertype,
  864. voidnearcspointertype,
  865. voidneardspointertype,
  866. voidnearsspointertype,
  867. voidnearespointertype,
  868. voidnearfspointertype,
  869. voidneargspointertype,
  870. {$ifdef i8086}
  871. voidfarpointertype,
  872. voidhugepointertype,
  873. charnearpointertype,
  874. charfarpointertype,
  875. bytefarpointertype, { used for Mem[] }
  876. wordfarpointertype, { used for MemW[] }
  877. longintfarpointertype, { used for MemL[] }
  878. {$endif i8086}
  879. {$endif x86}
  880. cundefinedtype,
  881. cformaltype, { unique formal definition }
  882. ctypedformaltype, { unique typed formal definition }
  883. voidtype, { Void (procedure) }
  884. cansichartype, { Char }
  885. cwidechartype, { WideChar }
  886. pasbool8type, { boolean type }
  887. pasbool16type,
  888. pasbool32type,
  889. pasbool64type,
  890. bool8type,
  891. bool16type,
  892. bool32type,
  893. bool64type, { implement me }
  894. u8inttype, { 8-Bit unsigned integer }
  895. s8inttype, { 8-Bit signed integer }
  896. u16inttype, { 16-Bit unsigned integer }
  897. s16inttype, { 16-Bit signed integer }
  898. u32inttype, { 32-Bit unsigned integer }
  899. s32inttype, { 32-Bit signed integer }
  900. u64inttype, { 64-bit unsigned integer }
  901. s64inttype, { 64-bit signed integer }
  902. s32floattype, { 32 bit floating point number }
  903. s64floattype, { 64 bit floating point number }
  904. s80floattype, { 80 bit floating point number }
  905. sc80floattype, { 80 bit floating point number but stored like in C }
  906. s64currencytype, { pointer to a currency type }
  907. cshortstringtype, { pointer to type of short string const }
  908. clongstringtype, { pointer to type of long string const }
  909. cansistringtype, { pointer to type of ansi string const }
  910. cwidestringtype, { pointer to type of wide string const }
  911. cunicodestringtype,
  912. openshortstringtype, { pointer to type of an open shortstring,
  913. needed for readln() }
  914. openchararraytype, { pointer to type of an open array of char,
  915. needed for readln() }
  916. cfiletype, { get the same definition for all file }
  917. { used for stabs }
  918. methodpointertype, { typecasting of methodpointers to extract self }
  919. hresultdef,
  920. { we use only one variant def for every variant class }
  921. cvarianttype,
  922. colevarianttype,
  923. { default integer type s32inttype on 32 bit systems, s64bittype on 64 bit systems }
  924. sinttype,
  925. uinttype,
  926. { integer types corresponding to OS_SINT/OS_INT }
  927. ossinttype,
  928. osuinttype,
  929. { unsigned and signed ord type with the same size as a pointer }
  930. ptruinttype,
  931. ptrsinttype,
  932. { several types to simulate more or less C++ objects for GDB }
  933. vmttype,
  934. vmtarraytype,
  935. pvmttype : tdef; { type of classrefs, used for stabs }
  936. { pointer to the anchestor of all classes }
  937. class_tobject : tobjectdef;
  938. { pointer to the ancestor of all COM interfaces }
  939. interface_iunknown : tobjectdef;
  940. { pointer to the ancestor of all dispinterfaces }
  941. interface_idispatch : tobjectdef;
  942. { pointer to the TGUID type
  943. of all interfaces }
  944. rec_tguid : trecorddef;
  945. { pointer to jump buffer }
  946. rec_jmp_buf : trecorddef;
  947. { Objective-C base types }
  948. objc_metaclasstype,
  949. objc_superclasstype,
  950. objc_idtype,
  951. objc_seltype : tpointerdef;
  952. objc_objecttype : trecorddef;
  953. { base type of @protocol(protocolname) Objective-C statements }
  954. objc_protocoltype : tobjectdef;
  955. { helper types for for-in "fast enumeration" support in Objective-C 2.0 }
  956. objc_fastenumeration : tobjectdef;
  957. objc_fastenumerationstate : trecorddef;
  958. { Java base types }
  959. { java.lang.Object }
  960. java_jlobject : tobjectdef;
  961. { java.lang.Throwable }
  962. java_jlthrowable : tobjectdef;
  963. { FPC base type for records }
  964. java_fpcbaserecordtype : tobjectdef;
  965. { java.lang.String }
  966. java_jlstring : tobjectdef;
  967. { java.lang.Enum }
  968. java_jlenum : tobjectdef;
  969. { java.util.EnumSet }
  970. java_juenumset : tobjectdef;
  971. { java.util.BitSet }
  972. java_jubitset : tobjectdef;
  973. { FPC java implementation of ansistrings }
  974. java_ansistring : tobjectdef;
  975. { FPC java implementation of shortstrings }
  976. java_shortstring : tobjectdef;
  977. { FPC java procvar base class }
  978. java_procvarbase : tobjectdef;
  979. function make_mangledname(const typeprefix:TSymStr;st:TSymtable;const suffix:TSymStr):TSymStr;
  980. function make_dllmangledname(const dllname,importname:TSymStr;
  981. import_nr : word; pco : tproccalloption):TSymStr;
  982. { should be in the types unit, but the types unit uses the node stuff :( }
  983. function is_interfacecom(def: tdef): boolean;
  984. function is_interfacecom_or_dispinterface(def: tdef): boolean;
  985. function is_any_interface_kind(def: tdef): boolean;
  986. function is_interfacecorba(def: tdef): boolean;
  987. function is_interface(def: tdef): boolean;
  988. function is_dispinterface(def: tdef): boolean;
  989. function is_object(def: tdef): boolean;
  990. function is_class(def: tdef): boolean;
  991. function is_cppclass(def: tdef): boolean;
  992. function is_objectpascal_helper(def: tdef): boolean;
  993. function is_objcclass(def: tdef): boolean;
  994. function is_objcclassref(def: tdef): boolean;
  995. function is_objcprotocol(def: tdef): boolean;
  996. function is_objccategory(def: tdef): boolean;
  997. function is_objc_class_or_protocol(def: tdef): boolean;
  998. function is_objc_protocol_or_category(def: tdef): boolean;
  999. function is_classhelper(def: tdef): boolean;
  1000. function is_class_or_interface(def: tdef): boolean;
  1001. function is_class_or_interface_or_objc(def: tdef): boolean;
  1002. function is_class_or_interface_or_objc_or_java(def: tdef): boolean;
  1003. function is_class_or_interface_or_dispinterface_or_objc_or_java(def: tdef): boolean;
  1004. function is_class_or_interface_or_object(def: tdef): boolean;
  1005. function is_class_or_interface_or_dispinterface(def: tdef): boolean;
  1006. function is_implicit_pointer_object_type(def: tdef): boolean;
  1007. { returns true, if def is a type which is an implicit pointer to an array (dyn. array or dyn. string) }
  1008. function is_implicit_array_pointer(def: tdef): boolean;
  1009. function is_class_or_object(def: tdef): boolean;
  1010. function is_record(def: tdef): boolean;
  1011. function is_javaclass(def: tdef): boolean;
  1012. function is_javaclassref(def: tdef): boolean;
  1013. function is_javainterface(def: tdef): boolean;
  1014. function is_java_class_or_interface(def: tdef): boolean;
  1015. procedure loadobjctypes;
  1016. procedure maybeloadcocoatypes;
  1017. function use_vectorfpu(def : tdef) : boolean;
  1018. { returns a pointerdef for def, reusing an existing one in case it exists
  1019. in the current module }
  1020. function getpointerdef(def: tdef): tpointerdef;
  1021. { returns an arraydef for an array containing a single array of def, resuing
  1022. an existing one in case it exists in the current module }
  1023. function getsingletonarraydef(def: tdef): tarraydef;
  1024. function getarraydef(def: tdef; elecount: asizeint): tarraydef;
  1025. function getansistringcodepage:tstringencoding; inline;
  1026. function getansistringdef:tstringdef;
  1027. function getparaencoding(def:tdef):tstringencoding; inline;
  1028. implementation
  1029. uses
  1030. SysUtils,
  1031. cutils,
  1032. { global }
  1033. verbose,
  1034. { target }
  1035. systems,paramgr,
  1036. { symtable }
  1037. symsym,symtable,defutil,objcdef,
  1038. { parser }
  1039. pgenutil,
  1040. { module }
  1041. fmodule,
  1042. { other }
  1043. gendef,
  1044. fpccrc
  1045. ;
  1046. {****************************************************************************
  1047. Helpers
  1048. ****************************************************************************}
  1049. function getansistringcodepage:tstringencoding; inline;
  1050. begin
  1051. if cs_explicit_codepage in current_settings.moduleswitches then
  1052. result:=current_settings.sourcecodepage
  1053. else
  1054. result:=0;
  1055. end;
  1056. function getansistringdef:tstringdef;
  1057. var
  1058. symtable:tsymtable;
  1059. begin
  1060. { if codepage is explicitly defined in this mudule we need to return
  1061. a replacement for ansistring def }
  1062. if cs_explicit_codepage in current_settings.moduleswitches then
  1063. begin
  1064. if not assigned(current_module) then
  1065. internalerror(2011101301);
  1066. { codepage can be redeclared only once per unit so we don't need a list of
  1067. redefined ansistring but only one pointer }
  1068. if not assigned(current_module.ansistrdef) then
  1069. begin
  1070. { if we did not create it yet we need to do this now }
  1071. if current_module.is_unit then
  1072. symtable:=current_module.globalsymtable
  1073. else
  1074. symtable:=current_module.localsymtable;
  1075. symtablestack.push(symtable);
  1076. current_module.ansistrdef:=cstringdef.createansi(current_settings.sourcecodepage);
  1077. symtablestack.pop(symtable);
  1078. end;
  1079. result:=tstringdef(current_module.ansistrdef);
  1080. end
  1081. else
  1082. result:=tstringdef(cansistringtype);
  1083. end;
  1084. function getparaencoding(def:tdef):tstringencoding; inline;
  1085. begin
  1086. { don't pass CP_NONE encoding to internal functions
  1087. they expect 0 encoding instead
  1088. exception: result of string concatenation, because if you pass the
  1089. result of a string concatenation to a rawbytestring, the result of
  1090. that concatenation shouldn't be converted to defaultsystemcodepage
  1091. if all strings have the same type }
  1092. result:=tstringdef(def).encoding;
  1093. if result=globals.CP_NONE then
  1094. result:=0
  1095. end;
  1096. function make_mangledname(const typeprefix:TSymStr;st:TSymtable;const suffix:TSymStr):TSymStr;
  1097. var
  1098. s,hs,
  1099. prefix : TSymStr;
  1100. oldlen,
  1101. newlen,
  1102. i : longint;
  1103. crc : dword;
  1104. hp : tparavarsym;
  1105. begin
  1106. prefix:='';
  1107. hp:=nil;
  1108. if not assigned(st) then
  1109. internalerror(200204212);
  1110. { sub procedures }
  1111. while (st.symtabletype=localsymtable) do
  1112. begin
  1113. if st.defowner.typ<>procdef then
  1114. internalerror(200204173);
  1115. { Add the full mangledname of procedure to prevent
  1116. conflicts with 2 overloads having both a nested procedure
  1117. with the same name, see tb0314 (PFV) }
  1118. s:=tprocdef(st.defowner).procsym.name;
  1119. oldlen:=length(s);
  1120. for i:=0 to tprocdef(st.defowner).paras.count-1 do
  1121. begin
  1122. hp:=tparavarsym(tprocdef(st.defowner).paras[i]);
  1123. if not(vo_is_hidden_para in hp.varoptions) then
  1124. s:=s+'$'+hp.vardef.mangledparaname;
  1125. end;
  1126. if not is_void(tprocdef(st.defowner).returndef) then
  1127. s:=s+'$$'+tprocdef(st.defowner).returndef.mangledparaname;
  1128. newlen:=length(s);
  1129. { Replace with CRC if the parameter line is very long }
  1130. if (newlen-oldlen>12) and
  1131. ((newlen+length(prefix)>100) or (newlen-oldlen>32)) then
  1132. begin
  1133. crc:=0;
  1134. for i:=0 to tprocdef(st.defowner).paras.count-1 do
  1135. begin
  1136. hp:=tparavarsym(tprocdef(st.defowner).paras[i]);
  1137. if not(vo_is_hidden_para in hp.varoptions) then
  1138. begin
  1139. hs:=hp.vardef.mangledparaname;
  1140. crc:=UpdateCrc32(crc,hs[1],length(hs));
  1141. end;
  1142. end;
  1143. hs:=hp.vardef.mangledparaname;
  1144. crc:=UpdateCrc32(crc,hs[1],length(hs));
  1145. s:=Copy(s,1,oldlen)+'$crc'+hexstr(crc,8);
  1146. end;
  1147. if prefix<>'' then
  1148. prefix:=s+'_'+prefix
  1149. else
  1150. prefix:=s;
  1151. if length(prefix)>100 then
  1152. begin
  1153. crc:=0;
  1154. crc:=UpdateCrc32(crc,prefix[1],length(prefix));
  1155. prefix:='$CRC'+hexstr(crc,8);
  1156. end;
  1157. st:=st.defowner.owner;
  1158. end;
  1159. { object/classes symtable, nested type definitions in classes require the while loop }
  1160. while st.symtabletype in [ObjectSymtable,recordsymtable] do
  1161. begin
  1162. if not (st.defowner.typ in [objectdef,recorddef]) then
  1163. internalerror(200204174);
  1164. prefix:=tabstractrecorddef(st.defowner).objname^+'_$_'+prefix;
  1165. st:=st.defowner.owner;
  1166. end;
  1167. { symtable must now be static or global }
  1168. if not(st.symtabletype in [staticsymtable,globalsymtable]) then
  1169. internalerror(200204175);
  1170. { The mangled name is made out of at most 4 parts:
  1171. 1) Optional typeprefix given as first parameter
  1172. with '_$' appended if not empty
  1173. 2) Unit name or 'P$'+program name (never empty)
  1174. 3) optional prefix variable that contains a unique
  1175. name for the local symbol table (prepended with '$_$'
  1176. if not empty)
  1177. 4) suffix as given as third parameter,
  1178. also optional (i.e. can be empty)
  1179. prepended by '_$$_' if not empty }
  1180. result:='';
  1181. if typeprefix<>'' then
  1182. result:=result+typeprefix+'_$';
  1183. { Add P$ for program, which can have the same name as
  1184. a unit }
  1185. if (TSymtable(main_module.localsymtable)=st) and
  1186. (not main_module.is_unit) then
  1187. result:=result+'P$'+st.name^
  1188. else
  1189. result:=result+st.name^;
  1190. if prefix<>'' then
  1191. result:=result+'$_$'+prefix;
  1192. if suffix<>'' then
  1193. result:=result+'_$$_'+suffix;
  1194. { the Darwin assembler assumes that all symbols starting with 'L' are local }
  1195. { Further, the Mac OS X 10.5 linker does not consider symbols which do not }
  1196. { start with '_' as regular symbols (it does not generate N_GSYM entries }
  1197. { those in the debug map, leading to troubles with dsymutil). So always }
  1198. { add an underscore on darwin. }
  1199. if (target_info.system in systems_darwin) then
  1200. result := '_' + result;
  1201. end;
  1202. function make_dllmangledname(const dllname,importname:TSymStr;import_nr : word; pco : tproccalloption):TSymStr;
  1203. var
  1204. crc : cardinal;
  1205. i : longint;
  1206. use_crc : boolean;
  1207. dllprefix : TSymStr;
  1208. begin
  1209. if (target_info.system in (systems_all_windows + systems_nativent +
  1210. [system_i386_emx, system_i386_os2]))
  1211. and (dllname <> '') then
  1212. begin
  1213. dllprefix:=lower(ExtractFileName(dllname));
  1214. { Remove .dll suffix if present }
  1215. if copy(dllprefix,length(dllprefix)-3,length(dllprefix))='.dll' then
  1216. dllprefix:=copy(dllprefix,1,length(dllprefix)-4);
  1217. use_crc:=false;
  1218. for i:=1 to length(dllprefix) do
  1219. if not (dllprefix[i] in ['a'..'z','A'..'Z','_','0'..'9']) then
  1220. begin
  1221. use_crc:=true;
  1222. break;
  1223. end;
  1224. if use_crc then
  1225. begin
  1226. crc:=0;
  1227. crc:=UpdateCrc32(crc,dllprefix[1],length(dllprefix));
  1228. dllprefix:='_$dll$crc$'+hexstr(crc,8)+'$';
  1229. end
  1230. else
  1231. dllprefix:='_$dll$'+dllprefix+'$';
  1232. if importname<>'' then
  1233. result:=dllprefix+importname
  1234. else
  1235. result:=dllprefix+'_index_'+tostr(import_nr);
  1236. { Replace ? and @ in import name, since GNU AS does not allow these characters in symbol names. }
  1237. { This allows to import VC++ mangled names from DLLs. }
  1238. { Do not perform replacement, if external symbol is not imported from DLL. }
  1239. if (dllname<>'') then
  1240. begin
  1241. Replace(result,'?','__q$$');
  1242. {$ifdef arm}
  1243. { @ symbol is not allowed in ARM assembler only }
  1244. Replace(result,'@','__a$$');
  1245. {$endif arm}
  1246. end;
  1247. end
  1248. else
  1249. begin
  1250. if importname<>'' then
  1251. begin
  1252. if not(pco in [pocall_cdecl,pocall_cppdecl]) then
  1253. result:=importname
  1254. else
  1255. result:=target_info.Cprefix+importname;
  1256. end
  1257. else
  1258. result:='_index_'+tostr(import_nr);
  1259. end;
  1260. end;
  1261. {****************************************************************************
  1262. TDEFAWARESYMTABLESTACK
  1263. (symtablestack descendant that does some special actions on
  1264. the pushed/popped symtables)
  1265. ****************************************************************************}
  1266. procedure tdefawaresymtablestack.add_helpers_and_generics(st:tsymtable;addgenerics:boolean);
  1267. var
  1268. i: integer;
  1269. s: string;
  1270. list: TFPObjectList;
  1271. def: tdef;
  1272. sym,srsym : tsym;
  1273. srsymtable : tsymtable;
  1274. entry : tgenericdummyentry;
  1275. begin
  1276. { search the symtable from first to last; the helper to use will be the
  1277. last one in the list }
  1278. for i:=0 to st.symlist.count-1 do
  1279. begin
  1280. if not (st.symlist[i] is ttypesym) then
  1281. continue;
  1282. def:=ttypesym(st.SymList[i]).typedef;
  1283. sym:=tsym(st.symlist[i]);
  1284. if is_objectpascal_helper(def) then
  1285. begin
  1286. s:=generate_objectpascal_helper_key(tobjectdef(def).extendeddef);
  1287. Message1(sym_d_adding_helper_for,s);
  1288. list:=TFPObjectList(current_module.extendeddefs.Find(s));
  1289. if not assigned(list) then
  1290. begin
  1291. list:=TFPObjectList.Create(false);
  1292. current_module.extendeddefs.Add(s,list);
  1293. end;
  1294. list.Add(def);
  1295. end
  1296. else
  1297. begin
  1298. if addgenerics and
  1299. (sp_generic_dummy in sym.symoptions)
  1300. then
  1301. begin
  1302. { did we already search for a generic with that name? }
  1303. list:=tfpobjectlist(current_module.genericdummysyms.find(sym.name));
  1304. if not assigned(list) then
  1305. begin
  1306. list:=tfpobjectlist.create(true);
  1307. current_module.genericdummysyms.add(sym.name,list);
  1308. end;
  1309. { is the dummy sym still "dummy"? }
  1310. if (sym.typ=typesym) and
  1311. (
  1312. { dummy sym defined in mode Delphi }
  1313. (ttypesym(sym).typedef.typ=undefineddef) or
  1314. { dummy sym defined in non-Delphi mode }
  1315. (tstoreddef(ttypesym(sym).typedef).is_generic)
  1316. ) then
  1317. begin
  1318. { do we have a non-generic type of the same name
  1319. available? }
  1320. if not searchsym_with_flags(sym.name,srsym,srsymtable,[ssf_no_addsymref]) then
  1321. srsym:=nil;
  1322. end
  1323. else
  1324. { dummy symbol is already not so dummy anymore }
  1325. srsym:=nil;
  1326. if assigned(srsym) then
  1327. begin
  1328. entry:=tgenericdummyentry.create;
  1329. entry.resolvedsym:=srsym;
  1330. entry.dummysym:=sym;
  1331. list.add(entry);
  1332. end;
  1333. end;
  1334. { add nested helpers as well }
  1335. if (def.typ in [recorddef,objectdef]) and
  1336. (sto_has_helper in tabstractrecorddef(def).symtable.tableoptions) then
  1337. add_helpers_and_generics(tabstractrecorddef(def).symtable,false);
  1338. end;
  1339. end;
  1340. end;
  1341. procedure tdefawaresymtablestack.remove_helpers_and_generics(st:tsymtable);
  1342. begin
  1343. if sto_has_helper in st.tableoptions then
  1344. remove_helpers(st);
  1345. if sto_has_generic in st.tableoptions then
  1346. remove_generics(st);
  1347. end;
  1348. procedure tdefawaresymtablestack.remove_helpers(st:TSymtable);
  1349. var
  1350. i, j: integer;
  1351. tmpst: TSymtable;
  1352. list: TFPObjectList;
  1353. begin
  1354. for i:=current_module.extendeddefs.count-1 downto 0 do
  1355. begin
  1356. list:=TFPObjectList(current_module.extendeddefs[i]);
  1357. for j:=list.count-1 downto 0 do
  1358. begin
  1359. if not (list[j] is tobjectdef) then
  1360. Internalerror(2011031501);
  1361. tmpst:=tobjectdef(list[j]).owner;
  1362. repeat
  1363. if tmpst=st then
  1364. begin
  1365. list.delete(j);
  1366. break;
  1367. end
  1368. else
  1369. begin
  1370. if assigned(tmpst.defowner) then
  1371. tmpst:=tmpst.defowner.owner
  1372. else
  1373. tmpst:=nil;
  1374. end;
  1375. until not assigned(tmpst) or (tmpst.symtabletype in [globalsymtable,staticsymtable]);
  1376. end;
  1377. if list.count=0 then
  1378. current_module.extendeddefs.delete(i);
  1379. end;
  1380. end;
  1381. procedure tdefawaresymtablestack.remove_generics(st:tsymtable);
  1382. var
  1383. i,j : longint;
  1384. entry : tgenericdummyentry;
  1385. list : tfpobjectlist;
  1386. begin
  1387. for i:=current_module.genericdummysyms.count-1 downto 0 do
  1388. begin
  1389. list:=tfpobjectlist(current_module.genericdummysyms[i]);
  1390. if not assigned(list) then
  1391. continue;
  1392. for j:=list.count-1 downto 0 do
  1393. begin
  1394. entry:=tgenericdummyentry(list[j]);
  1395. if entry.dummysym.owner=st then
  1396. list.delete(j);
  1397. end;
  1398. if list.count=0 then
  1399. current_module.genericdummysyms.delete(i);
  1400. end;
  1401. end;
  1402. procedure tdefawaresymtablestack.pushcommon(st:tsymtable);
  1403. begin
  1404. if (sto_has_generic in st.tableoptions) or
  1405. (
  1406. (st.symtabletype in [globalsymtable,staticsymtable]) and
  1407. (sto_has_helper in st.tableoptions)
  1408. ) then
  1409. { nested helpers will be added as well }
  1410. add_helpers_and_generics(st,true);
  1411. end;
  1412. procedure tdefawaresymtablestack.push(st: TSymtable);
  1413. begin
  1414. pushcommon(st);
  1415. inherited push(st);
  1416. end;
  1417. procedure tdefawaresymtablestack.pushafter(st,afterst:TSymtable);
  1418. begin
  1419. pushcommon(st);
  1420. inherited pushafter(st,afterst);
  1421. end;
  1422. procedure tdefawaresymtablestack.pop(st: TSymtable);
  1423. begin
  1424. inherited pop(st);
  1425. if (sto_has_generic in st.tableoptions) or
  1426. (
  1427. (st.symtabletype in [globalsymtable,staticsymtable]) and
  1428. (sto_has_helper in st.tableoptions)
  1429. ) then
  1430. { nested helpers will be removed as well }
  1431. remove_helpers_and_generics(st);
  1432. end;
  1433. {****************************************************************************
  1434. TDEF (base class for definitions)
  1435. ****************************************************************************}
  1436. constructor tgenericconstraintdata.create;
  1437. begin
  1438. interfaces:=tfpobjectlist.create(false);
  1439. interfacesderef:=tfplist.create;
  1440. end;
  1441. destructor tgenericconstraintdata.destroy;
  1442. var
  1443. i : longint;
  1444. begin
  1445. for i:=0 to interfacesderef.count-1 do
  1446. dispose(pderef(interfacesderef[i]));
  1447. interfacesderef.free;
  1448. interfaces.free;
  1449. inherited destroy;
  1450. end;
  1451. procedure tgenericconstraintdata.ppuload(ppufile: tcompilerppufile);
  1452. var
  1453. cnt,i : longint;
  1454. intfderef : pderef;
  1455. begin
  1456. ppufile.getsmallset(flags);
  1457. cnt:=ppufile.getlongint;
  1458. for i:=0 to cnt-1 do
  1459. begin
  1460. new(intfderef);
  1461. ppufile.getderef(intfderef^);
  1462. interfacesderef.add(intfderef);
  1463. end;
  1464. end;
  1465. procedure tgenericconstraintdata.ppuwrite(ppufile: tcompilerppufile);
  1466. var
  1467. i : longint;
  1468. begin
  1469. ppufile.putsmallset(flags);
  1470. ppufile.putlongint(interfacesderef.count);
  1471. for i:=0 to interfacesderef.count-1 do
  1472. ppufile.putderef(pderef(interfacesderef[i])^);
  1473. end;
  1474. procedure tgenericconstraintdata.buildderef;
  1475. var
  1476. intfderef : pderef;
  1477. i : longint;
  1478. begin
  1479. for i:=0 to interfaces.count-1 do
  1480. begin
  1481. new(intfderef);
  1482. intfderef^.build(tobjectdef(interfaces[i]));
  1483. interfacesderef.add(intfderef);
  1484. end;
  1485. end;
  1486. procedure tgenericconstraintdata.deref;
  1487. var
  1488. i : longint;
  1489. begin
  1490. for i:=0 to interfacesderef.count-1 do
  1491. interfaces.add(pderef(interfacesderef[i])^.resolve);
  1492. end;
  1493. procedure tstoreddef.writeentry(ppufile: tcompilerppufile; ibnr: byte);
  1494. begin
  1495. ppuwrite_platform(ppufile);
  1496. ppufile.writeentry(ibnr);
  1497. end;
  1498. procedure tstoreddef.fillgenericparas(symtable: tsymtable);
  1499. var
  1500. sym : tsym;
  1501. i : longint;
  1502. begin
  1503. if not assigned(symtable) then
  1504. internalerror(2012091201);
  1505. if [df_generic,df_specialization]*defoptions=[] then
  1506. exit;
  1507. for i:=0 to symtable.symlist.count-1 do
  1508. begin
  1509. sym:=tsym(symtable.symlist[i]);
  1510. if sp_generic_para in sym.symoptions then
  1511. begin
  1512. if not assigned(genericparas) then
  1513. genericparas:=tfphashobjectlist.create(false);
  1514. genericparas.Add(sym.name,sym);
  1515. end;
  1516. end;
  1517. end;
  1518. procedure tstoreddef.ppuwrite_platform(ppufile: tcompilerppufile);
  1519. begin
  1520. { by default: do nothing }
  1521. end;
  1522. procedure tstoreddef.ppuload_platform(ppufile: tcompilerppufile);
  1523. begin
  1524. { by default: do nothing }
  1525. end;
  1526. constructor tstoreddef.create(dt:tdeftyp);
  1527. var
  1528. insertstack : psymtablestackitem;
  1529. begin
  1530. inherited create(dt);
  1531. savesize := 0;
  1532. {$ifdef EXTDEBUG}
  1533. fileinfo := current_filepos;
  1534. {$endif}
  1535. generictokenbuf:=nil;
  1536. genericdef:=nil;
  1537. { Don't register forwarddefs, they are disposed at the
  1538. end of an type block }
  1539. if (dt=forwarddef) then
  1540. exit;
  1541. { Register in current_module }
  1542. if assigned(current_module) then
  1543. begin
  1544. current_module.deflist.Add(self);
  1545. DefId:=current_module.deflist.Count-1;
  1546. end;
  1547. { Register in symtable stack }
  1548. if assigned(symtablestack) then
  1549. begin
  1550. insertstack:=symtablestack.stack;
  1551. while assigned(insertstack) and
  1552. (insertstack^.symtable.symtabletype=withsymtable) do
  1553. insertstack:=insertstack^.next;
  1554. if not assigned(insertstack) then
  1555. internalerror(200602044);
  1556. insertstack^.symtable.insertdef(self);
  1557. end;
  1558. end;
  1559. destructor tstoreddef.destroy;
  1560. begin
  1561. { Direct calls are not allowed, use symtable.deletedef() }
  1562. if assigned(owner) then
  1563. internalerror(200612311);
  1564. if assigned(generictokenbuf) then
  1565. begin
  1566. generictokenbuf.free;
  1567. generictokenbuf:=nil;
  1568. end;
  1569. genericparas.free;
  1570. genconstraintdata.free;
  1571. stringdispose(_fullownerhierarchyname);
  1572. inherited destroy;
  1573. end;
  1574. constructor tstoreddef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  1575. var
  1576. sizeleft,i : longint;
  1577. buf : array[0..255] of byte;
  1578. begin
  1579. inherited create(dt);
  1580. DefId:=ppufile.getlongint;
  1581. current_module.deflist[DefId]:=self;
  1582. {$ifdef EXTDEBUG}
  1583. fillchar(fileinfo,sizeof(fileinfo),0);
  1584. {$endif}
  1585. { load }
  1586. ppufile.getderef(typesymderef);
  1587. ppufile.getsmallset(defoptions);
  1588. ppufile.getsmallset(defstates);
  1589. if df_genconstraint in defoptions then
  1590. begin
  1591. genconstraintdata:=tgenericconstraintdata.create;
  1592. genconstraintdata.ppuload(ppufile);
  1593. end;
  1594. if df_generic in defoptions then
  1595. begin
  1596. sizeleft:=ppufile.getlongint;
  1597. initgeneric;
  1598. while sizeleft>0 do
  1599. begin
  1600. if sizeleft>sizeof(buf) then
  1601. i:=sizeof(buf)
  1602. else
  1603. i:=sizeleft;
  1604. ppufile.getdata(buf,i);
  1605. generictokenbuf.write(buf,i);
  1606. dec(sizeleft,i);
  1607. end;
  1608. end;
  1609. if df_specialization in defoptions then
  1610. ppufile.getderef(genericdefderef);
  1611. end;
  1612. function tstoreddef.needs_separate_initrtti:boolean;
  1613. begin
  1614. result:=false;
  1615. end;
  1616. function tstoreddef.rtti_mangledname(rt : trttitype) : string;
  1617. var
  1618. prefix : string[4];
  1619. begin
  1620. if (rt=fullrtti) or (not needs_separate_initrtti) then
  1621. begin
  1622. prefix:='RTTI';
  1623. include(defstates,ds_rtti_table_used);
  1624. end
  1625. else
  1626. begin
  1627. prefix:='INIT';
  1628. include(defstates,ds_init_table_used);
  1629. end;
  1630. if assigned(typesym) and
  1631. (owner.symtabletype in [staticsymtable,globalsymtable]) then
  1632. result:=make_mangledname(prefix,owner,typesym.name)
  1633. else
  1634. result:=make_mangledname(prefix,findunitsymtable(owner),'DEF'+tostr(DefId))
  1635. end;
  1636. function tstoreddef.OwnerHierarchyName: string;
  1637. var
  1638. tmp: tdef;
  1639. begin
  1640. tmp:=self;
  1641. result:='';
  1642. repeat
  1643. { can be not assigned in case of a forwarddef }
  1644. if assigned(tmp.owner) and
  1645. (tmp.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  1646. tmp:=tdef(tmp.owner.defowner)
  1647. else
  1648. break;
  1649. result:=tabstractrecorddef(tmp).objrealname^+'.'+result;
  1650. until tmp=nil;
  1651. end;
  1652. function tstoreddef.fullownerhierarchyname: string;
  1653. var
  1654. tmp: tdef;
  1655. begin
  1656. if assigned(_fullownerhierarchyname) then
  1657. begin
  1658. result:=_fullownerhierarchyname^;
  1659. exit;
  1660. end;
  1661. { the def can only reside inside structured types or
  1662. procedures/functions/methods }
  1663. tmp:=self;
  1664. result:='';
  1665. repeat
  1666. { can be not assigned in case of a forwarddef }
  1667. if not assigned(tmp.owner) then
  1668. break
  1669. else
  1670. tmp:=tdef(tmp.owner.defowner);
  1671. if not assigned(tmp) then
  1672. break;
  1673. if tmp.typ in [recorddef,objectdef] then
  1674. result:=tabstractrecorddef(tmp).objrealname^+'.'+result
  1675. else
  1676. if tmp.typ=procdef then
  1677. result:=tprocdef(tmp).customprocname([pno_paranames,pno_proctypeoption])+'.'+result;
  1678. until tmp=nil;
  1679. _fullownerhierarchyname:=stringdup(result);
  1680. end;
  1681. function tstoreddef.in_currentunit: boolean;
  1682. var
  1683. st: tsymtable;
  1684. begin
  1685. st:=owner;
  1686. while not(st.symtabletype in [globalsymtable,staticsymtable]) do
  1687. st:=st.defowner.owner;
  1688. result:=st.iscurrentunit;
  1689. end;
  1690. function tstoreddef.getcopy : tstoreddef;
  1691. begin
  1692. Message(sym_e_cant_create_unique_type);
  1693. getcopy:=cerrordef.create;
  1694. end;
  1695. procedure tstoreddef.ppuwrite(ppufile:tcompilerppufile);
  1696. var
  1697. sizeleft,i : longint;
  1698. buf : array[0..255] of byte;
  1699. oldintfcrc : boolean;
  1700. begin
  1701. ppufile.putlongint(DefId);
  1702. ppufile.putderef(typesymderef);
  1703. ppufile.putsmallset(defoptions);
  1704. oldintfcrc:=ppufile.do_crc;
  1705. ppufile.do_crc:=false;
  1706. ppufile.putsmallset(defstates);
  1707. if df_genconstraint in defoptions then
  1708. genconstraintdata.ppuwrite(ppufile);
  1709. if df_generic in defoptions then
  1710. begin
  1711. if assigned(generictokenbuf) then
  1712. begin
  1713. sizeleft:=generictokenbuf.size;
  1714. generictokenbuf.seek(0);
  1715. end
  1716. else
  1717. sizeleft:=0;
  1718. ppufile.putlongint(sizeleft);
  1719. while sizeleft>0 do
  1720. begin
  1721. if sizeleft>sizeof(buf) then
  1722. i:=sizeof(buf)
  1723. else
  1724. i:=sizeleft;
  1725. generictokenbuf.read(buf,i);
  1726. ppufile.putdata(buf,i);
  1727. dec(sizeleft,i);
  1728. end;
  1729. end;
  1730. ppufile.do_crc:=oldintfcrc;
  1731. if df_specialization in defoptions then
  1732. ppufile.putderef(genericdefderef);
  1733. end;
  1734. procedure tstoreddef.buildderef;
  1735. begin
  1736. typesymderef.build(typesym);
  1737. genericdefderef.build(genericdef);
  1738. if assigned(genconstraintdata) then
  1739. genconstraintdata.buildderef;
  1740. end;
  1741. procedure tstoreddef.buildderefimpl;
  1742. begin
  1743. end;
  1744. procedure tstoreddef.deref;
  1745. begin
  1746. typesym:=ttypesym(typesymderef.resolve);
  1747. if df_specialization in defoptions then
  1748. genericdef:=tstoreddef(genericdefderef.resolve);
  1749. if assigned(genconstraintdata) then
  1750. genconstraintdata.deref;
  1751. end;
  1752. procedure tstoreddef.derefimpl;
  1753. begin
  1754. end;
  1755. function tstoreddef.size : asizeint;
  1756. begin
  1757. size:=savesize;
  1758. end;
  1759. function tstoreddef.getvardef:longint;
  1760. begin
  1761. result:=varUndefined;
  1762. end;
  1763. function tstoreddef.alignment : shortint;
  1764. begin
  1765. { natural alignment by default }
  1766. alignment:=size_2_align(savesize);
  1767. { can happen if savesize = 0, e.g. for voiddef or
  1768. an empty record
  1769. }
  1770. if (alignment=0) then
  1771. alignment:=1;
  1772. end;
  1773. { returns true, if the definition can be published }
  1774. function tstoreddef.is_publishable : boolean;
  1775. begin
  1776. is_publishable:=false;
  1777. end;
  1778. { needs an init table }
  1779. function tstoreddef.needs_inittable : boolean;
  1780. begin
  1781. needs_inittable:=false;
  1782. end;
  1783. function tstoreddef.is_intregable : boolean;
  1784. var
  1785. recsize,temp: longint;
  1786. begin
  1787. is_intregable:=false;
  1788. case typ of
  1789. orddef,
  1790. pointerdef,
  1791. enumdef,
  1792. classrefdef:
  1793. is_intregable:=true;
  1794. procvardef :
  1795. is_intregable:=tprocvardef(self).is_addressonly or (po_methodpointer in tprocvardef(self).procoptions);
  1796. objectdef:
  1797. is_intregable:=(is_implicit_pointer_object_type(self)) and not needs_inittable;
  1798. setdef:
  1799. is_intregable:=is_smallset(self);
  1800. recorddef:
  1801. begin
  1802. recsize:=size;
  1803. is_intregable:=
  1804. ispowerof2(recsize,temp) and
  1805. { sizeof(asizeint)*2 records in int registers is currently broken for endian_big targets }
  1806. (((recsize <= sizeof(asizeint)*2) and (target_info.endian=endian_little)
  1807. { records cannot go into registers on 16 bit targets for now }
  1808. and (sizeof(asizeint)>2)
  1809. and not trecorddef(self).contains_float_field) or
  1810. (recsize <= sizeof(asizeint)))
  1811. and not needs_inittable;
  1812. end;
  1813. end;
  1814. end;
  1815. function tstoreddef.is_fpuregable : boolean;
  1816. begin
  1817. {$ifdef x86}
  1818. result:=use_vectorfpu(self);
  1819. {$else x86}
  1820. result:=(typ=floatdef) and not(cs_fp_emulation in current_settings.moduleswitches);
  1821. {$endif x86}
  1822. end;
  1823. function tstoreddef.is_const_intregable : boolean;
  1824. begin
  1825. case typ of
  1826. stringdef:
  1827. result:=tstringdef(self).stringtype in [st_ansistring,st_unicodestring,st_widestring];
  1828. arraydef:
  1829. result:=is_dynamic_array(self);
  1830. objectdef:
  1831. result:=is_interface(self);
  1832. else
  1833. result:=false;
  1834. end;
  1835. end;
  1836. procedure tstoreddef.initgeneric;
  1837. begin
  1838. if assigned(generictokenbuf) then
  1839. internalerror(200512131);
  1840. generictokenbuf:=tdynamicarray.create(256);
  1841. end;
  1842. function tstoreddef.is_generic: boolean;
  1843. begin
  1844. result:=assigned(genericparas) and
  1845. (genericparas.count>0) and
  1846. (df_generic in defoptions);
  1847. end;
  1848. function tstoreddef.is_specialization: boolean;
  1849. begin
  1850. result:=assigned(genericparas) and
  1851. (genericparas.count>0) and
  1852. (df_specialization in defoptions);
  1853. end;
  1854. {****************************************************************************
  1855. Tstringdef
  1856. ****************************************************************************}
  1857. constructor tstringdef.createshort(l : byte);
  1858. begin
  1859. inherited create(stringdef);
  1860. stringtype:=st_shortstring;
  1861. encoding:=0;
  1862. len:=l;
  1863. end;
  1864. constructor tstringdef.loadshort(ppufile:tcompilerppufile);
  1865. begin
  1866. inherited ppuload(stringdef,ppufile);
  1867. stringtype:=st_shortstring;
  1868. encoding:=0;
  1869. len:=ppufile.getbyte;
  1870. ppuload_platform(ppufile);
  1871. end;
  1872. constructor tstringdef.createlong(l : asizeint);
  1873. begin
  1874. inherited create(stringdef);
  1875. stringtype:=st_longstring;
  1876. encoding:=0;
  1877. len:=l;
  1878. end;
  1879. constructor tstringdef.loadlong(ppufile:tcompilerppufile);
  1880. begin
  1881. inherited ppuload(stringdef,ppufile);
  1882. stringtype:=st_longstring;
  1883. encoding:=0;
  1884. len:=ppufile.getasizeint;
  1885. ppuload_platform(ppufile);
  1886. end;
  1887. constructor tstringdef.createansi(aencoding:tstringencoding);
  1888. begin
  1889. inherited create(stringdef);
  1890. stringtype:=st_ansistring;
  1891. encoding:=aencoding;
  1892. len:=-1;
  1893. end;
  1894. constructor tstringdef.loadansi(ppufile:tcompilerppufile);
  1895. begin
  1896. inherited ppuload(stringdef,ppufile);
  1897. stringtype:=st_ansistring;
  1898. len:=ppufile.getaint;
  1899. encoding:=ppufile.getword;
  1900. ppuload_platform(ppufile);
  1901. end;
  1902. constructor tstringdef.createwide;
  1903. begin
  1904. inherited create(stringdef);
  1905. stringtype:=st_widestring;
  1906. if target_info.endian=endian_little then
  1907. encoding:=CP_UTF16LE
  1908. else
  1909. encoding:=CP_UTF16BE;
  1910. len:=-1;
  1911. end;
  1912. constructor tstringdef.loadwide(ppufile:tcompilerppufile);
  1913. begin
  1914. inherited ppuload(stringdef,ppufile);
  1915. stringtype:=st_widestring;
  1916. if target_info.endian=endian_little then
  1917. encoding:=CP_UTF16LE
  1918. else
  1919. encoding:=CP_UTF16BE;
  1920. len:=ppufile.getaint;
  1921. ppuload_platform(ppufile);
  1922. end;
  1923. constructor tstringdef.createunicode;
  1924. begin
  1925. inherited create(stringdef);
  1926. stringtype:=st_unicodestring;
  1927. if target_info.endian=endian_little then
  1928. encoding:=CP_UTF16LE
  1929. else
  1930. encoding:=CP_UTF16BE;
  1931. len:=-1;
  1932. end;
  1933. constructor tstringdef.loadunicode(ppufile:tcompilerppufile);
  1934. begin
  1935. inherited ppuload(stringdef,ppufile);
  1936. stringtype:=st_unicodestring;
  1937. len:=ppufile.getaint;
  1938. encoding:=ppufile.getword;
  1939. ppuload_platform(ppufile);
  1940. end;
  1941. function tstringdef.getcopy : tstoreddef;
  1942. begin
  1943. result:=cstringdef.create(typ);
  1944. result.typ:=stringdef;
  1945. tstringdef(result).stringtype:=stringtype;
  1946. tstringdef(result).encoding:=encoding;
  1947. tstringdef(result).len:=len;
  1948. end;
  1949. function tstringdef.stringtypname:string;
  1950. const
  1951. typname:array[tstringtype] of string[10]=(
  1952. 'shortstr','longstr','ansistr','widestr','unicodestr'
  1953. );
  1954. begin
  1955. stringtypname:=typname[stringtype];
  1956. end;
  1957. procedure tstringdef.ppuwrite(ppufile:tcompilerppufile);
  1958. begin
  1959. inherited ppuwrite(ppufile);
  1960. if stringtype=st_shortstring then
  1961. begin
  1962. {$ifdef extdebug}
  1963. if len > 255 then internalerror(12122002);
  1964. {$endif}
  1965. ppufile.putbyte(byte(len))
  1966. end
  1967. else
  1968. ppufile.putaint(len);
  1969. if stringtype in [st_ansistring,st_unicodestring] then
  1970. ppufile.putword(encoding);
  1971. case stringtype of
  1972. st_shortstring : writeentry(ppufile,ibshortstringdef);
  1973. st_longstring : writeentry(ppufile,iblongstringdef);
  1974. st_ansistring : writeentry(ppufile,ibansistringdef);
  1975. st_widestring : writeentry(ppufile,ibwidestringdef);
  1976. st_unicodestring : writeentry(ppufile,ibunicodestringdef);
  1977. end;
  1978. end;
  1979. function tstringdef.needs_inittable : boolean;
  1980. begin
  1981. needs_inittable:=stringtype in [st_ansistring,st_widestring,st_unicodestring];
  1982. end;
  1983. function tstringdef.GetTypeName : string;
  1984. const
  1985. names : array[tstringtype] of string[15] = (
  1986. 'ShortString','LongString','AnsiString','WideString','UnicodeString');
  1987. begin
  1988. GetTypeName:=names[stringtype];
  1989. end;
  1990. function tstringdef.getvardef : longint;
  1991. const
  1992. vardef : array[tstringtype] of longint = (
  1993. varUndefined,varUndefined,varString,varOleStr,varUString);
  1994. begin
  1995. result:=vardef[stringtype];
  1996. end;
  1997. function tstringdef.alignment : shortint;
  1998. begin
  1999. case stringtype of
  2000. st_unicodestring,
  2001. st_widestring,
  2002. st_ansistring:
  2003. alignment:=size_2_align(size);
  2004. st_longstring,
  2005. st_shortstring:
  2006. { char to string accesses byte 0 and 1 with one word access }
  2007. if (tf_requires_proper_alignment in target_info.flags) or
  2008. { macpas needs an alignment of 2 (MetroWerks compatible) }
  2009. (m_mac in current_settings.modeswitches) then
  2010. alignment:=size_2_align(2)
  2011. else
  2012. alignment:=size_2_align(1);
  2013. else
  2014. internalerror(200412301);
  2015. end;
  2016. end;
  2017. function tstringdef.getmangledparaname : TSymStr;
  2018. begin
  2019. getmangledparaname:='STRING';
  2020. end;
  2021. function tstringdef.is_publishable : boolean;
  2022. begin
  2023. is_publishable:=true;
  2024. end;
  2025. function tstringdef.size: asizeint;
  2026. begin
  2027. case stringtype of
  2028. st_shortstring:
  2029. Result:=len+1;
  2030. st_longstring,
  2031. st_ansistring,
  2032. st_widestring,
  2033. st_unicodestring:
  2034. Result:=voidpointertype.size;
  2035. else
  2036. internalerror(2014032301);
  2037. end;
  2038. end;
  2039. {****************************************************************************
  2040. TENUMDEF
  2041. ****************************************************************************}
  2042. constructor tenumdef.create;
  2043. begin
  2044. inherited create(enumdef);
  2045. minval:=0;
  2046. maxval:=0;
  2047. calcsavesize;
  2048. has_jumps:=false;
  2049. basedef:=nil;
  2050. symtable:=tenumsymtable.create(self);
  2051. end;
  2052. constructor tenumdef.create_subrange(_basedef:tenumdef;_min,_max:asizeint);
  2053. begin
  2054. inherited create(enumdef);
  2055. minval:=_min;
  2056. maxval:=_max;
  2057. basedef:=_basedef;
  2058. calcsavesize;
  2059. has_jumps:=false;
  2060. symtable:=basedef.symtable.getcopy;
  2061. include(defoptions, df_copied_def);
  2062. end;
  2063. constructor tenumdef.ppuload(ppufile:tcompilerppufile);
  2064. begin
  2065. inherited ppuload(enumdef,ppufile);
  2066. minval:=ppufile.getaint;
  2067. maxval:=ppufile.getaint;
  2068. savesize:=ppufile.getaint;
  2069. has_jumps:=false;
  2070. if df_copied_def in defoptions then
  2071. begin
  2072. symtable:=nil;
  2073. ppufile.getderef(basedefderef);
  2074. ppuload_platform(ppufile);
  2075. end
  2076. else
  2077. begin
  2078. ppuload_platform(ppufile);
  2079. // create with nil defowner first to prevent values changes on insert
  2080. symtable:=tenumsymtable.create(nil);
  2081. tenumsymtable(symtable).ppuload(ppufile);
  2082. symtable.defowner:=self;
  2083. end;
  2084. end;
  2085. destructor tenumdef.destroy;
  2086. begin
  2087. symtable.free;
  2088. symtable:=nil;
  2089. inherited destroy;
  2090. end;
  2091. function tenumdef.getcopy : tstoreddef;
  2092. begin
  2093. if assigned(basedef) then
  2094. result:=cenumdef.create_subrange(basedef,minval,maxval)
  2095. else
  2096. begin
  2097. result:=cenumdef.create;
  2098. tenumdef(result).minval:=minval;
  2099. tenumdef(result).maxval:=maxval;
  2100. tenumdef(result).symtable.free;
  2101. tenumdef(result).symtable:=symtable.getcopy;
  2102. tenumdef(result).basedef:=self;
  2103. end;
  2104. tenumdef(result).has_jumps:=has_jumps;
  2105. tenumdef(result).basedefderef:=basedefderef;
  2106. include(tenumdef(result).defoptions,df_copied_def);
  2107. end;
  2108. procedure tenumdef.calcsavesize;
  2109. begin
  2110. {$IFNDEF cpu64bitaddr} {$push}{$warnings off} {$ENDIF} //comparison always false warning
  2111. if (current_settings.packenum=8) or (min<low(longint)) or (int64(max)>high(cardinal)) then
  2112. savesize:=8
  2113. {$IFDEF not cpu64bitaddr} {$pop} {$ENDIF}
  2114. else
  2115. if (current_settings.packenum=4) or (min<low(smallint)) or (max>high(word)) then
  2116. savesize:=4
  2117. else
  2118. if (current_settings.packenum=2) or (min<low(shortint)) or (max>high(byte)) then
  2119. savesize:=2
  2120. else
  2121. savesize:=1;
  2122. end;
  2123. function tenumdef.packedbitsize: asizeint;
  2124. var
  2125. sizeval: tconstexprint;
  2126. power: longint;
  2127. begin
  2128. result := 0;
  2129. if (minval >= 0) and
  2130. (maxval <= 1) then
  2131. result := 1
  2132. else
  2133. begin
  2134. if (minval>=0) then
  2135. sizeval:=maxval
  2136. else
  2137. { don't count 0 twice }
  2138. sizeval:=(cutils.max(-minval,maxval)*2)-1;
  2139. { 256 must become 512 etc. }
  2140. nextpowerof2(sizeval+1,power);
  2141. result := power;
  2142. end;
  2143. end;
  2144. procedure tenumdef.setmax(_max:asizeint);
  2145. begin
  2146. maxval:=_max;
  2147. calcsavesize;
  2148. end;
  2149. procedure tenumdef.setmin(_min:asizeint);
  2150. begin
  2151. minval:=_min;
  2152. calcsavesize;
  2153. end;
  2154. function tenumdef.min:asizeint;
  2155. begin
  2156. min:=minval;
  2157. end;
  2158. function tenumdef.max:asizeint;
  2159. begin
  2160. max:=maxval;
  2161. end;
  2162. function tenumdef.getfirstsym: tsym;
  2163. var
  2164. i:integer;
  2165. begin
  2166. for i := 0 to symtable.SymList.Count - 1 do
  2167. begin
  2168. result:=tsym(symtable.SymList[i]);
  2169. if tenumsym(result).value=minval then
  2170. exit;
  2171. end;
  2172. result:=nil;
  2173. end;
  2174. function tenumdef.int2enumsym(l: asizeint): tsym;
  2175. var
  2176. i: longint;
  2177. sym: tsym;
  2178. bdef: tenumdef;
  2179. begin
  2180. result:=nil;
  2181. if (l<minval) or
  2182. (l>maxval) then
  2183. exit;
  2184. bdef:=getbasedef;
  2185. for i:=0 to bdef.symtable.symlist.count-1 do
  2186. begin
  2187. sym:=tsym(bdef.symtable.symlist[i]);
  2188. if (sym.typ=enumsym) and
  2189. (tenumsym(sym).value=l) then
  2190. begin
  2191. result:=sym;
  2192. exit;
  2193. end;
  2194. end;
  2195. end;
  2196. function tenumdef.getbasedef: tenumdef;
  2197. begin
  2198. if not assigned(basedef) then
  2199. result:=self
  2200. else
  2201. result:=basedef;
  2202. end;
  2203. procedure tenumdef.buildderef;
  2204. begin
  2205. inherited buildderef;
  2206. if df_copied_def in defoptions then
  2207. basedefderef.build(basedef)
  2208. else
  2209. tenumsymtable(symtable).buildderef;
  2210. end;
  2211. procedure tenumdef.deref;
  2212. begin
  2213. inherited deref;
  2214. if df_copied_def in defoptions then
  2215. begin
  2216. basedef:=tenumdef(basedefderef.resolve);
  2217. symtable:=basedef.symtable.getcopy;
  2218. end
  2219. else
  2220. tenumsymtable(symtable).deref;
  2221. end;
  2222. procedure tenumdef.ppuwrite(ppufile:tcompilerppufile);
  2223. begin
  2224. inherited ppuwrite(ppufile);
  2225. ppufile.putaint(min);
  2226. ppufile.putaint(max);
  2227. ppufile.putaint(savesize);
  2228. if df_copied_def in defoptions then
  2229. ppufile.putderef(basedefderef);
  2230. writeentry(ppufile,ibenumdef);
  2231. if not (df_copied_def in defoptions) then
  2232. tenumsymtable(symtable).ppuwrite(ppufile);
  2233. end;
  2234. function tenumdef.is_publishable : boolean;
  2235. begin
  2236. is_publishable:=true;
  2237. end;
  2238. function tenumdef.GetTypeName : string;
  2239. begin
  2240. GetTypeName:='<enumeration type>';
  2241. end;
  2242. {****************************************************************************
  2243. TORDDEF
  2244. ****************************************************************************}
  2245. constructor torddef.create(t : tordtype;v,b : TConstExprInt);
  2246. begin
  2247. inherited create(orddef);
  2248. low:=v;
  2249. high:=b;
  2250. ordtype:=t;
  2251. setsize;
  2252. end;
  2253. constructor torddef.ppuload(ppufile:tcompilerppufile);
  2254. begin
  2255. inherited ppuload(orddef,ppufile);
  2256. ordtype:=tordtype(ppufile.getbyte);
  2257. low:=ppufile.getexprint;
  2258. high:=ppufile.getexprint;
  2259. setsize;
  2260. ppuload_platform(ppufile);
  2261. end;
  2262. function torddef.getcopy : tstoreddef;
  2263. begin
  2264. result:=corddef.create(ordtype,low,high);
  2265. result.typ:=orddef;
  2266. torddef(result).low:=low;
  2267. torddef(result).high:=high;
  2268. torddef(result).ordtype:=ordtype;
  2269. torddef(result).savesize:=savesize;
  2270. end;
  2271. function torddef.alignment:shortint;
  2272. begin
  2273. if (target_info.system in [system_i386_darwin,system_i386_iphonesim,system_arm_darwin]) and
  2274. (ordtype in [s64bit,u64bit]) then
  2275. result := 4
  2276. else
  2277. result := inherited alignment;
  2278. end;
  2279. procedure torddef.setsize;
  2280. const
  2281. sizetbl : array[tordtype] of longint = (
  2282. 0,
  2283. 1,2,4,8,
  2284. 1,2,4,8,
  2285. 1,2,4,8,
  2286. 1,2,4,8,
  2287. 1,2,8
  2288. );
  2289. begin
  2290. savesize:=sizetbl[ordtype];
  2291. end;
  2292. function torddef.packedbitsize: asizeint;
  2293. var
  2294. sizeval: tconstexprint;
  2295. power: longint;
  2296. begin
  2297. result := 0;
  2298. if ordtype = uvoid then
  2299. exit;
  2300. {$ifndef cpu64bitalu}
  2301. if (ordtype in [s64bit,u64bit]) then
  2302. {$else not cpu64bitalu}
  2303. if (ordtype = u64bit) or
  2304. ((ordtype = s64bit) and
  2305. ((low <= (system.low(int64) div 2)) or
  2306. (high > (system.high(int64) div 2)))) then
  2307. {$endif cpu64bitalu}
  2308. result := 64
  2309. else if (low >= 0) and
  2310. (high <= 1) then
  2311. result := 1
  2312. else
  2313. begin
  2314. if (low>=0) then
  2315. sizeval:=high
  2316. else
  2317. { don't count 0 twice }
  2318. sizeval:=(cutils.max(-low,high)*2)-1;
  2319. { 256 must become 512 etc. }
  2320. nextpowerof2(sizeval+1,power);
  2321. result := power;
  2322. end;
  2323. end;
  2324. function torddef.getvardef : longint;
  2325. const
  2326. basetype2vardef : array[tordtype] of longint = (
  2327. varUndefined,
  2328. varbyte,varword,varlongword,varqword,
  2329. varshortint,varsmallint,varinteger,varint64,
  2330. varboolean,varboolean,varboolean,varboolean,
  2331. varboolean,varboolean,varUndefined,varUndefined,
  2332. varUndefined,varUndefined,varCurrency);
  2333. begin
  2334. result:=basetype2vardef[ordtype];
  2335. end;
  2336. procedure torddef.ppuwrite(ppufile:tcompilerppufile);
  2337. begin
  2338. inherited ppuwrite(ppufile);
  2339. ppufile.putbyte(byte(ordtype));
  2340. ppufile.putexprint(low);
  2341. ppufile.putexprint(high);
  2342. writeentry(ppufile,iborddef);
  2343. end;
  2344. function torddef.is_publishable : boolean;
  2345. begin
  2346. is_publishable:=(ordtype<>uvoid);
  2347. end;
  2348. function torddef.GetTypeName : string;
  2349. const
  2350. names : array[tordtype] of string[20] = (
  2351. 'untyped',
  2352. 'Byte','Word','DWord','QWord',
  2353. 'ShortInt','SmallInt','LongInt','Int64',
  2354. 'Boolean','Boolean16','Boolean32','Boolean64',
  2355. 'ByteBool','WordBool','LongBool','QWordBool',
  2356. 'Char','WideChar','Currency');
  2357. begin
  2358. GetTypeName:=names[ordtype];
  2359. end;
  2360. {****************************************************************************
  2361. TFLOATDEF
  2362. ****************************************************************************}
  2363. constructor tfloatdef.create(t : tfloattype);
  2364. begin
  2365. inherited create(floatdef);
  2366. floattype:=t;
  2367. setsize;
  2368. end;
  2369. constructor tfloatdef.ppuload(ppufile:tcompilerppufile);
  2370. begin
  2371. inherited ppuload(floatdef,ppufile);
  2372. floattype:=tfloattype(ppufile.getbyte);
  2373. setsize;
  2374. ppuload_platform(ppufile);
  2375. end;
  2376. function tfloatdef.getcopy : tstoreddef;
  2377. begin
  2378. result:=cfloatdef.create(floattype);
  2379. result.typ:=floatdef;
  2380. tfloatdef(result).savesize:=savesize;
  2381. end;
  2382. function tfloatdef.alignment:shortint;
  2383. begin
  2384. if (target_info.system in [system_i386_darwin,system_i386_iphonesim,system_arm_darwin]) then
  2385. case floattype of
  2386. sc80real,
  2387. s80real: result:=16;
  2388. s64real,
  2389. s64currency,
  2390. s64comp : result:=4;
  2391. else
  2392. result := inherited alignment;
  2393. end
  2394. else
  2395. result := inherited alignment;
  2396. end;
  2397. function tfloatdef.structalignment: shortint;
  2398. begin
  2399. { aix is really annoying: the recommended scalar alignment for both
  2400. int64 and double is 64 bits, but in structs int64 has to be aligned
  2401. to 8 bytes and double to 4 bytes }
  2402. if (target_info.system in systems_aix) and
  2403. (floattype=s64real) then
  2404. result:=4
  2405. else
  2406. result:=alignment;
  2407. end;
  2408. procedure tfloatdef.setsize;
  2409. begin
  2410. case floattype of
  2411. s32real : savesize:=4;
  2412. s80real : savesize:=10;
  2413. sc80real:
  2414. if target_info.system in [system_i386_darwin,system_i386_iphonesim,system_x86_64_darwin,
  2415. system_x86_64_linux,system_x86_64_freebsd,
  2416. system_x86_64_openbsd,system_x86_64_netbsd,
  2417. system_x86_64_solaris,system_x86_64_embedded] then
  2418. savesize:=16
  2419. else
  2420. savesize:=12;
  2421. s64real,
  2422. s64currency,
  2423. s64comp : savesize:=8;
  2424. else
  2425. savesize:=0;
  2426. end;
  2427. end;
  2428. function tfloatdef.getvardef : longint;
  2429. const
  2430. floattype2vardef : array[tfloattype] of longint = (
  2431. varSingle,varDouble,varUndefined,varUndefined,
  2432. varUndefined,varCurrency,varUndefined);
  2433. begin
  2434. if (upper(typename)='TDATETIME') and
  2435. assigned(owner) and
  2436. assigned(owner.name) and
  2437. (owner.name^='SYSTEM') then
  2438. result:=varDate
  2439. else
  2440. result:=floattype2vardef[floattype];
  2441. end;
  2442. procedure tfloatdef.ppuwrite(ppufile:tcompilerppufile);
  2443. begin
  2444. inherited ppuwrite(ppufile);
  2445. ppufile.putbyte(byte(floattype));
  2446. writeentry(ppufile,ibfloatdef);
  2447. end;
  2448. function tfloatdef.is_publishable : boolean;
  2449. begin
  2450. is_publishable:=true;
  2451. end;
  2452. function tfloatdef.GetTypeName : string;
  2453. const
  2454. names : array[tfloattype] of string[20] = (
  2455. 'Single','Double','Extended','CExtended','Comp','Currency','Float128');
  2456. begin
  2457. GetTypeName:=names[floattype];
  2458. end;
  2459. {****************************************************************************
  2460. TFILEDEF
  2461. ****************************************************************************}
  2462. constructor tfiledef.createtext;
  2463. begin
  2464. inherited create(filedef);
  2465. filetyp:=ft_text;
  2466. typedfiledef:=nil;
  2467. end;
  2468. constructor tfiledef.createuntyped;
  2469. begin
  2470. inherited create(filedef);
  2471. filetyp:=ft_untyped;
  2472. typedfiledef:=nil;
  2473. end;
  2474. constructor tfiledef.createtyped(def:tdef);
  2475. begin
  2476. inherited create(filedef);
  2477. filetyp:=ft_typed;
  2478. typedfiledef:=def;
  2479. end;
  2480. constructor tfiledef.ppuload(ppufile:tcompilerppufile);
  2481. begin
  2482. inherited ppuload(filedef,ppufile);
  2483. filetyp:=tfiletyp(ppufile.getbyte);
  2484. if filetyp=ft_typed then
  2485. ppufile.getderef(typedfiledefderef)
  2486. else
  2487. typedfiledef:=nil;
  2488. ppuload_platform(ppufile);
  2489. end;
  2490. function tfiledef.getcopy : tstoreddef;
  2491. begin
  2492. case filetyp of
  2493. ft_typed:
  2494. result:=cfiledef.createtyped(typedfiledef);
  2495. ft_untyped:
  2496. result:=cfiledef.createuntyped;
  2497. ft_text:
  2498. result:=cfiledef.createtext;
  2499. else
  2500. internalerror(2004121201);
  2501. end;
  2502. end;
  2503. procedure tfiledef.buildderef;
  2504. begin
  2505. inherited buildderef;
  2506. if filetyp=ft_typed then
  2507. typedfiledefderef.build(typedfiledef);
  2508. end;
  2509. procedure tfiledef.deref;
  2510. begin
  2511. inherited deref;
  2512. if filetyp=ft_typed then
  2513. typedfiledef:=tdef(typedfiledefderef.resolve);
  2514. end;
  2515. function tfiledef.size:asizeint;
  2516. begin
  2517. if savesize=0 then
  2518. setsize;
  2519. size:=savesize;
  2520. end;
  2521. procedure tfiledef.setsize;
  2522. begin
  2523. case filetyp of
  2524. ft_text:
  2525. savesize:=search_system_type('TEXTREC').typedef.size;
  2526. ft_typed:
  2527. begin
  2528. savesize:=search_system_type('FILEREC').typedef.size;
  2529. { allocate put/get buffer in iso mode }
  2530. if m_iso in current_settings.modeswitches then
  2531. inc(savesize,typedfiledef.size);
  2532. end;
  2533. ft_untyped:
  2534. savesize:=search_system_type('FILEREC').typedef.size;
  2535. else
  2536. internalerror(2013113001);
  2537. end;
  2538. end;
  2539. procedure tfiledef.ppuwrite(ppufile:tcompilerppufile);
  2540. begin
  2541. inherited ppuwrite(ppufile);
  2542. ppufile.putbyte(byte(filetyp));
  2543. if filetyp=ft_typed then
  2544. ppufile.putderef(typedfiledefderef);
  2545. writeentry(ppufile,ibfiledef);
  2546. end;
  2547. function tfiledef.GetTypeName : string;
  2548. begin
  2549. case filetyp of
  2550. ft_untyped:
  2551. GetTypeName:='File';
  2552. ft_typed:
  2553. GetTypeName:='File Of '+typedfiledef.typename;
  2554. ft_text:
  2555. GetTypeName:='Text'
  2556. else
  2557. internalerror(2013113002);
  2558. end;
  2559. end;
  2560. function tfiledef.getmangledparaname : TSymStr;
  2561. begin
  2562. case filetyp of
  2563. ft_untyped:
  2564. getmangledparaname:='FILE';
  2565. ft_typed:
  2566. getmangledparaname:='FILE$OF$'+typedfiledef.mangledparaname;
  2567. ft_text:
  2568. getmangledparaname:='TEXT'
  2569. else
  2570. internalerror(2013113003);
  2571. end;
  2572. end;
  2573. {****************************************************************************
  2574. TVARIANTDEF
  2575. ****************************************************************************}
  2576. constructor tvariantdef.create(v : tvarianttype);
  2577. begin
  2578. inherited create(variantdef);
  2579. varianttype:=v;
  2580. setsize;
  2581. end;
  2582. constructor tvariantdef.ppuload(ppufile:tcompilerppufile);
  2583. begin
  2584. inherited ppuload(variantdef,ppufile);
  2585. varianttype:=tvarianttype(ppufile.getbyte);
  2586. setsize;
  2587. ppuload_platform(ppufile);
  2588. end;
  2589. function tvariantdef.getcopy : tstoreddef;
  2590. begin
  2591. result:=cvariantdef.create(varianttype);
  2592. end;
  2593. procedure tvariantdef.ppuwrite(ppufile:tcompilerppufile);
  2594. begin
  2595. inherited ppuwrite(ppufile);
  2596. ppufile.putbyte(byte(varianttype));
  2597. writeentry(ppufile,ibvariantdef);
  2598. end;
  2599. function tvariantdef.getvardef : longint;
  2600. begin
  2601. Result:=varVariant;
  2602. end;
  2603. procedure tvariantdef.setsize;
  2604. begin
  2605. {$ifdef cpu64bitaddr}
  2606. savesize:=24;
  2607. {$else cpu64bitaddr}
  2608. savesize:=16;
  2609. {$endif cpu64bitaddr}
  2610. end;
  2611. function tvariantdef.GetTypeName : string;
  2612. begin
  2613. case varianttype of
  2614. vt_normalvariant:
  2615. GetTypeName:='Variant';
  2616. vt_olevariant:
  2617. GetTypeName:='OleVariant';
  2618. else
  2619. internalerror(2013113004);
  2620. end;
  2621. end;
  2622. function tvariantdef.needs_inittable : boolean;
  2623. begin
  2624. needs_inittable:=true;
  2625. end;
  2626. function tvariantdef.is_publishable : boolean;
  2627. begin
  2628. is_publishable:=true;
  2629. end;
  2630. {****************************************************************************
  2631. TABSTRACtpointerdef
  2632. ****************************************************************************}
  2633. constructor tabstractpointerdef.create(dt:tdeftyp;def:tdef);
  2634. begin
  2635. inherited create(dt);
  2636. pointeddef:=def;
  2637. end;
  2638. constructor tabstractpointerdef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  2639. begin
  2640. inherited ppuload(dt,ppufile);
  2641. ppufile.getderef(pointeddefderef);
  2642. end;
  2643. procedure tabstractpointerdef.buildderef;
  2644. begin
  2645. inherited buildderef;
  2646. pointeddefderef.build(pointeddef);
  2647. end;
  2648. procedure tabstractpointerdef.deref;
  2649. begin
  2650. inherited deref;
  2651. pointeddef:=tdef(pointeddefderef.resolve);
  2652. end;
  2653. function tabstractpointerdef.size: asizeint;
  2654. begin
  2655. Result:=voidpointertype.size;
  2656. end;
  2657. function tabstractpointerdef.alignment: shortint;
  2658. begin
  2659. alignment:=size_2_align(voidpointertype.size);
  2660. end;
  2661. procedure tabstractpointerdef.ppuwrite(ppufile:tcompilerppufile);
  2662. begin
  2663. inherited ppuwrite(ppufile);
  2664. ppufile.putderef(pointeddefderef);
  2665. end;
  2666. {****************************************************************************
  2667. tpointerdef
  2668. ****************************************************************************}
  2669. constructor tpointerdef.create(def:tdef);
  2670. begin
  2671. inherited create(pointerdef,def);
  2672. has_pointer_math:=cs_pointermath in current_settings.localswitches;
  2673. end;
  2674. function tpointerdef.size: asizeint;
  2675. begin
  2676. result:=sizeof(pint);
  2677. end;
  2678. constructor tpointerdef.ppuload(ppufile:tcompilerppufile);
  2679. begin
  2680. inherited ppuload(pointerdef,ppufile);
  2681. has_pointer_math:=(ppufile.getbyte<>0);
  2682. ppuload_platform(ppufile);
  2683. end;
  2684. function tpointerdef.getcopy : tstoreddef;
  2685. begin
  2686. { don't use direct pointeddef if it is a forwarddef because in other case
  2687. one of them will be destroyed on forward type resolve and the second will
  2688. point to garbage }
  2689. if pointeddef.typ=forwarddef then
  2690. result:=cpointerdef.create(tforwarddef(pointeddef).getcopy)
  2691. else
  2692. result:=cpointerdef.create(pointeddef);
  2693. tpointerdef(result).has_pointer_math:=has_pointer_math;
  2694. tpointerdef(result).savesize:=savesize;
  2695. end;
  2696. procedure tpointerdef.ppuwrite(ppufile:tcompilerppufile);
  2697. begin
  2698. inherited ppuwrite(ppufile);
  2699. ppufile.putbyte(byte(has_pointer_math));
  2700. writeentry(ppufile,ibpointerdef);
  2701. end;
  2702. function tpointerdef.GetTypeName : string;
  2703. begin
  2704. { parameter types and the resultdef of a procvardef can contain a
  2705. pointer to this procvardef itself, resulting in endless recursion ->
  2706. use the typesym's name instead if it exists (if it doesn't, such as
  2707. for anynonymous procedure types in macpas/iso mode, then there cannot
  2708. be any recursive references to it either) }
  2709. if (pointeddef.typ<>procvardef) or
  2710. not assigned(pointeddef.typesym) then
  2711. GetTypeName:='^'+pointeddef.typename
  2712. else
  2713. GetTypeName:='^'+pointeddef.typesym.realname;
  2714. end;
  2715. {****************************************************************************
  2716. TCLASSREFDEF
  2717. ****************************************************************************}
  2718. constructor tclassrefdef.create(def:tdef);
  2719. begin
  2720. inherited create(classrefdef,def);
  2721. end;
  2722. constructor tclassrefdef.ppuload(ppufile:tcompilerppufile);
  2723. begin
  2724. inherited ppuload(classrefdef,ppufile);
  2725. ppuload_platform(ppufile);
  2726. end;
  2727. procedure tclassrefdef.ppuwrite(ppufile:tcompilerppufile);
  2728. begin
  2729. inherited ppuwrite(ppufile);
  2730. writeentry(ppufile,ibclassrefdef);
  2731. end;
  2732. function tclassrefdef.getcopy:tstoreddef;
  2733. begin
  2734. if pointeddef.typ=forwarddef then
  2735. result:=cclassrefdef.create(tforwarddef(pointeddef).getcopy)
  2736. else
  2737. result:=cclassrefdef.create(pointeddef);
  2738. end;
  2739. function tclassrefdef.GetTypeName : string;
  2740. begin
  2741. GetTypeName:='Class Of '+pointeddef.typename;
  2742. end;
  2743. function tclassrefdef.is_publishable : boolean;
  2744. begin
  2745. result:=true;
  2746. end;
  2747. function tclassrefdef.rtti_mangledname(rt: trttitype): string;
  2748. begin
  2749. if (tobjectdef(pointeddef).objecttype<>odt_objcclass) then
  2750. result:=inherited rtti_mangledname(rt)
  2751. else
  2752. result:=tobjectdef(pointeddef).rtti_mangledname(objcmetartti);
  2753. end;
  2754. procedure tclassrefdef.register_created_object_type;
  2755. begin
  2756. tobjectdef(pointeddef).register_created_classref_type;
  2757. end;
  2758. {***************************************************************************
  2759. TSETDEF
  2760. ***************************************************************************}
  2761. constructor tsetdef.create(def:tdef;low, high : asizeint);
  2762. var
  2763. setallocbits: aint;
  2764. packedsavesize: aint;
  2765. actual_setalloc: ShortInt;
  2766. begin
  2767. inherited create(setdef);
  2768. elementdef:=def;
  2769. setmax:=high;
  2770. actual_setalloc:=current_settings.setalloc;
  2771. {$if defined(cpu8bitalu) or defined(cpu16bitalu)}
  2772. if actual_setalloc=0 then
  2773. actual_setalloc:=1;
  2774. {$endif}
  2775. if (actual_setalloc=0) then
  2776. begin
  2777. setbase:=0;
  2778. if (high<32) then
  2779. savesize:=Sizeof(longint)
  2780. else if (high<256) then
  2781. savesize:=32
  2782. else
  2783. savesize:=(high+7) div 8
  2784. end
  2785. else
  2786. begin
  2787. setallocbits:=actual_setalloc*8;
  2788. setbase:=low and not(setallocbits-1);
  2789. packedsavesize:=actual_setalloc*((((high+setallocbits)-setbase)) DIV setallocbits);
  2790. savesize:=packedsavesize;
  2791. {$if not defined(cpu8bitalu) and not defined(cpu16bitalu)}
  2792. if savesize=3 then
  2793. savesize:=4;
  2794. {$endif}
  2795. end;
  2796. end;
  2797. constructor tsetdef.ppuload(ppufile:tcompilerppufile);
  2798. begin
  2799. inherited ppuload(setdef,ppufile);
  2800. ppufile.getderef(elementdefderef);
  2801. savesize:=ppufile.getaint;
  2802. setbase:=ppufile.getaint;
  2803. setmax:=ppufile.getaint;
  2804. ppuload_platform(ppufile);
  2805. end;
  2806. function tsetdef.getcopy : tstoreddef;
  2807. begin
  2808. result:=csetdef.create(elementdef,setbase,setmax);
  2809. { the copy might have been created with a different setalloc setting }
  2810. tsetdef(result).savesize:=savesize;
  2811. end;
  2812. procedure tsetdef.ppuwrite(ppufile:tcompilerppufile);
  2813. begin
  2814. inherited ppuwrite(ppufile);
  2815. ppufile.putderef(elementdefderef);
  2816. ppufile.putaint(savesize);
  2817. ppufile.putaint(setbase);
  2818. ppufile.putaint(setmax);
  2819. writeentry(ppufile,ibsetdef);
  2820. end;
  2821. procedure tsetdef.buildderef;
  2822. begin
  2823. inherited buildderef;
  2824. elementdefderef.build(elementdef);
  2825. end;
  2826. procedure tsetdef.deref;
  2827. begin
  2828. inherited deref;
  2829. elementdef:=tdef(elementdefderef.resolve);
  2830. end;
  2831. function tsetdef.is_publishable : boolean;
  2832. begin
  2833. is_publishable:=savesize in [1,2,4];
  2834. end;
  2835. function tsetdef.GetTypeName : string;
  2836. begin
  2837. if assigned(elementdef) then
  2838. GetTypeName:='Set Of '+elementdef.typename
  2839. else
  2840. GetTypeName:='Empty Set';
  2841. end;
  2842. {***************************************************************************
  2843. TFORMALDEF
  2844. ***************************************************************************}
  2845. constructor tformaldef.create(Atyped:boolean);
  2846. begin
  2847. inherited create(formaldef);
  2848. typed:=Atyped;
  2849. savesize:=0;
  2850. end;
  2851. constructor tformaldef.ppuload(ppufile:tcompilerppufile);
  2852. begin
  2853. inherited ppuload(formaldef,ppufile);
  2854. typed:=boolean(ppufile.getbyte);
  2855. savesize:=0;
  2856. ppuload_platform(ppufile);
  2857. end;
  2858. procedure tformaldef.ppuwrite(ppufile:tcompilerppufile);
  2859. begin
  2860. inherited ppuwrite(ppufile);
  2861. ppufile.putbyte(byte(typed));
  2862. writeentry(ppufile,ibformaldef);
  2863. end;
  2864. function tformaldef.GetTypeName : string;
  2865. begin
  2866. if typed then
  2867. GetTypeName:='<Typed formal type>'
  2868. else
  2869. GetTypeName:='<Formal type>';
  2870. end;
  2871. {***************************************************************************
  2872. TARRAYDEF
  2873. ***************************************************************************}
  2874. constructor tarraydef.create(l,h:asizeint;def:tdef);
  2875. begin
  2876. inherited create(arraydef);
  2877. lowrange:=l;
  2878. highrange:=h;
  2879. rangedef:=def;
  2880. _elementdef:=nil;
  2881. arrayoptions:=[];
  2882. symtable:=tarraysymtable.create(self);
  2883. end;
  2884. destructor tarraydef.destroy;
  2885. begin
  2886. symtable.free;
  2887. symtable:=nil;
  2888. inherited;
  2889. end;
  2890. constructor tarraydef.create_from_pointer(def:tdef);
  2891. begin
  2892. { use -1 so that the elecount will not overflow }
  2893. self.create(0,high(asizeint)-1,ptrsinttype);
  2894. arrayoptions:=[ado_IsConvertedPointer];
  2895. setelementdef(def);
  2896. end;
  2897. constructor tarraydef.ppuload(ppufile:tcompilerppufile);
  2898. begin
  2899. inherited ppuload(arraydef,ppufile);
  2900. { the addresses are calculated later }
  2901. ppufile.getderef(_elementdefderef);
  2902. ppufile.getderef(rangedefderef);
  2903. lowrange:=ppufile.getasizeint;
  2904. highrange:=ppufile.getasizeint;
  2905. ppufile.getsmallset(arrayoptions);
  2906. ppuload_platform(ppufile);
  2907. symtable:=tarraysymtable.create(self);
  2908. tarraysymtable(symtable).ppuload(ppufile)
  2909. end;
  2910. function tarraydef.getcopy : tstoreddef;
  2911. begin
  2912. result:=carraydef.create(lowrange,highrange,rangedef);
  2913. tarraydef(result).arrayoptions:=arrayoptions;
  2914. tarraydef(result)._elementdef:=_elementdef;
  2915. end;
  2916. procedure tarraydef.buildderef;
  2917. begin
  2918. inherited buildderef;
  2919. tarraysymtable(symtable).buildderef;
  2920. _elementdefderef.build(_elementdef);
  2921. rangedefderef.build(rangedef);
  2922. end;
  2923. procedure tarraydef.deref;
  2924. begin
  2925. inherited deref;
  2926. tarraysymtable(symtable).deref;
  2927. _elementdef:=tdef(_elementdefderef.resolve);
  2928. rangedef:=tdef(rangedefderef.resolve);
  2929. fillgenericparas(symtable);
  2930. end;
  2931. procedure tarraydef.ppuwrite(ppufile:tcompilerppufile);
  2932. begin
  2933. inherited ppuwrite(ppufile);
  2934. ppufile.putderef(_elementdefderef);
  2935. ppufile.putderef(rangedefderef);
  2936. ppufile.putasizeint(lowrange);
  2937. ppufile.putasizeint(highrange);
  2938. ppufile.putsmallset(arrayoptions);
  2939. writeentry(ppufile,ibarraydef);
  2940. tarraysymtable(symtable).ppuwrite(ppufile);
  2941. end;
  2942. function tarraydef.elesize : asizeint;
  2943. begin
  2944. if (ado_IsBitPacked in arrayoptions) then
  2945. internalerror(2006080101);
  2946. if assigned(_elementdef) then
  2947. result:=_elementdef.size
  2948. else
  2949. result:=0;
  2950. end;
  2951. function tarraydef.elepackedbitsize : asizeint;
  2952. begin
  2953. if not(ado_IsBitPacked in arrayoptions) then
  2954. internalerror(2006080102);
  2955. if assigned(_elementdef) then
  2956. result:=_elementdef.packedbitsize
  2957. else
  2958. result:=0;
  2959. end;
  2960. function tarraydef.elecount : asizeuint;
  2961. var
  2962. qhigh,qlow : qword;
  2963. begin
  2964. if ado_IsDynamicArray in arrayoptions then
  2965. begin
  2966. result:=0;
  2967. exit;
  2968. end;
  2969. if (highrange>0) and (lowrange<0) then
  2970. begin
  2971. qhigh:=highrange;
  2972. qlow:=qword(-lowrange);
  2973. { prevent overflow, return 0 to indicate overflow }
  2974. if qhigh+qlow>qword(high(asizeint)-1) then
  2975. result:=0
  2976. else
  2977. result:=qhigh+qlow+1;
  2978. end
  2979. else
  2980. result:=int64(highrange)-lowrange+1;
  2981. end;
  2982. function tarraydef.size : asizeint;
  2983. var
  2984. cachedelecount : asizeuint;
  2985. cachedelesize : asizeint;
  2986. begin
  2987. if ado_IsDynamicArray in arrayoptions then
  2988. begin
  2989. size:=voidpointertype.size;
  2990. exit;
  2991. end;
  2992. { Tarraydef.size may never be called for an open array! }
  2993. if highrange<lowrange then
  2994. internalerror(99080501);
  2995. if not (ado_IsBitPacked in arrayoptions) then
  2996. cachedelesize:=elesize
  2997. else
  2998. cachedelesize := elepackedbitsize;
  2999. cachedelecount:=elecount;
  3000. if (cachedelesize = 0) then
  3001. begin
  3002. size := 0;
  3003. exit;
  3004. end;
  3005. if (cachedelecount = 0) then
  3006. begin
  3007. size := -1;
  3008. exit;
  3009. end;
  3010. { prevent overflow, return -1 to indicate overflow }
  3011. { also make sure we don't need 64/128 bit arithmetic to calculate offsets }
  3012. if (cachedelecount > asizeuint(high(asizeint))) or
  3013. ((high(asizeint) div cachedelesize) < asizeint(cachedelecount)) or
  3014. { also lowrange*elesize must be < high(asizeint) to prevent overflow when
  3015. accessing the array, see ncgmem (PFV) }
  3016. ((high(asizeint) div cachedelesize) < abs(lowrange)) then
  3017. begin
  3018. result:=-1;
  3019. exit;
  3020. end;
  3021. result:=cachedelesize*asizeint(cachedelecount);
  3022. if (ado_IsBitPacked in arrayoptions) then
  3023. { can't just add 7 and divide by 8, because that may overflow }
  3024. result:=result div 8 + ord((result mod 8)<>0);
  3025. end;
  3026. procedure tarraydef.setelementdef(def:tdef);
  3027. begin
  3028. _elementdef:=def;
  3029. if not(
  3030. (ado_IsDynamicArray in arrayoptions) or
  3031. (ado_IsConvertedPointer in arrayoptions) or
  3032. (highrange<lowrange)
  3033. ) and
  3034. (size=-1) then
  3035. Message(sym_e_segment_too_large);
  3036. end;
  3037. function tarraydef.alignment : shortint;
  3038. begin
  3039. { alignment of dyn. arrays doesn't depend on the element size }
  3040. if (ado_IsDynamicArray in arrayoptions) then
  3041. alignment:=size_2_align(voidpointertype.size)
  3042. { alignment is the target alignment for the used load size }
  3043. else if (ado_IsBitPacked in arrayoptions) and
  3044. (elementdef.typ in [enumdef,orddef]) then
  3045. alignment:=cgsize_orddef(int_cgsize(packedbitsloadsize(elepackedbitsize))).alignment
  3046. { alignment is the alignment of the elements }
  3047. else
  3048. alignment:=elementdef.alignment
  3049. end;
  3050. function tarraydef.needs_inittable : boolean;
  3051. begin
  3052. needs_inittable:=(ado_IsDynamicArray in arrayoptions) or elementdef.needs_inittable;
  3053. end;
  3054. function tarraydef.needs_separate_initrtti : boolean;
  3055. begin
  3056. if ado_IsBitPacked in arrayoptions then
  3057. result:=false
  3058. else
  3059. result:=elementdef.needs_separate_initrtti;
  3060. end;
  3061. function tarraydef.GetTypeName : string;
  3062. begin
  3063. if (ado_IsConstString in arrayoptions) then
  3064. result:='Constant String'
  3065. else if (ado_isarrayofconst in arrayoptions) or
  3066. (ado_isConstructor in arrayoptions) then
  3067. begin
  3068. if (ado_isvariant in arrayoptions) or ((highrange=-1) and (lowrange=0)) then
  3069. GetTypeName:='Array Of Const'
  3070. else
  3071. GetTypeName:='{Array Of Const/Constant Open} Array of '+elementdef.typename;
  3072. end
  3073. else if (ado_IsDynamicArray in arrayoptions) then
  3074. GetTypeName:='{Dynamic} Array Of '+elementdef.typename
  3075. else if ((highrange=-1) and (lowrange=0)) then
  3076. GetTypeName:='{Open} Array Of '+elementdef.typename
  3077. else
  3078. begin
  3079. result := '';
  3080. if (ado_IsBitPacked in arrayoptions) then
  3081. result:='BitPacked ';
  3082. if rangedef.typ=enumdef then
  3083. result:=result+'Array['+rangedef.typename+'] Of '+elementdef.typename
  3084. else
  3085. result:=result+'Array['+tostr(lowrange)+'..'+
  3086. tostr(highrange)+'] Of '+elementdef.typename
  3087. end;
  3088. end;
  3089. function tarraydef.getmangledparaname : TSymStr;
  3090. begin
  3091. if ado_isarrayofconst in arrayoptions then
  3092. getmangledparaname:='array_of_const'
  3093. else
  3094. if ((highrange=-1) and (lowrange=0)) then
  3095. getmangledparaname:='array_of_'+elementdef.mangledparaname
  3096. else
  3097. internalerror(200204176);
  3098. end;
  3099. function tarraydef.is_publishable : boolean;
  3100. begin
  3101. Result:=ado_IsDynamicArray in arrayoptions;
  3102. end;
  3103. {***************************************************************************
  3104. tabstractrecorddef
  3105. ***************************************************************************}
  3106. constructor tabstractrecorddef.create(const n:string; dt:tdeftyp);
  3107. begin
  3108. inherited create(dt);
  3109. objname:=stringdup(upper(n));
  3110. objrealname:=stringdup(n);
  3111. objectoptions:=[];
  3112. if assigned(current_module.namespace) then
  3113. begin
  3114. import_lib:=stringdup(current_module.namespace^);
  3115. replace(import_lib^,'.','/');
  3116. end;
  3117. end;
  3118. constructor tabstractrecorddef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  3119. begin
  3120. inherited ppuload(dt,ppufile);
  3121. objrealname:=stringdup(ppufile.getstring);
  3122. objname:=stringdup(upper(objrealname^));
  3123. import_lib:=stringdup(ppufile.getstring);
  3124. { only used for external C++ classes and Java classes/records }
  3125. if (import_lib^='') then
  3126. stringdispose(import_lib);
  3127. ppufile.getsmallset(objectoptions);
  3128. end;
  3129. procedure tabstractrecorddef.ppuwrite(ppufile: tcompilerppufile);
  3130. begin
  3131. inherited ppuwrite(ppufile);
  3132. ppufile.putstring(objrealname^);
  3133. if assigned(import_lib) then
  3134. ppufile.putstring(import_lib^)
  3135. else
  3136. ppufile.putstring('');
  3137. ppufile.putsmallset(objectoptions);
  3138. end;
  3139. destructor tabstractrecorddef.destroy;
  3140. begin
  3141. stringdispose(objname);
  3142. stringdispose(objrealname);
  3143. stringdispose(import_lib);
  3144. tcinitcode.free;
  3145. inherited destroy;
  3146. end;
  3147. procedure tabstractrecorddef.check_forwards;
  3148. begin
  3149. { the defs of a copied def are defined for the original type only }
  3150. if not(df_copied_def in defoptions) then
  3151. tstoredsymtable(symtable).check_forwards;
  3152. end;
  3153. function tabstractrecorddef.find_procdef_bytype(pt:tproctypeoption): tprocdef;
  3154. var
  3155. i: longint;
  3156. sym: tsym;
  3157. begin
  3158. for i:=0 to symtable.SymList.Count-1 do
  3159. begin
  3160. sym:=tsym(symtable.SymList[i]);
  3161. if sym.typ=procsym then
  3162. begin
  3163. result:=tprocsym(sym).find_procdef_bytype(pt);
  3164. if assigned(result) then
  3165. exit;
  3166. end;
  3167. end;
  3168. result:=nil;
  3169. end;
  3170. function tabstractrecorddef.GetSymtable(t:tGetSymtable):TSymtable;
  3171. begin
  3172. if t=gs_record then
  3173. GetSymtable:=symtable
  3174. else
  3175. GetSymtable:=nil;
  3176. end;
  3177. function tabstractrecorddef.is_packed:boolean;
  3178. begin
  3179. result:=tabstractrecordsymtable(symtable).is_packed;
  3180. end;
  3181. function tabstractrecorddef.RttiName: string;
  3182. begin
  3183. Result:=OwnerHierarchyName+objrealname^;
  3184. end;
  3185. function tabstractrecorddef.search_enumerator_get: tprocdef;
  3186. var
  3187. sym : tsym;
  3188. i : integer;
  3189. pd : tprocdef;
  3190. hashedid : THashedIDString;
  3191. begin
  3192. result:=nil;
  3193. hashedid.id:='GETENUMERATOR';
  3194. sym:=tsym(symtable.FindWithHash(hashedid));
  3195. if assigned(sym) and (sym.typ=procsym) then
  3196. begin
  3197. for i := 0 to Tprocsym(sym).ProcdefList.Count - 1 do
  3198. begin
  3199. pd := tprocdef(Tprocsym(sym).ProcdefList[i]);
  3200. if (pd.proctypeoption = potype_function) and
  3201. (is_class_or_interface_or_object(pd.returndef) or is_record(pd.returndef)) and
  3202. (pd.visibility >= vis_public) then
  3203. begin
  3204. result:=pd;
  3205. exit;
  3206. end;
  3207. end;
  3208. end;
  3209. end;
  3210. function tabstractrecorddef.search_enumerator_move: tprocdef;
  3211. var
  3212. sym : tsym;
  3213. i : integer;
  3214. pd : tprocdef;
  3215. hashedid : THashedIDString;
  3216. begin
  3217. result:=nil;
  3218. // first search for po_enumerator_movenext method modifier
  3219. // then search for public function MoveNext: Boolean
  3220. for i:=0 to symtable.SymList.Count-1 do
  3221. begin
  3222. sym:=TSym(symtable.SymList[i]);
  3223. if (sym.typ=procsym) then
  3224. begin
  3225. pd:=Tprocsym(sym).find_procdef_byoptions([po_enumerator_movenext]);
  3226. if assigned(pd) then
  3227. begin
  3228. result:=pd;
  3229. exit;
  3230. end;
  3231. end;
  3232. end;
  3233. hashedid.id:='MOVENEXT';
  3234. sym:=tsym(symtable.FindWithHash(hashedid));
  3235. if assigned(sym) and (sym.typ=procsym) then
  3236. begin
  3237. for i:=0 to Tprocsym(sym).ProcdefList.Count-1 do
  3238. begin
  3239. pd := tprocdef(Tprocsym(sym).ProcdefList[i]);
  3240. if (pd.proctypeoption = potype_function) and
  3241. is_boolean(pd.returndef) and
  3242. (pd.minparacount = 0) and
  3243. (pd.visibility >= vis_public) then
  3244. begin
  3245. result:=pd;
  3246. exit;
  3247. end;
  3248. end;
  3249. end;
  3250. end;
  3251. function tabstractrecorddef.search_enumerator_current: tsym;
  3252. var
  3253. sym: tsym;
  3254. i: integer;
  3255. hashedid : THashedIDString;
  3256. begin
  3257. result:=nil;
  3258. // first search for ppo_enumerator_current property modifier
  3259. // then search for public property Current
  3260. for i:=0 to symtable.SymList.Count-1 do
  3261. begin
  3262. sym:=TSym(symtable.SymList[i]);
  3263. if (sym.typ=propertysym) and (ppo_enumerator_current in tpropertysym(sym).propoptions) then
  3264. begin
  3265. result:=sym;
  3266. exit;
  3267. end;
  3268. end;
  3269. hashedid.id:='CURRENT';
  3270. sym:=tsym(symtable.FindWithHash(hashedid));
  3271. if assigned(sym) and (sym.typ=propertysym) and
  3272. (sym.visibility >= vis_public) and not tpropertysym(sym).propaccesslist[palt_read].empty then
  3273. begin
  3274. result:=sym;
  3275. exit;
  3276. end;
  3277. end;
  3278. function tabstractrecorddef.jvm_full_typename(with_package_name: boolean): string;
  3279. var
  3280. st: tsymtable;
  3281. enclosingdef: tdef;
  3282. begin
  3283. if typ=objectdef then
  3284. result:=tobjectdef(self).objextname^
  3285. else if assigned(typesym) then
  3286. result:=typesym.realname
  3287. { have to generate anonymous nested type in current unit/class/record }
  3288. else
  3289. internalerror(2011032601);
  3290. { in case of specializations, add some extras to prevent name conflicts
  3291. with nested classes }
  3292. if df_specialization in defoptions then
  3293. result:='$'+result+'$specialization$';
  3294. st:=owner;
  3295. while assigned(st) and
  3296. (st.symtabletype in [objectsymtable,recordsymtable,localsymtable]) do
  3297. begin
  3298. { nested classes are named as "OuterClass$InnerClass" }
  3299. enclosingdef:=tdef(st.defowner);
  3300. if enclosingdef.typ=procdef then
  3301. result:=result+tprocdef(enclosingdef).procsym.realname+'$$'+tostr(tprocdef(enclosingdef).procsym.symid)+'$'
  3302. else if enclosingdef.typ=objectdef then
  3303. result:=tobjectdef(enclosingdef).objextname^+'$'+result
  3304. else if assigned(enclosingdef.typesym) then
  3305. result:=enclosingdef.typesym.realname+'$'+result
  3306. else
  3307. internalerror(2011060305);
  3308. st:=enclosingdef.owner;
  3309. end;
  3310. if with_package_name and
  3311. assigned(import_lib) then
  3312. result:=import_lib^+'/'+result;
  3313. end;
  3314. function tabstractrecorddef.contains_float_field: boolean;
  3315. var
  3316. i : longint;
  3317. begin
  3318. result:=true;
  3319. for i:=0 to symtable.symlist.count-1 do
  3320. begin
  3321. if tsym(symtable.symlist[i]).typ<>fieldvarsym then
  3322. continue;
  3323. if assigned(tfieldvarsym(symtable.symlist[i]).vardef) and
  3324. tstoreddef(tfieldvarsym(symtable.symlist[i]).vardef).is_fpuregable then
  3325. exit;
  3326. end;
  3327. result:=false;
  3328. end;
  3329. {***************************************************************************
  3330. trecorddef
  3331. ***************************************************************************}
  3332. constructor trecorddef.create(const n:string; p:TSymtable);
  3333. begin
  3334. inherited create(n,recorddef);
  3335. symtable:=p;
  3336. { we can own the symtable only if nobody else owns a copy so far }
  3337. if symtable.refcount=1 then
  3338. symtable.defowner:=self;
  3339. isunion:=false;
  3340. end;
  3341. constructor trecorddef.ppuload(ppufile:tcompilerppufile);
  3342. procedure readvariantrecdesc(var variantrecdesc : pvariantrecdesc);
  3343. var
  3344. i,j : longint;
  3345. begin
  3346. if ppufile.getbyte=1 then
  3347. begin
  3348. new(variantrecdesc);
  3349. ppufile.getderef(variantrecdesc^.variantselectorderef);
  3350. SetLength(variantrecdesc^.branches,ppufile.getasizeint);
  3351. for i:=0 to high(variantrecdesc^.branches) do
  3352. begin
  3353. SetLength(variantrecdesc^.branches[i].values,ppufile.getasizeint);
  3354. for j:=0 to high(variantrecdesc^.branches[i].values) do
  3355. variantrecdesc^.branches[i].values[j]:=ppufile.getexprint;
  3356. readvariantrecdesc(variantrecdesc^.branches[i].nestedvariant);
  3357. end;
  3358. end
  3359. else
  3360. variantrecdesc:=nil;
  3361. end;
  3362. begin
  3363. inherited ppuload(recorddef,ppufile);
  3364. if df_copied_def in defoptions then
  3365. begin
  3366. ppufile.getderef(cloneddefderef);
  3367. ppuload_platform(ppufile);
  3368. end
  3369. else
  3370. begin
  3371. ppuload_platform(ppufile);
  3372. symtable:=trecordsymtable.create(objrealname^,0);
  3373. trecordsymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  3374. trecordsymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  3375. trecordsymtable(symtable).padalignment:=shortint(ppufile.getbyte);
  3376. trecordsymtable(symtable).usefieldalignment:=shortint(ppufile.getbyte);
  3377. trecordsymtable(symtable).datasize:=ppufile.getasizeint;
  3378. trecordsymtable(symtable).paddingsize:=ppufile.getword;
  3379. trecordsymtable(symtable).ppuload(ppufile);
  3380. { the variantrecdesc is needed only for iso-like new statements new(prec,1,2,3 ...);
  3381. but because iso mode supports no units, there is no need to store the variantrecdesc
  3382. in the ppu
  3383. }
  3384. // readvariantrecdesc(variantrecdesc);
  3385. { requires usefieldalignment to be set }
  3386. symtable.defowner:=self;
  3387. end;
  3388. isunion:=false;
  3389. end;
  3390. destructor trecorddef.destroy;
  3391. begin
  3392. if assigned(symtable) then
  3393. begin
  3394. symtable.free;
  3395. symtable:=nil;
  3396. end;
  3397. inherited destroy;
  3398. end;
  3399. function trecorddef.getcopy : tstoreddef;
  3400. begin
  3401. result:=crecorddef.create(objrealname^,symtable.getcopy);
  3402. trecorddef(result).isunion:=isunion;
  3403. include(trecorddef(result).defoptions,df_copied_def);
  3404. if assigned(tcinitcode) then
  3405. trecorddef(result).tcinitcode:=tcinitcode.getcopy;
  3406. if assigned(import_lib) then
  3407. trecorddef(result).import_lib:=stringdup(import_lib^);
  3408. end;
  3409. function trecorddef.needs_inittable : boolean;
  3410. begin
  3411. needs_inittable:=trecordsymtable(symtable).needs_init_final
  3412. end;
  3413. function trecorddef.needs_separate_initrtti : boolean;
  3414. begin
  3415. result:=true;
  3416. end;
  3417. procedure trecorddef.buildderef;
  3418. begin
  3419. inherited buildderef;
  3420. if df_copied_def in defoptions then
  3421. cloneddefderef.build(symtable.defowner)
  3422. else
  3423. tstoredsymtable(symtable).buildderef;
  3424. end;
  3425. procedure trecorddef.buildderefimpl;
  3426. begin
  3427. inherited buildderefimpl;
  3428. if not (df_copied_def in defoptions) then
  3429. tstoredsymtable(symtable).buildderefimpl;
  3430. end;
  3431. procedure trecorddef.deref;
  3432. begin
  3433. inherited deref;
  3434. { now dereference the definitions }
  3435. if df_copied_def in defoptions then
  3436. begin
  3437. cloneddef:=trecorddef(cloneddefderef.resolve);
  3438. symtable:=cloneddef.symtable.getcopy;
  3439. end
  3440. else
  3441. tstoredsymtable(symtable).deref;
  3442. fillgenericparas(symtable);
  3443. { assign TGUID? load only from system unit }
  3444. if not(assigned(rec_tguid)) and
  3445. (upper(typename)='TGUID') and
  3446. assigned(owner) and
  3447. assigned(owner.name) and
  3448. (owner.name^='SYSTEM') then
  3449. rec_tguid:=self;
  3450. { assign JMP_BUF? load only from system unit }
  3451. if not(assigned(rec_jmp_buf)) and
  3452. (upper(typename)='JMP_BUF') and
  3453. assigned(owner) and
  3454. assigned(owner.name) and
  3455. (owner.name^='SYSTEM') then
  3456. rec_jmp_buf:=self;
  3457. end;
  3458. procedure trecorddef.ppuwrite(ppufile:tcompilerppufile);
  3459. procedure writevariantrecdesc(variantrecdesc : pvariantrecdesc);
  3460. var
  3461. i,j : longint;
  3462. begin
  3463. if assigned(variantrecdesc) then
  3464. begin
  3465. ppufile.putbyte(1);
  3466. ppufile.putderef(variantrecdesc^.variantselectorderef);
  3467. ppufile.putasizeint(length(variantrecdesc^.branches));
  3468. for i:=0 to high(variantrecdesc^.branches) do
  3469. begin
  3470. ppufile.putasizeint(length(variantrecdesc^.branches[i].values));
  3471. for j:=0 to high(variantrecdesc^.branches[i].values) do
  3472. ppufile.putexprint(variantrecdesc^.branches[i].values[j]);
  3473. writevariantrecdesc(variantrecdesc^.branches[i].nestedvariant);
  3474. end;
  3475. end
  3476. else
  3477. ppufile.putbyte(0);
  3478. end;
  3479. begin
  3480. inherited ppuwrite(ppufile);
  3481. if df_copied_def in defoptions then
  3482. ppufile.putderef(cloneddefderef)
  3483. else
  3484. begin
  3485. ppufile.putbyte(byte(trecordsymtable(symtable).fieldalignment));
  3486. ppufile.putbyte(byte(trecordsymtable(symtable).recordalignment));
  3487. ppufile.putbyte(byte(trecordsymtable(symtable).padalignment));
  3488. ppufile.putbyte(byte(trecordsymtable(symtable).usefieldalignment));
  3489. ppufile.putasizeint(trecordsymtable(symtable).datasize);
  3490. ppufile.putword(trecordsymtable(symtable).paddingsize);
  3491. { the variantrecdesc is needed only for iso-like new statements new(prec,1,2,3 ...);
  3492. but because iso mode supports no units, there is no need to store the variantrecdesc
  3493. in the ppu
  3494. }
  3495. // writevariantrecdesc(variantrecdesc);
  3496. end;
  3497. writeentry(ppufile,ibrecorddef);
  3498. if not(df_copied_def in defoptions) then
  3499. trecordsymtable(symtable).ppuwrite(ppufile);
  3500. end;
  3501. function trecorddef.size:asizeint;
  3502. begin
  3503. result:=trecordsymtable(symtable).datasize;
  3504. end;
  3505. function trecorddef.alignment:shortint;
  3506. begin
  3507. alignment:=trecordsymtable(symtable).recordalignment;
  3508. end;
  3509. function trecorddef.padalignment:shortint;
  3510. begin
  3511. padalignment := trecordsymtable(symtable).padalignment;
  3512. end;
  3513. function trecorddef.GetTypeName : string;
  3514. begin
  3515. GetTypeName:='<record type>'
  3516. end;
  3517. {***************************************************************************
  3518. TABSTRACTPROCDEF
  3519. ***************************************************************************}
  3520. constructor tabstractprocdef.create(dt:tdeftyp;level:byte);
  3521. begin
  3522. inherited create(dt);
  3523. parast:=tparasymtable.create(self,level);
  3524. paras:=nil;
  3525. minparacount:=0;
  3526. maxparacount:=0;
  3527. proctypeoption:=potype_none;
  3528. proccalloption:=pocall_none;
  3529. procoptions:=[];
  3530. {$ifdef i8086}
  3531. if current_settings.x86memorymodel in x86_far_code_models then
  3532. procoptions:=procoptions+[po_far];
  3533. {$endif i8086}
  3534. returndef:=voidtype;
  3535. savesize:=sizeof(pint);
  3536. callerargareasize:=0;
  3537. calleeargareasize:=0;
  3538. has_paraloc_info:=callnoside;
  3539. funcretloc[callerside].init;
  3540. funcretloc[calleeside].init;
  3541. check_mark_as_nested;
  3542. end;
  3543. destructor tabstractprocdef.destroy;
  3544. begin
  3545. if assigned(paras) then
  3546. begin
  3547. {$ifdef MEMDEBUG}
  3548. memprocpara.start;
  3549. {$endif MEMDEBUG}
  3550. paras.free;
  3551. paras:=nil;
  3552. {$ifdef MEMDEBUG}
  3553. memprocpara.stop;
  3554. {$endif MEMDEBUG}
  3555. end;
  3556. if assigned(parast) then
  3557. begin
  3558. {$ifdef MEMDEBUG}
  3559. memprocparast.start;
  3560. {$endif MEMDEBUG}
  3561. parast.free;
  3562. parast:=nil;
  3563. {$ifdef MEMDEBUG}
  3564. memprocparast.stop;
  3565. {$endif MEMDEBUG}
  3566. end;
  3567. funcretloc[callerside].done;
  3568. funcretloc[calleeside].done;
  3569. inherited destroy;
  3570. end;
  3571. procedure tabstractprocdef.count_para(p:TObject;arg:pointer);
  3572. begin
  3573. if (tsym(p).typ<>paravarsym) then
  3574. exit;
  3575. inc(plongint(arg)^);
  3576. if not(vo_is_hidden_para in tparavarsym(p).varoptions) then
  3577. begin
  3578. if not assigned(tparavarsym(p).defaultconstsym) then
  3579. inc(minparacount);
  3580. inc(maxparacount);
  3581. end;
  3582. end;
  3583. procedure tabstractprocdef.insert_para(p:TObject;arg:pointer);
  3584. begin
  3585. if (tsym(p).typ<>paravarsym) then
  3586. exit;
  3587. paras.add(p);
  3588. end;
  3589. procedure tabstractprocdef.calcparas;
  3590. var
  3591. paracount : longint;
  3592. begin
  3593. { This can already be assigned when
  3594. we need to reresolve this unit (PFV) }
  3595. if assigned(paras) then
  3596. paras.free;
  3597. paras:=tparalist.create(false);
  3598. paracount:=0;
  3599. minparacount:=0;
  3600. maxparacount:=0;
  3601. parast.SymList.ForEachCall(@count_para,@paracount);
  3602. paras.capacity:=paracount;
  3603. { Insert parameters in table }
  3604. parast.SymList.ForEachCall(@insert_para,nil);
  3605. { Order parameters }
  3606. paras.sortparas;
  3607. end;
  3608. procedure tabstractprocdef.buildderef;
  3609. begin
  3610. { released procdef? }
  3611. if not assigned(parast) then
  3612. exit;
  3613. inherited buildderef;
  3614. returndefderef.build(returndef);
  3615. if po_explicitparaloc in procoptions then
  3616. funcretloc[callerside].buildderef;
  3617. { parast }
  3618. tparasymtable(parast).buildderef;
  3619. end;
  3620. procedure tabstractprocdef.deref;
  3621. begin
  3622. inherited deref;
  3623. returndef:=tdef(returndefderef.resolve);
  3624. if po_explicitparaloc in procoptions then
  3625. begin
  3626. funcretloc[callerside].deref;
  3627. has_paraloc_info:=callerside;
  3628. end
  3629. else
  3630. begin
  3631. { deref is called after loading from a ppu, but also after another
  3632. unit has been reloaded/recompiled and all references must be
  3633. re-resolved. Since the funcretloc contains a reference to a tdef,
  3634. reset it so that we won't try to access the stale def }
  3635. funcretloc[callerside].init;
  3636. has_paraloc_info:=callnoside;
  3637. end;
  3638. { parast }
  3639. tparasymtable(parast).deref;
  3640. { recalculated parameters }
  3641. calcparas;
  3642. fillgenericparas(parast);
  3643. end;
  3644. constructor tabstractprocdef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  3645. begin
  3646. inherited ppuload(dt,ppufile);
  3647. parast:=nil;
  3648. Paras:=nil;
  3649. minparacount:=0;
  3650. maxparacount:=0;
  3651. ppufile.getderef(returndefderef);
  3652. proctypeoption:=tproctypeoption(ppufile.getbyte);
  3653. proccalloption:=tproccalloption(ppufile.getbyte);
  3654. ppufile.getnormalset(procoptions);
  3655. funcretloc[callerside].init;
  3656. if po_explicitparaloc in procoptions then
  3657. funcretloc[callerside].ppuload(ppufile);
  3658. savesize:=sizeof(pint);
  3659. if (po_explicitparaloc in procoptions) then
  3660. has_paraloc_info:=callerside;
  3661. end;
  3662. procedure tabstractprocdef.ppuwrite(ppufile:tcompilerppufile);
  3663. var
  3664. oldintfcrc : boolean;
  3665. begin
  3666. { released procdef? }
  3667. if not assigned(parast) then
  3668. exit;
  3669. inherited ppuwrite(ppufile);
  3670. ppufile.putderef(returndefderef);
  3671. oldintfcrc:=ppufile.do_interface_crc;
  3672. ppufile.do_interface_crc:=false;
  3673. ppufile.putbyte(ord(proctypeoption));
  3674. ppufile.putbyte(ord(proccalloption));
  3675. ppufile.putnormalset(procoptions);
  3676. ppufile.do_interface_crc:=oldintfcrc;
  3677. if (po_explicitparaloc in procoptions) then
  3678. funcretloc[callerside].ppuwrite(ppufile);
  3679. end;
  3680. function tabstractprocdef.typename_paras(pno: tprocnameoptions) : ansistring;
  3681. var
  3682. hs,s : ansistring;
  3683. hp : TParavarsym;
  3684. hpc : tconstsym;
  3685. first : boolean;
  3686. i : integer;
  3687. begin
  3688. s:='';
  3689. first:=true;
  3690. for i:=0 to paras.count-1 do
  3691. begin
  3692. hp:=tparavarsym(paras[i]);
  3693. if not(vo_is_hidden_para in hp.varoptions) or
  3694. (pno_showhidden in pno) then
  3695. begin
  3696. if first then
  3697. begin
  3698. s:=s+'(';
  3699. first:=false;
  3700. end
  3701. else
  3702. s:=s+';';
  3703. if vo_is_hidden_para in hp.varoptions then
  3704. s:=s+'<';
  3705. case hp.varspez of
  3706. vs_var :
  3707. s:=s+'var ';
  3708. vs_const :
  3709. s:=s+'const ';
  3710. vs_out :
  3711. s:=s+'out ';
  3712. vs_constref :
  3713. s:=s+'constref ';
  3714. end;
  3715. if (pno_paranames in pno) then
  3716. s:=s+hp.realname+':';
  3717. if hp.univpara then
  3718. s:=s+'univ ';
  3719. if assigned(hp.vardef.typesym) then
  3720. begin
  3721. hs:=hp.vardef.typesym.realname;
  3722. if hs[1]<>'$' then
  3723. s:=s+hp.vardef.OwnerHierarchyName+hs
  3724. else
  3725. s:=s+hp.vardef.GetTypeName;
  3726. end
  3727. else
  3728. s:=s+hp.vardef.GetTypeName;
  3729. { default value }
  3730. if assigned(hp.defaultconstsym) then
  3731. begin
  3732. hpc:=tconstsym(hp.defaultconstsym);
  3733. hs:='';
  3734. case hpc.consttyp of
  3735. conststring,
  3736. constresourcestring :
  3737. begin
  3738. If hpc.value.len>0 then
  3739. begin
  3740. setLength(hs,hpc.value.len);
  3741. { don't write past the end of hs if the constant
  3742. is > 255 chars }
  3743. move(hpc.value.valueptr^,hs[1],length(hs));
  3744. { make sure that constant strings with newline chars
  3745. don't create a linebreak in the assembler code,
  3746. since comments are line-based. Also remove nulls
  3747. because the comments are written as a pchar. }
  3748. ReplaceCase(hs,#0,'.');
  3749. ReplaceCase(hs,#10,'.');
  3750. ReplaceCase(hs,#13,'.');
  3751. end;
  3752. end;
  3753. constreal :
  3754. str(pbestreal(hpc.value.valueptr)^,hs);
  3755. constpointer :
  3756. hs:=tostr(hpc.value.valueordptr);
  3757. constord :
  3758. begin
  3759. if is_boolean(hpc.constdef) then
  3760. begin
  3761. if hpc.value.valueord<>0 then
  3762. hs:='TRUE'
  3763. else
  3764. hs:='FALSE';
  3765. end
  3766. else
  3767. hs:=tostr(hpc.value.valueord);
  3768. end;
  3769. constnil :
  3770. hs:='nil';
  3771. constset :
  3772. hs:='<set>';
  3773. end;
  3774. if hs<>'' then
  3775. s:=s+'="'+hs+'"';
  3776. end;
  3777. if vo_is_hidden_para in hp.varoptions then
  3778. s:=s+'>';
  3779. end;
  3780. end;
  3781. if not first then
  3782. s:=s+')';
  3783. if (po_varargs in procoptions) then
  3784. s:=s+';VarArgs';
  3785. typename_paras:=s;
  3786. end;
  3787. function tabstractprocdef.is_methodpointer:boolean;
  3788. begin
  3789. result:=false;
  3790. end;
  3791. function tabstractprocdef.is_addressonly:boolean;
  3792. begin
  3793. result:=true;
  3794. end;
  3795. function tabstractprocdef.no_self_node: boolean;
  3796. begin
  3797. Result:=([po_staticmethod,po_classmethod]<=procoptions)or
  3798. (proctypeoption in [potype_class_constructor,potype_class_destructor,potype_operator]);
  3799. end;
  3800. function tabstractprocdef.getcopyas(newtyp:tdeftyp;copytyp:tproccopytyp): tstoreddef;
  3801. var
  3802. j, nestinglevel: longint;
  3803. pvs, npvs: tparavarsym;
  3804. begin
  3805. nestinglevel:=parast.symtablelevel;
  3806. if newtyp=procdef then
  3807. begin
  3808. if (copytyp<>pc_bareproc) then
  3809. result:=cprocdef.create(nestinglevel)
  3810. else
  3811. result:=cprocdef.create(normal_function_level);
  3812. tprocdef(result).visibility:=vis_public;
  3813. end
  3814. else
  3815. begin
  3816. result:=cprocvardef.create(nestinglevel);
  3817. end;
  3818. tabstractprocdef(result).returndef:=returndef;
  3819. tabstractprocdef(result).returndefderef:=returndefderef;
  3820. pvs:=nil;
  3821. npvs:=nil;
  3822. for j:=0 to parast.symlist.count-1 do
  3823. begin
  3824. case tsym(parast.symlist[j]).typ of
  3825. paravarsym:
  3826. begin
  3827. pvs:=tparavarsym(parast.symlist[j]);
  3828. { in case of bare proc, don't copy self, vmt or framepointer
  3829. parameters }
  3830. if (copytyp=pc_bareproc) and
  3831. (([vo_is_self,vo_is_vmt,vo_is_parentfp,vo_is_result]*pvs.varoptions)<>[]) then
  3832. continue;
  3833. npvs:=cparavarsym.create(pvs.realname,pvs.paranr,pvs.varspez,
  3834. pvs.vardef,pvs.varoptions);
  3835. npvs.defaultconstsym:=pvs.defaultconstsym;
  3836. tabstractprocdef(result).parast.insert(npvs);
  3837. end;
  3838. constsym:
  3839. begin
  3840. // ignore, reuse original constym. Should also be duplicated
  3841. // be safe though
  3842. end;
  3843. symconst.typesym:
  3844. begin
  3845. // reuse original, part of generic declaration
  3846. end
  3847. else
  3848. internalerror(201160604);
  3849. end;
  3850. end;
  3851. tabstractprocdef(result).savesize:=savesize;
  3852. tabstractprocdef(result).proctypeoption:=proctypeoption;
  3853. tabstractprocdef(result).proccalloption:=proccalloption;
  3854. tabstractprocdef(result).procoptions:=procoptions;
  3855. if (copytyp=pc_bareproc) then
  3856. tabstractprocdef(result).procoptions:=tabstractprocdef(result).procoptions*[po_explicitparaloc,po_hascallingconvention,po_varargs,po_iocheck,po_has_importname,po_has_importdll];
  3857. if newtyp=procvardef then
  3858. tabstractprocdef(result).procoptions:=tabstractprocdef(result).procoptions-[po_has_importname,po_has_importdll];
  3859. tabstractprocdef(result).callerargareasize:=callerargareasize;
  3860. tabstractprocdef(result).calleeargareasize:=calleeargareasize;
  3861. tabstractprocdef(result).maxparacount:=maxparacount;
  3862. tabstractprocdef(result).minparacount:=minparacount;
  3863. if po_explicitparaloc in procoptions then
  3864. tabstractprocdef(result).funcretloc[callerside]:=funcretloc[callerside].getcopy;
  3865. { recalculate parameter info }
  3866. tabstractprocdef(result).has_paraloc_info:=callnoside;
  3867. {$ifdef m68k}
  3868. tabstractprocdef(result).exp_funcretloc:=exp_funcretloc;
  3869. {$endif}
  3870. if (typ=procdef) and
  3871. (newtyp=procvardef) and
  3872. (owner.symtabletype=ObjectSymtable) then
  3873. include(tprocvardef(result).procoptions,po_methodpointer);
  3874. end;
  3875. procedure tabstractprocdef.check_mark_as_nested;
  3876. begin
  3877. { nested procvars require that nested functions use the Delphi-style
  3878. nested procedure calling convention }
  3879. if (parast.symtablelevel>normal_function_level) and
  3880. (m_nested_procvars in current_settings.modeswitches) then
  3881. include(procoptions,po_delphi_nested_cc);
  3882. end;
  3883. procedure tabstractprocdef.init_paraloc_info(side: tcallercallee);
  3884. begin
  3885. if (side in [callerside,callbothsides]) and
  3886. not(has_paraloc_info in [callerside,callbothsides]) then
  3887. begin
  3888. callerargareasize:=paramanager.create_paraloc_info(self,callerside);
  3889. if has_paraloc_info in [calleeside,callbothsides] then
  3890. has_paraloc_info:=callbothsides
  3891. else
  3892. has_paraloc_info:=callerside;
  3893. end;
  3894. if (side in [calleeside,callbothsides]) and
  3895. not(has_paraloc_info in [calleeside,callbothsides]) then
  3896. begin
  3897. calleeargareasize:=paramanager.create_paraloc_info(self,calleeside);
  3898. if has_paraloc_info in [callerside,callbothsides] then
  3899. has_paraloc_info:=callbothsides
  3900. else
  3901. has_paraloc_info:=calleeside;
  3902. end;
  3903. end;
  3904. function tabstractprocdef.stack_tainting_parameter(side: tcallercallee): boolean;
  3905. var
  3906. p: tparavarsym;
  3907. ploc: PCGParalocation;
  3908. i: longint;
  3909. begin
  3910. result:=false;
  3911. init_paraloc_info(side);
  3912. for i:=0 to parast.SymList.Count-1 do
  3913. if tsym(parast.SymList[i]).typ=paravarsym then
  3914. begin
  3915. p:=tparavarsym(parast.SymList[i]);
  3916. { check if no parameter is located on the stack }
  3917. if is_open_array(p.vardef) or
  3918. is_array_of_const(p.vardef) then
  3919. begin
  3920. result:=true;
  3921. exit;
  3922. end;
  3923. ploc:=p.paraloc[side].location;
  3924. while assigned(ploc) do
  3925. begin
  3926. if (ploc^.loc=LOC_REFERENCE) then
  3927. begin
  3928. result:=true;
  3929. exit
  3930. end;
  3931. ploc:=ploc^.next;
  3932. end;
  3933. end;
  3934. end;
  3935. function tabstractprocdef.is_pushleftright: boolean;
  3936. begin
  3937. {$if defined(i8086) or defined(i386)}
  3938. result:=proccalloption in pushleftright_pocalls;
  3939. {$else}
  3940. result:=false;
  3941. {$endif}
  3942. end;
  3943. function tabstractprocdef.address_type: tdef;
  3944. begin
  3945. {$ifdef i8086}
  3946. if po_far in procoptions then
  3947. result:=voidfarpointertype
  3948. else
  3949. result:=voidnearpointertype;
  3950. {$else i8086}
  3951. result:=voidpointertype;
  3952. {$endif i8086}
  3953. end;
  3954. {***************************************************************************
  3955. TPROCDEF
  3956. ***************************************************************************}
  3957. function tprocdef.GetResultName: PShortString;
  3958. begin
  3959. if not assigned(implprocdefinfo) then
  3960. internalerror(2014010301);
  3961. result:=implprocdefinfo^.resultname;
  3962. end;
  3963. procedure tprocdef.SetResultName(AValue: PShortString);
  3964. begin
  3965. if not assigned(implprocdefinfo) then
  3966. internalerror(2014010302);
  3967. implprocdefinfo^.resultname:=AValue;
  3968. end;
  3969. function tprocdef.GetParentFPInitBlock: tnode;
  3970. begin
  3971. if not assigned(implprocdefinfo) then
  3972. internalerror(2014010303);
  3973. result:=implprocdefinfo^.parentfpinitblock;
  3974. end;
  3975. function tprocdef.GetParentFPStruct: tsym;
  3976. begin
  3977. if not assigned(implprocdefinfo) then
  3978. internalerror(2014010304);
  3979. result:=implprocdefinfo^.parentfpstruct;
  3980. end;
  3981. function tprocdef.GetParentFPStructPtrType: tdef;
  3982. begin
  3983. if not assigned(implprocdefinfo) then
  3984. internalerror(2014010305);
  3985. result:=implprocdefinfo^.parentfpstructptrtype;
  3986. end;
  3987. procedure tprocdef.SetParentFPInitBlock(AValue: tnode);
  3988. begin
  3989. if not assigned(implprocdefinfo) then
  3990. internalerror(2014010306);
  3991. implprocdefinfo^.parentfpinitblock:=AValue;
  3992. end;
  3993. function tprocdef.Getprocendtai: tai;
  3994. begin
  3995. if not assigned(implprocdefinfo) then
  3996. internalerror(2014010307);
  3997. result:=implprocdefinfo^.procendtai;
  3998. end;
  3999. function tprocdef.Getprocstarttai: tai;
  4000. begin
  4001. if not assigned(implprocdefinfo) then
  4002. internalerror(2014010308);
  4003. result:=implprocdefinfo^.procstarttai;
  4004. end;
  4005. procedure tprocdef.Setprocendtai(AValue: tai);
  4006. begin
  4007. if not assigned(implprocdefinfo) then
  4008. internalerror(2014010309);
  4009. implprocdefinfo^.procendtai:=AValue;
  4010. end;
  4011. function tprocdef.Getskpara: pointer;
  4012. begin
  4013. if not assigned(implprocdefinfo) then
  4014. internalerror(2014010310);
  4015. result:=implprocdefinfo^.skpara;
  4016. end;
  4017. procedure tprocdef.Setskpara(AValue: pointer);
  4018. begin
  4019. if not assigned(implprocdefinfo) then
  4020. internalerror(2014010311);
  4021. implprocdefinfo^.skpara:=AValue;
  4022. end;
  4023. function tprocdef.Getforwarddef: boolean;
  4024. begin
  4025. if not assigned(implprocdefinfo) then
  4026. internalerror(2014010312);
  4027. result:=implprocdefinfo^.forwarddef;
  4028. end;
  4029. function tprocdef.Gethasforward: boolean;
  4030. begin
  4031. if not assigned(implprocdefinfo) then
  4032. internalerror(2014010313);
  4033. result:=implprocdefinfo^.hasforward;
  4034. end;
  4035. function tprocdef.Getinterfacedef: boolean;
  4036. begin
  4037. if not assigned(implprocdefinfo) then
  4038. internalerror(2014010314);
  4039. result:=implprocdefinfo^.interfacedef;
  4040. end;
  4041. procedure tprocdef.Setforwarddef(AValue: boolean);
  4042. begin
  4043. if not assigned(implprocdefinfo) then
  4044. internalerror(2014010315);
  4045. implprocdefinfo^.forwarddef:=AValue;
  4046. end;
  4047. procedure tprocdef.Sethasforward(AValue: boolean);
  4048. begin
  4049. if not assigned(implprocdefinfo) then
  4050. internalerror(2014010316);
  4051. implprocdefinfo^.hasforward:=AValue;
  4052. end;
  4053. function tprocdef.GetIsEmpty: boolean;
  4054. begin
  4055. result:=pio_empty in implprocoptions;
  4056. end;
  4057. procedure tprocdef.SetIsEmpty(AValue: boolean);
  4058. begin
  4059. if AValue then
  4060. include(implprocoptions,pio_empty)
  4061. else
  4062. include(implprocoptions,pio_empty);
  4063. end;
  4064. function tprocdef.GetHasInliningInfo: boolean;
  4065. begin
  4066. result:=pio_has_inlininginfo in implprocoptions;
  4067. end;
  4068. procedure tprocdef.SetHasInliningInfo(AValue: boolean);
  4069. begin
  4070. if AValue then
  4071. include(implprocoptions,pio_has_inlininginfo)
  4072. else
  4073. exclude(implprocoptions,pio_has_inlininginfo);
  4074. end;
  4075. procedure tprocdef.Setinterfacedef(AValue: boolean);
  4076. begin
  4077. if not assigned(implprocdefinfo) then
  4078. internalerror(2014010317);
  4079. implprocdefinfo^.interfacedef:=AValue;
  4080. end;
  4081. procedure tprocdef.Setprocstarttai(AValue: tai);
  4082. begin
  4083. if not assigned(implprocdefinfo) then
  4084. internalerror(2014010318);
  4085. implprocdefinfo^.procstarttai:=AValue;
  4086. end;
  4087. procedure tprocdef.SetParentFPStruct(AValue: tsym);
  4088. begin
  4089. if not assigned(implprocdefinfo) then
  4090. internalerror(2014010319);
  4091. implprocdefinfo^.parentfpstruct:=AValue;
  4092. end;
  4093. procedure tprocdef.SetParentFPStructPtrType(AValue: tdef);
  4094. begin
  4095. if not assigned(implprocdefinfo) then
  4096. internalerror(2014010320);
  4097. implprocdefinfo^.parentfpstructptrtype:=AValue;
  4098. end;
  4099. constructor tprocdef.create(level:byte);
  4100. begin
  4101. inherited create(procdef,level);
  4102. implprocdefinfo:=allocmem(sizeof(implprocdefinfo^));
  4103. localst:=tlocalsymtable.create(self,parast.symtablelevel);
  4104. {$ifdef symansistr}
  4105. _mangledname:='';
  4106. {$else symansistr}
  4107. _mangledname:=nil;
  4108. {$endif symansistr}
  4109. fileinfo:=current_filepos;
  4110. extnumber:=$ffff;
  4111. aliasnames:=TCmdStrList.create;
  4112. funcretsym:=nil;
  4113. forwarddef:=true;
  4114. interfacedef:=false;
  4115. hasforward:=false;
  4116. struct := nil;
  4117. import_dll:=nil;
  4118. import_name:=nil;
  4119. import_nr:=0;
  4120. inlininginfo:=nil;
  4121. deprecatedmsg:=nil;
  4122. end;
  4123. constructor tprocdef.ppuload(ppufile:tcompilerppufile);
  4124. var
  4125. i,aliasnamescount : longint;
  4126. level : byte;
  4127. begin
  4128. inherited ppuload(procdef,ppufile);
  4129. {$ifdef symansistr}
  4130. if po_has_mangledname in procoptions then
  4131. _mangledname:=ppufile.getansistring
  4132. else
  4133. _mangledname:='';
  4134. {$else symansistr}
  4135. if po_has_mangledname in procoptions then
  4136. _mangledname:=stringdup(ppufile.getstring)
  4137. else
  4138. _mangledname:=nil;
  4139. {$endif symansistr}
  4140. extnumber:=ppufile.getword;
  4141. level:=ppufile.getbyte;
  4142. ppufile.getderef(structderef);
  4143. ppufile.getderef(procsymderef);
  4144. ppufile.getposinfo(fileinfo);
  4145. visibility:=tvisibility(ppufile.getbyte);
  4146. ppufile.getsmallset(symoptions);
  4147. if sp_has_deprecated_msg in symoptions then
  4148. deprecatedmsg:=stringdup(ppufile.getstring)
  4149. else
  4150. deprecatedmsg:=nil;
  4151. synthetickind:=tsynthetickind(ppufile.getbyte);
  4152. { import stuff }
  4153. if po_has_importdll in procoptions then
  4154. import_dll:=stringdup(ppufile.getstring)
  4155. else
  4156. import_dll:=nil;
  4157. if po_has_importname in procoptions then
  4158. import_name:=stringdup(ppufile.getstring)
  4159. else
  4160. import_name:=nil;
  4161. import_nr:=ppufile.getword;
  4162. if (po_msgint in procoptions) then
  4163. messageinf.i:=ppufile.getlongint;
  4164. if (po_msgstr in procoptions) then
  4165. messageinf.str:=stringdup(ppufile.getstring);
  4166. if (po_dispid in procoptions) then
  4167. dispid:=ppufile.getlongint;
  4168. { inline stuff }
  4169. ppufile.getsmallset(implprocoptions);
  4170. if has_inlininginfo then
  4171. begin
  4172. ppufile.getderef(funcretsymderef);
  4173. new(inlininginfo);
  4174. ppufile.getsmallset(inlininginfo^.flags);
  4175. end
  4176. else
  4177. begin
  4178. inlininginfo:=nil;
  4179. funcretsym:=nil;
  4180. end;
  4181. aliasnames:=TCmdStrList.create;
  4182. { count alias names }
  4183. aliasnamescount:=ppufile.getbyte;
  4184. for i:=1 to aliasnamescount do
  4185. aliasnames.insert(ppufile.getstring);
  4186. ppuload_platform(ppufile);
  4187. { load para symtable }
  4188. parast:=tparasymtable.create(self,level);
  4189. tparasymtable(parast).ppuload(ppufile);
  4190. { load local symtable }
  4191. if has_inlininginfo then
  4192. begin
  4193. localst:=tlocalsymtable.create(self,level);
  4194. tlocalsymtable(localst).ppuload(ppufile);
  4195. end
  4196. else
  4197. localst:=nil;
  4198. { inline stuff }
  4199. if has_inlininginfo then
  4200. inlininginfo^.code:=ppuloadnodetree(ppufile);
  4201. { default values for no persistent data }
  4202. if (cs_link_deffile in current_settings.globalswitches) and
  4203. (tf_need_export in target_info.flags) and
  4204. (po_exports in procoptions) then
  4205. deffile.AddExport(mangledname);
  4206. { Disable po_has_inlining until the derefimpl is done }
  4207. has_inlininginfo:=false;
  4208. end;
  4209. destructor tprocdef.destroy;
  4210. begin
  4211. aliasnames.free;
  4212. aliasnames:=nil;
  4213. if assigned(localst) and
  4214. (localst.symtabletype<>staticsymtable) then
  4215. begin
  4216. {$ifdef MEMDEBUG}
  4217. memproclocalst.start;
  4218. {$endif MEMDEBUG}
  4219. localst.free;
  4220. localst:=nil;
  4221. {$ifdef MEMDEBUG}
  4222. memproclocalst.start;
  4223. {$endif MEMDEBUG}
  4224. end;
  4225. if assigned(inlininginfo) then
  4226. begin
  4227. {$ifdef MEMDEBUG}
  4228. memprocnodetree.start;
  4229. {$endif MEMDEBUG}
  4230. tnode(inlininginfo^.code).free;
  4231. {$ifdef MEMDEBUG}
  4232. memprocnodetree.start;
  4233. {$endif MEMDEBUG}
  4234. dispose(inlininginfo);
  4235. inlininginfo:=nil;
  4236. end;
  4237. if assigned(implprocdefinfo) then
  4238. begin
  4239. stringdispose(implprocdefinfo^.resultname);
  4240. freemem(implprocdefinfo);
  4241. implprocdefinfo:=nil;
  4242. end;
  4243. stringdispose(import_dll);
  4244. stringdispose(import_name);
  4245. stringdispose(deprecatedmsg);
  4246. if (po_msgstr in procoptions) then
  4247. stringdispose(messageinf.str);
  4248. {$ifndef symansistr}
  4249. if assigned(_mangledname) then
  4250. begin
  4251. {$ifdef MEMDEBUG}
  4252. memmanglednames.start;
  4253. {$endif MEMDEBUG}
  4254. stringdispose(_mangledname);
  4255. {$ifdef MEMDEBUG}
  4256. memmanglednames.stop;
  4257. {$endif MEMDEBUG}
  4258. end;
  4259. {$endif symansistr}
  4260. inherited destroy;
  4261. end;
  4262. procedure tprocdef.ppuwrite(ppufile:tcompilerppufile);
  4263. var
  4264. oldintfcrc : boolean;
  4265. aliasnamescount : longint;
  4266. item : TCmdStrListItem;
  4267. begin
  4268. { released procdef? }
  4269. if not assigned(parast) then
  4270. exit;
  4271. inherited ppuwrite(ppufile);
  4272. {$ifdef symansistr}
  4273. if po_has_mangledname in procoptions then
  4274. ppufile.putansistring(_mangledname);
  4275. {$else symansistr}
  4276. if po_has_mangledname in procoptions then
  4277. ppufile.putstring(_mangledname^);
  4278. {$endif symansistr}
  4279. ppufile.putword(extnumber);
  4280. ppufile.putbyte(parast.symtablelevel);
  4281. ppufile.putderef(structderef);
  4282. ppufile.putderef(procsymderef);
  4283. ppufile.putposinfo(fileinfo);
  4284. ppufile.putbyte(byte(visibility));
  4285. ppufile.putsmallset(symoptions);
  4286. if sp_has_deprecated_msg in symoptions then
  4287. ppufile.putstring(deprecatedmsg^);
  4288. ppufile.putbyte(byte(synthetickind));
  4289. { import }
  4290. if po_has_importdll in procoptions then
  4291. ppufile.putstring(import_dll^);
  4292. if po_has_importname in procoptions then
  4293. ppufile.putstring(import_name^);
  4294. ppufile.putword(import_nr);
  4295. if (po_msgint in procoptions) then
  4296. ppufile.putlongint(messageinf.i);
  4297. if (po_msgstr in procoptions) then
  4298. ppufile.putstring(messageinf.str^);
  4299. if (po_dispid in procoptions) then
  4300. ppufile.putlongint(dispid);
  4301. { inline stuff }
  4302. oldintfcrc:=ppufile.do_crc;
  4303. ppufile.do_crc:=false;
  4304. ppufile.putsmallset(implprocoptions);
  4305. if has_inlininginfo then
  4306. begin
  4307. ppufile.putderef(funcretsymderef);
  4308. ppufile.putsmallset(inlininginfo^.flags);
  4309. end;
  4310. { count alias names }
  4311. aliasnamescount:=0;
  4312. item:=TCmdStrListItem(aliasnames.first);
  4313. while assigned(item) do
  4314. begin
  4315. inc(aliasnamescount);
  4316. item:=TCmdStrListItem(item.next);
  4317. end;
  4318. if aliasnamescount>255 then
  4319. internalerror(200711021);
  4320. ppufile.putbyte(aliasnamescount);
  4321. item:=TCmdStrListItem(aliasnames.first);
  4322. while assigned(item) do
  4323. begin
  4324. ppufile.putstring(item.str);
  4325. item:=TCmdStrListItem(item.next);
  4326. end;
  4327. ppufile.do_crc:=oldintfcrc;
  4328. { write this entry }
  4329. writeentry(ppufile,ibprocdef);
  4330. { Save the para symtable, this is taken from the interface }
  4331. tparasymtable(parast).ppuwrite(ppufile);
  4332. { save localsymtable for inline procedures or when local
  4333. browser info is requested, this has no influence on the crc }
  4334. if has_inlininginfo then
  4335. begin
  4336. oldintfcrc:=ppufile.do_crc;
  4337. ppufile.do_crc:=false;
  4338. tlocalsymtable(localst).ppuwrite(ppufile);
  4339. ppufile.do_crc:=oldintfcrc;
  4340. end;
  4341. { node tree for inlining }
  4342. oldintfcrc:=ppufile.do_crc;
  4343. ppufile.do_crc:=false;
  4344. if has_inlininginfo then
  4345. ppuwritenodetree(ppufile,inlininginfo^.code);
  4346. ppufile.do_crc:=oldintfcrc;
  4347. end;
  4348. function tprocdef.fullprocname(showhidden:boolean):string;
  4349. var
  4350. pno: tprocnameoptions;
  4351. begin
  4352. pno:=[];
  4353. if showhidden then
  4354. include(pno,pno_showhidden);
  4355. result:=customprocname(pno);
  4356. end;
  4357. function tprocdef.customprocname(pno: tprocnameoptions):ansistring;
  4358. var
  4359. s, rn : ansistring;
  4360. t : ttoken;
  4361. begin
  4362. {$ifdef EXTDEBUG}
  4363. include(pno,pno_showhidden);
  4364. {$endif EXTDEBUG}
  4365. s:='';
  4366. if proctypeoption=potype_operator then
  4367. begin
  4368. for t:=NOTOKEN to last_overloaded do
  4369. if procsym.realname='$'+overloaded_names[t] then
  4370. begin
  4371. s:='operator ';
  4372. if (pno_ownername in pno) and
  4373. assigned(struct) then
  4374. s:=s+struct.RttiName+'.';
  4375. s:=s+arraytokeninfo[t].str+typename_paras(pno);
  4376. break;
  4377. end;
  4378. end
  4379. else
  4380. begin
  4381. if (po_classmethod in procoptions) and
  4382. not(pno_noclassmarker in pno) then
  4383. s:='class ';
  4384. case proctypeoption of
  4385. potype_constructor,
  4386. potype_class_constructor:
  4387. s:=s+'constructor ';
  4388. potype_class_destructor,
  4389. potype_destructor:
  4390. s:=s+'destructor ';
  4391. else
  4392. if (pno_proctypeoption in pno) then
  4393. begin
  4394. if assigned(returndef) and
  4395. not(is_void(returndef)) then
  4396. s:=s+'function '
  4397. else
  4398. s:=s+'procedure ';
  4399. end;
  4400. end;
  4401. if (pno_ownername in pno) and
  4402. (owner.symtabletype in [recordsymtable,objectsymtable]) then
  4403. s:=s+tabstractrecorddef(owner.defowner).RttiName+'.';
  4404. rn:=procsym.realname;
  4405. if (pno_noleadingdollar in pno) and
  4406. (rn[1]='$') then
  4407. delete(rn,1,1);
  4408. s:=s+rn+typename_paras(pno);
  4409. end;
  4410. if not(proctypeoption in [potype_constructor,potype_destructor,
  4411. potype_class_constructor,potype_class_destructor]) and
  4412. assigned(returndef) and
  4413. not(is_void(returndef)) then
  4414. s:=s+':'+returndef.GetTypeName;
  4415. if owner.symtabletype=localsymtable then
  4416. s:=s+' is nested';
  4417. s:=s+';';
  4418. { forced calling convention? }
  4419. if (po_hascallingconvention in procoptions) then
  4420. s:=s+' '+ProcCallOptionStr[proccalloption]+';';
  4421. if (po_staticmethod in procoptions) and
  4422. not (proctypeoption in [potype_class_constructor,potype_class_destructor]) then
  4423. s:=s+' Static;';
  4424. if pno_mangledname in pno then
  4425. s:=s+' -- mangled name: '+mangledname;
  4426. customprocname:=s;
  4427. end;
  4428. function tprocdef.is_methodpointer:boolean;
  4429. begin
  4430. { don't check assigned(_class), that's also the case for nested
  4431. procedures inside methods }
  4432. result:=(owner.symtabletype=ObjectSymtable)and not no_self_node;
  4433. end;
  4434. function tprocdef.is_addressonly:boolean;
  4435. begin
  4436. result:=assigned(owner) and
  4437. not is_methodpointer and
  4438. (not(m_nested_procvars in current_settings.modeswitches) or
  4439. not is_nested_pd(self));
  4440. end;
  4441. procedure tprocdef.make_external;
  4442. begin
  4443. include(procoptions,po_external);
  4444. forwarddef:=false;
  4445. end;
  4446. function tprocdef.GetSymtable(t:tGetSymtable):TSymtable;
  4447. begin
  4448. case t of
  4449. gs_local :
  4450. GetSymtable:=localst;
  4451. gs_para :
  4452. GetSymtable:=parast;
  4453. else
  4454. GetSymtable:=nil;
  4455. end;
  4456. end;
  4457. function tprocdef.getcopyas(newtyp: tdeftyp; copytyp: tproccopytyp): tstoreddef;
  4458. var
  4459. j : longint;
  4460. begin
  4461. result:=inherited getcopyas(newtyp,copytyp);
  4462. if newtyp=procvardef then
  4463. exit;
  4464. { don't copy mangled name, can be different }
  4465. tprocdef(result).messageinf:=messageinf;
  4466. tprocdef(result).dispid:=dispid;
  4467. if po_msgstr in procoptions then
  4468. tprocdef(result).messageinf.str:=stringdup(messageinf.str^);
  4469. tprocdef(result).symoptions:=symoptions;
  4470. if assigned(deprecatedmsg) then
  4471. tprocdef(result).deprecatedmsg:=stringdup(deprecatedmsg^);
  4472. { will have to be associated with appropriate procsym }
  4473. tprocdef(result).procsym:=nil;
  4474. if copytyp<>pc_bareproc then
  4475. tprocdef(result).aliasnames.concatListcopy(aliasnames);
  4476. if assigned(funcretsym) then
  4477. begin
  4478. if funcretsym.owner=parast then
  4479. begin
  4480. j:=parast.symlist.indexof(funcretsym);
  4481. if j<0 then
  4482. internalerror(2011040606);
  4483. tprocdef(result).funcretsym:=tsym(tprocdef(result).parast.symlist[j]);
  4484. end
  4485. else if funcretsym.owner=localst then
  4486. begin
  4487. { nothing to do, will be inserted for the new procdef while
  4488. parsing its body (by pdecsub.insert_funcret_local) }
  4489. end
  4490. else
  4491. internalerror(2011040605);
  4492. end;
  4493. { will have to be associated with a new struct }
  4494. tprocdef(result).struct:=nil;
  4495. if assigned(implprocdefinfo) then
  4496. begin
  4497. if assigned(resultname) then
  4498. tprocdef(result).resultname:=stringdup(resultname^);
  4499. end;
  4500. if assigned(import_dll) then
  4501. tprocdef(result).import_dll:=stringdup(import_dll^);
  4502. if assigned(import_name) then
  4503. tprocdef(result).import_name:=stringdup(import_name^);
  4504. tprocdef(result).import_nr:=import_nr;
  4505. tprocdef(result).extnumber:=$ffff;
  4506. tprocdef(result).visibility:=visibility;
  4507. tprocdef(result).synthetickind:=synthetickind;
  4508. { we need a separate implementation for the copied def }
  4509. tprocdef(result).forwarddef:=true;
  4510. tprocdef(result).interfacedef:=true;
  4511. { create new paralist }
  4512. tprocdef(result).calcparas;
  4513. end;
  4514. function tprocdef.getcopy: tstoreddef;
  4515. begin
  4516. result:=getcopyas(procdef,pc_normal);
  4517. end;
  4518. procedure tprocdef.buildderef;
  4519. begin
  4520. inherited buildderef;
  4521. structderef.build(struct);
  4522. { procsym that originaly defined this definition, should be in the
  4523. same symtable }
  4524. procsymderef.build(procsym);
  4525. end;
  4526. procedure tprocdef.buildderefimpl;
  4527. begin
  4528. inherited buildderefimpl;
  4529. { inline tree }
  4530. if has_inlininginfo then
  4531. begin
  4532. { Localst is not available for main/unit init }
  4533. if assigned(localst) then
  4534. begin
  4535. tlocalsymtable(localst).buildderef;
  4536. tlocalsymtable(localst).buildderefimpl;
  4537. end;
  4538. funcretsymderef.build(funcretsym);
  4539. inlininginfo^.code.buildderefimpl;
  4540. end;
  4541. end;
  4542. procedure tprocdef.deref;
  4543. begin
  4544. inherited deref;
  4545. struct:=tabstractrecorddef(structderef.resolve);
  4546. { procsym that originaly defined this definition, should be in the
  4547. same symtable }
  4548. procsym:=tprocsym(procsymderef.resolve);
  4549. end;
  4550. procedure tprocdef.derefimpl;
  4551. begin
  4552. { Enable has_inlininginfo when the inlininginfo
  4553. structure is available. The has_inlininginfo was disabled
  4554. after the load, since the data was invalid }
  4555. if assigned(inlininginfo) then
  4556. has_inlininginfo:=true;
  4557. { Inline }
  4558. if has_inlininginfo then
  4559. begin
  4560. { Locals }
  4561. if assigned(localst) then
  4562. begin
  4563. tlocalsymtable(localst).deref;
  4564. tlocalsymtable(localst).derefimpl;
  4565. end;
  4566. inlininginfo^.code.derefimpl;
  4567. { funcretsym, this is always located in the localst }
  4568. funcretsym:=tsym(funcretsymderef.resolve);
  4569. end
  4570. else
  4571. begin
  4572. { safety }
  4573. { Not safe! A unit may be reresolved after its interface has been
  4574. parsed but before its implementation has been parsed, and in that
  4575. case the funcretsym is still required!
  4576. funcretsym:=nil; }
  4577. end;
  4578. end;
  4579. function tprocdef.GetTypeName : string;
  4580. begin
  4581. GetTypeName := FullProcName(false);
  4582. end;
  4583. function tprocdef.mangledname : TSymStr;
  4584. begin
  4585. {$ifdef symansistr}
  4586. if _mangledname='' then
  4587. begin
  4588. result:=defaultmangledname;
  4589. _mangledname:=result;
  4590. end
  4591. else
  4592. result:=_mangledname;
  4593. {$else symansistr}
  4594. if not assigned(_mangledname) then
  4595. begin
  4596. result:=defaultmangledname;
  4597. _mangledname:=stringdup(mangledname);
  4598. end
  4599. else
  4600. result:=_mangledname^;
  4601. {$endif symansistr}
  4602. end;
  4603. function tprocdef.defaultmangledname: TSymStr;
  4604. var
  4605. hp : TParavarsym;
  4606. hs : TSymStr;
  4607. crc : dword;
  4608. newlen,
  4609. oldlen,
  4610. i : integer;
  4611. begin
  4612. hp:=nil;
  4613. { we need to use the symtable where the procsym is inserted,
  4614. because that is visible to the world }
  4615. defaultmangledname:=make_mangledname('',procsym.owner,procsym.name);
  4616. oldlen:=length(defaultmangledname);
  4617. { add parameter types }
  4618. for i:=0 to paras.count-1 do
  4619. begin
  4620. hp:=tparavarsym(paras[i]);
  4621. if not(vo_is_hidden_para in hp.varoptions) then
  4622. defaultmangledname:=defaultmangledname+'$'+hp.vardef.mangledparaname;
  4623. end;
  4624. { add resultdef, add $$ as separator to make it unique from a
  4625. parameter separator }
  4626. if not is_void(returndef) then
  4627. defaultmangledname:=defaultmangledname+'$$'+returndef.mangledparaname;
  4628. newlen:=length(defaultmangledname);
  4629. { Replace with CRC if the parameter line is very long }
  4630. if (newlen-oldlen>12) and
  4631. ((newlen>100) or (newlen-oldlen>64)) then
  4632. begin
  4633. crc:=0;
  4634. for i:=0 to paras.count-1 do
  4635. begin
  4636. hp:=tparavarsym(paras[i]);
  4637. if not(vo_is_hidden_para in hp.varoptions) then
  4638. begin
  4639. hs:=hp.vardef.mangledparaname;
  4640. crc:=UpdateCrc32(crc,hs[1],length(hs));
  4641. end;
  4642. end;
  4643. hs:=hp.vardef.mangledparaname;
  4644. crc:=UpdateCrc32(crc,hs[1],length(hs));
  4645. defaultmangledname:=Copy(defaultmangledname,1,oldlen)+'$crc'+hexstr(crc,8);
  4646. end;
  4647. end;
  4648. function tprocdef.cplusplusmangledname : TSymStr;
  4649. function getcppparaname(p : tdef) : TSymStr;
  4650. const
  4651. {$ifdef NAMEMANGLING_GCC2}
  4652. ordtype2str : array[tordtype] of string[2] = (
  4653. '',
  4654. 'Uc','Us','Ui','Us',
  4655. 'Sc','s','i','x',
  4656. 'b','b','b','b','b',
  4657. 'c','w','x');
  4658. {$else NAMEMANGLING_GCC2}
  4659. ordtype2str : array[tordtype] of string[1] = (
  4660. 'v',
  4661. 'h','t','j','y',
  4662. 'a','s','i','x',
  4663. 'b','b','b','b',
  4664. 'b','b','b','b',
  4665. 'c','w','x');
  4666. floattype2str : array[tfloattype] of string[1] = (
  4667. 'f','d','e','e',
  4668. 'd','d','g');
  4669. {$endif NAMEMANGLING_GCC2}
  4670. var
  4671. s : TSymStr;
  4672. begin
  4673. case p.typ of
  4674. orddef:
  4675. s:=ordtype2str[torddef(p).ordtype];
  4676. pointerdef:
  4677. s:='P'+getcppparaname(tpointerdef(p).pointeddef);
  4678. {$ifndef NAMEMANGLING_GCC2}
  4679. floatdef:
  4680. s:=floattype2str[tfloatdef(p).floattype];
  4681. {$endif NAMEMANGLING_GCC2}
  4682. else
  4683. internalerror(2103001);
  4684. end;
  4685. getcppparaname:=s;
  4686. end;
  4687. var
  4688. s,s2 : TSymStr;
  4689. hp : TParavarsym;
  4690. i : integer;
  4691. begin
  4692. {$ifdef NAMEMANGLING_GCC2}
  4693. { outdated gcc 2.x name mangling scheme }
  4694. s := procsym.realname;
  4695. if procsym.owner.symtabletype=ObjectSymtable then
  4696. begin
  4697. s2:=upper(tobjectdef(procsym.owner.defowner).objrealname^);
  4698. case proctypeoption of
  4699. potype_destructor:
  4700. s:='_$_'+tostr(length(s2))+s2;
  4701. potype_constructor:
  4702. s:='___'+tostr(length(s2))+s2;
  4703. else
  4704. s:='_'+s+'__'+tostr(length(s2))+s2;
  4705. end;
  4706. end
  4707. else s:=s+'__';
  4708. s:=s+'F';
  4709. { concat modifiers }
  4710. { !!!!! }
  4711. { now we handle the parameters }
  4712. if maxparacount>0 then
  4713. begin
  4714. for i:=0 to paras.count-1 do
  4715. begin
  4716. hp:=tparavarsym(paras[i]);
  4717. { no hidden parameters form part of a C++ mangled name:
  4718. a) self is not included
  4719. b) there are no "high" or other hidden parameters
  4720. }
  4721. if vo_is_hidden_para in hp.varoptions then
  4722. continue;
  4723. s2:=getcppparaname(hp.vardef);
  4724. if hp.varspez in [vs_var,vs_out] then
  4725. s2:='R'+s2;
  4726. s:=s+s2;
  4727. end;
  4728. end
  4729. else
  4730. s:=s+'v';
  4731. cplusplusmangledname:=s;
  4732. {$else NAMEMANGLING_GCC2}
  4733. { gcc 3.x and 4.x name mangling scheme }
  4734. { see http://www.codesourcery.com/public/cxx-abi/abi.html#mangling }
  4735. if procsym.owner.symtabletype=ObjectSymtable then
  4736. begin
  4737. s:='_ZN';
  4738. s2:=tobjectdef(procsym.owner.defowner).objextname^;
  4739. s:=s+tostr(length(s2))+s2;
  4740. case proctypeoption of
  4741. potype_constructor:
  4742. s:=s+'C1';
  4743. potype_destructor:
  4744. s:=s+'D1';
  4745. else
  4746. s:=s+tostr(length(procsym.realname))+procsym.realname;
  4747. end;
  4748. s:=s+'E';
  4749. end
  4750. else
  4751. s:=procsym.realname;
  4752. { now we handle the parameters }
  4753. if maxparacount>0 then
  4754. begin
  4755. for i:=0 to paras.count-1 do
  4756. begin
  4757. hp:=tparavarsym(paras[i]);
  4758. { no hidden parameters form part of a C++ mangled name:
  4759. a) self is not included
  4760. b) there are no "high" or other hidden parameters
  4761. }
  4762. if vo_is_hidden_para in hp.varoptions then
  4763. continue;
  4764. s2:=getcppparaname(hp.vardef);
  4765. if hp.varspez in [vs_var,vs_out] then
  4766. s2:='R'+s2;
  4767. s:=s+s2;
  4768. end;
  4769. end
  4770. else
  4771. s:=s+'v';
  4772. cplusplusmangledname:=s;
  4773. {$endif NAMEMANGLING_GCC2}
  4774. end;
  4775. function tprocdef.objcmangledname : TSymStr;
  4776. var
  4777. manglednamelen: longint;
  4778. iscatmethod : boolean;
  4779. begin
  4780. if not (po_msgstr in procoptions) then
  4781. internalerror(2009030901);
  4782. { we may very well need longer strings to handle these... }
  4783. manglednamelen:=length(tobjectdef(procsym.owner.defowner).objextname^)+
  4784. length('+"[ ]"')+length(messageinf.str^);
  4785. iscatmethod:=oo_is_classhelper in tobjectdef(procsym.owner.defowner).objectoptions;
  4786. if (iscatmethod) then
  4787. inc(manglednamelen,length(tobjectdef(procsym.owner.defowner).childof.objextname^)+length('()'));
  4788. if manglednamelen>255 then
  4789. Message1(parser_e_objc_message_name_too_long,messageinf.str^);
  4790. if not(po_classmethod in procoptions) then
  4791. result:='"-['
  4792. else
  4793. result:='"+[';
  4794. { quotes are necessary because the +/- otherwise confuse the assembler
  4795. into expecting a number
  4796. }
  4797. if iscatmethod then
  4798. result:=result+tobjectdef(procsym.owner.defowner).childof.objextname^+'(';
  4799. result:=result+tobjectdef(procsym.owner.defowner).objextname^;
  4800. if iscatmethod then
  4801. result:=result+')';
  4802. result:=result+' '+messageinf.str^+']"';
  4803. end;
  4804. procedure tprocdef.setmangledname(const s : TSymStr);
  4805. begin
  4806. { This is not allowed anymore, the forward declaration
  4807. already needs to create the correct mangledname, no changes
  4808. afterwards are allowed (PFV) }
  4809. { Exception: interface definitions in mode macpas, since in that }
  4810. { case no reference to the old name can exist yet (JM) }
  4811. {$ifdef symansistr}
  4812. if _mangledname<>'' then
  4813. if ((m_mac in current_settings.modeswitches) and
  4814. (interfacedef)) then
  4815. _mangledname:=''
  4816. else
  4817. internalerror(200411171);
  4818. {$else symansistr}
  4819. if assigned(_mangledname) then
  4820. if ((m_mac in current_settings.modeswitches) and
  4821. (interfacedef)) then
  4822. stringdispose(_mangledname)
  4823. else
  4824. internalerror(200411171);
  4825. {$endif symansistr}
  4826. {$ifdef jvm}
  4827. { this routine can be called for compilerproces. can't set mangled
  4828. name since it must be calculated, but it uses import_name when set
  4829. -> set that one }
  4830. import_name:=stringdup(s);
  4831. include(procoptions,po_has_importname);
  4832. include(procoptions,po_has_mangledname);
  4833. {$else}
  4834. {$ifdef symansistr}
  4835. _mangledname:=s;
  4836. {$else symansistr}
  4837. _mangledname:=stringdup(s);
  4838. {$endif symansistr}
  4839. {$endif jvm}
  4840. include(procoptions,po_has_mangledname);
  4841. end;
  4842. {***************************************************************************
  4843. TPROCVARDEF
  4844. ***************************************************************************}
  4845. constructor tprocvardef.create(level:byte);
  4846. begin
  4847. inherited create(procvardef,level);
  4848. end;
  4849. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  4850. begin
  4851. inherited ppuload(procvardef,ppufile);
  4852. { load para symtable }
  4853. parast:=tparasymtable.create(self,ppufile.getbyte);
  4854. ppuload_platform(ppufile);
  4855. tparasymtable(parast).ppuload(ppufile);
  4856. end;
  4857. function tprocvardef.getcopy : tstoreddef;
  4858. var
  4859. i : tcallercallee;
  4860. j : longint;
  4861. begin
  4862. result:=cprocvardef.create(parast.symtablelevel);
  4863. tprocvardef(result).returndef:=returndef;
  4864. tprocvardef(result).returndefderef:=returndefderef;
  4865. tprocvardef(result).parast:=parast.getcopy;
  4866. tprocvardef(result).savesize:=savesize;
  4867. { create paralist copy }
  4868. calcparas;
  4869. tprocvardef(result).paras:=tparalist.create(false);
  4870. tprocvardef(result).paras.count:=paras.count;
  4871. for j:=0 to paras.count-1 do
  4872. tprocvardef(result).paras[j]:=paras[j];
  4873. tprocvardef(result).proctypeoption:=proctypeoption;
  4874. tprocvardef(result).proccalloption:=proccalloption;
  4875. tprocvardef(result).procoptions:=procoptions;
  4876. tprocvardef(result).callerargareasize:=callerargareasize;
  4877. tprocvardef(result).calleeargareasize:=calleeargareasize;
  4878. tprocvardef(result).maxparacount:=maxparacount;
  4879. tprocvardef(result).minparacount:=minparacount;
  4880. for i:=low(tcallercallee) to high(tcallercallee) do
  4881. tprocvardef(result).funcretloc[i]:=funcretloc[i].getcopy;
  4882. tprocvardef(result).has_paraloc_info:=has_paraloc_info;
  4883. {$ifdef m68k}
  4884. tprocvardef(result).exp_funcretloc:=exp_funcretloc;
  4885. {$endif}
  4886. end;
  4887. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  4888. begin
  4889. inherited ppuwrite(ppufile);
  4890. { Save the para symtable level (necessary to distinguish nested
  4891. procvars) }
  4892. ppufile.putbyte(parast.symtablelevel);
  4893. { Write this entry }
  4894. writeentry(ppufile,ibprocvardef);
  4895. { Save the para symtable, this is taken from the interface }
  4896. tparasymtable(parast).ppuwrite(ppufile);
  4897. end;
  4898. function tprocvardef.GetSymtable(t:tGetSymtable):TSymtable;
  4899. begin
  4900. case t of
  4901. gs_para :
  4902. GetSymtable:=parast;
  4903. else
  4904. GetSymtable:=nil;
  4905. end;
  4906. end;
  4907. function tprocvardef.size : asizeint;
  4908. var
  4909. far_code_extra_bytes: integer = 0;
  4910. begin
  4911. {$ifdef i8086}
  4912. if po_far in procoptions then
  4913. far_code_extra_bytes:=2;
  4914. {$endif i8086}
  4915. if ((po_methodpointer in procoptions) or
  4916. is_nested_pd(self)) and
  4917. not(po_addressonly in procoptions) then
  4918. size:=sizeof(pint)+far_code_extra_bytes+voidpointertype.size
  4919. else
  4920. size:=sizeof(pint)+far_code_extra_bytes;
  4921. end;
  4922. function tprocvardef.is_methodpointer:boolean;
  4923. begin
  4924. result:=(po_methodpointer in procoptions);
  4925. end;
  4926. function tprocvardef.is_addressonly:boolean;
  4927. begin
  4928. result:=(not(po_methodpointer in procoptions) and
  4929. not is_nested_pd(self)) or
  4930. (po_addressonly in procoptions);
  4931. end;
  4932. function tprocvardef.getmangledparaname:TSymStr;
  4933. begin
  4934. if not(po_methodpointer in procoptions) then
  4935. if not is_nested_pd(self) then
  4936. result:='procvar'
  4937. else
  4938. result:='nestedprovar'
  4939. else
  4940. result:='procvarofobj'
  4941. end;
  4942. function tprocvardef.is_publishable : boolean;
  4943. begin
  4944. is_publishable:=(po_methodpointer in procoptions);
  4945. end;
  4946. function tprocvardef.GetTypeName : string;
  4947. var
  4948. s: string;
  4949. pno : tprocnameoptions;
  4950. begin
  4951. {$ifdef EXTDEBUG}
  4952. pno:=[pno_showhidden];
  4953. {$else EXTDEBUG}
  4954. pno:=[];
  4955. {$endif EXTDEBUG}
  4956. s:='<';
  4957. if po_classmethod in procoptions then
  4958. s := s+'class method type of'
  4959. else
  4960. if po_addressonly in procoptions then
  4961. s := s+'address of'
  4962. else
  4963. s := s+'procedure variable type of';
  4964. if assigned(returndef) and
  4965. (returndef<>voidtype) then
  4966. s:=s+' function'+typename_paras(pno)+':'+returndef.GetTypeName
  4967. else
  4968. s:=s+' procedure'+typename_paras(pno);
  4969. if po_methodpointer in procoptions then
  4970. s := s+' of object';
  4971. if is_nested_pd(self) then
  4972. s := s+' is nested';
  4973. GetTypeName := s+';'+ProcCallOptionStr[proccalloption]+'>';
  4974. end;
  4975. {***************************************************************************
  4976. TOBJECTDEF
  4977. ***************************************************************************}
  4978. constructor tobjectdef.create(ot:tobjecttyp;const n:string;c:tobjectdef);
  4979. begin
  4980. inherited create(n,objectdef);
  4981. fcurrent_dispid:=0;
  4982. objecttype:=ot;
  4983. childof:=nil;
  4984. if objecttype=odt_helper then
  4985. owner.includeoption(sto_has_helper);
  4986. symtable:=tObjectSymtable.create(self,n,current_settings.packrecords);
  4987. { create space for vmt !! }
  4988. vmtentries:=TFPList.Create;
  4989. vmt_offset:=0;
  4990. set_parent(c);
  4991. if objecttype in [odt_interfacecorba,odt_interfacecom,odt_dispinterface] then
  4992. prepareguid;
  4993. { setup implemented interfaces }
  4994. if objecttype in [odt_class,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  4995. ImplementedInterfaces:=TFPObjectList.Create(true)
  4996. else
  4997. ImplementedInterfaces:=nil;
  4998. writing_class_record_dbginfo:=false;
  4999. end;
  5000. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  5001. var
  5002. i,
  5003. implintfcount : longint;
  5004. d, getterd : tderef;
  5005. ImplIntf : TImplementedInterface;
  5006. vmtentry : pvmtentry;
  5007. begin
  5008. inherited ppuload(objectdef,ppufile);
  5009. objecttype:=tobjecttyp(ppufile.getbyte);
  5010. objextname:=stringdup(ppufile.getstring);
  5011. { only used for external Objective-C classes/protocols }
  5012. if (objextname^='') then
  5013. stringdispose(objextname);
  5014. symtable:=tObjectSymtable.create(self,objrealname^,0);
  5015. tObjectSymtable(symtable).datasize:=ppufile.getasizeint;
  5016. tObjectSymtable(symtable).paddingsize:=ppufile.getword;
  5017. tObjectSymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  5018. tObjectSymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  5019. vmt_offset:=ppufile.getlongint;
  5020. ppufile.getderef(childofderef);
  5021. { load guid }
  5022. iidstr:=nil;
  5023. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  5024. begin
  5025. new(iidguid);
  5026. ppufile.getguid(iidguid^);
  5027. iidstr:=stringdup(ppufile.getstring);
  5028. end;
  5029. abstractcnt:=ppufile.getlongint;
  5030. if objecttype=odt_helper then
  5031. ppufile.getderef(extendeddefderef);
  5032. vmtentries:=TFPList.Create;
  5033. vmtentries.count:=ppufile.getlongint;
  5034. for i:=0 to vmtentries.count-1 do
  5035. begin
  5036. ppufile.getderef(d);
  5037. new(vmtentry);
  5038. vmtentry^.procdef:=nil;
  5039. vmtentry^.procdefderef:=d;
  5040. vmtentry^.visibility:=tvisibility(ppufile.getbyte);
  5041. vmtentries[i]:=vmtentry;
  5042. end;
  5043. { load implemented interfaces }
  5044. if objecttype in [odt_class,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  5045. begin
  5046. ImplementedInterfaces:=TFPObjectList.Create(true);
  5047. implintfcount:=ppufile.getlongint;
  5048. for i:=0 to implintfcount-1 do
  5049. begin
  5050. ppufile.getderef(d);
  5051. ppufile.getderef(getterd);
  5052. ImplIntf:=TImplementedInterface.Create_deref(d,getterd);
  5053. ImplIntf.IOffset:=ppufile.getlongint;
  5054. byte(ImplIntf.IType):=ppufile.getbyte;
  5055. ImplementedInterfaces.Add(ImplIntf);
  5056. end;
  5057. end
  5058. else
  5059. ImplementedInterfaces:=nil;
  5060. if df_copied_def in defoptions then
  5061. begin
  5062. ppufile.getderef(cloneddefderef);
  5063. ppuload_platform(ppufile);
  5064. end
  5065. else
  5066. begin
  5067. ppuload_platform(ppufile);
  5068. tObjectSymtable(symtable).ppuload(ppufile);
  5069. end;
  5070. { handles the predefined class tobject }
  5071. { the last TOBJECT which is loaded gets }
  5072. { it ! }
  5073. if (childof=nil) and
  5074. (objecttype in [odt_class,odt_javaclass]) and
  5075. (objname^='TOBJECT') then
  5076. class_tobject:=self;
  5077. if (childof=nil) and
  5078. (objecttype=odt_interfacecom) then
  5079. if (objname^='IUNKNOWN') then
  5080. interface_iunknown:=self
  5081. else
  5082. if (objname^='IDISPATCH') then
  5083. interface_idispatch:=self;
  5084. if (childof=nil) and
  5085. (objecttype=odt_objcclass) and
  5086. (objname^='PROTOCOL') then
  5087. objc_protocoltype:=self;
  5088. if (objecttype=odt_javaclass) and
  5089. not(oo_is_formal in objectoptions) then
  5090. begin
  5091. if (objname^='JLOBJECT') then
  5092. java_jlobject:=self
  5093. else if (objname^='JLTHROWABLE') then
  5094. java_jlthrowable:=self
  5095. else if (objname^='FPCBASERECORDTYPE') then
  5096. java_fpcbaserecordtype:=self
  5097. else if (objname^='JLSTRING') then
  5098. java_jlstring:=self
  5099. else if (objname^='ANSISTRINGCLASS') then
  5100. java_ansistring:=self
  5101. else if (objname^='SHORTSTRINGCLASS') then
  5102. java_shortstring:=self
  5103. else if (objname^='JLENUM') then
  5104. java_jlenum:=self
  5105. else if (objname^='JUENUMSET') then
  5106. java_juenumset:=self
  5107. else if (objname^='FPCBITSET') then
  5108. java_jubitset:=self
  5109. else if (objname^='FPCBASEPROCVARTYPE') then
  5110. java_procvarbase:=self;
  5111. end;
  5112. writing_class_record_dbginfo:=false;
  5113. end;
  5114. destructor tobjectdef.destroy;
  5115. begin
  5116. if assigned(symtable) then
  5117. begin
  5118. symtable.free;
  5119. symtable:=nil;
  5120. end;
  5121. stringdispose(objextname);
  5122. stringdispose(iidstr);
  5123. if assigned(ImplementedInterfaces) then
  5124. begin
  5125. ImplementedInterfaces.free;
  5126. ImplementedInterfaces:=nil;
  5127. end;
  5128. if assigned(iidguid) then
  5129. begin
  5130. dispose(iidguid);
  5131. iidguid:=nil;
  5132. end;
  5133. if assigned(vmtentries) then
  5134. begin
  5135. resetvmtentries;
  5136. vmtentries.free;
  5137. vmtentries:=nil;
  5138. end;
  5139. if assigned(vmcallstaticinfo) then
  5140. begin
  5141. freemem(vmcallstaticinfo);
  5142. vmcallstaticinfo:=nil;
  5143. end;
  5144. inherited destroy;
  5145. end;
  5146. function tobjectdef.getcopy : tstoreddef;
  5147. var
  5148. i : longint;
  5149. begin
  5150. result:=cobjectdef.create(objecttype,objrealname^,childof);
  5151. { the constructor allocates a symtable which we release to avoid memory leaks }
  5152. tobjectdef(result).symtable.free;
  5153. tobjectdef(result).symtable:=symtable.getcopy;
  5154. if assigned(objextname) then
  5155. tobjectdef(result).objextname:=stringdup(objextname^);
  5156. if assigned(import_lib) then
  5157. tobjectdef(result).import_lib:=stringdup(import_lib^);
  5158. tobjectdef(result).objectoptions:=objectoptions;
  5159. include(tobjectdef(result).defoptions,df_copied_def);
  5160. tobjectdef(result).extendeddef:=extendeddef;
  5161. if assigned(tcinitcode) then
  5162. tobjectdef(result).tcinitcode:=tcinitcode.getcopy;
  5163. tobjectdef(result).vmt_offset:=vmt_offset;
  5164. if assigned(iidguid) then
  5165. begin
  5166. new(tobjectdef(result).iidguid);
  5167. move(iidguid^,tobjectdef(result).iidguid^,sizeof(iidguid^));
  5168. end;
  5169. if assigned(iidstr) then
  5170. tobjectdef(result).iidstr:=stringdup(iidstr^);
  5171. tobjectdef(result).abstractcnt:=abstractcnt;
  5172. if assigned(ImplementedInterfaces) then
  5173. begin
  5174. for i:=0 to ImplementedInterfaces.count-1 do
  5175. tobjectdef(result).ImplementedInterfaces.Add(TImplementedInterface(ImplementedInterfaces[i]).Getcopy);
  5176. end;
  5177. if assigned(vmtentries) then
  5178. begin
  5179. tobjectdef(result).vmtentries:=TFPList.Create;
  5180. tobjectdef(result).copyvmtentries(self);
  5181. end;
  5182. end;
  5183. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  5184. var
  5185. i : longint;
  5186. vmtentry : pvmtentry;
  5187. ImplIntf : TImplementedInterface;
  5188. old_do_indirect_crc: boolean;
  5189. begin
  5190. { if class1 in unit A changes, and class2 in unit B inherits from it
  5191. (so unit B uses unit A), then unit B with class2 will be recompiled.
  5192. However, if there is also a class3 in unit C that only depends on
  5193. unit B, then unit C will not be recompiled because nothing changed
  5194. to the interface of unit B. Nevertheless, unit C can indirectly
  5195. depend on unit A via derefs, and these must be updated -> the
  5196. indirect crc keeps track of such changes. }
  5197. old_do_indirect_crc:=ppufile.do_indirect_crc;
  5198. ppufile.do_indirect_crc:=true;
  5199. inherited ppuwrite(ppufile);
  5200. ppufile.putbyte(byte(objecttype));
  5201. if assigned(objextname) then
  5202. ppufile.putstring(objextname^)
  5203. else
  5204. ppufile.putstring('');
  5205. ppufile.putasizeint(tObjectSymtable(symtable).datasize);
  5206. ppufile.putword(tObjectSymtable(symtable).paddingsize);
  5207. ppufile.putbyte(byte(tObjectSymtable(symtable).fieldalignment));
  5208. ppufile.putbyte(byte(tObjectSymtable(symtable).recordalignment));
  5209. ppufile.putlongint(vmt_offset);
  5210. ppufile.putderef(childofderef);
  5211. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  5212. begin
  5213. ppufile.putguid(iidguid^);
  5214. ppufile.putstring(iidstr^);
  5215. end;
  5216. ppufile.putlongint(abstractcnt);
  5217. if objecttype=odt_helper then
  5218. ppufile.putderef(extendeddefderef);
  5219. ppufile.putlongint(vmtentries.count);
  5220. for i:=0 to vmtentries.count-1 do
  5221. begin
  5222. vmtentry:=pvmtentry(vmtentries[i]);
  5223. ppufile.putderef(vmtentry^.procdefderef);
  5224. ppufile.putbyte(byte(vmtentry^.visibility));
  5225. end;
  5226. if assigned(ImplementedInterfaces) then
  5227. begin
  5228. ppufile.putlongint(ImplementedInterfaces.Count);
  5229. for i:=0 to ImplementedInterfaces.Count-1 do
  5230. begin
  5231. ImplIntf:=TImplementedInterface(ImplementedInterfaces[i]);
  5232. ppufile.putderef(ImplIntf.intfdefderef);
  5233. ppufile.putderef(ImplIntf.ImplementsGetterDeref);
  5234. ppufile.putlongint(ImplIntf.Ioffset);
  5235. ppufile.putbyte(byte(ImplIntf.IType));
  5236. end;
  5237. end;
  5238. if df_copied_def in defoptions then
  5239. ppufile.putderef(cloneddefderef);
  5240. writeentry(ppufile,ibobjectdef);
  5241. if not(df_copied_def in defoptions) then
  5242. tObjectSymtable(symtable).ppuwrite(ppufile);
  5243. ppufile.do_indirect_crc:=old_do_indirect_crc;
  5244. end;
  5245. function tobjectdef.GetTypeName:string;
  5246. begin
  5247. { in this case we will go in endless recursion, because then }
  5248. { there is no tsym associated yet with the def. It can occur }
  5249. { (tests/webtbf/tw4757.pp), so for now give a generic name }
  5250. { instead of the actual type name }
  5251. if not assigned(typesym) then
  5252. result:='<Currently Parsed Class>'
  5253. else
  5254. result:=typesymbolprettyname;
  5255. end;
  5256. procedure tobjectdef.buildderef;
  5257. var
  5258. i : longint;
  5259. vmtentry : pvmtentry;
  5260. begin
  5261. inherited buildderef;
  5262. childofderef.build(childof);
  5263. if df_copied_def in defoptions then
  5264. cloneddefderef.build(symtable.defowner)
  5265. else
  5266. tstoredsymtable(symtable).buildderef;
  5267. if objecttype=odt_helper then
  5268. extendeddefderef.build(extendeddef);
  5269. for i:=0 to vmtentries.count-1 do
  5270. begin
  5271. vmtentry:=pvmtentry(vmtentries[i]);
  5272. vmtentry^.procdefderef.build(vmtentry^.procdef);
  5273. end;
  5274. if assigned(ImplementedInterfaces) then
  5275. begin
  5276. for i:=0 to ImplementedInterfaces.count-1 do
  5277. TImplementedInterface(ImplementedInterfaces[i]).buildderef;
  5278. end;
  5279. end;
  5280. procedure tobjectdef.deref;
  5281. var
  5282. i : longint;
  5283. vmtentry : pvmtentry;
  5284. begin
  5285. inherited deref;
  5286. childof:=tobjectdef(childofderef.resolve);
  5287. if df_copied_def in defoptions then
  5288. begin
  5289. cloneddef:=tobjectdef(cloneddefderef.resolve);
  5290. symtable:=cloneddef.symtable.getcopy;
  5291. end
  5292. else
  5293. tstoredsymtable(symtable).deref;
  5294. fillgenericparas(symtable);
  5295. if objecttype=odt_helper then
  5296. extendeddef:=tdef(extendeddefderef.resolve);
  5297. for i:=0 to vmtentries.count-1 do
  5298. begin
  5299. vmtentry:=pvmtentry(vmtentries[i]);
  5300. vmtentry^.procdef:=tprocdef(vmtentry^.procdefderef.resolve);
  5301. end;
  5302. if assigned(ImplementedInterfaces) then
  5303. begin
  5304. for i:=0 to ImplementedInterfaces.count-1 do
  5305. TImplementedInterface(ImplementedInterfaces[i]).deref;
  5306. end;
  5307. end;
  5308. procedure create_class_helper_for_procdef(def: tobject; arg: pointer);
  5309. var
  5310. pd: tprocdef absolute def;
  5311. st: tsymtable;
  5312. psym: tsym;
  5313. nname: TIDString;
  5314. begin
  5315. if (tdef(def).typ<>procdef) then
  5316. exit;
  5317. { pd.owner = objcclass symtable -> defowner = objcclassdef ->
  5318. owner = symtable in which objcclassdef is defined
  5319. }
  5320. st:=pd.owner.defowner.owner;
  5321. nname:=class_helper_prefix+tprocsym(pd.procsym).name;
  5322. { check for an existing procsym with our special name }
  5323. psym:=tsym(st.find(nname));
  5324. if not assigned(psym) then
  5325. begin
  5326. psym:=cprocsym.create(nname);
  5327. { avoid warning about this symbol being unused }
  5328. psym.IncRefCount;
  5329. { don't check for duplicates:
  5330. a) we checked above
  5331. b) in case we are in the implementation section of a unit, this
  5332. will also check for this symbol in the interface section
  5333. (since you normally cannot have symbols with the same name
  5334. both interface and implementation), and it's possible to
  5335. have class helpers for the same class in the interface and
  5336. in the implementation, and they cannot be merged since only
  5337. the once in the interface must be saved to the ppu/visible
  5338. from other units }
  5339. st.insert(psym,false);
  5340. end
  5341. else if (psym.typ<>procsym) then
  5342. internalerror(2009111501);
  5343. { add ourselves to this special procsym }
  5344. tprocsym(psym).procdeflist.add(def);
  5345. end;
  5346. procedure tobjectdef.buildderefimpl;
  5347. begin
  5348. inherited buildderefimpl;
  5349. if not (df_copied_def in defoptions) then
  5350. tstoredsymtable(symtable).buildderefimpl;
  5351. end;
  5352. procedure tobjectdef.derefimpl;
  5353. begin
  5354. inherited derefimpl;
  5355. if not (df_copied_def in defoptions) then
  5356. tstoredsymtable(symtable).derefimpl;
  5357. { the procdefs are not owned by the class helper procsyms, so they
  5358. are not stored/restored either -> re-add them here }
  5359. if (objecttype=odt_objcclass) or
  5360. (oo_is_classhelper in objectoptions) then
  5361. symtable.DefList.ForEachCall(@create_class_helper_for_procdef,nil);
  5362. end;
  5363. procedure tobjectdef.resetvmtentries;
  5364. var
  5365. i : longint;
  5366. begin
  5367. for i:=0 to vmtentries.Count-1 do
  5368. Dispose(pvmtentry(vmtentries[i]));
  5369. vmtentries.clear;
  5370. end;
  5371. procedure tobjectdef.copyvmtentries(objdef:tobjectdef);
  5372. var
  5373. i : longint;
  5374. vmtentry : pvmtentry;
  5375. begin
  5376. resetvmtentries;
  5377. vmtentries.count:=objdef.vmtentries.count;
  5378. for i:=0 to objdef.vmtentries.count-1 do
  5379. begin
  5380. new(vmtentry);
  5381. vmtentry^:=pvmtentry(objdef.vmtentries[i])^;
  5382. vmtentries[i]:=vmtentry;
  5383. end;
  5384. end;
  5385. function tobjectdef.getparentdef:tdef;
  5386. begin
  5387. { TODO: Remove getparentdef hack}
  5388. { With 2 forward declared classes with the child class before the
  5389. parent class the child class is written earlier to the ppu. Leaving it
  5390. possible to have a reference to the parent class for property overriding,
  5391. but the parent class still has the childof not resolved yet (PFV) }
  5392. if childof=nil then
  5393. childof:=tobjectdef(childofderef.resolve);
  5394. result:=childof;
  5395. end;
  5396. procedure tobjectdef.prepareguid;
  5397. begin
  5398. { set up guid }
  5399. if not assigned(iidguid) then
  5400. begin
  5401. new(iidguid);
  5402. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  5403. end;
  5404. { setup iidstring }
  5405. if not assigned(iidstr) then
  5406. iidstr:=stringdup(''); { default is empty string }
  5407. end;
  5408. procedure tobjectdef.set_parent( c : tobjectdef);
  5409. begin
  5410. if assigned(childof) then
  5411. exit;
  5412. childof:=c;
  5413. if not assigned(c) then
  5414. exit;
  5415. { inherit options and status }
  5416. objectoptions:=objectoptions+(c.objectoptions*inherited_objectoptions);
  5417. { initially has the same number of abstract methods as the parent }
  5418. abstractcnt:=c.abstractcnt;
  5419. { add the data of the anchestor class/object }
  5420. if (objecttype in [odt_class,odt_object,odt_objcclass,odt_javaclass]) then
  5421. begin
  5422. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize+tObjectSymtable(c.symtable).datasize;
  5423. { inherit recordalignment }
  5424. tObjectSymtable(symtable).recordalignment:=tObjectSymtable(c.symtable).recordalignment;
  5425. { if both the parent and this record use C-alignment, also inherit
  5426. the current field alignment }
  5427. if (tObjectSymtable(c.symtable).usefieldalignment=C_alignment) and
  5428. (tObjectSymtable(symtable).usefieldalignment=C_alignment) then
  5429. tObjectSymtable(symtable).fieldalignment:=tObjectSymtable(c.symtable).fieldalignment;
  5430. { the padding is not inherited for Objective-C classes (maybe not
  5431. for cppclass either?) }
  5432. if objecttype=odt_objcclass then
  5433. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize-tObjectSymtable(c.symtable).paddingsize;
  5434. if (oo_has_vmt in objectoptions) and
  5435. (oo_has_vmt in c.objectoptions) then
  5436. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize-sizeof(pint);
  5437. { if parent has a vmt field then the offset is the same for the child PM }
  5438. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  5439. begin
  5440. vmt_offset:=c.vmt_offset;
  5441. include(objectoptions,oo_has_vmt);
  5442. end;
  5443. end;
  5444. end;
  5445. procedure tobjectdef.insertvmt;
  5446. var
  5447. vs: tfieldvarsym;
  5448. begin
  5449. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  5450. exit;
  5451. if (oo_has_vmt in objectoptions) then
  5452. internalerror(12345)
  5453. else
  5454. begin
  5455. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,
  5456. tObjectSymtable(symtable).fieldalignment);
  5457. if (tf_requires_proper_alignment in target_info.flags) then
  5458. begin
  5459. { Align VMT pointer and whole object instance if target CPU requires alignment. }
  5460. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,sizeof(pint));
  5461. tObjectSymtable(symtable).alignrecord(tObjectSymtable(symtable).datasize,sizeof(pint));
  5462. end;
  5463. vs:=cfieldvarsym.create('_vptr$'+objname^,vs_value,voidpointertype,[]);
  5464. hidesym(vs);
  5465. tObjectSymtable(symtable).insert(vs);
  5466. tObjectSymtable(symtable).addfield(vs,vis_hidden);
  5467. if (tObjectSymtable(symtable).usefieldalignment<>bit_alignment) then
  5468. vmt_offset:=vs.fieldoffset
  5469. else
  5470. vmt_offset:=vs.fieldoffset div 8;
  5471. include(objectoptions,oo_has_vmt);
  5472. end;
  5473. end;
  5474. procedure tobjectdef.check_forwards;
  5475. begin
  5476. if not(objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcprotocol,odt_interfacejava]) then
  5477. inherited;
  5478. if (oo_is_forward in objectoptions) then
  5479. begin
  5480. { ok, in future, the forward can be resolved }
  5481. Message1(sym_e_class_forward_not_resolved,objrealname^);
  5482. exclude(objectoptions,oo_is_forward);
  5483. end;
  5484. end;
  5485. function tobjectdef.find_destructor: tprocdef;
  5486. var
  5487. objdef: tobjectdef;
  5488. begin
  5489. objdef:=self;
  5490. while assigned(objdef) do
  5491. begin
  5492. result:=objdef.find_procdef_bytype(potype_destructor);
  5493. if assigned(result) then
  5494. exit;
  5495. objdef:=objdef.childof;
  5496. end;
  5497. result:=nil;
  5498. end;
  5499. function tobjectdef.implements_any_interfaces: boolean;
  5500. begin
  5501. result := (ImplementedInterfaces.Count > 0) or
  5502. (assigned(childof) and childof.implements_any_interfaces);
  5503. end;
  5504. function tobjectdef.size : asizeint;
  5505. begin
  5506. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava] then
  5507. result:=voidpointertype.size
  5508. else
  5509. result:=tObjectSymtable(symtable).datasize;
  5510. end;
  5511. function tobjectdef.alignment:shortint;
  5512. begin
  5513. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava] then
  5514. alignment:=voidpointertype.size
  5515. else
  5516. alignment:=tObjectSymtable(symtable).recordalignment;
  5517. end;
  5518. function tobjectdef.vmtmethodoffset(index:longint):longint;
  5519. var
  5520. codeptrsize: Integer;
  5521. begin
  5522. {$ifdef i8086}
  5523. if current_settings.x86memorymodel in x86_far_code_models then
  5524. codeptrsize:=4
  5525. else
  5526. codeptrsize:=2;
  5527. {$else i8086}
  5528. codeptrsize:=sizeof(pint);
  5529. {$endif i8086}
  5530. { for offset of methods for classes, see rtl/inc/objpash.inc }
  5531. case objecttype of
  5532. odt_class:
  5533. { the +2*sizeof(pint) is size and -size }
  5534. vmtmethodoffset:=index*codeptrsize+10*sizeof(pint)+2*sizeof(pint);
  5535. odt_helper,
  5536. odt_objcclass,
  5537. odt_objcprotocol:
  5538. vmtmethodoffset:=0;
  5539. odt_interfacecom,odt_interfacecorba,odt_dispinterface:
  5540. vmtmethodoffset:=index*codeptrsize;
  5541. odt_javaclass,
  5542. odt_interfacejava:
  5543. { invalid }
  5544. vmtmethodoffset:=-1;
  5545. else
  5546. {$ifdef WITHDMT}
  5547. vmtmethodoffset:=index*codeptrsize+4*sizeof(pint);
  5548. {$else WITHDMT}
  5549. vmtmethodoffset:=index*codeptrsize+3*sizeof(pint);
  5550. {$endif WITHDMT}
  5551. end;
  5552. end;
  5553. function tobjectdef.vmt_mangledname : TSymStr;
  5554. begin
  5555. if not(oo_has_vmt in objectoptions) then
  5556. Message1(parser_n_object_has_no_vmt,objrealname^);
  5557. vmt_mangledname:=make_mangledname('VMT',owner,objname^);
  5558. end;
  5559. function tobjectdef.needs_inittable : boolean;
  5560. var
  5561. hp : tobjectdef;
  5562. begin
  5563. case objecttype of
  5564. odt_helper,
  5565. odt_class :
  5566. needs_inittable:=false;
  5567. odt_dispinterface,
  5568. odt_interfacecom:
  5569. needs_inittable:=true;
  5570. odt_interfacecorba:
  5571. begin
  5572. hp:=childof;
  5573. while assigned(hp) do
  5574. begin
  5575. if hp=interface_iunknown then
  5576. begin
  5577. needs_inittable:=true;
  5578. exit;
  5579. end;
  5580. hp:=hp.childof;
  5581. end;
  5582. needs_inittable:=false;
  5583. end;
  5584. odt_object:
  5585. needs_inittable:=
  5586. tObjectSymtable(symtable).needs_init_final or
  5587. (assigned(childof) and
  5588. childof.needs_inittable);
  5589. odt_cppclass,
  5590. odt_objcclass,
  5591. odt_objcprotocol,
  5592. odt_javaclass,
  5593. odt_interfacejava:
  5594. needs_inittable:=false;
  5595. else
  5596. internalerror(200108267);
  5597. end;
  5598. end;
  5599. function tobjectdef.needs_separate_initrtti : boolean;
  5600. begin
  5601. result:=not (objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface]);
  5602. end;
  5603. function tobjectdef.rtti_mangledname(rt: trttitype): string;
  5604. begin
  5605. if not(objecttype in [odt_objcclass,odt_objcprotocol]) then
  5606. result:=inherited rtti_mangledname(rt)
  5607. else
  5608. begin
  5609. { necessary in case of a dynamic array of nsobject, or
  5610. if an nsobject field appears in a record that needs
  5611. init/finalisation }
  5612. if rt=initrtti then
  5613. begin
  5614. result:=voidpointertype.rtti_mangledname(rt);
  5615. exit;
  5616. end;
  5617. if not(target_info.system in systems_objc_nfabi) then
  5618. begin
  5619. result:=target_asm.labelprefix;
  5620. case objecttype of
  5621. odt_objcclass:
  5622. begin
  5623. case rt of
  5624. objcclassrtti:
  5625. if not(oo_is_classhelper in objectoptions) then
  5626. result:=result+'_OBJC_CLASS_'
  5627. else
  5628. result:=result+'_OBJC_CATEGORY_';
  5629. objcmetartti:
  5630. if not(oo_is_classhelper in objectoptions) then
  5631. result:=result+'_OBJC_METACLASS_'
  5632. else
  5633. internalerror(2009111511);
  5634. else
  5635. internalerror(2009092302);
  5636. end;
  5637. end;
  5638. odt_objcprotocol:
  5639. result:=result+'_OBJC_PROTOCOL_';
  5640. end;
  5641. end
  5642. else
  5643. begin
  5644. case objecttype of
  5645. odt_objcclass:
  5646. begin
  5647. if (oo_is_classhelper in objectoptions) and
  5648. (rt<>objcclassrtti) then
  5649. internalerror(2009111512);
  5650. case rt of
  5651. objcclassrtti:
  5652. if not(oo_is_classhelper in objectoptions) then
  5653. result:='_OBJC_CLASS_$_'
  5654. else
  5655. result:='_OBJC_$_CATEGORY_';
  5656. objcmetartti:
  5657. result:='_OBJC_METACLASS_$_';
  5658. objcclassrortti:
  5659. result:=lower(target_asm.labelprefix)+'_OBJC_CLASS_RO_$_';
  5660. objcmetarortti:
  5661. result:=lower(target_asm.labelprefix)+'_OBJC_METACLASS_RO_$_';
  5662. else
  5663. internalerror(2009092303);
  5664. end;
  5665. end;
  5666. odt_objcprotocol:
  5667. begin
  5668. result:=lower(target_asm.labelprefix);
  5669. case rt of
  5670. objcclassrtti:
  5671. result:=result+'_OBJC_PROTOCOL_$_';
  5672. objcmetartti:
  5673. result:=result+'_OBJC_LABEL_PROTOCOL_$_';
  5674. else
  5675. internalerror(2009092501);
  5676. end;
  5677. end;
  5678. else
  5679. internalerror(2013113005);
  5680. end;
  5681. end;
  5682. result:=result+objextname^;
  5683. end;
  5684. end;
  5685. function tobjectdef.members_need_inittable : boolean;
  5686. begin
  5687. members_need_inittable:=tObjectSymtable(symtable).needs_init_final;
  5688. end;
  5689. function tobjectdef.is_publishable : boolean;
  5690. begin
  5691. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface];
  5692. end;
  5693. function tobjectdef.get_next_dispid: longint;
  5694. begin
  5695. inc(fcurrent_dispid);
  5696. result:=fcurrent_dispid;
  5697. end;
  5698. function tobjectdef.search_enumerator_get: tprocdef;
  5699. begin
  5700. result:=inherited;
  5701. if not assigned(result) and assigned(childof) then
  5702. result:=childof.search_enumerator_get;
  5703. end;
  5704. function tobjectdef.search_enumerator_move: tprocdef;
  5705. begin
  5706. result:=inherited;
  5707. if not assigned(result) and assigned(childof) then
  5708. result:=childof.search_enumerator_move;
  5709. end;
  5710. function tobjectdef.search_enumerator_current: tsym;
  5711. begin
  5712. result:=inherited;
  5713. if not assigned(result) and assigned(childof) then
  5714. result:=childof.search_enumerator_current;
  5715. end;
  5716. procedure tobjectdef.register_created_classref_type;
  5717. begin
  5718. if not classref_created_in_current_module then
  5719. begin
  5720. classref_created_in_current_module:=true;
  5721. current_module.wpoinfo.addcreatedobjtypeforclassref(self);
  5722. end;
  5723. end;
  5724. procedure tobjectdef.register_created_object_type;
  5725. begin
  5726. if not created_in_current_module then
  5727. begin
  5728. created_in_current_module:=true;
  5729. current_module.wpoinfo.addcreatedobjtype(self);
  5730. end;
  5731. end;
  5732. procedure tobjectdef.register_maybe_created_object_type;
  5733. begin
  5734. { if we know it has been created for sure, no need
  5735. to also record that it maybe can be created in
  5736. this module
  5737. }
  5738. if not (created_in_current_module) and
  5739. not (maybe_created_in_current_module) then
  5740. begin
  5741. maybe_created_in_current_module:=true;
  5742. current_module.wpoinfo.addmaybecreatedbyclassref(self);
  5743. end;
  5744. end;
  5745. procedure tobjectdef.register_vmt_call(index: longint);
  5746. begin
  5747. if (is_object(self) or is_class(self)) then
  5748. current_module.wpoinfo.addcalledvmtentry(self,index);
  5749. end;
  5750. procedure check_and_finish_msg(data: tobject; arg: pointer);
  5751. var
  5752. def: tdef absolute data;
  5753. pd: tprocdef absolute data;
  5754. i,
  5755. paracount: longint;
  5756. begin
  5757. if (def.typ=procdef) then
  5758. begin
  5759. { add all messages also under a dummy name to the symtable in
  5760. which the objcclass/protocol/category is declared, so they can
  5761. be called via id.<name>
  5762. }
  5763. create_class_helper_for_procdef(pd,nil);
  5764. { we have to wait until now to set the mangled name because it
  5765. depends on the (possibly external) class name, which is defined
  5766. at the very end. }
  5767. if not(po_msgstr in pd.procoptions) then
  5768. begin
  5769. CGMessagePos(pd.fileinfo,parser_e_objc_requires_msgstr);
  5770. { recover to avoid internalerror later on }
  5771. include(pd.procoptions,po_msgstr);
  5772. pd.messageinf.str:=stringdup('MissingDeclaration');
  5773. end;
  5774. { Mangled name is already set in case this is a copy of
  5775. another type. }
  5776. if not(po_has_mangledname in pd.procoptions) then
  5777. begin
  5778. { check whether the number of formal parameters is correct,
  5779. and whether they have valid Objective-C types }
  5780. paracount:=0;
  5781. for i:=1 to length(pd.messageinf.str^) do
  5782. if pd.messageinf.str^[i]=':' then
  5783. inc(paracount);
  5784. for i:=0 to pd.paras.count-1 do
  5785. if not(vo_is_hidden_para in tparavarsym(pd.paras[i]).varoptions) and
  5786. not is_array_of_const(tparavarsym(pd.paras[i]).vardef) then
  5787. dec(paracount);
  5788. if (paracount<>0) then
  5789. MessagePos(pd.fileinfo,sym_e_objc_para_mismatch);
  5790. pd.setmangledname(pd.objcmangledname);
  5791. end
  5792. else
  5793. { all checks already done }
  5794. exit;
  5795. if not(oo_is_external in pd.struct.objectoptions) then
  5796. begin
  5797. if (po_varargs in pd.procoptions) then
  5798. MessagePos(pd.fileinfo,parser_e_varargs_need_cdecl_and_external)
  5799. else
  5800. begin
  5801. { check for "array of const" parameters }
  5802. for i:=0 to pd.parast.symlist.count-1 do
  5803. begin
  5804. if (tsym(pd.parast.symlist[i]).typ=paravarsym) and
  5805. is_array_of_const(tparavarsym(pd.parast.symlist[i]).vardef) then
  5806. MessagePos(pd.fileinfo,parser_e_varargs_need_cdecl_and_external);
  5807. end;
  5808. end;
  5809. end;
  5810. end;
  5811. end;
  5812. procedure mark_private_fields_used(data: tobject; arg: pointer);
  5813. var
  5814. sym: tsym absolute data;
  5815. begin
  5816. if (sym.typ=fieldvarsym) and
  5817. (tfieldvarsym(sym).visibility in [vis_private,vis_strictprivate]) then
  5818. sym.IncRefCount;
  5819. end;
  5820. procedure tobjectdef.finish_objc_data;
  5821. begin
  5822. self.symtable.DefList.foreachcall(@check_and_finish_msg,nil);
  5823. if (oo_is_external in objectoptions) then
  5824. self.symtable.SymList.ForEachCall(@mark_private_fields_used,nil);
  5825. end;
  5826. procedure verify_objc_vardef(data: tobject; arg: pointer);
  5827. var
  5828. sym: tabstractvarsym absolute data;
  5829. res: pboolean absolute arg;
  5830. founderrordef: tdef;
  5831. begin
  5832. if not(tsym(data).typ in [paravarsym,fieldvarsym]) then
  5833. exit;
  5834. if (sym.typ=paravarsym) and
  5835. ((vo_is_hidden_para in tparavarsym(sym).varoptions) or
  5836. is_array_of_const(tparavarsym(sym).vardef)) then
  5837. exit;
  5838. if not objcchecktype(sym.vardef,founderrordef) then
  5839. begin
  5840. MessagePos1(sym.fileinfo,type_e_objc_type_unsupported,founderrordef.typename);
  5841. res^:=false;
  5842. end;
  5843. end;
  5844. procedure verify_objc_procdef_paras(data: tobject; arg: pointer);
  5845. var
  5846. def: tdef absolute data;
  5847. res: pboolean absolute arg;
  5848. founderrordef: tdef;
  5849. begin
  5850. if (def.typ<>procdef) then
  5851. exit;
  5852. { check parameter types for validity }
  5853. tprocdef(def).paras.foreachcall(@verify_objc_vardef,arg);
  5854. { check the result type for validity }
  5855. if not objcchecktype(tprocdef(def).returndef,founderrordef) then
  5856. begin
  5857. MessagePos1(tprocdef(def).funcretsym.fileinfo,type_e_objc_type_unsupported,founderrordef.typename);
  5858. res^:=false;
  5859. end;
  5860. end;
  5861. function tobjectdef.check_objc_types: boolean;
  5862. begin
  5863. { done in separate step from finish_objc_data, because when
  5864. finish_objc_data is called, not all forwarddefs have been resolved
  5865. yet and we need to know all types here }
  5866. result:=true;
  5867. self.symtable.symlist.foreachcall(@verify_objc_vardef,@result);
  5868. self.symtable.deflist.foreachcall(@verify_objc_procdef_paras,@result);
  5869. end;
  5870. procedure do_cpp_import_info(data: tobject; arg: pointer);
  5871. var
  5872. def: tdef absolute data;
  5873. pd: tprocdef absolute data;
  5874. begin
  5875. if (def.typ=procdef) then
  5876. begin
  5877. pd.setmangledname(target_info.Cprefix+pd.cplusplusmangledname);
  5878. if (oo_is_external in pd.struct.objectoptions) then
  5879. begin
  5880. { copied from psub.read_proc }
  5881. if assigned(tobjectdef(pd.struct).import_lib) then
  5882. current_module.AddExternalImport(tobjectdef(pd.struct).import_lib^,pd.mangledname,pd.mangledname,0,false,false)
  5883. else
  5884. begin
  5885. { add import name to external list for DLL scanning }
  5886. if tf_has_dllscanner in target_info.flags then
  5887. current_module.dllscannerinputlist.Add(pd.mangledname,pd);
  5888. end;
  5889. end;
  5890. end;
  5891. end;
  5892. procedure tobjectdef.finish_cpp_data;
  5893. begin
  5894. self.symtable.DefList.ForEachCall(@do_cpp_import_info,nil);
  5895. end;
  5896. {****************************************************************************
  5897. TImplementedInterface
  5898. ****************************************************************************}
  5899. function TImplementedInterface.GetIOffset: longint;
  5900. begin
  5901. if (fIOffset=-1) and
  5902. (IType in [etFieldValue,etFieldValueClass]) then
  5903. result:=tfieldvarsym(ImplementsField).fieldoffset
  5904. else
  5905. result:=fIOffset;
  5906. end;
  5907. constructor TImplementedInterface.create(aintf: tobjectdef);
  5908. begin
  5909. inherited create;
  5910. intfdef:=aintf;
  5911. IOffset:=-1;
  5912. IType:=etStandard;
  5913. NameMappings:=nil;
  5914. procdefs:=nil;
  5915. end;
  5916. constructor TImplementedInterface.create_deref(intfd,getterd:tderef);
  5917. begin
  5918. inherited create;
  5919. intfdef:=nil;
  5920. intfdefderef:=intfd;
  5921. ImplementsGetterDeref:=getterd;
  5922. IOffset:=-1;
  5923. IType:=etStandard;
  5924. NameMappings:=nil;
  5925. procdefs:=nil;
  5926. end;
  5927. destructor TImplementedInterface.destroy;
  5928. var
  5929. i : longint;
  5930. mappedname : pshortstring;
  5931. begin
  5932. if assigned(NameMappings) then
  5933. begin
  5934. for i:=0 to NameMappings.Count-1 do
  5935. begin
  5936. mappedname:=pshortstring(NameMappings[i]);
  5937. stringdispose(mappedname);
  5938. end;
  5939. NameMappings.free;
  5940. NameMappings:=nil;
  5941. end;
  5942. if assigned(procdefs) then
  5943. begin
  5944. procdefs.free;
  5945. procdefs:=nil;
  5946. end;
  5947. inherited destroy;
  5948. end;
  5949. procedure TImplementedInterface.buildderef;
  5950. begin
  5951. intfdefderef.build(intfdef);
  5952. ImplementsGetterDeref.build(ImplementsGetter);
  5953. end;
  5954. procedure TImplementedInterface.deref;
  5955. begin
  5956. intfdef:=tobjectdef(intfdefderef.resolve);
  5957. ImplementsGetter:=tsym(ImplementsGetterDeref.resolve);
  5958. end;
  5959. procedure TImplementedInterface.AddMapping(const origname,newname: string);
  5960. begin
  5961. if not assigned(NameMappings) then
  5962. NameMappings:=TFPHashList.Create;
  5963. NameMappings.Add(origname,stringdup(newname));
  5964. end;
  5965. function TImplementedInterface.GetMapping(const origname: string):string;
  5966. var
  5967. mappedname : pshortstring;
  5968. begin
  5969. result:='';
  5970. if not assigned(NameMappings) then
  5971. exit;
  5972. mappedname:=PShortstring(NameMappings.Find(origname));
  5973. if assigned(mappedname) then
  5974. result:=mappedname^;
  5975. end;
  5976. procedure TImplementedInterface.AddImplProc(pd:tprocdef);
  5977. begin
  5978. if not assigned(procdefs) then
  5979. procdefs:=TFPObjectList.Create(false);
  5980. { duplicate entries must be stored, because multiple }
  5981. { interfaces can declare methods with the same name }
  5982. { and all of these get their own VMT entry }
  5983. procdefs.Add(pd);
  5984. end;
  5985. function TImplementedInterface.IsImplMergePossible(MergingIntf:TImplementedInterface;out weight: longint): boolean;
  5986. var
  5987. i : longint;
  5988. begin
  5989. result:=false;
  5990. { interfaces being implemented through delegation are not mergable (FK) }
  5991. if (IType<>etStandard) or (MergingIntf.IType<>etStandard) or not(assigned(ProcDefs)) or not(assigned(MergingIntf.ProcDefs)) then
  5992. exit;
  5993. weight:=0;
  5994. { empty interface is mergeable }
  5995. if ProcDefs.Count=0 then
  5996. begin
  5997. result:=true;
  5998. exit;
  5999. end;
  6000. { The interface to merge must at least the number of
  6001. procedures of this interface }
  6002. if MergingIntf.ProcDefs.Count<ProcDefs.Count then
  6003. exit;
  6004. for i:=0 to ProcDefs.Count-1 do
  6005. begin
  6006. if MergingIntf.ProcDefs[i]<>ProcDefs[i] then
  6007. exit;
  6008. end;
  6009. weight:=ProcDefs.Count;
  6010. result:=true;
  6011. end;
  6012. function TImplementedInterface.getcopy:TImplementedInterface;
  6013. begin
  6014. Result:=TImplementedInterface.Create(nil);
  6015. { 1) the procdefs list will be freed once for each copy
  6016. 2) since the procdefs list owns its elements, those will also be freed for each copy
  6017. 3) idem for the name mappings
  6018. }
  6019. { warning: this is completely wrong on so many levels...
  6020. Move(pointer(self)^,pointer(result)^,InstanceSize);
  6021. We need to make clean copies of the different fields
  6022. this is not implemented yet, and thus we generate an internal
  6023. error instead PM 2011-06-14 }
  6024. internalerror(2011061401);
  6025. end;
  6026. {****************************************************************************
  6027. TFORWARDDEF
  6028. ****************************************************************************}
  6029. constructor tforwarddef.create(const s:string;const pos:tfileposinfo);
  6030. begin
  6031. inherited create(forwarddef);
  6032. tosymname:=stringdup(s);
  6033. forwardpos:=pos;
  6034. end;
  6035. function tforwarddef.GetTypeName:string;
  6036. begin
  6037. GetTypeName:='unresolved forward to '+tosymname^;
  6038. end;
  6039. destructor tforwarddef.destroy;
  6040. begin
  6041. stringdispose(tosymname);
  6042. inherited destroy;
  6043. end;
  6044. function tforwarddef.getcopy:tstoreddef;
  6045. begin
  6046. result:=cforwarddef.create(tosymname^, forwardpos);
  6047. end;
  6048. {****************************************************************************
  6049. TUNDEFINEDDEF
  6050. ****************************************************************************}
  6051. constructor tundefineddef.create;
  6052. begin
  6053. inherited create(undefineddef);
  6054. end;
  6055. constructor tundefineddef.ppuload(ppufile:tcompilerppufile);
  6056. begin
  6057. inherited ppuload(undefineddef,ppufile);
  6058. ppuload_platform(ppufile);
  6059. end;
  6060. function tundefineddef.GetTypeName:string;
  6061. begin
  6062. GetTypeName:='<undefined type>';
  6063. end;
  6064. procedure tundefineddef.ppuwrite(ppufile:tcompilerppufile);
  6065. begin
  6066. inherited ppuwrite(ppufile);
  6067. writeentry(ppufile,ibundefineddef);
  6068. end;
  6069. {****************************************************************************
  6070. TERRORDEF
  6071. ****************************************************************************}
  6072. constructor terrordef.create;
  6073. begin
  6074. inherited create(errordef);
  6075. { prevent consecutive faults }
  6076. savesize:=1;
  6077. end;
  6078. procedure terrordef.ppuwrite(ppufile:tcompilerppufile);
  6079. begin
  6080. { Can't write errordefs to ppu }
  6081. internalerror(200411063);
  6082. end;
  6083. function terrordef.GetTypeName:string;
  6084. begin
  6085. GetTypeName:='<erroneous type>';
  6086. end;
  6087. function terrordef.getmangledparaname:TSymStr;
  6088. begin
  6089. getmangledparaname:='error';
  6090. end;
  6091. {****************************************************************************
  6092. Definition Helpers
  6093. ****************************************************************************}
  6094. function is_interfacecom(def: tdef): boolean;
  6095. begin
  6096. is_interfacecom:=
  6097. assigned(def) and
  6098. (def.typ=objectdef) and
  6099. (tobjectdef(def).objecttype=odt_interfacecom);
  6100. end;
  6101. function is_interfacecom_or_dispinterface(def: tdef): boolean;
  6102. begin
  6103. is_interfacecom_or_dispinterface:=
  6104. assigned(def) and
  6105. (def.typ=objectdef) and
  6106. (tobjectdef(def).objecttype in [odt_interfacecom,odt_dispinterface]);
  6107. end;
  6108. function is_any_interface_kind(def: tdef): boolean;
  6109. begin
  6110. result:=
  6111. assigned(def) and
  6112. (def.typ=objectdef) and
  6113. ((tobjectdef(def).objecttype in [odt_interfacecom,odt_dispinterface,odt_interfacecorba,odt_interfacejava,odt_objcprotocol]) or
  6114. is_objccategory(def));
  6115. end;
  6116. function is_interfacecorba(def: tdef): boolean;
  6117. begin
  6118. is_interfacecorba:=
  6119. assigned(def) and
  6120. (def.typ=objectdef) and
  6121. (tobjectdef(def).objecttype=odt_interfacecorba);
  6122. end;
  6123. function is_interface(def: tdef): boolean;
  6124. begin
  6125. is_interface:=
  6126. assigned(def) and
  6127. (def.typ=objectdef) and
  6128. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  6129. end;
  6130. function is_dispinterface(def: tdef): boolean;
  6131. begin
  6132. result:=
  6133. assigned(def) and
  6134. (def.typ=objectdef) and
  6135. (tobjectdef(def).objecttype=odt_dispinterface);
  6136. end;
  6137. function is_class(def: tdef): boolean;
  6138. begin
  6139. is_class:=
  6140. assigned(def) and
  6141. (def.typ=objectdef) and
  6142. (tobjectdef(def).objecttype=odt_class);
  6143. end;
  6144. function is_object(def: tdef): boolean;
  6145. begin
  6146. is_object:=
  6147. assigned(def) and
  6148. (def.typ=objectdef) and
  6149. (tobjectdef(def).objecttype=odt_object);
  6150. end;
  6151. function is_cppclass(def: tdef): boolean;
  6152. begin
  6153. is_cppclass:=
  6154. assigned(def) and
  6155. (def.typ=objectdef) and
  6156. (tobjectdef(def).objecttype=odt_cppclass);
  6157. end;
  6158. function is_objcclass(def: tdef): boolean;
  6159. begin
  6160. is_objcclass:=
  6161. assigned(def) and
  6162. (def.typ=objectdef) and
  6163. (tobjectdef(def).objecttype=odt_objcclass);
  6164. end;
  6165. function is_objectpascal_helper(def: tdef): boolean;
  6166. begin
  6167. result:=
  6168. assigned(def) and
  6169. (def.typ=objectdef) and
  6170. (tobjectdef(def).objecttype=odt_helper);
  6171. end;
  6172. function is_objcclassref(def: tdef): boolean;
  6173. begin
  6174. is_objcclassref:=
  6175. assigned(def) and
  6176. (def.typ=classrefdef) and
  6177. is_objcclass(tclassrefdef(def).pointeddef);
  6178. end;
  6179. function is_objcprotocol(def: tdef): boolean;
  6180. begin
  6181. result:=
  6182. assigned(def) and
  6183. (def.typ=objectdef) and
  6184. (tobjectdef(def).objecttype=odt_objcprotocol);
  6185. end;
  6186. function is_objccategory(def: tdef): boolean;
  6187. begin
  6188. result:=
  6189. assigned(def) and
  6190. (def.typ=objectdef) and
  6191. { if used as a forward type }
  6192. ((tobjectdef(def).objecttype=odt_objccategory) or
  6193. { if used as after it has been resolved }
  6194. ((tobjectdef(def).objecttype=odt_objcclass) and
  6195. (oo_is_classhelper in tobjectdef(def).objectoptions)));
  6196. end;
  6197. function is_objc_class_or_protocol(def: tdef): boolean;
  6198. begin
  6199. result:=
  6200. assigned(def) and
  6201. (def.typ=objectdef) and
  6202. (tobjectdef(def).objecttype in [odt_objcclass,odt_objcprotocol]);
  6203. end;
  6204. function is_objc_protocol_or_category(def: tdef): boolean;
  6205. begin
  6206. result:=
  6207. assigned(def) and
  6208. (def.typ=objectdef) and
  6209. ((tobjectdef(def).objecttype = odt_objcprotocol) or
  6210. ((tobjectdef(def).objecttype = odt_objcclass) and
  6211. (oo_is_classhelper in tobjectdef(def).objectoptions)));
  6212. end;
  6213. function is_classhelper(def: tdef): boolean;
  6214. begin
  6215. result:=
  6216. is_objectpascal_helper(def) or
  6217. is_objccategory(def);
  6218. end;
  6219. function is_class_or_interface(def: tdef): boolean;
  6220. begin
  6221. result:=
  6222. assigned(def) and
  6223. (def.typ=objectdef) and
  6224. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  6225. end;
  6226. function is_class_or_interface_or_objc(def: tdef): boolean;
  6227. begin
  6228. result:=
  6229. assigned(def) and
  6230. (def.typ=objectdef) and
  6231. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_objcclass,odt_objcprotocol]);
  6232. end;
  6233. function is_class_or_interface_or_objc_or_java(def: tdef): boolean;
  6234. begin
  6235. result:=
  6236. assigned(def) and
  6237. (def.typ=objectdef) and
  6238. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava]);
  6239. end;
  6240. function is_class_or_interface_or_dispinterface_or_objc_or_java(def: tdef): boolean;
  6241. begin
  6242. result:=
  6243. assigned(def) and
  6244. (def.typ=objectdef) and
  6245. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava]);
  6246. end;
  6247. function is_class_or_interface_or_object(def: tdef): boolean;
  6248. begin
  6249. result:=
  6250. assigned(def) and
  6251. (def.typ=objectdef) and
  6252. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_object]);
  6253. end;
  6254. function is_class_or_interface_or_dispinterface(def: tdef): boolean;
  6255. begin
  6256. result:=
  6257. assigned(def) and
  6258. (def.typ=objectdef) and
  6259. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface]);
  6260. end;
  6261. function is_implicit_pointer_object_type(def: tdef): boolean;
  6262. begin
  6263. result:=
  6264. assigned(def) and
  6265. (((def.typ=objectdef) and
  6266. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava])) or
  6267. ((target_info.system in systems_jvm) and
  6268. (def.typ=recorddef)));
  6269. end;
  6270. function is_implicit_array_pointer(def: tdef): boolean;
  6271. begin
  6272. result:=is_dynamic_array(def) or is_dynamicstring(def);
  6273. end;
  6274. function is_class_or_object(def: tdef): boolean;
  6275. begin
  6276. result:=
  6277. assigned(def) and
  6278. (def.typ=objectdef) and
  6279. (tobjectdef(def).objecttype in [odt_class,odt_object]);
  6280. end;
  6281. function is_record(def: tdef): boolean;
  6282. begin
  6283. result:=
  6284. assigned(def) and
  6285. (def.typ=recorddef);
  6286. end;
  6287. function is_javaclass(def: tdef): boolean;
  6288. begin
  6289. result:=
  6290. assigned(def) and
  6291. (def.typ=objectdef) and
  6292. (tobjectdef(def).objecttype=odt_javaclass);
  6293. end;
  6294. function is_javaclassref(def: tdef): boolean;
  6295. begin
  6296. is_javaclassref:=
  6297. assigned(def) and
  6298. (def.typ=classrefdef) and
  6299. is_javaclass(tclassrefdef(def).pointeddef);
  6300. end;
  6301. function is_javainterface(def: tdef): boolean;
  6302. begin
  6303. result:=
  6304. assigned(def) and
  6305. (def.typ=objectdef) and
  6306. (tobjectdef(def).objecttype=odt_interfacejava);
  6307. end;
  6308. function is_java_class_or_interface(def: tdef): boolean;
  6309. begin
  6310. result:=
  6311. assigned(def) and
  6312. (def.typ=objectdef) and
  6313. (tobjectdef(def).objecttype in [odt_javaclass,odt_interfacejava]);
  6314. end;
  6315. procedure loadobjctypes;
  6316. begin
  6317. objc_metaclasstype:=tpointerdef(search_named_unit_globaltype('OBJC','POBJC_CLASS',true).typedef);
  6318. objc_superclasstype:=tpointerdef(search_named_unit_globaltype('OBJC','POBJC_SUPER',true).typedef);
  6319. objc_idtype:=tpointerdef(search_named_unit_globaltype('OBJC','ID',true).typedef);
  6320. objc_seltype:=tpointerdef(search_named_unit_globaltype('OBJC','SEL',true).typedef);
  6321. objc_objecttype:=trecorddef(search_named_unit_globaltype('OBJC','OBJC_OBJECT',true).typedef);
  6322. end;
  6323. procedure maybeloadcocoatypes;
  6324. var
  6325. tsym: ttypesym;
  6326. cocoaunit: string[15];
  6327. begin
  6328. if assigned(objc_fastenumeration) then
  6329. exit;
  6330. if not(target_info.system in [system_arm_darwin,system_i386_iphonesim]) then
  6331. cocoaunit:='COCOAALL'
  6332. else
  6333. cocoaunit:='IPHONEALL';
  6334. tsym:=search_named_unit_globaltype(cocoaunit,'NSFASTENUMERATIONPROTOCOL',false);
  6335. if assigned(tsym) then
  6336. objc_fastenumeration:=tobjectdef(tsym.typedef)
  6337. else
  6338. objc_fastenumeration:=nil;
  6339. tsym:=search_named_unit_globaltype(cocoaunit,'NSFASTENUMERATIONSTATE',false);
  6340. if assigned(tsym) then
  6341. objc_fastenumerationstate:=trecorddef(tsym.typedef)
  6342. else
  6343. objc_fastenumerationstate:=nil;
  6344. end;
  6345. function use_vectorfpu(def : tdef) : boolean;
  6346. begin
  6347. {$ifdef x86}
  6348. {$define use_vectorfpuimplemented}
  6349. use_vectorfpu:=(is_single(def) and (current_settings.fputype in sse_singlescalar)) or
  6350. (is_double(def) and (current_settings.fputype in sse_doublescalar));
  6351. {$endif x86}
  6352. {$ifdef arm}
  6353. {$define use_vectorfpuimplemented}
  6354. use_vectorfpu:=(current_settings.fputype in vfp_scalar);
  6355. {$endif arm}
  6356. {$ifndef use_vectorfpuimplemented}
  6357. use_vectorfpu:=false;
  6358. {$endif}
  6359. end;
  6360. function getpointerdef(def: tdef): tpointerdef;
  6361. var
  6362. res: PHashSetItem;
  6363. oldsymtablestack: tsymtablestack;
  6364. begin
  6365. if not assigned(current_module) then
  6366. internalerror(2011071101);
  6367. res:=current_module.ptrdefs.FindOrAdd(@def,sizeof(def));
  6368. if not assigned(res^.Data) then
  6369. begin
  6370. { since these pointerdefs can be reused anywhere in the current
  6371. unit, add them to the global/staticsymtable }
  6372. oldsymtablestack:=symtablestack;
  6373. { do not simply push/pop current_module.localsymtable, because
  6374. that can have side-effects (e.g., it removes helpers) }
  6375. symtablestack:=nil;
  6376. res^.Data:=cpointerdef.create(def);
  6377. if assigned(current_module.localsymtable) then
  6378. current_module.localsymtable.insertdef(tdef(res^.Data))
  6379. else
  6380. current_module.globalsymtable.insertdef(tdef(res^.Data));
  6381. symtablestack:=oldsymtablestack;
  6382. end;
  6383. result:=tpointerdef(res^.Data);
  6384. end;
  6385. function getsingletonarraydef(def: tdef): tarraydef;
  6386. begin
  6387. result:=getarraydef(def,1);
  6388. end;
  6389. function getarraydef(def: tdef; elecount: asizeint): tarraydef;
  6390. var
  6391. res: PHashSetItem;
  6392. oldsymtablestack: tsymtablestack;
  6393. arrdesc: packed record
  6394. def: tdef;
  6395. elecount: asizeint;
  6396. end;
  6397. begin
  6398. if not assigned(current_module) then
  6399. internalerror(2011081301);
  6400. arrdesc.def:=def;
  6401. arrdesc.elecount:=elecount;
  6402. res:=current_module.arraydefs.FindOrAdd(@arrdesc,sizeof(arrdesc));
  6403. if not assigned(res^.Data) then
  6404. begin
  6405. { since these arraydef can be reused anywhere in the current
  6406. unit, add them to the global/staticsymtable }
  6407. oldsymtablestack:=symtablestack;
  6408. symtablestack:=nil;
  6409. res^.Data:=carraydef.create(0,elecount-1,ptrsinttype);
  6410. tarraydef(res^.Data).elementdef:=def;
  6411. if assigned(current_module.localsymtable) then
  6412. current_module.localsymtable.insertdef(tdef(res^.Data))
  6413. else
  6414. current_module.globalsymtable.insertdef(tdef(res^.Data));
  6415. symtablestack:=oldsymtablestack;
  6416. end;
  6417. result:=tarraydef(res^.Data);
  6418. end;
  6419. end.