12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260 |
- /* Check functions
- Copyright (C) 2002-2015 Free Software Foundation, Inc.
- Contributed by Andy Vaught & Katherine Holcomb
- This file is part of GCC.
- GCC is free software; you can redistribute it and/or modify it under
- the terms of the GNU General Public License as published by the Free
- Software Foundation; either version 3, or (at your option) any later
- version.
- GCC is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- for more details.
- You should have received a copy of the GNU General Public License
- along with GCC; see the file COPYING3. If not see
- <http://www.gnu.org/licenses/>. */
- /* These functions check to see if an argument list is compatible with
- a particular intrinsic function or subroutine. Presence of
- required arguments has already been established, the argument list
- has been sorted into the right order and has NULL arguments in the
- correct places for missing optional arguments. */
- #include "config.h"
- #include "system.h"
- #include "coretypes.h"
- #include "flags.h"
- #include "gfortran.h"
- #include "intrinsic.h"
- #include "constructor.h"
- #include "target-memory.h"
- /* Make sure an expression is a scalar. */
- static bool
- scalar_check (gfc_expr *e, int n)
- {
- if (e->rank == 0)
- return true;
- gfc_error ("%qs argument of %qs intrinsic at %L must be a scalar",
- gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
- &e->where);
- return false;
- }
- /* Check the type of an expression. */
- static bool
- type_check (gfc_expr *e, int n, bt type)
- {
- if (e->ts.type == type)
- return true;
- gfc_error ("%qs argument of %qs intrinsic at %L must be %s",
- gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
- &e->where, gfc_basic_typename (type));
- return false;
- }
- /* Check that the expression is a numeric type. */
- static bool
- numeric_check (gfc_expr *e, int n)
- {
- if (gfc_numeric_ts (&e->ts))
- return true;
- /* If the expression has not got a type, check if its namespace can
- offer a default type. */
- if ((e->expr_type == EXPR_VARIABLE || e->expr_type == EXPR_FUNCTION)
- && e->symtree->n.sym->ts.type == BT_UNKNOWN
- && gfc_set_default_type (e->symtree->n.sym, 0, e->symtree->n.sym->ns)
- && gfc_numeric_ts (&e->symtree->n.sym->ts))
- {
- e->ts = e->symtree->n.sym->ts;
- return true;
- }
- gfc_error ("%qs argument of %qs intrinsic at %L must be a numeric type",
- gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
- &e->where);
- return false;
- }
- /* Check that an expression is integer or real. */
- static bool
- int_or_real_check (gfc_expr *e, int n)
- {
- if (e->ts.type != BT_INTEGER && e->ts.type != BT_REAL)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER "
- "or REAL", gfc_current_intrinsic_arg[n]->name,
- gfc_current_intrinsic, &e->where);
- return false;
- }
- return true;
- }
- /* Check that an expression is real or complex. */
- static bool
- real_or_complex_check (gfc_expr *e, int n)
- {
- if (e->ts.type != BT_REAL && e->ts.type != BT_COMPLEX)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L must be REAL "
- "or COMPLEX", gfc_current_intrinsic_arg[n]->name,
- gfc_current_intrinsic, &e->where);
- return false;
- }
- return true;
- }
- /* Check that an expression is INTEGER or PROCEDURE. */
- static bool
- int_or_proc_check (gfc_expr *e, int n)
- {
- if (e->ts.type != BT_INTEGER && e->ts.type != BT_PROCEDURE)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER "
- "or PROCEDURE", gfc_current_intrinsic_arg[n]->name,
- gfc_current_intrinsic, &e->where);
- return false;
- }
- return true;
- }
- /* Check that the expression is an optional constant integer
- and that it specifies a valid kind for that type. */
- static bool
- kind_check (gfc_expr *k, int n, bt type)
- {
- int kind;
- if (k == NULL)
- return true;
- if (!type_check (k, n, BT_INTEGER))
- return false;
- if (!scalar_check (k, n))
- return false;
- if (!gfc_check_init_expr (k))
- {
- gfc_error ("%qs argument of %qs intrinsic at %L must be a constant",
- gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
- &k->where);
- return false;
- }
- if (gfc_extract_int (k, &kind) != NULL
- || gfc_validate_kind (type, kind, true) < 0)
- {
- gfc_error ("Invalid kind for %s at %L", gfc_basic_typename (type),
- &k->where);
- return false;
- }
- return true;
- }
- /* Make sure the expression is a double precision real. */
- static bool
- double_check (gfc_expr *d, int n)
- {
- if (!type_check (d, n, BT_REAL))
- return false;
- if (d->ts.kind != gfc_default_double_kind)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L must be double "
- "precision", gfc_current_intrinsic_arg[n]->name,
- gfc_current_intrinsic, &d->where);
- return false;
- }
- return true;
- }
- static bool
- coarray_check (gfc_expr *e, int n)
- {
- if (e->ts.type == BT_CLASS && gfc_expr_attr (e).class_ok
- && CLASS_DATA (e)->attr.codimension
- && CLASS_DATA (e)->as->corank)
- {
- gfc_add_class_array_ref (e);
- return true;
- }
- if (!gfc_is_coarray (e))
- {
- gfc_error ("Expected coarray variable as %qs argument to the %s "
- "intrinsic at %L", gfc_current_intrinsic_arg[n]->name,
- gfc_current_intrinsic, &e->where);
- return false;
- }
- return true;
- }
- /* Make sure the expression is a logical array. */
- static bool
- logical_array_check (gfc_expr *array, int n)
- {
- if (array->ts.type != BT_LOGICAL || array->rank == 0)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L must be a logical "
- "array", gfc_current_intrinsic_arg[n]->name,
- gfc_current_intrinsic, &array->where);
- return false;
- }
- return true;
- }
- /* Make sure an expression is an array. */
- static bool
- array_check (gfc_expr *e, int n)
- {
- if (e->ts.type == BT_CLASS && gfc_expr_attr (e).class_ok
- && CLASS_DATA (e)->attr.dimension
- && CLASS_DATA (e)->as->rank)
- {
- gfc_add_class_array_ref (e);
- return true;
- }
- if (e->rank != 0 && e->ts.type != BT_PROCEDURE)
- return true;
- gfc_error ("%qs argument of %qs intrinsic at %L must be an array",
- gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
- &e->where);
- return false;
- }
- /* If expr is a constant, then check to ensure that it is greater than
- of equal to zero. */
- static bool
- nonnegative_check (const char *arg, gfc_expr *expr)
- {
- int i;
- if (expr->expr_type == EXPR_CONSTANT)
- {
- gfc_extract_int (expr, &i);
- if (i < 0)
- {
- gfc_error ("%qs at %L must be nonnegative", arg, &expr->where);
- return false;
- }
- }
- return true;
- }
- /* If expr2 is constant, then check that the value is less than
- (less than or equal to, if 'or_equal' is true) bit_size(expr1). */
- static bool
- less_than_bitsize1 (const char *arg1, gfc_expr *expr1, const char *arg2,
- gfc_expr *expr2, bool or_equal)
- {
- int i2, i3;
- if (expr2->expr_type == EXPR_CONSTANT)
- {
- gfc_extract_int (expr2, &i2);
- i3 = gfc_validate_kind (BT_INTEGER, expr1->ts.kind, false);
- /* For ISHFT[C], check that |shift| <= bit_size(i). */
- if (arg2 == NULL)
- {
- if (i2 < 0)
- i2 = -i2;
- if (i2 > gfc_integer_kinds[i3].bit_size)
- {
- gfc_error ("The absolute value of SHIFT at %L must be less "
- "than or equal to BIT_SIZE(%qs)",
- &expr2->where, arg1);
- return false;
- }
- }
- if (or_equal)
- {
- if (i2 > gfc_integer_kinds[i3].bit_size)
- {
- gfc_error ("%qs at %L must be less than "
- "or equal to BIT_SIZE(%qs)",
- arg2, &expr2->where, arg1);
- return false;
- }
- }
- else
- {
- if (i2 >= gfc_integer_kinds[i3].bit_size)
- {
- gfc_error ("%qs at %L must be less than BIT_SIZE(%qs)",
- arg2, &expr2->where, arg1);
- return false;
- }
- }
- }
- return true;
- }
- /* If expr is constant, then check that the value is less than or equal
- to the bit_size of the kind k. */
- static bool
- less_than_bitsizekind (const char *arg, gfc_expr *expr, int k)
- {
- int i, val;
- if (expr->expr_type != EXPR_CONSTANT)
- return true;
- i = gfc_validate_kind (BT_INTEGER, k, false);
- gfc_extract_int (expr, &val);
- if (val > gfc_integer_kinds[i].bit_size)
- {
- gfc_error ("%qs at %L must be less than or equal to the BIT_SIZE of "
- "INTEGER(KIND=%d)", arg, &expr->where, k);
- return false;
- }
- return true;
- }
- /* If expr2 and expr3 are constants, then check that the value is less than
- or equal to bit_size(expr1). */
- static bool
- less_than_bitsize2 (const char *arg1, gfc_expr *expr1, const char *arg2,
- gfc_expr *expr2, const char *arg3, gfc_expr *expr3)
- {
- int i2, i3;
- if (expr2->expr_type == EXPR_CONSTANT && expr3->expr_type == EXPR_CONSTANT)
- {
- gfc_extract_int (expr2, &i2);
- gfc_extract_int (expr3, &i3);
- i2 += i3;
- i3 = gfc_validate_kind (BT_INTEGER, expr1->ts.kind, false);
- if (i2 > gfc_integer_kinds[i3].bit_size)
- {
- gfc_error ("%<%s + %s%> at %L must be less than or equal "
- "to BIT_SIZE(%qs)",
- arg2, arg3, &expr2->where, arg1);
- return false;
- }
- }
- return true;
- }
- /* Make sure two expressions have the same type. */
- static bool
- same_type_check (gfc_expr *e, int n, gfc_expr *f, int m)
- {
- if (gfc_compare_types (&e->ts, &f->ts))
- return true;
- gfc_error ("%qs argument of %qs intrinsic at %L must be the same type "
- "and kind as %qs", gfc_current_intrinsic_arg[m]->name,
- gfc_current_intrinsic, &f->where,
- gfc_current_intrinsic_arg[n]->name);
- return false;
- }
- /* Make sure that an expression has a certain (nonzero) rank. */
- static bool
- rank_check (gfc_expr *e, int n, int rank)
- {
- if (e->rank == rank)
- return true;
- gfc_error ("%qs argument of %qs intrinsic at %L must be of rank %d",
- gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
- &e->where, rank);
- return false;
- }
- /* Make sure a variable expression is not an optional dummy argument. */
- static bool
- nonoptional_check (gfc_expr *e, int n)
- {
- if (e->expr_type == EXPR_VARIABLE && e->symtree->n.sym->attr.optional)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L must not be OPTIONAL",
- gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
- &e->where);
- }
- /* TODO: Recursive check on nonoptional variables? */
- return true;
- }
- /* Check for ALLOCATABLE attribute. */
- static bool
- allocatable_check (gfc_expr *e, int n)
- {
- symbol_attribute attr;
- attr = gfc_variable_attr (e, NULL);
- if (!attr.allocatable || attr.associate_var)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L must be ALLOCATABLE",
- gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
- &e->where);
- return false;
- }
- return true;
- }
- /* Check that an expression has a particular kind. */
- static bool
- kind_value_check (gfc_expr *e, int n, int k)
- {
- if (e->ts.kind == k)
- return true;
- gfc_error ("%qs argument of %qs intrinsic at %L must be of kind %d",
- gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
- &e->where, k);
- return false;
- }
- /* Make sure an expression is a variable. */
- static bool
- variable_check (gfc_expr *e, int n, bool allow_proc)
- {
- if (e->expr_type == EXPR_VARIABLE
- && e->symtree->n.sym->attr.intent == INTENT_IN
- && (gfc_current_intrinsic_arg[n]->intent == INTENT_OUT
- || gfc_current_intrinsic_arg[n]->intent == INTENT_INOUT))
- {
- gfc_ref *ref;
- bool pointer = e->symtree->n.sym->ts.type == BT_CLASS
- && CLASS_DATA (e->symtree->n.sym)
- ? CLASS_DATA (e->symtree->n.sym)->attr.class_pointer
- : e->symtree->n.sym->attr.pointer;
- for (ref = e->ref; ref; ref = ref->next)
- {
- if (pointer && ref->type == REF_COMPONENT)
- break;
- if (ref->type == REF_COMPONENT
- && ((ref->u.c.component->ts.type == BT_CLASS
- && CLASS_DATA (ref->u.c.component)->attr.class_pointer)
- || (ref->u.c.component->ts.type != BT_CLASS
- && ref->u.c.component->attr.pointer)))
- break;
- }
- if (!ref)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L cannot be "
- "INTENT(IN)", gfc_current_intrinsic_arg[n]->name,
- gfc_current_intrinsic, &e->where);
- return false;
- }
- }
- if (e->expr_type == EXPR_VARIABLE
- && e->symtree->n.sym->attr.flavor != FL_PARAMETER
- && (allow_proc || !e->symtree->n.sym->attr.function))
- return true;
- if (e->expr_type == EXPR_VARIABLE && e->symtree->n.sym->attr.function
- && e->symtree->n.sym == e->symtree->n.sym->result)
- {
- gfc_namespace *ns;
- for (ns = gfc_current_ns; ns; ns = ns->parent)
- if (ns->proc_name == e->symtree->n.sym)
- return true;
- }
- gfc_error ("%qs argument of %qs intrinsic at %L must be a variable",
- gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic, &e->where);
- return false;
- }
- /* Check the common DIM parameter for correctness. */
- static bool
- dim_check (gfc_expr *dim, int n, bool optional)
- {
- if (dim == NULL)
- return true;
- if (!type_check (dim, n, BT_INTEGER))
- return false;
- if (!scalar_check (dim, n))
- return false;
- if (!optional && !nonoptional_check (dim, n))
- return false;
- return true;
- }
- /* If a coarray DIM parameter is a constant, make sure that it is greater than
- zero and less than or equal to the corank of the given array. */
- static bool
- dim_corank_check (gfc_expr *dim, gfc_expr *array)
- {
- int corank;
- gcc_assert (array->expr_type == EXPR_VARIABLE);
- if (dim->expr_type != EXPR_CONSTANT)
- return true;
- if (array->ts.type == BT_CLASS)
- return true;
- corank = gfc_get_corank (array);
- if (mpz_cmp_ui (dim->value.integer, 1) < 0
- || mpz_cmp_ui (dim->value.integer, corank) > 0)
- {
- gfc_error ("%<dim%> argument of %qs intrinsic at %L is not a valid "
- "codimension index", gfc_current_intrinsic, &dim->where);
- return false;
- }
- return true;
- }
- /* If a DIM parameter is a constant, make sure that it is greater than
- zero and less than or equal to the rank of the given array. If
- allow_assumed is zero then dim must be less than the rank of the array
- for assumed size arrays. */
- static bool
- dim_rank_check (gfc_expr *dim, gfc_expr *array, int allow_assumed)
- {
- gfc_array_ref *ar;
- int rank;
- if (dim == NULL)
- return true;
- if (dim->expr_type != EXPR_CONSTANT)
- return true;
- if (array->expr_type == EXPR_FUNCTION && array->value.function.isym
- && array->value.function.isym->id == GFC_ISYM_SPREAD)
- rank = array->rank + 1;
- else
- rank = array->rank;
- /* Assumed-rank array. */
- if (rank == -1)
- rank = GFC_MAX_DIMENSIONS;
- if (array->expr_type == EXPR_VARIABLE)
- {
- ar = gfc_find_array_ref (array);
- if (ar->as->type == AS_ASSUMED_SIZE
- && !allow_assumed
- && ar->type != AR_ELEMENT
- && ar->type != AR_SECTION)
- rank--;
- }
- if (mpz_cmp_ui (dim->value.integer, 1) < 0
- || mpz_cmp_ui (dim->value.integer, rank) > 0)
- {
- gfc_error ("%<dim%> argument of %qs intrinsic at %L is not a valid "
- "dimension index", gfc_current_intrinsic, &dim->where);
- return false;
- }
- return true;
- }
- /* Compare the size of a along dimension ai with the size of b along
- dimension bi, returning 0 if they are known not to be identical,
- and 1 if they are identical, or if this cannot be determined. */
- static int
- identical_dimen_shape (gfc_expr *a, int ai, gfc_expr *b, int bi)
- {
- mpz_t a_size, b_size;
- int ret;
- gcc_assert (a->rank > ai);
- gcc_assert (b->rank > bi);
- ret = 1;
- if (gfc_array_dimen_size (a, ai, &a_size))
- {
- if (gfc_array_dimen_size (b, bi, &b_size))
- {
- if (mpz_cmp (a_size, b_size) != 0)
- ret = 0;
- mpz_clear (b_size);
- }
- mpz_clear (a_size);
- }
- return ret;
- }
- /* Calculate the length of a character variable, including substrings.
- Strip away parentheses if necessary. Return -1 if no length could
- be determined. */
- static long
- gfc_var_strlen (const gfc_expr *a)
- {
- gfc_ref *ra;
- while (a->expr_type == EXPR_OP && a->value.op.op == INTRINSIC_PARENTHESES)
- a = a->value.op.op1;
- for (ra = a->ref; ra != NULL && ra->type != REF_SUBSTRING; ra = ra->next)
- ;
- if (ra)
- {
- long start_a, end_a;
- if (!ra->u.ss.end)
- return -1;
- if ((!ra->u.ss.start || ra->u.ss.start->expr_type == EXPR_CONSTANT)
- && ra->u.ss.end->expr_type == EXPR_CONSTANT)
- {
- start_a = ra->u.ss.start ? mpz_get_si (ra->u.ss.start->value.integer)
- : 1;
- end_a = mpz_get_si (ra->u.ss.end->value.integer);
- return (end_a < start_a) ? 0 : end_a - start_a + 1;
- }
- else if (ra->u.ss.start
- && gfc_dep_compare_expr (ra->u.ss.start, ra->u.ss.end) == 0)
- return 1;
- else
- return -1;
- }
- if (a->ts.u.cl && a->ts.u.cl->length
- && a->ts.u.cl->length->expr_type == EXPR_CONSTANT)
- return mpz_get_si (a->ts.u.cl->length->value.integer);
- else if (a->expr_type == EXPR_CONSTANT
- && (a->ts.u.cl == NULL || a->ts.u.cl->length == NULL))
- return a->value.character.length;
- else
- return -1;
- }
- /* Check whether two character expressions have the same length;
- returns true if they have or if the length cannot be determined,
- otherwise return false and raise a gfc_error. */
- bool
- gfc_check_same_strlen (const gfc_expr *a, const gfc_expr *b, const char *name)
- {
- long len_a, len_b;
- len_a = gfc_var_strlen(a);
- len_b = gfc_var_strlen(b);
- if (len_a == -1 || len_b == -1 || len_a == len_b)
- return true;
- else
- {
- gfc_error ("Unequal character lengths (%ld/%ld) in %s at %L",
- len_a, len_b, name, &a->where);
- return false;
- }
- }
- /***** Check functions *****/
- /* Check subroutine suitable for intrinsics taking a real argument and
- a kind argument for the result. */
- static bool
- check_a_kind (gfc_expr *a, gfc_expr *kind, bt type)
- {
- if (!type_check (a, 0, BT_REAL))
- return false;
- if (!kind_check (kind, 1, type))
- return false;
- return true;
- }
- /* Check subroutine suitable for ceiling, floor and nint. */
- bool
- gfc_check_a_ikind (gfc_expr *a, gfc_expr *kind)
- {
- return check_a_kind (a, kind, BT_INTEGER);
- }
- /* Check subroutine suitable for aint, anint. */
- bool
- gfc_check_a_xkind (gfc_expr *a, gfc_expr *kind)
- {
- return check_a_kind (a, kind, BT_REAL);
- }
- bool
- gfc_check_abs (gfc_expr *a)
- {
- if (!numeric_check (a, 0))
- return false;
- return true;
- }
- bool
- gfc_check_achar (gfc_expr *a, gfc_expr *kind)
- {
- if (!type_check (a, 0, BT_INTEGER))
- return false;
- if (!kind_check (kind, 1, BT_CHARACTER))
- return false;
- return true;
- }
- bool
- gfc_check_access_func (gfc_expr *name, gfc_expr *mode)
- {
- if (!type_check (name, 0, BT_CHARACTER)
- || !scalar_check (name, 0))
- return false;
- if (!kind_value_check (name, 0, gfc_default_character_kind))
- return false;
- if (!type_check (mode, 1, BT_CHARACTER)
- || !scalar_check (mode, 1))
- return false;
- if (!kind_value_check (mode, 1, gfc_default_character_kind))
- return false;
- return true;
- }
- bool
- gfc_check_all_any (gfc_expr *mask, gfc_expr *dim)
- {
- if (!logical_array_check (mask, 0))
- return false;
- if (!dim_check (dim, 1, false))
- return false;
- if (!dim_rank_check (dim, mask, 0))
- return false;
- return true;
- }
- bool
- gfc_check_allocated (gfc_expr *array)
- {
- if (!variable_check (array, 0, false))
- return false;
- if (!allocatable_check (array, 0))
- return false;
- return true;
- }
- /* Common check function where the first argument must be real or
- integer and the second argument must be the same as the first. */
- bool
- gfc_check_a_p (gfc_expr *a, gfc_expr *p)
- {
- if (!int_or_real_check (a, 0))
- return false;
- if (a->ts.type != p->ts.type)
- {
- gfc_error ("%qs and %qs arguments of %qs intrinsic at %L must "
- "have the same type", gfc_current_intrinsic_arg[0]->name,
- gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
- &p->where);
- return false;
- }
- if (a->ts.kind != p->ts.kind)
- {
- if (!gfc_notify_std (GFC_STD_GNU, "Different type kinds at %L",
- &p->where))
- return false;
- }
- return true;
- }
- bool
- gfc_check_x_yd (gfc_expr *x, gfc_expr *y)
- {
- if (!double_check (x, 0) || !double_check (y, 1))
- return false;
- return true;
- }
- bool
- gfc_check_associated (gfc_expr *pointer, gfc_expr *target)
- {
- symbol_attribute attr1, attr2;
- int i;
- bool t;
- locus *where;
- where = &pointer->where;
- if (pointer->expr_type == EXPR_NULL)
- goto null_arg;
- attr1 = gfc_expr_attr (pointer);
- if (!attr1.pointer && !attr1.proc_pointer)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L must be a POINTER",
- gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
- &pointer->where);
- return false;
- }
- /* F2008, C1242. */
- if (attr1.pointer && gfc_is_coindexed (pointer))
- {
- gfc_error ("%qs argument of %qs intrinsic at %L shall not be "
- "coindexed", gfc_current_intrinsic_arg[0]->name,
- gfc_current_intrinsic, &pointer->where);
- return false;
- }
- /* Target argument is optional. */
- if (target == NULL)
- return true;
- where = &target->where;
- if (target->expr_type == EXPR_NULL)
- goto null_arg;
- if (target->expr_type == EXPR_VARIABLE || target->expr_type == EXPR_FUNCTION)
- attr2 = gfc_expr_attr (target);
- else
- {
- gfc_error ("%qs argument of %qs intrinsic at %L must be a pointer "
- "or target VARIABLE or FUNCTION",
- gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
- &target->where);
- return false;
- }
- if (attr1.pointer && !attr2.pointer && !attr2.target)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L must be a POINTER "
- "or a TARGET", gfc_current_intrinsic_arg[1]->name,
- gfc_current_intrinsic, &target->where);
- return false;
- }
- /* F2008, C1242. */
- if (attr1.pointer && gfc_is_coindexed (target))
- {
- gfc_error ("%qs argument of %qs intrinsic at %L shall not be "
- "coindexed", gfc_current_intrinsic_arg[1]->name,
- gfc_current_intrinsic, &target->where);
- return false;
- }
- t = true;
- if (!same_type_check (pointer, 0, target, 1))
- t = false;
- if (!rank_check (target, 0, pointer->rank))
- t = false;
- if (target->rank > 0)
- {
- for (i = 0; i < target->rank; i++)
- if (target->ref->u.ar.dimen_type[i] == DIMEN_VECTOR)
- {
- gfc_error ("Array section with a vector subscript at %L shall not "
- "be the target of a pointer",
- &target->where);
- t = false;
- break;
- }
- }
- return t;
- null_arg:
- gfc_error ("NULL pointer at %L is not permitted as actual argument "
- "of %qs intrinsic function", where, gfc_current_intrinsic);
- return false;
- }
- bool
- gfc_check_atan_2 (gfc_expr *y, gfc_expr *x)
- {
- /* gfc_notify_std would be a waste of time as the return value
- is seemingly used only for the generic resolution. The error
- will be: Too many arguments. */
- if ((gfc_option.allow_std & GFC_STD_F2008) == 0)
- return false;
- return gfc_check_atan2 (y, x);
- }
- bool
- gfc_check_atan2 (gfc_expr *y, gfc_expr *x)
- {
- if (!type_check (y, 0, BT_REAL))
- return false;
- if (!same_type_check (y, 0, x, 1))
- return false;
- return true;
- }
- static bool
- gfc_check_atomic (gfc_expr *atom, int atom_no, gfc_expr *value, int val_no,
- gfc_expr *stat, int stat_no)
- {
- if (!scalar_check (atom, atom_no) || !scalar_check (value, val_no))
- return false;
- if (!(atom->ts.type == BT_INTEGER && atom->ts.kind == gfc_atomic_int_kind)
- && !(atom->ts.type == BT_LOGICAL
- && atom->ts.kind == gfc_atomic_logical_kind))
- {
- gfc_error ("ATOM argument at %L to intrinsic function %s shall be an "
- "integer of ATOMIC_INT_KIND or a logical of "
- "ATOMIC_LOGICAL_KIND", &atom->where, gfc_current_intrinsic);
- return false;
- }
- if (!gfc_is_coarray (atom) && !gfc_is_coindexed (atom))
- {
- gfc_error ("ATOM argument at %L of the %s intrinsic function shall be a "
- "coarray or coindexed", &atom->where, gfc_current_intrinsic);
- return false;
- }
- if (atom->ts.type != value->ts.type)
- {
- gfc_error_1 ("'%s' argument of '%s' intrinsic at %L shall have the same "
- "type as '%s' at %L", gfc_current_intrinsic_arg[val_no]->name,
- gfc_current_intrinsic, &value->where,
- gfc_current_intrinsic_arg[atom_no]->name, &atom->where);
- return false;
- }
- if (stat != NULL)
- {
- if (!type_check (stat, stat_no, BT_INTEGER))
- return false;
- if (!scalar_check (stat, stat_no))
- return false;
- if (!variable_check (stat, stat_no, false))
- return false;
- if (!kind_value_check (stat, stat_no, gfc_default_integer_kind))
- return false;
- if (!gfc_notify_std (GFC_STD_F2008_TS, "STAT= argument to %s at %L",
- gfc_current_intrinsic, &stat->where))
- return false;
- }
- return true;
- }
- bool
- gfc_check_atomic_def (gfc_expr *atom, gfc_expr *value, gfc_expr *stat)
- {
- if (atom->expr_type == EXPR_FUNCTION
- && atom->value.function.isym
- && atom->value.function.isym->id == GFC_ISYM_CAF_GET)
- atom = atom->value.function.actual->expr;
- if (!gfc_check_vardef_context (atom, false, false, false, NULL))
- {
- gfc_error ("ATOM argument of the %s intrinsic function at %L shall be "
- "definable", gfc_current_intrinsic, &atom->where);
- return false;
- }
- return gfc_check_atomic (atom, 0, value, 1, stat, 2);
- }
- bool
- gfc_check_atomic_op (gfc_expr *atom, gfc_expr *value, gfc_expr *stat)
- {
- if (atom->ts.type != BT_INTEGER || atom->ts.kind != gfc_atomic_int_kind)
- {
- gfc_error ("ATOM argument at %L to intrinsic function %s shall be an "
- "integer of ATOMIC_INT_KIND", &atom->where,
- gfc_current_intrinsic);
- return false;
- }
- return gfc_check_atomic_def (atom, value, stat);
- }
- bool
- gfc_check_atomic_ref (gfc_expr *value, gfc_expr *atom, gfc_expr *stat)
- {
- if (atom->expr_type == EXPR_FUNCTION
- && atom->value.function.isym
- && atom->value.function.isym->id == GFC_ISYM_CAF_GET)
- atom = atom->value.function.actual->expr;
- if (!gfc_check_vardef_context (value, false, false, false, NULL))
- {
- gfc_error ("VALUE argument of the %s intrinsic function at %L shall be "
- "definable", gfc_current_intrinsic, &value->where);
- return false;
- }
- return gfc_check_atomic (atom, 1, value, 0, stat, 2);
- }
- bool
- gfc_check_atomic_cas (gfc_expr *atom, gfc_expr *old, gfc_expr *compare,
- gfc_expr *new_val, gfc_expr *stat)
- {
- if (atom->expr_type == EXPR_FUNCTION
- && atom->value.function.isym
- && atom->value.function.isym->id == GFC_ISYM_CAF_GET)
- atom = atom->value.function.actual->expr;
- if (!gfc_check_atomic (atom, 0, new_val, 3, stat, 4))
- return false;
- if (!scalar_check (old, 1) || !scalar_check (compare, 2))
- return false;
- if (!same_type_check (atom, 0, old, 1))
- return false;
- if (!same_type_check (atom, 0, compare, 2))
- return false;
- if (!gfc_check_vardef_context (atom, false, false, false, NULL))
- {
- gfc_error ("ATOM argument of the %s intrinsic function at %L shall be "
- "definable", gfc_current_intrinsic, &atom->where);
- return false;
- }
- if (!gfc_check_vardef_context (old, false, false, false, NULL))
- {
- gfc_error ("OLD argument of the %s intrinsic function at %L shall be "
- "definable", gfc_current_intrinsic, &old->where);
- return false;
- }
- return true;
- }
- bool
- gfc_check_atomic_fetch_op (gfc_expr *atom, gfc_expr *value, gfc_expr *old,
- gfc_expr *stat)
- {
- if (atom->expr_type == EXPR_FUNCTION
- && atom->value.function.isym
- && atom->value.function.isym->id == GFC_ISYM_CAF_GET)
- atom = atom->value.function.actual->expr;
- if (atom->ts.type != BT_INTEGER || atom->ts.kind != gfc_atomic_int_kind)
- {
- gfc_error ("ATOM argument at %L to intrinsic function %s shall be an "
- "integer of ATOMIC_INT_KIND", &atom->where,
- gfc_current_intrinsic);
- return false;
- }
- if (!gfc_check_atomic (atom, 0, value, 1, stat, 3))
- return false;
- if (!scalar_check (old, 2))
- return false;
- if (!same_type_check (atom, 0, old, 2))
- return false;
- if (!gfc_check_vardef_context (atom, false, false, false, NULL))
- {
- gfc_error ("ATOM argument of the %s intrinsic function at %L shall be "
- "definable", gfc_current_intrinsic, &atom->where);
- return false;
- }
- if (!gfc_check_vardef_context (old, false, false, false, NULL))
- {
- gfc_error ("OLD argument of the %s intrinsic function at %L shall be "
- "definable", gfc_current_intrinsic, &old->where);
- return false;
- }
- return true;
- }
- /* BESJN and BESYN functions. */
- bool
- gfc_check_besn (gfc_expr *n, gfc_expr *x)
- {
- if (!type_check (n, 0, BT_INTEGER))
- return false;
- if (n->expr_type == EXPR_CONSTANT)
- {
- int i;
- gfc_extract_int (n, &i);
- if (i < 0 && !gfc_notify_std (GFC_STD_GNU, "Negative argument "
- "N at %L", &n->where))
- return false;
- }
- if (!type_check (x, 1, BT_REAL))
- return false;
- return true;
- }
- /* Transformational version of the Bessel JN and YN functions. */
- bool
- gfc_check_bessel_n2 (gfc_expr *n1, gfc_expr *n2, gfc_expr *x)
- {
- if (!type_check (n1, 0, BT_INTEGER))
- return false;
- if (!scalar_check (n1, 0))
- return false;
- if (!nonnegative_check ("N1", n1))
- return false;
- if (!type_check (n2, 1, BT_INTEGER))
- return false;
- if (!scalar_check (n2, 1))
- return false;
- if (!nonnegative_check ("N2", n2))
- return false;
- if (!type_check (x, 2, BT_REAL))
- return false;
- if (!scalar_check (x, 2))
- return false;
- return true;
- }
- bool
- gfc_check_bge_bgt_ble_blt (gfc_expr *i, gfc_expr *j)
- {
- if (!type_check (i, 0, BT_INTEGER))
- return false;
- if (!type_check (j, 1, BT_INTEGER))
- return false;
- return true;
- }
- bool
- gfc_check_bitfcn (gfc_expr *i, gfc_expr *pos)
- {
- if (!type_check (i, 0, BT_INTEGER))
- return false;
- if (!type_check (pos, 1, BT_INTEGER))
- return false;
- if (!nonnegative_check ("pos", pos))
- return false;
- if (!less_than_bitsize1 ("i", i, "pos", pos, false))
- return false;
- return true;
- }
- bool
- gfc_check_char (gfc_expr *i, gfc_expr *kind)
- {
- if (!type_check (i, 0, BT_INTEGER))
- return false;
- if (!kind_check (kind, 1, BT_CHARACTER))
- return false;
- return true;
- }
- bool
- gfc_check_chdir (gfc_expr *dir)
- {
- if (!type_check (dir, 0, BT_CHARACTER))
- return false;
- if (!kind_value_check (dir, 0, gfc_default_character_kind))
- return false;
- return true;
- }
- bool
- gfc_check_chdir_sub (gfc_expr *dir, gfc_expr *status)
- {
- if (!type_check (dir, 0, BT_CHARACTER))
- return false;
- if (!kind_value_check (dir, 0, gfc_default_character_kind))
- return false;
- if (status == NULL)
- return true;
- if (!type_check (status, 1, BT_INTEGER))
- return false;
- if (!scalar_check (status, 1))
- return false;
- return true;
- }
- bool
- gfc_check_chmod (gfc_expr *name, gfc_expr *mode)
- {
- if (!type_check (name, 0, BT_CHARACTER))
- return false;
- if (!kind_value_check (name, 0, gfc_default_character_kind))
- return false;
- if (!type_check (mode, 1, BT_CHARACTER))
- return false;
- if (!kind_value_check (mode, 1, gfc_default_character_kind))
- return false;
- return true;
- }
- bool
- gfc_check_chmod_sub (gfc_expr *name, gfc_expr *mode, gfc_expr *status)
- {
- if (!type_check (name, 0, BT_CHARACTER))
- return false;
- if (!kind_value_check (name, 0, gfc_default_character_kind))
- return false;
- if (!type_check (mode, 1, BT_CHARACTER))
- return false;
- if (!kind_value_check (mode, 1, gfc_default_character_kind))
- return false;
- if (status == NULL)
- return true;
- if (!type_check (status, 2, BT_INTEGER))
- return false;
- if (!scalar_check (status, 2))
- return false;
- return true;
- }
- bool
- gfc_check_cmplx (gfc_expr *x, gfc_expr *y, gfc_expr *kind)
- {
- if (!numeric_check (x, 0))
- return false;
- if (y != NULL)
- {
- if (!numeric_check (y, 1))
- return false;
- if (x->ts.type == BT_COMPLEX)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L must not be "
- "present if %<x%> is COMPLEX",
- gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
- &y->where);
- return false;
- }
- if (y->ts.type == BT_COMPLEX)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L must have a type "
- "of either REAL or INTEGER",
- gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
- &y->where);
- return false;
- }
- }
- if (!kind_check (kind, 2, BT_COMPLEX))
- return false;
- if (!kind && warn_conversion
- && x->ts.type == BT_REAL && x->ts.kind > gfc_default_real_kind)
- gfc_warning_now (OPT_Wconversion, "Conversion from %s to default-kind "
- "COMPLEX(%d) at %L might lose precision, consider using "
- "the KIND argument", gfc_typename (&x->ts),
- gfc_default_real_kind, &x->where);
- else if (y && !kind && warn_conversion
- && y->ts.type == BT_REAL && y->ts.kind > gfc_default_real_kind)
- gfc_warning_now (OPT_Wconversion, "Conversion from %s to default-kind "
- "COMPLEX(%d) at %L might lose precision, consider using "
- "the KIND argument", gfc_typename (&y->ts),
- gfc_default_real_kind, &y->where);
- return true;
- }
- static bool
- check_co_collective (gfc_expr *a, gfc_expr *image_idx, gfc_expr *stat,
- gfc_expr *errmsg, bool co_reduce)
- {
- if (!variable_check (a, 0, false))
- return false;
- if (!gfc_check_vardef_context (a, false, false, false, "argument 'A' with "
- "INTENT(INOUT)"))
- return false;
- /* Fortran 2008, 12.5.2.4, paragraph 18. */
- if (gfc_has_vector_subscript (a))
- {
- gfc_error ("Argument %<A%> with INTENT(INOUT) at %L of the intrinsic "
- "subroutine %s shall not have a vector subscript",
- &a->where, gfc_current_intrinsic);
- return false;
- }
- if (gfc_is_coindexed (a))
- {
- gfc_error ("The A argument at %L to the intrinsic %s shall not be "
- "coindexed", &a->where, gfc_current_intrinsic);
- return false;
- }
- if (image_idx != NULL)
- {
- if (!type_check (image_idx, co_reduce ? 2 : 1, BT_INTEGER))
- return false;
- if (!scalar_check (image_idx, co_reduce ? 2 : 1))
- return false;
- }
- if (stat != NULL)
- {
- if (!type_check (stat, co_reduce ? 3 : 2, BT_INTEGER))
- return false;
- if (!scalar_check (stat, co_reduce ? 3 : 2))
- return false;
- if (!variable_check (stat, co_reduce ? 3 : 2, false))
- return false;
- if (stat->ts.kind != 4)
- {
- gfc_error ("The stat= argument at %L must be a kind=4 integer "
- "variable", &stat->where);
- return false;
- }
- }
- if (errmsg != NULL)
- {
- if (!type_check (errmsg, co_reduce ? 4 : 3, BT_CHARACTER))
- return false;
- if (!scalar_check (errmsg, co_reduce ? 4 : 3))
- return false;
- if (!variable_check (errmsg, co_reduce ? 4 : 3, false))
- return false;
- if (errmsg->ts.kind != 1)
- {
- gfc_error ("The errmsg= argument at %L must be a default-kind "
- "character variable", &errmsg->where);
- return false;
- }
- }
- if (flag_coarray == GFC_FCOARRAY_NONE)
- {
- gfc_fatal_error ("Coarrays disabled at %L, use %<-fcoarray=%> to enable",
- &a->where);
- return false;
- }
- return true;
- }
- bool
- gfc_check_co_broadcast (gfc_expr *a, gfc_expr *source_image, gfc_expr *stat,
- gfc_expr *errmsg)
- {
- if (a->ts.type == BT_CLASS || gfc_expr_attr (a).alloc_comp)
- {
- gfc_error ("Support for the A argument at %L which is polymorphic A "
- "argument or has allocatable components is not yet "
- "implemented", &a->where);
- return false;
- }
- return check_co_collective (a, source_image, stat, errmsg, false);
- }
- bool
- gfc_check_co_reduce (gfc_expr *a, gfc_expr *op, gfc_expr *result_image,
- gfc_expr *stat, gfc_expr *errmsg)
- {
- symbol_attribute attr;
- gfc_formal_arglist *formal;
- gfc_symbol *sym;
- if (a->ts.type == BT_CLASS)
- {
- gfc_error ("The A argument at %L of CO_REDUCE shall not be polymorphic",
- &a->where);
- return false;
- }
- if (gfc_expr_attr (a).alloc_comp)
- {
- gfc_error ("Support for the A argument at %L with allocatable components"
- " is not yet implemented", &a->where);
- return false;
- }
- if (!check_co_collective (a, result_image, stat, errmsg, true))
- return false;
- if (!gfc_resolve_expr (op))
- return false;
- attr = gfc_expr_attr (op);
- if (!attr.pure || !attr.function)
- {
- gfc_error ("OPERATOR argument at %L must be a PURE function",
- &op->where);
- return false;
- }
- if (attr.intrinsic)
- {
- /* None of the intrinsics fulfills the criteria of taking two arguments,
- returning the same type and kind as the arguments and being permitted
- as actual argument. */
- gfc_error ("Intrinsic function %s at %L is not permitted for CO_REDUCE",
- op->symtree->n.sym->name, &op->where);
- return false;
- }
- if (gfc_is_proc_ptr_comp (op))
- {
- gfc_component *comp = gfc_get_proc_ptr_comp (op);
- sym = comp->ts.interface;
- }
- else
- sym = op->symtree->n.sym;
- formal = sym->formal;
- if (!formal || !formal->next || formal->next->next)
- {
- gfc_error ("The function passed as OPERATOR at %L shall have two "
- "arguments", &op->where);
- return false;
- }
- if (sym->result->ts.type == BT_UNKNOWN)
- gfc_set_default_type (sym->result, 0, NULL);
- if (!gfc_compare_types (&a->ts, &sym->result->ts))
- {
- gfc_error_1 ("A argument at %L has type %s but the function passed as "
- "OPERATOR at %L returns %s",
- &a->where, gfc_typename (&a->ts), &op->where,
- gfc_typename (&sym->result->ts));
- return false;
- }
- if (!gfc_compare_types (&a->ts, &formal->sym->ts)
- || !gfc_compare_types (&a->ts, &formal->next->sym->ts))
- {
- gfc_error ("The function passed as OPERATOR at %L has arguments of type "
- "%s and %s but shall have type %s", &op->where,
- gfc_typename (&formal->sym->ts),
- gfc_typename (&formal->next->sym->ts), gfc_typename (&a->ts));
- return false;
- }
- if (op->rank || attr.allocatable || attr.pointer || formal->sym->as
- || formal->next->sym->as || formal->sym->attr.allocatable
- || formal->next->sym->attr.allocatable || formal->sym->attr.pointer
- || formal->next->sym->attr.pointer)
- {
- gfc_error ("The function passed as OPERATOR at %L shall have scalar "
- "nonallocatable nonpointer arguments and return a "
- "nonallocatable nonpointer scalar", &op->where);
- return false;
- }
- if (formal->sym->attr.value != formal->next->sym->attr.value)
- {
- gfc_error ("The function passed as OPERATOR at %L shall have the VALUE "
- "attribute either for none or both arguments", &op->where);
- return false;
- }
- if (formal->sym->attr.target != formal->next->sym->attr.target)
- {
- gfc_error ("The function passed as OPERATOR at %L shall have the TARGET "
- "attribute either for none or both arguments", &op->where);
- return false;
- }
- if (formal->sym->attr.asynchronous != formal->next->sym->attr.asynchronous)
- {
- gfc_error ("The function passed as OPERATOR at %L shall have the "
- "ASYNCHRONOUS attribute either for none or both arguments",
- &op->where);
- return false;
- }
- if (formal->sym->attr.optional || formal->next->sym->attr.optional)
- {
- gfc_error ("The function passed as OPERATOR at %L shall not have the "
- "OPTIONAL attribute for either of the arguments", &op->where);
- return false;
- }
- if (a->ts.type == BT_CHARACTER)
- {
- gfc_charlen *cl;
- unsigned long actual_size, formal_size1, formal_size2, result_size;
- cl = a->ts.u.cl;
- actual_size = cl && cl->length && cl->length->expr_type == EXPR_CONSTANT
- ? mpz_get_ui (cl->length->value.integer) : 0;
- cl = formal->sym->ts.u.cl;
- formal_size1 = cl && cl->length && cl->length->expr_type == EXPR_CONSTANT
- ? mpz_get_ui (cl->length->value.integer) : 0;
- cl = formal->next->sym->ts.u.cl;
- formal_size2 = cl && cl->length && cl->length->expr_type == EXPR_CONSTANT
- ? mpz_get_ui (cl->length->value.integer) : 0;
- cl = sym->ts.u.cl;
- result_size = cl && cl->length && cl->length->expr_type == EXPR_CONSTANT
- ? mpz_get_ui (cl->length->value.integer) : 0;
- if (actual_size
- && ((formal_size1 && actual_size != formal_size1)
- || (formal_size2 && actual_size != formal_size2)))
- {
- gfc_error_1 ("The character length of the A argument at %L and of the "
- "arguments of the OPERATOR at %L shall be the same",
- &a->where, &op->where);
- return false;
- }
- if (actual_size && result_size && actual_size != result_size)
- {
- gfc_error_1 ("The character length of the A argument at %L and of the "
- "function result of the OPERATOR at %L shall be the same",
- &a->where, &op->where);
- return false;
- }
- }
- return true;
- }
- bool
- gfc_check_co_minmax (gfc_expr *a, gfc_expr *result_image, gfc_expr *stat,
- gfc_expr *errmsg)
- {
- if (a->ts.type != BT_INTEGER && a->ts.type != BT_REAL
- && a->ts.type != BT_CHARACTER)
- {
- gfc_error_1 ("'%s' argument of '%s' intrinsic at %L shall be of type "
- "integer, real or character",
- gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
- &a->where);
- return false;
- }
- return check_co_collective (a, result_image, stat, errmsg, false);
- }
- bool
- gfc_check_co_sum (gfc_expr *a, gfc_expr *result_image, gfc_expr *stat,
- gfc_expr *errmsg)
- {
- if (!numeric_check (a, 0))
- return false;
- return check_co_collective (a, result_image, stat, errmsg, false);
- }
- bool
- gfc_check_complex (gfc_expr *x, gfc_expr *y)
- {
- if (!int_or_real_check (x, 0))
- return false;
- if (!scalar_check (x, 0))
- return false;
- if (!int_or_real_check (y, 1))
- return false;
- if (!scalar_check (y, 1))
- return false;
- return true;
- }
- bool
- gfc_check_count (gfc_expr *mask, gfc_expr *dim, gfc_expr *kind)
- {
- if (!logical_array_check (mask, 0))
- return false;
- if (!dim_check (dim, 1, false))
- return false;
- if (!dim_rank_check (dim, mask, 0))
- return false;
- if (!kind_check (kind, 2, BT_INTEGER))
- return false;
- if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
- "with KIND argument at %L",
- gfc_current_intrinsic, &kind->where))
- return false;
- return true;
- }
- bool
- gfc_check_cshift (gfc_expr *array, gfc_expr *shift, gfc_expr *dim)
- {
- if (!array_check (array, 0))
- return false;
- if (!type_check (shift, 1, BT_INTEGER))
- return false;
- if (!dim_check (dim, 2, true))
- return false;
- if (!dim_rank_check (dim, array, false))
- return false;
- if (array->rank == 1 || shift->rank == 0)
- {
- if (!scalar_check (shift, 1))
- return false;
- }
- else if (shift->rank == array->rank - 1)
- {
- int d;
- if (!dim)
- d = 1;
- else if (dim->expr_type == EXPR_CONSTANT)
- gfc_extract_int (dim, &d);
- else
- d = -1;
- if (d > 0)
- {
- int i, j;
- for (i = 0, j = 0; i < array->rank; i++)
- if (i != d - 1)
- {
- if (!identical_dimen_shape (array, i, shift, j))
- {
- gfc_error ("%qs argument of %qs intrinsic at %L has "
- "invalid shape in dimension %d (%ld/%ld)",
- gfc_current_intrinsic_arg[1]->name,
- gfc_current_intrinsic, &shift->where, i + 1,
- mpz_get_si (array->shape[i]),
- mpz_get_si (shift->shape[j]));
- return false;
- }
- j += 1;
- }
- }
- }
- else
- {
- gfc_error ("%qs argument of intrinsic %qs at %L of must have rank "
- "%d or be a scalar", gfc_current_intrinsic_arg[1]->name,
- gfc_current_intrinsic, &shift->where, array->rank - 1);
- return false;
- }
- return true;
- }
- bool
- gfc_check_ctime (gfc_expr *time)
- {
- if (!scalar_check (time, 0))
- return false;
- if (!type_check (time, 0, BT_INTEGER))
- return false;
- return true;
- }
- bool gfc_check_datan2 (gfc_expr *y, gfc_expr *x)
- {
- if (!double_check (y, 0) || !double_check (x, 1))
- return false;
- return true;
- }
- bool
- gfc_check_dcmplx (gfc_expr *x, gfc_expr *y)
- {
- if (!numeric_check (x, 0))
- return false;
- if (y != NULL)
- {
- if (!numeric_check (y, 1))
- return false;
- if (x->ts.type == BT_COMPLEX)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L must not be "
- "present if %<x%> is COMPLEX",
- gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
- &y->where);
- return false;
- }
- if (y->ts.type == BT_COMPLEX)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L must have a type "
- "of either REAL or INTEGER",
- gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
- &y->where);
- return false;
- }
- }
- return true;
- }
- bool
- gfc_check_dble (gfc_expr *x)
- {
- if (!numeric_check (x, 0))
- return false;
- return true;
- }
- bool
- gfc_check_digits (gfc_expr *x)
- {
- if (!int_or_real_check (x, 0))
- return false;
- return true;
- }
- bool
- gfc_check_dot_product (gfc_expr *vector_a, gfc_expr *vector_b)
- {
- switch (vector_a->ts.type)
- {
- case BT_LOGICAL:
- if (!type_check (vector_b, 1, BT_LOGICAL))
- return false;
- break;
- case BT_INTEGER:
- case BT_REAL:
- case BT_COMPLEX:
- if (!numeric_check (vector_b, 1))
- return false;
- break;
- default:
- gfc_error ("%qs argument of %qs intrinsic at %L must be numeric "
- "or LOGICAL", gfc_current_intrinsic_arg[0]->name,
- gfc_current_intrinsic, &vector_a->where);
- return false;
- }
- if (!rank_check (vector_a, 0, 1))
- return false;
- if (!rank_check (vector_b, 1, 1))
- return false;
- if (! identical_dimen_shape (vector_a, 0, vector_b, 0))
- {
- gfc_error ("Different shape for arguments %qs and %qs at %L for "
- "intrinsic %<dot_product%>",
- gfc_current_intrinsic_arg[0]->name,
- gfc_current_intrinsic_arg[1]->name, &vector_a->where);
- return false;
- }
- return true;
- }
- bool
- gfc_check_dprod (gfc_expr *x, gfc_expr *y)
- {
- if (!type_check (x, 0, BT_REAL)
- || !type_check (y, 1, BT_REAL))
- return false;
- if (x->ts.kind != gfc_default_real_kind)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L must be default "
- "real", gfc_current_intrinsic_arg[0]->name,
- gfc_current_intrinsic, &x->where);
- return false;
- }
- if (y->ts.kind != gfc_default_real_kind)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L must be default "
- "real", gfc_current_intrinsic_arg[1]->name,
- gfc_current_intrinsic, &y->where);
- return false;
- }
- return true;
- }
- bool
- gfc_check_dshift (gfc_expr *i, gfc_expr *j, gfc_expr *shift)
- {
- if (!type_check (i, 0, BT_INTEGER))
- return false;
- if (!type_check (j, 1, BT_INTEGER))
- return false;
- if (i->is_boz && j->is_boz)
- {
- gfc_error_1 ("'I' at %L and 'J' at %L cannot both be BOZ literal "
- "constants", &i->where, &j->where);
- return false;
- }
- if (!i->is_boz && !j->is_boz && !same_type_check (i, 0, j, 1))
- return false;
- if (!type_check (shift, 2, BT_INTEGER))
- return false;
- if (!nonnegative_check ("SHIFT", shift))
- return false;
- if (i->is_boz)
- {
- if (!less_than_bitsize1 ("J", j, "SHIFT", shift, true))
- return false;
- i->ts.kind = j->ts.kind;
- }
- else
- {
- if (!less_than_bitsize1 ("I", i, "SHIFT", shift, true))
- return false;
- j->ts.kind = i->ts.kind;
- }
- return true;
- }
- bool
- gfc_check_eoshift (gfc_expr *array, gfc_expr *shift, gfc_expr *boundary,
- gfc_expr *dim)
- {
- if (!array_check (array, 0))
- return false;
- if (!type_check (shift, 1, BT_INTEGER))
- return false;
- if (!dim_check (dim, 3, true))
- return false;
- if (!dim_rank_check (dim, array, false))
- return false;
- if (array->rank == 1 || shift->rank == 0)
- {
- if (!scalar_check (shift, 1))
- return false;
- }
- else if (shift->rank == array->rank - 1)
- {
- int d;
- if (!dim)
- d = 1;
- else if (dim->expr_type == EXPR_CONSTANT)
- gfc_extract_int (dim, &d);
- else
- d = -1;
- if (d > 0)
- {
- int i, j;
- for (i = 0, j = 0; i < array->rank; i++)
- if (i != d - 1)
- {
- if (!identical_dimen_shape (array, i, shift, j))
- {
- gfc_error ("%qs argument of %qs intrinsic at %L has "
- "invalid shape in dimension %d (%ld/%ld)",
- gfc_current_intrinsic_arg[1]->name,
- gfc_current_intrinsic, &shift->where, i + 1,
- mpz_get_si (array->shape[i]),
- mpz_get_si (shift->shape[j]));
- return false;
- }
- j += 1;
- }
- }
- }
- else
- {
- gfc_error ("%qs argument of intrinsic %qs at %L of must have rank "
- "%d or be a scalar", gfc_current_intrinsic_arg[1]->name,
- gfc_current_intrinsic, &shift->where, array->rank - 1);
- return false;
- }
- if (boundary != NULL)
- {
- if (!same_type_check (array, 0, boundary, 2))
- return false;
- if (array->rank == 1 || boundary->rank == 0)
- {
- if (!scalar_check (boundary, 2))
- return false;
- }
- else if (boundary->rank == array->rank - 1)
- {
- if (!gfc_check_conformance (shift, boundary,
- "arguments '%s' and '%s' for "
- "intrinsic %s",
- gfc_current_intrinsic_arg[1]->name,
- gfc_current_intrinsic_arg[2]->name,
- gfc_current_intrinsic))
- return false;
- }
- else
- {
- gfc_error ("%qs argument of intrinsic %qs at %L of must have "
- "rank %d or be a scalar",
- gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
- &shift->where, array->rank - 1);
- return false;
- }
- }
- return true;
- }
- bool
- gfc_check_float (gfc_expr *a)
- {
- if (!type_check (a, 0, BT_INTEGER))
- return false;
- if ((a->ts.kind != gfc_default_integer_kind)
- && !gfc_notify_std (GFC_STD_GNU, "non-default INTEGER "
- "kind argument to %s intrinsic at %L",
- gfc_current_intrinsic, &a->where))
- return false;
- return true;
- }
- /* A single complex argument. */
- bool
- gfc_check_fn_c (gfc_expr *a)
- {
- if (!type_check (a, 0, BT_COMPLEX))
- return false;
- return true;
- }
- /* A single real argument. */
- bool
- gfc_check_fn_r (gfc_expr *a)
- {
- if (!type_check (a, 0, BT_REAL))
- return false;
- return true;
- }
- /* A single double argument. */
- bool
- gfc_check_fn_d (gfc_expr *a)
- {
- if (!double_check (a, 0))
- return false;
- return true;
- }
- /* A single real or complex argument. */
- bool
- gfc_check_fn_rc (gfc_expr *a)
- {
- if (!real_or_complex_check (a, 0))
- return false;
- return true;
- }
- bool
- gfc_check_fn_rc2008 (gfc_expr *a)
- {
- if (!real_or_complex_check (a, 0))
- return false;
- if (a->ts.type == BT_COMPLEX
- && !gfc_notify_std (GFC_STD_F2008, "COMPLEX argument %qs "
- "of %qs intrinsic at %L",
- gfc_current_intrinsic_arg[0]->name,
- gfc_current_intrinsic, &a->where))
- return false;
- return true;
- }
- bool
- gfc_check_fnum (gfc_expr *unit)
- {
- if (!type_check (unit, 0, BT_INTEGER))
- return false;
- if (!scalar_check (unit, 0))
- return false;
- return true;
- }
- bool
- gfc_check_huge (gfc_expr *x)
- {
- if (!int_or_real_check (x, 0))
- return false;
- return true;
- }
- bool
- gfc_check_hypot (gfc_expr *x, gfc_expr *y)
- {
- if (!type_check (x, 0, BT_REAL))
- return false;
- if (!same_type_check (x, 0, y, 1))
- return false;
- return true;
- }
- /* Check that the single argument is an integer. */
- bool
- gfc_check_i (gfc_expr *i)
- {
- if (!type_check (i, 0, BT_INTEGER))
- return false;
- return true;
- }
- bool
- gfc_check_iand (gfc_expr *i, gfc_expr *j)
- {
- if (!type_check (i, 0, BT_INTEGER))
- return false;
- if (!type_check (j, 1, BT_INTEGER))
- return false;
- if (i->ts.kind != j->ts.kind)
- {
- if (!gfc_notify_std (GFC_STD_GNU, "Different type kinds at %L",
- &i->where))
- return false;
- }
- return true;
- }
- bool
- gfc_check_ibits (gfc_expr *i, gfc_expr *pos, gfc_expr *len)
- {
- if (!type_check (i, 0, BT_INTEGER))
- return false;
- if (!type_check (pos, 1, BT_INTEGER))
- return false;
- if (!type_check (len, 2, BT_INTEGER))
- return false;
- if (!nonnegative_check ("pos", pos))
- return false;
- if (!nonnegative_check ("len", len))
- return false;
- if (!less_than_bitsize2 ("i", i, "pos", pos, "len", len))
- return false;
- return true;
- }
- bool
- gfc_check_ichar_iachar (gfc_expr *c, gfc_expr *kind)
- {
- int i;
- if (!type_check (c, 0, BT_CHARACTER))
- return false;
- if (!kind_check (kind, 1, BT_INTEGER))
- return false;
- if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
- "with KIND argument at %L",
- gfc_current_intrinsic, &kind->where))
- return false;
- if (c->expr_type == EXPR_VARIABLE || c->expr_type == EXPR_SUBSTRING)
- {
- gfc_expr *start;
- gfc_expr *end;
- gfc_ref *ref;
- /* Substring references don't have the charlength set. */
- ref = c->ref;
- while (ref && ref->type != REF_SUBSTRING)
- ref = ref->next;
- gcc_assert (ref == NULL || ref->type == REF_SUBSTRING);
- if (!ref)
- {
- /* Check that the argument is length one. Non-constant lengths
- can't be checked here, so assume they are ok. */
- if (c->ts.u.cl && c->ts.u.cl->length)
- {
- /* If we already have a length for this expression then use it. */
- if (c->ts.u.cl->length->expr_type != EXPR_CONSTANT)
- return true;
- i = mpz_get_si (c->ts.u.cl->length->value.integer);
- }
- else
- return true;
- }
- else
- {
- start = ref->u.ss.start;
- end = ref->u.ss.end;
- gcc_assert (start);
- if (end == NULL || end->expr_type != EXPR_CONSTANT
- || start->expr_type != EXPR_CONSTANT)
- return true;
- i = mpz_get_si (end->value.integer) + 1
- - mpz_get_si (start->value.integer);
- }
- }
- else
- return true;
- if (i != 1)
- {
- gfc_error ("Argument of %s at %L must be of length one",
- gfc_current_intrinsic, &c->where);
- return false;
- }
- return true;
- }
- bool
- gfc_check_idnint (gfc_expr *a)
- {
- if (!double_check (a, 0))
- return false;
- return true;
- }
- bool
- gfc_check_ieor (gfc_expr *i, gfc_expr *j)
- {
- if (!type_check (i, 0, BT_INTEGER))
- return false;
- if (!type_check (j, 1, BT_INTEGER))
- return false;
- if (i->ts.kind != j->ts.kind)
- {
- if (!gfc_notify_std (GFC_STD_GNU, "Different type kinds at %L",
- &i->where))
- return false;
- }
- return true;
- }
- bool
- gfc_check_index (gfc_expr *string, gfc_expr *substring, gfc_expr *back,
- gfc_expr *kind)
- {
- if (!type_check (string, 0, BT_CHARACTER)
- || !type_check (substring, 1, BT_CHARACTER))
- return false;
- if (back != NULL && !type_check (back, 2, BT_LOGICAL))
- return false;
- if (!kind_check (kind, 3, BT_INTEGER))
- return false;
- if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
- "with KIND argument at %L",
- gfc_current_intrinsic, &kind->where))
- return false;
- if (string->ts.kind != substring->ts.kind)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L must be the same "
- "kind as %qs", gfc_current_intrinsic_arg[1]->name,
- gfc_current_intrinsic, &substring->where,
- gfc_current_intrinsic_arg[0]->name);
- return false;
- }
- return true;
- }
- bool
- gfc_check_int (gfc_expr *x, gfc_expr *kind)
- {
- if (!numeric_check (x, 0))
- return false;
- if (!kind_check (kind, 1, BT_INTEGER))
- return false;
- return true;
- }
- bool
- gfc_check_intconv (gfc_expr *x)
- {
- if (!numeric_check (x, 0))
- return false;
- return true;
- }
- bool
- gfc_check_ior (gfc_expr *i, gfc_expr *j)
- {
- if (!type_check (i, 0, BT_INTEGER))
- return false;
- if (!type_check (j, 1, BT_INTEGER))
- return false;
- if (i->ts.kind != j->ts.kind)
- {
- if (!gfc_notify_std (GFC_STD_GNU, "Different type kinds at %L",
- &i->where))
- return false;
- }
- return true;
- }
- bool
- gfc_check_ishft (gfc_expr *i, gfc_expr *shift)
- {
- if (!type_check (i, 0, BT_INTEGER)
- || !type_check (shift, 1, BT_INTEGER))
- return false;
- if (!less_than_bitsize1 ("I", i, NULL, shift, true))
- return false;
- return true;
- }
- bool
- gfc_check_ishftc (gfc_expr *i, gfc_expr *shift, gfc_expr *size)
- {
- if (!type_check (i, 0, BT_INTEGER)
- || !type_check (shift, 1, BT_INTEGER))
- return false;
- if (size != NULL)
- {
- int i2, i3;
- if (!type_check (size, 2, BT_INTEGER))
- return false;
- if (!less_than_bitsize1 ("I", i, "SIZE", size, true))
- return false;
- if (size->expr_type == EXPR_CONSTANT)
- {
- gfc_extract_int (size, &i3);
- if (i3 <= 0)
- {
- gfc_error ("SIZE at %L must be positive", &size->where);
- return false;
- }
- if (shift->expr_type == EXPR_CONSTANT)
- {
- gfc_extract_int (shift, &i2);
- if (i2 < 0)
- i2 = -i2;
- if (i2 > i3)
- {
- gfc_error_1 ("The absolute value of SHIFT at %L must be less "
- "than or equal to SIZE at %L", &shift->where,
- &size->where);
- return false;
- }
- }
- }
- }
- else if (!less_than_bitsize1 ("I", i, NULL, shift, true))
- return false;
- return true;
- }
- bool
- gfc_check_kill (gfc_expr *pid, gfc_expr *sig)
- {
- if (!type_check (pid, 0, BT_INTEGER))
- return false;
- if (!type_check (sig, 1, BT_INTEGER))
- return false;
- return true;
- }
- bool
- gfc_check_kill_sub (gfc_expr *pid, gfc_expr *sig, gfc_expr *status)
- {
- if (!type_check (pid, 0, BT_INTEGER))
- return false;
- if (!scalar_check (pid, 0))
- return false;
- if (!type_check (sig, 1, BT_INTEGER))
- return false;
- if (!scalar_check (sig, 1))
- return false;
- if (status == NULL)
- return true;
- if (!type_check (status, 2, BT_INTEGER))
- return false;
- if (!scalar_check (status, 2))
- return false;
- return true;
- }
- bool
- gfc_check_kind (gfc_expr *x)
- {
- if (x->ts.type == BT_DERIVED || x->ts.type == BT_CLASS)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L must be of "
- "intrinsic type", gfc_current_intrinsic_arg[0]->name,
- gfc_current_intrinsic, &x->where);
- return false;
- }
- if (x->ts.type == BT_PROCEDURE)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L must be a data entity",
- gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
- &x->where);
- return false;
- }
- return true;
- }
- bool
- gfc_check_lbound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
- {
- if (!array_check (array, 0))
- return false;
- if (!dim_check (dim, 1, false))
- return false;
- if (!dim_rank_check (dim, array, 1))
- return false;
- if (!kind_check (kind, 2, BT_INTEGER))
- return false;
- if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
- "with KIND argument at %L",
- gfc_current_intrinsic, &kind->where))
- return false;
- return true;
- }
- bool
- gfc_check_lcobound (gfc_expr *coarray, gfc_expr *dim, gfc_expr *kind)
- {
- if (flag_coarray == GFC_FCOARRAY_NONE)
- {
- gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
- return false;
- }
- if (!coarray_check (coarray, 0))
- return false;
- if (dim != NULL)
- {
- if (!dim_check (dim, 1, false))
- return false;
- if (!dim_corank_check (dim, coarray))
- return false;
- }
- if (!kind_check (kind, 2, BT_INTEGER))
- return false;
- return true;
- }
- bool
- gfc_check_len_lentrim (gfc_expr *s, gfc_expr *kind)
- {
- if (!type_check (s, 0, BT_CHARACTER))
- return false;
- if (!kind_check (kind, 1, BT_INTEGER))
- return false;
- if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
- "with KIND argument at %L",
- gfc_current_intrinsic, &kind->where))
- return false;
- return true;
- }
- bool
- gfc_check_lge_lgt_lle_llt (gfc_expr *a, gfc_expr *b)
- {
- if (!type_check (a, 0, BT_CHARACTER))
- return false;
- if (!kind_value_check (a, 0, gfc_default_character_kind))
- return false;
- if (!type_check (b, 1, BT_CHARACTER))
- return false;
- if (!kind_value_check (b, 1, gfc_default_character_kind))
- return false;
- return true;
- }
- bool
- gfc_check_link (gfc_expr *path1, gfc_expr *path2)
- {
- if (!type_check (path1, 0, BT_CHARACTER))
- return false;
- if (!kind_value_check (path1, 0, gfc_default_character_kind))
- return false;
- if (!type_check (path2, 1, BT_CHARACTER))
- return false;
- if (!kind_value_check (path2, 1, gfc_default_character_kind))
- return false;
- return true;
- }
- bool
- gfc_check_link_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
- {
- if (!type_check (path1, 0, BT_CHARACTER))
- return false;
- if (!kind_value_check (path1, 0, gfc_default_character_kind))
- return false;
- if (!type_check (path2, 1, BT_CHARACTER))
- return false;
- if (!kind_value_check (path2, 0, gfc_default_character_kind))
- return false;
- if (status == NULL)
- return true;
- if (!type_check (status, 2, BT_INTEGER))
- return false;
- if (!scalar_check (status, 2))
- return false;
- return true;
- }
- bool
- gfc_check_loc (gfc_expr *expr)
- {
- return variable_check (expr, 0, true);
- }
- bool
- gfc_check_symlnk (gfc_expr *path1, gfc_expr *path2)
- {
- if (!type_check (path1, 0, BT_CHARACTER))
- return false;
- if (!kind_value_check (path1, 0, gfc_default_character_kind))
- return false;
- if (!type_check (path2, 1, BT_CHARACTER))
- return false;
- if (!kind_value_check (path2, 1, gfc_default_character_kind))
- return false;
- return true;
- }
- bool
- gfc_check_symlnk_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
- {
- if (!type_check (path1, 0, BT_CHARACTER))
- return false;
- if (!kind_value_check (path1, 0, gfc_default_character_kind))
- return false;
- if (!type_check (path2, 1, BT_CHARACTER))
- return false;
- if (!kind_value_check (path2, 1, gfc_default_character_kind))
- return false;
- if (status == NULL)
- return true;
- if (!type_check (status, 2, BT_INTEGER))
- return false;
- if (!scalar_check (status, 2))
- return false;
- return true;
- }
- bool
- gfc_check_logical (gfc_expr *a, gfc_expr *kind)
- {
- if (!type_check (a, 0, BT_LOGICAL))
- return false;
- if (!kind_check (kind, 1, BT_LOGICAL))
- return false;
- return true;
- }
- /* Min/max family. */
- static bool
- min_max_args (gfc_actual_arglist *args)
- {
- gfc_actual_arglist *arg;
- int i, j, nargs, *nlabels, nlabelless;
- bool a1 = false, a2 = false;
- if (args == NULL || args->next == NULL)
- {
- gfc_error ("Intrinsic %qs at %L must have at least two arguments",
- gfc_current_intrinsic, gfc_current_intrinsic_where);
- return false;
- }
- if (!args->name)
- a1 = true;
- if (!args->next->name)
- a2 = true;
- nargs = 0;
- for (arg = args; arg; arg = arg->next)
- if (arg->name)
- nargs++;
- if (nargs == 0)
- return true;
- /* Note: Having a keywordless argument after an "arg=" is checked before. */
- nlabelless = 0;
- nlabels = XALLOCAVEC (int, nargs);
- for (arg = args, i = 0; arg; arg = arg->next, i++)
- if (arg->name)
- {
- int n;
- char *endp;
- if (arg->name[0] != 'a' || arg->name[1] < '1' || arg->name[1] > '9')
- goto unknown;
- n = strtol (&arg->name[1], &endp, 10);
- if (endp[0] != '\0')
- goto unknown;
- if (n <= 0)
- goto unknown;
- if (n <= nlabelless)
- goto duplicate;
- nlabels[i] = n;
- if (n == 1)
- a1 = true;
- if (n == 2)
- a2 = true;
- }
- else
- nlabelless++;
- if (!a1 || !a2)
- {
- gfc_error ("Missing %qs argument to the %s intrinsic at %L",
- !a1 ? "a1" : "a2", gfc_current_intrinsic,
- gfc_current_intrinsic_where);
- return false;
- }
- /* Check for duplicates. */
- for (i = 0; i < nargs; i++)
- for (j = i + 1; j < nargs; j++)
- if (nlabels[i] == nlabels[j])
- goto duplicate;
- return true;
- duplicate:
- gfc_error ("Duplicate argument %qs at %L to intrinsic %s", arg->name,
- &arg->expr->where, gfc_current_intrinsic);
- return false;
- unknown:
- gfc_error ("Unknown argument %qs at %L to intrinsic %s", arg->name,
- &arg->expr->where, gfc_current_intrinsic);
- return false;
- }
- static bool
- check_rest (bt type, int kind, gfc_actual_arglist *arglist)
- {
- gfc_actual_arglist *arg, *tmp;
- gfc_expr *x;
- int m, n;
- if (!min_max_args (arglist))
- return false;
- for (arg = arglist, n=1; arg; arg = arg->next, n++)
- {
- x = arg->expr;
- if (x->ts.type != type || x->ts.kind != kind)
- {
- if (x->ts.type == type)
- {
- if (!gfc_notify_std (GFC_STD_GNU, "Different type "
- "kinds at %L", &x->where))
- return false;
- }
- else
- {
- gfc_error ("%<a%d%> argument of %qs intrinsic at %L must be "
- "%s(%d)", n, gfc_current_intrinsic, &x->where,
- gfc_basic_typename (type), kind);
- return false;
- }
- }
- for (tmp = arglist, m=1; tmp != arg; tmp = tmp->next, m++)
- if (!gfc_check_conformance (tmp->expr, x,
- "arguments 'a%d' and 'a%d' for "
- "intrinsic '%s'", m, n,
- gfc_current_intrinsic))
- return false;
- }
- return true;
- }
- bool
- gfc_check_min_max (gfc_actual_arglist *arg)
- {
- gfc_expr *x;
- if (!min_max_args (arg))
- return false;
- x = arg->expr;
- if (x->ts.type == BT_CHARACTER)
- {
- if (!gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
- "with CHARACTER argument at %L",
- gfc_current_intrinsic, &x->where))
- return false;
- }
- else if (x->ts.type != BT_INTEGER && x->ts.type != BT_REAL)
- {
- gfc_error ("%<a1%> argument of %qs intrinsic at %L must be INTEGER, "
- "REAL or CHARACTER", gfc_current_intrinsic, &x->where);
- return false;
- }
- return check_rest (x->ts.type, x->ts.kind, arg);
- }
- bool
- gfc_check_min_max_integer (gfc_actual_arglist *arg)
- {
- return check_rest (BT_INTEGER, gfc_default_integer_kind, arg);
- }
- bool
- gfc_check_min_max_real (gfc_actual_arglist *arg)
- {
- return check_rest (BT_REAL, gfc_default_real_kind, arg);
- }
- bool
- gfc_check_min_max_double (gfc_actual_arglist *arg)
- {
- return check_rest (BT_REAL, gfc_default_double_kind, arg);
- }
- /* End of min/max family. */
- bool
- gfc_check_malloc (gfc_expr *size)
- {
- if (!type_check (size, 0, BT_INTEGER))
- return false;
- if (!scalar_check (size, 0))
- return false;
- return true;
- }
- bool
- gfc_check_matmul (gfc_expr *matrix_a, gfc_expr *matrix_b)
- {
- if ((matrix_a->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_a->ts))
- {
- gfc_error ("%qs argument of %qs intrinsic at %L must be numeric "
- "or LOGICAL", gfc_current_intrinsic_arg[0]->name,
- gfc_current_intrinsic, &matrix_a->where);
- return false;
- }
- if ((matrix_b->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_b->ts))
- {
- gfc_error ("%qs argument of %qs intrinsic at %L must be numeric "
- "or LOGICAL", gfc_current_intrinsic_arg[1]->name,
- gfc_current_intrinsic, &matrix_b->where);
- return false;
- }
- if ((matrix_a->ts.type == BT_LOGICAL && gfc_numeric_ts (&matrix_b->ts))
- || (gfc_numeric_ts (&matrix_a->ts) && matrix_b->ts.type == BT_LOGICAL))
- {
- gfc_error ("Argument types of %qs intrinsic at %L must match (%s/%s)",
- gfc_current_intrinsic, &matrix_a->where,
- gfc_typename(&matrix_a->ts), gfc_typename(&matrix_b->ts));
- return false;
- }
- switch (matrix_a->rank)
- {
- case 1:
- if (!rank_check (matrix_b, 1, 2))
- return false;
- /* Check for case matrix_a has shape(m), matrix_b has shape (m, k). */
- if (!identical_dimen_shape (matrix_a, 0, matrix_b, 0))
- {
- gfc_error ("Different shape on dimension 1 for arguments %qs "
- "and %qs at %L for intrinsic matmul",
- gfc_current_intrinsic_arg[0]->name,
- gfc_current_intrinsic_arg[1]->name, &matrix_a->where);
- return false;
- }
- break;
- case 2:
- if (matrix_b->rank != 2)
- {
- if (!rank_check (matrix_b, 1, 1))
- return false;
- }
- /* matrix_b has rank 1 or 2 here. Common check for the cases
- - matrix_a has shape (n,m) and matrix_b has shape (m, k)
- - matrix_a has shape (n,m) and matrix_b has shape (m). */
- if (!identical_dimen_shape (matrix_a, 1, matrix_b, 0))
- {
- gfc_error ("Different shape on dimension 2 for argument %qs and "
- "dimension 1 for argument %qs at %L for intrinsic "
- "matmul", gfc_current_intrinsic_arg[0]->name,
- gfc_current_intrinsic_arg[1]->name, &matrix_a->where);
- return false;
- }
- break;
- default:
- gfc_error ("%qs argument of %qs intrinsic at %L must be of rank "
- "1 or 2", gfc_current_intrinsic_arg[0]->name,
- gfc_current_intrinsic, &matrix_a->where);
- return false;
- }
- return true;
- }
- /* Whoever came up with this interface was probably on something.
- The possibilities for the occupation of the second and third
- parameters are:
- Arg #2 Arg #3
- NULL NULL
- DIM NULL
- MASK NULL
- NULL MASK minloc(array, mask=m)
- DIM MASK
- I.e. in the case of minloc(array,mask), mask will be in the second
- position of the argument list and we'll have to fix that up. */
- bool
- gfc_check_minloc_maxloc (gfc_actual_arglist *ap)
- {
- gfc_expr *a, *m, *d;
- a = ap->expr;
- if (!int_or_real_check (a, 0) || !array_check (a, 0))
- return false;
- d = ap->next->expr;
- m = ap->next->next->expr;
- if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
- && ap->next->name == NULL)
- {
- m = d;
- d = NULL;
- ap->next->expr = NULL;
- ap->next->next->expr = m;
- }
- if (!dim_check (d, 1, false))
- return false;
- if (!dim_rank_check (d, a, 0))
- return false;
- if (m != NULL && !type_check (m, 2, BT_LOGICAL))
- return false;
- if (m != NULL
- && !gfc_check_conformance (a, m,
- "arguments '%s' and '%s' for intrinsic %s",
- gfc_current_intrinsic_arg[0]->name,
- gfc_current_intrinsic_arg[2]->name,
- gfc_current_intrinsic))
- return false;
- return true;
- }
- /* Similar to minloc/maxloc, the argument list might need to be
- reordered for the MINVAL, MAXVAL, PRODUCT, and SUM intrinsics. The
- difference is that MINLOC/MAXLOC take an additional KIND argument.
- The possibilities are:
- Arg #2 Arg #3
- NULL NULL
- DIM NULL
- MASK NULL
- NULL MASK minval(array, mask=m)
- DIM MASK
- I.e. in the case of minval(array,mask), mask will be in the second
- position of the argument list and we'll have to fix that up. */
- static bool
- check_reduction (gfc_actual_arglist *ap)
- {
- gfc_expr *a, *m, *d;
- a = ap->expr;
- d = ap->next->expr;
- m = ap->next->next->expr;
- if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
- && ap->next->name == NULL)
- {
- m = d;
- d = NULL;
- ap->next->expr = NULL;
- ap->next->next->expr = m;
- }
- if (!dim_check (d, 1, false))
- return false;
- if (!dim_rank_check (d, a, 0))
- return false;
- if (m != NULL && !type_check (m, 2, BT_LOGICAL))
- return false;
- if (m != NULL
- && !gfc_check_conformance (a, m,
- "arguments '%s' and '%s' for intrinsic %s",
- gfc_current_intrinsic_arg[0]->name,
- gfc_current_intrinsic_arg[2]->name,
- gfc_current_intrinsic))
- return false;
- return true;
- }
- bool
- gfc_check_minval_maxval (gfc_actual_arglist *ap)
- {
- if (!int_or_real_check (ap->expr, 0)
- || !array_check (ap->expr, 0))
- return false;
- return check_reduction (ap);
- }
- bool
- gfc_check_product_sum (gfc_actual_arglist *ap)
- {
- if (!numeric_check (ap->expr, 0)
- || !array_check (ap->expr, 0))
- return false;
- return check_reduction (ap);
- }
- /* For IANY, IALL and IPARITY. */
- bool
- gfc_check_mask (gfc_expr *i, gfc_expr *kind)
- {
- int k;
- if (!type_check (i, 0, BT_INTEGER))
- return false;
- if (!nonnegative_check ("I", i))
- return false;
- if (!kind_check (kind, 1, BT_INTEGER))
- return false;
- if (kind)
- gfc_extract_int (kind, &k);
- else
- k = gfc_default_integer_kind;
- if (!less_than_bitsizekind ("I", i, k))
- return false;
- return true;
- }
- bool
- gfc_check_transf_bit_intrins (gfc_actual_arglist *ap)
- {
- if (ap->expr->ts.type != BT_INTEGER)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER",
- gfc_current_intrinsic_arg[0]->name,
- gfc_current_intrinsic, &ap->expr->where);
- return false;
- }
- if (!array_check (ap->expr, 0))
- return false;
- return check_reduction (ap);
- }
- bool
- gfc_check_merge (gfc_expr *tsource, gfc_expr *fsource, gfc_expr *mask)
- {
- if (!same_type_check (tsource, 0, fsource, 1))
- return false;
- if (!type_check (mask, 2, BT_LOGICAL))
- return false;
- if (tsource->ts.type == BT_CHARACTER)
- return gfc_check_same_strlen (tsource, fsource, "MERGE intrinsic");
- return true;
- }
- bool
- gfc_check_merge_bits (gfc_expr *i, gfc_expr *j, gfc_expr *mask)
- {
- if (!type_check (i, 0, BT_INTEGER))
- return false;
- if (!type_check (j, 1, BT_INTEGER))
- return false;
- if (!type_check (mask, 2, BT_INTEGER))
- return false;
- if (!same_type_check (i, 0, j, 1))
- return false;
- if (!same_type_check (i, 0, mask, 2))
- return false;
- return true;
- }
- bool
- gfc_check_move_alloc (gfc_expr *from, gfc_expr *to)
- {
- if (!variable_check (from, 0, false))
- return false;
- if (!allocatable_check (from, 0))
- return false;
- if (gfc_is_coindexed (from))
- {
- gfc_error ("The FROM argument to MOVE_ALLOC at %L shall not be "
- "coindexed", &from->where);
- return false;
- }
- if (!variable_check (to, 1, false))
- return false;
- if (!allocatable_check (to, 1))
- return false;
- if (gfc_is_coindexed (to))
- {
- gfc_error ("The TO argument to MOVE_ALLOC at %L shall not be "
- "coindexed", &to->where);
- return false;
- }
- if (from->ts.type == BT_CLASS && to->ts.type == BT_DERIVED)
- {
- gfc_error ("The TO arguments in MOVE_ALLOC at %L must be "
- "polymorphic if FROM is polymorphic",
- &to->where);
- return false;
- }
- if (!same_type_check (to, 1, from, 0))
- return false;
- if (to->rank != from->rank)
- {
- gfc_error ("The FROM and TO arguments of the MOVE_ALLOC intrinsic at %L "
- "must have the same rank %d/%d", &to->where, from->rank,
- to->rank);
- return false;
- }
- /* IR F08/0040; cf. 12-006A. */
- if (gfc_get_corank (to) != gfc_get_corank (from))
- {
- gfc_error ("The FROM and TO arguments of the MOVE_ALLOC intrinsic at %L "
- "must have the same corank %d/%d", &to->where,
- gfc_get_corank (from), gfc_get_corank (to));
- return false;
- }
- /* CLASS arguments: Make sure the vtab of from is present. */
- if (to->ts.type == BT_CLASS && !UNLIMITED_POLY (from))
- gfc_find_vtab (&from->ts);
- return true;
- }
- bool
- gfc_check_nearest (gfc_expr *x, gfc_expr *s)
- {
- if (!type_check (x, 0, BT_REAL))
- return false;
- if (!type_check (s, 1, BT_REAL))
- return false;
- if (s->expr_type == EXPR_CONSTANT)
- {
- if (mpfr_sgn (s->value.real) == 0)
- {
- gfc_error ("Argument %<S%> of NEAREST at %L shall not be zero",
- &s->where);
- return false;
- }
- }
- return true;
- }
- bool
- gfc_check_new_line (gfc_expr *a)
- {
- if (!type_check (a, 0, BT_CHARACTER))
- return false;
- return true;
- }
- bool
- gfc_check_norm2 (gfc_expr *array, gfc_expr *dim)
- {
- if (!type_check (array, 0, BT_REAL))
- return false;
- if (!array_check (array, 0))
- return false;
- if (!dim_rank_check (dim, array, false))
- return false;
- return true;
- }
- bool
- gfc_check_null (gfc_expr *mold)
- {
- symbol_attribute attr;
- if (mold == NULL)
- return true;
- if (!variable_check (mold, 0, true))
- return false;
- attr = gfc_variable_attr (mold, NULL);
- if (!attr.pointer && !attr.proc_pointer && !attr.allocatable)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L must be a POINTER, "
- "ALLOCATABLE or procedure pointer",
- gfc_current_intrinsic_arg[0]->name,
- gfc_current_intrinsic, &mold->where);
- return false;
- }
- if (attr.allocatable
- && !gfc_notify_std (GFC_STD_F2003, "NULL intrinsic with "
- "allocatable MOLD at %L", &mold->where))
- return false;
- /* F2008, C1242. */
- if (gfc_is_coindexed (mold))
- {
- gfc_error ("%qs argument of %qs intrinsic at %L shall not be "
- "coindexed", gfc_current_intrinsic_arg[0]->name,
- gfc_current_intrinsic, &mold->where);
- return false;
- }
- return true;
- }
- bool
- gfc_check_pack (gfc_expr *array, gfc_expr *mask, gfc_expr *vector)
- {
- if (!array_check (array, 0))
- return false;
- if (!type_check (mask, 1, BT_LOGICAL))
- return false;
- if (!gfc_check_conformance (array, mask,
- "arguments '%s' and '%s' for intrinsic '%s'",
- gfc_current_intrinsic_arg[0]->name,
- gfc_current_intrinsic_arg[1]->name,
- gfc_current_intrinsic))
- return false;
- if (vector != NULL)
- {
- mpz_t array_size, vector_size;
- bool have_array_size, have_vector_size;
- if (!same_type_check (array, 0, vector, 2))
- return false;
- if (!rank_check (vector, 2, 1))
- return false;
- /* VECTOR requires at least as many elements as MASK
- has .TRUE. values. */
- have_array_size = gfc_array_size(array, &array_size);
- have_vector_size = gfc_array_size(vector, &vector_size);
- if (have_vector_size
- && (mask->expr_type == EXPR_ARRAY
- || (mask->expr_type == EXPR_CONSTANT
- && have_array_size)))
- {
- int mask_true_values = 0;
- if (mask->expr_type == EXPR_ARRAY)
- {
- gfc_constructor *mask_ctor;
- mask_ctor = gfc_constructor_first (mask->value.constructor);
- while (mask_ctor)
- {
- if (mask_ctor->expr->expr_type != EXPR_CONSTANT)
- {
- mask_true_values = 0;
- break;
- }
- if (mask_ctor->expr->value.logical)
- mask_true_values++;
- mask_ctor = gfc_constructor_next (mask_ctor);
- }
- }
- else if (mask->expr_type == EXPR_CONSTANT && mask->value.logical)
- mask_true_values = mpz_get_si (array_size);
- if (mpz_get_si (vector_size) < mask_true_values)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L must "
- "provide at least as many elements as there "
- "are .TRUE. values in %qs (%ld/%d)",
- gfc_current_intrinsic_arg[2]->name,
- gfc_current_intrinsic, &vector->where,
- gfc_current_intrinsic_arg[1]->name,
- mpz_get_si (vector_size), mask_true_values);
- return false;
- }
- }
- if (have_array_size)
- mpz_clear (array_size);
- if (have_vector_size)
- mpz_clear (vector_size);
- }
- return true;
- }
- bool
- gfc_check_parity (gfc_expr *mask, gfc_expr *dim)
- {
- if (!type_check (mask, 0, BT_LOGICAL))
- return false;
- if (!array_check (mask, 0))
- return false;
- if (!dim_rank_check (dim, mask, false))
- return false;
- return true;
- }
- bool
- gfc_check_precision (gfc_expr *x)
- {
- if (!real_or_complex_check (x, 0))
- return false;
- return true;
- }
- bool
- gfc_check_present (gfc_expr *a)
- {
- gfc_symbol *sym;
- if (!variable_check (a, 0, true))
- return false;
- sym = a->symtree->n.sym;
- if (!sym->attr.dummy)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L must be of a "
- "dummy variable", gfc_current_intrinsic_arg[0]->name,
- gfc_current_intrinsic, &a->where);
- return false;
- }
- if (!sym->attr.optional)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L must be of "
- "an OPTIONAL dummy variable",
- gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
- &a->where);
- return false;
- }
- /* 13.14.82 PRESENT(A)
- ......
- Argument. A shall be the name of an optional dummy argument that is
- accessible in the subprogram in which the PRESENT function reference
- appears... */
- if (a->ref != NULL
- && !(a->ref->next == NULL && a->ref->type == REF_ARRAY
- && (a->ref->u.ar.type == AR_FULL
- || (a->ref->u.ar.type == AR_ELEMENT
- && a->ref->u.ar.as->rank == 0))))
- {
- gfc_error ("%qs argument of %qs intrinsic at %L must not be a "
- "subobject of %qs", gfc_current_intrinsic_arg[0]->name,
- gfc_current_intrinsic, &a->where, sym->name);
- return false;
- }
- return true;
- }
- bool
- gfc_check_radix (gfc_expr *x)
- {
- if (!int_or_real_check (x, 0))
- return false;
- return true;
- }
- bool
- gfc_check_range (gfc_expr *x)
- {
- if (!numeric_check (x, 0))
- return false;
- return true;
- }
- bool
- gfc_check_rank (gfc_expr *a ATTRIBUTE_UNUSED)
- {
- /* Any data object is allowed; a "data object" is a "constant (4.1.3),
- variable (6), or subobject of a constant (2.4.3.2.3)" (F2008, 1.3.45). */
- bool is_variable = true;
- /* Functions returning pointers are regarded as variable, cf. F2008, R602. */
- if (a->expr_type == EXPR_FUNCTION)
- is_variable = a->value.function.esym
- ? a->value.function.esym->result->attr.pointer
- : a->symtree->n.sym->result->attr.pointer;
- if (a->expr_type == EXPR_OP || a->expr_type == EXPR_NULL
- || a->expr_type == EXPR_COMPCALL|| a->expr_type == EXPR_PPC
- || !is_variable)
- {
- gfc_error ("The argument of the RANK intrinsic at %L must be a data "
- "object", &a->where);
- return false;
- }
- return true;
- }
- /* real, float, sngl. */
- bool
- gfc_check_real (gfc_expr *a, gfc_expr *kind)
- {
- if (!numeric_check (a, 0))
- return false;
- if (!kind_check (kind, 1, BT_REAL))
- return false;
- return true;
- }
- bool
- gfc_check_rename (gfc_expr *path1, gfc_expr *path2)
- {
- if (!type_check (path1, 0, BT_CHARACTER))
- return false;
- if (!kind_value_check (path1, 0, gfc_default_character_kind))
- return false;
- if (!type_check (path2, 1, BT_CHARACTER))
- return false;
- if (!kind_value_check (path2, 1, gfc_default_character_kind))
- return false;
- return true;
- }
- bool
- gfc_check_rename_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
- {
- if (!type_check (path1, 0, BT_CHARACTER))
- return false;
- if (!kind_value_check (path1, 0, gfc_default_character_kind))
- return false;
- if (!type_check (path2, 1, BT_CHARACTER))
- return false;
- if (!kind_value_check (path2, 1, gfc_default_character_kind))
- return false;
- if (status == NULL)
- return true;
- if (!type_check (status, 2, BT_INTEGER))
- return false;
- if (!scalar_check (status, 2))
- return false;
- return true;
- }
- bool
- gfc_check_repeat (gfc_expr *x, gfc_expr *y)
- {
- if (!type_check (x, 0, BT_CHARACTER))
- return false;
- if (!scalar_check (x, 0))
- return false;
- if (!type_check (y, 0, BT_INTEGER))
- return false;
- if (!scalar_check (y, 1))
- return false;
- return true;
- }
- bool
- gfc_check_reshape (gfc_expr *source, gfc_expr *shape,
- gfc_expr *pad, gfc_expr *order)
- {
- mpz_t size;
- mpz_t nelems;
- int shape_size;
- if (!array_check (source, 0))
- return false;
- if (!rank_check (shape, 1, 1))
- return false;
- if (!type_check (shape, 1, BT_INTEGER))
- return false;
- if (!gfc_array_size (shape, &size))
- {
- gfc_error ("%<shape%> argument of %<reshape%> intrinsic at %L must be an "
- "array of constant size", &shape->where);
- return false;
- }
- shape_size = mpz_get_ui (size);
- mpz_clear (size);
- if (shape_size <= 0)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L is empty",
- gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
- &shape->where);
- return false;
- }
- else if (shape_size > GFC_MAX_DIMENSIONS)
- {
- gfc_error ("%<shape%> argument of %<reshape%> intrinsic at %L has more "
- "than %d elements", &shape->where, GFC_MAX_DIMENSIONS);
- return false;
- }
- else if (shape->expr_type == EXPR_ARRAY && gfc_is_constant_expr (shape))
- {
- gfc_expr *e;
- int i, extent;
- for (i = 0; i < shape_size; ++i)
- {
- e = gfc_constructor_lookup_expr (shape->value.constructor, i);
- if (e->expr_type != EXPR_CONSTANT)
- continue;
- gfc_extract_int (e, &extent);
- if (extent < 0)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L has "
- "negative element (%d)",
- gfc_current_intrinsic_arg[1]->name,
- gfc_current_intrinsic, &e->where, extent);
- return false;
- }
- }
- }
- if (pad != NULL)
- {
- if (!same_type_check (source, 0, pad, 2))
- return false;
- if (!array_check (pad, 2))
- return false;
- }
- if (order != NULL)
- {
- if (!array_check (order, 3))
- return false;
- if (!type_check (order, 3, BT_INTEGER))
- return false;
- if (order->expr_type == EXPR_ARRAY)
- {
- int i, order_size, dim, perm[GFC_MAX_DIMENSIONS];
- gfc_expr *e;
- for (i = 0; i < GFC_MAX_DIMENSIONS; ++i)
- perm[i] = 0;
- gfc_array_size (order, &size);
- order_size = mpz_get_ui (size);
- mpz_clear (size);
- if (order_size != shape_size)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L "
- "has wrong number of elements (%d/%d)",
- gfc_current_intrinsic_arg[3]->name,
- gfc_current_intrinsic, &order->where,
- order_size, shape_size);
- return false;
- }
- for (i = 1; i <= order_size; ++i)
- {
- e = gfc_constructor_lookup_expr (order->value.constructor, i-1);
- if (e->expr_type != EXPR_CONSTANT)
- continue;
- gfc_extract_int (e, &dim);
- if (dim < 1 || dim > order_size)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L "
- "has out-of-range dimension (%d)",
- gfc_current_intrinsic_arg[3]->name,
- gfc_current_intrinsic, &e->where, dim);
- return false;
- }
- if (perm[dim-1] != 0)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L has "
- "invalid permutation of dimensions (dimension "
- "%<%d%> duplicated)",
- gfc_current_intrinsic_arg[3]->name,
- gfc_current_intrinsic, &e->where, dim);
- return false;
- }
- perm[dim-1] = 1;
- }
- }
- }
- if (pad == NULL && shape->expr_type == EXPR_ARRAY
- && gfc_is_constant_expr (shape)
- && !(source->expr_type == EXPR_VARIABLE && source->symtree->n.sym->as
- && source->symtree->n.sym->as->type == AS_ASSUMED_SIZE))
- {
- /* Check the match in size between source and destination. */
- if (gfc_array_size (source, &nelems))
- {
- gfc_constructor *c;
- bool test;
- mpz_init_set_ui (size, 1);
- for (c = gfc_constructor_first (shape->value.constructor);
- c; c = gfc_constructor_next (c))
- mpz_mul (size, size, c->expr->value.integer);
- test = mpz_cmp (nelems, size) < 0 && mpz_cmp_ui (size, 0) > 0;
- mpz_clear (nelems);
- mpz_clear (size);
- if (test)
- {
- gfc_error ("Without padding, there are not enough elements "
- "in the intrinsic RESHAPE source at %L to match "
- "the shape", &source->where);
- return false;
- }
- }
- }
- return true;
- }
- bool
- gfc_check_same_type_as (gfc_expr *a, gfc_expr *b)
- {
- if (a->ts.type != BT_DERIVED && a->ts.type != BT_CLASS)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L "
- "cannot be of type %s",
- gfc_current_intrinsic_arg[0]->name,
- gfc_current_intrinsic,
- &a->where, gfc_typename (&a->ts));
- return false;
- }
- if (!(gfc_type_is_extensible (a->ts.u.derived) || UNLIMITED_POLY (a)))
- {
- gfc_error ("%qs argument of %qs intrinsic at %L "
- "must be of an extensible type",
- gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
- &a->where);
- return false;
- }
- if (b->ts.type != BT_DERIVED && b->ts.type != BT_CLASS)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L "
- "cannot be of type %s",
- gfc_current_intrinsic_arg[0]->name,
- gfc_current_intrinsic,
- &b->where, gfc_typename (&b->ts));
- return false;
- }
- if (!(gfc_type_is_extensible (b->ts.u.derived) || UNLIMITED_POLY (b)))
- {
- gfc_error ("%qs argument of %qs intrinsic at %L "
- "must be of an extensible type",
- gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
- &b->where);
- return false;
- }
- return true;
- }
- bool
- gfc_check_scale (gfc_expr *x, gfc_expr *i)
- {
- if (!type_check (x, 0, BT_REAL))
- return false;
- if (!type_check (i, 1, BT_INTEGER))
- return false;
- return true;
- }
- bool
- gfc_check_scan (gfc_expr *x, gfc_expr *y, gfc_expr *z, gfc_expr *kind)
- {
- if (!type_check (x, 0, BT_CHARACTER))
- return false;
- if (!type_check (y, 1, BT_CHARACTER))
- return false;
- if (z != NULL && !type_check (z, 2, BT_LOGICAL))
- return false;
- if (!kind_check (kind, 3, BT_INTEGER))
- return false;
- if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
- "with KIND argument at %L",
- gfc_current_intrinsic, &kind->where))
- return false;
- if (!same_type_check (x, 0, y, 1))
- return false;
- return true;
- }
- bool
- gfc_check_secnds (gfc_expr *r)
- {
- if (!type_check (r, 0, BT_REAL))
- return false;
- if (!kind_value_check (r, 0, 4))
- return false;
- if (!scalar_check (r, 0))
- return false;
- return true;
- }
- bool
- gfc_check_selected_char_kind (gfc_expr *name)
- {
- if (!type_check (name, 0, BT_CHARACTER))
- return false;
- if (!kind_value_check (name, 0, gfc_default_character_kind))
- return false;
- if (!scalar_check (name, 0))
- return false;
- return true;
- }
- bool
- gfc_check_selected_int_kind (gfc_expr *r)
- {
- if (!type_check (r, 0, BT_INTEGER))
- return false;
- if (!scalar_check (r, 0))
- return false;
- return true;
- }
- bool
- gfc_check_selected_real_kind (gfc_expr *p, gfc_expr *r, gfc_expr *radix)
- {
- if (p == NULL && r == NULL
- && !gfc_notify_std (GFC_STD_F2008, "SELECTED_REAL_KIND with"
- " neither %<P%> nor %<R%> argument at %L",
- gfc_current_intrinsic_where))
- return false;
- if (p)
- {
- if (!type_check (p, 0, BT_INTEGER))
- return false;
- if (!scalar_check (p, 0))
- return false;
- }
- if (r)
- {
- if (!type_check (r, 1, BT_INTEGER))
- return false;
- if (!scalar_check (r, 1))
- return false;
- }
- if (radix)
- {
- if (!type_check (radix, 1, BT_INTEGER))
- return false;
- if (!scalar_check (radix, 1))
- return false;
- if (!gfc_notify_std (GFC_STD_F2008, "%qs intrinsic with "
- "RADIX argument at %L", gfc_current_intrinsic,
- &radix->where))
- return false;
- }
- return true;
- }
- bool
- gfc_check_set_exponent (gfc_expr *x, gfc_expr *i)
- {
- if (!type_check (x, 0, BT_REAL))
- return false;
- if (!type_check (i, 1, BT_INTEGER))
- return false;
- return true;
- }
- bool
- gfc_check_shape (gfc_expr *source, gfc_expr *kind)
- {
- gfc_array_ref *ar;
- if (source->rank == 0 || source->expr_type != EXPR_VARIABLE)
- return true;
- ar = gfc_find_array_ref (source);
- if (ar->as && ar->as->type == AS_ASSUMED_SIZE && ar->type == AR_FULL)
- {
- gfc_error ("%<source%> argument of %<shape%> intrinsic at %L must not be "
- "an assumed size array", &source->where);
- return false;
- }
- if (!kind_check (kind, 1, BT_INTEGER))
- return false;
- if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
- "with KIND argument at %L",
- gfc_current_intrinsic, &kind->where))
- return false;
- return true;
- }
- bool
- gfc_check_shift (gfc_expr *i, gfc_expr *shift)
- {
- if (!type_check (i, 0, BT_INTEGER))
- return false;
- if (!type_check (shift, 0, BT_INTEGER))
- return false;
- if (!nonnegative_check ("SHIFT", shift))
- return false;
- if (!less_than_bitsize1 ("I", i, "SHIFT", shift, true))
- return false;
- return true;
- }
- bool
- gfc_check_sign (gfc_expr *a, gfc_expr *b)
- {
- if (!int_or_real_check (a, 0))
- return false;
- if (!same_type_check (a, 0, b, 1))
- return false;
- return true;
- }
- bool
- gfc_check_size (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
- {
- if (!array_check (array, 0))
- return false;
- if (!dim_check (dim, 1, true))
- return false;
- if (!dim_rank_check (dim, array, 0))
- return false;
- if (!kind_check (kind, 2, BT_INTEGER))
- return false;
- if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
- "with KIND argument at %L",
- gfc_current_intrinsic, &kind->where))
- return false;
- return true;
- }
- bool
- gfc_check_sizeof (gfc_expr *arg)
- {
- if (arg->ts.type == BT_PROCEDURE)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L shall not be a procedure",
- gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
- &arg->where);
- return false;
- }
- /* TYPE(*) is acceptable if and only if it uses an array descriptor. */
- if (arg->ts.type == BT_ASSUMED
- && (arg->symtree->n.sym->as == NULL
- || (arg->symtree->n.sym->as->type != AS_ASSUMED_SHAPE
- && arg->symtree->n.sym->as->type != AS_DEFERRED
- && arg->symtree->n.sym->as->type != AS_ASSUMED_RANK)))
- {
- gfc_error ("%qs argument of %qs intrinsic at %L shall not be TYPE(*)",
- gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
- &arg->where);
- return false;
- }
- if (arg->rank && arg->expr_type == EXPR_VARIABLE
- && arg->symtree->n.sym->as != NULL
- && arg->symtree->n.sym->as->type == AS_ASSUMED_SIZE && arg->ref
- && arg->ref->type == REF_ARRAY && arg->ref->u.ar.type == AR_FULL)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L shall not be an "
- "assumed-size array", gfc_current_intrinsic_arg[0]->name,
- gfc_current_intrinsic, &arg->where);
- return false;
- }
- return true;
- }
- /* Check whether an expression is interoperable. When returning false,
- msg is set to a string telling why the expression is not interoperable,
- otherwise, it is set to NULL. The msg string can be used in diagnostics.
- If c_loc is true, character with len > 1 are allowed (cf. Fortran
- 2003corr5); additionally, assumed-shape/assumed-rank/deferred-shape
- arrays are permitted. And if c_f_ptr is true, deferred-shape arrays
- are permitted. */
- static bool
- is_c_interoperable (gfc_expr *expr, const char **msg, bool c_loc, bool c_f_ptr)
- {
- *msg = NULL;
- if (expr->ts.type == BT_CLASS)
- {
- *msg = "Expression is polymorphic";
- return false;
- }
- if (expr->ts.type == BT_DERIVED && !expr->ts.u.derived->attr.is_bind_c
- && !expr->ts.u.derived->ts.is_iso_c)
- {
- *msg = "Expression is a noninteroperable derived type";
- return false;
- }
- if (expr->ts.type == BT_PROCEDURE)
- {
- *msg = "Procedure unexpected as argument";
- return false;
- }
- if (gfc_notification_std (GFC_STD_GNU) && expr->ts.type == BT_LOGICAL)
- {
- int i;
- for (i = 0; gfc_logical_kinds[i].kind; i++)
- if (gfc_logical_kinds[i].kind == expr->ts.kind)
- return true;
- *msg = "Extension to use a non-C_Bool-kind LOGICAL";
- return false;
- }
- if (gfc_notification_std (GFC_STD_GNU) && expr->ts.type == BT_CHARACTER
- && expr->ts.kind != 1)
- {
- *msg = "Extension to use a non-C_CHAR-kind CHARACTER";
- return false;
- }
- if (expr->ts.type == BT_CHARACTER) {
- if (expr->ts.deferred)
- {
- /* TS 29113 allows deferred-length strings as dummy arguments,
- but it is not an interoperable type. */
- *msg = "Expression shall not be a deferred-length string";
- return false;
- }
- if (expr->ts.u.cl && expr->ts.u.cl->length
- && !gfc_simplify_expr (expr, 0))
- gfc_internal_error ("is_c_interoperable(): gfc_simplify_expr failed");
- if (!c_loc && expr->ts.u.cl
- && (!expr->ts.u.cl->length
- || expr->ts.u.cl->length->expr_type != EXPR_CONSTANT
- || mpz_cmp_si (expr->ts.u.cl->length->value.integer, 1) != 0))
- {
- *msg = "Type shall have a character length of 1";
- return false;
- }
- }
- /* Note: The following checks are about interoperatable variables, Fortran
- 15.3.5/15.3.6. In intrinsics like C_LOC or in procedure interface, more
- is allowed, e.g. assumed-shape arrays with TS 29113. */
- if (gfc_is_coarray (expr))
- {
- *msg = "Coarrays are not interoperable";
- return false;
- }
- if (!c_loc && expr->rank > 0 && expr->expr_type != EXPR_ARRAY)
- {
- gfc_array_ref *ar = gfc_find_array_ref (expr);
- if (ar->type != AR_FULL)
- {
- *msg = "Only whole-arrays are interoperable";
- return false;
- }
- if (!c_f_ptr && ar->as->type != AS_EXPLICIT
- && ar->as->type != AS_ASSUMED_SIZE)
- {
- *msg = "Only explicit-size and assumed-size arrays are interoperable";
- return false;
- }
- }
- return true;
- }
- bool
- gfc_check_c_sizeof (gfc_expr *arg)
- {
- const char *msg;
- if (!is_c_interoperable (arg, &msg, false, false))
- {
- gfc_error ("%qs argument of %qs intrinsic at %L must be an "
- "interoperable data entity: %s",
- gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
- &arg->where, msg);
- return false;
- }
- if (arg->ts.type == BT_ASSUMED)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L shall not be "
- "TYPE(*)",
- gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
- &arg->where);
- return false;
- }
- if (arg->rank && arg->expr_type == EXPR_VARIABLE
- && arg->symtree->n.sym->as != NULL
- && arg->symtree->n.sym->as->type == AS_ASSUMED_SIZE && arg->ref
- && arg->ref->type == REF_ARRAY && arg->ref->u.ar.type == AR_FULL)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L shall not be an "
- "assumed-size array", gfc_current_intrinsic_arg[0]->name,
- gfc_current_intrinsic, &arg->where);
- return false;
- }
- return true;
- }
- bool
- gfc_check_c_associated (gfc_expr *c_ptr_1, gfc_expr *c_ptr_2)
- {
- if (c_ptr_1->ts.type != BT_DERIVED
- || c_ptr_1->ts.u.derived->from_intmod != INTMOD_ISO_C_BINDING
- || (c_ptr_1->ts.u.derived->intmod_sym_id != ISOCBINDING_PTR
- && c_ptr_1->ts.u.derived->intmod_sym_id != ISOCBINDING_FUNPTR))
- {
- gfc_error ("Argument C_PTR_1 at %L to C_ASSOCIATED shall have the "
- "type TYPE(C_PTR) or TYPE(C_FUNPTR)", &c_ptr_1->where);
- return false;
- }
- if (!scalar_check (c_ptr_1, 0))
- return false;
- if (c_ptr_2
- && (c_ptr_2->ts.type != BT_DERIVED
- || c_ptr_2->ts.u.derived->from_intmod != INTMOD_ISO_C_BINDING
- || (c_ptr_1->ts.u.derived->intmod_sym_id
- != c_ptr_2->ts.u.derived->intmod_sym_id)))
- {
- gfc_error ("Argument C_PTR_2 at %L to C_ASSOCIATED shall have the "
- "same type as C_PTR_1: %s instead of %s", &c_ptr_1->where,
- gfc_typename (&c_ptr_1->ts),
- gfc_typename (&c_ptr_2->ts));
- return false;
- }
- if (c_ptr_2 && !scalar_check (c_ptr_2, 1))
- return false;
- return true;
- }
- bool
- gfc_check_c_f_pointer (gfc_expr *cptr, gfc_expr *fptr, gfc_expr *shape)
- {
- symbol_attribute attr;
- const char *msg;
- if (cptr->ts.type != BT_DERIVED
- || cptr->ts.u.derived->from_intmod != INTMOD_ISO_C_BINDING
- || cptr->ts.u.derived->intmod_sym_id != ISOCBINDING_PTR)
- {
- gfc_error ("Argument CPTR at %L to C_F_POINTER shall have the "
- "type TYPE(C_PTR)", &cptr->where);
- return false;
- }
- if (!scalar_check (cptr, 0))
- return false;
- attr = gfc_expr_attr (fptr);
- if (!attr.pointer)
- {
- gfc_error ("Argument FPTR at %L to C_F_POINTER must be a pointer",
- &fptr->where);
- return false;
- }
- if (fptr->ts.type == BT_CLASS)
- {
- gfc_error ("FPTR argument at %L to C_F_POINTER shall not be polymorphic",
- &fptr->where);
- return false;
- }
- if (gfc_is_coindexed (fptr))
- {
- gfc_error ("Argument FPTR at %L to C_F_POINTER shall not be "
- "coindexed", &fptr->where);
- return false;
- }
- if (fptr->rank == 0 && shape)
- {
- gfc_error ("Unexpected SHAPE argument at %L to C_F_POINTER with scalar "
- "FPTR", &fptr->where);
- return false;
- }
- else if (fptr->rank && !shape)
- {
- gfc_error ("Expected SHAPE argument to C_F_POINTER with array "
- "FPTR at %L", &fptr->where);
- return false;
- }
- if (shape && !rank_check (shape, 2, 1))
- return false;
- if (shape && !type_check (shape, 2, BT_INTEGER))
- return false;
- if (shape)
- {
- mpz_t size;
- if (gfc_array_size (shape, &size))
- {
- if (mpz_cmp_ui (size, fptr->rank) != 0)
- {
- mpz_clear (size);
- gfc_error ("SHAPE argument at %L to C_F_POINTER must have the same "
- "size as the RANK of FPTR", &shape->where);
- return false;
- }
- mpz_clear (size);
- }
- }
- if (fptr->ts.type == BT_CLASS)
- {
- gfc_error ("Polymorphic FPTR at %L to C_F_POINTER", &fptr->where);
- return false;
- }
- if (!is_c_interoperable (fptr, &msg, false, true))
- return gfc_notify_std (GFC_STD_F2008_TS, "Noninteroperable array FPTR "
- "at %L to C_F_POINTER: %s", &fptr->where, msg);
- return true;
- }
- bool
- gfc_check_c_f_procpointer (gfc_expr *cptr, gfc_expr *fptr)
- {
- symbol_attribute attr;
- if (cptr->ts.type != BT_DERIVED
- || cptr->ts.u.derived->from_intmod != INTMOD_ISO_C_BINDING
- || cptr->ts.u.derived->intmod_sym_id != ISOCBINDING_FUNPTR)
- {
- gfc_error ("Argument CPTR at %L to C_F_PROCPOINTER shall have the "
- "type TYPE(C_FUNPTR)", &cptr->where);
- return false;
- }
- if (!scalar_check (cptr, 0))
- return false;
- attr = gfc_expr_attr (fptr);
- if (!attr.proc_pointer)
- {
- gfc_error ("Argument FPTR at %L to C_F_PROCPOINTER shall be a procedure "
- "pointer", &fptr->where);
- return false;
- }
- if (gfc_is_coindexed (fptr))
- {
- gfc_error ("Argument FPTR at %L to C_F_PROCPOINTER shall not be "
- "coindexed", &fptr->where);
- return false;
- }
- if (!attr.is_bind_c)
- return gfc_notify_std (GFC_STD_F2008_TS, "Noninteroperable procedure "
- "pointer at %L to C_F_PROCPOINTER", &fptr->where);
- return true;
- }
- bool
- gfc_check_c_funloc (gfc_expr *x)
- {
- symbol_attribute attr;
- if (gfc_is_coindexed (x))
- {
- gfc_error ("Argument X at %L to C_FUNLOC shall not be "
- "coindexed", &x->where);
- return false;
- }
- attr = gfc_expr_attr (x);
- if (attr.function && !attr.proc_pointer && x->expr_type == EXPR_VARIABLE
- && x->symtree->n.sym == x->symtree->n.sym->result)
- {
- gfc_namespace *ns = gfc_current_ns;
- for (ns = gfc_current_ns; ns; ns = ns->parent)
- if (x->symtree->n.sym == ns->proc_name)
- {
- gfc_error ("Function result %qs at %L is invalid as X argument "
- "to C_FUNLOC", x->symtree->n.sym->name, &x->where);
- return false;
- }
- }
- if (attr.flavor != FL_PROCEDURE)
- {
- gfc_error ("Argument X at %L to C_FUNLOC shall be a procedure "
- "or a procedure pointer", &x->where);
- return false;
- }
- if (!attr.is_bind_c)
- return gfc_notify_std (GFC_STD_F2008_TS, "Noninteroperable procedure "
- "at %L to C_FUNLOC", &x->where);
- return true;
- }
- bool
- gfc_check_c_loc (gfc_expr *x)
- {
- symbol_attribute attr;
- const char *msg;
- if (gfc_is_coindexed (x))
- {
- gfc_error ("Argument X at %L to C_LOC shall not be coindexed", &x->where);
- return false;
- }
- if (x->ts.type == BT_CLASS)
- {
- gfc_error ("X argument at %L to C_LOC shall not be polymorphic",
- &x->where);
- return false;
- }
- attr = gfc_expr_attr (x);
- if (!attr.pointer
- && (x->expr_type != EXPR_VARIABLE || !attr.target
- || attr.flavor == FL_PARAMETER))
- {
- gfc_error ("Argument X at %L to C_LOC shall have either "
- "the POINTER or the TARGET attribute", &x->where);
- return false;
- }
- if (x->ts.type == BT_CHARACTER
- && gfc_var_strlen (x) == 0)
- {
- gfc_error ("Argument X at %L to C_LOC shall be not be a zero-sized "
- "string", &x->where);
- return false;
- }
- if (!is_c_interoperable (x, &msg, true, false))
- {
- if (x->ts.type == BT_CLASS)
- {
- gfc_error ("Argument at %L to C_LOC shall not be polymorphic",
- &x->where);
- return false;
- }
-
- if (x->rank
- && !gfc_notify_std (GFC_STD_F2008_TS,
- "Noninteroperable array at %L as"
- " argument to C_LOC: %s", &x->where, msg))
- return false;
- }
- else if (x->rank > 0 && gfc_notification_std (GFC_STD_F2008))
- {
- gfc_array_ref *ar = gfc_find_array_ref (x);
- if (ar->as->type != AS_EXPLICIT && ar->as->type != AS_ASSUMED_SIZE
- && !attr.allocatable
- && !gfc_notify_std (GFC_STD_F2008,
- "Array of interoperable type at %L "
- "to C_LOC which is nonallocatable and neither "
- "assumed size nor explicit size", &x->where))
- return false;
- else if (ar->type != AR_FULL
- && !gfc_notify_std (GFC_STD_F2008, "Array section at %L "
- "to C_LOC", &x->where))
- return false;
- }
- return true;
- }
- bool
- gfc_check_sleep_sub (gfc_expr *seconds)
- {
- if (!type_check (seconds, 0, BT_INTEGER))
- return false;
- if (!scalar_check (seconds, 0))
- return false;
- return true;
- }
- bool
- gfc_check_sngl (gfc_expr *a)
- {
- if (!type_check (a, 0, BT_REAL))
- return false;
- if ((a->ts.kind != gfc_default_double_kind)
- && !gfc_notify_std (GFC_STD_GNU, "non double precision "
- "REAL argument to %s intrinsic at %L",
- gfc_current_intrinsic, &a->where))
- return false;
- return true;
- }
- bool
- gfc_check_spread (gfc_expr *source, gfc_expr *dim, gfc_expr *ncopies)
- {
- if (source->rank >= GFC_MAX_DIMENSIONS)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L must be less "
- "than rank %d", gfc_current_intrinsic_arg[0]->name,
- gfc_current_intrinsic, &source->where, GFC_MAX_DIMENSIONS);
- return false;
- }
- if (dim == NULL)
- return false;
- if (!dim_check (dim, 1, false))
- return false;
- /* dim_rank_check() does not apply here. */
- if (dim
- && dim->expr_type == EXPR_CONSTANT
- && (mpz_cmp_ui (dim->value.integer, 1) < 0
- || mpz_cmp_ui (dim->value.integer, source->rank + 1) > 0))
- {
- gfc_error ("%qs argument of %qs intrinsic at %L is not a valid "
- "dimension index", gfc_current_intrinsic_arg[1]->name,
- gfc_current_intrinsic, &dim->where);
- return false;
- }
- if (!type_check (ncopies, 2, BT_INTEGER))
- return false;
- if (!scalar_check (ncopies, 2))
- return false;
- return true;
- }
- /* Functions for checking FGETC, FPUTC, FGET and FPUT (subroutines and
- functions). */
- bool
- gfc_check_fgetputc_sub (gfc_expr *unit, gfc_expr *c, gfc_expr *status)
- {
- if (!type_check (unit, 0, BT_INTEGER))
- return false;
- if (!scalar_check (unit, 0))
- return false;
- if (!type_check (c, 1, BT_CHARACTER))
- return false;
- if (!kind_value_check (c, 1, gfc_default_character_kind))
- return false;
- if (status == NULL)
- return true;
- if (!type_check (status, 2, BT_INTEGER)
- || !kind_value_check (status, 2, gfc_default_integer_kind)
- || !scalar_check (status, 2))
- return false;
- return true;
- }
- bool
- gfc_check_fgetputc (gfc_expr *unit, gfc_expr *c)
- {
- return gfc_check_fgetputc_sub (unit, c, NULL);
- }
- bool
- gfc_check_fgetput_sub (gfc_expr *c, gfc_expr *status)
- {
- if (!type_check (c, 0, BT_CHARACTER))
- return false;
- if (!kind_value_check (c, 0, gfc_default_character_kind))
- return false;
- if (status == NULL)
- return true;
- if (!type_check (status, 1, BT_INTEGER)
- || !kind_value_check (status, 1, gfc_default_integer_kind)
- || !scalar_check (status, 1))
- return false;
- return true;
- }
- bool
- gfc_check_fgetput (gfc_expr *c)
- {
- return gfc_check_fgetput_sub (c, NULL);
- }
- bool
- gfc_check_fseek_sub (gfc_expr *unit, gfc_expr *offset, gfc_expr *whence, gfc_expr *status)
- {
- if (!type_check (unit, 0, BT_INTEGER))
- return false;
- if (!scalar_check (unit, 0))
- return false;
- if (!type_check (offset, 1, BT_INTEGER))
- return false;
- if (!scalar_check (offset, 1))
- return false;
- if (!type_check (whence, 2, BT_INTEGER))
- return false;
- if (!scalar_check (whence, 2))
- return false;
- if (status == NULL)
- return true;
- if (!type_check (status, 3, BT_INTEGER))
- return false;
- if (!kind_value_check (status, 3, 4))
- return false;
- if (!scalar_check (status, 3))
- return false;
- return true;
- }
- bool
- gfc_check_fstat (gfc_expr *unit, gfc_expr *array)
- {
- if (!type_check (unit, 0, BT_INTEGER))
- return false;
- if (!scalar_check (unit, 0))
- return false;
- if (!type_check (array, 1, BT_INTEGER)
- || !kind_value_check (unit, 0, gfc_default_integer_kind))
- return false;
- if (!array_check (array, 1))
- return false;
- return true;
- }
- bool
- gfc_check_fstat_sub (gfc_expr *unit, gfc_expr *array, gfc_expr *status)
- {
- if (!type_check (unit, 0, BT_INTEGER))
- return false;
- if (!scalar_check (unit, 0))
- return false;
- if (!type_check (array, 1, BT_INTEGER)
- || !kind_value_check (array, 1, gfc_default_integer_kind))
- return false;
- if (!array_check (array, 1))
- return false;
- if (status == NULL)
- return true;
- if (!type_check (status, 2, BT_INTEGER)
- || !kind_value_check (status, 2, gfc_default_integer_kind))
- return false;
- if (!scalar_check (status, 2))
- return false;
- return true;
- }
- bool
- gfc_check_ftell (gfc_expr *unit)
- {
- if (!type_check (unit, 0, BT_INTEGER))
- return false;
- if (!scalar_check (unit, 0))
- return false;
- return true;
- }
- bool
- gfc_check_ftell_sub (gfc_expr *unit, gfc_expr *offset)
- {
- if (!type_check (unit, 0, BT_INTEGER))
- return false;
- if (!scalar_check (unit, 0))
- return false;
- if (!type_check (offset, 1, BT_INTEGER))
- return false;
- if (!scalar_check (offset, 1))
- return false;
- return true;
- }
- bool
- gfc_check_stat (gfc_expr *name, gfc_expr *array)
- {
- if (!type_check (name, 0, BT_CHARACTER))
- return false;
- if (!kind_value_check (name, 0, gfc_default_character_kind))
- return false;
- if (!type_check (array, 1, BT_INTEGER)
- || !kind_value_check (array, 1, gfc_default_integer_kind))
- return false;
- if (!array_check (array, 1))
- return false;
- return true;
- }
- bool
- gfc_check_stat_sub (gfc_expr *name, gfc_expr *array, gfc_expr *status)
- {
- if (!type_check (name, 0, BT_CHARACTER))
- return false;
- if (!kind_value_check (name, 0, gfc_default_character_kind))
- return false;
- if (!type_check (array, 1, BT_INTEGER)
- || !kind_value_check (array, 1, gfc_default_integer_kind))
- return false;
- if (!array_check (array, 1))
- return false;
- if (status == NULL)
- return true;
- if (!type_check (status, 2, BT_INTEGER)
- || !kind_value_check (array, 1, gfc_default_integer_kind))
- return false;
- if (!scalar_check (status, 2))
- return false;
- return true;
- }
- bool
- gfc_check_image_index (gfc_expr *coarray, gfc_expr *sub)
- {
- mpz_t nelems;
- if (flag_coarray == GFC_FCOARRAY_NONE)
- {
- gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
- return false;
- }
- if (!coarray_check (coarray, 0))
- return false;
- if (sub->rank != 1)
- {
- gfc_error ("%s argument to IMAGE_INDEX must be a rank one array at %L",
- gfc_current_intrinsic_arg[1]->name, &sub->where);
- return false;
- }
- if (gfc_array_size (sub, &nelems))
- {
- int corank = gfc_get_corank (coarray);
- if (mpz_cmp_ui (nelems, corank) != 0)
- {
- gfc_error ("The number of array elements of the SUB argument to "
- "IMAGE_INDEX at %L shall be %d (corank) not %d",
- &sub->where, corank, (int) mpz_get_si (nelems));
- mpz_clear (nelems);
- return false;
- }
- mpz_clear (nelems);
- }
- return true;
- }
- bool
- gfc_check_num_images (gfc_expr *distance, gfc_expr *failed)
- {
- if (flag_coarray == GFC_FCOARRAY_NONE)
- {
- gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
- return false;
- }
- if (distance)
- {
- if (!type_check (distance, 0, BT_INTEGER))
- return false;
- if (!nonnegative_check ("DISTANCE", distance))
- return false;
- if (!scalar_check (distance, 0))
- return false;
- if (!gfc_notify_std (GFC_STD_F2008_TS, "DISTANCE= argument to "
- "NUM_IMAGES at %L", &distance->where))
- return false;
- }
- if (failed)
- {
- if (!type_check (failed, 1, BT_LOGICAL))
- return false;
- if (!scalar_check (failed, 1))
- return false;
- if (!gfc_notify_std (GFC_STD_F2008_TS, "FAILED= argument to "
- "NUM_IMAGES at %L", &distance->where))
- return false;
- }
- return true;
- }
- bool
- gfc_check_this_image (gfc_expr *coarray, gfc_expr *dim, gfc_expr *distance)
- {
- if (flag_coarray == GFC_FCOARRAY_NONE)
- {
- gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
- return false;
- }
- if (coarray == NULL && dim == NULL && distance == NULL)
- return true;
- if (dim != NULL && coarray == NULL)
- {
- gfc_error ("DIM argument without COARRAY argument not allowed for "
- "THIS_IMAGE intrinsic at %L", &dim->where);
- return false;
- }
- if (distance && (coarray || dim))
- {
- gfc_error ("The DISTANCE argument may not be specified together with the "
- "COARRAY or DIM argument in intrinsic at %L",
- &distance->where);
- return false;
- }
- /* Assume that we have "this_image (distance)". */
- if (coarray && !gfc_is_coarray (coarray) && coarray->ts.type == BT_INTEGER)
- {
- if (dim)
- {
- gfc_error ("Unexpected DIM argument with noncoarray argument at %L",
- &coarray->where);
- return false;
- }
- distance = coarray;
- }
- if (distance)
- {
- if (!type_check (distance, 2, BT_INTEGER))
- return false;
- if (!nonnegative_check ("DISTANCE", distance))
- return false;
- if (!scalar_check (distance, 2))
- return false;
- if (!gfc_notify_std (GFC_STD_F2008_TS, "DISTANCE= argument to "
- "THIS_IMAGE at %L", &distance->where))
- return false;
- return true;
- }
- if (!coarray_check (coarray, 0))
- return false;
- if (dim != NULL)
- {
- if (!dim_check (dim, 1, false))
- return false;
- if (!dim_corank_check (dim, coarray))
- return false;
- }
- return true;
- }
- /* Calculate the sizes for transfer, used by gfc_check_transfer and also
- by gfc_simplify_transfer. Return false if we cannot do so. */
- bool
- gfc_calculate_transfer_sizes (gfc_expr *source, gfc_expr *mold, gfc_expr *size,
- size_t *source_size, size_t *result_size,
- size_t *result_length_p)
- {
- size_t result_elt_size;
- if (source->expr_type == EXPR_FUNCTION)
- return false;
- if (size && size->expr_type != EXPR_CONSTANT)
- return false;
- /* Calculate the size of the source. */
- *source_size = gfc_target_expr_size (source);
- if (*source_size == 0)
- return false;
- /* Determine the size of the element. */
- result_elt_size = gfc_element_size (mold);
- if (result_elt_size == 0)
- return false;
- if (mold->expr_type == EXPR_ARRAY || mold->rank || size)
- {
- int result_length;
- if (size)
- result_length = (size_t)mpz_get_ui (size->value.integer);
- else
- {
- result_length = *source_size / result_elt_size;
- if (result_length * result_elt_size < *source_size)
- result_length += 1;
- }
- *result_size = result_length * result_elt_size;
- if (result_length_p)
- *result_length_p = result_length;
- }
- else
- *result_size = result_elt_size;
- return true;
- }
- bool
- gfc_check_transfer (gfc_expr *source, gfc_expr *mold, gfc_expr *size)
- {
- size_t source_size;
- size_t result_size;
- if (mold->ts.type == BT_HOLLERITH)
- {
- gfc_error ("%<MOLD%> argument of %<TRANSFER%> intrinsic at %L must not be"
- " %s", &mold->where, gfc_basic_typename (BT_HOLLERITH));
- return false;
- }
- if (size != NULL)
- {
- if (!type_check (size, 2, BT_INTEGER))
- return false;
- if (!scalar_check (size, 2))
- return false;
- if (!nonoptional_check (size, 2))
- return false;
- }
- if (!warn_surprising)
- return true;
- /* If we can't calculate the sizes, we cannot check any more.
- Return true for that case. */
- if (!gfc_calculate_transfer_sizes (source, mold, size, &source_size,
- &result_size, NULL))
- return true;
- if (source_size < result_size)
- gfc_warning (0, "Intrinsic TRANSFER at %L has partly undefined result: "
- "source size %ld < result size %ld", &source->where,
- (long) source_size, (long) result_size);
- return true;
- }
- bool
- gfc_check_transpose (gfc_expr *matrix)
- {
- if (!rank_check (matrix, 0, 2))
- return false;
- return true;
- }
- bool
- gfc_check_ubound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
- {
- if (!array_check (array, 0))
- return false;
- if (!dim_check (dim, 1, false))
- return false;
- if (!dim_rank_check (dim, array, 0))
- return false;
- if (!kind_check (kind, 2, BT_INTEGER))
- return false;
- if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
- "with KIND argument at %L",
- gfc_current_intrinsic, &kind->where))
- return false;
- return true;
- }
- bool
- gfc_check_ucobound (gfc_expr *coarray, gfc_expr *dim, gfc_expr *kind)
- {
- if (flag_coarray == GFC_FCOARRAY_NONE)
- {
- gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
- return false;
- }
- if (!coarray_check (coarray, 0))
- return false;
- if (dim != NULL)
- {
- if (!dim_check (dim, 1, false))
- return false;
- if (!dim_corank_check (dim, coarray))
- return false;
- }
- if (!kind_check (kind, 2, BT_INTEGER))
- return false;
- return true;
- }
- bool
- gfc_check_unpack (gfc_expr *vector, gfc_expr *mask, gfc_expr *field)
- {
- mpz_t vector_size;
- if (!rank_check (vector, 0, 1))
- return false;
- if (!array_check (mask, 1))
- return false;
- if (!type_check (mask, 1, BT_LOGICAL))
- return false;
- if (!same_type_check (vector, 0, field, 2))
- return false;
- if (mask->expr_type == EXPR_ARRAY
- && gfc_array_size (vector, &vector_size))
- {
- int mask_true_count = 0;
- gfc_constructor *mask_ctor;
- mask_ctor = gfc_constructor_first (mask->value.constructor);
- while (mask_ctor)
- {
- if (mask_ctor->expr->expr_type != EXPR_CONSTANT)
- {
- mask_true_count = 0;
- break;
- }
- if (mask_ctor->expr->value.logical)
- mask_true_count++;
- mask_ctor = gfc_constructor_next (mask_ctor);
- }
- if (mpz_get_si (vector_size) < mask_true_count)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L must "
- "provide at least as many elements as there "
- "are .TRUE. values in %qs (%ld/%d)",
- gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
- &vector->where, gfc_current_intrinsic_arg[1]->name,
- mpz_get_si (vector_size), mask_true_count);
- return false;
- }
- mpz_clear (vector_size);
- }
- if (mask->rank != field->rank && field->rank != 0)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L must have "
- "the same rank as %qs or be a scalar",
- gfc_current_intrinsic_arg[2]->name, gfc_current_intrinsic,
- &field->where, gfc_current_intrinsic_arg[1]->name);
- return false;
- }
- if (mask->rank == field->rank)
- {
- int i;
- for (i = 0; i < field->rank; i++)
- if (! identical_dimen_shape (mask, i, field, i))
- {
- gfc_error ("%qs and %qs arguments of %qs intrinsic at %L "
- "must have identical shape.",
- gfc_current_intrinsic_arg[2]->name,
- gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
- &field->where);
- }
- }
- return true;
- }
- bool
- gfc_check_verify (gfc_expr *x, gfc_expr *y, gfc_expr *z, gfc_expr *kind)
- {
- if (!type_check (x, 0, BT_CHARACTER))
- return false;
- if (!same_type_check (x, 0, y, 1))
- return false;
- if (z != NULL && !type_check (z, 2, BT_LOGICAL))
- return false;
- if (!kind_check (kind, 3, BT_INTEGER))
- return false;
- if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
- "with KIND argument at %L",
- gfc_current_intrinsic, &kind->where))
- return false;
- return true;
- }
- bool
- gfc_check_trim (gfc_expr *x)
- {
- if (!type_check (x, 0, BT_CHARACTER))
- return false;
- if (!scalar_check (x, 0))
- return false;
- return true;
- }
- bool
- gfc_check_ttynam (gfc_expr *unit)
- {
- if (!scalar_check (unit, 0))
- return false;
- if (!type_check (unit, 0, BT_INTEGER))
- return false;
- return true;
- }
- /* Common check function for the half a dozen intrinsics that have a
- single real argument. */
- bool
- gfc_check_x (gfc_expr *x)
- {
- if (!type_check (x, 0, BT_REAL))
- return false;
- return true;
- }
- /************* Check functions for intrinsic subroutines *************/
- bool
- gfc_check_cpu_time (gfc_expr *time)
- {
- if (!scalar_check (time, 0))
- return false;
- if (!type_check (time, 0, BT_REAL))
- return false;
- if (!variable_check (time, 0, false))
- return false;
- return true;
- }
- bool
- gfc_check_date_and_time (gfc_expr *date, gfc_expr *time,
- gfc_expr *zone, gfc_expr *values)
- {
- if (date != NULL)
- {
- if (!type_check (date, 0, BT_CHARACTER))
- return false;
- if (!kind_value_check (date, 0, gfc_default_character_kind))
- return false;
- if (!scalar_check (date, 0))
- return false;
- if (!variable_check (date, 0, false))
- return false;
- }
- if (time != NULL)
- {
- if (!type_check (time, 1, BT_CHARACTER))
- return false;
- if (!kind_value_check (time, 1, gfc_default_character_kind))
- return false;
- if (!scalar_check (time, 1))
- return false;
- if (!variable_check (time, 1, false))
- return false;
- }
- if (zone != NULL)
- {
- if (!type_check (zone, 2, BT_CHARACTER))
- return false;
- if (!kind_value_check (zone, 2, gfc_default_character_kind))
- return false;
- if (!scalar_check (zone, 2))
- return false;
- if (!variable_check (zone, 2, false))
- return false;
- }
- if (values != NULL)
- {
- if (!type_check (values, 3, BT_INTEGER))
- return false;
- if (!array_check (values, 3))
- return false;
- if (!rank_check (values, 3, 1))
- return false;
- if (!variable_check (values, 3, false))
- return false;
- }
- return true;
- }
- bool
- gfc_check_mvbits (gfc_expr *from, gfc_expr *frompos, gfc_expr *len,
- gfc_expr *to, gfc_expr *topos)
- {
- if (!type_check (from, 0, BT_INTEGER))
- return false;
- if (!type_check (frompos, 1, BT_INTEGER))
- return false;
- if (!type_check (len, 2, BT_INTEGER))
- return false;
- if (!same_type_check (from, 0, to, 3))
- return false;
- if (!variable_check (to, 3, false))
- return false;
- if (!type_check (topos, 4, BT_INTEGER))
- return false;
- if (!nonnegative_check ("frompos", frompos))
- return false;
- if (!nonnegative_check ("topos", topos))
- return false;
- if (!nonnegative_check ("len", len))
- return false;
- if (!less_than_bitsize2 ("from", from, "frompos", frompos, "len", len))
- return false;
- if (!less_than_bitsize2 ("to", to, "topos", topos, "len", len))
- return false;
- return true;
- }
- bool
- gfc_check_random_number (gfc_expr *harvest)
- {
- if (!type_check (harvest, 0, BT_REAL))
- return false;
- if (!variable_check (harvest, 0, false))
- return false;
- return true;
- }
- bool
- gfc_check_random_seed (gfc_expr *size, gfc_expr *put, gfc_expr *get)
- {
- unsigned int nargs = 0, kiss_size;
- locus *where = NULL;
- mpz_t put_size, get_size;
- bool have_gfc_real_16; /* Try and mimic HAVE_GFC_REAL_16 in libgfortran. */
- have_gfc_real_16 = gfc_validate_kind (BT_REAL, 16, true) != -1;
- /* Keep the number of bytes in sync with kiss_size in
- libgfortran/intrinsics/random.c. */
- kiss_size = (have_gfc_real_16 ? 48 : 32) / gfc_default_integer_kind;
- if (size != NULL)
- {
- if (size->expr_type != EXPR_VARIABLE
- || !size->symtree->n.sym->attr.optional)
- nargs++;
- if (!scalar_check (size, 0))
- return false;
- if (!type_check (size, 0, BT_INTEGER))
- return false;
- if (!variable_check (size, 0, false))
- return false;
- if (!kind_value_check (size, 0, gfc_default_integer_kind))
- return false;
- }
- if (put != NULL)
- {
- if (put->expr_type != EXPR_VARIABLE
- || !put->symtree->n.sym->attr.optional)
- {
- nargs++;
- where = &put->where;
- }
- if (!array_check (put, 1))
- return false;
- if (!rank_check (put, 1, 1))
- return false;
- if (!type_check (put, 1, BT_INTEGER))
- return false;
- if (!kind_value_check (put, 1, gfc_default_integer_kind))
- return false;
- if (gfc_array_size (put, &put_size)
- && mpz_get_ui (put_size) < kiss_size)
- gfc_error ("Size of %qs argument of %qs intrinsic at %L "
- "too small (%i/%i)",
- gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
- where, (int) mpz_get_ui (put_size), kiss_size);
- }
- if (get != NULL)
- {
- if (get->expr_type != EXPR_VARIABLE
- || !get->symtree->n.sym->attr.optional)
- {
- nargs++;
- where = &get->where;
- }
- if (!array_check (get, 2))
- return false;
- if (!rank_check (get, 2, 1))
- return false;
- if (!type_check (get, 2, BT_INTEGER))
- return false;
- if (!variable_check (get, 2, false))
- return false;
- if (!kind_value_check (get, 2, gfc_default_integer_kind))
- return false;
- if (gfc_array_size (get, &get_size)
- && mpz_get_ui (get_size) < kiss_size)
- gfc_error ("Size of %qs argument of %qs intrinsic at %L "
- "too small (%i/%i)",
- gfc_current_intrinsic_arg[2]->name, gfc_current_intrinsic,
- where, (int) mpz_get_ui (get_size), kiss_size);
- }
- /* RANDOM_SEED may not have more than one non-optional argument. */
- if (nargs > 1)
- gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic, where);
- return true;
- }
- bool
- gfc_check_second_sub (gfc_expr *time)
- {
- if (!scalar_check (time, 0))
- return false;
- if (!type_check (time, 0, BT_REAL))
- return false;
- if (!kind_value_check (time, 0, 4))
- return false;
- return true;
- }
- /* COUNT and COUNT_MAX of SYSTEM_CLOCK are scalar, default-kind integer
- variables in Fortran 95. In Fortran 2003 and later, they can be of any
- kind, and COUNT_RATE can be of type real. Note, count, count_rate, and
- count_max are all optional arguments */
- bool
- gfc_check_system_clock (gfc_expr *count, gfc_expr *count_rate,
- gfc_expr *count_max)
- {
- if (count != NULL)
- {
- if (!scalar_check (count, 0))
- return false;
- if (!type_check (count, 0, BT_INTEGER))
- return false;
- if (count->ts.kind != gfc_default_integer_kind
- && !gfc_notify_std (GFC_STD_F2003, "COUNT argument to "
- "SYSTEM_CLOCK at %L has non-default kind",
- &count->where))
- return false;
- if (!variable_check (count, 0, false))
- return false;
- }
- if (count_rate != NULL)
- {
- if (!scalar_check (count_rate, 1))
- return false;
- if (!variable_check (count_rate, 1, false))
- return false;
- if (count_rate->ts.type == BT_REAL)
- {
- if (!gfc_notify_std (GFC_STD_F2003, "Real COUNT_RATE argument to "
- "SYSTEM_CLOCK at %L", &count_rate->where))
- return false;
- }
- else
- {
- if (!type_check (count_rate, 1, BT_INTEGER))
- return false;
- if (count_rate->ts.kind != gfc_default_integer_kind
- && !gfc_notify_std (GFC_STD_F2003, "COUNT_RATE argument to "
- "SYSTEM_CLOCK at %L has non-default kind",
- &count_rate->where))
- return false;
- }
- }
- if (count_max != NULL)
- {
- if (!scalar_check (count_max, 2))
- return false;
- if (!type_check (count_max, 2, BT_INTEGER))
- return false;
- if (count_max->ts.kind != gfc_default_integer_kind
- && !gfc_notify_std (GFC_STD_F2003, "COUNT_MAX argument to "
- "SYSTEM_CLOCK at %L has non-default kind",
- &count_max->where))
- return false;
- if (!variable_check (count_max, 2, false))
- return false;
- }
- return true;
- }
- bool
- gfc_check_irand (gfc_expr *x)
- {
- if (x == NULL)
- return true;
- if (!scalar_check (x, 0))
- return false;
- if (!type_check (x, 0, BT_INTEGER))
- return false;
- if (!kind_value_check (x, 0, 4))
- return false;
- return true;
- }
- bool
- gfc_check_alarm_sub (gfc_expr *seconds, gfc_expr *handler, gfc_expr *status)
- {
- if (!scalar_check (seconds, 0))
- return false;
- if (!type_check (seconds, 0, BT_INTEGER))
- return false;
- if (!int_or_proc_check (handler, 1))
- return false;
- if (handler->ts.type == BT_INTEGER && !scalar_check (handler, 1))
- return false;
- if (status == NULL)
- return true;
- if (!scalar_check (status, 2))
- return false;
- if (!type_check (status, 2, BT_INTEGER))
- return false;
- if (!kind_value_check (status, 2, gfc_default_integer_kind))
- return false;
- return true;
- }
- bool
- gfc_check_rand (gfc_expr *x)
- {
- if (x == NULL)
- return true;
- if (!scalar_check (x, 0))
- return false;
- if (!type_check (x, 0, BT_INTEGER))
- return false;
- if (!kind_value_check (x, 0, 4))
- return false;
- return true;
- }
- bool
- gfc_check_srand (gfc_expr *x)
- {
- if (!scalar_check (x, 0))
- return false;
- if (!type_check (x, 0, BT_INTEGER))
- return false;
- if (!kind_value_check (x, 0, 4))
- return false;
- return true;
- }
- bool
- gfc_check_ctime_sub (gfc_expr *time, gfc_expr *result)
- {
- if (!scalar_check (time, 0))
- return false;
- if (!type_check (time, 0, BT_INTEGER))
- return false;
- if (!type_check (result, 1, BT_CHARACTER))
- return false;
- if (!kind_value_check (result, 1, gfc_default_character_kind))
- return false;
- return true;
- }
- bool
- gfc_check_dtime_etime (gfc_expr *x)
- {
- if (!array_check (x, 0))
- return false;
- if (!rank_check (x, 0, 1))
- return false;
- if (!variable_check (x, 0, false))
- return false;
- if (!type_check (x, 0, BT_REAL))
- return false;
- if (!kind_value_check (x, 0, 4))
- return false;
- return true;
- }
- bool
- gfc_check_dtime_etime_sub (gfc_expr *values, gfc_expr *time)
- {
- if (!array_check (values, 0))
- return false;
- if (!rank_check (values, 0, 1))
- return false;
- if (!variable_check (values, 0, false))
- return false;
- if (!type_check (values, 0, BT_REAL))
- return false;
- if (!kind_value_check (values, 0, 4))
- return false;
- if (!scalar_check (time, 1))
- return false;
- if (!type_check (time, 1, BT_REAL))
- return false;
- if (!kind_value_check (time, 1, 4))
- return false;
- return true;
- }
- bool
- gfc_check_fdate_sub (gfc_expr *date)
- {
- if (!type_check (date, 0, BT_CHARACTER))
- return false;
- if (!kind_value_check (date, 0, gfc_default_character_kind))
- return false;
- return true;
- }
- bool
- gfc_check_gerror (gfc_expr *msg)
- {
- if (!type_check (msg, 0, BT_CHARACTER))
- return false;
- if (!kind_value_check (msg, 0, gfc_default_character_kind))
- return false;
- return true;
- }
- bool
- gfc_check_getcwd_sub (gfc_expr *cwd, gfc_expr *status)
- {
- if (!type_check (cwd, 0, BT_CHARACTER))
- return false;
- if (!kind_value_check (cwd, 0, gfc_default_character_kind))
- return false;
- if (status == NULL)
- return true;
- if (!scalar_check (status, 1))
- return false;
- if (!type_check (status, 1, BT_INTEGER))
- return false;
- return true;
- }
- bool
- gfc_check_getarg (gfc_expr *pos, gfc_expr *value)
- {
- if (!type_check (pos, 0, BT_INTEGER))
- return false;
- if (pos->ts.kind > gfc_default_integer_kind)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L must be of a kind "
- "not wider than the default kind (%d)",
- gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
- &pos->where, gfc_default_integer_kind);
- return false;
- }
- if (!type_check (value, 1, BT_CHARACTER))
- return false;
- if (!kind_value_check (value, 1, gfc_default_character_kind))
- return false;
- return true;
- }
- bool
- gfc_check_getlog (gfc_expr *msg)
- {
- if (!type_check (msg, 0, BT_CHARACTER))
- return false;
- if (!kind_value_check (msg, 0, gfc_default_character_kind))
- return false;
- return true;
- }
- bool
- gfc_check_exit (gfc_expr *status)
- {
- if (status == NULL)
- return true;
- if (!type_check (status, 0, BT_INTEGER))
- return false;
- if (!scalar_check (status, 0))
- return false;
- return true;
- }
- bool
- gfc_check_flush (gfc_expr *unit)
- {
- if (unit == NULL)
- return true;
- if (!type_check (unit, 0, BT_INTEGER))
- return false;
- if (!scalar_check (unit, 0))
- return false;
- return true;
- }
- bool
- gfc_check_free (gfc_expr *i)
- {
- if (!type_check (i, 0, BT_INTEGER))
- return false;
- if (!scalar_check (i, 0))
- return false;
- return true;
- }
- bool
- gfc_check_hostnm (gfc_expr *name)
- {
- if (!type_check (name, 0, BT_CHARACTER))
- return false;
- if (!kind_value_check (name, 0, gfc_default_character_kind))
- return false;
- return true;
- }
- bool
- gfc_check_hostnm_sub (gfc_expr *name, gfc_expr *status)
- {
- if (!type_check (name, 0, BT_CHARACTER))
- return false;
- if (!kind_value_check (name, 0, gfc_default_character_kind))
- return false;
- if (status == NULL)
- return true;
- if (!scalar_check (status, 1))
- return false;
- if (!type_check (status, 1, BT_INTEGER))
- return false;
- return true;
- }
- bool
- gfc_check_itime_idate (gfc_expr *values)
- {
- if (!array_check (values, 0))
- return false;
- if (!rank_check (values, 0, 1))
- return false;
- if (!variable_check (values, 0, false))
- return false;
- if (!type_check (values, 0, BT_INTEGER))
- return false;
- if (!kind_value_check (values, 0, gfc_default_integer_kind))
- return false;
- return true;
- }
- bool
- gfc_check_ltime_gmtime (gfc_expr *time, gfc_expr *values)
- {
- if (!type_check (time, 0, BT_INTEGER))
- return false;
- if (!kind_value_check (time, 0, gfc_default_integer_kind))
- return false;
- if (!scalar_check (time, 0))
- return false;
- if (!array_check (values, 1))
- return false;
- if (!rank_check (values, 1, 1))
- return false;
- if (!variable_check (values, 1, false))
- return false;
- if (!type_check (values, 1, BT_INTEGER))
- return false;
- if (!kind_value_check (values, 1, gfc_default_integer_kind))
- return false;
- return true;
- }
- bool
- gfc_check_ttynam_sub (gfc_expr *unit, gfc_expr *name)
- {
- if (!scalar_check (unit, 0))
- return false;
- if (!type_check (unit, 0, BT_INTEGER))
- return false;
- if (!type_check (name, 1, BT_CHARACTER))
- return false;
- if (!kind_value_check (name, 1, gfc_default_character_kind))
- return false;
- return true;
- }
- bool
- gfc_check_isatty (gfc_expr *unit)
- {
- if (unit == NULL)
- return false;
- if (!type_check (unit, 0, BT_INTEGER))
- return false;
- if (!scalar_check (unit, 0))
- return false;
- return true;
- }
- bool
- gfc_check_isnan (gfc_expr *x)
- {
- if (!type_check (x, 0, BT_REAL))
- return false;
- return true;
- }
- bool
- gfc_check_perror (gfc_expr *string)
- {
- if (!type_check (string, 0, BT_CHARACTER))
- return false;
- if (!kind_value_check (string, 0, gfc_default_character_kind))
- return false;
- return true;
- }
- bool
- gfc_check_umask (gfc_expr *mask)
- {
- if (!type_check (mask, 0, BT_INTEGER))
- return false;
- if (!scalar_check (mask, 0))
- return false;
- return true;
- }
- bool
- gfc_check_umask_sub (gfc_expr *mask, gfc_expr *old)
- {
- if (!type_check (mask, 0, BT_INTEGER))
- return false;
- if (!scalar_check (mask, 0))
- return false;
- if (old == NULL)
- return true;
- if (!scalar_check (old, 1))
- return false;
- if (!type_check (old, 1, BT_INTEGER))
- return false;
- return true;
- }
- bool
- gfc_check_unlink (gfc_expr *name)
- {
- if (!type_check (name, 0, BT_CHARACTER))
- return false;
- if (!kind_value_check (name, 0, gfc_default_character_kind))
- return false;
- return true;
- }
- bool
- gfc_check_unlink_sub (gfc_expr *name, gfc_expr *status)
- {
- if (!type_check (name, 0, BT_CHARACTER))
- return false;
- if (!kind_value_check (name, 0, gfc_default_character_kind))
- return false;
- if (status == NULL)
- return true;
- if (!scalar_check (status, 1))
- return false;
- if (!type_check (status, 1, BT_INTEGER))
- return false;
- return true;
- }
- bool
- gfc_check_signal (gfc_expr *number, gfc_expr *handler)
- {
- if (!scalar_check (number, 0))
- return false;
- if (!type_check (number, 0, BT_INTEGER))
- return false;
- if (!int_or_proc_check (handler, 1))
- return false;
- if (handler->ts.type == BT_INTEGER && !scalar_check (handler, 1))
- return false;
- return true;
- }
- bool
- gfc_check_signal_sub (gfc_expr *number, gfc_expr *handler, gfc_expr *status)
- {
- if (!scalar_check (number, 0))
- return false;
- if (!type_check (number, 0, BT_INTEGER))
- return false;
- if (!int_or_proc_check (handler, 1))
- return false;
- if (handler->ts.type == BT_INTEGER && !scalar_check (handler, 1))
- return false;
- if (status == NULL)
- return true;
- if (!type_check (status, 2, BT_INTEGER))
- return false;
- if (!scalar_check (status, 2))
- return false;
- return true;
- }
- bool
- gfc_check_system_sub (gfc_expr *cmd, gfc_expr *status)
- {
- if (!type_check (cmd, 0, BT_CHARACTER))
- return false;
- if (!kind_value_check (cmd, 0, gfc_default_character_kind))
- return false;
- if (!scalar_check (status, 1))
- return false;
- if (!type_check (status, 1, BT_INTEGER))
- return false;
- if (!kind_value_check (status, 1, gfc_default_integer_kind))
- return false;
- return true;
- }
- /* This is used for the GNU intrinsics AND, OR and XOR. */
- bool
- gfc_check_and (gfc_expr *i, gfc_expr *j)
- {
- if (i->ts.type != BT_INTEGER && i->ts.type != BT_LOGICAL)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER "
- "or LOGICAL", gfc_current_intrinsic_arg[0]->name,
- gfc_current_intrinsic, &i->where);
- return false;
- }
- if (j->ts.type != BT_INTEGER && j->ts.type != BT_LOGICAL)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER "
- "or LOGICAL", gfc_current_intrinsic_arg[1]->name,
- gfc_current_intrinsic, &j->where);
- return false;
- }
- if (i->ts.type != j->ts.type)
- {
- gfc_error ("%qs and %qs arguments of %qs intrinsic at %L must "
- "have the same type", gfc_current_intrinsic_arg[0]->name,
- gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
- &j->where);
- return false;
- }
- if (!scalar_check (i, 0))
- return false;
- if (!scalar_check (j, 1))
- return false;
- return true;
- }
- bool
- gfc_check_storage_size (gfc_expr *a, gfc_expr *kind)
- {
- if (a->expr_type == EXPR_NULL)
- {
- gfc_error ("Intrinsic function NULL at %L cannot be an actual "
- "argument to STORAGE_SIZE, because it returns a "
- "disassociated pointer", &a->where);
- return false;
- }
- if (a->ts.type == BT_ASSUMED)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L shall not be TYPE(*)",
- gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
- &a->where);
- return false;
- }
- if (a->ts.type == BT_PROCEDURE)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L shall not be a "
- "procedure", gfc_current_intrinsic_arg[0]->name,
- gfc_current_intrinsic, &a->where);
- return false;
- }
- if (kind == NULL)
- return true;
- if (!type_check (kind, 1, BT_INTEGER))
- return false;
- if (!scalar_check (kind, 1))
- return false;
- if (kind->expr_type != EXPR_CONSTANT)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L must be a constant",
- gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
- &kind->where);
- return false;
- }
- return true;
- }
|