ninl.pas 240 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064
  1. {
  2. Copyright (c) 1998-2007 by Florian Klaempfl
  3. Type checking and register allocation for inline nodes
  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 ninl;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,htypechk,symtype,compinnr;
  22. type
  23. TInlineNodeFlag = (
  24. inf_inlineconst
  25. );
  26. TInlineNodeFlags = set of TInlineNodeFlag;
  27. tinlinenode = class(tunarynode)
  28. inlinenodeflags : TInlineNodeFlags;
  29. inlinenumber : tinlinenumber;
  30. constructor create(number : tinlinenumber;is_const:boolean;l : tnode);virtual;
  31. constructor createintern(number : tinlinenumber;is_const:boolean;l : tnode);virtual;
  32. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  33. procedure ppuwrite(ppufile:tcompilerppufile);override;
  34. function dogetcopy : tnode;override;
  35. procedure printnodeinfo(var t : text);override;
  36. {$ifdef DEBUG_NODE_XML}
  37. procedure XMLPrintNodeInfo(var t : text);override;
  38. {$endif DEBUG_NODE_XML}
  39. function pass_1 : tnode;override;
  40. function pass_typecheck:tnode;override;
  41. function pass_typecheck_cpu:tnode;virtual;
  42. function simplify(forinline : boolean): tnode;override;
  43. function docompare(p: tnode): boolean; override;
  44. procedure mark_write;override;
  45. { returns a node tree where the inc/dec are replaced by add/sub }
  46. function getaddsub_for_incdec : tnode;
  47. { pack and unpack are changed into for-loops by the compiler }
  48. function first_pack_unpack: tnode; virtual;
  49. property parameters : tnode read left write left;
  50. function may_have_sideeffect_norecurse: boolean;
  51. protected
  52. { All the following routines currently
  53. call compilerprocs, unless they are
  54. overridden in which case, the code
  55. generator handles them.
  56. }
  57. function first_pi: tnode ; virtual;
  58. function first_arctan_real: tnode; virtual;
  59. function first_abs_real: tnode; virtual;
  60. function first_sqr_real: tnode; virtual;
  61. function first_sqrt_real: tnode; virtual;
  62. function first_ln_real: tnode; virtual;
  63. function first_cos_real: tnode; virtual;
  64. function first_sin_real: tnode; virtual;
  65. function first_exp_real: tnode; virtual;
  66. function first_frac_real: tnode; virtual;
  67. function first_round_real: tnode; virtual;
  68. function first_trunc_real: tnode; virtual;
  69. function first_int_real: tnode; virtual;
  70. function first_abs_long: tnode; virtual;
  71. function first_IncDec: tnode; virtual;
  72. function first_IncludeExclude: tnode; virtual;
  73. function first_get_frame: tnode; virtual;
  74. function first_setlength: tnode; virtual;
  75. function first_copy: tnode; virtual;
  76. { This one by default generates an internal error, because such
  77. nodes are not generated by the parser. It's however used internally
  78. by the JVM backend to create new dynamic arrays. }
  79. function first_new: tnode; virtual;
  80. function first_length: tnode; virtual;
  81. function first_high: tnode; virtual;
  82. function first_box: tnode; virtual; abstract;
  83. function first_unbox: tnode; virtual; abstract;
  84. function first_assigned: tnode; virtual;
  85. function first_assert: tnode; virtual;
  86. function first_popcnt: tnode; virtual;
  87. function first_bitscan: tnode; virtual;
  88. { override these for Seg() support }
  89. function typecheck_seg: tnode; virtual;
  90. function first_seg: tnode; virtual;
  91. function first_sar: tnode; virtual;
  92. function first_fma : tnode; virtual;
  93. function first_minmax: tnode; virtual;
  94. {$if not defined(cpu64bitalu) and not defined(cpuhighleveltarget)}
  95. function first_ShiftRot_assign_64bitint: tnode; virtual;
  96. {$endif not cpu64bitalu and not cpuhighleveltarget}
  97. function first_AndOrXorShiftRot_assign: tnode; virtual;
  98. function first_NegNot_assign: tnode; virtual;
  99. function first_cpu : tnode; virtual;
  100. procedure CheckParameters(count : integer);
  101. private
  102. function handle_str: tnode;
  103. function handle_reset_rewrite_typed: tnode;
  104. function handle_text_read_write(filepara,params:Ttertiarynode;var newstatement:Tnode):boolean;
  105. function handle_typed_read_write(filepara,params:Ttertiarynode;var newstatement:Tnode):boolean;
  106. function handle_read_write: tnode;
  107. function handle_val: tnode;
  108. function handle_default: tnode;
  109. function handle_setlength: tnode;
  110. function handle_copy: tnode;
  111. function handle_box: tnode;
  112. function handle_unbox: tnode;
  113. function handle_insert:tnode;
  114. function handle_delete:tnode;
  115. function handle_concat:tnode;
  116. end;
  117. tinlinenodeclass = class of tinlinenode;
  118. var
  119. cinlinenode : tinlinenodeclass = tinlinenode;
  120. function geninlinenode(number : tinlinenumber;is_const:boolean;l : tnode) : tinlinenode;
  121. implementation
  122. uses
  123. verbose,globals,systems,constexp,
  124. globtype,cutils,cclasses,fmodule,
  125. symconst,symdef,symsym,symcpu,symtable,paramgr,defcmp,defutil,symbase,
  126. cpuinfo,cpubase,
  127. pass_1,ppu,
  128. ncal,ncon,ncnv,nadd,nld,nbas,nflw,nmem,nmat,nutils,ngenutil,
  129. nobjc,objcdef,
  130. cgbase,procinfo;
  131. function geninlinenode(number : tinlinenumber;is_const:boolean;l : tnode) : tinlinenode;
  132. begin
  133. geninlinenode:=cinlinenode.create(number,is_const,l);
  134. end;
  135. {*****************************************************************************
  136. TINLINENODE
  137. *****************************************************************************}
  138. constructor tinlinenode.create(number : tinlinenumber;is_const:boolean;l : tnode);
  139. begin
  140. inherited create(inlinen,l);
  141. if is_const then
  142. inlinenodeflags:=[inf_inlineconst]
  143. else
  144. inlinenodeflags:=[];
  145. inlinenumber:=number;
  146. end;
  147. constructor tinlinenode.createintern(number : tinlinenumber; is_const : boolean;
  148. l : tnode);
  149. begin
  150. create(number,is_const,l);
  151. inlinenodeflags:=[];
  152. include(flags,nf_internal);
  153. end;
  154. constructor tinlinenode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  155. begin
  156. inherited ppuload(t,ppufile);
  157. ppufile.getset(tppuset1(inlinenodeflags));
  158. inlinenumber:=tinlinenumber(ppufile.getlongint);
  159. end;
  160. procedure tinlinenode.ppuwrite(ppufile:tcompilerppufile);
  161. begin
  162. inherited ppuwrite(ppufile);
  163. ppufile.putset(tppuset1(inlinenodeflags));
  164. ppufile.putlongint(longint(inlinenumber));
  165. end;
  166. function tinlinenode.dogetcopy : tnode;
  167. var
  168. n : tinlinenode;
  169. begin
  170. n:=tinlinenode(inherited dogetcopy);
  171. n.inlinenodeflags:=inlinenodeflags;
  172. n.inlinenumber:=inlinenumber;
  173. result:=n;
  174. end;
  175. procedure tinlinenode.printnodeinfo(var t : text);
  176. begin
  177. inherited;
  178. write(t,', inlinenumber = ',inlinenumber);
  179. end;
  180. {$ifdef DEBUG_NODE_XML}
  181. procedure TInlineNode.XMLPrintNodeInfo(var T: Text);
  182. var
  183. i: TInlineNodeFlag;
  184. First: Boolean;
  185. begin
  186. inherited XMLPrintNodeInfo(T);
  187. First := True;
  188. for i in inlinenodeflags do
  189. begin
  190. if First then
  191. begin
  192. Write(T, ' inlinenodeflags="', i);
  193. First := False;
  194. end
  195. else
  196. Write(T, ',', i)
  197. end;
  198. if not First then
  199. Write(T, '"');
  200. Write(T, ' inlinenumber="', inlinenumber, '"');
  201. end;
  202. {$endif DEBUG_NODE_XML}
  203. function get_str_int_func(def: tdef): string;
  204. var
  205. ordtype: tordtype;
  206. begin
  207. ordtype := torddef(def).ordtype;
  208. if not (ordtype in [scurrency,s64bit,u64bit,s32bit,u32bit,s16bit,u16bit,s8bit,u8bit]) then
  209. internalerror(2013032603);
  210. if is_oversizedord(def) then
  211. begin
  212. case ordtype of
  213. scurrency,
  214. s64bit: exit('int64');
  215. u64bit: exit('qword');
  216. s32bit: exit('longint');
  217. u32bit: exit('longword');
  218. s16bit: exit('smallint');
  219. u16bit: exit('word');
  220. else
  221. internalerror(2013032604);
  222. end;
  223. end
  224. else
  225. begin
  226. if is_nativeuint(def) then
  227. exit('uint')
  228. else
  229. exit('sint');
  230. end;
  231. internalerror(2013032605);
  232. end;
  233. function tinlinenode.handle_str : tnode;
  234. var
  235. lenpara,
  236. fracpara,
  237. newparas,
  238. tmppara,
  239. dest,
  240. source : tcallparanode;
  241. procname: string;
  242. is_real,is_enum : boolean;
  243. rt : aint;
  244. intrinsiccode: TInlineNumber;
  245. begin
  246. result := cerrornode.create;
  247. { get destination string }
  248. dest := tcallparanode(left);
  249. { get source para (number) }
  250. source := dest;
  251. while assigned(source.right) do
  252. source := tcallparanode(source.right);
  253. { destination parameter must be a normal (not a colon) parameter, this
  254. check is needed because str(v:len) also has 2 parameters }
  255. if (source=dest) or
  256. (cpf_is_colon_para in tcallparanode(dest).callparaflags) then
  257. begin
  258. CGMessage1(parser_e_wrong_parameter_size,'Str');
  259. exit;
  260. end;
  261. { in case we are in a generic definition, we cannot
  262. do all checks, the parameters might be type parameters,
  263. bailout as well in case of an error before }
  264. if (df_generic in current_procinfo.procdef.defoptions) or
  265. (dest.resultdef.typ=errordef) or
  266. (source.resultdef.typ=errordef) then
  267. begin
  268. result.Free;
  269. result:=nil;
  270. resultdef:=voidtype;
  271. exit;
  272. end;
  273. is_real:=(source.resultdef.typ = floatdef) or is_currency(source.resultdef);
  274. is_enum:=source.left.resultdef.typ=enumdef;
  275. if ((dest.left.resultdef.typ<>stringdef) and
  276. not(is_chararray(dest.left.resultdef))) or
  277. not(is_real or is_enum or
  278. (source.left.resultdef.typ=orddef)) then
  279. begin
  280. CGMessagePos(fileinfo,parser_e_illegal_expression);
  281. exit;
  282. end;
  283. { get len/frac parameters }
  284. lenpara := nil;
  285. fracpara := nil;
  286. if (cpf_is_colon_para in tcallparanode(dest.right).callparaflags) then
  287. begin
  288. lenpara := tcallparanode(dest.right);
  289. { we can let the callnode do the type checking of these parameters too, }
  290. { but then the error messages aren't as nice }
  291. if not is_integer(lenpara.resultdef) then
  292. begin
  293. CGMessagePos1(lenpara.fileinfo,
  294. type_e_integer_expr_expected,lenpara.resultdef.typename);
  295. exit;
  296. end;
  297. if (cpf_is_colon_para in tcallparanode(lenpara.right).callparaflags) then
  298. begin
  299. { parameters are in reverse order! }
  300. fracpara := lenpara;
  301. lenpara := tcallparanode(lenpara.right);
  302. if not is_real then
  303. begin
  304. CGMessagePos(lenpara.fileinfo,parser_e_illegal_colon_qualifier);
  305. exit
  306. end;
  307. if not is_integer(lenpara.resultdef) then
  308. begin
  309. CGMessagePos1(lenpara.fileinfo,
  310. type_e_integer_expr_expected,lenpara.resultdef.typename);
  311. exit;
  312. end;
  313. end;
  314. end;
  315. { generate the parameter list for the compilerproc }
  316. newparas := dest;
  317. { if we have a float parameter, insert the realtype, len and fracpara parameters }
  318. if is_real then
  319. begin
  320. { insert realtype parameter }
  321. if not is_currency(source.resultdef) then
  322. begin
  323. rt:=ord(tfloatdef(source.left.resultdef).floattype);
  324. newparas.right := ccallparanode.create(cordconstnode.create(
  325. rt,s32inttype,true),newparas.right);
  326. tmppara:=tcallparanode(newparas.right);
  327. end
  328. else
  329. tmppara:=newparas;
  330. { if necessary, insert a fraction parameter }
  331. if not assigned(fracpara) then
  332. begin
  333. tmppara.right := ccallparanode.create(
  334. cordconstnode.create(int64(-1),s32inttype,false),
  335. tmppara.right);
  336. fracpara := tcallparanode(tmppara.right);
  337. end;
  338. { if necessary, insert a length para }
  339. if not assigned(lenpara) then
  340. fracpara.right := ccallparanode.create(
  341. cordconstnode.create(int64(-32767),s32inttype,false),
  342. fracpara.right);
  343. end
  344. else if is_enum then
  345. begin
  346. {Insert a reference to the ord2string index.}
  347. newparas.right:=Ccallparanode.create(
  348. Caddrnode.create_internal(
  349. Crttinode.create(Tenumdef(source.left.resultdef),fullrtti,rdt_normal)
  350. ),
  351. newparas.right);
  352. {Insert a reference to the typinfo.}
  353. newparas.right:=Ccallparanode.create(
  354. Caddrnode.create_internal(
  355. Crttinode.create(Tenumdef(source.left.resultdef),fullrtti,rdt_ord2str)
  356. ),
  357. newparas.right);
  358. {Insert a type conversion from the enumeration to longint.}
  359. source.left:=Ctypeconvnode.create_internal(source.left,s32inttype);
  360. typecheckpass(source.left);
  361. { if necessary, insert a length para }
  362. if not assigned(lenpara) then
  363. Tcallparanode(Tcallparanode(newparas.right).right).right:=
  364. Ccallparanode.create(
  365. cordconstnode.create(int64(-1),s32inttype,false),
  366. Tcallparanode(Tcallparanode(newparas.right).right).right
  367. );
  368. end
  369. else
  370. { for a normal parameter, insert a only length parameter if one is missing }
  371. if not assigned(lenpara) then
  372. newparas.right := ccallparanode.create(cordconstnode.create(int64(-1),s32inttype,false),
  373. newparas.right);
  374. { remove the parameters from the original node so they won't get disposed, }
  375. { since they're reused }
  376. left := nil;
  377. intrinsiccode := Default(TInlineNumber);
  378. { create procedure name }
  379. if is_chararray(dest.resultdef) then
  380. procname:='fpc_chararray_'
  381. else
  382. procname := 'fpc_' + tstringdef(dest.resultdef).stringtypname+'_';
  383. if is_real then
  384. if is_currency(source.resultdef) then
  385. procname := procname + 'currency'
  386. else
  387. procname := procname + 'float'
  388. else if is_enum then
  389. procname:=procname+'enum'
  390. else
  391. case torddef(source.resultdef).ordtype of
  392. pasbool1,pasbool8,pasbool16,pasbool32,pasbool64,
  393. bool8bit,bool16bit,bool32bit,bool64bit:
  394. procname := procname + 'bool';
  395. else
  396. begin
  397. intrinsiccode := in_str_x_string;
  398. procname := procname + get_str_int_func(source.resultdef);
  399. end;
  400. end;
  401. { for ansistrings insert the encoding argument }
  402. if is_ansistring(dest.resultdef) then
  403. newparas:=ccallparanode.create(cordconstnode.create(
  404. getparaencoding(dest.resultdef),u16inttype,true),newparas);
  405. { free the errornode we generated in the beginning }
  406. result.free;
  407. { create the call node, }
  408. result := ccallnode.createfromintrinsic(intrinsiccode,procname,newparas);
  409. end;
  410. function tinlinenode.handle_default: tnode;
  411. function getdefaultvarsym(def:tdef):tnode;
  412. var
  413. hashedid : thashedidstring;
  414. srsym : tsym;
  415. srsymtable : tsymtable;
  416. defaultname : tidstring;
  417. begin
  418. if not assigned(def) or
  419. not (def.typ in [arraydef,recorddef,variantdef,objectdef,procvardef]) or
  420. ((def.typ=objectdef) and not is_object(def)) then
  421. internalerror(201202101);
  422. { extra '$' prefix because on darwin the result of makemangledname
  423. is prefixed by '_' and hence adding a '$' at the start of the
  424. prefix passed to makemangledname doesn't help (the whole point of
  425. the copy() operation below is to ensure that the id does not start
  426. with a '$', because that is interpreted specially by the symtable
  427. routines -- that's also why we prefix with '$_', so it will still
  428. work if make_mangledname() would somehow return a name that already
  429. starts with '$' }
  430. defaultname:='$_'+make_mangledname('zero',def.owner,def.typesym.Name);
  431. { can't hardcode the position of the '$', e.g. on darwin an underscore
  432. is added }
  433. hashedid.id:=copy(defaultname,2,255);
  434. { in case of a previous error, current_procinfo might not be set
  435. so avoid a crash in this case }
  436. if assigned(current_procinfo) then
  437. begin
  438. { the default sym is always part of the current procedure/function }
  439. srsymtable:=current_module.localsymtable;
  440. srsym:=tsym(srsymtable.findwithhash(hashedid));
  441. if not assigned(srsym) then
  442. begin
  443. { no valid default variable found, so create it }
  444. srsym:=cstaticvarsym.create(defaultname,vs_const,def,[]);
  445. { mark the staticvarsym as typedconst }
  446. include(tabstractvarsym(srsym).varoptions,vo_is_typed_const);
  447. include(tabstractvarsym(srsym).varoptions,vo_is_default_var);
  448. { The variable has a value assigned }
  449. tabstractvarsym(srsym).varstate:=vs_initialised;
  450. srsymtable.insertsym(srsym);
  451. cnodeutils.insertbssdata(tstaticvarsym(srsym));
  452. end;
  453. result:=cloadnode.create(srsym,srsymtable);
  454. end
  455. else
  456. result:=cerrornode.create;
  457. end;
  458. var
  459. def : tdef;
  460. begin
  461. if not assigned(left) or (left.nodetype<>typen) then
  462. internalerror(2012032102);
  463. def:=ttypenode(left).typedef;
  464. if assigned(current_procinfo) and
  465. (df_generic in current_procinfo.procdef.defoptions) then
  466. begin
  467. { don't allow as a default parameter value, because it may not be valid
  468. when specialising }
  469. if block_type<>bt_const then
  470. result:=cpointerconstnode.create(0,def)
  471. else
  472. result:=cerrornode.create;
  473. exit;
  474. end;
  475. result:=nil;
  476. case def.typ of
  477. enumdef,
  478. orddef:
  479. { don't do a rangecheck as Default will also return 0
  480. for the following types (Delphi compatible):
  481. TRange1 = -10..-5;
  482. TRange2 = 5..10;
  483. TEnum = (a:=5;b:=10); }
  484. result:=cordconstnode.create(0,def,false);
  485. classrefdef,
  486. pointerdef:
  487. result:=cpointerconstnode.create(0,def);
  488. procvardef:
  489. if tprocvardef(def).size<>sizeof(pint) then
  490. result:=getdefaultvarsym(def)
  491. else
  492. result:=cpointerconstnode.create(0,def);
  493. stringdef:
  494. result:=cstringconstnode.createstr('');
  495. floatdef:
  496. result:=crealconstnode.create(0,def);
  497. objectdef:
  498. begin
  499. if is_implicit_pointer_object_type(def) then
  500. result:=cpointerconstnode.create(0,def)
  501. else
  502. if is_object(def) then
  503. begin
  504. { Delphi does not recursively check whether
  505. an object contains unsupported types }
  506. if not (m_delphi in current_settings.modeswitches) and
  507. not is_valid_for_default(def) then
  508. Message(type_e_type_not_allowed_for_default);
  509. result:=getdefaultvarsym(def);
  510. end
  511. else
  512. Message(type_e_type_not_allowed_for_default);
  513. end;
  514. variantdef,
  515. recorddef:
  516. begin
  517. { Delphi does not recursively check whether a record
  518. contains unsupported types }
  519. if (def.typ=recorddef) and not (m_delphi in current_settings.modeswitches) and
  520. not is_valid_for_default(def) then
  521. Message(type_e_type_not_allowed_for_default);
  522. result:=getdefaultvarsym(def);
  523. end;
  524. setdef:
  525. begin
  526. result:=csetconstnode.create(nil,def);
  527. New(tsetconstnode(result).value_set);
  528. tsetconstnode(result).value_set^:=[];
  529. end;
  530. arraydef:
  531. begin
  532. { can other array types be parsed by single_type? }
  533. if ado_isdynamicarray in tarraydef(def).arrayoptions then
  534. result:=cpointerconstnode.create(0,def)
  535. else
  536. begin
  537. result:=getdefaultvarsym(def);
  538. end;
  539. end;
  540. undefineddef:
  541. begin
  542. if sp_generic_dummy in def.typesym.symoptions then
  543. begin
  544. { this matches the error messages that are printed
  545. in case of non-Delphi modes }
  546. Message(parser_e_no_generics_as_types);
  547. Message(type_e_type_id_expected);
  548. end
  549. else
  550. result:=cpointerconstnode.create(0,def);
  551. end;
  552. else
  553. Message(type_e_type_not_allowed_for_default);
  554. end;
  555. if not assigned(result) then
  556. result:=cerrornode.create;
  557. end;
  558. function tinlinenode.handle_reset_rewrite_typed: tnode;
  559. begin
  560. { since this is a "in_xxxx_typedfile" node, we can be sure we have }
  561. { a typed file as argument and we don't have to check it again (JM) }
  562. { add the recsize parameter }
  563. { iso mode extension with name? }
  564. if inlinenumber in [in_reset_typedfile_name,in_rewrite_typedfile_name] then
  565. begin
  566. left := ccallparanode.create(cordconstnode.create(
  567. tfiledef(tcallparanode(tcallparanode(left).nextpara).paravalue.resultdef).typedfiledef.size,s32inttype,true),left);
  568. end
  569. else
  570. begin
  571. { note: for some reason, the parameter of intern procedures with only one }
  572. { parameter is gets lifted out of its original tcallparanode (see round }
  573. { line 1306 of ncal.pas), so recreate a tcallparanode here (JM) }
  574. left := ccallparanode.create(cordconstnode.create(
  575. tfiledef(left.resultdef).typedfiledef.size,s32inttype,true),
  576. ccallparanode.create(left,nil));
  577. end;
  578. { create the correct call }
  579. if m_isolike_io in current_settings.modeswitches then
  580. begin
  581. case inlinenumber of
  582. in_reset_typedfile:
  583. result := ccallnode.createintern('fpc_reset_typed_iso',left);
  584. in_reset_typedfile_name:
  585. result := ccallnode.createintern('fpc_reset_typed_name_iso',left);
  586. in_rewrite_typedfile:
  587. result := ccallnode.createintern('fpc_rewrite_typed_iso',left);
  588. in_rewrite_typedfile_name:
  589. result := ccallnode.createintern('fpc_rewrite_typed_name_iso',left);
  590. else
  591. internalerror(2016101502);
  592. end;
  593. end
  594. else
  595. begin
  596. if inlinenumber=in_reset_typedfile then
  597. result := ccallnode.createintern('fpc_reset_typed',left)
  598. else
  599. result := ccallnode.createintern('fpc_rewrite_typed',left);
  600. end;
  601. { make sure left doesn't get disposed, since we use it in the new call }
  602. left := nil;
  603. end;
  604. procedure maybe_convert_to_string(var n: tnode);
  605. begin
  606. { stringconstnodes are arrays of char. It's much more }
  607. { efficient to write a constant string, so convert }
  608. { either to shortstring or ansistring depending on }
  609. { length }
  610. if (n.nodetype=stringconstn) then
  611. if is_chararray(n.resultdef) then
  612. if (tstringconstnode(n).len<=255) then
  613. inserttypeconv(n,cshortstringtype)
  614. else
  615. inserttypeconv(n,getansistringdef)
  616. else if is_widechararray(n.resultdef) then
  617. inserttypeconv(n,cunicodestringtype);
  618. end;
  619. procedure get_read_write_int_func(def: tdef; out func_suffix: string; out readfunctype: tdef);
  620. var
  621. ordtype: tordtype;
  622. begin
  623. ordtype := torddef(def).ordtype;
  624. if is_oversizedint(def) then
  625. begin
  626. case ordtype of
  627. s64bit:
  628. begin
  629. func_suffix := 'int64';
  630. readfunctype:=s64inttype;
  631. end;
  632. u64bit :
  633. begin
  634. func_suffix := 'qword';
  635. readfunctype:=u64inttype;
  636. end;
  637. s32bit:
  638. begin
  639. func_suffix := 'longint';
  640. readfunctype:=s32inttype;
  641. end;
  642. u32bit :
  643. begin
  644. func_suffix := 'longword';
  645. readfunctype:=u32inttype;
  646. end;
  647. s16bit:
  648. begin
  649. func_suffix := 'smallint';
  650. readfunctype:=s16inttype;
  651. end;
  652. u16bit :
  653. begin
  654. func_suffix := 'word';
  655. readfunctype:=u16inttype;
  656. end;
  657. else
  658. internalerror(2013032602);
  659. end;
  660. end
  661. else
  662. begin
  663. case ordtype of
  664. s64bit,
  665. s32bit,
  666. s16bit,
  667. s8bit:
  668. begin
  669. func_suffix := 'sint';
  670. readfunctype := sinttype;
  671. end;
  672. u64bit,
  673. u32bit,
  674. u16bit,
  675. u8bit:
  676. begin
  677. func_suffix := 'uint';
  678. readfunctype := uinttype;
  679. end;
  680. else
  681. internalerror(2013032601);
  682. end;
  683. end;
  684. end;
  685. function Tinlinenode.handle_text_read_write(filepara,params:Ttertiarynode;var newstatement:Tnode):boolean;
  686. {Read(ln)/write(ln) for text files.}
  687. const procprefixes:array[boolean] of string[15]=('fpc_write_text_','fpc_read_text_');
  688. var error_para,is_real,special_handling,found_error,do_read:boolean;
  689. p1:Tnode;
  690. nextpara,
  691. indexpara,
  692. lenpara,
  693. para,
  694. fracpara:Tcallparanode;
  695. temp:Ttempcreatenode;
  696. readfunctype:Tdef;
  697. name:string[63];
  698. func_suffix:string[8];
  699. begin
  700. para:=Tcallparanode(params);
  701. found_error:=false;
  702. do_read:=inlinenumber in [in_read_x,in_readln_x,in_readstr_x];
  703. name:='';
  704. while assigned(para) do
  705. begin
  706. { is this parameter faulty? }
  707. error_para:=false;
  708. { is this parameter a real? }
  709. is_real:=false;
  710. { type used for the read(), this is used to check
  711. whether a temp is needed for range checking }
  712. readfunctype:=nil;
  713. { can't read/write types }
  714. if (para.left.nodetype=typen) and not(is_typeparam(ttypenode(para.left).typedef)) then
  715. begin
  716. CGMessagePos(para.fileinfo,type_e_cant_read_write_type);
  717. error_para := true;
  718. end;
  719. { support writeln(procvar) }
  720. if para.left.resultdef.typ=procvardef then
  721. begin
  722. p1:=ccallnode.create_procvar(nil,para.left);
  723. typecheckpass(p1);
  724. para.left:=p1;
  725. end;
  726. if inlinenumber in [in_write_x,in_writeln_x] then
  727. { prefer strings to chararrays }
  728. maybe_convert_to_string(para.left);
  729. if is_typeparam(para.left.resultdef) then
  730. error_para:=true
  731. else
  732. case para.left.resultdef.typ of
  733. stringdef :
  734. begin
  735. name:=procprefixes[do_read]+tstringdef(para.left.resultdef).stringtypname;
  736. if (m_isolike_io in current_settings.modeswitches) and (tstringdef(para.left.resultdef).stringtype<>st_shortstring) then
  737. begin
  738. CGMessagePos(para.fileinfo,type_e_cant_read_write_type_in_iso_mode);
  739. error_para := true;
  740. end;
  741. end;
  742. pointerdef :
  743. begin
  744. if (not is_pchar(para.left.resultdef)) or do_read then
  745. begin
  746. CGMessagePos(para.fileinfo,type_e_cant_read_write_type);
  747. error_para := true;
  748. end
  749. else
  750. name:=procprefixes[do_read]+'pchar_as_pointer';
  751. end;
  752. floatdef :
  753. begin
  754. is_real:=true;
  755. if Tfloatdef(para.left.resultdef).floattype=s64currency then
  756. name := procprefixes[do_read]+'currency'
  757. else
  758. begin
  759. name := procprefixes[do_read]+'float';
  760. readfunctype:=pbestrealtype^;
  761. end;
  762. { iso pascal needs a different handler }
  763. if (m_isolike_io in current_settings.modeswitches) and do_read then
  764. name:=name+'_iso';
  765. end;
  766. enumdef:
  767. begin
  768. if m_isolike_io in current_settings.modeswitches then
  769. begin
  770. error_para := true;
  771. CGMessagePos(para.fileinfo,type_e_cant_read_write_type);
  772. end;
  773. name:=procprefixes[do_read]+'enum';
  774. if do_read then
  775. { read is done with a var parameter so we need the correct
  776. size for that }
  777. case para.left.resultdef.size of
  778. 1:
  779. begin
  780. name:=name+'_shortint';
  781. readfunctype:=s8inttype;
  782. end;
  783. 2:
  784. begin
  785. name:=name+'_smallint';
  786. readfunctype:=s16inttype;
  787. end;
  788. 4:
  789. begin
  790. name:=name+'_longint';
  791. readfunctype:=s32inttype;
  792. end;
  793. else
  794. internalerror(2022082601);
  795. end
  796. else
  797. readfunctype:=s32inttype;
  798. end;
  799. orddef :
  800. begin
  801. case Torddef(para.left.resultdef).ordtype of
  802. s8bit,
  803. s16bit,
  804. s32bit,
  805. s64bit,
  806. u8bit,
  807. u16bit,
  808. u32bit,
  809. u64bit:
  810. begin
  811. get_read_write_int_func(para.left.resultdef,func_suffix,readfunctype);
  812. name := procprefixes[do_read]+func_suffix;
  813. if (m_isolike_io in current_settings.modeswitches) and do_read then
  814. name:=name+'_iso';
  815. end;
  816. uchar :
  817. begin
  818. name := procprefixes[do_read]+'char';
  819. { iso pascal needs a different handler }
  820. if (m_isolike_io in current_settings.modeswitches) and do_read then
  821. name:=name+'_iso';
  822. readfunctype:=cansichartype;
  823. end;
  824. uwidechar :
  825. begin
  826. name := procprefixes[do_read]+'widechar';
  827. readfunctype:=cwidechartype;
  828. end;
  829. scurrency:
  830. begin
  831. name := procprefixes[do_read]+'currency';
  832. { iso pascal needs a different handler }
  833. if (m_isolike_io in current_settings.modeswitches) and do_read then
  834. name:=name+'_iso';
  835. readfunctype:=s64currencytype;
  836. is_real:=true;
  837. end;
  838. pasbool1,
  839. pasbool8,
  840. pasbool16,
  841. pasbool32,
  842. pasbool64,
  843. bool8bit,
  844. bool16bit,
  845. bool32bit,
  846. bool64bit:
  847. if do_read then
  848. begin
  849. CGMessagePos(para.fileinfo,type_e_cant_read_write_type);
  850. error_para := true;
  851. end
  852. else
  853. begin
  854. name := procprefixes[do_read]+'boolean';
  855. readfunctype:=pasbool1type;
  856. end
  857. else
  858. begin
  859. CGMessagePos(para.fileinfo,type_e_cant_read_write_type);
  860. error_para := true;
  861. end;
  862. end;
  863. end;
  864. variantdef :
  865. begin
  866. name:=procprefixes[do_read]+'variant';
  867. include(current_module.moduleflags,mf_uses_variants);
  868. end;
  869. arraydef :
  870. begin
  871. if is_chararray(para.left.resultdef) then
  872. name := procprefixes[do_read]+'pchar_as_array'
  873. else
  874. begin
  875. CGMessagePos(para.fileinfo,type_e_cant_read_write_type);
  876. error_para := true;
  877. end
  878. end;
  879. else
  880. begin
  881. CGMessagePos(para.fileinfo,type_e_cant_read_write_type);
  882. error_para := true;
  883. end;
  884. end;
  885. { iso pascal needs a different handler }
  886. if (m_isolike_io in current_settings.modeswitches) and not(do_read) then
  887. name:=name+'_iso';
  888. { check for length/fractional colon para's }
  889. fracpara:=nil;
  890. lenpara:=nil;
  891. indexpara:=nil;
  892. if assigned(para.right) and
  893. (cpf_is_colon_para in tcallparanode(para.right).callparaflags) then
  894. begin
  895. lenpara := tcallparanode(para.right);
  896. if assigned(lenpara.right) and
  897. (cpf_is_colon_para in tcallparanode(lenpara.right).callparaflags) then
  898. fracpara:=tcallparanode(lenpara.right);
  899. end;
  900. { get the next parameter now already, because we're going }
  901. { to muck around with the pointers }
  902. if assigned(fracpara) then
  903. nextpara := tcallparanode(fracpara.right)
  904. else if assigned(lenpara) then
  905. nextpara := tcallparanode(lenpara.right)
  906. else
  907. nextpara := tcallparanode(para.right);
  908. { check if a fracpara is allowed }
  909. if assigned(fracpara) and not is_real then
  910. begin
  911. CGMessagePos(fracpara.fileinfo,parser_e_illegal_colon_qualifier);
  912. error_para := true;
  913. end
  914. else if assigned(lenpara) and do_read then
  915. begin
  916. { I think this is already filtered out by parsing, but I'm not sure (JM) }
  917. CGMessagePos(lenpara.fileinfo,parser_e_illegal_colon_qualifier);
  918. error_para := true;
  919. end;
  920. { adjust found_error }
  921. found_error := found_error or error_para;
  922. if not error_para then
  923. begin
  924. special_handling:=false;
  925. { create dummy frac/len para's if necessary }
  926. if not do_read then
  927. begin
  928. { difference in default value for floats and the rest :( }
  929. if not is_real then
  930. begin
  931. if not assigned(lenpara) then
  932. begin
  933. if m_isolike_io in current_settings.modeswitches then
  934. lenpara := ccallparanode.create(
  935. cordconstnode.create(-1,s32inttype,false),nil)
  936. else
  937. lenpara := ccallparanode.create(
  938. cordconstnode.create(0,s32inttype,false),nil);
  939. end
  940. else
  941. { make sure we don't pass the successive }
  942. { parameters too. We also already have a }
  943. { reference to the next parameter in }
  944. { nextpara }
  945. lenpara.right := nil;
  946. end
  947. else
  948. begin
  949. if not assigned(lenpara) then
  950. lenpara := ccallparanode.create(
  951. cordconstnode.create(int64(-32767),s32inttype,false),nil);
  952. { also create a default fracpara if necessary }
  953. if not assigned(fracpara) then
  954. fracpara := ccallparanode.create(
  955. cordconstnode.create(int64(-1),s32inttype,false),nil);
  956. { add it to the lenpara }
  957. lenpara.right := fracpara;
  958. if not is_currency(para.left.resultdef) then
  959. begin
  960. { and add the realtype para (this also removes the link }
  961. { to any parameters coming after it) }
  962. fracpara.right := ccallparanode.create(
  963. cordconstnode.create(ord(tfloatdef(para.left.resultdef).floattype),
  964. s32inttype,true),nil);
  965. end
  966. else
  967. fracpara.right:=nil;
  968. end;
  969. if para.left.resultdef.typ=enumdef then
  970. begin
  971. {To write(ln) an enum we need a some extra parameters.}
  972. {Insert a reference to the ord2string index.}
  973. indexpara:=Ccallparanode.create(
  974. Caddrnode.create_internal(
  975. Crttinode.create(Tenumdef(para.left.resultdef),fullrtti,rdt_normal)
  976. ),
  977. nil);
  978. {Insert a reference to the typinfo.}
  979. indexpara:=Ccallparanode.create(
  980. Caddrnode.create_internal(
  981. Crttinode.create(Tenumdef(para.left.resultdef),fullrtti,rdt_ord2str)
  982. ),
  983. indexpara);
  984. {Insert a type conversion to to convert the enum to longint.}
  985. para.left:=Ctypeconvnode.create_internal(para.left,s32inttype);
  986. typecheckpass(para.left);
  987. end;
  988. end
  989. else
  990. begin
  991. {To read(ln) an enum we need a an extra parameter.}
  992. if para.left.resultdef.typ=enumdef then
  993. begin
  994. {Insert a reference to the string2ord index.}
  995. indexpara:=Ccallparanode.create(Caddrnode.create_internal(
  996. Crttinode.create(Tenumdef(para.left.resultdef),fullrtti,rdt_str2ord)
  997. ),nil);
  998. {Insert a type conversion to to convert the enum to longint.}
  999. para.left:=Ctypeconvnode.create_internal(para.left,readfunctype);
  1000. typecheckpass(para.left);
  1001. end;
  1002. { special handling of reading small numbers, because the helpers }
  1003. { expect a longint/card/bestreal var parameter. Use a temp. can't }
  1004. { use functions because then the call to FPC_IOCHECK destroys }
  1005. { their result before we can store it }
  1006. if (readfunctype<>nil) and (para.left.resultdef<>readfunctype) then
  1007. special_handling:=true;
  1008. end;
  1009. if special_handling then
  1010. begin
  1011. { since we're not going to pass the parameter as var-parameter }
  1012. { to the read function, manually check whether the parameter }
  1013. { can be used as var-parameter (e.g., whether it isn't a }
  1014. { property) }
  1015. valid_for_var(para.left,true);
  1016. { create the parameter list: the temp ... }
  1017. temp := ctempcreatenode.create(readfunctype,readfunctype.size,tt_persistent,false);
  1018. addstatement(Tstatementnode(newstatement),temp);
  1019. { ... and the file }
  1020. p1 := ccallparanode.create(ctemprefnode.create(temp),
  1021. filepara.getcopy);
  1022. Tcallparanode(Tcallparanode(p1).right).right:=indexpara;
  1023. { create the call to the helper }
  1024. addstatement(Tstatementnode(newstatement),
  1025. ccallnode.createintern(name,tcallparanode(p1)));
  1026. { assign the result to the original var (this automatically }
  1027. { takes care of range checking) }
  1028. addstatement(Tstatementnode(newstatement),
  1029. cassignmentnode.create(para.left,
  1030. ctemprefnode.create(temp)));
  1031. { release the temp location }
  1032. addstatement(Tstatementnode(newstatement),ctempdeletenode.create(temp));
  1033. { statement of para is used }
  1034. para.left := nil;
  1035. { free the enclosing tcallparanode, but not the }
  1036. { parameters coming after it }
  1037. para.right := nil;
  1038. para.free;
  1039. end
  1040. else
  1041. { read of non s/u-8/16bit, or a write }
  1042. begin
  1043. { add the filepara to the current parameter }
  1044. para.right := filepara.getcopy;
  1045. {Add the lenpara and the indexpara(s) (fracpara and realtype are
  1046. already linked with the lenpara if necessary).}
  1047. if indexpara=nil then
  1048. Tcallparanode(para.right).right:=lenpara
  1049. else
  1050. begin
  1051. if lenpara=nil then
  1052. Tcallparanode(para.right).right:=indexpara
  1053. else
  1054. begin
  1055. Tcallparanode(para.right).right:=lenpara;
  1056. lenpara.right:=indexpara;
  1057. end;
  1058. { indexpara.right:=lenpara;}
  1059. end;
  1060. { in case of writing a chararray, add whether it's zero-based }
  1061. if para.left.resultdef.typ=arraydef then
  1062. para := ccallparanode.create(cordconstnode.create(
  1063. ord(tarraydef(para.left.resultdef).lowrange=0),pasbool1type,false),para)
  1064. else
  1065. { in case of reading an ansistring pass a codepage argument }
  1066. if do_read and is_ansistring(para.left.resultdef) then
  1067. para:=ccallparanode.create(cordconstnode.create(
  1068. getparaencoding(para.left.resultdef),u16inttype,true),para);
  1069. { create the call statement }
  1070. addstatement(Tstatementnode(newstatement),
  1071. ccallnode.createintern(name,para));
  1072. end
  1073. end
  1074. else
  1075. { error_para = true }
  1076. begin
  1077. { free the parameter, since it isn't referenced anywhere anymore }
  1078. para.right := nil;
  1079. para.free;
  1080. if assigned(lenpara) then
  1081. begin
  1082. lenpara.right := nil;
  1083. lenpara.free;
  1084. end;
  1085. if assigned(fracpara) then
  1086. begin
  1087. fracpara.right := nil;
  1088. fracpara.free;
  1089. end;
  1090. end;
  1091. { process next parameter }
  1092. para := nextpara;
  1093. end;
  1094. { if no error, add the write(ln)/read(ln) end calls }
  1095. if not found_error then
  1096. begin
  1097. case inlinenumber of
  1098. in_read_x,
  1099. in_readstr_x:
  1100. name:='fpc_read_end';
  1101. in_write_x,
  1102. in_writestr_x:
  1103. name:='fpc_write_end';
  1104. in_readln_x:
  1105. begin
  1106. name:='fpc_readln_end';
  1107. if m_isolike_io in current_settings.modeswitches then
  1108. name:=name+'_iso';
  1109. end;
  1110. in_writeln_x:
  1111. name:='fpc_writeln_end';
  1112. else
  1113. internalerror(2019050501);
  1114. end;
  1115. addstatement(Tstatementnode(newstatement),ccallnode.createintern(name,filepara.getcopy));
  1116. end;
  1117. handle_text_read_write:=found_error;
  1118. end;
  1119. function Tinlinenode.handle_typed_read_write(filepara,params:Ttertiarynode;var newstatement:Tnode):boolean;
  1120. {Read/write for typed files.}
  1121. const procprefixes:array[boolean,boolean] of string[19]=(('fpc_typed_write','fpc_typed_read'),
  1122. ('fpc_typed_write','fpc_typed_read_iso'));
  1123. procnamesdisplay:array[boolean,boolean] of string[8] = (('Write','Read'),('WriteStr','ReadStr'));
  1124. var found_error,do_read,is_rwstr:boolean;
  1125. para,nextpara:Tcallparanode;
  1126. p1:Tnode;
  1127. temp:Ttempcreatenode;
  1128. begin
  1129. found_error:=false;
  1130. para:=Tcallparanode(params);
  1131. do_read:=inlinenumber in [in_read_x,in_readln_x,in_readstr_x];
  1132. is_rwstr := inlinenumber in [in_readstr_x,in_writestr_x];
  1133. temp:=nil;
  1134. { add the typesize to the filepara }
  1135. if filepara.resultdef.typ=filedef then
  1136. filepara.right := ccallparanode.create(cordconstnode.create(
  1137. tfiledef(filepara.resultdef).typedfiledef.size,s32inttype,true),nil);
  1138. { check for "no parameters" (you need at least one extra para for typed files) }
  1139. if not assigned(para) then
  1140. begin
  1141. CGMessage1(parser_e_wrong_parameter_size,procnamesdisplay[is_rwstr,do_read]);
  1142. found_error := true;
  1143. end;
  1144. { process all parameters }
  1145. while assigned(para) do
  1146. begin
  1147. { check if valid parameter }
  1148. if para.left.nodetype=typen then
  1149. begin
  1150. CGMessagePos(para.left.fileinfo,type_e_cant_read_write_type);
  1151. found_error := true;
  1152. end;
  1153. { support writeln(procvar) }
  1154. if (para.left.resultdef.typ=procvardef) then
  1155. begin
  1156. p1:=ccallnode.create_procvar(nil,para.left);
  1157. typecheckpass(p1);
  1158. para.left:=p1;
  1159. end;
  1160. if filepara.resultdef.typ=filedef then
  1161. inserttypeconv(para.left,tfiledef(filepara.resultdef).typedfiledef);
  1162. if assigned(para.right) and
  1163. (cpf_is_colon_para in tcallparanode(para.right).callparaflags) then
  1164. begin
  1165. CGMessagePos(para.right.fileinfo,parser_e_illegal_colon_qualifier);
  1166. { skip all colon para's }
  1167. nextpara := tcallparanode(tcallparanode(para.right).right);
  1168. while assigned(nextpara) and (cpf_is_colon_para in nextpara.callparaflags) do
  1169. nextpara := tcallparanode(nextpara.right);
  1170. found_error := true;
  1171. end
  1172. else
  1173. { get next parameter }
  1174. nextpara := tcallparanode(para.right);
  1175. { When we have a call, we have a problem: you can't pass the }
  1176. { result of a call as a formal const parameter. Solution: }
  1177. { assign the result to a temp and pass this temp as parameter }
  1178. { This is not very efficient, but write(typedfile,x) is }
  1179. { already slow by itself anyway (no buffering) (JM) }
  1180. { Actually, thge same goes for every non-simple expression }
  1181. { (such as an addition, ...) -> put everything but load nodes }
  1182. { into temps (JM) }
  1183. { of course, this must only be allowed for writes!!! (JM) }
  1184. if not(do_read) and (para.left.nodetype <> loadn) then
  1185. begin
  1186. { create temp for result }
  1187. temp := ctempcreatenode.create(para.left.resultdef,
  1188. para.left.resultdef.size,tt_persistent,false);
  1189. addstatement(Tstatementnode(newstatement),temp);
  1190. { assign result to temp }
  1191. addstatement(Tstatementnode(newstatement),
  1192. cassignmentnode.create(ctemprefnode.create(temp),
  1193. para.left));
  1194. { replace (reused) paranode with temp }
  1195. para.left := ctemprefnode.create(temp);
  1196. end;
  1197. { add fileparameter }
  1198. para.right := filepara.getcopy;
  1199. { create call statment }
  1200. { since the parameters are in the correct order, we have to insert }
  1201. { the statements always at the end of the current block }
  1202. addstatement(Tstatementnode(newstatement),
  1203. Ccallnode.createintern(procprefixes[m_isolike_io in current_settings.modeswitches,do_read],para
  1204. ));
  1205. { if we used a temp, free it }
  1206. if para.left.nodetype = temprefn then
  1207. addstatement(Tstatementnode(newstatement),ctempdeletenode.create(temp));
  1208. { process next parameter }
  1209. para := nextpara;
  1210. end;
  1211. handle_typed_read_write:=found_error;
  1212. end;
  1213. function tinlinenode.handle_read_write: tnode;
  1214. var
  1215. filepara,
  1216. nextpara,
  1217. params : tcallparanode;
  1218. newstatement : tstatementnode;
  1219. newblock : tblocknode;
  1220. filetemp : Ttempcreatenode;
  1221. name : string[31];
  1222. textsym : ttypesym;
  1223. is_typed,
  1224. do_read,
  1225. is_rwstr,
  1226. found_error : boolean;
  1227. begin
  1228. filepara := nil;
  1229. is_typed := false;
  1230. filetemp := nil;
  1231. do_read := inlinenumber in [in_read_x,in_readln_x,in_readstr_x];
  1232. is_rwstr := inlinenumber in [in_readstr_x,in_writestr_x];
  1233. { if we fail, we can quickly exit this way. We must generate something }
  1234. { instead of the inline node, because firstpass will bomb with an }
  1235. { internalerror if it encounters a read/write }
  1236. result := cerrornode.create;
  1237. { reverse the parameters (needed to get the colon parameters in the }
  1238. { correct order when processing write(ln) }
  1239. reverseparameters(tcallparanode(left));
  1240. if is_rwstr then
  1241. begin
  1242. filepara := tcallparanode(left);
  1243. { needs at least two parameters: source/dest string + min. 1 value }
  1244. if not(assigned(filepara)) or
  1245. not(assigned(filepara.right)) then
  1246. begin
  1247. CGMessagePos1(fileinfo,parser_e_wrong_parameter_size,'ReadStr/WriteStr');
  1248. exit;
  1249. end
  1250. else if (filepara.resultdef.typ <> stringdef) then
  1251. begin
  1252. { convert chararray to string, or give an appropriate error message }
  1253. { (if you want to optimize to use shortstring, keep in mind that }
  1254. { readstr internally always uses ansistring, and to account for }
  1255. { chararrays with > 255 characters) }
  1256. inserttypeconv(filepara.left,getansistringdef);
  1257. filepara.resultdef:=filepara.left.resultdef;
  1258. if codegenerror then
  1259. exit;
  1260. end
  1261. end
  1262. else if assigned(left) then
  1263. begin
  1264. { check if we have a file parameter and if yes, what kind it is }
  1265. filepara := tcallparanode(left);
  1266. if (filepara.resultdef.typ=filedef) then
  1267. begin
  1268. if (tfiledef(filepara.resultdef).filetyp=ft_untyped) then
  1269. begin
  1270. CGMessagePos(fileinfo,type_e_no_read_write_for_untyped_file);
  1271. exit;
  1272. end
  1273. else
  1274. begin
  1275. if (tfiledef(filepara.resultdef).filetyp=ft_typed) then
  1276. begin
  1277. if (inlinenumber in [in_readln_x,in_writeln_x]) then
  1278. begin
  1279. CGMessagePos(fileinfo,type_e_no_readln_writeln_for_typed_file);
  1280. exit;
  1281. end;
  1282. is_typed := true;
  1283. end
  1284. end;
  1285. end
  1286. else
  1287. filepara := nil;
  1288. end;
  1289. if assigned(filepara) and
  1290. assigned(filepara.right) and
  1291. (cpf_is_colon_para in tcallparanode(filepara.right).callparaflags) then
  1292. begin
  1293. CGMessagePos(filepara.fileinfo,parser_e_illegal_colon_qualifier);
  1294. { for recovery we can simply continue, because the compiler will
  1295. simply treat the next parameters as normal parameters }
  1296. end;
  1297. { create a blocknode in which the successive write/read statements will be }
  1298. { put, since they belong together. Also create a dummy statement already to }
  1299. { make inserting of additional statements easier }
  1300. newblock:=internalstatements(newstatement);
  1301. if is_rwstr then
  1302. begin
  1303. { create a dummy temp text file that will be used to cache the
  1304. readstr/writestr state. Can't use a global variable in the system
  1305. unit because these can be nested (in case of parameters to
  1306. writestr that are function calls to functions that also call
  1307. readstr/writestr) }
  1308. textsym:=search_system_type('TEXT');
  1309. filetemp:=ctempcreatenode.create(textsym.typedef,textsym.typedef.size,tt_persistent,false);
  1310. addstatement(newstatement,filetemp);
  1311. if (do_read) then
  1312. name:='fpc_setupreadstr_'
  1313. else
  1314. name:='fpc_setupwritestr_';
  1315. name:=name+tstringdef(filepara.resultdef).stringtypname;
  1316. { the file para is a var parameter, but it is properly initialized,
  1317. so it should be actually an out parameter }
  1318. if not(do_read) then
  1319. set_varstate(filepara.left,vs_written,[]);
  1320. { remove the source/destination string parameter from the }
  1321. { parameter chain }
  1322. left:=filepara.right;
  1323. filepara.right:=ccallparanode.create(ctemprefnode.create(filetemp),nil);
  1324. { in case of a writestr() to an ansistring, also pass the string's
  1325. code page }
  1326. if not do_read and
  1327. is_ansistring(filepara.left.resultdef) then
  1328. filepara:=ccallparanode.create(genintconstnode(tstringdef(filepara.left.resultdef).encoding),filepara);
  1329. { pass the temp text file and the source/destination string to the
  1330. setup routine, which will store the string's address in the
  1331. textrec }
  1332. addstatement(newstatement,ccallnode.createintern(name,filepara));
  1333. filepara:=ccallparanode.create(ctemprefnode.create(filetemp),nil);
  1334. end
  1335. { if we don't have a filepara, create one containing the default }
  1336. else if not assigned(filepara) then
  1337. begin
  1338. { since the input/output variables are threadvars loading them into
  1339. a temp once is faster. Create a temp which will hold a pointer to the file }
  1340. filetemp := ctempcreatenode.create(voidpointertype,voidpointertype.size,tt_persistent,true);
  1341. addstatement(newstatement,filetemp);
  1342. { make sure the resultdef of the temp (and as such of the }
  1343. { temprefs coming after it) is set (necessary because the }
  1344. { temprefs will be part of the filepara, of which we need }
  1345. { the resultdef later on and temprefs can only be }
  1346. { typecheckpassed if the resultdef of the temp is known) }
  1347. typecheckpass(tnode(filetemp));
  1348. { assign the address of the file to the temp }
  1349. if do_read then
  1350. name := 'input'
  1351. else
  1352. name := 'output';
  1353. addstatement(newstatement,
  1354. cassignmentnode.create(ctemprefnode.create(filetemp),
  1355. ccallnode.createintern('fpc_get_'+name,nil)));
  1356. { create a new fileparameter as follows: file_type(temp^) }
  1357. { (so that we pass the value and not the address of the temp }
  1358. { to the read/write routine) }
  1359. textsym:=search_system_type('TEXT');
  1360. filepara := ccallparanode.create(ctypeconvnode.create_internal(
  1361. cderefnode.create(ctemprefnode.create(filetemp)),textsym.typedef),nil);
  1362. end
  1363. else
  1364. { remove filepara from the parameter chain }
  1365. begin
  1366. left := filepara.right;
  1367. filepara.right := nil;
  1368. { the file para is a var parameter, but it must be valid already }
  1369. set_varstate(filepara.left,vs_readwritten,[vsf_must_be_valid]);
  1370. { check if we should make a temp to store the result of a complex }
  1371. { expression (better heuristics, anyone?) (JM) }
  1372. if (filepara.left.nodetype <> loadn) then
  1373. begin
  1374. { create a temp which will hold a pointer to the file }
  1375. filetemp := ctempcreatenode.create(voidpointertype,voidpointertype.size,tt_persistent,true);
  1376. { add it to the statements }
  1377. addstatement(newstatement,filetemp);
  1378. { make sure the resultdef of the temp (and as such of the }
  1379. { temprefs coming after it) is set (necessary because the }
  1380. { temprefs will be part of the filepara, of which we need }
  1381. { the resultdef later on and temprefs can only be }
  1382. { typecheckpassed if the resultdef of the temp is known) }
  1383. typecheckpass(tnode(filetemp));
  1384. { assign the address of the file to the temp }
  1385. addstatement(newstatement,
  1386. cassignmentnode.create(ctemprefnode.create(filetemp),
  1387. caddrnode.create_internal(filepara.left)));
  1388. typecheckpass(newstatement.left);
  1389. { create a new fileparameter as follows: file_type(temp^) }
  1390. { (so that we pass the value and not the address of the temp }
  1391. { to the read/write routine) }
  1392. nextpara := ccallparanode.create(ctypeconvnode.create_internal(
  1393. cderefnode.create(ctemprefnode.create(filetemp)),filepara.left.resultdef),nil);
  1394. { replace the old file para with the new one }
  1395. filepara.left := nil;
  1396. filepara.free;
  1397. filepara := nextpara;
  1398. end;
  1399. end;
  1400. { the resultdef of the filepara must be set since it's }
  1401. { used below }
  1402. filepara.get_paratype;
  1403. { now, filepara is nowhere referenced anymore, so we can safely dispose it }
  1404. { if something goes wrong or at the end of the procedure }
  1405. { we're going to reuse the paranodes, so make sure they don't get freed }
  1406. { twice }
  1407. params:=Tcallparanode(left);
  1408. left := nil;
  1409. if is_typed then
  1410. found_error:=handle_typed_read_write(filepara,Ttertiarynode(params),tnode(newstatement))
  1411. else
  1412. found_error:=handle_text_read_write(filepara,Ttertiarynode(params),tnode(newstatement));
  1413. { free the file parameter (it's copied inside the handle_*_read_write methods) }
  1414. filepara.free;
  1415. { if we found an error, simply delete the generated blocknode }
  1416. if found_error then
  1417. begin
  1418. { ensure that the tempinfo is freed correctly by destroying a
  1419. delete node for it
  1420. Note: this might happen legitimately whe parsing a generic that
  1421. passes a undefined type to Write/Read }
  1422. if assigned(filetemp) then
  1423. ctempdeletenode.create(filetemp).free;
  1424. newblock.free
  1425. end
  1426. else
  1427. begin
  1428. { deallocate the temp for the file para if we used one }
  1429. if assigned(filetemp) then
  1430. addstatement(newstatement,ctempdeletenode.create(filetemp));
  1431. { otherwise return the newly generated block of instructions, }
  1432. { but first free the errornode we generated at the beginning }
  1433. result.free;
  1434. result := newblock
  1435. end;
  1436. end;
  1437. function get_val_int_func(def: tdef): string;
  1438. var
  1439. ordtype: tordtype;
  1440. begin
  1441. ordtype := torddef(def).ordtype;
  1442. if not (ordtype in [s64bit,u64bit,s32bit,u32bit,s16bit,u16bit,s8bit,u8bit]) then
  1443. internalerror(2020080101);
  1444. if is_oversizedint(def) then
  1445. begin
  1446. case ordtype of
  1447. s64bit: exit('int64');
  1448. u64bit: exit('qword');
  1449. s32bit: exit('longint');
  1450. u32bit: exit('longword');
  1451. s16bit: exit('smallint');
  1452. u16bit: exit('word');
  1453. else
  1454. internalerror(2013032606);
  1455. end;
  1456. end
  1457. else
  1458. begin
  1459. case ordtype of
  1460. s64bit,s32bit,s16bit,s8bit: exit('sint');
  1461. u64bit,u32bit,u16bit,u8bit: exit('uint');
  1462. else
  1463. internalerror(2013032607);
  1464. end;
  1465. end;
  1466. internalerror(2013032608);
  1467. end;
  1468. function tinlinenode.handle_val: tnode;
  1469. var
  1470. procname,
  1471. suffix : string[31];
  1472. sourcepara,
  1473. destpara,
  1474. codepara,
  1475. sizepara,
  1476. newparas : tcallparanode;
  1477. orgcode,tc : tnode;
  1478. newstatement : tstatementnode;
  1479. newblock : tblocknode;
  1480. tempcode : ttempcreatenode;
  1481. valsinttype : tdef;
  1482. begin
  1483. { for easy exiting if something goes wrong }
  1484. result := cerrornode.create;
  1485. { check the amount of parameters }
  1486. if not(assigned(left)) or
  1487. not(assigned(tcallparanode(left).right)) then
  1488. begin
  1489. CGMessage1(parser_e_wrong_parameter_size,'Val');
  1490. exit;
  1491. end;
  1492. suffix:='';
  1493. { in case we are in a generic definition, we cannot
  1494. do all checks, the parameters might be type parameters }
  1495. if df_generic in current_procinfo.procdef.defoptions then
  1496. begin
  1497. result.Free;
  1498. result:=nil;
  1499. resultdef:=voidtype;
  1500. exit;
  1501. end;
  1502. { retrieve the ValSInt type }
  1503. valsinttype:=search_system_type('VALSINT').typedef;
  1504. { reverse parameters for easier processing }
  1505. reverseparameters(tcallparanode(left));
  1506. { get the parameters }
  1507. tempcode := nil;
  1508. orgcode := nil;
  1509. sizepara := nil;
  1510. sourcepara := tcallparanode(left);
  1511. destpara := tcallparanode(sourcepara.right);
  1512. codepara := tcallparanode(destpara.right);
  1513. { check if codepara is valid }
  1514. if assigned(codepara) and
  1515. (
  1516. not is_integer(codepara.resultdef)
  1517. {$ifndef cpu64bitaddr}
  1518. or is_64bitint(codepara.resultdef)
  1519. {$endif not cpu64bitaddr}
  1520. ) then
  1521. begin
  1522. CGMessagePos1(codepara.fileinfo,type_e_integer_expr_expected,codepara.resultdef.typename);
  1523. exit;
  1524. end;
  1525. { check if dest para is valid }
  1526. if not is_integer(destpara.resultdef) and
  1527. not is_currency(destpara.resultdef) and
  1528. not(destpara.resultdef.typ in [floatdef,enumdef]) then
  1529. begin
  1530. CGMessagePos(destpara.fileinfo,type_e_integer_or_real_expr_expected);
  1531. exit;
  1532. end;
  1533. { we're going to reuse the exisiting para's, so make sure they }
  1534. { won't be disposed }
  1535. left := nil;
  1536. { create the blocknode which will hold the generated statements + }
  1537. { an initial dummy statement }
  1538. newblock:=internalstatements(newstatement);
  1539. { do we need a temp for code? Yes, if no code specified, or if }
  1540. { code is not a valsinttype sized parameter (we already checked }
  1541. { whether the code para, if specified, was an orddef) }
  1542. if not assigned(codepara) or
  1543. (codepara.resultdef.size<>valsinttype.size) then
  1544. begin
  1545. tempcode := ctempcreatenode.create(valsinttype,valsinttype.size,tt_persistent,false);
  1546. addstatement(newstatement,tempcode);
  1547. { set the resultdef of the temp (needed to be able to get }
  1548. { the resultdef of the tempref used in the new code para) }
  1549. typecheckpass(tnode(tempcode));
  1550. { create a temp codepara, but save the original code para to }
  1551. { assign the result to later on }
  1552. if assigned(codepara) then
  1553. begin
  1554. orgcode := codepara.left;
  1555. codepara.left := ctemprefnode.create(tempcode);
  1556. end
  1557. else
  1558. codepara := ccallparanode.create(ctemprefnode.create(tempcode),nil);
  1559. { we need its resultdef later on }
  1560. codepara.get_paratype;
  1561. end
  1562. else if (torddef(codepara.resultdef).ordtype <> torddef(valsinttype).ordtype) then
  1563. { because code is a var parameter, it must match types exactly }
  1564. { however, since it will return values >= 0, both signed and }
  1565. { and unsigned ints of the same size are fine. Since the formal }
  1566. { code para type is sinttype, insert a typecoversion to sint for }
  1567. { unsigned para's }
  1568. begin
  1569. codepara.left := ctypeconvnode.create_internal(codepara.left,valsinttype);
  1570. { make it explicit, oterwise you may get a nonsense range }
  1571. { check error if the cardinal already contained a value }
  1572. { > $7fffffff }
  1573. codepara.get_paratype;
  1574. end;
  1575. { create the procedure name }
  1576. procname := 'fpc_val_';
  1577. case destpara.resultdef.typ of
  1578. orddef:
  1579. begin
  1580. case torddef(destpara.resultdef).ordtype of
  1581. s8bit,s16bit,s32bit,s64bit,
  1582. u8bit,u16bit,u32bit,u64bit:
  1583. begin
  1584. suffix := get_val_int_func(destpara.resultdef) + '_';
  1585. { we also need a destsize para in the case of sint or uint }
  1586. if (suffix = 'sint_') or (suffix = 'uint_') then
  1587. sizepara := ccallparanode.create(cordconstnode.create
  1588. (destpara.resultdef.size,s32inttype,true),nil);
  1589. end;
  1590. scurrency: suffix := 'currency_';
  1591. else
  1592. internalerror(200304225);
  1593. end;
  1594. end;
  1595. floatdef:
  1596. suffix:='real_';
  1597. enumdef:
  1598. begin
  1599. suffix:='enum_';
  1600. sizepara:=Ccallparanode.create(Caddrnode.create_internal(
  1601. Crttinode.create(Tenumdef(destpara.resultdef),fullrtti,rdt_str2ord)
  1602. ),nil);
  1603. end;
  1604. else
  1605. internalerror(2019050515);
  1606. end;
  1607. procname := procname + suffix;
  1608. { play a trick to have tcallnode handle invalid source parameters: }
  1609. { the shortstring-longint val routine by default }
  1610. if (sourcepara.resultdef.typ = stringdef) then
  1611. procname := procname + tstringdef(sourcepara.resultdef).stringtypname
  1612. { zero-based arrays (of char) can be implicitely converted to ansistring, but don't do
  1613. so if not needed because the array is too short }
  1614. else if is_zero_based_array(sourcepara.resultdef) and (sourcepara.resultdef.size>255) then
  1615. procname := procname + 'ansistr'
  1616. else
  1617. procname := procname + 'shortstr';
  1618. { set up the correct parameters for the call: the code para... }
  1619. newparas := codepara;
  1620. { and the source para }
  1621. codepara.right := sourcepara;
  1622. { sizepara either contains nil if none is needed (which is ok, since }
  1623. { then the next statement severes any possible links with other paras }
  1624. { that sourcepara may have) or it contains the necessary size para and }
  1625. { its right field is nil }
  1626. sourcepara.right := sizepara;
  1627. { create the call and assign the result to dest (val helpers are functions).
  1628. Use a trick to prevent a type size mismatch warning to be generated by the
  1629. assignment node. First convert implicitly to the resultdef. This will insert
  1630. the range check. The Second conversion is done explicitly to hide the implicit conversion
  1631. for the assignment node and therefor preventing the warning (PFV)
  1632. The implicit conversion is avoided for enums because implicit conversion between
  1633. longint (which is what fpc_val_enum_shortstr returns) and enumerations is not
  1634. possible. (DM).
  1635. The implicit conversion is also avoided for COMP type if it is handled by FPU (x86)
  1636. to prevent warning about automatic type conversion. }
  1637. if (destpara.resultdef.typ=enumdef) or
  1638. ((destpara.resultdef.typ=floatdef) and (tfloatdef(destpara.resultdef).floattype=s64comp))
  1639. then
  1640. tc:=ccallnode.createfromintrinsic(in_val_x,procname,newparas)
  1641. else
  1642. tc:=ctypeconvnode.create(ccallnode.createfromintrinsic(in_val_x,procname,newparas),destpara.left.resultdef);
  1643. addstatement(newstatement,cassignmentnode.create(
  1644. destpara.left,ctypeconvnode.create_internal(tc,destpara.left.resultdef)));
  1645. { dispose of the enclosing paranode of the destination }
  1646. destpara.left := nil;
  1647. destpara.right := nil;
  1648. destpara.free;
  1649. { check if we used a temp for code and whether we have to store }
  1650. { it to the real code parameter }
  1651. if assigned(orgcode) then
  1652. addstatement(newstatement,cassignmentnode.create(
  1653. orgcode,
  1654. ctypeconvnode.create_internal(
  1655. ctemprefnode.create(tempcode),orgcode.resultdef)));
  1656. { release the temp if we allocated one }
  1657. if assigned(tempcode) then
  1658. addstatement(newstatement,ctempdeletenode.create(tempcode));
  1659. { free the errornode }
  1660. result.free;
  1661. { and return it }
  1662. result := newblock;
  1663. end;
  1664. function tinlinenode.handle_setlength: tnode;
  1665. var
  1666. def: tdef;
  1667. destppn,
  1668. paras: tnode;
  1669. newstatement: tstatementnode;
  1670. ppn: tcallparanode;
  1671. counter,
  1672. dims: longint;
  1673. isarray: boolean;
  1674. begin
  1675. { for easy exiting if something goes wrong }
  1676. result:=cerrornode.create;
  1677. resultdef:=voidtype;
  1678. paras:=left;
  1679. dims:=0;
  1680. if assigned(paras) then
  1681. begin
  1682. { check type of lengths }
  1683. ppn:=tcallparanode(paras);
  1684. while assigned(ppn.right) do
  1685. begin
  1686. set_varstate(ppn.left,vs_read,[vsf_must_be_valid]);
  1687. inserttypeconv(ppn.left,sinttype);
  1688. inc(dims);
  1689. ppn:=tcallparanode(ppn.right);
  1690. end;
  1691. end
  1692. else
  1693. internalerror(2013112912);
  1694. if dims=0 then
  1695. begin
  1696. CGMessage1(parser_e_wrong_parameter_size,'SetLength');
  1697. exit;
  1698. end;
  1699. { last param must be var }
  1700. destppn:=ppn.left;
  1701. valid_for_var(destppn,true);
  1702. set_varstate(destppn,vs_written,[vsf_must_be_valid,vsf_use_hints,vsf_use_hint_for_string_result]);
  1703. { first param must be a string or dynamic array ...}
  1704. isarray:=is_dynamic_array(destppn.resultdef);
  1705. if not((destppn.resultdef.typ=stringdef) or
  1706. isarray) then
  1707. begin
  1708. { possibly generic involved? }
  1709. if df_generic in current_procinfo.procdef.defoptions then
  1710. result:=internalstatements(newstatement)
  1711. else
  1712. CGMessage(type_e_mismatch);
  1713. exit;
  1714. end;
  1715. { only dynamic arrays accept more dimensions }
  1716. if (dims>1) then
  1717. begin
  1718. if (not isarray) then
  1719. CGMessage(type_e_mismatch)
  1720. else
  1721. begin
  1722. { check if the amount of dimensions is valid }
  1723. def:=tarraydef(destppn.resultdef).elementdef;
  1724. counter:=dims;
  1725. while counter > 1 do
  1726. begin
  1727. if not(is_dynamic_array(def)) then
  1728. begin
  1729. CGMessage1(parser_e_wrong_parameter_size,'SetLength');
  1730. break;
  1731. end;
  1732. dec(counter);
  1733. def:=tarraydef(def).elementdef;
  1734. end;
  1735. end;
  1736. end;
  1737. result.free;
  1738. result:=nil;
  1739. end;
  1740. function tinlinenode.handle_copy: tnode;
  1741. procedure do_error(typemismatch:boolean;func:string;fi:tfileposinfo);
  1742. procedure write_dynarray_copy;
  1743. begin
  1744. MessagePos1(fileinfo,sym_e_param_list,'Copy(Dynamic Array;'+sizesinttype.typename+'=`<low>`;'+sizesinttype.typename+'=`<length>`);');
  1745. end;
  1746. begin
  1747. if typemismatch then
  1748. CGMessagePos(fi,type_e_mismatch)
  1749. else
  1750. CGMessagePos1(fi,parser_e_wrong_parameter_size,'Copy');
  1751. if func='' then
  1752. begin
  1753. write_system_parameter_lists('fpc_shortstr_copy');
  1754. write_system_parameter_lists('fpc_char_copy');
  1755. write_system_parameter_lists('fpc_unicodestr_copy');
  1756. if tf_winlikewidestring in target_info.flags then
  1757. write_system_parameter_lists('fpc_widestr_copy');
  1758. write_system_parameter_lists('fpc_ansistr_copy');
  1759. write_dynarray_copy;
  1760. end
  1761. else if func='fpc_dynarray_copy' then
  1762. write_dynarray_copy
  1763. else
  1764. write_system_parameter_lists(func);
  1765. end;
  1766. var
  1767. paras : tnode;
  1768. ppn : tcallparanode;
  1769. paradef : tdef;
  1770. counter : integer;
  1771. minargs,
  1772. maxargs : longint;
  1773. func : string;
  1774. begin
  1775. if not assigned(left) then
  1776. begin
  1777. do_error(false,'',fileinfo);
  1778. exit(cerrornode.create);
  1779. end;
  1780. result:=nil;
  1781. { determine copy function to use based on the first argument,
  1782. also count the number of arguments in this loop }
  1783. counter:=1;
  1784. paras:=left;
  1785. ppn:=tcallparanode(paras);
  1786. while assigned(ppn.right) do
  1787. begin
  1788. inc(counter);
  1789. set_varstate(ppn.left,vs_read,[vsf_must_be_valid]);
  1790. ppn:=tcallparanode(ppn.right);
  1791. end;
  1792. set_varstate(ppn.left,vs_read,[vsf_must_be_valid]);
  1793. paradef:=ppn.left.resultdef;
  1794. { the string variants all require 2 or 3 args, only the array one allows less }
  1795. minargs:=2;
  1796. maxargs:=3;
  1797. func:='';
  1798. if is_ansistring(paradef) then
  1799. begin
  1800. // set resultdef to argument def
  1801. resultdef:=paradef;
  1802. func:='fpc_ansistr_copy';
  1803. end
  1804. else if (is_chararray(paradef) and (paradef.size>255)) or
  1805. ((cs_refcountedstrings in current_settings.localswitches) and is_pchar(paradef)) then
  1806. begin
  1807. // set resultdef to ansistring type since result will be in ansistring codepage
  1808. resultdef:=getansistringdef;
  1809. func:='fpc_ansistr_copy';
  1810. end
  1811. else if is_widestring(paradef) then
  1812. begin
  1813. resultdef:=cwidestringtype;
  1814. func:='fpc_widestr_copy';
  1815. end
  1816. else if is_unicodestring(paradef) or
  1817. is_widechararray(paradef) or
  1818. is_pwidechar(paradef) then
  1819. begin
  1820. resultdef:=cunicodestringtype;
  1821. func:='fpc_unicodestr_copy';
  1822. end
  1823. else
  1824. if is_char(paradef) then
  1825. begin
  1826. resultdef:=cshortstringtype;
  1827. func:='fpc_char_copy';
  1828. end
  1829. else
  1830. if is_dynamic_array(paradef) then
  1831. begin
  1832. minargs:=1;
  1833. resultdef:=paradef;
  1834. func:='fpc_array_to_dynarray_copy';
  1835. end
  1836. else
  1837. if is_open_array(paradef) then
  1838. begin
  1839. minargs:=1;
  1840. resultdef:=carraydef.create(0,-1,tarraydef(paradef).rangedef);
  1841. tarraydef(resultdef).arrayoptions:=tarraydef(resultdef).arrayoptions+[ado_IsDynamicArray];
  1842. tarraydef(resultdef).elementdef:=tarraydef(paradef).elementdef;
  1843. func:='fpc_array_to_dynarray_copy';
  1844. end
  1845. else if counter in [2..3] then
  1846. begin
  1847. resultdef:=cshortstringtype;
  1848. func:='fpc_shortstr_copy';
  1849. end
  1850. else if counter<=maxargs then
  1851. begin
  1852. do_error(true,'',ppn.left.fileinfo);
  1853. exit(cerrornode.create);
  1854. end;
  1855. if (counter<minargs) or (counter>maxargs) then
  1856. begin
  1857. do_error(false,func,fileinfo);
  1858. exit(cerrornode.create);
  1859. end;
  1860. end;
  1861. {$maxfpuregisters 0}
  1862. function getpi : bestreal;
  1863. begin
  1864. {$ifdef x86}
  1865. { x86 has pi in hardware }
  1866. result:=pi;
  1867. {$else x86}
  1868. {$ifdef cpuextended}
  1869. result:=MathPiExtended.Value;
  1870. {$else cpuextended}
  1871. result:=MathPi.Value;
  1872. {$endif cpuextended}
  1873. {$endif x86}
  1874. end;
  1875. function tinlinenode.simplify(forinline : boolean): tnode;
  1876. function do_lowhigh(def:tdef) : tnode;
  1877. var
  1878. v : tconstexprint;
  1879. enum : tenumsym;
  1880. hp : tnode;
  1881. i : integer;
  1882. begin
  1883. case def.typ of
  1884. orddef:
  1885. begin
  1886. set_varstate(left,vs_read,[]);
  1887. if inlinenumber=in_low_x then
  1888. v:=torddef(def).low
  1889. else
  1890. v:=torddef(def).high;
  1891. hp:=cordconstnode.create(v,def,true);
  1892. typecheckpass(hp);
  1893. do_lowhigh:=hp;
  1894. end;
  1895. enumdef:
  1896. begin
  1897. set_varstate(left,vs_read,[]);
  1898. if inlinenumber=in_high_x then
  1899. v:=tenumdef(def).maxval
  1900. else
  1901. v:=tenumdef(def).minval;
  1902. enum:=nil;
  1903. for i := 0 to tenumdef(def).symtable.SymList.Count - 1 do
  1904. if tenumsym(tenumdef(def).symtable.SymList[i]).value=v then
  1905. begin
  1906. enum:=tenumsym(tenumdef(def).symtable.SymList[i]);
  1907. break;
  1908. end;
  1909. if not assigned(enum) then
  1910. internalerror(309993)
  1911. else
  1912. hp:=genenumnode(enum);
  1913. do_lowhigh:=hp;
  1914. end;
  1915. else
  1916. internalerror(87);
  1917. end;
  1918. end;
  1919. function getconstrealvalue : bestreal;
  1920. begin
  1921. case left.nodetype of
  1922. ordconstn:
  1923. getconstrealvalue:=tordconstnode(left).value;
  1924. realconstn:
  1925. getconstrealvalue:=trealconstnode(left).value_real;
  1926. else
  1927. internalerror(309992);
  1928. end;
  1929. end;
  1930. procedure setconstrealvalue(r : bestreal);
  1931. begin
  1932. result:=crealconstnode.create(r,pbestrealtype^);
  1933. end;
  1934. function handle_ln_const(r : bestreal) : tnode;
  1935. begin
  1936. if r<=0.0 then
  1937. if floating_point_range_check_error then
  1938. begin
  1939. result:=crealconstnode.create(0,pbestrealtype^);
  1940. CGMessage(type_e_wrong_math_argument)
  1941. end
  1942. else
  1943. begin
  1944. if r=0.0 then
  1945. result:=crealconstnode.create(MathNegInf.Value,pbestrealtype^)
  1946. else
  1947. result:=crealconstnode.create(MathQNaN.Value,pbestrealtype^)
  1948. end
  1949. else
  1950. result:=crealconstnode.create(ln(r),pbestrealtype^)
  1951. end;
  1952. function handle_sqrt_const(r : bestreal) : tnode;
  1953. begin
  1954. if r<0.0 then
  1955. if floating_point_range_check_error then
  1956. begin
  1957. result:=crealconstnode.create(0,pbestrealtype^);
  1958. CGMessage(type_e_wrong_math_argument)
  1959. end
  1960. else
  1961. result:=crealconstnode.create(MathQNaN.Value,pbestrealtype^)
  1962. else
  1963. result:=crealconstnode.create(sqrt(r),pbestrealtype^)
  1964. end;
  1965. function handle_const_sar : tnode;
  1966. var
  1967. vl,vl2 : TConstExprInt;
  1968. bits,shift: integer;
  1969. mask : qword;
  1970. def : tdef;
  1971. begin
  1972. result:=nil;
  1973. if (left.nodetype=ordconstn) or ((left.nodetype=callparan) and (tcallparanode(left).left.nodetype=ordconstn)) then
  1974. begin
  1975. if (left.nodetype=callparan) and
  1976. assigned(tcallparanode(left).right) then
  1977. begin
  1978. vl:=tordconstnode(tcallparanode(left).left).value;
  1979. if forinline then
  1980. case resultdef.size of
  1981. 1,2,4:
  1982. vl:=vl and byte($1f);
  1983. 8:
  1984. vl:=vl and byte($3f);
  1985. else
  1986. internalerror(2013122303);
  1987. end;
  1988. if (tcallparanode(tcallparanode(left).right).left.nodetype=ordconstn) then
  1989. begin
  1990. def:=tcallparanode(tcallparanode(left).right).left.resultdef;
  1991. vl2:=tordconstnode(tcallparanode(tcallparanode(left).right).left).value;
  1992. end
  1993. else if vl=0 then
  1994. begin
  1995. result:=tcallparanode(tcallparanode(left).right).left;
  1996. tcallparanode(tcallparanode(left).right).left:=nil;
  1997. exit;
  1998. end
  1999. else
  2000. exit;
  2001. end
  2002. else
  2003. begin
  2004. def:=left.resultdef;
  2005. vl:=1;
  2006. vl2:=tordconstnode(left).value;
  2007. end;
  2008. bits:=def.size*8;
  2009. shift:=vl.svalue and (bits-1);
  2010. case bits of
  2011. 8:
  2012. mask:=$ff;
  2013. 16:
  2014. mask:=$ffff;
  2015. 32:
  2016. mask:=$ffffffff;
  2017. 64:
  2018. mask:=qword($ffffffffffffffff);
  2019. else
  2020. mask:=qword(1 shl bits)-1;
  2021. end;
  2022. {$push}
  2023. {$r-,q-}
  2024. if shift=0 then
  2025. result:=cordconstnode.create(vl2.svalue,def,false)
  2026. else if vl2.svalue<0 then
  2027. result:=cordconstnode.create(((vl2.svalue shr shift) or (mask shl (bits-shift))) and mask,def,false)
  2028. else
  2029. result:=cordconstnode.create((vl2.svalue shr shift) and mask,def,false);
  2030. {$pop}
  2031. end
  2032. else if (left.nodetype=callparan) and assigned(tcallparanode(left).right) and
  2033. (tcallparanode(tcallparanode(left).right).left.nodetype=ordconstn) then
  2034. begin
  2035. def:=tcallparanode(tcallparanode(left).right).left.resultdef;
  2036. vl2:=tordconstnode(tcallparanode(tcallparanode(left).right).left).value;
  2037. { sar(0,x) is 0 }
  2038. { sar32(ffffffff,x) is ffffffff, etc. }
  2039. if ((vl2=0) or
  2040. ((resultdef.size=1) and (shortint(vl2.svalue)=-1)) or
  2041. ((resultdef.size=2) and (smallint(vl2.svalue)=-1)) or
  2042. ((resultdef.size=4) and (longint(vl2.svalue)=-1)) or
  2043. ((resultdef.size=8) and (int64(vl2.svalue)=-1))) and
  2044. ((cs_opt_level4 in current_settings.optimizerswitches) or
  2045. not might_have_sideeffects(tcallparanode(left).left)) then
  2046. begin
  2047. if vl2=0 then
  2048. result:=cordconstnode.create(0,resultdef,true)
  2049. else
  2050. result:=cordconstnode.create(-1,resultdef,true);
  2051. end;
  2052. end;
  2053. end;
  2054. function handle_const_rox : tnode;
  2055. var
  2056. vl,vl2 : TConstExprInt;
  2057. bits,shift: integer;
  2058. def : tdef;
  2059. begin
  2060. result:=nil;
  2061. if (left.nodetype=ordconstn) or ((left.nodetype=callparan) and (tcallparanode(left).left.nodetype=ordconstn)) then
  2062. begin
  2063. if (left.nodetype=callparan) and
  2064. assigned(tcallparanode(left).right) then
  2065. begin
  2066. vl:=tordconstnode(tcallparanode(left).left).value;
  2067. if forinline then
  2068. case resultdef.size of
  2069. { unlike shifts, for rotates, when masking out the higher bits
  2070. of the rotate count, we go all the way down to byte, because
  2071. it doesn't matter, it produces the same result, since it's a rotate }
  2072. 1:
  2073. vl:=vl and byte($07);
  2074. 2:
  2075. vl:=vl and byte($0f);
  2076. 4:
  2077. vl:=vl and byte($1f);
  2078. 8:
  2079. vl:=vl and byte($3f);
  2080. else
  2081. internalerror(2013122304);
  2082. end;
  2083. if (tcallparanode(tcallparanode(left).right).left.nodetype=ordconstn) then
  2084. begin
  2085. def:=tcallparanode(tcallparanode(left).right).left.resultdef;
  2086. vl2:=tordconstnode(tcallparanode(tcallparanode(left).right).left).value;
  2087. end
  2088. else if vl=0 then
  2089. begin
  2090. result:=tcallparanode(tcallparanode(left).right).left;
  2091. tcallparanode(tcallparanode(left).right).left:=nil;
  2092. exit;
  2093. end
  2094. else
  2095. exit;
  2096. end
  2097. else
  2098. begin
  2099. def:=left.resultdef;
  2100. vl:=1;
  2101. vl2:=tordconstnode(left).value;
  2102. end;
  2103. bits:=def.size*8;
  2104. shift:=vl.svalue and (bits-1);
  2105. {$push}
  2106. {$r-,q-}
  2107. if shift=0 then
  2108. result:=cordconstnode.create(vl2.svalue,def,false)
  2109. else
  2110. case inlinenumber of
  2111. in_ror_x,in_ror_x_y:
  2112. case def.size of
  2113. 1:
  2114. result:=cordconstnode.create(RorByte(Byte(vl2.svalue),shift),def,false);
  2115. 2:
  2116. result:=cordconstnode.create(RorWord(Word(vl2.svalue),shift),def,false);
  2117. 4:
  2118. result:=cordconstnode.create(RorDWord(DWord(vl2.svalue),shift),def,false);
  2119. 8:
  2120. result:=cordconstnode.create(RorQWord(QWord(vl2.svalue),shift),def,false);
  2121. else
  2122. internalerror(2011061903);
  2123. end;
  2124. in_rol_x,in_rol_x_y:
  2125. case def.size of
  2126. 1:
  2127. result:=cordconstnode.create(RolByte(Byte(vl2.svalue),shift),def,false);
  2128. 2:
  2129. result:=cordconstnode.create(RolWord(Word(vl2.svalue),shift),def,false);
  2130. 4:
  2131. result:=cordconstnode.create(RolDWord(DWord(vl2.svalue),shift),def,false);
  2132. 8:
  2133. result:=cordconstnode.create(RolQWord(QWord(vl2.svalue),shift),def,false);
  2134. else
  2135. internalerror(2011061902);
  2136. end;
  2137. else
  2138. internalerror(2011061901);
  2139. end;
  2140. {$pop}
  2141. end
  2142. else if (left.nodetype=callparan) and assigned(tcallparanode(left).right) and
  2143. (tcallparanode(tcallparanode(left).right).left.nodetype=ordconstn) then
  2144. begin
  2145. def:=tcallparanode(tcallparanode(left).right).left.resultdef;
  2146. vl2:=tordconstnode(tcallparanode(tcallparanode(left).right).left).value;
  2147. { rol/ror are unsigned operations, so cut off upper bits }
  2148. case resultdef.size of
  2149. 1:
  2150. vl2:=vl2 and byte($ff);
  2151. 2:
  2152. vl2:=vl2 and word($ffff);
  2153. 4:
  2154. vl2:=vl2 and dword($ffffffff);
  2155. 8:
  2156. vl2:=vl2 and qword($ffffffffffffffff);
  2157. else
  2158. internalerror(2017050101);
  2159. end;
  2160. { rol(0,x) and ror(0,x) are 0 }
  2161. { rol32(ffffffff,x) and ror32(ffffffff,x) are ffffffff, etc. }
  2162. if ((vl2=0) or
  2163. ((resultdef.size=1) and (vl2=$ff)) or
  2164. ((resultdef.size=2) and (vl2=$ffff)) or
  2165. ((resultdef.size=4) and (vl2=$ffffffff)) or
  2166. ((resultdef.size=8) and (vl2.uvalue=qword($ffffffffffffffff)))) and
  2167. ((cs_opt_level4 in current_settings.optimizerswitches) or
  2168. not might_have_sideeffects(tcallparanode(left).left)) then
  2169. result:=cordconstnode.create(vl2,resultdef,true);
  2170. end;
  2171. end;
  2172. function is_minmax_deterministic(var node: tordconstnode; const DoMax: Boolean; out res: Boolean): Boolean;
  2173. begin
  2174. Result := False;
  2175. if not is_integer(resultdef) then
  2176. InternalError(2024031501);
  2177. if (node.value <= torddef(resultdef).low) then
  2178. begin
  2179. res := not DoMax;
  2180. Exit(True);
  2181. end
  2182. else if (node.value >= torddef(resultdef).high) then
  2183. begin
  2184. res := DoMax;
  2185. Exit(True);
  2186. end
  2187. end;
  2188. var
  2189. hp,hp2 : tnode;
  2190. vl,vl2 : TConstExprInt;
  2191. vr : bestreal;
  2192. helperres : Boolean;
  2193. begin { simplify }
  2194. result:=nil;
  2195. { handle intern constant functions in separate case }
  2196. if inf_inlineconst in inlinenodeflags then
  2197. begin
  2198. { no parameters? }
  2199. if not assigned(left) then
  2200. internalerror(200501231)
  2201. else
  2202. begin
  2203. vl:=0;
  2204. vl2:=0; { second parameter Ex: ptr(vl,vl2) }
  2205. case left.nodetype of
  2206. realconstn :
  2207. begin
  2208. { Real functions are all handled with internproc below }
  2209. CGMessage1(type_e_integer_expr_expected,left.resultdef.typename)
  2210. end;
  2211. ordconstn :
  2212. vl:=tordconstnode(left).value;
  2213. callparan :
  2214. begin
  2215. { both exists, else it was not generated }
  2216. vl:=tordconstnode(tcallparanode(left).left).value;
  2217. vl2:=tordconstnode(tcallparanode(tcallparanode(left).right).left).value;
  2218. end;
  2219. else
  2220. CGMessage(parser_e_illegal_expression);
  2221. end;
  2222. case inlinenumber of
  2223. in_const_abs :
  2224. if vl.signed then
  2225. hp:=create_simplified_ord_const(abs(vl.svalue),resultdef,forinline,false)
  2226. else
  2227. hp:=create_simplified_ord_const(vl.uvalue,resultdef,forinline,false);
  2228. in_const_sqr:
  2229. if vl.signed then
  2230. hp:=create_simplified_ord_const(sqr(vl.svalue),resultdef,forinline,false)
  2231. else
  2232. hp:=create_simplified_ord_const(sqr(vl.uvalue),resultdef,forinline,false);
  2233. in_const_odd :
  2234. hp:=cordconstnode.create(qword(odd(int64(vl))),pasbool1type,true);
  2235. in_const_swap_word :
  2236. hp:=cordconstnode.create((vl and $ff) shl 8+(vl shr 8),left.resultdef,true);
  2237. in_const_swap_long :
  2238. hp:=cordconstnode.create((vl and $ffff) shl 16+(vl shr 16),left.resultdef,true);
  2239. in_const_swap_qword :
  2240. hp:=cordconstnode.create((vl and $ffffffff) shl 32+(vl shr 32),left.resultdef,true);
  2241. in_const_ptr:
  2242. begin
  2243. {Don't construct pointers from negative values.}
  2244. if (vl.signed and (vl.svalue<0)) or (vl2.signed and (vl2.svalue<0)) then
  2245. cgmessage(parser_e_range_check_error);
  2246. {$if defined(i8086)}
  2247. hp:=cpointerconstnode.create((vl2.uvalue shl 16)+vl.uvalue,voidfarpointertype);
  2248. {$elseif defined(i386)}
  2249. hp:=cpointerconstnode.create((vl2.uvalue shl 4)+vl.uvalue,voidnearfspointertype);
  2250. {$else}
  2251. hp:=cpointerconstnode.create((vl2.uvalue shl 4)+vl.uvalue,voidpointertype);
  2252. {$endif}
  2253. end;
  2254. in_const_eh_return_data_regno:
  2255. begin
  2256. vl:=eh_return_data_regno(vl.svalue);
  2257. if vl=-1 then
  2258. CGMessagePos(left.fileinfo,type_e_range_check_error_bounds);
  2259. hp:=genintconstnode(vl);
  2260. end;
  2261. else
  2262. internalerror(88);
  2263. end;
  2264. end;
  2265. if hp=nil then
  2266. hp:=cerrornode.create;
  2267. result:=hp;
  2268. end
  2269. else
  2270. begin
  2271. case inlinenumber of
  2272. in_lo_long,
  2273. in_hi_long,
  2274. in_lo_qword,
  2275. in_hi_qword,
  2276. in_lo_word,
  2277. in_hi_word :
  2278. begin
  2279. if left.nodetype=ordconstn then
  2280. begin
  2281. case inlinenumber of
  2282. in_lo_word :
  2283. result:=cordconstnode.create(tordconstnode(left).value and $ff,u8inttype,true);
  2284. in_hi_word :
  2285. result:=cordconstnode.create(tordconstnode(left).value shr 8,u8inttype,true);
  2286. in_lo_long :
  2287. result:=cordconstnode.create(tordconstnode(left).value and $ffff,u16inttype,true);
  2288. in_hi_long :
  2289. result:=cordconstnode.create(tordconstnode(left).value shr 16,u16inttype,true);
  2290. in_lo_qword :
  2291. result:=cordconstnode.create(tordconstnode(left).value and $ffffffff,u32inttype,true);
  2292. in_hi_qword :
  2293. result:=cordconstnode.create(tordconstnode(left).value shr 32,u32inttype,true);
  2294. else
  2295. internalerror(2019050514);
  2296. end;
  2297. end;
  2298. end;
  2299. in_ord_x:
  2300. begin
  2301. case left.resultdef.typ of
  2302. orddef :
  2303. begin
  2304. case torddef(left.resultdef).ordtype of
  2305. pasbool1,
  2306. pasbool8,
  2307. uchar:
  2308. begin
  2309. { change to byte() }
  2310. result:=ctypeconvnode.create_internal(left,u8inttype);
  2311. left:=nil;
  2312. end;
  2313. pasbool16,
  2314. uwidechar :
  2315. begin
  2316. { change to word() }
  2317. result:=ctypeconvnode.create_internal(left,u16inttype);
  2318. left:=nil;
  2319. end;
  2320. pasbool32 :
  2321. begin
  2322. { change to dword() }
  2323. result:=ctypeconvnode.create_internal(left,u32inttype);
  2324. left:=nil;
  2325. end;
  2326. pasbool64 :
  2327. begin
  2328. { change to qword() }
  2329. result:=ctypeconvnode.create_internal(left,u64inttype);
  2330. left:=nil;
  2331. end;
  2332. bool8bit:
  2333. begin
  2334. { change to shortint() }
  2335. result:=ctypeconvnode.create_internal(left,s8inttype);
  2336. left:=nil;
  2337. end;
  2338. bool16bit :
  2339. begin
  2340. { change to smallint() }
  2341. result:=ctypeconvnode.create_internal(left,s16inttype);
  2342. left:=nil;
  2343. end;
  2344. bool32bit :
  2345. begin
  2346. { change to longint() }
  2347. result:=ctypeconvnode.create_internal(left,s32inttype);
  2348. left:=nil;
  2349. end;
  2350. bool64bit :
  2351. begin
  2352. { change to int64() }
  2353. result:=ctypeconvnode.create_internal(left,s64inttype);
  2354. left:=nil;
  2355. end;
  2356. uvoid :
  2357. CGMessage1(type_e_ordinal_expr_expected,left.resultdef.typename);
  2358. else
  2359. begin
  2360. { all other orddef need no transformation }
  2361. result:=left;
  2362. left:=nil;
  2363. end;
  2364. end;
  2365. end;
  2366. enumdef :
  2367. begin
  2368. result:=ctypeconvnode.create_internal(left,s32inttype);
  2369. left:=nil;
  2370. end;
  2371. undefineddef :
  2372. begin
  2373. { we just create a constant 0 here, that's marked as a
  2374. parameter }
  2375. result:=cordconstnode.create(0,s32inttype,false);
  2376. include(result.flags,nf_generic_para);
  2377. left:=nil;
  2378. end;
  2379. pointerdef :
  2380. begin
  2381. if m_mac in current_settings.modeswitches then
  2382. begin
  2383. result:=ctypeconvnode.create_internal(left,ptruinttype);
  2384. left:=nil;
  2385. end
  2386. end;
  2387. else
  2388. internalerror(2019050513);
  2389. end;
  2390. (*
  2391. if (left.nodetype=ordconstn) then
  2392. begin
  2393. result:=cordconstnode.create(
  2394. tordconstnode(left).value,sinttype,true);
  2395. end
  2396. else if (m_mac in current_settings.modeswitches) and
  2397. (left.ndoetype=pointerconstn) then
  2398. result:=cordconstnode.create(
  2399. tpointerconstnode(left).value,ptruinttype,true);
  2400. *)
  2401. end;
  2402. in_chr_byte:
  2403. begin
  2404. { convert to explicit char() }
  2405. result:=ctypeconvnode.create_internal(left,cansichartype);
  2406. left:=nil;
  2407. end;
  2408. in_length_x:
  2409. begin
  2410. case left.resultdef.typ of
  2411. stringdef :
  2412. begin
  2413. if (left.nodetype=stringconstn) then
  2414. begin
  2415. result:=cordconstnode.create(
  2416. tstringconstnode(left).len,sinttype,true);
  2417. end;
  2418. end;
  2419. orddef :
  2420. begin
  2421. { length of char is always one }
  2422. if is_char(left.resultdef) or
  2423. is_widechar(left.resultdef) then
  2424. begin
  2425. result:=cordconstnode.create(1,sinttype,false);
  2426. end
  2427. end;
  2428. arraydef :
  2429. begin
  2430. if (left.nodetype=stringconstn) then
  2431. begin
  2432. result:=cordconstnode.create(
  2433. tstringconstnode(left).len,sinttype,true);
  2434. end
  2435. else if not is_open_array(left.resultdef) and
  2436. not is_array_of_const(left.resultdef) and
  2437. not is_dynamic_array(left.resultdef) then
  2438. result:=genintconstnode(tarraydef(left.resultdef).highrange-
  2439. tarraydef(left.resultdef).lowrange+1,sizesinttype);
  2440. end;
  2441. else
  2442. ;
  2443. end;
  2444. end;
  2445. in_assigned_x:
  2446. begin
  2447. if is_constnode(tcallparanode(left).left) or
  2448. (tcallparanode(left).left.nodetype = pointerconstn) then
  2449. begin
  2450. { let an add node figure it out }
  2451. result:=caddnode.create(unequaln,tcallparanode(left).left,cnilnode.create);
  2452. tcallparanode(left).left := nil;
  2453. end;
  2454. end;
  2455. in_pred_x,
  2456. in_succ_x:
  2457. begin
  2458. case left.nodetype of
  2459. ordconstn:
  2460. begin
  2461. if inlinenumber=in_succ_x then
  2462. vl:=tordconstnode(left).value+1
  2463. else
  2464. vl:=tordconstnode(left).value-1;
  2465. if is_integer(left.resultdef) then
  2466. { the type of the original integer constant is irrelevant,
  2467. it should be automatically adapted to the new value
  2468. (except when inlining) }
  2469. result:=create_simplified_ord_const(vl,resultdef,forinline,cs_check_range in localswitches)
  2470. else
  2471. { check the range for enums, chars, booleans }
  2472. result:=cordconstnode.create(vl,left.resultdef,not(nf_internal in flags));
  2473. result.flags:=result.flags+(flags*[nf_internal]);
  2474. end;
  2475. addn,
  2476. subn:
  2477. begin
  2478. { fold succ/pred in child add/sub nodes with a constant if possible:
  2479. - no overflow/range checking
  2480. - equal types
  2481. }
  2482. if ([cs_check_overflow,cs_check_range]*current_settings.localswitches)=[] then
  2483. begin
  2484. if inlinenumber=in_succ_x then
  2485. vl:=1
  2486. else
  2487. vl:=-1;
  2488. if (taddnode(left).left.nodetype=ordconstn) and equal_defs(resultdef,taddnode(left).left.resultdef) then
  2489. begin
  2490. tordconstnode(taddnode(left).left).value:=tordconstnode(taddnode(left).left).value+vl;
  2491. result:=left;
  2492. left:=nil;
  2493. end
  2494. else if (taddnode(left).right.nodetype=ordconstn) and equal_defs(resultdef,taddnode(left).right.resultdef) then
  2495. begin
  2496. if left.nodetype=subn then
  2497. tordconstnode(taddnode(left).right).value:=tordconstnode(taddnode(left).right).value-vl
  2498. else
  2499. tordconstnode(taddnode(left).right).value:=tordconstnode(taddnode(left).right).value+vl;
  2500. result:=left;
  2501. left:=nil;
  2502. end;
  2503. end;
  2504. end;
  2505. else
  2506. ;
  2507. end;
  2508. end;
  2509. in_low_x,
  2510. in_high_x:
  2511. begin
  2512. case left.resultdef.typ of
  2513. orddef,
  2514. enumdef:
  2515. begin
  2516. result:=do_lowhigh(left.resultdef);
  2517. end;
  2518. setdef:
  2519. begin
  2520. result:=do_lowhigh(tsetdef(left.resultdef).elementdef);
  2521. end;
  2522. arraydef:
  2523. begin
  2524. if (inlinenumber=in_low_x) then
  2525. begin
  2526. result:=cordconstnode.create(int64(tarraydef(
  2527. left.resultdef).lowrange),tarraydef(left.resultdef).rangedef,true);
  2528. end
  2529. else if not is_open_array(left.resultdef) and
  2530. not is_array_of_const(left.resultdef) and
  2531. not is_dynamic_array(left.resultdef) then
  2532. result:=cordconstnode.create(int64(tarraydef(left.resultdef).highrange),
  2533. tarraydef(left.resultdef).rangedef,true);
  2534. end;
  2535. stringdef:
  2536. begin
  2537. if inlinenumber=in_low_x then
  2538. begin
  2539. if is_dynamicstring(left.resultdef) and
  2540. not(cs_zerobasedstrings in current_settings.localswitches) then
  2541. result:=cordconstnode.create(1,u8inttype,false)
  2542. else
  2543. result:=cordconstnode.create(0,u8inttype,false);
  2544. end
  2545. else if not is_dynamicstring(left.resultdef) then
  2546. result:=cordconstnode.create(tstringdef(left.resultdef).len,u8inttype,true)
  2547. end;
  2548. undefineddef:
  2549. begin
  2550. result:=cordconstnode.create(0,u8inttype,false);
  2551. end;
  2552. errordef:
  2553. ;
  2554. else
  2555. internalerror(2019050512);
  2556. end;
  2557. end;
  2558. in_exp_real :
  2559. begin
  2560. if left.nodetype in [ordconstn,realconstn] then
  2561. begin
  2562. result:=crealconstnode.create(exp(getconstrealvalue),pbestrealtype^);
  2563. if (trealconstnode(result).value_real=MathInf.Value) and
  2564. floating_point_range_check_error then
  2565. begin
  2566. result:=crealconstnode.create(0,pbestrealtype^);
  2567. CGMessage(parser_e_range_check_error);
  2568. end;
  2569. end
  2570. end;
  2571. in_trunc_real :
  2572. begin
  2573. if left.nodetype in [ordconstn,realconstn] then
  2574. begin
  2575. vr:=getconstrealvalue;
  2576. if (vr>=9223372036854775807.99) or (vr<=-9223372036854775808.0) then
  2577. begin
  2578. message3(type_e_range_check_error_bounds,realtostr(vr),'-9223372036854775808.0','9223372036854775807.99..');
  2579. result:=cordconstnode.create(1,s64inttype,false)
  2580. end
  2581. else
  2582. result:=cordconstnode.create(trunc(vr),s64inttype,true)
  2583. end
  2584. end;
  2585. in_round_real :
  2586. begin
  2587. { can't evaluate while inlining, may depend on fpu setting }
  2588. if (not forinline) and
  2589. (left.nodetype in [ordconstn,realconstn]) then
  2590. begin
  2591. vr:=getconstrealvalue;
  2592. if (vr>=9223372036854775807.5) or (vr<=-9223372036854775808.5) then
  2593. begin
  2594. message3(type_e_range_check_error_bounds,realtostr(vr),'-9223372036854775808.49..','9223372036854775807.49..');
  2595. result:=cordconstnode.create(1,s64inttype,false)
  2596. end
  2597. else
  2598. result:=cordconstnode.create(round(vr),s64inttype,true)
  2599. end
  2600. end;
  2601. in_frac_real :
  2602. begin
  2603. if left.nodetype in [ordconstn,realconstn] then
  2604. setconstrealvalue(frac(getconstrealvalue))
  2605. end;
  2606. in_int_real :
  2607. begin
  2608. if left.nodetype in [ordconstn,realconstn] then
  2609. setconstrealvalue(int(getconstrealvalue));
  2610. end;
  2611. in_pi_real :
  2612. begin
  2613. if block_type=bt_const then
  2614. setconstrealvalue(getpi)
  2615. end;
  2616. in_cos_real :
  2617. begin
  2618. if left.nodetype in [ordconstn,realconstn] then
  2619. setconstrealvalue(cos(getconstrealvalue))
  2620. end;
  2621. in_sin_real :
  2622. begin
  2623. if left.nodetype in [ordconstn,realconstn] then
  2624. setconstrealvalue(sin(getconstrealvalue))
  2625. end;
  2626. in_arctan_real :
  2627. begin
  2628. if left.nodetype in [ordconstn,realconstn] then
  2629. setconstrealvalue(arctan(getconstrealvalue))
  2630. end;
  2631. in_abs_real :
  2632. begin
  2633. if left.nodetype in [ordconstn,realconstn] then
  2634. setconstrealvalue(abs(getconstrealvalue))
  2635. end;
  2636. in_abs_long:
  2637. begin
  2638. if left.nodetype=ordconstn then
  2639. begin
  2640. if tordconstnode(left).value<0 then
  2641. result:=cordconstnode.create((-tordconstnode(left).value),resultdef,false)
  2642. else
  2643. result:=cordconstnode.create((tordconstnode(left).value),resultdef,false);
  2644. end
  2645. end;
  2646. in_sqr_real :
  2647. begin
  2648. if left.nodetype in [ordconstn,realconstn] then
  2649. setconstrealvalue(sqr(getconstrealvalue))
  2650. end;
  2651. in_sqrt_real :
  2652. begin
  2653. if left.nodetype in [ordconstn,realconstn] then
  2654. result:=handle_sqrt_const(getconstrealvalue);
  2655. end;
  2656. in_ln_real :
  2657. begin
  2658. if left.nodetype in [ordconstn,realconstn] then
  2659. result:=handle_ln_const(getconstrealvalue);
  2660. end;
  2661. in_assert_x_y :
  2662. begin
  2663. if not(cs_do_assertion in current_settings.localswitches) then
  2664. { we need a valid node, so insert a nothingn }
  2665. result:=cnothingnode.create;
  2666. end;
  2667. in_sar_x,
  2668. in_sar_x_y :
  2669. begin
  2670. result:=handle_const_sar;
  2671. end;
  2672. in_rol_x,
  2673. in_rol_x_y,
  2674. in_ror_x,
  2675. in_ror_x_y :
  2676. result:=handle_const_rox;
  2677. in_bsf_x:
  2678. begin
  2679. if left.nodetype=ordconstn then
  2680. begin
  2681. case left.resultdef.size of
  2682. 1:
  2683. result:=cordconstnode.create(BsfByte(Byte(tordconstnode(left).value.uvalue)),resultdef,false);
  2684. 2:
  2685. result:=cordconstnode.create(BsfWord(Word(tordconstnode(left).value.uvalue)),resultdef,false);
  2686. 4:
  2687. result:=cordconstnode.create(BsfDWord(DWord(tordconstnode(left).value.uvalue)),resultdef,false);
  2688. 8:
  2689. result:=cordconstnode.create(BsfQWord(QWord(tordconstnode(left).value.uvalue)),resultdef,false);
  2690. else
  2691. internalerror(2017042401);
  2692. end;
  2693. end;
  2694. end;
  2695. in_bsr_x :
  2696. begin
  2697. if left.nodetype=ordconstn then
  2698. begin
  2699. case left.resultdef.size of
  2700. 1:
  2701. result:=cordconstnode.create(BsrByte(Byte(tordconstnode(left).value.uvalue)),resultdef,false);
  2702. 2:
  2703. result:=cordconstnode.create(BsrWord(Word(tordconstnode(left).value.uvalue)),resultdef,false);
  2704. 4:
  2705. result:=cordconstnode.create(BsrDWord(DWord(tordconstnode(left).value.uvalue)),resultdef,false);
  2706. 8:
  2707. result:=cordconstnode.create(BsrQWord(QWord(tordconstnode(left).value.uvalue)),resultdef,false);
  2708. else
  2709. internalerror(2017042402);
  2710. end;
  2711. end;
  2712. end;
  2713. in_popcnt_x :
  2714. begin
  2715. if left.nodetype=ordconstn then
  2716. begin
  2717. result:=cordconstnode.create(PopCnt(tordconstnode(left).value),resultdef,false);
  2718. end;
  2719. end;
  2720. in_min_single,
  2721. in_min_double:
  2722. begin
  2723. { Check to see if the result is deterministic }
  2724. if left.nodetype=callparan then
  2725. begin
  2726. hp:=tcallparanode(tcallparanode(left).nextpara).paravalue;
  2727. hp2:=tcallparanode(left).paravalue;
  2728. if (hp.nodetype=realconstn) then
  2729. begin
  2730. if (trealconstnode(hp).value_real = MathQNaN.value) then
  2731. { If one of the inputs is NaN, the second parameter
  2732. is taken }
  2733. result:=hp2.getcopy()
  2734. else if (trealconstnode(hp).value_real = MathNegInf.value) then
  2735. { Nothing is less than than -oo }
  2736. result:=crealconstnode.create(MathNegInf.value,resultdef)
  2737. else if (trealconstnode(hp).value_real = MathInf.value) then
  2738. { Everything is less than +oo }
  2739. result:=hp2.getcopy()
  2740. else if (hp2.nodetype=realconstn) then
  2741. begin
  2742. { Both actual parameters are constants, so take
  2743. the smaller of the two right now }
  2744. if (trealconstnode(hp).value_real < trealconstnode(hp2).value_real) then
  2745. result:=crealconstnode.create(trealconstnode(hp).value_real,resultdef)
  2746. else
  2747. result:=crealconstnode.create(trealconstnode(hp2).value_real,resultdef);
  2748. end;
  2749. end
  2750. else if (hp2.nodetype=realconstn) then
  2751. begin
  2752. if (trealconstnode(hp2).value_real = MathQNaN.value) then
  2753. { If one of the inputs is NaN, the second parameter
  2754. is taken (even if it is NaN) }
  2755. result:=crealconstnode.create(MathQNaN.value,resultdef)
  2756. else if (trealconstnode(hp2).value_real = MathNegInf.value) then
  2757. { Nothing is less than than -oo }
  2758. result:=crealconstnode.create(MathNegInf.value,resultdef)
  2759. else if (trealconstnode(hp2).value_real = MathInf.value) then
  2760. { Everything is less than +oo }
  2761. result:=hp.getcopy();
  2762. end;
  2763. end;
  2764. end;
  2765. in_max_single,
  2766. in_max_double:
  2767. begin
  2768. { Check to see if the result is deterministic }
  2769. if left.nodetype=callparan then
  2770. begin
  2771. hp:=tcallparanode(tcallparanode(left).nextpara).paravalue;
  2772. hp2:=tcallparanode(left).paravalue;
  2773. if (hp.nodetype=realconstn) then
  2774. begin
  2775. if (trealconstnode(hp).value_real = MathQNaN.value) then
  2776. { If one of the inputs is NaN, the second parameter
  2777. is taken }
  2778. result:=hp2.getcopy()
  2779. else if (trealconstnode(hp).value_real = MathNegInf.value) then
  2780. { Everything is greater than than -oo }
  2781. result:=hp2.getcopy()
  2782. else if (trealconstnode(hp).value_real = MathInf.value) then
  2783. { Nothing is greater than +oo }
  2784. result:=crealconstnode.create(MathInf.value,resultdef)
  2785. else if (hp2.nodetype=realconstn) then
  2786. begin
  2787. { Both actual parameters are constants, so take
  2788. the larger of the two right now }
  2789. if (trealconstnode(hp).value_real > trealconstnode(hp2).value_real) then
  2790. result:=crealconstnode.create(trealconstnode(hp).value_real,resultdef)
  2791. else
  2792. result:=crealconstnode.create(trealconstnode(hp2).value_real,resultdef)
  2793. end;
  2794. end
  2795. else if (hp2.nodetype=realconstn) then
  2796. begin
  2797. if (trealconstnode(hp2).value_real = MathQNaN.value) then
  2798. { If one of the inputs is NaN, the second parameter
  2799. is taken (even if it is NaN) }
  2800. result:=crealconstnode.create(MathQNaN.value,resultdef)
  2801. else if (trealconstnode(hp2).value_real = MathNegInf.value) then
  2802. { Everything is greater than than -oo }
  2803. result:=hp.getcopy()
  2804. else if (trealconstnode(hp2).value_real = MathInf.value) then
  2805. { Nothing is greater than +oo }
  2806. result:=crealconstnode.create(MathInf.value,resultdef);
  2807. end;
  2808. end;
  2809. end;
  2810. in_min_longint,
  2811. in_min_int64:
  2812. begin
  2813. if left.nodetype=callparan then
  2814. begin
  2815. { Check to see if the result is deterministic }
  2816. hp:=tcallparanode(tcallparanode(left).nextpara).paravalue;
  2817. hp2:=tcallparanode(left).paravalue;
  2818. if (hp.nodetype=ordconstn) then
  2819. begin
  2820. if (hp2.nodetype=ordconstn) then
  2821. begin
  2822. { Both actual parameters are constants, so take
  2823. the smaller of the two right now }
  2824. if inlinenumber=in_min_longint then
  2825. result:=cordconstnode.create(min(LongInt(tordconstnode(hp).value.svalue),LongInt(tordconstnode(hp2).value.svalue)),resultdef,false)
  2826. else
  2827. result:=cordconstnode.create(min(tordconstnode(hp).value,tordconstnode(hp2).value),resultdef,false);
  2828. end;
  2829. if is_minmax_deterministic(tordconstnode(hp), False, helperres) then
  2830. begin
  2831. if helperres then
  2832. result:=cordconstnode.create(tordconstnode(hp).value,resultdef,false)
  2833. else
  2834. result:=hp2.getcopy();
  2835. end;
  2836. end
  2837. else if (hp2.nodetype=ordconstn) then
  2838. begin
  2839. if is_minmax_deterministic(tordconstnode(hp2), False, helperres) then
  2840. begin
  2841. if helperres then
  2842. result:=cordconstnode.create(tordconstnode(hp2).value,resultdef,false)
  2843. else
  2844. result:=hp.getcopy();
  2845. end;
  2846. end;
  2847. end;
  2848. end;
  2849. in_max_longint,
  2850. in_max_int64:
  2851. begin
  2852. if left.nodetype=callparan then
  2853. begin
  2854. { Check to see if the result is deterministic }
  2855. hp:=tcallparanode(left).paravalue;
  2856. hp2:=tcallparanode(tcallparanode(left).nextpara).paravalue;
  2857. if (hp.nodetype=ordconstn) then
  2858. begin
  2859. if (hp2.nodetype=ordconstn) then
  2860. begin
  2861. { Both actual parameters are constants, so take
  2862. the larger of the two right now }
  2863. if inlinenumber=in_max_longint then
  2864. result:=cordconstnode.create(max(LongInt(tordconstnode(hp).value.svalue),LongInt(tordconstnode(hp2).value.svalue)),resultdef,false)
  2865. else
  2866. result:=cordconstnode.create(max(tordconstnode(hp).value,tordconstnode(hp2).value),resultdef,false);
  2867. end;
  2868. if is_minmax_deterministic(tordconstnode(hp), True, helperres) then
  2869. begin
  2870. if helperres then
  2871. result:=cordconstnode.create(tordconstnode(hp).value,resultdef,false)
  2872. else
  2873. result:=hp2.getcopy();
  2874. end;
  2875. end
  2876. else if (hp2.nodetype=ordconstn) then
  2877. begin
  2878. if is_minmax_deterministic(tordconstnode(hp2), True, helperres) then
  2879. begin
  2880. if helperres then
  2881. result:=cordconstnode.create(tordconstnode(hp2).value,resultdef,false)
  2882. else
  2883. result:=hp.getcopy();
  2884. end;
  2885. end;
  2886. end;
  2887. end;
  2888. in_min_dword,
  2889. in_min_qword:
  2890. begin
  2891. if left.nodetype=callparan then
  2892. begin
  2893. { Check to see if the result is deterministic }
  2894. hp:=tcallparanode(tcallparanode(left).nextpara).paravalue;
  2895. hp2:=tcallparanode(left).paravalue;
  2896. if (hp.nodetype=ordconstn) then
  2897. begin
  2898. if (hp2.nodetype=ordconstn) then
  2899. begin
  2900. { Both actual parameters are constants, so take
  2901. the smaller of the two right now }
  2902. if inlinenumber=in_min_dword then
  2903. result:=cordconstnode.create(min(DWord(tordconstnode(hp).value.uvalue),DWord(tordconstnode(hp2).value.uvalue)),resultdef,false)
  2904. else
  2905. result:=cordconstnode.create(min(tordconstnode(hp).value,tordconstnode(hp2).value),resultdef,false);
  2906. end;
  2907. if is_minmax_deterministic(tordconstnode(hp), False, helperres) then
  2908. begin
  2909. if helperres then
  2910. result:=cordconstnode.create(tordconstnode(hp).value,resultdef,false)
  2911. else
  2912. result:=hp2.getcopy();
  2913. end;
  2914. end
  2915. else if (hp2.nodetype=ordconstn) then
  2916. begin
  2917. if is_minmax_deterministic(tordconstnode(hp2), False, helperres) then
  2918. begin
  2919. if helperres then
  2920. result:=cordconstnode.create(tordconstnode(hp2).value,resultdef,false)
  2921. else
  2922. result:=hp.getcopy();
  2923. end;
  2924. end;
  2925. end;
  2926. end;
  2927. in_max_dword,
  2928. in_max_qword:
  2929. begin
  2930. if left.nodetype=callparan then
  2931. begin
  2932. { Check to see if the result is deterministic }
  2933. hp:=tcallparanode(left).paravalue;
  2934. hp2:=tcallparanode(tcallparanode(left).nextpara).paravalue;
  2935. if (hp.nodetype=ordconstn) then
  2936. begin
  2937. if (hp2.nodetype=ordconstn) then
  2938. begin
  2939. { Both actual parameters are constants, so take
  2940. the larger of the two right now }
  2941. if inlinenumber=in_max_dword then
  2942. result:=cordconstnode.create(max(DWord(tordconstnode(hp).value.uvalue),DWord(tordconstnode(hp2).value.uvalue)),resultdef,false)
  2943. else
  2944. result:=cordconstnode.create(max(tordconstnode(hp).value,tordconstnode(hp2).value),resultdef,false);
  2945. end;
  2946. if is_minmax_deterministic(tordconstnode(hp), True, helperres) then
  2947. begin
  2948. if helperres then
  2949. result:=cordconstnode.create(tordconstnode(hp).value,resultdef,false)
  2950. else
  2951. result:=hp2.getcopy();
  2952. end;
  2953. end
  2954. else if (hp2.nodetype=ordconstn) then
  2955. begin
  2956. if is_minmax_deterministic(tordconstnode(hp2), True, helperres) then
  2957. begin
  2958. if helperres then
  2959. result:=cordconstnode.create(tordconstnode(hp2).value,resultdef,false)
  2960. else
  2961. result:=hp.getcopy();
  2962. end;
  2963. end;
  2964. end;
  2965. end;
  2966. else
  2967. ;
  2968. end;
  2969. end;
  2970. end;
  2971. function tinlinenode.pass_typecheck:tnode;
  2972. type
  2973. tfloattypeset = set of tfloattype;
  2974. function removefloatupcasts(var p: tnode; const floattypes: tfloattypeset): tdef;
  2975. var
  2976. hnode: tnode;
  2977. begin
  2978. { System unit declares internal functions like this:
  2979. function foo(x: valreal): valreal; [internproc: number];
  2980. Calls to such functions are initially processed by callnode,
  2981. which typechecks the arguments, possibly inserting conversion to valreal.
  2982. To handle smaller types without excess precision, we need to remove
  2983. these extra typecasts. }
  2984. if not(cs_excessprecision in current_settings.localswitches) and
  2985. (p.nodetype=typeconvn) and
  2986. (ttypeconvnode(p).left.resultdef.typ=floatdef) and
  2987. (p.flags*[nf_explicit,nf_internal]=[]) and
  2988. (tfloatdef(ttypeconvnode(p).left.resultdef).floattype in (floattypes*[s32real,s64real,s80real,sc80real,s128real])) then
  2989. begin
  2990. hnode:=ttypeconvnode(p).left;
  2991. ttypeconvnode(p).left:=nil;
  2992. p.free;
  2993. p:=hnode;
  2994. result:=p.resultdef;
  2995. end
  2996. else if (p.nodetype=typeconvn) and
  2997. (p.flags*[nf_explicit,nf_internal]=[]) and
  2998. (ttypeconvnode(p).left.resultdef.typ=floatdef) and
  2999. (tfloatdef(ttypeconvnode(p).left.resultdef).floattype in (floattypes*[s64currency,s64comp])) then
  3000. begin
  3001. hnode:=ttypeconvnode(p).left;
  3002. ttypeconvnode(p).left:=nil;
  3003. p.free;
  3004. p:=hnode;
  3005. if is_currency(p.resultdef) then
  3006. begin
  3007. if (nf_is_currency in p.flags) and
  3008. (p.nodetype=slashn) and
  3009. (taddnode(p).right.nodetype=realconstn) and
  3010. (trealconstnode(taddnode(p).right).value_real=10000.0) and
  3011. not(nf_is_currency in taddnode(p).left.flags) then
  3012. begin
  3013. hnode:=taddnode(p).left;
  3014. taddnode(p).left:=nil;
  3015. p.free;
  3016. p:=hnode;
  3017. end;
  3018. end;
  3019. result:=p.resultdef;
  3020. end
  3021. { in case the system helper was declared with overloads for different types,
  3022. keep those }
  3023. else if (p.resultdef.typ=floatdef) and
  3024. (tfloatdef(p.resultdef).floattype in (floattypes*[s32real,s64real,s80real,sc80real,s128real])) then
  3025. result:=p.resultdef
  3026. else
  3027. begin
  3028. { for variant parameters; the rest has been converted by the
  3029. call node already }
  3030. if not(p.nodetype in [ordconstn,realconstn]) then
  3031. inserttypeconv(P,pbestrealtype^);
  3032. result:=p.resultdef
  3033. end;
  3034. end;
  3035. procedure handle_pack_unpack;
  3036. var
  3037. source, target, index: tcallparanode;
  3038. unpackedarraydef, packedarraydef: tarraydef;
  3039. tempindex: TConstExprInt;
  3040. begin
  3041. resultdef:=voidtype;
  3042. unpackedarraydef := nil;
  3043. packedarraydef := nil;
  3044. source := tcallparanode(left);
  3045. if (inlinenumber = in_unpack_x_y_z) then
  3046. begin
  3047. target := tcallparanode(source.right);
  3048. index := tcallparanode(target.right);
  3049. { source must be a packed array }
  3050. if not is_packed_array(source.left.resultdef) then
  3051. CGMessagePos2(source.left.fileinfo,type_e_got_expected_packed_array,'1',source.left.resultdef.typename)
  3052. else
  3053. packedarraydef := tarraydef(source.left.resultdef);
  3054. { target can be any kind of array, as long as it's not packed }
  3055. if (target.left.resultdef.typ <> arraydef) or
  3056. is_packed_array(target.left.resultdef) then
  3057. CGMessagePos2(target.left.fileinfo,type_e_got_expected_unpacked_array,'2',target.left.resultdef.typename)
  3058. else
  3059. unpackedarraydef := tarraydef(target.left.resultdef);
  3060. end
  3061. else
  3062. begin
  3063. index := tcallparanode(source.right);
  3064. target := tcallparanode(index.right);
  3065. { source can be any kind of array, as long as it's not packed }
  3066. if (source.left.resultdef.typ <> arraydef) or
  3067. is_packed_array(source.left.resultdef) then
  3068. CGMessagePos2(source.left.fileinfo,type_e_got_expected_unpacked_array,'1',source.left.resultdef.typename)
  3069. else
  3070. unpackedarraydef := tarraydef(source.left.resultdef);
  3071. { target must be a packed array }
  3072. if not is_packed_array(target.left.resultdef) then
  3073. CGMessagePos2(target.left.fileinfo,type_e_got_expected_packed_array,'3',target.left.resultdef.typename)
  3074. else
  3075. packedarraydef := tarraydef(target.left.resultdef);
  3076. end;
  3077. if assigned(unpackedarraydef) then
  3078. begin
  3079. { index must be compatible with the unpacked array's indextype }
  3080. inserttypeconv(index.left,unpackedarraydef.rangedef);
  3081. { range check at compile time if possible }
  3082. if assigned(packedarraydef) and
  3083. (index.left.nodetype = ordconstn) and
  3084. not is_special_array(unpackedarraydef) then
  3085. begin
  3086. adaptrange(unpackedarraydef,tordconstnode(index.left).value,false,false,cs_check_range in current_settings.localswitches);
  3087. tempindex := tordconstnode(index.left).value + packedarraydef.highrange-packedarraydef.lowrange;
  3088. adaptrange(unpackedarraydef,tempindex,false,false,cs_check_range in current_settings.localswitches);
  3089. end;
  3090. end;
  3091. { source array is read and must be valid }
  3092. set_varstate(source.left,vs_read,[vsf_must_be_valid]);
  3093. { target array is written }
  3094. valid_for_assignment(target.left,true);
  3095. set_varstate(target.left,vs_written,[]);
  3096. { index in the unpacked array is read and must be valid }
  3097. set_varstate(index.left,vs_read,[vsf_must_be_valid]);
  3098. { if the size of the arrays is 0 (array of empty records), }
  3099. { do nothing }
  3100. if (source.resultdef.size = 0) then
  3101. result:=cnothingnode.create;
  3102. end;
  3103. function handle_objc_encode: tnode;
  3104. var
  3105. encodedtype: ansistring;
  3106. errordef: tdef;
  3107. begin
  3108. encodedtype:='';
  3109. if not objctryencodetype(left.resultdef,encodedtype,errordef) then
  3110. Message1(type_e_objc_type_unsupported,errordef.typename);
  3111. result:=cstringconstnode.createpchar(ansistring2pchar(encodedtype),length(encodedtype),nil);
  3112. end;
  3113. var
  3114. hightree,
  3115. hp : tnode;
  3116. temp_pnode: pnode;
  3117. begin
  3118. result:=nil;
  3119. { when handling writeln "left" contains no valid address }
  3120. if assigned(left) then
  3121. begin
  3122. if left.nodetype=callparan then
  3123. tcallparanode(left).get_paratype
  3124. else
  3125. typecheckpass(left);
  3126. end;
  3127. if not(inf_inlineconst in inlinenodeflags) then
  3128. begin
  3129. case inlinenumber of
  3130. in_lo_long,
  3131. in_hi_long,
  3132. in_lo_qword,
  3133. in_hi_qword,
  3134. in_lo_word,
  3135. in_hi_word :
  3136. begin
  3137. { give warning for incompatibility with tp and delphi }
  3138. if (inlinenumber in [in_lo_long,in_hi_long,in_lo_qword,in_hi_qword]) and
  3139. ((m_tp7 in current_settings.modeswitches) or
  3140. (m_delphi in current_settings.modeswitches)) then
  3141. CGMessage(type_w_maybe_wrong_hi_lo);
  3142. set_varstate(left,vs_read,[vsf_must_be_valid]);
  3143. if not is_integer(left.resultdef) then
  3144. CGMessage1(type_e_integer_expr_expected,left.resultdef.typename);
  3145. case inlinenumber of
  3146. in_lo_word,
  3147. in_hi_word :
  3148. resultdef:=u8inttype;
  3149. in_lo_long,
  3150. in_hi_long :
  3151. resultdef:=u16inttype;
  3152. in_lo_qword,
  3153. in_hi_qword :
  3154. resultdef:=u32inttype;
  3155. else
  3156. ;
  3157. end;
  3158. end;
  3159. in_sizeof_x:
  3160. begin
  3161. { the constant evaluation of in_sizeof_x happens in pexpr where possible,
  3162. though for generics it can reach here as well }
  3163. set_varstate(left,vs_read,[]);
  3164. if (left.resultdef.typ<>undefineddef) and
  3165. assigned(current_procinfo) and
  3166. paramanager.push_high_param(vs_value,left.resultdef,current_procinfo.procdef.proccalloption) then
  3167. begin
  3168. { this should be an open array or array of const, both of
  3169. which can only be simple load nodes of parameters }
  3170. if left.nodetype<>loadn then
  3171. internalerror(2014120701);
  3172. hightree:=load_high_value_node(tparavarsym(tloadnode(left).symtableentry));
  3173. if assigned(hightree) then
  3174. begin
  3175. hp:=caddnode.create(addn,hightree,
  3176. cordconstnode.create(1,sizesinttype,false));
  3177. if (left.resultdef.typ=arraydef) then
  3178. if not is_packed_array(tarraydef(left.resultdef)) then
  3179. begin
  3180. if (tarraydef(left.resultdef).elesize<>1) then
  3181. hp:=caddnode.create(muln,hp,cordconstnode.create(tarraydef(
  3182. left.resultdef).elesize,sizesinttype,true));
  3183. end
  3184. else if (tarraydef(left.resultdef).elepackedbitsize <> 8) then
  3185. begin
  3186. { no packed open array support yet }
  3187. if (hp.nodetype <> ordconstn) then
  3188. internalerror(2006081511);
  3189. hp.free;
  3190. hp := cordconstnode.create(left.resultdef.size,sizesinttype,true);
  3191. {
  3192. hp:=
  3193. ctypeconvnode.create_explicit(sizesinttype,
  3194. cmoddivnode.create(divn,
  3195. caddnode.create(addn,
  3196. caddnode.create(muln,hp,cordconstnode.create(tarraydef(
  3197. left.resultdef).elepackedbitsize,s64inttype,true)),
  3198. cordconstnode.create(a,s64inttype,true)),
  3199. cordconstnode.create(8,s64inttype,true)),
  3200. sizesinttype);
  3201. }
  3202. end;
  3203. result:=hp;
  3204. end;
  3205. end
  3206. else
  3207. resultdef:=sizesinttype;
  3208. end;
  3209. in_typeof_x:
  3210. begin
  3211. if target_info.system in systems_managed_vm then
  3212. message(parser_e_feature_unsupported_for_vm);
  3213. typecheckpass(left);
  3214. set_varstate(left,vs_read,[]);
  3215. if (left.resultdef.typ=objectdef) and
  3216. not(oo_has_vmt in tobjectdef(left.resultdef).objectoptions) then
  3217. message(type_e_typeof_requires_vmt);
  3218. resultdef:=voidpointertype;
  3219. end;
  3220. in_ord_x:
  3221. begin
  3222. set_varstate(left,vs_read,[vsf_must_be_valid]);
  3223. case left.resultdef.typ of
  3224. orddef,
  3225. enumdef,
  3226. undefineddef :
  3227. ;
  3228. pointerdef :
  3229. begin
  3230. if not(m_mac in current_settings.modeswitches) then
  3231. CGMessage1(type_e_ordinal_expr_expected,left.resultdef.typename);
  3232. end
  3233. else
  3234. CGMessage1(type_e_ordinal_expr_expected,left.resultdef.typename);
  3235. end;
  3236. end;
  3237. in_chr_byte:
  3238. begin
  3239. set_varstate(left,vs_read,[vsf_must_be_valid]);
  3240. end;
  3241. in_length_x:
  3242. begin
  3243. if ((left.resultdef.typ=arraydef) and
  3244. (not is_special_array(left.resultdef) or
  3245. is_open_array(left.resultdef))) or
  3246. (left.resultdef.typ=orddef) then
  3247. set_varstate(left,vs_read,[])
  3248. else
  3249. set_varstate(left,vs_read,[vsf_must_be_valid]);
  3250. case left.resultdef.typ of
  3251. variantdef:
  3252. begin
  3253. inserttypeconv(left,getansistringdef);
  3254. end;
  3255. stringdef :
  3256. begin
  3257. { we don't need string convertions here, }
  3258. { except if from widestring to ansistring }
  3259. { and vice versa (that can change the }
  3260. { length) }
  3261. if (left.nodetype=typeconvn) and
  3262. (ttypeconvnode(left).left.resultdef.typ=stringdef) and
  3263. not(is_wide_or_unicode_string(left.resultdef) xor
  3264. is_wide_or_unicode_string(ttypeconvnode(left).left.resultdef)) then
  3265. begin
  3266. hp:=ttypeconvnode(left).left;
  3267. ttypeconvnode(left).left:=nil;
  3268. left.free;
  3269. left:=hp;
  3270. end;
  3271. end;
  3272. orddef :
  3273. begin
  3274. { will be handled in simplify }
  3275. if not is_char(left.resultdef) and
  3276. not is_widechar(left.resultdef) then
  3277. CGMessage(type_e_mismatch);
  3278. end;
  3279. pointerdef :
  3280. begin
  3281. if is_pchar(left.resultdef) then
  3282. begin
  3283. hp := ccallparanode.create(left,nil);
  3284. result := ccallnode.createintern('fpc_pchar_length',hp);
  3285. { make sure the left node doesn't get disposed, since it's }
  3286. { reused in the new node (JM) }
  3287. left:=nil;
  3288. exit;
  3289. end
  3290. else if is_pwidechar(left.resultdef) then
  3291. begin
  3292. hp := ccallparanode.create(left,nil);
  3293. result := ccallnode.createintern('fpc_pwidechar_length',hp);
  3294. { make sure the left node doesn't get disposed, since it's }
  3295. { reused in the new node (JM) }
  3296. left:=nil;
  3297. exit;
  3298. end
  3299. else
  3300. CGMessage(type_e_mismatch);
  3301. end;
  3302. arraydef :
  3303. begin
  3304. if is_open_array(left.resultdef) or
  3305. is_array_of_const(left.resultdef) then
  3306. begin
  3307. hightree:=load_high_value_node(tparavarsym(tloadnode(left).symtableentry));
  3308. if assigned(hightree) then
  3309. result:=caddnode.create(addn,hightree,
  3310. cordconstnode.create(1,sinttype,false));
  3311. exit;
  3312. end
  3313. { Length() for dynamic arrays is inlined }
  3314. else
  3315. begin
  3316. { will be handled in simplify }
  3317. end;
  3318. end;
  3319. undefineddef :
  3320. begin
  3321. if not (df_generic in current_procinfo.procdef.defoptions) then
  3322. CGMessage(type_e_mismatch);
  3323. { otherwise nothing }
  3324. end;
  3325. else
  3326. CGMessage(type_e_mismatch);
  3327. end;
  3328. { shortstring return an 8 bit value as the length
  3329. is the first byte of the string }
  3330. if is_shortstring(left.resultdef) then
  3331. resultdef:=u8inttype
  3332. else
  3333. resultdef:=sizesinttype;
  3334. end;
  3335. in_typeinfo_x:
  3336. begin
  3337. if target_info.system in systems_managed_vm then
  3338. message(parser_e_feature_unsupported_for_vm);
  3339. if (left.resultdef.typ=enumdef) and
  3340. (tenumdef(left.resultdef).has_jumps) and
  3341. (
  3342. (left.nodetype<>typen) or
  3343. not (sp_generic_para in ttypenode(left).typesym.symoptions)
  3344. ) then
  3345. CGMessage(type_e_no_type_info);
  3346. set_varstate(left,vs_read,[vsf_must_be_valid]);
  3347. resultdef:=voidpointertype;
  3348. end;
  3349. in_gettypekind_x:
  3350. begin
  3351. if target_info.system in systems_managed_vm then
  3352. message(parser_e_feature_unsupported_for_vm);
  3353. set_varstate(left,vs_read,[vsf_must_be_valid]);
  3354. resultdef:=typekindtype;
  3355. end;
  3356. in_ismanagedtype_x:
  3357. begin
  3358. if target_info.system in systems_managed_vm then
  3359. message(parser_e_feature_unsupported_for_vm);
  3360. set_varstate(left,vs_read,[vsf_must_be_valid]);
  3361. resultdef:=pasbool1type;
  3362. end;
  3363. in_isconstvalue_x:
  3364. begin
  3365. set_varstate(left,vs_read,[vsf_must_be_valid]);
  3366. resultdef:=pasbool1type;
  3367. end;
  3368. in_assigned_x:
  3369. begin
  3370. { the parser has already made sure the expression is valid }
  3371. { in case of a complex procvar, only check the "code" pointer }
  3372. if (tcallparanode(left).left.resultdef.typ=procvardef) and
  3373. not tprocvardef(tcallparanode(left).left.resultdef).is_addressonly then
  3374. begin
  3375. inserttypeconv_explicit(tcallparanode(left).left,search_system_type('TMETHOD').typedef);
  3376. tcallparanode(left).left:=csubscriptnode.create(tsym(tabstractrecorddef(tcallparanode(left).left.resultdef).symtable.find('CODE')),tcallparanode(left).left);
  3377. tcallparanode(left).get_paratype;
  3378. end;
  3379. { Postpone conversion into addnode until firstpass, so targets
  3380. may override first_assigned and insert specific code. }
  3381. set_varstate(tcallparanode(left).left,vs_read,[vsf_must_be_valid]);
  3382. resultdef:=pasbool1type;
  3383. end;
  3384. in_ofs_x :
  3385. internalerror(2000101001);
  3386. in_seg_x :
  3387. begin
  3388. result := typecheck_seg;
  3389. end;
  3390. in_pred_x,
  3391. in_succ_x:
  3392. begin
  3393. set_varstate(left,vs_read,[vsf_must_be_valid]);
  3394. resultdef:=left.resultdef;
  3395. if is_ordinal(resultdef) or is_typeparam(resultdef) then
  3396. begin
  3397. if (resultdef.typ=enumdef) and
  3398. (tenumdef(resultdef).has_jumps) and
  3399. not(m_delphi in current_settings.modeswitches) and
  3400. not(nf_internal in flags) then
  3401. CGMessage(type_e_succ_and_pred_enums_with_assign_not_possible);
  3402. end
  3403. else
  3404. CGMessage(type_e_ordinal_expr_expected)
  3405. end;
  3406. in_copy_x:
  3407. result:=handle_copy;
  3408. in_initialize_x,
  3409. in_finalize_x:
  3410. begin
  3411. { inlined from pinline }
  3412. internalerror(200204231);
  3413. end;
  3414. in_setlength_x:
  3415. begin
  3416. result:=handle_setlength;
  3417. end;
  3418. in_inc_x,
  3419. in_dec_x:
  3420. begin
  3421. resultdef:=voidtype;
  3422. if not(df_generic in current_procinfo.procdef.defoptions) then
  3423. begin
  3424. if assigned(left) then
  3425. begin
  3426. { first param must be var }
  3427. valid_for_var(tcallparanode(left).left,true);
  3428. set_varstate(tcallparanode(left).left,vs_readwritten,[vsf_must_be_valid]);
  3429. if (left.resultdef.typ in [enumdef,pointerdef]) or
  3430. is_ordinal(left.resultdef) or
  3431. is_currency(left.resultdef) then
  3432. begin
  3433. { value of left gets changed -> must be unique }
  3434. set_unique(tcallparanode(left).left);
  3435. { two paras ? }
  3436. if assigned(tcallparanode(left).right) then
  3437. begin
  3438. if is_integer(tcallparanode(left).right.resultdef) then
  3439. begin
  3440. set_varstate(tcallparanode(tcallparanode(left).right).left,vs_read,[vsf_must_be_valid]);
  3441. { when range/overflow checking is on, we
  3442. convert this to a regular add, and for proper
  3443. checking we need the original type }
  3444. if ([cs_check_range,cs_check_overflow]*current_settings.localswitches=[]) then
  3445. if (tcallparanode(left).left.resultdef.typ=pointerdef) then
  3446. begin
  3447. { don't convert values added to pointers into the pointer types themselves,
  3448. because that will turn signed values into unsigned ones, which then
  3449. goes wrong when they have to be multiplied with the size of the elements
  3450. to which the pointer points in ncginl (mantis #17342) }
  3451. if is_signed(tcallparanode(tcallparanode(left).right).left.resultdef) then
  3452. inserttypeconv(tcallparanode(tcallparanode(left).right).left,tpointerdef(tcallparanode(left).left.resultdef).pointer_arithmetic_int_type)
  3453. else
  3454. inserttypeconv(tcallparanode(tcallparanode(left).right).left,tpointerdef(tcallparanode(left).left.resultdef).pointer_arithmetic_uint_type)
  3455. end
  3456. else if is_integer(tcallparanode(left).left.resultdef) then
  3457. inserttypeconv(tcallparanode(tcallparanode(left).right).left,tcallparanode(left).left.resultdef)
  3458. else
  3459. inserttypeconv_internal(tcallparanode(tcallparanode(left).right).left,tcallparanode(left).left.resultdef);
  3460. if assigned(tcallparanode(tcallparanode(left).right).right) then
  3461. { should be handled in the parser (JM) }
  3462. internalerror(2006020901);
  3463. end
  3464. else
  3465. CGMessagePos(tcallparanode(left).right.fileinfo,type_e_ordinal_expr_expected);
  3466. end;
  3467. end
  3468. { generic type parameter? }
  3469. else if is_typeparam(left.resultdef) then
  3470. begin
  3471. result:=cnothingnode.create;
  3472. exit;
  3473. end
  3474. else
  3475. begin
  3476. hp:=self;
  3477. if isunaryoverloaded(hp,[]) then
  3478. begin
  3479. { inc(rec) and dec(rec) assigns result value to argument }
  3480. result:=cassignmentnode.create(tcallparanode(left).left.getcopy,hp);
  3481. exit;
  3482. end
  3483. else
  3484. CGMessagePos(left.fileinfo,type_e_ordinal_expr_expected);
  3485. end;
  3486. end
  3487. else
  3488. CGMessagePos(fileinfo,type_e_mismatch);
  3489. end;
  3490. end;
  3491. in_and_assign_x_y,
  3492. in_or_assign_x_y,
  3493. in_xor_assign_x_y,
  3494. in_sar_assign_x_y,
  3495. in_shl_assign_x_y,
  3496. in_shr_assign_x_y,
  3497. in_rol_assign_x_y,
  3498. in_ror_assign_x_y:
  3499. begin
  3500. resultdef:=voidtype;
  3501. if not(df_generic in current_procinfo.procdef.defoptions) then
  3502. begin
  3503. { first parameter must exist }
  3504. if not assigned(left) or (left.nodetype<>callparan) then
  3505. internalerror(2017032501);
  3506. { second parameter must exist }
  3507. if not assigned(tcallparanode(left).right) or (tcallparanode(left).right.nodetype<>callparan) then
  3508. internalerror(2017032502);
  3509. { third parameter must NOT exist }
  3510. if assigned(tcallparanode(tcallparanode(left).right).right) then
  3511. internalerror(2017032503);
  3512. valid_for_var(tcallparanode(tcallparanode(left).right).left,true);
  3513. set_varstate(tcallparanode(tcallparanode(left).right).left,vs_readwritten,[vsf_must_be_valid]);
  3514. if is_integer(tcallparanode(left).right.resultdef) then
  3515. begin
  3516. { value of right gets changed -> must be unique }
  3517. set_unique(tcallparanode(tcallparanode(left).right).left);
  3518. if is_integer(left.resultdef) then
  3519. begin
  3520. set_varstate(tcallparanode(left).left,vs_read,[vsf_must_be_valid]);
  3521. { these nodes shouldn't be created, when range checking is on }
  3522. if [cs_check_range,cs_check_overflow]*localswitches<>[] then
  3523. internalerror(2017032701);
  3524. if inlinenumber in [in_sar_assign_x_y,in_shl_assign_x_y,in_shr_assign_x_y,in_rol_assign_x_y,in_ror_assign_x_y] then
  3525. inserttypeconv(tcallparanode(left).left,sinttype)
  3526. else
  3527. inserttypeconv(tcallparanode(left).left,tcallparanode(tcallparanode(left).right).left.resultdef);
  3528. end
  3529. else
  3530. CGMessagePos(left.fileinfo,type_e_ordinal_expr_expected);
  3531. end
  3532. { generic type parameter? }
  3533. else if is_typeparam(tcallparanode(left).right.resultdef) then
  3534. begin
  3535. result:=cnothingnode.create;
  3536. exit;
  3537. end
  3538. else
  3539. CGMessagePos(tcallparanode(left).right.fileinfo,type_e_ordinal_expr_expected);
  3540. end;
  3541. end;
  3542. in_neg_assign_x,
  3543. in_not_assign_x:
  3544. begin
  3545. resultdef:=voidtype;
  3546. if not(df_generic in current_procinfo.procdef.defoptions) then
  3547. begin
  3548. valid_for_var(left,true);
  3549. set_varstate(left,vs_readwritten,[vsf_must_be_valid]);
  3550. if is_integer(left.resultdef) then
  3551. begin
  3552. { value of left gets changed -> must be unique }
  3553. set_unique(left);
  3554. { these nodes shouldn't be created, when range checking is on }
  3555. if [cs_check_range,cs_check_overflow]*current_settings.localswitches<>[] then
  3556. internalerror(2017040703);
  3557. end
  3558. { generic type parameter? }
  3559. else if is_typeparam(left.resultdef) then
  3560. begin
  3561. result:=cnothingnode.create;
  3562. exit;
  3563. end
  3564. else
  3565. CGMessagePos(left.fileinfo,type_e_ordinal_expr_expected);
  3566. end;
  3567. end;
  3568. in_read_x,
  3569. in_readln_x,
  3570. in_readstr_x,
  3571. in_write_x,
  3572. in_writeln_x,
  3573. in_writestr_x :
  3574. begin
  3575. result := handle_read_write;
  3576. end;
  3577. in_settextbuf_file_x :
  3578. begin
  3579. if target_info.system in systems_managed_vm then
  3580. message(parser_e_feature_unsupported_for_vm);
  3581. resultdef:=voidtype;
  3582. { now we know the type of buffer }
  3583. hp:=ccallparanode.create(cordconstnode.create(
  3584. tcallparanode(left).left.resultdef.size,s32inttype,true),left);
  3585. result:=ccallnode.createintern('SETTEXTBUF',hp);
  3586. left:=nil;
  3587. end;
  3588. { the firstpass of the arg has been done in firstcalln ? }
  3589. in_reset_typedfile,
  3590. in_rewrite_typedfile,
  3591. in_reset_typedfile_name,
  3592. in_rewrite_typedfile_name :
  3593. begin
  3594. result := handle_reset_rewrite_typed;
  3595. end;
  3596. in_str_x_string :
  3597. begin
  3598. result:=handle_str;
  3599. end;
  3600. in_val_x :
  3601. begin
  3602. result:=handle_val;
  3603. end;
  3604. in_include_x_y,
  3605. in_exclude_x_y:
  3606. begin
  3607. resultdef:=voidtype;
  3608. { the parser already checks whether we have two (and exactly two) }
  3609. { parameters (JM) }
  3610. { first param must be var }
  3611. valid_for_var(tcallparanode(left).left,true);
  3612. set_varstate(tcallparanode(left).left,vs_readwritten,[vsf_must_be_valid]);
  3613. { check type }
  3614. if (left.resultdef.typ=setdef) then
  3615. begin
  3616. { insert a type conversion }
  3617. { to the type of the set elements }
  3618. set_varstate(tcallparanode(tcallparanode(left).right).left,vs_read,[vsf_must_be_valid]);
  3619. inserttypeconv(tcallparanode(tcallparanode(left).right).left,
  3620. tsetdef(left.resultdef).elementdef);
  3621. end
  3622. else if left.resultdef.typ<>undefineddef then
  3623. CGMessage(type_e_mismatch);
  3624. end;
  3625. in_pack_x_y_z,
  3626. in_unpack_x_y_z :
  3627. begin
  3628. handle_pack_unpack;
  3629. end;
  3630. in_slice_x:
  3631. begin
  3632. if target_info.system in systems_managed_vm then
  3633. message(parser_e_feature_unsupported_for_vm);
  3634. result:=nil;
  3635. resultdef:=tcallparanode(left).left.resultdef;
  3636. if (resultdef.typ <> arraydef) then
  3637. CGMessagePos(left.fileinfo,type_e_mismatch)
  3638. else if is_packed_array(resultdef) then
  3639. CGMessagePos2(left.fileinfo,type_e_got_expected_unpacked_array,'1',resultdef.typename);
  3640. if not(is_integer(tcallparanode(tcallparanode(left).right).left.resultdef)) then
  3641. CGMessagePos1(tcallparanode(left).right.fileinfo,
  3642. type_e_integer_expr_expected,
  3643. tcallparanode(tcallparanode(left).right).left.resultdef.typename);
  3644. end;
  3645. in_new_x:
  3646. resultdef:=left.resultdef;
  3647. in_low_x,
  3648. in_high_x:
  3649. begin
  3650. case left.resultdef.typ of
  3651. undefineddef,
  3652. orddef,
  3653. enumdef,
  3654. setdef:
  3655. ;
  3656. arraydef:
  3657. begin
  3658. if (inlinenumber=in_low_x) then
  3659. set_varstate(left,vs_read,[])
  3660. else
  3661. begin
  3662. if is_open_array(left.resultdef) or
  3663. is_array_of_const(left.resultdef) then
  3664. begin
  3665. set_varstate(left,vs_read,[]);
  3666. result:=load_high_value_node(tparavarsym(tloadnode(left).symtableentry));
  3667. end
  3668. else
  3669. begin
  3670. set_varstate(left,vs_read,[]);
  3671. resultdef:=sizesinttype;
  3672. end;
  3673. end;
  3674. end;
  3675. stringdef:
  3676. begin
  3677. if inlinenumber=in_low_x then
  3678. begin
  3679. set_varstate(left,vs_read,[]);
  3680. end
  3681. else
  3682. begin
  3683. if is_open_string(left.resultdef) then
  3684. begin
  3685. set_varstate(left,vs_read,[]);
  3686. result:=load_high_value_node(tparavarsym(tloadnode(left).symtableentry))
  3687. end
  3688. else if is_dynamicstring(left.resultdef) then
  3689. begin
  3690. result:=cinlinenode.create(in_length_x,false,left);
  3691. if cs_zerobasedstrings in current_settings.localswitches then
  3692. result:=caddnode.create(subn,result,cordconstnode.create(1,sinttype,false));
  3693. { make sure the left node doesn't get disposed, since it's }
  3694. { reused in the new node (JM) }
  3695. left:=nil;
  3696. end
  3697. end;
  3698. end;
  3699. else
  3700. CGMessage(type_e_mismatch);
  3701. end;
  3702. end;
  3703. in_exp_real,
  3704. in_frac_real,
  3705. in_int_real,
  3706. in_cos_real,
  3707. in_sin_real,
  3708. in_arctan_real,
  3709. in_ln_real :
  3710. begin
  3711. { on the Z80, the double result is returned in a var param, because
  3712. it's too big to fit in registers. In that case we have 2 parameters
  3713. and left.nodetype is a callparan. }
  3714. if left.nodetype = callparan then
  3715. temp_pnode := @tcallparanode(left).left
  3716. else
  3717. temp_pnode := @left;
  3718. set_varstate(temp_pnode^,vs_read,[vsf_must_be_valid]);
  3719. { converting an int64 to double on platforms without }
  3720. { extended can cause precision loss }
  3721. if not(temp_pnode^.nodetype in [ordconstn,realconstn]) then
  3722. inserttypeconv(temp_pnode^,pbestrealtype^);
  3723. resultdef:=pbestrealtype^;
  3724. end;
  3725. in_trunc_real,
  3726. in_round_real :
  3727. begin
  3728. { on i8086, the int64 result is returned in a var param, because
  3729. it's too big to fit in a register or a pair of registers. In
  3730. that case we have 2 parameters and left.nodetype is a callparan. }
  3731. if left.nodetype=callparan then
  3732. temp_pnode:=@tcallparanode(left).left
  3733. else
  3734. temp_pnode:=@left;
  3735. set_varstate(temp_pnode^,vs_read,[vsf_must_be_valid]);
  3736. { on platforms where comp and currency are "type int64", this is
  3737. handled via inlined system helpers (-> no need for special
  3738. handling of s64currency/s64comp for them) }
  3739. if inlinenumber=in_trunc_real then
  3740. removefloatupcasts(temp_pnode^,[s32real,s64real,s80real,sc80real,s128real,s64currency,s64comp])
  3741. else
  3742. removefloatupcasts(temp_pnode^,[s32real,s64real,s80real,sc80real,s128real,s64comp]);
  3743. if (inlinenumber=in_trunc_real) and
  3744. is_currency(temp_pnode^.resultdef) then
  3745. begin
  3746. result:=cmoddivnode.create(divn,ctypeconvnode.create_internal(temp_pnode^.getcopy,s64inttype),genintconstnode(10000));
  3747. exit;
  3748. end
  3749. else if is_fpucomp(temp_pnode^.resultdef) then
  3750. begin
  3751. result:=ctypeconvnode.create_internal(temp_pnode^.getcopy,s64inttype);
  3752. exit;
  3753. end;
  3754. resultdef:=s64inttype;
  3755. end;
  3756. in_pi_real :
  3757. begin
  3758. resultdef:=pbestrealtype^;
  3759. end;
  3760. in_abs_long:
  3761. begin
  3762. set_varstate(left,vs_read,[vsf_must_be_valid]);
  3763. resultdef:=left.resultdef;
  3764. end;
  3765. in_abs_real,
  3766. in_sqr_real,
  3767. in_sqrt_real :
  3768. begin
  3769. { on the Z80, the double result is returned in a var param, because
  3770. it's too big to fit in registers. In that case we have 2 parameters
  3771. and left.nodetype is a callparan. }
  3772. if left.nodetype = callparan then
  3773. temp_pnode := @tcallparanode(left).left
  3774. else
  3775. temp_pnode := @left;
  3776. set_varstate(temp_pnode^,vs_read,[vsf_must_be_valid]);
  3777. resultdef:=removefloatupcasts(temp_pnode^,[s32real,s64real,s80real,sc80real,s128real]);
  3778. end;
  3779. {$ifdef SUPPORT_MMX}
  3780. in_mmx_pcmpeqb..in_mmx_pcmpgtw:
  3781. begin
  3782. end;
  3783. {$endif SUPPORT_MMX}
  3784. in_aligned_x,
  3785. in_unaligned_x:
  3786. begin
  3787. resultdef:=left.resultdef;
  3788. end;
  3789. in_volatile_x:
  3790. begin
  3791. resultdef:=left.resultdef;
  3792. { volatile only makes sense if the value is in memory }
  3793. make_not_regable(left,[ra_addr_regable]);
  3794. end;
  3795. in_assert_x_y :
  3796. begin
  3797. resultdef:=voidtype;
  3798. if assigned(left) then
  3799. begin
  3800. set_varstate(tcallparanode(left).left,vs_read,[vsf_must_be_valid]);
  3801. { check type }
  3802. if is_boolean(left.resultdef) or
  3803. (
  3804. (left.resultdef.typ=undefineddef) and
  3805. (df_generic in current_procinfo.procdef.defoptions)
  3806. ) then
  3807. begin
  3808. set_varstate(tcallparanode(tcallparanode(left).right).left,vs_read,[vsf_must_be_valid]);
  3809. { must always be a string }
  3810. inserttypeconv(tcallparanode(tcallparanode(left).right).left,cshortstringtype);
  3811. end
  3812. else
  3813. CGMessage1(type_e_boolean_expr_expected,left.resultdef.typename);
  3814. end
  3815. else
  3816. CGMessage(type_e_mismatch);
  3817. if (cs_do_assertion in current_settings.localswitches) then
  3818. include(current_procinfo.flags,pi_do_call);
  3819. end;
  3820. in_prefetch_var:
  3821. resultdef:=voidtype;
  3822. in_get_frame,
  3823. in_get_caller_frame,
  3824. in_get_caller_addr:
  3825. begin
  3826. resultdef:=voidpointertype;
  3827. end;
  3828. in_rol_x,
  3829. in_ror_x,
  3830. in_sar_x:
  3831. begin
  3832. set_varstate(left,vs_read,[vsf_must_be_valid]);
  3833. resultdef:=left.resultdef;
  3834. end;
  3835. in_rol_x_y,
  3836. in_ror_x_y,
  3837. in_sar_x_y:
  3838. begin
  3839. set_varstate(tcallparanode(left).left,vs_read,[vsf_must_be_valid]);
  3840. set_varstate(tcallparanode(tcallparanode(left).right).left,vs_read,[vsf_must_be_valid]);
  3841. resultdef:=tcallparanode(tcallparanode(left).right).left.resultdef;
  3842. end;
  3843. in_bsf_x,
  3844. in_bsr_x:
  3845. begin
  3846. set_varstate(left,vs_read,[vsf_must_be_valid]);
  3847. if not is_integer(left.resultdef) then
  3848. CGMessage1(type_e_integer_expr_expected,left.resultdef.typename);
  3849. if torddef(left.resultdef).ordtype in [u64bit, s64bit] then
  3850. resultdef:=u64inttype
  3851. else
  3852. resultdef:=u32inttype
  3853. end;
  3854. in_popcnt_x:
  3855. begin
  3856. set_varstate(left,vs_read,[vsf_must_be_valid]);
  3857. if not is_integer(left.resultdef) then
  3858. CGMessage1(type_e_integer_expr_expected,left.resultdef.typename);
  3859. resultdef:=left.resultdef;
  3860. end;
  3861. in_objc_selector_x:
  3862. begin
  3863. result:=cobjcselectornode.create(left);
  3864. { reused }
  3865. left:=nil;
  3866. end;
  3867. in_objc_protocol_x:
  3868. begin
  3869. result:=cobjcprotocolnode.create(left);
  3870. { reused }
  3871. left:=nil;
  3872. end;
  3873. in_objc_encode_x:
  3874. begin
  3875. result:=handle_objc_encode;
  3876. end;
  3877. in_default_x:
  3878. begin
  3879. result:=handle_default;
  3880. end;
  3881. in_box_x:
  3882. begin
  3883. result:=handle_box;
  3884. end;
  3885. in_unbox_x_y:
  3886. begin
  3887. result:=handle_unbox;
  3888. end;
  3889. in_fma_single,
  3890. in_fma_double,
  3891. in_fma_extended,
  3892. in_fma_float128:
  3893. begin
  3894. set_varstate(tcallparanode(left).left,vs_read,[vsf_must_be_valid]);
  3895. set_varstate(tcallparanode(tcallparanode(left).right).left,vs_read,[vsf_must_be_valid]);
  3896. set_varstate(tcallparanode(tcallparanode(tcallparanode(left).right).right).left,vs_read,[vsf_must_be_valid]);
  3897. resultdef:=tcallparanode(left).left.resultdef;
  3898. end;
  3899. in_max_longint,
  3900. in_max_dword,
  3901. in_min_longint,
  3902. in_min_dword,
  3903. in_max_int64,
  3904. in_max_qword,
  3905. in_min_int64,
  3906. in_min_qword,
  3907. in_max_single,
  3908. in_max_double,
  3909. in_min_single,
  3910. in_min_double:
  3911. begin
  3912. set_varstate(tcallparanode(left).left,vs_read,[vsf_must_be_valid]);
  3913. set_varstate(tcallparanode(tcallparanode(left).right).left,vs_read,[vsf_must_be_valid]);
  3914. resultdef:=tcallparanode(left).left.resultdef;
  3915. end;
  3916. in_delete_x_y_z:
  3917. begin
  3918. result:=handle_delete;
  3919. end;
  3920. in_insert_x_y_z:
  3921. begin
  3922. result:=handle_insert;
  3923. end;
  3924. in_concat_x:
  3925. begin
  3926. result:=handle_concat;
  3927. end;
  3928. else
  3929. result:=pass_typecheck_cpu;
  3930. end;
  3931. end;
  3932. if not assigned(result) and not
  3933. codegenerror then
  3934. result:=simplify(false);
  3935. end;
  3936. function tinlinenode.pass_typecheck_cpu : tnode;
  3937. begin
  3938. Result:=nil;
  3939. internalerror(2017110102);
  3940. end;
  3941. function tinlinenode.pass_1 : tnode;
  3942. var
  3943. hp: tnode;
  3944. shiftconst: longint;
  3945. objdef: tobjectdef;
  3946. sym : tsym;
  3947. begin
  3948. result:=nil;
  3949. { if we handle writeln; left contains no valid address }
  3950. if assigned(left) then
  3951. begin
  3952. if left.nodetype=callparan then
  3953. tcallparanode(left).firstcallparan
  3954. else
  3955. firstpass(left);
  3956. end;
  3957. { intern const should already be handled }
  3958. if inf_inlineconst in inlinenodeflags then
  3959. internalerror(200104044);
  3960. case inlinenumber of
  3961. in_lo_qword,
  3962. in_hi_qword,
  3963. in_lo_long,
  3964. in_hi_long,
  3965. in_lo_word,
  3966. in_hi_word:
  3967. begin
  3968. shiftconst := 0;
  3969. case inlinenumber of
  3970. in_hi_qword:
  3971. shiftconst := 32;
  3972. in_hi_long:
  3973. shiftconst := 16;
  3974. in_hi_word:
  3975. shiftconst := 8;
  3976. else
  3977. ;
  3978. end;
  3979. if shiftconst <> 0 then
  3980. result := ctypeconvnode.create_internal(cshlshrnode.create(shrn,left,
  3981. cordconstnode.create(shiftconst,sinttype,false)),resultdef)
  3982. else
  3983. result := ctypeconvnode.create_internal(left,resultdef);
  3984. left := nil;
  3985. firstpass(result);
  3986. end;
  3987. in_sizeof_x,
  3988. in_typeof_x:
  3989. begin
  3990. expectloc:=LOC_REGISTER;
  3991. case left.resultdef.typ of
  3992. objectdef,classrefdef:
  3993. begin
  3994. if left.resultdef.typ=objectdef then
  3995. begin
  3996. result:=cloadvmtaddrnode.create(left);
  3997. objdef:=tobjectdef(left.resultdef);
  3998. end
  3999. else
  4000. begin
  4001. result:=left;
  4002. objdef:=tobjectdef(tclassrefdef(left.resultdef).pointeddef);
  4003. end;
  4004. left:=nil;
  4005. if inlinenumber=in_sizeof_x then
  4006. begin
  4007. inserttypeconv_explicit(result,cpointerdef.getreusable(objdef.vmt_def));
  4008. result:=cderefnode.create(result);
  4009. result:=genloadfield(result,'VINSTANCESIZE');
  4010. end
  4011. else
  4012. inserttypeconv_explicit(result,voidpointertype);
  4013. end;
  4014. undefineddef:
  4015. ;
  4016. else
  4017. internalerror(2015122702);
  4018. end;
  4019. end;
  4020. in_length_x:
  4021. begin
  4022. result:=first_length;
  4023. end;
  4024. in_typeinfo_x:
  4025. begin
  4026. if (left.resultdef.typ=enumdef) and
  4027. (tenumdef(left.resultdef).has_jumps) then
  4028. begin
  4029. if (left.nodetype=typen) and (sp_generic_para in ttypenode(left).typesym.symoptions) then
  4030. result:=cnilnode.create
  4031. else
  4032. internalerror(2021032601);
  4033. end
  4034. else
  4035. result:=caddrnode.create_internal(
  4036. crttinode.create(tstoreddef(left.resultdef),fullrtti,rdt_normal)
  4037. );
  4038. end;
  4039. in_gettypekind_x:
  4040. begin
  4041. sym:=tenumdef(typekindtype).int2enumsym(get_typekind(left.resultdef));
  4042. if not assigned(sym) then
  4043. internalerror(2017081101);
  4044. if sym.typ<>enumsym then
  4045. internalerror(2017081102);
  4046. result:=genenumnode(tenumsym(sym));
  4047. end;
  4048. in_ismanagedtype_x:
  4049. begin
  4050. if left.resultdef.needs_inittable then
  4051. result:=cordconstnode.create(1,resultdef,false)
  4052. else
  4053. result:=cordconstnode.create(0,resultdef,false);
  4054. end;
  4055. in_isconstvalue_x:
  4056. begin
  4057. if is_constnode(left) then
  4058. result:=cordconstnode.create(1,resultdef,false)
  4059. else
  4060. result:=cordconstnode.create(0,resultdef,false);
  4061. end;
  4062. in_assigned_x:
  4063. begin
  4064. result:=first_assigned;
  4065. end;
  4066. in_pred_x,
  4067. in_succ_x:
  4068. begin
  4069. expectloc:=LOC_REGISTER;
  4070. { in case of range/overflow checking, use a regular addnode
  4071. because it's too complex to handle correctly otherwise }
  4072. {$ifndef jvm}
  4073. { enums are class instances in the JVM -> always need conversion }
  4074. if (([cs_check_overflow,cs_check_range]*current_settings.localswitches)<>[]) and not(nf_internal in flags) then
  4075. {$endif}
  4076. begin
  4077. { create constant 1 }
  4078. hp:=cordconstnode.create(1,left.resultdef,false);
  4079. typecheckpass(hp);
  4080. if not is_integer(hp.resultdef) then
  4081. inserttypeconv_internal(hp,sinttype);
  4082. { avoid type errors from the addn/subn }
  4083. if not is_integer(left.resultdef) then
  4084. inserttypeconv_internal(left,sinttype);
  4085. { addition/substraction depending on succ/pred }
  4086. if inlinenumber=in_succ_x then
  4087. hp:=caddnode.create(addn,left,hp)
  4088. else
  4089. hp:=caddnode.create(subn,left,hp);
  4090. { the condition above is not tested for jvm, so we need to avoid overflow checks here
  4091. by setting nf_internal for the add/sub node as well }
  4092. if nf_internal in flags then
  4093. include(hp.flags,nf_internal);
  4094. { assign result of addition }
  4095. if not(is_integer(resultdef)) then
  4096. inserttypeconv(hp,corddef.create(
  4097. {$ifdef cpu64bitaddr}
  4098. s64bit,
  4099. {$else cpu64bitaddr}
  4100. s32bit,
  4101. {$endif cpu64bitaddr}
  4102. get_min_value(resultdef),
  4103. get_max_value(resultdef),
  4104. true))
  4105. else
  4106. inserttypeconv(hp,resultdef);
  4107. if nf_internal in flags then
  4108. include(hp.flags,nf_internal);
  4109. { avoid any possible errors/warnings }
  4110. inserttypeconv_internal(hp,resultdef);
  4111. { firstpass it }
  4112. firstpass(hp);
  4113. { left is reused }
  4114. left:=nil;
  4115. { return new node }
  4116. result:=hp;
  4117. end;
  4118. end;
  4119. in_setlength_x:
  4120. result:=first_setlength;
  4121. in_copy_x:
  4122. result:=first_copy;
  4123. in_initialize_x,
  4124. in_finalize_x:
  4125. begin
  4126. expectloc:=LOC_VOID;
  4127. end;
  4128. in_inc_x,
  4129. in_dec_x:
  4130. begin
  4131. result:=first_IncDec;
  4132. end;
  4133. in_and_assign_x_y,
  4134. in_or_assign_x_y,
  4135. in_xor_assign_x_y,
  4136. in_sar_assign_x_y,
  4137. in_shl_assign_x_y,
  4138. in_shr_assign_x_y,
  4139. in_rol_assign_x_y,
  4140. in_ror_assign_x_y:
  4141. begin
  4142. result:=first_AndOrXorShiftRot_assign;
  4143. end;
  4144. in_neg_assign_x,
  4145. in_not_assign_x:
  4146. begin
  4147. result:=first_NegNot_assign;
  4148. end;
  4149. in_include_x_y,
  4150. in_exclude_x_y:
  4151. begin
  4152. result:=first_IncludeExclude;
  4153. end;
  4154. in_pack_x_y_z,
  4155. in_unpack_x_y_z:
  4156. begin
  4157. result:=first_pack_unpack;
  4158. end;
  4159. in_exp_real:
  4160. begin
  4161. result:= first_exp_real;
  4162. end;
  4163. in_round_real:
  4164. begin
  4165. result:= first_round_real;
  4166. end;
  4167. in_trunc_real:
  4168. begin
  4169. result:= first_trunc_real;
  4170. end;
  4171. in_int_real:
  4172. begin
  4173. result:= first_int_real;
  4174. end;
  4175. in_frac_real:
  4176. begin
  4177. result:= first_frac_real;
  4178. end;
  4179. in_cos_real:
  4180. begin
  4181. result:= first_cos_real;
  4182. end;
  4183. in_sin_real:
  4184. begin
  4185. result := first_sin_real;
  4186. end;
  4187. in_arctan_real:
  4188. begin
  4189. result := first_arctan_real;
  4190. end;
  4191. in_pi_real :
  4192. begin
  4193. result := first_pi;
  4194. end;
  4195. in_abs_real:
  4196. begin
  4197. result := first_abs_real;
  4198. end;
  4199. in_abs_long:
  4200. begin
  4201. result := first_abs_long;
  4202. end;
  4203. in_sqr_real:
  4204. begin
  4205. result := first_sqr_real;
  4206. end;
  4207. in_sqrt_real:
  4208. begin
  4209. result := first_sqrt_real;
  4210. end;
  4211. in_ln_real:
  4212. begin
  4213. result := first_ln_real;
  4214. end;
  4215. {$ifdef SUPPORT_MMX}
  4216. in_mmx_pcmpeqb..in_mmx_pcmpgtw:
  4217. begin
  4218. end;
  4219. {$endif SUPPORT_MMX}
  4220. in_assert_x_y :
  4221. begin
  4222. result:=first_assert;
  4223. end;
  4224. in_low_x:
  4225. internalerror(200104047);
  4226. in_high_x:
  4227. begin
  4228. result:=first_high;
  4229. end;
  4230. in_slice_x:
  4231. { slice can be used only in calls for open array parameters, so it has to be converted appropriatly before
  4232. if we get here, the array could not be passed to an open array parameter so it is an error }
  4233. CGMessagePos(left.fileinfo,type_e_mismatch);
  4234. in_ord_x,
  4235. in_chr_byte:
  4236. begin
  4237. { should not happend as it's converted to typeconv }
  4238. internalerror(200104045);
  4239. end;
  4240. in_ofs_x :
  4241. internalerror(2000101002);
  4242. in_seg_x :
  4243. begin
  4244. result:=first_seg;
  4245. end;
  4246. in_settextbuf_file_x,
  4247. in_reset_typedfile,
  4248. in_rewrite_typedfile,
  4249. in_reset_typedfile_name,
  4250. in_rewrite_typedfile_name,
  4251. in_str_x_string,
  4252. in_val_x,
  4253. in_read_x,
  4254. in_readln_x,
  4255. in_write_x,
  4256. in_writeln_x :
  4257. begin
  4258. { should be handled by pass_typecheck }
  4259. internalerror(2001082302);
  4260. end;
  4261. in_get_frame:
  4262. begin
  4263. result:=first_get_frame;
  4264. end;
  4265. in_get_caller_frame:
  4266. begin
  4267. expectloc:=LOC_REGISTER;
  4268. end;
  4269. in_get_caller_addr:
  4270. begin
  4271. expectloc:=LOC_REGISTER;
  4272. end;
  4273. in_prefetch_var:
  4274. begin
  4275. expectloc:=LOC_VOID;
  4276. end;
  4277. in_aligned_x,
  4278. in_unaligned_x,
  4279. in_volatile_x:
  4280. begin
  4281. expectloc:=tcallparanode(left).left.expectloc;
  4282. end;
  4283. in_rol_x,
  4284. in_rol_x_y,
  4285. in_ror_x,
  4286. in_ror_x_y:
  4287. expectloc:=LOC_REGISTER;
  4288. in_bsf_x,
  4289. in_bsr_x:
  4290. result:=first_bitscan;
  4291. in_sar_x,
  4292. in_sar_x_y:
  4293. result:=first_sar;
  4294. in_popcnt_x:
  4295. result:=first_popcnt;
  4296. in_new_x:
  4297. result:=first_new;
  4298. in_box_x:
  4299. result:=first_box;
  4300. in_unbox_x_y:
  4301. result:=first_unbox;
  4302. in_fma_single,
  4303. in_fma_double,
  4304. in_fma_extended,
  4305. in_fma_float128:
  4306. result:=first_fma;
  4307. in_max_longint,
  4308. in_max_dword,
  4309. in_min_longint,
  4310. in_min_dword,
  4311. in_max_int64,
  4312. in_max_qword,
  4313. in_min_int64,
  4314. in_min_qword,
  4315. in_min_single,
  4316. in_min_double,
  4317. in_max_single,
  4318. in_max_double:
  4319. result:=first_minmax;
  4320. else
  4321. result:=first_cpu;
  4322. end;
  4323. end;
  4324. {$maxfpuregisters default}
  4325. function tinlinenode.docompare(p: tnode): boolean;
  4326. begin
  4327. docompare :=
  4328. inherited docompare(p) and
  4329. (inlinenumber = tinlinenode(p).inlinenumber);
  4330. end;
  4331. procedure tinlinenode.mark_write;
  4332. begin
  4333. case inlinenumber of
  4334. in_aligned_x, in_unaligned_x:
  4335. tcallparanode(left).left.mark_write;
  4336. else
  4337. inherited mark_write;
  4338. end;
  4339. end;
  4340. function tinlinenode.first_pi : tnode;
  4341. begin
  4342. result:=crealconstnode.create(getpi,pbestrealtype^);
  4343. end;
  4344. function tinlinenode.first_arctan_real : tnode;
  4345. var
  4346. temp_pnode: pnode;
  4347. begin
  4348. { create the call to the helper }
  4349. { on entry left node contains the parameter }
  4350. if left.nodetype = callparan then
  4351. temp_pnode := @tcallparanode(left).left
  4352. else
  4353. temp_pnode := @left;
  4354. result := ccallnode.createintern('fpc_arctan_real',
  4355. ccallparanode.create(temp_pnode^,nil));
  4356. temp_pnode^ := nil;
  4357. end;
  4358. function tinlinenode.first_abs_real : tnode;
  4359. var
  4360. callnode : tcallnode;
  4361. temp_pnode: pnode;
  4362. begin
  4363. { create the call to the helper }
  4364. { on entry left node contains the parameter }
  4365. if left.nodetype = callparan then
  4366. temp_pnode := @tcallparanode(left).left
  4367. else
  4368. temp_pnode := @left;
  4369. callnode:=ccallnode.createintern('fpc_abs_real',
  4370. ccallparanode.create(temp_pnode^,nil));
  4371. result := ctypeconvnode.create(callnode,resultdef);
  4372. include(callnode.callnodeflags,cnf_check_fpu_exceptions);
  4373. temp_pnode^ := nil;
  4374. end;
  4375. function tinlinenode.first_sqr_real : tnode;
  4376. var
  4377. callnode : tcallnode;
  4378. temp_pnode: pnode;
  4379. begin
  4380. {$ifndef cpufpemu}
  4381. { this procedure might be only used for cpus definining cpufpemu else
  4382. the optimizer might go into an endless loop when doing x*x -> changes }
  4383. internalerror(2011092401);
  4384. {$endif cpufpemu}
  4385. { create the call to the helper }
  4386. { on entry left node contains the parameter }
  4387. if left.nodetype = callparan then
  4388. temp_pnode := @tcallparanode(left).left
  4389. else
  4390. temp_pnode := @left;
  4391. callnode:=ccallnode.createintern('fpc_sqr_real',
  4392. ccallparanode.create(temp_pnode^,nil));
  4393. result := ctypeconvnode.create(callnode,resultdef);
  4394. include(callnode.callnodeflags,cnf_check_fpu_exceptions);
  4395. temp_pnode^ := nil;
  4396. end;
  4397. function tinlinenode.first_sqrt_real : tnode;
  4398. var
  4399. fdef: tdef;
  4400. procname: string[31];
  4401. callnode: tcallnode;
  4402. temp_pnode: pnode;
  4403. begin
  4404. if left.nodetype = callparan then
  4405. temp_pnode := @tcallparanode(left).left
  4406. else
  4407. temp_pnode := @left;
  4408. if ((cs_fp_emulation in current_settings.moduleswitches)
  4409. {$ifdef cpufpemu}
  4410. or (current_settings.fputype=fpu_soft)
  4411. {$endif cpufpemu}
  4412. ) and not (target_info.system in systems_wince) then
  4413. begin
  4414. case tfloatdef(temp_pnode^.resultdef).floattype of
  4415. s32real:
  4416. begin
  4417. fdef:=search_system_type('FLOAT32REC').typedef;
  4418. procname:='float32_sqrt';
  4419. end;
  4420. s64real:
  4421. begin
  4422. fdef:=search_system_type('FLOAT64').typedef;
  4423. procname:='float64_sqrt';
  4424. end;
  4425. {!!! not yet implemented
  4426. s128real:
  4427. }
  4428. else
  4429. internalerror(2014052101);
  4430. end;
  4431. result:=ctypeconvnode.create_internal(ccallnode.createintern(procname,ccallparanode.create(
  4432. ctypeconvnode.create_internal(temp_pnode^,fdef),nil)),resultdef);
  4433. end
  4434. else
  4435. begin
  4436. { create the call to the helper }
  4437. { on entry left node contains the parameter }
  4438. callnode := ccallnode.createintern('fpc_sqrt_real',
  4439. ccallparanode.create(temp_pnode^,nil));
  4440. result := ctypeconvnode.create(callnode,resultdef);
  4441. include(callnode.callnodeflags,cnf_check_fpu_exceptions);
  4442. end;
  4443. temp_pnode^ := nil;
  4444. end;
  4445. function tinlinenode.first_ln_real : tnode;
  4446. var
  4447. temp_pnode: pnode;
  4448. begin
  4449. { create the call to the helper }
  4450. { on entry left node contains the parameter }
  4451. if left.nodetype = callparan then
  4452. temp_pnode := @tcallparanode(left).left
  4453. else
  4454. temp_pnode := @left;
  4455. result := ccallnode.createintern('fpc_ln_real',
  4456. ccallparanode.create(temp_pnode^,nil));
  4457. include(tcallnode(result).callnodeflags,cnf_check_fpu_exceptions);
  4458. temp_pnode^ := nil;
  4459. end;
  4460. function tinlinenode.first_cos_real : tnode;
  4461. var
  4462. temp_pnode: pnode;
  4463. begin
  4464. { create the call to the helper }
  4465. { on entry left node contains the parameter }
  4466. if left.nodetype = callparan then
  4467. temp_pnode := @tcallparanode(left).left
  4468. else
  4469. temp_pnode := @left;
  4470. result := ccallnode.createintern('fpc_cos_real',
  4471. ccallparanode.create(temp_pnode^,nil));
  4472. include(tcallnode(result).callnodeflags,cnf_check_fpu_exceptions);
  4473. temp_pnode^ := nil;
  4474. end;
  4475. function tinlinenode.first_sin_real : tnode;
  4476. var
  4477. temp_pnode: pnode;
  4478. begin
  4479. { create the call to the helper }
  4480. { on entry left node contains the parameter }
  4481. if left.nodetype = callparan then
  4482. temp_pnode := @tcallparanode(left).left
  4483. else
  4484. temp_pnode := @left;
  4485. result := ccallnode.createintern('fpc_sin_real',
  4486. ccallparanode.create(temp_pnode^,nil));
  4487. include(tcallnode(result).callnodeflags,cnf_check_fpu_exceptions);
  4488. temp_pnode^ := nil;
  4489. end;
  4490. function tinlinenode.first_exp_real : tnode;
  4491. var
  4492. temp_pnode: pnode;
  4493. begin
  4494. { create the call to the helper }
  4495. { on entry left node contains the parameter }
  4496. if left.nodetype = callparan then
  4497. temp_pnode := @tcallparanode(left).left
  4498. else
  4499. temp_pnode := @left;
  4500. result := ccallnode.createintern('fpc_exp_real',ccallparanode.create(temp_pnode^,nil));
  4501. include(tcallnode(result).callnodeflags,cnf_check_fpu_exceptions);
  4502. temp_pnode^ := nil;
  4503. end;
  4504. function tinlinenode.first_int_real : tnode;
  4505. var
  4506. temp_pnode: pnode;
  4507. begin
  4508. { create the call to the helper }
  4509. { on entry left node contains the parameter }
  4510. if left.nodetype = callparan then
  4511. temp_pnode := @tcallparanode(left).left
  4512. else
  4513. temp_pnode := @left;
  4514. result := ccallnode.createintern('fpc_int_real',ccallparanode.create(temp_pnode^,nil));
  4515. include(tcallnode(result).callnodeflags,cnf_check_fpu_exceptions);
  4516. temp_pnode^ := nil;
  4517. end;
  4518. function tinlinenode.first_frac_real : tnode;
  4519. var
  4520. temp_pnode: pnode;
  4521. begin
  4522. { create the call to the helper }
  4523. { on entry left node contains the parameter }
  4524. if left.nodetype = callparan then
  4525. temp_pnode := @tcallparanode(left).left
  4526. else
  4527. temp_pnode := @left;
  4528. result := ccallnode.createintern('fpc_frac_real',ccallparanode.create(temp_pnode^,nil));
  4529. include(tcallnode(result).callnodeflags,cnf_check_fpu_exceptions);
  4530. temp_pnode^ := nil;
  4531. end;
  4532. function tinlinenode.first_round_real : tnode;
  4533. var
  4534. temp_pnode: pnode;
  4535. begin
  4536. { create the call to the helper }
  4537. { on entry left node contains the parameter }
  4538. if left.nodetype = callparan then
  4539. temp_pnode := @tcallparanode(left).left
  4540. else
  4541. temp_pnode := @left;
  4542. result := ccallnode.createintern('fpc_round_real',ccallparanode.create(temp_pnode^,nil));
  4543. include(tcallnode(result).callnodeflags,cnf_check_fpu_exceptions);
  4544. temp_pnode^ := nil;
  4545. end;
  4546. function tinlinenode.first_trunc_real : tnode;
  4547. var
  4548. temp_pnode: pnode;
  4549. begin
  4550. { create the call to the helper }
  4551. { on entry left node contains the parameter }
  4552. if left.nodetype = callparan then
  4553. temp_pnode := @tcallparanode(left).left
  4554. else
  4555. temp_pnode := @left;
  4556. result := ccallnode.createintern('fpc_trunc_real',ccallparanode.create(temp_pnode^,nil));
  4557. include(tcallnode(result).callnodeflags,cnf_check_fpu_exceptions);
  4558. temp_pnode^ := nil;
  4559. end;
  4560. function tinlinenode.first_abs_long : tnode;
  4561. begin
  4562. expectloc:=LOC_REGISTER;
  4563. result:=nil;
  4564. end;
  4565. function tinlinenode.getaddsub_for_incdec : tnode;
  4566. var
  4567. hp,hpp,resultnode : tnode;
  4568. tempnode: ttempcreatenode;
  4569. newstatement: tstatementnode;
  4570. newblock: tblocknode;
  4571. begin
  4572. newblock := internalstatements(newstatement);
  4573. { extra parameter? }
  4574. if assigned(tcallparanode(left).right) then
  4575. begin
  4576. { Yes, use for add node }
  4577. hpp := tcallparanode(tcallparanode(left).right).left;
  4578. tcallparanode(tcallparanode(left).right).left := nil;
  4579. if assigned(tcallparanode(tcallparanode(left).right).right) then
  4580. CGMessage(parser_e_illegal_expression);
  4581. end
  4582. else
  4583. begin
  4584. { no, create constant 1 }
  4585. hpp := cordconstnode.create(1,tcallparanode(left).left.resultdef,false);
  4586. end;
  4587. typecheckpass(hpp);
  4588. { make sure we don't call functions part of the left node twice (and generally }
  4589. { optimize the code generation) }
  4590. { Storing address is not always an optimization: alignment of left is not known
  4591. at this point, so we must assume the worst and use an unaligned pointer.
  4592. This results in larger and slower code on alignment-sensitive targets.
  4593. Therefore the complexity condition below is questionable, maybe just filtering
  4594. out calls with "= NODE_COMPLEXITY_INF" is sufficient.
  4595. Value of 3 corresponds to subscript nodes, i.e. record field. }
  4596. if node_complexity(tcallparanode(left).left) > 3 then
  4597. begin
  4598. tempnode := ctempcreatenode.create(voidpointertype,voidpointertype.size,tt_persistent,true);
  4599. addstatement(newstatement,tempnode);
  4600. addstatement(newstatement,cassignmentnode.create(ctemprefnode.create(tempnode),
  4601. caddrnode.create_internal(tcallparanode(left).left.getcopy)));
  4602. hp := cderefnode.create(ctemprefnode.create(tempnode));
  4603. inserttypeconv_internal(hp,tcallparanode(left).left.resultdef);
  4604. end
  4605. else
  4606. begin
  4607. hp := tcallparanode(left).left.getcopy;
  4608. tempnode := nil;
  4609. end;
  4610. resultnode := hp.getcopy;
  4611. { Remove "modify" flag from what will be an assignment destination }
  4612. Exclude(resultnode.flags, nf_modify);
  4613. { avoid type errors from the addn/subn }
  4614. if not is_integer(resultnode.resultdef) then
  4615. begin
  4616. inserttypeconv_internal(hp,sinttype);
  4617. inserttypeconv_internal(hpp,sinttype);
  4618. end;
  4619. { addition/subtraction depending on inc/dec }
  4620. if inlinenumber = in_inc_x then
  4621. hpp := caddnode.create_internal(addn,hp,hpp)
  4622. else
  4623. hpp := caddnode.create_internal(subn,hp,hpp);
  4624. { assign result of addition }
  4625. { inherit internal flag }
  4626. if not(is_integer(resultnode.resultdef)) then
  4627. begin
  4628. if nf_internal in flags then
  4629. inserttypeconv_internal(hpp,corddef.create(
  4630. {$ifdef cpu64bitaddr}
  4631. s64bit,
  4632. {$else cpu64bitaddr}
  4633. s32bit,
  4634. {$endif cpu64bitaddr}
  4635. get_min_value(resultnode.resultdef),
  4636. get_max_value(resultnode.resultdef),
  4637. true))
  4638. else
  4639. inserttypeconv(hpp,corddef.create(
  4640. {$ifdef cpu64bitaddr}
  4641. s64bit,
  4642. {$else cpu64bitaddr}
  4643. s32bit,
  4644. {$endif cpu64bitaddr}
  4645. get_min_value(resultnode.resultdef),
  4646. get_max_value(resultnode.resultdef),
  4647. true))
  4648. end
  4649. else
  4650. begin
  4651. if nf_internal in flags then
  4652. inserttypeconv_internal(hpp,resultnode.resultdef)
  4653. else
  4654. inserttypeconv(hpp,resultnode.resultdef);
  4655. end;
  4656. { avoid any possible warnings }
  4657. inserttypeconv_internal(hpp,resultnode.resultdef);
  4658. { force pass 1, so copied trees get first pass'ed as well and flags like
  4659. nf_call_unique get set right }
  4660. node_reset_pass1_write(hpp);
  4661. do_typecheckpass(hpp);
  4662. addstatement(newstatement,cassignmentnode.create(resultnode,hpp));
  4663. { firstpass it }
  4664. firstpass(tnode(newstatement.left));
  4665. { deallocate the temp }
  4666. if assigned(tempnode) then
  4667. addstatement(newstatement,ctempdeletenode.create(tempnode));
  4668. { firstpass it }
  4669. firstpass(tnode(newblock));
  4670. { return new node }
  4671. result := newblock;
  4672. end;
  4673. function tinlinenode.first_IncDec: tnode;
  4674. begin
  4675. expectloc:=LOC_VOID;
  4676. result:=nil;
  4677. { range/overflow checking doesn't work properly }
  4678. { with the inc/dec code that's generated (JM) }
  4679. if ((localswitches * [cs_check_overflow,cs_check_range] <> []) and
  4680. { No overflow check for pointer operations, because inc(pointer,-1) will always
  4681. trigger an overflow. For uint32 it works because then the operation is done
  4682. in 64bit. Range checking is not applicable to pointers either }
  4683. (tcallparanode(left).left.resultdef.typ<>pointerdef))
  4684. {$ifdef jvm}
  4685. { enums are class instances on the JVM -> special treatment }
  4686. or (tcallparanode(left).left.resultdef.typ=enumdef)
  4687. {$endif}
  4688. then
  4689. { convert to simple add (JM) }
  4690. result:=getaddsub_for_incdec
  4691. end;
  4692. function tinlinenode.first_IncludeExclude: tnode;
  4693. begin
  4694. result:=nil;
  4695. expectloc:=LOC_VOID;
  4696. end;
  4697. function tinlinenode.first_get_frame: tnode;
  4698. begin
  4699. include(current_procinfo.flags,pi_needs_stackframe);
  4700. include(current_procinfo.flags,pi_uses_get_frame);
  4701. expectloc:=LOC_CREGISTER;
  4702. result:=nil;
  4703. end;
  4704. function tinlinenode.first_setlength: tnode;
  4705. var
  4706. paras : tnode;
  4707. npara,
  4708. ppn : tcallparanode;
  4709. dims,
  4710. counter : integer;
  4711. isarray : boolean;
  4712. destppn : tnode;
  4713. newstatement : tstatementnode;
  4714. temp : ttempcreatenode;
  4715. newblock : tnode;
  4716. begin
  4717. paras:=left;
  4718. ppn:=tcallparanode(paras);
  4719. dims:=0;
  4720. while assigned(ppn.right) do
  4721. begin
  4722. inc(dims);
  4723. ppn:=tcallparanode(ppn.right);
  4724. end;
  4725. destppn:=ppn.left;
  4726. isarray:=is_dynamic_array(destppn.resultdef);
  4727. { first param must be a string or dynamic array ...}
  4728. if isarray then
  4729. begin
  4730. { SetLength(Arr, 0), Arr := nil, Arr := [] }
  4731. if (dims=1) and is_constintvalue(tcallparanode(paras).left, 0) then
  4732. begin
  4733. ppn.left:=nil; { unlink destppn }
  4734. result:=ccallparanode.create(ctypeconvnode.create_internal(destppn,voidpointertype),nil);
  4735. result:=ccallnode.createintern('fpc_dynarray_clear',
  4736. ccallparanode.create(caddrnode.create_internal(
  4737. crttinode.create(tstoreddef(destppn.resultdef),initrtti,rdt_normal)),
  4738. result));
  4739. exit;
  4740. end;
  4741. { create statements with call initialize the arguments and
  4742. call fpc_dynarr_setlength }
  4743. newblock:=internalstatements(newstatement);
  4744. { get temp for array of lengths }
  4745. temp:=ctempcreatenode.create(carraydef.getreusable(sinttype,dims),dims*sinttype.size,tt_persistent,false);
  4746. addstatement(newstatement,temp);
  4747. { load array of lengths }
  4748. ppn:=tcallparanode(paras);
  4749. counter:=dims-1;
  4750. while assigned(ppn.right) do
  4751. begin
  4752. addstatement(newstatement,cassignmentnode.create(
  4753. cvecnode.create(
  4754. ctemprefnode.create(temp),
  4755. genintconstnode(counter)
  4756. ),
  4757. ppn.left));
  4758. ppn.left:=nil;
  4759. dec(counter);
  4760. ppn:=tcallparanode(ppn.right);
  4761. end;
  4762. { destppn is also reused }
  4763. ppn.left:=nil;
  4764. { create call to fpc_dynarr_setlength }
  4765. npara:=ccallparanode.create(caddrnode.create_internal(
  4766. cvecnode.create(
  4767. ctemprefnode.create(temp),
  4768. genintconstnode(0)
  4769. )),
  4770. ccallparanode.create(cordconstnode.create
  4771. (dims,sinttype,true),
  4772. ccallparanode.create(caddrnode.create_internal
  4773. (crttinode.create(tstoreddef(destppn.resultdef),initrtti,rdt_normal)),
  4774. ccallparanode.create(ctypeconvnode.create_internal(destppn,voidpointertype),nil))));
  4775. addstatement(newstatement,ccallnode.createintern('fpc_dynarray_setlength',npara));
  4776. addstatement(newstatement,ctempdeletenode.create(temp));
  4777. end
  4778. else if is_ansistring(destppn.resultdef) then
  4779. begin
  4780. newblock:=ccallnode.createintern(
  4781. 'fpc_'+tstringdef(destppn.resultdef).stringtypname+'_setlength',
  4782. ccallparanode.create(
  4783. cordconstnode.create(getparaencoding(destppn.resultdef),u16inttype,true),
  4784. paras
  4785. )
  4786. );
  4787. { we reused the parameters, make sure we don't release them }
  4788. left:=nil;
  4789. end
  4790. else
  4791. begin
  4792. { we can reuse the supplied parameters }
  4793. newblock:=ccallnode.createintern(
  4794. 'fpc_'+tstringdef(destppn.resultdef).stringtypname+'_setlength',paras);
  4795. { we reused the parameters, make sure we don't release them }
  4796. left:=nil;
  4797. end;
  4798. result:=newblock;
  4799. end;
  4800. function tinlinenode.first_copy: tnode;
  4801. var
  4802. lowppn,
  4803. countppn,
  4804. elesizeppn,
  4805. eletypeppn,
  4806. maxcountppn,
  4807. arrayppn,
  4808. rttippn,
  4809. npara,
  4810. paras : tnode;
  4811. ppn : tcallparanode;
  4812. paradef : tdef;
  4813. counter : integer;
  4814. begin
  4815. { determine copy function to use based on the first argument,
  4816. also count the number of arguments in this loop }
  4817. counter:=1;
  4818. paras:=left;
  4819. ppn:=tcallparanode(paras);
  4820. while assigned(ppn.right) do
  4821. begin
  4822. inc(counter);
  4823. ppn:=tcallparanode(ppn.right);
  4824. end;
  4825. paradef:=ppn.left.resultdef;
  4826. { fill up third parameter }
  4827. if counter=2 then
  4828. begin
  4829. paras:=ccallparanode.create(cordconstnode.create(torddef(sinttype).high,sinttype,false),paras);
  4830. counter:=3;
  4831. end;
  4832. if is_ansistring(resultdef) then
  4833. { keep the specific kind of ansistringdef as result }
  4834. result:=ccallnode.createinternres('fpc_ansistr_copy',paras,resultdef)
  4835. else if is_widestring(resultdef) then
  4836. result:=ccallnode.createintern('fpc_widestr_copy',paras)
  4837. else if is_unicodestring(resultdef) then
  4838. result:=ccallnode.createintern('fpc_unicodestr_copy',paras)
  4839. { can't check for resultdef = cansichartype, because resultdef=
  4840. cshortstringtype here }
  4841. else if is_char(paradef) then
  4842. result:=ccallnode.createintern('fpc_char_copy',paras)
  4843. else if is_dynamic_array(resultdef) then
  4844. begin
  4845. { create statements with call }
  4846. elesizeppn:=cordconstnode.create(tarraydef(paradef).elesize,sinttype,false);
  4847. if is_managed_type(tarraydef(paradef).elementdef) then
  4848. eletypeppn:=caddrnode.create_internal(
  4849. crttinode.create(tstoreddef(tarraydef(paradef).elementdef),initrtti,rdt_normal))
  4850. else
  4851. eletypeppn:=cordconstnode.create(0,voidpointertype,false);
  4852. maxcountppn:=geninlinenode(in_length_x,false,ppn.left.getcopy);
  4853. case counter of
  4854. 1:
  4855. begin
  4856. { copy the whole array using [0..high(sizeint)] range }
  4857. countppn:=cordconstnode.create(torddef(sinttype).high,sinttype,false);
  4858. lowppn:=cordconstnode.create(0,sinttype,false);
  4859. end;
  4860. 2:
  4861. begin
  4862. { copy the array using [low..high(sizeint)] range }
  4863. countppn:=cordconstnode.create(torddef(sinttype).high,sinttype,false);
  4864. lowppn:=tcallparanode(paras).left.getcopy;
  4865. end;
  4866. 3:
  4867. begin
  4868. countppn:=tcallparanode(paras).left.getcopy;
  4869. lowppn:=tcallparanode(tcallparanode(paras).right).left.getcopy;
  4870. end;
  4871. else
  4872. internalerror(2012100703);
  4873. end;
  4874. if is_open_array(paradef) then
  4875. begin
  4876. arrayppn:=caddrnode.create_internal(ppn.left);
  4877. end
  4878. else if is_dynamic_array(paradef) then
  4879. begin
  4880. arrayppn:=ctypeconvnode.create_internal(ppn.left,voidpointertype);
  4881. end
  4882. else
  4883. internalerror(2012100704);
  4884. rttippn:=caddrnode.create_internal(crttinode.create(tstoreddef(resultdef),initrtti,rdt_normal));
  4885. { create call to fpc_array_to_dynarray_copy }
  4886. npara:=ccallparanode.create(eletypeppn,
  4887. ccallparanode.create(elesizeppn,
  4888. ccallparanode.create(maxcountppn,
  4889. ccallparanode.create(countppn,
  4890. ccallparanode.create(lowppn,
  4891. ccallparanode.create(rttippn,
  4892. ccallparanode.create(arrayppn,nil)))))));
  4893. result:=ccallnode.createinternres('fpc_array_to_dynarray_copy',npara,resultdef);
  4894. ppn.left:=nil;
  4895. paras.free;
  4896. end
  4897. else
  4898. result:=ccallnode.createintern('fpc_shortstr_copy',paras);
  4899. { parameters are reused }
  4900. left:=nil;
  4901. end;
  4902. function tinlinenode.first_new: tnode;
  4903. var
  4904. newstatement : tstatementnode;
  4905. newblock : tblocknode;
  4906. temp : ttempcreatenode;
  4907. para : tcallparanode;
  4908. begin
  4909. { create statements with call to getmem+initialize }
  4910. newblock:=internalstatements(newstatement);
  4911. { create temp for result }
  4912. temp := ctempcreatenode.create(left.resultdef,left.resultdef.size,tt_persistent,true);
  4913. addstatement(newstatement,temp);
  4914. { create call to fpc_getmem }
  4915. para := ccallparanode.create(cordconstnode.create
  4916. (tpointerdef(left.resultdef).pointeddef.size,s32inttype,true),nil);
  4917. addstatement(newstatement,cassignmentnode.create(
  4918. ctemprefnode.create(temp),
  4919. ccallnode.createintern('fpc_getmem',para)));
  4920. { create call to fpc_initialize }
  4921. if is_managed_type(tpointerdef(left.resultdef).pointeddef) then
  4922. begin
  4923. para := ccallparanode.create(caddrnode.create_internal(crttinode.create
  4924. (tstoreddef(tpointerdef(left.resultdef).pointeddef),initrtti,rdt_normal)),
  4925. ccallparanode.create(ctemprefnode.create
  4926. (temp),nil));
  4927. addstatement(newstatement,ccallnode.createintern('fpc_initialize',para));
  4928. end;
  4929. { the last statement should return the value as
  4930. location and type, this is done be referencing the
  4931. temp and converting it first from a persistent temp to
  4932. normal temp }
  4933. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  4934. addstatement(newstatement,ctemprefnode.create(temp));
  4935. result:=newblock;
  4936. end;
  4937. function tinlinenode.first_length: tnode;
  4938. begin
  4939. result:=nil;
  4940. if is_shortstring(left.resultdef) then
  4941. expectloc:=left.expectloc
  4942. else
  4943. begin
  4944. { ansi/wide string }
  4945. expectloc:=LOC_REGISTER;
  4946. end;
  4947. end;
  4948. function tinlinenode.first_high: tnode;
  4949. begin
  4950. result:=nil;
  4951. if not(is_dynamic_array(left.resultdef)) then
  4952. Internalerror(2019122802);
  4953. expectloc:=LOC_REGISTER;
  4954. end;
  4955. function tinlinenode.first_assigned: tnode;
  4956. begin
  4957. { Comparison must not call procvars, indicate that with nf_load_procvar flag }
  4958. result:=caddnode.create(unequaln,tcallparanode(left).left,cnilnode.create);
  4959. include(result.flags,nf_load_procvar);
  4960. tcallparanode(left).left:=nil;
  4961. end;
  4962. function tinlinenode.first_assert: tnode;
  4963. var
  4964. paras: tcallparanode;
  4965. begin
  4966. paras:=tcallparanode(tcallparanode(left).right);
  4967. paras:=ccallparanode.create(cstringconstnode.createstr(current_module.sourcefiles.get_file_name(current_filepos.fileindex)),paras);
  4968. paras:=ccallparanode.create(genintconstnode(fileinfo.line),paras);
  4969. {$ifdef SUPPORT_GET_FRAME}
  4970. paras:=ccallparanode.create(geninlinenode(in_get_frame,false,nil),paras);
  4971. {$else}
  4972. paras:=ccallparanode.create(ccallnode.createinternfromunit('SYSTEM','GET_FRAME',nil),paras);
  4973. {$endif}
  4974. result:=cifnode.create(cnotnode.create(tcallparanode(left).left),
  4975. ccallnode.createintern('fpc_assert',paras),nil);
  4976. include(result.flags,nf_internal);
  4977. tcallparanode(left).left:=nil;
  4978. tcallparanode(left).right:=nil;
  4979. end;
  4980. function tinlinenode.first_popcnt: tnode;
  4981. var
  4982. suffix : string;
  4983. begin
  4984. case torddef(left.resultdef).ordtype of
  4985. u8bit: suffix:='byte';
  4986. u16bit: suffix:='word';
  4987. u32bit: suffix:='dword';
  4988. u64bit: suffix:='qword';
  4989. else
  4990. internalerror(2012082601);
  4991. end;
  4992. result:=ccallnode.createintern('fpc_popcnt_'+suffix,ccallparanode.create(left,nil));
  4993. left:=nil;
  4994. end;
  4995. function tinlinenode.first_bitscan: tnode;
  4996. begin
  4997. result:=nil;
  4998. expectloc:=LOC_REGISTER;
  4999. end;
  5000. function tinlinenode.typecheck_seg: tnode;
  5001. begin
  5002. if target_info.system in systems_managed_vm then
  5003. message(parser_e_feature_unsupported_for_vm);
  5004. set_varstate(left,vs_read,[]);
  5005. result:=cordconstnode.create(0,s32inttype,false);
  5006. end;
  5007. function tinlinenode.first_seg: tnode;
  5008. begin
  5009. internalerror(200104046);
  5010. result:=nil;
  5011. end;
  5012. function tinlinenode.first_sar: tnode;
  5013. begin
  5014. result:=nil;
  5015. expectloc:=LOC_REGISTER;
  5016. {$if not defined(cpu64bitalu) and not defined(cpucg64shiftsupport)}
  5017. if is_64bitint(resultdef) then
  5018. begin
  5019. if (inlinenumber=in_sar_x) then
  5020. left:=ccallparanode.create(cordconstnode.create(1,u8inttype,false),
  5021. ccallparanode.create(left,nil));
  5022. result:=ccallnode.createintern('fpc_sarint64',left);
  5023. left:=nil;
  5024. end;
  5025. {$endif not defined(cpu64bitalu) and not defined(cpucg64shiftsupport)}
  5026. end;
  5027. function tinlinenode.handle_box: tnode;
  5028. begin
  5029. result:=nil;
  5030. if not assigned(left) or
  5031. assigned(tcallparanode(left).right) then
  5032. CGMessage1(parser_e_wrong_parameter_size,'FpcInternalBox');
  5033. resultdef:=class_tobject;
  5034. end;
  5035. function tinlinenode.handle_unbox: tnode;
  5036. begin
  5037. result:=nil;
  5038. if not assigned(left) or
  5039. not assigned(tcallparanode(left).right) or
  5040. assigned(tcallparanode(tcallparanode(left).right).right) then
  5041. CGMessage1(parser_e_wrong_parameter_size,'FpcInternalUnBox');
  5042. if tcallparanode(left).left.nodetype<>typen then
  5043. internalerror(2011071701);
  5044. ttypenode(tcallparanode(left).left).allowed:=true;
  5045. resultdef:=tcallparanode(left).left.resultdef;
  5046. end;
  5047. function tinlinenode.handle_insert: tnode;
  5048. procedure do_error;
  5049. begin
  5050. CGMessagePos1(fileinfo,parser_e_wrong_parameter_size,'Insert');
  5051. write_system_parameter_lists('fpc_shortstr_insert');
  5052. write_system_parameter_lists('fpc_shortstr_insert_char');
  5053. write_system_parameter_lists('fpc_unicodestr_insert');
  5054. if tf_winlikewidestring in target_info.flags then
  5055. write_system_parameter_lists('fpc_widestr_insert');
  5056. write_system_parameter_lists('fpc_ansistr_insert');
  5057. MessagePos1(fileinfo,sym_e_param_list,'Insert(Dynamic Array;var Dynamic Array;'+sinttype.typename+');');
  5058. MessagePos1(fileinfo,sym_e_param_list,'Insert(Element;var Dynamic Array;'+sinttype.typename+');');
  5059. end;
  5060. var
  5061. procname : String;
  5062. newn,
  5063. datan,
  5064. datacountn,
  5065. firstn,
  5066. secondn : tnode;
  5067. first,
  5068. second : tdef;
  5069. isconstr,
  5070. iscomparray,
  5071. iscompelem : boolean;
  5072. datatemp : ttempcreatenode;
  5073. insertblock : tblocknode;
  5074. insertstatement : tstatementnode;
  5075. begin
  5076. if not assigned(left) or
  5077. not assigned(tcallparanode(left).right) or
  5078. not assigned(tcallparanode(tcallparanode(left).right).right) or
  5079. assigned(tcallparanode(tcallparanode(tcallparanode(left).right).right).right) then
  5080. begin
  5081. do_error;
  5082. exit(cerrornode.create);
  5083. end;
  5084. { determine the correct function based on the second parameter }
  5085. firstn:=tcallparanode(tcallparanode(tcallparanode(left).right).right).left;
  5086. first:=firstn.resultdef;
  5087. secondn:=tcallparanode(tcallparanode(left).right).left;
  5088. second:=secondn.resultdef;
  5089. if is_shortstring(second) then
  5090. begin
  5091. if is_char(first) then
  5092. procname:='fpc_shortstr_insert_char'
  5093. else
  5094. procname:='fpc_shortstr_insert';
  5095. end
  5096. else if is_unicodestring(second) then
  5097. procname:='fpc_unicodestr_insert'
  5098. else if is_widestring(second) then
  5099. procname:='fpc_widestr_insert'
  5100. else if is_ansistring(second) then
  5101. procname:='fpc_ansistr_insert'
  5102. else if is_dynamic_array(second) then
  5103. begin
  5104. { The first parameter needs to be
  5105. a) a dynamic array of the same type
  5106. b) a single element of the same type
  5107. c) a static array of the same type (not Delphi compatible)
  5108. }
  5109. isconstr:=is_array_constructor(first);
  5110. iscomparray:=(first.typ=arraydef) and equal_defs(tarraydef(first).elementdef,tarraydef(second).elementdef);
  5111. iscompelem:=compare_defs(first,tarraydef(second).elementdef,niln)<>te_incompatible;
  5112. if not iscomparray
  5113. and not iscompelem
  5114. and not isconstr then
  5115. begin
  5116. CGMessagePos(fileinfo,type_e_array_required);
  5117. exit(cerrornode.create);
  5118. end;
  5119. insertblock:=internalstatements(insertstatement);
  5120. datatemp:=nil;
  5121. if iscomparray then
  5122. begin
  5123. datatemp:=ctempcreatenode.create_value(first,first.size,tt_normal,false,firstn);
  5124. addstatement(insertstatement,datatemp);
  5125. if is_dynamic_array(first) then
  5126. datan:=ctypeconvnode.create_internal(ctemprefnode.create(datatemp),voidpointertype)
  5127. else
  5128. datan:=caddrnode.create_internal(cvecnode.create(ctemprefnode.create(datatemp),cordconstnode.create(0,sizesinttype,false)));
  5129. datacountn:=cinlinenode.create(in_length_x,false,ctemprefnode.create(datatemp));
  5130. end
  5131. else if isconstr then
  5132. begin
  5133. inserttypeconv(firstn,second);
  5134. datatemp:=ctempcreatenode.create_value(second,second.size,tt_normal,false,firstn);
  5135. addstatement(insertstatement,datatemp);
  5136. datan:=ctypeconvnode.create_internal(ctemprefnode.create(datatemp),voidpointertype);
  5137. datacountn:=cinlinenode.create(in_length_x,false,ctemprefnode.create(datatemp));
  5138. end
  5139. else
  5140. begin
  5141. if is_const(firstn) then
  5142. begin
  5143. datatemp:=ctempcreatenode.create_value(tarraydef(second).elementdef,tarraydef(second).elementdef.size,tt_normal,false,firstn);
  5144. addstatement(insertstatement,datatemp);
  5145. datan:=caddrnode.create_internal(ctemprefnode.create(datatemp));
  5146. end
  5147. else
  5148. begin
  5149. datan:=firstn;
  5150. inserttypeconv(datan,tarraydef(second).elementdef);
  5151. datan:=caddrnode.create_internal(datan);
  5152. end;
  5153. datacountn:=cordconstnode.create(1,sizesinttype,false);
  5154. end;
  5155. procname:='fpc_dynarray_insert';
  5156. { recreate the parameters as array pointer, source, data, count, typeinfo }
  5157. newn:=ccallparanode.create(caddrnode.create_internal(crttinode.create(tstoreddef(second),initrtti,rdt_normal)),
  5158. ccallparanode.create(datacountn,
  5159. ccallparanode.create(datan,
  5160. ccallparanode.create(tcallparanode(left).left,
  5161. ccallparanode.create(ctypeconvnode.create_internal(secondn,voidpointertype),nil)))));
  5162. addstatement(insertstatement,ccallnode.createintern(procname,newn));
  5163. if assigned(datatemp) then
  5164. addstatement(insertstatement,ctempdeletenode.create(datatemp));
  5165. tcallparanode(tcallparanode(tcallparanode(left).right).right).left:=nil; // insert idx
  5166. tcallparanode(tcallparanode(left).right).left:=nil; // dyn array
  5167. tcallparanode(left).left:=nil; // insert element/array
  5168. left.free;
  5169. left:=nil;
  5170. result:=insertblock;
  5171. exit; { ! }
  5172. end
  5173. else if second.typ=undefineddef then
  5174. { just pick one }
  5175. procname:='fpc_ansistr_insert'
  5176. else
  5177. begin
  5178. do_error;
  5179. exit(cerrornode.create);
  5180. end;
  5181. result:=ccallnode.createintern(procname,left);
  5182. left:=nil;
  5183. end;
  5184. function tinlinenode.handle_delete: tnode;
  5185. procedure do_error;
  5186. begin
  5187. CGMessagePos1(fileinfo,parser_e_wrong_parameter_size,'Delete');
  5188. write_system_parameter_lists('fpc_shortstr_delete');
  5189. write_system_parameter_lists('fpc_unicodestr_delete');
  5190. if tf_winlikewidestring in target_info.flags then
  5191. write_system_parameter_lists('fpc_widestr_delete');
  5192. write_system_parameter_lists('fpc_ansistr_delete');
  5193. MessagePos1(fileinfo,sym_e_param_list,'Delete(var Dynamic Array;'+sinttype.typename+';'+sinttype.typename+');');
  5194. end;
  5195. var
  5196. procname : String;
  5197. first : tdef;
  5198. firstn,
  5199. newn : tnode;
  5200. begin
  5201. if not assigned(left) or
  5202. not assigned(tcallparanode(left).right) or
  5203. not assigned(tcallparanode(tcallparanode(left).right).right) or
  5204. assigned(tcallparanode(tcallparanode(tcallparanode(left).right).right).right) then
  5205. begin
  5206. do_error;
  5207. exit(cerrornode.create);
  5208. end;
  5209. { determine the correct function based on the first parameter }
  5210. firstn:=tcallparanode(tcallparanode(tcallparanode(left).right).right).left;
  5211. first:=firstn.resultdef;
  5212. if is_shortstring(first) then
  5213. procname:='fpc_shortstr_delete'
  5214. else if is_unicodestring(first) then
  5215. procname:='fpc_unicodestr_delete'
  5216. else if is_widestring(first) then
  5217. procname:='fpc_widestr_delete'
  5218. else if is_ansistring(first) then
  5219. procname:='fpc_ansistr_delete'
  5220. else if is_dynamic_array(first) then
  5221. begin
  5222. procname:='fpc_dynarray_delete';
  5223. { recreate the parameters as array pointer, src, count, typeinfo }
  5224. newn:=ccallparanode.create(caddrnode.create_internal
  5225. (crttinode.create(tstoreddef(first),initrtti,rdt_normal)),
  5226. ccallparanode.create(tcallparanode(left).left,
  5227. ccallparanode.create(tcallparanode(tcallparanode(left).right).left,
  5228. ccallparanode.create(ctypeconvnode.create_internal(firstn,voidpointertype),nil))));
  5229. tcallparanode(tcallparanode(tcallparanode(left).right).right).left:=nil;
  5230. tcallparanode(tcallparanode(left).right).left:=nil;
  5231. tcallparanode(left).left:=nil;
  5232. left.free;
  5233. left:=newn;
  5234. end
  5235. else if first.typ=undefineddef then
  5236. { just pick one }
  5237. procname:='fpc_ansistr_delete'
  5238. else
  5239. begin
  5240. do_error;
  5241. exit(cerrornode.create);
  5242. end;
  5243. result:=ccallnode.createintern(procname,left);
  5244. left:=nil;
  5245. end;
  5246. function tinlinenode.handle_concat:tnode;
  5247. procedure do_error;
  5248. begin
  5249. CGMessagePos1(fileinfo,parser_e_wrong_parameter_size,'Concat');
  5250. MessagePos1(fileinfo,sym_e_param_list,'Concat(String[;String;...])');
  5251. MessagePos1(fileinfo,sym_e_param_list,'Concat(Dynamic Array[;Dynamic Array;...])');
  5252. end;
  5253. var
  5254. cpn : tcallparanode;
  5255. list : tfpobjectlist;
  5256. n,
  5257. arrn,
  5258. firstn : tnode;
  5259. i : longint;
  5260. arrconstr : tarrayconstructornode;
  5261. newstatement : tstatementnode;
  5262. tempnode : ttempcreatenode;
  5263. lastchanged : boolean;
  5264. begin
  5265. if not assigned(left) then
  5266. begin
  5267. do_error;
  5268. exit(cerrornode.create);
  5269. end;
  5270. result:=nil;
  5271. { the arguments are right to left, but we need to work on them from
  5272. left to right, so insert them in a list and process that from back
  5273. to front }
  5274. list:=tfpobjectlist.create(false);
  5275. { remember the last (aka first) dynamic array parameter (important
  5276. in case of array constructors) }
  5277. arrn:=nil;
  5278. cpn:=tcallparanode(left);
  5279. while assigned(cpn) do
  5280. begin
  5281. list.add(cpn.left);
  5282. if is_dynamic_array(cpn.left.resultdef) then
  5283. arrn:=cpn.left;
  5284. cpn.left:=nil;
  5285. cpn:=tcallparanode(cpn.right);
  5286. end;
  5287. if list.count=0 then
  5288. internalerror(2017100901);
  5289. firstn:=tnode(list.last);
  5290. if not assigned(firstn) then
  5291. internalerror(2017100902);
  5292. { are we dealing with strings or dynamic arrays? }
  5293. if is_dynamic_array(firstn.resultdef) or is_array_constructor(firstn.resultdef) then
  5294. begin
  5295. { try to combine all consecutive array constructors }
  5296. lastchanged:=false;
  5297. i:=0;
  5298. repeat
  5299. if lastchanged or is_array_constructor(tnode(list[i]).resultdef) then
  5300. begin
  5301. if (i<list.count-1) and is_array_constructor(tnode(list[i+1]).resultdef) then
  5302. begin
  5303. arrconstr:=tarrayconstructornode(list[i+1]);
  5304. while assigned(arrconstr.right) do
  5305. arrconstr:=tarrayconstructornode(arrconstr.right);
  5306. arrconstr.right:=tnode(list[i]);
  5307. list[i]:=list[i+1];
  5308. list.delete(i+1);
  5309. lastchanged:=true;
  5310. tnode(list[i]).resultdef:=nil;
  5311. { don't increase index! }
  5312. continue;
  5313. end;
  5314. if lastchanged then
  5315. begin
  5316. { we concatted all consecutive ones, so typecheck the new one again }
  5317. n:=tnode(list[i]);
  5318. typecheckpass(n);
  5319. list[i]:=n;
  5320. end;
  5321. lastchanged:=false;
  5322. end;
  5323. inc(i);
  5324. until i=list.count;
  5325. if list.count=1 then
  5326. begin
  5327. { no need to call the concat helper }
  5328. result:=firstn;
  5329. end
  5330. else
  5331. begin
  5332. { if we reach this point then the concat list didn't consist
  5333. solely of array constructors }
  5334. if not assigned(arrn) then
  5335. internalerror(2017101001);
  5336. result:=internalstatements(newstatement);
  5337. { generate the open array constructor for the source arrays
  5338. note: the order needs to be swapped again here! }
  5339. arrconstr:=nil;
  5340. for i:=0 to list.count-1 do
  5341. begin
  5342. n:=tnode(list[i]);
  5343. { first convert to the target type }
  5344. if not is_array_constructor(n.resultdef) then
  5345. inserttypeconv(n,arrn.resultdef);
  5346. { we need to ensure that we get a reference counted
  5347. assignement for the temp array }
  5348. tempnode:=ctempcreatenode.create(arrn.resultdef,arrn.resultdef.size,tt_persistent,true);
  5349. addstatement(newstatement,tempnode);
  5350. addstatement(newstatement,cassignmentnode.create(ctemprefnode.create(tempnode),n));
  5351. addstatement(newstatement,ctempdeletenode.create_normal_temp(tempnode));
  5352. n:=ctemprefnode.create(tempnode);
  5353. { then to a plain pointer for the helper }
  5354. inserttypeconv_internal(n,voidpointertype);
  5355. arrconstr:=carrayconstructornode.create(n,arrconstr);
  5356. end;
  5357. Include(arrconstr.arrayconstructornodeflags,acnf_allow_array_constructor);
  5358. { based on the code from nopt.genmultistringadd() }
  5359. tempnode:=ctempcreatenode.create(arrn.resultdef,arrn.resultdef.size,tt_persistent,true);
  5360. addstatement(newstatement,tempnode);
  5361. { initialize the temp, since it will be passed to a
  5362. var-parameter (and finalization, which is performed by the
  5363. ttempcreate node and which takes care of the initialization
  5364. on native targets, is a noop on managed VM targets) }
  5365. if (target_info.system in systems_managed_vm) and
  5366. is_managed_type(arrn.resultdef) then
  5367. addstatement(newstatement,cinlinenode.create(in_setlength_x,
  5368. false,
  5369. ccallparanode.create(genintconstnode(0),
  5370. ccallparanode.create(ctemprefnode.create(tempnode),nil))));
  5371. cpn:=ccallparanode.create(
  5372. arrconstr,
  5373. ccallparanode.create(
  5374. caddrnode.create_internal(crttinode.create(tstoreddef(arrn.resultdef),initrtti,rdt_normal)),
  5375. ccallparanode.create(ctypeconvnode.create_internal(ctemprefnode.create(tempnode),voidpointertype),nil))
  5376. );
  5377. addstatement(
  5378. newstatement,
  5379. ccallnode.createintern(
  5380. 'fpc_dynarray_concat_multi',
  5381. cpn
  5382. )
  5383. );
  5384. addstatement(newstatement,ctempdeletenode.create_normal_temp(tempnode));
  5385. addstatement(newstatement,ctemprefnode.create(tempnode));
  5386. end;
  5387. end
  5388. else
  5389. begin
  5390. { enforce strings }
  5391. for i:=list.count-1 downto 0 do
  5392. begin
  5393. if assigned(result) then
  5394. result:=caddnode.create(addn,result,tnode(list[i]))
  5395. else
  5396. begin
  5397. result:=tnode(list[i]);
  5398. { Force string type if it isn't yet }
  5399. if not(
  5400. (result.resultdef.typ=stringdef) or
  5401. is_chararray(result.resultdef) or
  5402. is_char(result.resultdef)
  5403. ) then
  5404. inserttypeconv(result,cshortstringtype);
  5405. end;
  5406. end;
  5407. end;
  5408. list.free;
  5409. end;
  5410. function tinlinenode.first_pack_unpack: tnode;
  5411. var
  5412. loopstatement : tstatementnode;
  5413. loop : tblocknode;
  5414. loopvar : ttempcreatenode;
  5415. tempnode,
  5416. source,
  5417. target,
  5418. index,
  5419. unpackednode,
  5420. packednode,
  5421. sourcevecindex,
  5422. targetvecindex,
  5423. loopbody : tnode;
  5424. temprangedef : tdef;
  5425. ulorange,
  5426. uhirange,
  5427. plorange,
  5428. phirange : TConstExprInt;
  5429. begin
  5430. { transform into a for loop which assigns the data of the (un)packed }
  5431. { array to the other one }
  5432. source := left;
  5433. if (inlinenumber = in_unpack_x_y_z) then
  5434. begin
  5435. target := tcallparanode(source).right;
  5436. index := tcallparanode(target).right;
  5437. packednode := tcallparanode(source).left;
  5438. unpackednode := tcallparanode(target).left;
  5439. end
  5440. else
  5441. begin
  5442. index := tcallparanode(source).right;
  5443. target := tcallparanode(index).right;
  5444. packednode := tcallparanode(target).left;
  5445. unpackednode := tcallparanode(source).left;
  5446. end;
  5447. source := tcallparanode(source).left;
  5448. target := tcallparanode(target).left;
  5449. index := tcallparanode(index).left;
  5450. loop := internalstatements(loopstatement);
  5451. loopvar := ctempcreatenode.create(
  5452. tarraydef(packednode.resultdef).rangedef,
  5453. tarraydef(packednode.resultdef).rangedef.size,
  5454. tt_persistent,true);
  5455. addstatement(loopstatement,loopvar);
  5456. { For range checking: we have to convert to an integer type (in case the index type }
  5457. { is an enum), add the index and loop variable together, convert the result }
  5458. { implicitly to an orddef with range equal to the rangedef to get range checking }
  5459. { and finally convert it explicitly back to the actual rangedef to avoid type }
  5460. { errors }
  5461. temprangedef:=nil;
  5462. getrange(unpackednode.resultdef,ulorange,uhirange);
  5463. getrange(packednode.resultdef,plorange,phirange);
  5464. { does not really need to be registered, but then we would have to
  5465. record it elsewhere so it still can be freed }
  5466. temprangedef:=corddef.create(torddef(sinttype).ordtype,ulorange,uhirange,true);
  5467. sourcevecindex := ctemprefnode.create(loopvar);
  5468. targetvecindex := ctypeconvnode.create_internal(index.getcopy,sinttype);
  5469. targetvecindex := caddnode.create(subn,targetvecindex,cordconstnode.create(plorange,sinttype,true));
  5470. targetvecindex := caddnode.create(addn,targetvecindex,ctemprefnode.create(loopvar));
  5471. targetvecindex := ctypeconvnode.create(targetvecindex,temprangedef);
  5472. targetvecindex := ctypeconvnode.create_explicit(targetvecindex,tarraydef(unpackednode.resultdef).rangedef);
  5473. if (inlinenumber = in_pack_x_y_z) then
  5474. begin
  5475. { swap source and target vec indices }
  5476. tempnode := sourcevecindex;
  5477. sourcevecindex := targetvecindex;
  5478. targetvecindex := tempnode;
  5479. end;
  5480. { create the assignment in the loop body }
  5481. loopbody :=
  5482. cassignmentnode.create(
  5483. cvecnode.create(target.getcopy,targetvecindex),
  5484. cvecnode.create(source.getcopy,sourcevecindex)
  5485. );
  5486. { create the actual for loop }
  5487. tempnode := cfornode.create(
  5488. ctemprefnode.create(loopvar),
  5489. cinlinenode.create(in_low_x,false,packednode.getcopy),
  5490. cinlinenode.create(in_high_x,false,packednode.getcopy),
  5491. loopbody,
  5492. false);
  5493. addstatement(loopstatement,tempnode);
  5494. { free the loop counter }
  5495. addstatement(loopstatement,ctempdeletenode.create(loopvar));
  5496. result := loop;
  5497. end;
  5498. function tinlinenode.may_have_sideeffect_norecurse: boolean;
  5499. begin
  5500. result:=
  5501. (inlinenumber in [in_write_x,in_writeln_x,in_read_x,in_readln_x,in_str_x_string,
  5502. in_val_x,in_reset_x,in_rewrite_x,in_reset_typedfile,in_rewrite_typedfile,
  5503. in_reset_typedfile_name,in_rewrite_typedfile_name,in_settextbuf_file_x,
  5504. in_inc_x,in_dec_x,in_include_x_y,in_exclude_x_y,in_break,in_continue,in_setlength_x,
  5505. in_finalize_x,in_new_x,in_dispose_x,in_exit,in_copy_x,in_initialize_x,in_leave,in_cycle,
  5506. in_and_assign_x_y,in_or_assign_x_y,in_xor_assign_x_y,in_sar_assign_x_y,in_shl_assign_x_y,
  5507. in_shr_assign_x_y,in_rol_assign_x_y,in_ror_assign_x_y,in_neg_assign_x,in_not_assign_x]) or
  5508. ((inlinenumber = in_assert_x_y) and
  5509. (cs_do_assertion in localswitches));
  5510. end;
  5511. function tinlinenode.first_fma: tnode;
  5512. begin
  5513. CGMessage1(cg_e_function_not_support_by_selected_instruction_set,'FMA');
  5514. result:=nil;
  5515. end;
  5516. function tinlinenode.first_minmax: tnode;
  5517. begin
  5518. CGMessage1(cg_e_function_not_support_by_selected_instruction_set,'MIN/MAX');
  5519. result:=nil;
  5520. end;
  5521. //
  5522. //||||||| .merge-left.r31134
  5523. //
  5524. //{$ifdef ARM}
  5525. // {$i armtype.inc}
  5526. //{$endif ARM}
  5527. //=======
  5528. //
  5529. //{$ifdef x86}
  5530. // {$i x86type.inc}
  5531. //{$endif x86}
  5532. //{$ifdef ARM}
  5533. // {$i armtype.inc}
  5534. //{$endif ARM}
  5535. {$if not defined(cpu64bitalu) and not defined(cpuhighleveltarget)}
  5536. function tinlinenode.first_ShiftRot_assign_64bitint: tnode;
  5537. var
  5538. procname: string[31];
  5539. begin
  5540. {$ifdef cpucg64shiftsupport}
  5541. if inlinenumber in [in_sar_assign_x_y,in_shl_assign_x_y,in_shr_assign_x_y] then
  5542. begin
  5543. result:=nil;
  5544. expectloc:=tcallparanode(tcallparanode(left).right).left.expectloc;
  5545. exit;
  5546. end;
  5547. {$endif cpucg64shiftsupport}
  5548. result := nil;
  5549. if is_signed(tcallparanode(left).right.resultdef) then
  5550. procname:='int64'
  5551. else
  5552. procname:='qword';
  5553. case inlinenumber of
  5554. in_sar_assign_x_y:
  5555. procname := 'fpc_sar_assign_'+procname;
  5556. in_shl_assign_x_y:
  5557. procname := 'fpc_shl_assign_'+procname;
  5558. in_shr_assign_x_y:
  5559. procname := 'fpc_shr_assign_'+procname;
  5560. in_rol_assign_x_y:
  5561. procname := 'fpc_rol_assign_'+procname;
  5562. in_ror_assign_x_y:
  5563. procname := 'fpc_ror_assign_'+procname;
  5564. else
  5565. internalerror(2017041301);
  5566. end;
  5567. result := ccallnode.createintern(procname,ccallparanode.create(tcallparanode(left).left,
  5568. ccallparanode.create(tcallparanode(tcallparanode(left).right).left,nil)));
  5569. tcallparanode(tcallparanode(left).right).left := nil;
  5570. tcallparanode(left).left := nil;
  5571. firstpass(result);
  5572. end;
  5573. {$endif not cpu64bitalu and nto cpuhighleveltarget}
  5574. function tinlinenode.first_AndOrXorShiftRot_assign: tnode;
  5575. begin
  5576. {$if not defined(cpu64bitalu) and not defined(cpuhighleveltarget)}
  5577. { 64 bit ints have their own shift handling }
  5578. if is_64bit(tcallparanode(left).right.resultdef) and
  5579. (inlinenumber in [in_sar_assign_x_y,in_shl_assign_x_y,in_shr_assign_x_y,in_rol_assign_x_y,in_ror_assign_x_y]) then
  5580. result := first_ShiftRot_assign_64bitint
  5581. else
  5582. {$endif not cpu64bitalu and not cpuhighleveltarget}
  5583. begin
  5584. result:=nil;
  5585. expectloc:=tcallparanode(tcallparanode(left).right).left.expectloc;
  5586. end;
  5587. end;
  5588. function tinlinenode.first_NegNot_assign: tnode;
  5589. begin
  5590. result:=nil;
  5591. expectloc:=left.expectloc;
  5592. end;
  5593. function tinlinenode.first_cpu : tnode;
  5594. begin
  5595. Result:=nil;
  5596. internalerror(2017110101);
  5597. end;
  5598. procedure tinlinenode.CheckParameters(count: integer);
  5599. var
  5600. p: tnode;
  5601. begin
  5602. if count=1 then
  5603. begin
  5604. // Sometimes there are more callparanodes
  5605. if left is tcallparanode then
  5606. set_varstate(tcallparanode(left).left,vs_read,[vsf_must_be_valid])
  5607. else
  5608. set_varstate(left,vs_read,[vsf_must_be_valid])
  5609. end
  5610. else
  5611. begin
  5612. p:=left;
  5613. while count>0 do
  5614. begin
  5615. set_varstate(tcallparanode(p).left,vs_read,[vsf_must_be_valid]);
  5616. p:=tcallparanode(p).right;
  5617. dec(count);
  5618. end;
  5619. end;
  5620. end;
  5621. end.