symdef.pas 259 KB

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