symdef.pas 249 KB

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