iresolve.c 83 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704
  1. /* Intrinsic function resolution.
  2. Copyright (C) 2000-2015 Free Software Foundation, Inc.
  3. Contributed by Andy Vaught & Katherine Holcomb
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify it under
  6. the terms of the GNU General Public License as published by the Free
  7. Software Foundation; either version 3, or (at your option) any later
  8. version.
  9. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GCC; see the file COPYING3. If not see
  15. <http://www.gnu.org/licenses/>. */
  16. /* Assign name and types to intrinsic procedures. For functions, the
  17. first argument to a resolution function is an expression pointer to
  18. the original function node and the rest are pointers to the
  19. arguments of the function call. For subroutines, a pointer to the
  20. code node is passed. The result type and library subroutine name
  21. are generally set according to the function arguments. */
  22. #include "config.h"
  23. #include "system.h"
  24. #include "coretypes.h"
  25. #include "hash-set.h"
  26. #include "machmode.h"
  27. #include "vec.h"
  28. #include "double-int.h"
  29. #include "input.h"
  30. #include "alias.h"
  31. #include "symtab.h"
  32. #include "options.h"
  33. #include "wide-int.h"
  34. #include "inchash.h"
  35. #include "tree.h"
  36. #include "stringpool.h"
  37. #include "gfortran.h"
  38. #include "intrinsic.h"
  39. #include "constructor.h"
  40. #include "arith.h"
  41. /* Given printf-like arguments, return a stable version of the result string.
  42. We already have a working, optimized string hashing table in the form of
  43. the identifier table. Reusing this table is likely not to be wasted,
  44. since if the function name makes it to the gimple output of the frontend,
  45. we'll have to create the identifier anyway. */
  46. const char *
  47. gfc_get_string (const char *format, ...)
  48. {
  49. char temp_name[128];
  50. va_list ap;
  51. tree ident;
  52. va_start (ap, format);
  53. vsnprintf (temp_name, sizeof (temp_name), format, ap);
  54. va_end (ap);
  55. temp_name[sizeof (temp_name) - 1] = 0;
  56. ident = get_identifier (temp_name);
  57. return IDENTIFIER_POINTER (ident);
  58. }
  59. /* MERGE and SPREAD need to have source charlen's present for passing
  60. to the result expression. */
  61. static void
  62. check_charlen_present (gfc_expr *source)
  63. {
  64. if (source->ts.u.cl == NULL)
  65. source->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL);
  66. if (source->expr_type == EXPR_CONSTANT)
  67. {
  68. source->ts.u.cl->length
  69. = gfc_get_int_expr (gfc_default_integer_kind, NULL,
  70. source->value.character.length);
  71. source->rank = 0;
  72. }
  73. else if (source->expr_type == EXPR_ARRAY)
  74. {
  75. gfc_constructor *c = gfc_constructor_first (source->value.constructor);
  76. source->ts.u.cl->length
  77. = gfc_get_int_expr (gfc_default_integer_kind, NULL,
  78. c->expr->value.character.length);
  79. }
  80. }
  81. /* Helper function for resolving the "mask" argument. */
  82. static void
  83. resolve_mask_arg (gfc_expr *mask)
  84. {
  85. gfc_typespec ts;
  86. gfc_clear_ts (&ts);
  87. if (mask->rank == 0)
  88. {
  89. /* For the scalar case, coerce the mask to kind=4 unconditionally
  90. (because this is the only kind we have a library function
  91. for). */
  92. if (mask->ts.kind != 4)
  93. {
  94. ts.type = BT_LOGICAL;
  95. ts.kind = 4;
  96. gfc_convert_type (mask, &ts, 2);
  97. }
  98. }
  99. else
  100. {
  101. /* In the library, we access the mask with a GFC_LOGICAL_1
  102. argument. No need to waste memory if we are about to create
  103. a temporary array. */
  104. if (mask->expr_type == EXPR_OP && mask->ts.kind != 1)
  105. {
  106. ts.type = BT_LOGICAL;
  107. ts.kind = 1;
  108. gfc_convert_type_warn (mask, &ts, 2, 0);
  109. }
  110. }
  111. }
  112. static void
  113. resolve_bound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind,
  114. const char *name, bool coarray)
  115. {
  116. f->ts.type = BT_INTEGER;
  117. if (kind)
  118. f->ts.kind = mpz_get_si (kind->value.integer);
  119. else
  120. f->ts.kind = gfc_default_integer_kind;
  121. if (dim == NULL)
  122. {
  123. f->rank = 1;
  124. if (array->rank != -1)
  125. {
  126. f->shape = gfc_get_shape (1);
  127. mpz_init_set_ui (f->shape[0], coarray ? gfc_get_corank (array)
  128. : array->rank);
  129. }
  130. }
  131. f->value.function.name = gfc_get_string (name);
  132. }
  133. static void
  134. resolve_transformational (const char *name, gfc_expr *f, gfc_expr *array,
  135. gfc_expr *dim, gfc_expr *mask)
  136. {
  137. const char *prefix;
  138. f->ts = array->ts;
  139. if (mask)
  140. {
  141. if (mask->rank == 0)
  142. prefix = "s";
  143. else
  144. prefix = "m";
  145. resolve_mask_arg (mask);
  146. }
  147. else
  148. prefix = "";
  149. if (dim != NULL)
  150. {
  151. f->rank = array->rank - 1;
  152. f->shape = gfc_copy_shape_excluding (array->shape, array->rank, dim);
  153. gfc_resolve_dim_arg (dim);
  154. }
  155. f->value.function.name
  156. = gfc_get_string (PREFIX ("%s%s_%c%d"), prefix, name,
  157. gfc_type_letter (array->ts.type), array->ts.kind);
  158. }
  159. /********************** Resolution functions **********************/
  160. void
  161. gfc_resolve_abs (gfc_expr *f, gfc_expr *a)
  162. {
  163. f->ts = a->ts;
  164. if (f->ts.type == BT_COMPLEX)
  165. f->ts.type = BT_REAL;
  166. f->value.function.name
  167. = gfc_get_string ("__abs_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
  168. }
  169. void
  170. gfc_resolve_access (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED,
  171. gfc_expr *mode ATTRIBUTE_UNUSED)
  172. {
  173. f->ts.type = BT_INTEGER;
  174. f->ts.kind = gfc_c_int_kind;
  175. f->value.function.name = PREFIX ("access_func");
  176. }
  177. void
  178. gfc_resolve_adjustl (gfc_expr *f, gfc_expr *string)
  179. {
  180. f->ts.type = BT_CHARACTER;
  181. f->ts.kind = string->ts.kind;
  182. f->value.function.name = gfc_get_string ("__adjustl_s%d", f->ts.kind);
  183. }
  184. void
  185. gfc_resolve_adjustr (gfc_expr *f, gfc_expr *string)
  186. {
  187. f->ts.type = BT_CHARACTER;
  188. f->ts.kind = string->ts.kind;
  189. f->value.function.name = gfc_get_string ("__adjustr_s%d", f->ts.kind);
  190. }
  191. static void
  192. gfc_resolve_char_achar (gfc_expr *f, gfc_expr *x, gfc_expr *kind,
  193. const char *name)
  194. {
  195. f->ts.type = BT_CHARACTER;
  196. f->ts.kind = (kind == NULL)
  197. ? gfc_default_character_kind : mpz_get_si (kind->value.integer);
  198. f->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL);
  199. f->ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind, NULL, 1);
  200. f->value.function.name = gfc_get_string (name, f->ts.kind,
  201. gfc_type_letter (x->ts.type),
  202. x->ts.kind);
  203. }
  204. void
  205. gfc_resolve_achar (gfc_expr *f, gfc_expr *x, gfc_expr *kind)
  206. {
  207. gfc_resolve_char_achar (f, x, kind, "__achar_%d_%c%d");
  208. }
  209. void
  210. gfc_resolve_acos (gfc_expr *f, gfc_expr *x)
  211. {
  212. f->ts = x->ts;
  213. f->value.function.name
  214. = gfc_get_string ("__acos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
  215. }
  216. void
  217. gfc_resolve_acosh (gfc_expr *f, gfc_expr *x)
  218. {
  219. f->ts = x->ts;
  220. f->value.function.name
  221. = gfc_get_string ("__acosh_%c%d", gfc_type_letter (x->ts.type),
  222. x->ts.kind);
  223. }
  224. void
  225. gfc_resolve_aimag (gfc_expr *f, gfc_expr *x)
  226. {
  227. f->ts.type = BT_REAL;
  228. f->ts.kind = x->ts.kind;
  229. f->value.function.name
  230. = gfc_get_string ("__aimag_%c%d", gfc_type_letter (x->ts.type),
  231. x->ts.kind);
  232. }
  233. void
  234. gfc_resolve_and (gfc_expr *f, gfc_expr *i, gfc_expr *j)
  235. {
  236. f->ts.type = i->ts.type;
  237. f->ts.kind = gfc_kind_max (i, j);
  238. if (i->ts.kind != j->ts.kind)
  239. {
  240. if (i->ts.kind == gfc_kind_max (i, j))
  241. gfc_convert_type (j, &i->ts, 2);
  242. else
  243. gfc_convert_type (i, &j->ts, 2);
  244. }
  245. f->value.function.name
  246. = gfc_get_string ("__and_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
  247. }
  248. void
  249. gfc_resolve_aint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
  250. {
  251. gfc_typespec ts;
  252. gfc_clear_ts (&ts);
  253. f->ts.type = a->ts.type;
  254. f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
  255. if (a->ts.kind != f->ts.kind)
  256. {
  257. ts.type = f->ts.type;
  258. ts.kind = f->ts.kind;
  259. gfc_convert_type (a, &ts, 2);
  260. }
  261. /* The resolved name is only used for specific intrinsics where
  262. the return kind is the same as the arg kind. */
  263. f->value.function.name
  264. = gfc_get_string ("__aint_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
  265. }
  266. void
  267. gfc_resolve_dint (gfc_expr *f, gfc_expr *a)
  268. {
  269. gfc_resolve_aint (f, a, NULL);
  270. }
  271. void
  272. gfc_resolve_all (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
  273. {
  274. f->ts = mask->ts;
  275. if (dim != NULL)
  276. {
  277. gfc_resolve_dim_arg (dim);
  278. f->rank = mask->rank - 1;
  279. f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
  280. }
  281. f->value.function.name
  282. = gfc_get_string (PREFIX ("all_%c%d"), gfc_type_letter (mask->ts.type),
  283. mask->ts.kind);
  284. }
  285. void
  286. gfc_resolve_anint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
  287. {
  288. gfc_typespec ts;
  289. gfc_clear_ts (&ts);
  290. f->ts.type = a->ts.type;
  291. f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
  292. if (a->ts.kind != f->ts.kind)
  293. {
  294. ts.type = f->ts.type;
  295. ts.kind = f->ts.kind;
  296. gfc_convert_type (a, &ts, 2);
  297. }
  298. /* The resolved name is only used for specific intrinsics where
  299. the return kind is the same as the arg kind. */
  300. f->value.function.name
  301. = gfc_get_string ("__anint_%c%d", gfc_type_letter (a->ts.type),
  302. a->ts.kind);
  303. }
  304. void
  305. gfc_resolve_dnint (gfc_expr *f, gfc_expr *a)
  306. {
  307. gfc_resolve_anint (f, a, NULL);
  308. }
  309. void
  310. gfc_resolve_any (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
  311. {
  312. f->ts = mask->ts;
  313. if (dim != NULL)
  314. {
  315. gfc_resolve_dim_arg (dim);
  316. f->rank = mask->rank - 1;
  317. f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
  318. }
  319. f->value.function.name
  320. = gfc_get_string (PREFIX ("any_%c%d"), gfc_type_letter (mask->ts.type),
  321. mask->ts.kind);
  322. }
  323. void
  324. gfc_resolve_asin (gfc_expr *f, gfc_expr *x)
  325. {
  326. f->ts = x->ts;
  327. f->value.function.name
  328. = gfc_get_string ("__asin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
  329. }
  330. void
  331. gfc_resolve_asinh (gfc_expr *f, gfc_expr *x)
  332. {
  333. f->ts = x->ts;
  334. f->value.function.name
  335. = gfc_get_string ("__asinh_%c%d", gfc_type_letter (x->ts.type),
  336. x->ts.kind);
  337. }
  338. void
  339. gfc_resolve_atan (gfc_expr *f, gfc_expr *x)
  340. {
  341. f->ts = x->ts;
  342. f->value.function.name
  343. = gfc_get_string ("__atan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
  344. }
  345. void
  346. gfc_resolve_atanh (gfc_expr *f, gfc_expr *x)
  347. {
  348. f->ts = x->ts;
  349. f->value.function.name
  350. = gfc_get_string ("__atanh_%c%d", gfc_type_letter (x->ts.type),
  351. x->ts.kind);
  352. }
  353. void
  354. gfc_resolve_atan2 (gfc_expr *f, gfc_expr *x, gfc_expr *y ATTRIBUTE_UNUSED)
  355. {
  356. f->ts = x->ts;
  357. f->value.function.name
  358. = gfc_get_string ("__atan2_%c%d", gfc_type_letter (x->ts.type),
  359. x->ts.kind);
  360. }
  361. /* Resolve the BESYN and BESJN intrinsics. */
  362. void
  363. gfc_resolve_besn (gfc_expr *f, gfc_expr *n, gfc_expr *x)
  364. {
  365. gfc_typespec ts;
  366. gfc_clear_ts (&ts);
  367. f->ts = x->ts;
  368. if (n->ts.kind != gfc_c_int_kind)
  369. {
  370. ts.type = BT_INTEGER;
  371. ts.kind = gfc_c_int_kind;
  372. gfc_convert_type (n, &ts, 2);
  373. }
  374. f->value.function.name = gfc_get_string ("<intrinsic>");
  375. }
  376. void
  377. gfc_resolve_bessel_n2 (gfc_expr *f, gfc_expr *n1, gfc_expr *n2, gfc_expr *x)
  378. {
  379. gfc_typespec ts;
  380. gfc_clear_ts (&ts);
  381. f->ts = x->ts;
  382. f->rank = 1;
  383. if (n1->expr_type == EXPR_CONSTANT && n2->expr_type == EXPR_CONSTANT)
  384. {
  385. f->shape = gfc_get_shape (1);
  386. mpz_init (f->shape[0]);
  387. mpz_sub (f->shape[0], n2->value.integer, n1->value.integer);
  388. mpz_add_ui (f->shape[0], f->shape[0], 1);
  389. }
  390. if (n1->ts.kind != gfc_c_int_kind)
  391. {
  392. ts.type = BT_INTEGER;
  393. ts.kind = gfc_c_int_kind;
  394. gfc_convert_type (n1, &ts, 2);
  395. }
  396. if (n2->ts.kind != gfc_c_int_kind)
  397. {
  398. ts.type = BT_INTEGER;
  399. ts.kind = gfc_c_int_kind;
  400. gfc_convert_type (n2, &ts, 2);
  401. }
  402. if (f->value.function.isym->id == GFC_ISYM_JN2)
  403. f->value.function.name = gfc_get_string (PREFIX ("bessel_jn_r%d"),
  404. f->ts.kind);
  405. else
  406. f->value.function.name = gfc_get_string (PREFIX ("bessel_yn_r%d"),
  407. f->ts.kind);
  408. }
  409. void
  410. gfc_resolve_btest (gfc_expr *f, gfc_expr *i, gfc_expr *pos)
  411. {
  412. f->ts.type = BT_LOGICAL;
  413. f->ts.kind = gfc_default_logical_kind;
  414. f->value.function.name
  415. = gfc_get_string ("__btest_%d_%d", i->ts.kind, pos->ts.kind);
  416. }
  417. void
  418. gfc_resolve_c_loc (gfc_expr *f, gfc_expr *x ATTRIBUTE_UNUSED)
  419. {
  420. f->ts = f->value.function.isym->ts;
  421. }
  422. void
  423. gfc_resolve_c_funloc (gfc_expr *f, gfc_expr *x ATTRIBUTE_UNUSED)
  424. {
  425. f->ts = f->value.function.isym->ts;
  426. }
  427. void
  428. gfc_resolve_ceiling (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
  429. {
  430. f->ts.type = BT_INTEGER;
  431. f->ts.kind = (kind == NULL)
  432. ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
  433. f->value.function.name
  434. = gfc_get_string ("__ceiling_%d_%c%d", f->ts.kind,
  435. gfc_type_letter (a->ts.type), a->ts.kind);
  436. }
  437. void
  438. gfc_resolve_char (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
  439. {
  440. gfc_resolve_char_achar (f, a, kind, "__char_%d_%c%d");
  441. }
  442. void
  443. gfc_resolve_chdir (gfc_expr *f, gfc_expr *d ATTRIBUTE_UNUSED)
  444. {
  445. f->ts.type = BT_INTEGER;
  446. f->ts.kind = gfc_default_integer_kind;
  447. f->value.function.name = gfc_get_string (PREFIX ("chdir_i%d"), f->ts.kind);
  448. }
  449. void
  450. gfc_resolve_chdir_sub (gfc_code *c)
  451. {
  452. const char *name;
  453. int kind;
  454. if (c->ext.actual->next->expr != NULL)
  455. kind = c->ext.actual->next->expr->ts.kind;
  456. else
  457. kind = gfc_default_integer_kind;
  458. name = gfc_get_string (PREFIX ("chdir_i%d_sub"), kind);
  459. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  460. }
  461. void
  462. gfc_resolve_chmod (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED,
  463. gfc_expr *mode ATTRIBUTE_UNUSED)
  464. {
  465. f->ts.type = BT_INTEGER;
  466. f->ts.kind = gfc_c_int_kind;
  467. f->value.function.name = PREFIX ("chmod_func");
  468. }
  469. void
  470. gfc_resolve_chmod_sub (gfc_code *c)
  471. {
  472. const char *name;
  473. int kind;
  474. if (c->ext.actual->next->next->expr != NULL)
  475. kind = c->ext.actual->next->next->expr->ts.kind;
  476. else
  477. kind = gfc_default_integer_kind;
  478. name = gfc_get_string (PREFIX ("chmod_i%d_sub"), kind);
  479. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  480. }
  481. void
  482. gfc_resolve_cmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y, gfc_expr *kind)
  483. {
  484. f->ts.type = BT_COMPLEX;
  485. f->ts.kind = (kind == NULL)
  486. ? gfc_default_real_kind : mpz_get_si (kind->value.integer);
  487. if (y == NULL)
  488. f->value.function.name
  489. = gfc_get_string ("__cmplx0_%d_%c%d", f->ts.kind,
  490. gfc_type_letter (x->ts.type), x->ts.kind);
  491. else
  492. f->value.function.name
  493. = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
  494. gfc_type_letter (x->ts.type), x->ts.kind,
  495. gfc_type_letter (y->ts.type), y->ts.kind);
  496. }
  497. void
  498. gfc_resolve_dcmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y)
  499. {
  500. gfc_resolve_cmplx (f, x, y, gfc_get_int_expr (gfc_default_integer_kind, NULL,
  501. gfc_default_double_kind));
  502. }
  503. void
  504. gfc_resolve_complex (gfc_expr *f, gfc_expr *x, gfc_expr *y)
  505. {
  506. int kind;
  507. if (x->ts.type == BT_INTEGER)
  508. {
  509. if (y->ts.type == BT_INTEGER)
  510. kind = gfc_default_real_kind;
  511. else
  512. kind = y->ts.kind;
  513. }
  514. else
  515. {
  516. if (y->ts.type == BT_REAL)
  517. kind = (x->ts.kind > y->ts.kind) ? x->ts.kind : y->ts.kind;
  518. else
  519. kind = x->ts.kind;
  520. }
  521. f->ts.type = BT_COMPLEX;
  522. f->ts.kind = kind;
  523. f->value.function.name
  524. = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
  525. gfc_type_letter (x->ts.type), x->ts.kind,
  526. gfc_type_letter (y->ts.type), y->ts.kind);
  527. }
  528. void
  529. gfc_resolve_conjg (gfc_expr *f, gfc_expr *x)
  530. {
  531. f->ts = x->ts;
  532. f->value.function.name = gfc_get_string ("__conjg_%d", x->ts.kind);
  533. }
  534. void
  535. gfc_resolve_cos (gfc_expr *f, gfc_expr *x)
  536. {
  537. f->ts = x->ts;
  538. f->value.function.name
  539. = gfc_get_string ("__cos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
  540. }
  541. void
  542. gfc_resolve_cosh (gfc_expr *f, gfc_expr *x)
  543. {
  544. f->ts = x->ts;
  545. f->value.function.name
  546. = gfc_get_string ("__cosh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
  547. }
  548. void
  549. gfc_resolve_count (gfc_expr *f, gfc_expr *mask, gfc_expr *dim, gfc_expr *kind)
  550. {
  551. f->ts.type = BT_INTEGER;
  552. if (kind)
  553. f->ts.kind = mpz_get_si (kind->value.integer);
  554. else
  555. f->ts.kind = gfc_default_integer_kind;
  556. if (dim != NULL)
  557. {
  558. f->rank = mask->rank - 1;
  559. gfc_resolve_dim_arg (dim);
  560. f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
  561. }
  562. resolve_mask_arg (mask);
  563. f->value.function.name
  564. = gfc_get_string (PREFIX ("count_%d_%c"), f->ts.kind,
  565. gfc_type_letter (mask->ts.type));
  566. }
  567. void
  568. gfc_resolve_cshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
  569. gfc_expr *dim)
  570. {
  571. int n, m;
  572. if (array->ts.type == BT_CHARACTER && array->ref)
  573. gfc_resolve_substring_charlen (array);
  574. f->ts = array->ts;
  575. f->rank = array->rank;
  576. f->shape = gfc_copy_shape (array->shape, array->rank);
  577. if (shift->rank > 0)
  578. n = 1;
  579. else
  580. n = 0;
  581. /* If dim kind is greater than default integer we need to use the larger. */
  582. m = gfc_default_integer_kind;
  583. if (dim != NULL)
  584. m = m < dim->ts.kind ? dim->ts.kind : m;
  585. /* Convert shift to at least m, so we don't need
  586. kind=1 and kind=2 versions of the library functions. */
  587. if (shift->ts.kind < m)
  588. {
  589. gfc_typespec ts;
  590. gfc_clear_ts (&ts);
  591. ts.type = BT_INTEGER;
  592. ts.kind = m;
  593. gfc_convert_type_warn (shift, &ts, 2, 0);
  594. }
  595. if (dim != NULL)
  596. {
  597. if (dim->expr_type != EXPR_CONSTANT && dim->symtree != NULL
  598. && dim->symtree->n.sym->attr.optional)
  599. {
  600. /* Mark this for later setting the type in gfc_conv_missing_dummy. */
  601. dim->representation.length = shift->ts.kind;
  602. }
  603. else
  604. {
  605. gfc_resolve_dim_arg (dim);
  606. /* Convert dim to shift's kind to reduce variations. */
  607. if (dim->ts.kind != shift->ts.kind)
  608. gfc_convert_type_warn (dim, &shift->ts, 2, 0);
  609. }
  610. }
  611. if (array->ts.type == BT_CHARACTER)
  612. {
  613. if (array->ts.kind == gfc_default_character_kind)
  614. f->value.function.name
  615. = gfc_get_string (PREFIX ("cshift%d_%d_char"), n, shift->ts.kind);
  616. else
  617. f->value.function.name
  618. = gfc_get_string (PREFIX ("cshift%d_%d_char%d"), n, shift->ts.kind,
  619. array->ts.kind);
  620. }
  621. else
  622. f->value.function.name
  623. = gfc_get_string (PREFIX ("cshift%d_%d"), n, shift->ts.kind);
  624. }
  625. void
  626. gfc_resolve_ctime (gfc_expr *f, gfc_expr *time)
  627. {
  628. gfc_typespec ts;
  629. gfc_clear_ts (&ts);
  630. f->ts.type = BT_CHARACTER;
  631. f->ts.kind = gfc_default_character_kind;
  632. /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
  633. if (time->ts.kind != 8)
  634. {
  635. ts.type = BT_INTEGER;
  636. ts.kind = 8;
  637. ts.u.derived = NULL;
  638. ts.u.cl = NULL;
  639. gfc_convert_type (time, &ts, 2);
  640. }
  641. f->value.function.name = gfc_get_string (PREFIX ("ctime"));
  642. }
  643. void
  644. gfc_resolve_dble (gfc_expr *f, gfc_expr *a)
  645. {
  646. f->ts.type = BT_REAL;
  647. f->ts.kind = gfc_default_double_kind;
  648. f->value.function.name
  649. = gfc_get_string ("__dble_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
  650. }
  651. void
  652. gfc_resolve_dim (gfc_expr *f, gfc_expr *a, gfc_expr *p)
  653. {
  654. f->ts.type = a->ts.type;
  655. if (p != NULL)
  656. f->ts.kind = gfc_kind_max (a,p);
  657. else
  658. f->ts.kind = a->ts.kind;
  659. if (p != NULL && a->ts.kind != p->ts.kind)
  660. {
  661. if (a->ts.kind == gfc_kind_max (a,p))
  662. gfc_convert_type (p, &a->ts, 2);
  663. else
  664. gfc_convert_type (a, &p->ts, 2);
  665. }
  666. f->value.function.name
  667. = gfc_get_string ("__dim_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
  668. }
  669. void
  670. gfc_resolve_dot_product (gfc_expr *f, gfc_expr *a, gfc_expr *b)
  671. {
  672. gfc_expr temp;
  673. temp.expr_type = EXPR_OP;
  674. gfc_clear_ts (&temp.ts);
  675. temp.value.op.op = INTRINSIC_NONE;
  676. temp.value.op.op1 = a;
  677. temp.value.op.op2 = b;
  678. gfc_type_convert_binary (&temp, 1);
  679. f->ts = temp.ts;
  680. f->value.function.name
  681. = gfc_get_string (PREFIX ("dot_product_%c%d"),
  682. gfc_type_letter (f->ts.type), f->ts.kind);
  683. }
  684. void
  685. gfc_resolve_dprod (gfc_expr *f, gfc_expr *a ATTRIBUTE_UNUSED,
  686. gfc_expr *b ATTRIBUTE_UNUSED)
  687. {
  688. f->ts.kind = gfc_default_double_kind;
  689. f->ts.type = BT_REAL;
  690. f->value.function.name = gfc_get_string ("__dprod_r%d", f->ts.kind);
  691. }
  692. void
  693. gfc_resolve_dshift (gfc_expr *f, gfc_expr *i, gfc_expr *j ATTRIBUTE_UNUSED,
  694. gfc_expr *shift ATTRIBUTE_UNUSED)
  695. {
  696. f->ts = i->ts;
  697. if (f->value.function.isym->id == GFC_ISYM_DSHIFTL)
  698. f->value.function.name = gfc_get_string ("dshiftl_i%d", f->ts.kind);
  699. else if (f->value.function.isym->id == GFC_ISYM_DSHIFTR)
  700. f->value.function.name = gfc_get_string ("dshiftr_i%d", f->ts.kind);
  701. else
  702. gcc_unreachable ();
  703. }
  704. void
  705. gfc_resolve_eoshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
  706. gfc_expr *boundary, gfc_expr *dim)
  707. {
  708. int n, m;
  709. if (array->ts.type == BT_CHARACTER && array->ref)
  710. gfc_resolve_substring_charlen (array);
  711. f->ts = array->ts;
  712. f->rank = array->rank;
  713. f->shape = gfc_copy_shape (array->shape, array->rank);
  714. n = 0;
  715. if (shift->rank > 0)
  716. n = n | 1;
  717. if (boundary && boundary->rank > 0)
  718. n = n | 2;
  719. /* If dim kind is greater than default integer we need to use the larger. */
  720. m = gfc_default_integer_kind;
  721. if (dim != NULL)
  722. m = m < dim->ts.kind ? dim->ts.kind : m;
  723. /* Convert shift to at least m, so we don't need
  724. kind=1 and kind=2 versions of the library functions. */
  725. if (shift->ts.kind < m)
  726. {
  727. gfc_typespec ts;
  728. gfc_clear_ts (&ts);
  729. ts.type = BT_INTEGER;
  730. ts.kind = m;
  731. gfc_convert_type_warn (shift, &ts, 2, 0);
  732. }
  733. if (dim != NULL)
  734. {
  735. if (dim->expr_type != EXPR_CONSTANT && dim->symtree != NULL
  736. && dim->symtree->n.sym->attr.optional)
  737. {
  738. /* Mark this for later setting the type in gfc_conv_missing_dummy. */
  739. dim->representation.length = shift->ts.kind;
  740. }
  741. else
  742. {
  743. gfc_resolve_dim_arg (dim);
  744. /* Convert dim to shift's kind to reduce variations. */
  745. if (dim->ts.kind != shift->ts.kind)
  746. gfc_convert_type_warn (dim, &shift->ts, 2, 0);
  747. }
  748. }
  749. if (array->ts.type == BT_CHARACTER)
  750. {
  751. if (array->ts.kind == gfc_default_character_kind)
  752. f->value.function.name
  753. = gfc_get_string (PREFIX ("eoshift%d_%d_char"), n, shift->ts.kind);
  754. else
  755. f->value.function.name
  756. = gfc_get_string (PREFIX ("eoshift%d_%d_char%d"), n, shift->ts.kind,
  757. array->ts.kind);
  758. }
  759. else
  760. f->value.function.name
  761. = gfc_get_string (PREFIX ("eoshift%d_%d"), n, shift->ts.kind);
  762. }
  763. void
  764. gfc_resolve_exp (gfc_expr *f, gfc_expr *x)
  765. {
  766. f->ts = x->ts;
  767. f->value.function.name
  768. = gfc_get_string ("__exp_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
  769. }
  770. void
  771. gfc_resolve_exponent (gfc_expr *f, gfc_expr *x)
  772. {
  773. f->ts.type = BT_INTEGER;
  774. f->ts.kind = gfc_default_integer_kind;
  775. f->value.function.name = gfc_get_string ("__exponent_%d", x->ts.kind);
  776. }
  777. /* Resolve the EXTENDS_TYPE_OF intrinsic function. */
  778. void
  779. gfc_resolve_extends_type_of (gfc_expr *f, gfc_expr *a, gfc_expr *mo)
  780. {
  781. gfc_symbol *vtab;
  782. gfc_symtree *st;
  783. /* Prevent double resolution. */
  784. if (f->ts.type == BT_LOGICAL)
  785. return;
  786. /* Replace the first argument with the corresponding vtab. */
  787. if (a->ts.type == BT_CLASS)
  788. gfc_add_vptr_component (a);
  789. else if (a->ts.type == BT_DERIVED)
  790. {
  791. vtab = gfc_find_derived_vtab (a->ts.u.derived);
  792. /* Clear the old expr. */
  793. gfc_free_ref_list (a->ref);
  794. memset (a, '\0', sizeof (gfc_expr));
  795. /* Construct a new one. */
  796. a->expr_type = EXPR_VARIABLE;
  797. st = gfc_find_symtree (vtab->ns->sym_root, vtab->name);
  798. a->symtree = st;
  799. a->ts = vtab->ts;
  800. }
  801. /* Replace the second argument with the corresponding vtab. */
  802. if (mo->ts.type == BT_CLASS)
  803. gfc_add_vptr_component (mo);
  804. else if (mo->ts.type == BT_DERIVED)
  805. {
  806. vtab = gfc_find_derived_vtab (mo->ts.u.derived);
  807. /* Clear the old expr. */
  808. gfc_free_ref_list (mo->ref);
  809. memset (mo, '\0', sizeof (gfc_expr));
  810. /* Construct a new one. */
  811. mo->expr_type = EXPR_VARIABLE;
  812. st = gfc_find_symtree (vtab->ns->sym_root, vtab->name);
  813. mo->symtree = st;
  814. mo->ts = vtab->ts;
  815. }
  816. f->ts.type = BT_LOGICAL;
  817. f->ts.kind = 4;
  818. f->value.function.isym->formal->ts = a->ts;
  819. f->value.function.isym->formal->next->ts = mo->ts;
  820. /* Call library function. */
  821. f->value.function.name = gfc_get_string (PREFIX ("is_extension_of"));
  822. }
  823. void
  824. gfc_resolve_fdate (gfc_expr *f)
  825. {
  826. f->ts.type = BT_CHARACTER;
  827. f->ts.kind = gfc_default_character_kind;
  828. f->value.function.name = gfc_get_string (PREFIX ("fdate"));
  829. }
  830. void
  831. gfc_resolve_floor (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
  832. {
  833. f->ts.type = BT_INTEGER;
  834. f->ts.kind = (kind == NULL)
  835. ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
  836. f->value.function.name
  837. = gfc_get_string ("__floor%d_%c%d", f->ts.kind,
  838. gfc_type_letter (a->ts.type), a->ts.kind);
  839. }
  840. void
  841. gfc_resolve_fnum (gfc_expr *f, gfc_expr *n)
  842. {
  843. f->ts.type = BT_INTEGER;
  844. f->ts.kind = gfc_default_integer_kind;
  845. if (n->ts.kind != f->ts.kind)
  846. gfc_convert_type (n, &f->ts, 2);
  847. f->value.function.name = gfc_get_string (PREFIX ("fnum_i%d"), f->ts.kind);
  848. }
  849. void
  850. gfc_resolve_fraction (gfc_expr *f, gfc_expr *x)
  851. {
  852. f->ts = x->ts;
  853. f->value.function.name = gfc_get_string ("__fraction_%d", x->ts.kind);
  854. }
  855. /* Resolve single-argument g77 math intrinsics, eg BESY0, ERF. */
  856. void
  857. gfc_resolve_g77_math1 (gfc_expr *f, gfc_expr *x)
  858. {
  859. f->ts = x->ts;
  860. f->value.function.name = gfc_get_string ("<intrinsic>");
  861. }
  862. void
  863. gfc_resolve_gamma (gfc_expr *f, gfc_expr *x)
  864. {
  865. f->ts = x->ts;
  866. f->value.function.name
  867. = gfc_get_string ("__tgamma_%d", x->ts.kind);
  868. }
  869. void
  870. gfc_resolve_getcwd (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
  871. {
  872. f->ts.type = BT_INTEGER;
  873. f->ts.kind = 4;
  874. f->value.function.name = gfc_get_string (PREFIX ("getcwd"));
  875. }
  876. void
  877. gfc_resolve_getgid (gfc_expr *f)
  878. {
  879. f->ts.type = BT_INTEGER;
  880. f->ts.kind = 4;
  881. f->value.function.name = gfc_get_string (PREFIX ("getgid"));
  882. }
  883. void
  884. gfc_resolve_getpid (gfc_expr *f)
  885. {
  886. f->ts.type = BT_INTEGER;
  887. f->ts.kind = 4;
  888. f->value.function.name = gfc_get_string (PREFIX ("getpid"));
  889. }
  890. void
  891. gfc_resolve_getuid (gfc_expr *f)
  892. {
  893. f->ts.type = BT_INTEGER;
  894. f->ts.kind = 4;
  895. f->value.function.name = gfc_get_string (PREFIX ("getuid"));
  896. }
  897. void
  898. gfc_resolve_hostnm (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
  899. {
  900. f->ts.type = BT_INTEGER;
  901. f->ts.kind = 4;
  902. f->value.function.name = gfc_get_string (PREFIX ("hostnm"));
  903. }
  904. void
  905. gfc_resolve_hypot (gfc_expr *f, gfc_expr *x, gfc_expr *y ATTRIBUTE_UNUSED)
  906. {
  907. f->ts = x->ts;
  908. f->value.function.name = gfc_get_string ("__hypot_r%d", x->ts.kind);
  909. }
  910. void
  911. gfc_resolve_iall (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
  912. {
  913. resolve_transformational ("iall", f, array, dim, mask);
  914. }
  915. void
  916. gfc_resolve_iand (gfc_expr *f, gfc_expr *i, gfc_expr *j)
  917. {
  918. /* If the kind of i and j are different, then g77 cross-promoted the
  919. kinds to the largest value. The Fortran 95 standard requires the
  920. kinds to match. */
  921. if (i->ts.kind != j->ts.kind)
  922. {
  923. if (i->ts.kind == gfc_kind_max (i, j))
  924. gfc_convert_type (j, &i->ts, 2);
  925. else
  926. gfc_convert_type (i, &j->ts, 2);
  927. }
  928. f->ts = i->ts;
  929. f->value.function.name = gfc_get_string ("__iand_%d", i->ts.kind);
  930. }
  931. void
  932. gfc_resolve_iany (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
  933. {
  934. resolve_transformational ("iany", f, array, dim, mask);
  935. }
  936. void
  937. gfc_resolve_ibclr (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
  938. {
  939. f->ts = i->ts;
  940. f->value.function.name = gfc_get_string ("__ibclr_%d", i->ts.kind);
  941. }
  942. void
  943. gfc_resolve_ibits (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED,
  944. gfc_expr *len ATTRIBUTE_UNUSED)
  945. {
  946. f->ts = i->ts;
  947. f->value.function.name = gfc_get_string ("__ibits_%d", i->ts.kind);
  948. }
  949. void
  950. gfc_resolve_ibset (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
  951. {
  952. f->ts = i->ts;
  953. f->value.function.name = gfc_get_string ("__ibset_%d", i->ts.kind);
  954. }
  955. void
  956. gfc_resolve_iachar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
  957. {
  958. f->ts.type = BT_INTEGER;
  959. if (kind)
  960. f->ts.kind = mpz_get_si (kind->value.integer);
  961. else
  962. f->ts.kind = gfc_default_integer_kind;
  963. f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
  964. }
  965. void
  966. gfc_resolve_ichar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
  967. {
  968. f->ts.type = BT_INTEGER;
  969. if (kind)
  970. f->ts.kind = mpz_get_si (kind->value.integer);
  971. else
  972. f->ts.kind = gfc_default_integer_kind;
  973. f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
  974. }
  975. void
  976. gfc_resolve_idnint (gfc_expr *f, gfc_expr *a)
  977. {
  978. gfc_resolve_nint (f, a, NULL);
  979. }
  980. void
  981. gfc_resolve_ierrno (gfc_expr *f)
  982. {
  983. f->ts.type = BT_INTEGER;
  984. f->ts.kind = gfc_default_integer_kind;
  985. f->value.function.name = gfc_get_string (PREFIX ("ierrno_i%d"), f->ts.kind);
  986. }
  987. void
  988. gfc_resolve_ieor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
  989. {
  990. /* If the kind of i and j are different, then g77 cross-promoted the
  991. kinds to the largest value. The Fortran 95 standard requires the
  992. kinds to match. */
  993. if (i->ts.kind != j->ts.kind)
  994. {
  995. if (i->ts.kind == gfc_kind_max (i, j))
  996. gfc_convert_type (j, &i->ts, 2);
  997. else
  998. gfc_convert_type (i, &j->ts, 2);
  999. }
  1000. f->ts = i->ts;
  1001. f->value.function.name = gfc_get_string ("__ieor_%d", i->ts.kind);
  1002. }
  1003. void
  1004. gfc_resolve_ior (gfc_expr *f, gfc_expr *i, gfc_expr *j)
  1005. {
  1006. /* If the kind of i and j are different, then g77 cross-promoted the
  1007. kinds to the largest value. The Fortran 95 standard requires the
  1008. kinds to match. */
  1009. if (i->ts.kind != j->ts.kind)
  1010. {
  1011. if (i->ts.kind == gfc_kind_max (i, j))
  1012. gfc_convert_type (j, &i->ts, 2);
  1013. else
  1014. gfc_convert_type (i, &j->ts, 2);
  1015. }
  1016. f->ts = i->ts;
  1017. f->value.function.name = gfc_get_string ("__ior_%d", i->ts.kind);
  1018. }
  1019. void
  1020. gfc_resolve_index_func (gfc_expr *f, gfc_expr *str,
  1021. gfc_expr *sub_str ATTRIBUTE_UNUSED, gfc_expr *back,
  1022. gfc_expr *kind)
  1023. {
  1024. gfc_typespec ts;
  1025. gfc_clear_ts (&ts);
  1026. f->ts.type = BT_INTEGER;
  1027. if (kind)
  1028. f->ts.kind = mpz_get_si (kind->value.integer);
  1029. else
  1030. f->ts.kind = gfc_default_integer_kind;
  1031. if (back && back->ts.kind != gfc_default_integer_kind)
  1032. {
  1033. ts.type = BT_LOGICAL;
  1034. ts.kind = gfc_default_integer_kind;
  1035. ts.u.derived = NULL;
  1036. ts.u.cl = NULL;
  1037. gfc_convert_type (back, &ts, 2);
  1038. }
  1039. f->value.function.name
  1040. = gfc_get_string ("__index_%d_i%d", str->ts.kind, f->ts.kind);
  1041. }
  1042. void
  1043. gfc_resolve_int (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
  1044. {
  1045. f->ts.type = BT_INTEGER;
  1046. f->ts.kind = (kind == NULL)
  1047. ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
  1048. f->value.function.name
  1049. = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
  1050. gfc_type_letter (a->ts.type), a->ts.kind);
  1051. }
  1052. void
  1053. gfc_resolve_int2 (gfc_expr *f, gfc_expr *a)
  1054. {
  1055. f->ts.type = BT_INTEGER;
  1056. f->ts.kind = 2;
  1057. f->value.function.name
  1058. = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
  1059. gfc_type_letter (a->ts.type), a->ts.kind);
  1060. }
  1061. void
  1062. gfc_resolve_int8 (gfc_expr *f, gfc_expr *a)
  1063. {
  1064. f->ts.type = BT_INTEGER;
  1065. f->ts.kind = 8;
  1066. f->value.function.name
  1067. = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
  1068. gfc_type_letter (a->ts.type), a->ts.kind);
  1069. }
  1070. void
  1071. gfc_resolve_long (gfc_expr *f, gfc_expr *a)
  1072. {
  1073. f->ts.type = BT_INTEGER;
  1074. f->ts.kind = 4;
  1075. f->value.function.name
  1076. = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
  1077. gfc_type_letter (a->ts.type), a->ts.kind);
  1078. }
  1079. void
  1080. gfc_resolve_iparity (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
  1081. {
  1082. resolve_transformational ("iparity", f, array, dim, mask);
  1083. }
  1084. void
  1085. gfc_resolve_isatty (gfc_expr *f, gfc_expr *u)
  1086. {
  1087. gfc_typespec ts;
  1088. gfc_clear_ts (&ts);
  1089. f->ts.type = BT_LOGICAL;
  1090. f->ts.kind = gfc_default_integer_kind;
  1091. if (u->ts.kind != gfc_c_int_kind)
  1092. {
  1093. ts.type = BT_INTEGER;
  1094. ts.kind = gfc_c_int_kind;
  1095. ts.u.derived = NULL;
  1096. ts.u.cl = NULL;
  1097. gfc_convert_type (u, &ts, 2);
  1098. }
  1099. f->value.function.name = gfc_get_string (PREFIX ("isatty_l%d"), f->ts.kind);
  1100. }
  1101. void
  1102. gfc_resolve_ishft (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
  1103. {
  1104. f->ts = i->ts;
  1105. f->value.function.name
  1106. = gfc_get_string ("__ishft_%d_%d", i->ts.kind, shift->ts.kind);
  1107. }
  1108. void
  1109. gfc_resolve_rshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
  1110. {
  1111. f->ts = i->ts;
  1112. f->value.function.name
  1113. = gfc_get_string ("__rshift_%d_%d", i->ts.kind, shift->ts.kind);
  1114. }
  1115. void
  1116. gfc_resolve_lshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
  1117. {
  1118. f->ts = i->ts;
  1119. f->value.function.name
  1120. = gfc_get_string ("__lshift_%d_%d", i->ts.kind, shift->ts.kind);
  1121. }
  1122. void
  1123. gfc_resolve_ishftc (gfc_expr *f, gfc_expr *i, gfc_expr *shift, gfc_expr *size)
  1124. {
  1125. int s_kind;
  1126. s_kind = (size == NULL) ? gfc_default_integer_kind : size->ts.kind;
  1127. f->ts = i->ts;
  1128. f->value.function.name
  1129. = gfc_get_string ("__ishftc_%d_%d_%d", i->ts.kind, shift->ts.kind, s_kind);
  1130. }
  1131. void
  1132. gfc_resolve_kill (gfc_expr *f, gfc_expr *p ATTRIBUTE_UNUSED,
  1133. gfc_expr *s ATTRIBUTE_UNUSED)
  1134. {
  1135. f->ts.type = BT_INTEGER;
  1136. f->ts.kind = gfc_default_integer_kind;
  1137. f->value.function.name = gfc_get_string (PREFIX ("kill_i%d"), f->ts.kind);
  1138. }
  1139. void
  1140. gfc_resolve_lbound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
  1141. {
  1142. resolve_bound (f, array, dim, kind, "__lbound", false);
  1143. }
  1144. void
  1145. gfc_resolve_lcobound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
  1146. {
  1147. resolve_bound (f, array, dim, kind, "__lcobound", true);
  1148. }
  1149. void
  1150. gfc_resolve_len (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
  1151. {
  1152. f->ts.type = BT_INTEGER;
  1153. if (kind)
  1154. f->ts.kind = mpz_get_si (kind->value.integer);
  1155. else
  1156. f->ts.kind = gfc_default_integer_kind;
  1157. f->value.function.name
  1158. = gfc_get_string ("__len_%d_i%d", string->ts.kind,
  1159. gfc_default_integer_kind);
  1160. }
  1161. void
  1162. gfc_resolve_len_trim (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
  1163. {
  1164. f->ts.type = BT_INTEGER;
  1165. if (kind)
  1166. f->ts.kind = mpz_get_si (kind->value.integer);
  1167. else
  1168. f->ts.kind = gfc_default_integer_kind;
  1169. f->value.function.name = gfc_get_string ("__len_trim%d", string->ts.kind);
  1170. }
  1171. void
  1172. gfc_resolve_lgamma (gfc_expr *f, gfc_expr *x)
  1173. {
  1174. f->ts = x->ts;
  1175. f->value.function.name
  1176. = gfc_get_string ("__lgamma_%d", x->ts.kind);
  1177. }
  1178. void
  1179. gfc_resolve_link (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
  1180. gfc_expr *p2 ATTRIBUTE_UNUSED)
  1181. {
  1182. f->ts.type = BT_INTEGER;
  1183. f->ts.kind = gfc_default_integer_kind;
  1184. f->value.function.name = gfc_get_string (PREFIX ("link_i%d"), f->ts.kind);
  1185. }
  1186. void
  1187. gfc_resolve_loc (gfc_expr *f, gfc_expr *x)
  1188. {
  1189. f->ts.type= BT_INTEGER;
  1190. f->ts.kind = gfc_index_integer_kind;
  1191. f->value.function.name = gfc_get_string ("__loc_%d", x->ts.kind);
  1192. }
  1193. void
  1194. gfc_resolve_log (gfc_expr *f, gfc_expr *x)
  1195. {
  1196. f->ts = x->ts;
  1197. f->value.function.name
  1198. = gfc_get_string ("__log_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
  1199. }
  1200. void
  1201. gfc_resolve_log10 (gfc_expr *f, gfc_expr *x)
  1202. {
  1203. f->ts = x->ts;
  1204. f->value.function.name
  1205. = gfc_get_string ("__log10_%c%d", gfc_type_letter (x->ts.type),
  1206. x->ts.kind);
  1207. }
  1208. void
  1209. gfc_resolve_logical (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
  1210. {
  1211. f->ts.type = BT_LOGICAL;
  1212. f->ts.kind = (kind == NULL)
  1213. ? gfc_default_logical_kind : mpz_get_si (kind->value.integer);
  1214. f->rank = a->rank;
  1215. f->value.function.name
  1216. = gfc_get_string ("__logical_%d_%c%d", f->ts.kind,
  1217. gfc_type_letter (a->ts.type), a->ts.kind);
  1218. }
  1219. void
  1220. gfc_resolve_malloc (gfc_expr *f, gfc_expr *size)
  1221. {
  1222. if (size->ts.kind < gfc_index_integer_kind)
  1223. {
  1224. gfc_typespec ts;
  1225. gfc_clear_ts (&ts);
  1226. ts.type = BT_INTEGER;
  1227. ts.kind = gfc_index_integer_kind;
  1228. gfc_convert_type_warn (size, &ts, 2, 0);
  1229. }
  1230. f->ts.type = BT_INTEGER;
  1231. f->ts.kind = gfc_index_integer_kind;
  1232. f->value.function.name = gfc_get_string (PREFIX ("malloc"));
  1233. }
  1234. void
  1235. gfc_resolve_matmul (gfc_expr *f, gfc_expr *a, gfc_expr *b)
  1236. {
  1237. gfc_expr temp;
  1238. if (a->ts.type == BT_LOGICAL && b->ts.type == BT_LOGICAL)
  1239. {
  1240. f->ts.type = BT_LOGICAL;
  1241. f->ts.kind = gfc_default_logical_kind;
  1242. }
  1243. else
  1244. {
  1245. temp.expr_type = EXPR_OP;
  1246. gfc_clear_ts (&temp.ts);
  1247. temp.value.op.op = INTRINSIC_NONE;
  1248. temp.value.op.op1 = a;
  1249. temp.value.op.op2 = b;
  1250. gfc_type_convert_binary (&temp, 1);
  1251. f->ts = temp.ts;
  1252. }
  1253. f->rank = (a->rank == 2 && b->rank == 2) ? 2 : 1;
  1254. if (a->rank == 2 && b->rank == 2)
  1255. {
  1256. if (a->shape && b->shape)
  1257. {
  1258. f->shape = gfc_get_shape (f->rank);
  1259. mpz_init_set (f->shape[0], a->shape[0]);
  1260. mpz_init_set (f->shape[1], b->shape[1]);
  1261. }
  1262. }
  1263. else if (a->rank == 1)
  1264. {
  1265. if (b->shape)
  1266. {
  1267. f->shape = gfc_get_shape (f->rank);
  1268. mpz_init_set (f->shape[0], b->shape[1]);
  1269. }
  1270. }
  1271. else
  1272. {
  1273. /* b->rank == 1 and a->rank == 2 here, all other cases have
  1274. been caught in check.c. */
  1275. if (a->shape)
  1276. {
  1277. f->shape = gfc_get_shape (f->rank);
  1278. mpz_init_set (f->shape[0], a->shape[0]);
  1279. }
  1280. }
  1281. f->value.function.name
  1282. = gfc_get_string (PREFIX ("matmul_%c%d"), gfc_type_letter (f->ts.type),
  1283. f->ts.kind);
  1284. }
  1285. static void
  1286. gfc_resolve_minmax (const char *name, gfc_expr *f, gfc_actual_arglist *args)
  1287. {
  1288. gfc_actual_arglist *a;
  1289. f->ts.type = args->expr->ts.type;
  1290. f->ts.kind = args->expr->ts.kind;
  1291. /* Find the largest type kind. */
  1292. for (a = args->next; a; a = a->next)
  1293. {
  1294. if (a->expr->ts.kind > f->ts.kind)
  1295. f->ts.kind = a->expr->ts.kind;
  1296. }
  1297. /* Convert all parameters to the required kind. */
  1298. for (a = args; a; a = a->next)
  1299. {
  1300. if (a->expr->ts.kind != f->ts.kind)
  1301. gfc_convert_type (a->expr, &f->ts, 2);
  1302. }
  1303. f->value.function.name
  1304. = gfc_get_string (name, gfc_type_letter (f->ts.type), f->ts.kind);
  1305. }
  1306. void
  1307. gfc_resolve_max (gfc_expr *f, gfc_actual_arglist *args)
  1308. {
  1309. gfc_resolve_minmax ("__max_%c%d", f, args);
  1310. }
  1311. void
  1312. gfc_resolve_maxloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
  1313. gfc_expr *mask)
  1314. {
  1315. const char *name;
  1316. int i, j, idim;
  1317. f->ts.type = BT_INTEGER;
  1318. f->ts.kind = gfc_default_integer_kind;
  1319. if (dim == NULL)
  1320. {
  1321. f->rank = 1;
  1322. f->shape = gfc_get_shape (1);
  1323. mpz_init_set_si (f->shape[0], array->rank);
  1324. }
  1325. else
  1326. {
  1327. f->rank = array->rank - 1;
  1328. gfc_resolve_dim_arg (dim);
  1329. if (array->shape && dim->expr_type == EXPR_CONSTANT)
  1330. {
  1331. idim = (int) mpz_get_si (dim->value.integer);
  1332. f->shape = gfc_get_shape (f->rank);
  1333. for (i = 0, j = 0; i < f->rank; i++, j++)
  1334. {
  1335. if (i == (idim - 1))
  1336. j++;
  1337. mpz_init_set (f->shape[i], array->shape[j]);
  1338. }
  1339. }
  1340. }
  1341. if (mask)
  1342. {
  1343. if (mask->rank == 0)
  1344. name = "smaxloc";
  1345. else
  1346. name = "mmaxloc";
  1347. resolve_mask_arg (mask);
  1348. }
  1349. else
  1350. name = "maxloc";
  1351. f->value.function.name
  1352. = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
  1353. gfc_type_letter (array->ts.type), array->ts.kind);
  1354. }
  1355. void
  1356. gfc_resolve_maxval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
  1357. gfc_expr *mask)
  1358. {
  1359. const char *name;
  1360. int i, j, idim;
  1361. f->ts = array->ts;
  1362. if (dim != NULL)
  1363. {
  1364. f->rank = array->rank - 1;
  1365. gfc_resolve_dim_arg (dim);
  1366. if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
  1367. {
  1368. idim = (int) mpz_get_si (dim->value.integer);
  1369. f->shape = gfc_get_shape (f->rank);
  1370. for (i = 0, j = 0; i < f->rank; i++, j++)
  1371. {
  1372. if (i == (idim - 1))
  1373. j++;
  1374. mpz_init_set (f->shape[i], array->shape[j]);
  1375. }
  1376. }
  1377. }
  1378. if (mask)
  1379. {
  1380. if (mask->rank == 0)
  1381. name = "smaxval";
  1382. else
  1383. name = "mmaxval";
  1384. resolve_mask_arg (mask);
  1385. }
  1386. else
  1387. name = "maxval";
  1388. f->value.function.name
  1389. = gfc_get_string (PREFIX ("%s_%c%d"), name,
  1390. gfc_type_letter (array->ts.type), array->ts.kind);
  1391. }
  1392. void
  1393. gfc_resolve_mclock (gfc_expr *f)
  1394. {
  1395. f->ts.type = BT_INTEGER;
  1396. f->ts.kind = 4;
  1397. f->value.function.name = PREFIX ("mclock");
  1398. }
  1399. void
  1400. gfc_resolve_mclock8 (gfc_expr *f)
  1401. {
  1402. f->ts.type = BT_INTEGER;
  1403. f->ts.kind = 8;
  1404. f->value.function.name = PREFIX ("mclock8");
  1405. }
  1406. void
  1407. gfc_resolve_mask (gfc_expr *f, gfc_expr *i ATTRIBUTE_UNUSED,
  1408. gfc_expr *kind)
  1409. {
  1410. f->ts.type = BT_INTEGER;
  1411. f->ts.kind = kind ? mpz_get_si (kind->value.integer)
  1412. : gfc_default_integer_kind;
  1413. if (f->value.function.isym->id == GFC_ISYM_MASKL)
  1414. f->value.function.name = gfc_get_string ("__maskl_i%d", f->ts.kind);
  1415. else
  1416. f->value.function.name = gfc_get_string ("__maskr_i%d", f->ts.kind);
  1417. }
  1418. void
  1419. gfc_resolve_merge (gfc_expr *f, gfc_expr *tsource,
  1420. gfc_expr *fsource ATTRIBUTE_UNUSED,
  1421. gfc_expr *mask ATTRIBUTE_UNUSED)
  1422. {
  1423. if (tsource->ts.type == BT_CHARACTER && tsource->ref)
  1424. gfc_resolve_substring_charlen (tsource);
  1425. if (fsource->ts.type == BT_CHARACTER && fsource->ref)
  1426. gfc_resolve_substring_charlen (fsource);
  1427. if (tsource->ts.type == BT_CHARACTER)
  1428. check_charlen_present (tsource);
  1429. f->ts = tsource->ts;
  1430. f->value.function.name
  1431. = gfc_get_string ("__merge_%c%d", gfc_type_letter (tsource->ts.type),
  1432. tsource->ts.kind);
  1433. }
  1434. void
  1435. gfc_resolve_merge_bits (gfc_expr *f, gfc_expr *i,
  1436. gfc_expr *j ATTRIBUTE_UNUSED,
  1437. gfc_expr *mask ATTRIBUTE_UNUSED)
  1438. {
  1439. f->ts = i->ts;
  1440. f->value.function.name = gfc_get_string ("__merge_bits_i%d", i->ts.kind);
  1441. }
  1442. void
  1443. gfc_resolve_min (gfc_expr *f, gfc_actual_arglist *args)
  1444. {
  1445. gfc_resolve_minmax ("__min_%c%d", f, args);
  1446. }
  1447. void
  1448. gfc_resolve_minloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
  1449. gfc_expr *mask)
  1450. {
  1451. const char *name;
  1452. int i, j, idim;
  1453. f->ts.type = BT_INTEGER;
  1454. f->ts.kind = gfc_default_integer_kind;
  1455. if (dim == NULL)
  1456. {
  1457. f->rank = 1;
  1458. f->shape = gfc_get_shape (1);
  1459. mpz_init_set_si (f->shape[0], array->rank);
  1460. }
  1461. else
  1462. {
  1463. f->rank = array->rank - 1;
  1464. gfc_resolve_dim_arg (dim);
  1465. if (array->shape && dim->expr_type == EXPR_CONSTANT)
  1466. {
  1467. idim = (int) mpz_get_si (dim->value.integer);
  1468. f->shape = gfc_get_shape (f->rank);
  1469. for (i = 0, j = 0; i < f->rank; i++, j++)
  1470. {
  1471. if (i == (idim - 1))
  1472. j++;
  1473. mpz_init_set (f->shape[i], array->shape[j]);
  1474. }
  1475. }
  1476. }
  1477. if (mask)
  1478. {
  1479. if (mask->rank == 0)
  1480. name = "sminloc";
  1481. else
  1482. name = "mminloc";
  1483. resolve_mask_arg (mask);
  1484. }
  1485. else
  1486. name = "minloc";
  1487. f->value.function.name
  1488. = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
  1489. gfc_type_letter (array->ts.type), array->ts.kind);
  1490. }
  1491. void
  1492. gfc_resolve_minval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
  1493. gfc_expr *mask)
  1494. {
  1495. const char *name;
  1496. int i, j, idim;
  1497. f->ts = array->ts;
  1498. if (dim != NULL)
  1499. {
  1500. f->rank = array->rank - 1;
  1501. gfc_resolve_dim_arg (dim);
  1502. if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
  1503. {
  1504. idim = (int) mpz_get_si (dim->value.integer);
  1505. f->shape = gfc_get_shape (f->rank);
  1506. for (i = 0, j = 0; i < f->rank; i++, j++)
  1507. {
  1508. if (i == (idim - 1))
  1509. j++;
  1510. mpz_init_set (f->shape[i], array->shape[j]);
  1511. }
  1512. }
  1513. }
  1514. if (mask)
  1515. {
  1516. if (mask->rank == 0)
  1517. name = "sminval";
  1518. else
  1519. name = "mminval";
  1520. resolve_mask_arg (mask);
  1521. }
  1522. else
  1523. name = "minval";
  1524. f->value.function.name
  1525. = gfc_get_string (PREFIX ("%s_%c%d"), name,
  1526. gfc_type_letter (array->ts.type), array->ts.kind);
  1527. }
  1528. void
  1529. gfc_resolve_mod (gfc_expr *f, gfc_expr *a, gfc_expr *p)
  1530. {
  1531. f->ts.type = a->ts.type;
  1532. if (p != NULL)
  1533. f->ts.kind = gfc_kind_max (a,p);
  1534. else
  1535. f->ts.kind = a->ts.kind;
  1536. if (p != NULL && a->ts.kind != p->ts.kind)
  1537. {
  1538. if (a->ts.kind == gfc_kind_max (a,p))
  1539. gfc_convert_type (p, &a->ts, 2);
  1540. else
  1541. gfc_convert_type (a, &p->ts, 2);
  1542. }
  1543. f->value.function.name
  1544. = gfc_get_string ("__mod_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
  1545. }
  1546. void
  1547. gfc_resolve_modulo (gfc_expr *f, gfc_expr *a, gfc_expr *p)
  1548. {
  1549. f->ts.type = a->ts.type;
  1550. if (p != NULL)
  1551. f->ts.kind = gfc_kind_max (a,p);
  1552. else
  1553. f->ts.kind = a->ts.kind;
  1554. if (p != NULL && a->ts.kind != p->ts.kind)
  1555. {
  1556. if (a->ts.kind == gfc_kind_max (a,p))
  1557. gfc_convert_type (p, &a->ts, 2);
  1558. else
  1559. gfc_convert_type (a, &p->ts, 2);
  1560. }
  1561. f->value.function.name
  1562. = gfc_get_string ("__modulo_%c%d", gfc_type_letter (f->ts.type),
  1563. f->ts.kind);
  1564. }
  1565. void
  1566. gfc_resolve_nearest (gfc_expr *f, gfc_expr *a, gfc_expr *p)
  1567. {
  1568. if (p->ts.kind != a->ts.kind)
  1569. gfc_convert_type (p, &a->ts, 2);
  1570. f->ts = a->ts;
  1571. f->value.function.name
  1572. = gfc_get_string ("__nearest_%c%d", gfc_type_letter (a->ts.type),
  1573. a->ts.kind);
  1574. }
  1575. void
  1576. gfc_resolve_nint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
  1577. {
  1578. f->ts.type = BT_INTEGER;
  1579. f->ts.kind = (kind == NULL)
  1580. ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
  1581. f->value.function.name
  1582. = gfc_get_string ("__nint_%d_%d", f->ts.kind, a->ts.kind);
  1583. }
  1584. void
  1585. gfc_resolve_norm2 (gfc_expr *f, gfc_expr *array, gfc_expr *dim)
  1586. {
  1587. resolve_transformational ("norm2", f, array, dim, NULL);
  1588. }
  1589. void
  1590. gfc_resolve_not (gfc_expr *f, gfc_expr *i)
  1591. {
  1592. f->ts = i->ts;
  1593. f->value.function.name = gfc_get_string ("__not_%d", i->ts.kind);
  1594. }
  1595. void
  1596. gfc_resolve_or (gfc_expr *f, gfc_expr *i, gfc_expr *j)
  1597. {
  1598. f->ts.type = i->ts.type;
  1599. f->ts.kind = gfc_kind_max (i, j);
  1600. if (i->ts.kind != j->ts.kind)
  1601. {
  1602. if (i->ts.kind == gfc_kind_max (i, j))
  1603. gfc_convert_type (j, &i->ts, 2);
  1604. else
  1605. gfc_convert_type (i, &j->ts, 2);
  1606. }
  1607. f->value.function.name
  1608. = gfc_get_string ("__or_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
  1609. }
  1610. void
  1611. gfc_resolve_pack (gfc_expr *f, gfc_expr *array, gfc_expr *mask,
  1612. gfc_expr *vector ATTRIBUTE_UNUSED)
  1613. {
  1614. if (array->ts.type == BT_CHARACTER && array->ref)
  1615. gfc_resolve_substring_charlen (array);
  1616. f->ts = array->ts;
  1617. f->rank = 1;
  1618. resolve_mask_arg (mask);
  1619. if (mask->rank != 0)
  1620. {
  1621. if (array->ts.type == BT_CHARACTER)
  1622. f->value.function.name
  1623. = array->ts.kind == 1 ? PREFIX ("pack_char")
  1624. : gfc_get_string
  1625. (PREFIX ("pack_char%d"),
  1626. array->ts.kind);
  1627. else
  1628. f->value.function.name = PREFIX ("pack");
  1629. }
  1630. else
  1631. {
  1632. if (array->ts.type == BT_CHARACTER)
  1633. f->value.function.name
  1634. = array->ts.kind == 1 ? PREFIX ("pack_s_char")
  1635. : gfc_get_string
  1636. (PREFIX ("pack_s_char%d"),
  1637. array->ts.kind);
  1638. else
  1639. f->value.function.name = PREFIX ("pack_s");
  1640. }
  1641. }
  1642. void
  1643. gfc_resolve_parity (gfc_expr *f, gfc_expr *array, gfc_expr *dim)
  1644. {
  1645. resolve_transformational ("parity", f, array, dim, NULL);
  1646. }
  1647. void
  1648. gfc_resolve_product (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
  1649. gfc_expr *mask)
  1650. {
  1651. resolve_transformational ("product", f, array, dim, mask);
  1652. }
  1653. void
  1654. gfc_resolve_rank (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED)
  1655. {
  1656. f->ts.type = BT_INTEGER;
  1657. f->ts.kind = gfc_default_integer_kind;
  1658. f->value.function.name = gfc_get_string ("__rank");
  1659. }
  1660. void
  1661. gfc_resolve_real (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
  1662. {
  1663. f->ts.type = BT_REAL;
  1664. if (kind != NULL)
  1665. f->ts.kind = mpz_get_si (kind->value.integer);
  1666. else
  1667. f->ts.kind = (a->ts.type == BT_COMPLEX)
  1668. ? a->ts.kind : gfc_default_real_kind;
  1669. f->value.function.name
  1670. = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
  1671. gfc_type_letter (a->ts.type), a->ts.kind);
  1672. }
  1673. void
  1674. gfc_resolve_realpart (gfc_expr *f, gfc_expr *a)
  1675. {
  1676. f->ts.type = BT_REAL;
  1677. f->ts.kind = a->ts.kind;
  1678. f->value.function.name
  1679. = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
  1680. gfc_type_letter (a->ts.type), a->ts.kind);
  1681. }
  1682. void
  1683. gfc_resolve_rename (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
  1684. gfc_expr *p2 ATTRIBUTE_UNUSED)
  1685. {
  1686. f->ts.type = BT_INTEGER;
  1687. f->ts.kind = gfc_default_integer_kind;
  1688. f->value.function.name = gfc_get_string (PREFIX ("rename_i%d"), f->ts.kind);
  1689. }
  1690. void
  1691. gfc_resolve_repeat (gfc_expr *f, gfc_expr *string,
  1692. gfc_expr *ncopies)
  1693. {
  1694. int len;
  1695. gfc_expr *tmp;
  1696. f->ts.type = BT_CHARACTER;
  1697. f->ts.kind = string->ts.kind;
  1698. f->value.function.name = gfc_get_string ("__repeat_%d", string->ts.kind);
  1699. /* If possible, generate a character length. */
  1700. if (f->ts.u.cl == NULL)
  1701. f->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL);
  1702. tmp = NULL;
  1703. if (string->expr_type == EXPR_CONSTANT)
  1704. {
  1705. len = string->value.character.length;
  1706. tmp = gfc_get_int_expr (gfc_default_integer_kind, NULL , len);
  1707. }
  1708. else if (string->ts.u.cl && string->ts.u.cl->length)
  1709. {
  1710. tmp = gfc_copy_expr (string->ts.u.cl->length);
  1711. }
  1712. if (tmp)
  1713. f->ts.u.cl->length = gfc_multiply (tmp, gfc_copy_expr (ncopies));
  1714. }
  1715. void
  1716. gfc_resolve_reshape (gfc_expr *f, gfc_expr *source, gfc_expr *shape,
  1717. gfc_expr *pad ATTRIBUTE_UNUSED,
  1718. gfc_expr *order ATTRIBUTE_UNUSED)
  1719. {
  1720. mpz_t rank;
  1721. int kind;
  1722. int i;
  1723. if (source->ts.type == BT_CHARACTER && source->ref)
  1724. gfc_resolve_substring_charlen (source);
  1725. f->ts = source->ts;
  1726. gfc_array_size (shape, &rank);
  1727. f->rank = mpz_get_si (rank);
  1728. mpz_clear (rank);
  1729. switch (source->ts.type)
  1730. {
  1731. case BT_COMPLEX:
  1732. case BT_REAL:
  1733. case BT_INTEGER:
  1734. case BT_LOGICAL:
  1735. case BT_CHARACTER:
  1736. kind = source->ts.kind;
  1737. break;
  1738. default:
  1739. kind = 0;
  1740. break;
  1741. }
  1742. switch (kind)
  1743. {
  1744. case 4:
  1745. case 8:
  1746. case 10:
  1747. case 16:
  1748. if (source->ts.type == BT_COMPLEX || source->ts.type == BT_REAL)
  1749. f->value.function.name
  1750. = gfc_get_string (PREFIX ("reshape_%c%d"),
  1751. gfc_type_letter (source->ts.type),
  1752. source->ts.kind);
  1753. else if (source->ts.type == BT_CHARACTER)
  1754. f->value.function.name = gfc_get_string (PREFIX ("reshape_char%d"),
  1755. kind);
  1756. else
  1757. f->value.function.name
  1758. = gfc_get_string (PREFIX ("reshape_%d"), source->ts.kind);
  1759. break;
  1760. default:
  1761. f->value.function.name = (source->ts.type == BT_CHARACTER
  1762. ? PREFIX ("reshape_char") : PREFIX ("reshape"));
  1763. break;
  1764. }
  1765. if (shape->expr_type == EXPR_ARRAY && gfc_is_constant_expr (shape))
  1766. {
  1767. gfc_constructor *c;
  1768. f->shape = gfc_get_shape (f->rank);
  1769. c = gfc_constructor_first (shape->value.constructor);
  1770. for (i = 0; i < f->rank; i++)
  1771. {
  1772. mpz_init_set (f->shape[i], c->expr->value.integer);
  1773. c = gfc_constructor_next (c);
  1774. }
  1775. }
  1776. /* Force-convert both SHAPE and ORDER to index_kind so that we don't need
  1777. so many runtime variations. */
  1778. if (shape->ts.kind != gfc_index_integer_kind)
  1779. {
  1780. gfc_typespec ts = shape->ts;
  1781. ts.kind = gfc_index_integer_kind;
  1782. gfc_convert_type_warn (shape, &ts, 2, 0);
  1783. }
  1784. if (order && order->ts.kind != gfc_index_integer_kind)
  1785. gfc_convert_type_warn (order, &shape->ts, 2, 0);
  1786. }
  1787. void
  1788. gfc_resolve_rrspacing (gfc_expr *f, gfc_expr *x)
  1789. {
  1790. f->ts = x->ts;
  1791. f->value.function.name = gfc_get_string ("__rrspacing_%d", x->ts.kind);
  1792. }
  1793. void
  1794. gfc_resolve_scale (gfc_expr *f, gfc_expr *x, gfc_expr *i ATTRIBUTE_UNUSED)
  1795. {
  1796. f->ts = x->ts;
  1797. f->value.function.name = gfc_get_string ("__scale_%d", x->ts.kind);
  1798. }
  1799. void
  1800. gfc_resolve_scan (gfc_expr *f, gfc_expr *string,
  1801. gfc_expr *set ATTRIBUTE_UNUSED,
  1802. gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
  1803. {
  1804. f->ts.type = BT_INTEGER;
  1805. if (kind)
  1806. f->ts.kind = mpz_get_si (kind->value.integer);
  1807. else
  1808. f->ts.kind = gfc_default_integer_kind;
  1809. f->value.function.name = gfc_get_string ("__scan_%d", string->ts.kind);
  1810. }
  1811. void
  1812. gfc_resolve_secnds (gfc_expr *t1, gfc_expr *t0)
  1813. {
  1814. t1->ts = t0->ts;
  1815. t1->value.function.name = gfc_get_string (PREFIX ("secnds"));
  1816. }
  1817. void
  1818. gfc_resolve_set_exponent (gfc_expr *f, gfc_expr *x,
  1819. gfc_expr *i ATTRIBUTE_UNUSED)
  1820. {
  1821. f->ts = x->ts;
  1822. f->value.function.name = gfc_get_string ("__set_exponent_%d", x->ts.kind);
  1823. }
  1824. void
  1825. gfc_resolve_shape (gfc_expr *f, gfc_expr *array, gfc_expr *kind)
  1826. {
  1827. f->ts.type = BT_INTEGER;
  1828. if (kind)
  1829. f->ts.kind = mpz_get_si (kind->value.integer);
  1830. else
  1831. f->ts.kind = gfc_default_integer_kind;
  1832. f->rank = 1;
  1833. if (array->rank != -1)
  1834. {
  1835. f->shape = gfc_get_shape (1);
  1836. mpz_init_set_ui (f->shape[0], array->rank);
  1837. }
  1838. f->value.function.name = gfc_get_string (PREFIX ("shape_%d"), f->ts.kind);
  1839. }
  1840. void
  1841. gfc_resolve_shift (gfc_expr *f, gfc_expr *i, gfc_expr *shift ATTRIBUTE_UNUSED)
  1842. {
  1843. f->ts = i->ts;
  1844. if (f->value.function.isym->id == GFC_ISYM_SHIFTA)
  1845. f->value.function.name = gfc_get_string ("shifta_i%d", f->ts.kind);
  1846. else if (f->value.function.isym->id == GFC_ISYM_SHIFTL)
  1847. f->value.function.name = gfc_get_string ("shiftl_i%d", f->ts.kind);
  1848. else if (f->value.function.isym->id == GFC_ISYM_SHIFTR)
  1849. f->value.function.name = gfc_get_string ("shiftr_i%d", f->ts.kind);
  1850. else
  1851. gcc_unreachable ();
  1852. }
  1853. void
  1854. gfc_resolve_sign (gfc_expr *f, gfc_expr *a, gfc_expr *b ATTRIBUTE_UNUSED)
  1855. {
  1856. f->ts = a->ts;
  1857. f->value.function.name
  1858. = gfc_get_string ("__sign_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
  1859. }
  1860. void
  1861. gfc_resolve_signal (gfc_expr *f, gfc_expr *number, gfc_expr *handler)
  1862. {
  1863. f->ts.type = BT_INTEGER;
  1864. f->ts.kind = gfc_c_int_kind;
  1865. /* handler can be either BT_INTEGER or BT_PROCEDURE */
  1866. if (handler->ts.type == BT_INTEGER)
  1867. {
  1868. if (handler->ts.kind != gfc_c_int_kind)
  1869. gfc_convert_type (handler, &f->ts, 2);
  1870. f->value.function.name = gfc_get_string (PREFIX ("signal_func_int"));
  1871. }
  1872. else
  1873. f->value.function.name = gfc_get_string (PREFIX ("signal_func"));
  1874. if (number->ts.kind != gfc_c_int_kind)
  1875. gfc_convert_type (number, &f->ts, 2);
  1876. }
  1877. void
  1878. gfc_resolve_sin (gfc_expr *f, gfc_expr *x)
  1879. {
  1880. f->ts = x->ts;
  1881. f->value.function.name
  1882. = gfc_get_string ("__sin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
  1883. }
  1884. void
  1885. gfc_resolve_sinh (gfc_expr *f, gfc_expr *x)
  1886. {
  1887. f->ts = x->ts;
  1888. f->value.function.name
  1889. = gfc_get_string ("__sinh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
  1890. }
  1891. void
  1892. gfc_resolve_size (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
  1893. gfc_expr *dim ATTRIBUTE_UNUSED, gfc_expr *kind)
  1894. {
  1895. f->ts.type = BT_INTEGER;
  1896. if (kind)
  1897. f->ts.kind = mpz_get_si (kind->value.integer);
  1898. else
  1899. f->ts.kind = gfc_default_integer_kind;
  1900. }
  1901. void
  1902. gfc_resolve_stride (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
  1903. gfc_expr *dim ATTRIBUTE_UNUSED)
  1904. {
  1905. f->ts.type = BT_INTEGER;
  1906. f->ts.kind = gfc_index_integer_kind;
  1907. }
  1908. void
  1909. gfc_resolve_spacing (gfc_expr *f, gfc_expr *x)
  1910. {
  1911. f->ts = x->ts;
  1912. f->value.function.name = gfc_get_string ("__spacing_%d", x->ts.kind);
  1913. }
  1914. void
  1915. gfc_resolve_spread (gfc_expr *f, gfc_expr *source, gfc_expr *dim,
  1916. gfc_expr *ncopies)
  1917. {
  1918. if (source->ts.type == BT_CHARACTER && source->ref)
  1919. gfc_resolve_substring_charlen (source);
  1920. if (source->ts.type == BT_CHARACTER)
  1921. check_charlen_present (source);
  1922. f->ts = source->ts;
  1923. f->rank = source->rank + 1;
  1924. if (source->rank == 0)
  1925. {
  1926. if (source->ts.type == BT_CHARACTER)
  1927. f->value.function.name
  1928. = source->ts.kind == 1 ? PREFIX ("spread_char_scalar")
  1929. : gfc_get_string
  1930. (PREFIX ("spread_char%d_scalar"),
  1931. source->ts.kind);
  1932. else
  1933. f->value.function.name = PREFIX ("spread_scalar");
  1934. }
  1935. else
  1936. {
  1937. if (source->ts.type == BT_CHARACTER)
  1938. f->value.function.name
  1939. = source->ts.kind == 1 ? PREFIX ("spread_char")
  1940. : gfc_get_string
  1941. (PREFIX ("spread_char%d"),
  1942. source->ts.kind);
  1943. else
  1944. f->value.function.name = PREFIX ("spread");
  1945. }
  1946. if (dim && gfc_is_constant_expr (dim)
  1947. && ncopies && gfc_is_constant_expr (ncopies) && source->shape[0])
  1948. {
  1949. int i, idim;
  1950. idim = mpz_get_ui (dim->value.integer);
  1951. f->shape = gfc_get_shape (f->rank);
  1952. for (i = 0; i < (idim - 1); i++)
  1953. mpz_init_set (f->shape[i], source->shape[i]);
  1954. mpz_init_set (f->shape[idim - 1], ncopies->value.integer);
  1955. for (i = idim; i < f->rank ; i++)
  1956. mpz_init_set (f->shape[i], source->shape[i-1]);
  1957. }
  1958. gfc_resolve_dim_arg (dim);
  1959. gfc_resolve_index (ncopies, 1);
  1960. }
  1961. void
  1962. gfc_resolve_sqrt (gfc_expr *f, gfc_expr *x)
  1963. {
  1964. f->ts = x->ts;
  1965. f->value.function.name
  1966. = gfc_get_string ("__sqrt_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
  1967. }
  1968. /* Resolve the g77 compatibility function STAT AND FSTAT. */
  1969. void
  1970. gfc_resolve_stat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
  1971. gfc_expr *a ATTRIBUTE_UNUSED)
  1972. {
  1973. f->ts.type = BT_INTEGER;
  1974. f->ts.kind = gfc_default_integer_kind;
  1975. f->value.function.name = gfc_get_string (PREFIX ("stat_i%d"), f->ts.kind);
  1976. }
  1977. void
  1978. gfc_resolve_lstat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
  1979. gfc_expr *a ATTRIBUTE_UNUSED)
  1980. {
  1981. f->ts.type = BT_INTEGER;
  1982. f->ts.kind = gfc_default_integer_kind;
  1983. f->value.function.name = gfc_get_string (PREFIX ("lstat_i%d"), f->ts.kind);
  1984. }
  1985. void
  1986. gfc_resolve_fstat (gfc_expr *f, gfc_expr *n, gfc_expr *a ATTRIBUTE_UNUSED)
  1987. {
  1988. f->ts.type = BT_INTEGER;
  1989. f->ts.kind = gfc_default_integer_kind;
  1990. if (n->ts.kind != f->ts.kind)
  1991. gfc_convert_type (n, &f->ts, 2);
  1992. f->value.function.name = gfc_get_string (PREFIX ("fstat_i%d"), f->ts.kind);
  1993. }
  1994. void
  1995. gfc_resolve_fgetc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
  1996. {
  1997. gfc_typespec ts;
  1998. gfc_clear_ts (&ts);
  1999. f->ts.type = BT_INTEGER;
  2000. f->ts.kind = gfc_c_int_kind;
  2001. if (u->ts.kind != gfc_c_int_kind)
  2002. {
  2003. ts.type = BT_INTEGER;
  2004. ts.kind = gfc_c_int_kind;
  2005. ts.u.derived = NULL;
  2006. ts.u.cl = NULL;
  2007. gfc_convert_type (u, &ts, 2);
  2008. }
  2009. f->value.function.name = gfc_get_string (PREFIX ("fgetc"));
  2010. }
  2011. void
  2012. gfc_resolve_fget (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
  2013. {
  2014. f->ts.type = BT_INTEGER;
  2015. f->ts.kind = gfc_c_int_kind;
  2016. f->value.function.name = gfc_get_string (PREFIX ("fget"));
  2017. }
  2018. void
  2019. gfc_resolve_fputc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
  2020. {
  2021. gfc_typespec ts;
  2022. gfc_clear_ts (&ts);
  2023. f->ts.type = BT_INTEGER;
  2024. f->ts.kind = gfc_c_int_kind;
  2025. if (u->ts.kind != gfc_c_int_kind)
  2026. {
  2027. ts.type = BT_INTEGER;
  2028. ts.kind = gfc_c_int_kind;
  2029. ts.u.derived = NULL;
  2030. ts.u.cl = NULL;
  2031. gfc_convert_type (u, &ts, 2);
  2032. }
  2033. f->value.function.name = gfc_get_string (PREFIX ("fputc"));
  2034. }
  2035. void
  2036. gfc_resolve_fput (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
  2037. {
  2038. f->ts.type = BT_INTEGER;
  2039. f->ts.kind = gfc_c_int_kind;
  2040. f->value.function.name = gfc_get_string (PREFIX ("fput"));
  2041. }
  2042. void
  2043. gfc_resolve_ftell (gfc_expr *f, gfc_expr *u)
  2044. {
  2045. gfc_typespec ts;
  2046. gfc_clear_ts (&ts);
  2047. f->ts.type = BT_INTEGER;
  2048. f->ts.kind = gfc_intio_kind;
  2049. if (u->ts.kind != gfc_c_int_kind)
  2050. {
  2051. ts.type = BT_INTEGER;
  2052. ts.kind = gfc_c_int_kind;
  2053. ts.u.derived = NULL;
  2054. ts.u.cl = NULL;
  2055. gfc_convert_type (u, &ts, 2);
  2056. }
  2057. f->value.function.name = gfc_get_string (PREFIX ("ftell2"));
  2058. }
  2059. void
  2060. gfc_resolve_storage_size (gfc_expr *f, gfc_expr *a ATTRIBUTE_UNUSED,
  2061. gfc_expr *kind)
  2062. {
  2063. f->ts.type = BT_INTEGER;
  2064. if (kind)
  2065. f->ts.kind = mpz_get_si (kind->value.integer);
  2066. else
  2067. f->ts.kind = gfc_default_integer_kind;
  2068. }
  2069. void
  2070. gfc_resolve_sum (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
  2071. {
  2072. resolve_transformational ("sum", f, array, dim, mask);
  2073. }
  2074. void
  2075. gfc_resolve_symlnk (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
  2076. gfc_expr *p2 ATTRIBUTE_UNUSED)
  2077. {
  2078. f->ts.type = BT_INTEGER;
  2079. f->ts.kind = gfc_default_integer_kind;
  2080. f->value.function.name = gfc_get_string (PREFIX ("symlnk_i%d"), f->ts.kind);
  2081. }
  2082. /* Resolve the g77 compatibility function SYSTEM. */
  2083. void
  2084. gfc_resolve_system (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
  2085. {
  2086. f->ts.type = BT_INTEGER;
  2087. f->ts.kind = 4;
  2088. f->value.function.name = gfc_get_string (PREFIX ("system"));
  2089. }
  2090. void
  2091. gfc_resolve_tan (gfc_expr *f, gfc_expr *x)
  2092. {
  2093. f->ts = x->ts;
  2094. f->value.function.name
  2095. = gfc_get_string ("__tan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
  2096. }
  2097. void
  2098. gfc_resolve_tanh (gfc_expr *f, gfc_expr *x)
  2099. {
  2100. f->ts = x->ts;
  2101. f->value.function.name
  2102. = gfc_get_string ("__tanh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
  2103. }
  2104. void
  2105. gfc_resolve_image_index (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
  2106. gfc_expr *sub ATTRIBUTE_UNUSED)
  2107. {
  2108. static char image_index[] = "__image_index";
  2109. f->ts.type = BT_INTEGER;
  2110. f->ts.kind = gfc_default_integer_kind;
  2111. f->value.function.name = image_index;
  2112. }
  2113. void
  2114. gfc_resolve_this_image (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
  2115. gfc_expr *distance ATTRIBUTE_UNUSED)
  2116. {
  2117. static char this_image[] = "__this_image";
  2118. if (array && gfc_is_coarray (array))
  2119. resolve_bound (f, array, dim, NULL, "__this_image", true);
  2120. else
  2121. {
  2122. f->ts.type = BT_INTEGER;
  2123. f->ts.kind = gfc_default_integer_kind;
  2124. f->value.function.name = this_image;
  2125. }
  2126. }
  2127. void
  2128. gfc_resolve_time (gfc_expr *f)
  2129. {
  2130. f->ts.type = BT_INTEGER;
  2131. f->ts.kind = 4;
  2132. f->value.function.name = gfc_get_string (PREFIX ("time_func"));
  2133. }
  2134. void
  2135. gfc_resolve_time8 (gfc_expr *f)
  2136. {
  2137. f->ts.type = BT_INTEGER;
  2138. f->ts.kind = 8;
  2139. f->value.function.name = gfc_get_string (PREFIX ("time8_func"));
  2140. }
  2141. void
  2142. gfc_resolve_transfer (gfc_expr *f, gfc_expr *source ATTRIBUTE_UNUSED,
  2143. gfc_expr *mold, gfc_expr *size)
  2144. {
  2145. /* TODO: Make this do something meaningful. */
  2146. static char transfer0[] = "__transfer0", transfer1[] = "__transfer1";
  2147. if (mold->ts.type == BT_CHARACTER
  2148. && !mold->ts.u.cl->length
  2149. && gfc_is_constant_expr (mold))
  2150. {
  2151. int len;
  2152. if (mold->expr_type == EXPR_CONSTANT)
  2153. {
  2154. len = mold->value.character.length;
  2155. mold->ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind,
  2156. NULL, len);
  2157. }
  2158. else
  2159. {
  2160. gfc_constructor *c = gfc_constructor_first (mold->value.constructor);
  2161. len = c->expr->value.character.length;
  2162. mold->ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind,
  2163. NULL, len);
  2164. }
  2165. }
  2166. f->ts = mold->ts;
  2167. if (size == NULL && mold->rank == 0)
  2168. {
  2169. f->rank = 0;
  2170. f->value.function.name = transfer0;
  2171. }
  2172. else
  2173. {
  2174. f->rank = 1;
  2175. f->value.function.name = transfer1;
  2176. if (size && gfc_is_constant_expr (size))
  2177. {
  2178. f->shape = gfc_get_shape (1);
  2179. mpz_init_set (f->shape[0], size->value.integer);
  2180. }
  2181. }
  2182. }
  2183. void
  2184. gfc_resolve_transpose (gfc_expr *f, gfc_expr *matrix)
  2185. {
  2186. if (matrix->ts.type == BT_CHARACTER && matrix->ref)
  2187. gfc_resolve_substring_charlen (matrix);
  2188. f->ts = matrix->ts;
  2189. f->rank = 2;
  2190. if (matrix->shape)
  2191. {
  2192. f->shape = gfc_get_shape (2);
  2193. mpz_init_set (f->shape[0], matrix->shape[1]);
  2194. mpz_init_set (f->shape[1], matrix->shape[0]);
  2195. }
  2196. switch (matrix->ts.kind)
  2197. {
  2198. case 4:
  2199. case 8:
  2200. case 10:
  2201. case 16:
  2202. switch (matrix->ts.type)
  2203. {
  2204. case BT_REAL:
  2205. case BT_COMPLEX:
  2206. f->value.function.name
  2207. = gfc_get_string (PREFIX ("transpose_%c%d"),
  2208. gfc_type_letter (matrix->ts.type),
  2209. matrix->ts.kind);
  2210. break;
  2211. case BT_INTEGER:
  2212. case BT_LOGICAL:
  2213. /* Use the integer routines for real and logical cases. This
  2214. assumes they all have the same alignment requirements. */
  2215. f->value.function.name
  2216. = gfc_get_string (PREFIX ("transpose_i%d"), matrix->ts.kind);
  2217. break;
  2218. default:
  2219. if (matrix->ts.type == BT_CHARACTER && matrix->ts.kind == 4)
  2220. f->value.function.name = PREFIX ("transpose_char4");
  2221. else
  2222. f->value.function.name = PREFIX ("transpose");
  2223. break;
  2224. }
  2225. break;
  2226. default:
  2227. f->value.function.name = (matrix->ts.type == BT_CHARACTER
  2228. ? PREFIX ("transpose_char")
  2229. : PREFIX ("transpose"));
  2230. break;
  2231. }
  2232. }
  2233. void
  2234. gfc_resolve_trim (gfc_expr *f, gfc_expr *string)
  2235. {
  2236. f->ts.type = BT_CHARACTER;
  2237. f->ts.kind = string->ts.kind;
  2238. f->value.function.name = gfc_get_string ("__trim_%d", string->ts.kind);
  2239. }
  2240. void
  2241. gfc_resolve_ubound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
  2242. {
  2243. resolve_bound (f, array, dim, kind, "__ubound", false);
  2244. }
  2245. void
  2246. gfc_resolve_ucobound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
  2247. {
  2248. resolve_bound (f, array, dim, kind, "__ucobound", true);
  2249. }
  2250. /* Resolve the g77 compatibility function UMASK. */
  2251. void
  2252. gfc_resolve_umask (gfc_expr *f, gfc_expr *n)
  2253. {
  2254. f->ts.type = BT_INTEGER;
  2255. f->ts.kind = n->ts.kind;
  2256. f->value.function.name = gfc_get_string (PREFIX ("umask_i%d"), n->ts.kind);
  2257. }
  2258. /* Resolve the g77 compatibility function UNLINK. */
  2259. void
  2260. gfc_resolve_unlink (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
  2261. {
  2262. f->ts.type = BT_INTEGER;
  2263. f->ts.kind = 4;
  2264. f->value.function.name = gfc_get_string (PREFIX ("unlink"));
  2265. }
  2266. void
  2267. gfc_resolve_ttynam (gfc_expr *f, gfc_expr *unit)
  2268. {
  2269. gfc_typespec ts;
  2270. gfc_clear_ts (&ts);
  2271. f->ts.type = BT_CHARACTER;
  2272. f->ts.kind = gfc_default_character_kind;
  2273. if (unit->ts.kind != gfc_c_int_kind)
  2274. {
  2275. ts.type = BT_INTEGER;
  2276. ts.kind = gfc_c_int_kind;
  2277. ts.u.derived = NULL;
  2278. ts.u.cl = NULL;
  2279. gfc_convert_type (unit, &ts, 2);
  2280. }
  2281. f->value.function.name = gfc_get_string (PREFIX ("ttynam"));
  2282. }
  2283. void
  2284. gfc_resolve_unpack (gfc_expr *f, gfc_expr *vector, gfc_expr *mask,
  2285. gfc_expr *field ATTRIBUTE_UNUSED)
  2286. {
  2287. if (vector->ts.type == BT_CHARACTER && vector->ref)
  2288. gfc_resolve_substring_charlen (vector);
  2289. f->ts = vector->ts;
  2290. f->rank = mask->rank;
  2291. resolve_mask_arg (mask);
  2292. if (vector->ts.type == BT_CHARACTER)
  2293. {
  2294. if (vector->ts.kind == 1)
  2295. f->value.function.name
  2296. = gfc_get_string (PREFIX ("unpack%d_char"), field->rank > 0 ? 1 : 0);
  2297. else
  2298. f->value.function.name
  2299. = gfc_get_string (PREFIX ("unpack%d_char%d"),
  2300. field->rank > 0 ? 1 : 0, vector->ts.kind);
  2301. }
  2302. else
  2303. f->value.function.name
  2304. = gfc_get_string (PREFIX ("unpack%d"), field->rank > 0 ? 1 : 0);
  2305. }
  2306. void
  2307. gfc_resolve_verify (gfc_expr *f, gfc_expr *string,
  2308. gfc_expr *set ATTRIBUTE_UNUSED,
  2309. gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
  2310. {
  2311. f->ts.type = BT_INTEGER;
  2312. if (kind)
  2313. f->ts.kind = mpz_get_si (kind->value.integer);
  2314. else
  2315. f->ts.kind = gfc_default_integer_kind;
  2316. f->value.function.name = gfc_get_string ("__verify_%d", string->ts.kind);
  2317. }
  2318. void
  2319. gfc_resolve_xor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
  2320. {
  2321. f->ts.type = i->ts.type;
  2322. f->ts.kind = gfc_kind_max (i, j);
  2323. if (i->ts.kind != j->ts.kind)
  2324. {
  2325. if (i->ts.kind == gfc_kind_max (i, j))
  2326. gfc_convert_type (j, &i->ts, 2);
  2327. else
  2328. gfc_convert_type (i, &j->ts, 2);
  2329. }
  2330. f->value.function.name
  2331. = gfc_get_string ("__xor_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
  2332. }
  2333. /* Intrinsic subroutine resolution. */
  2334. void
  2335. gfc_resolve_alarm_sub (gfc_code *c)
  2336. {
  2337. const char *name;
  2338. gfc_expr *seconds, *handler;
  2339. gfc_typespec ts;
  2340. gfc_clear_ts (&ts);
  2341. seconds = c->ext.actual->expr;
  2342. handler = c->ext.actual->next->expr;
  2343. ts.type = BT_INTEGER;
  2344. ts.kind = gfc_c_int_kind;
  2345. /* handler can be either BT_INTEGER or BT_PROCEDURE.
  2346. In all cases, the status argument is of default integer kind
  2347. (enforced in check.c) so that the function suffix is fixed. */
  2348. if (handler->ts.type == BT_INTEGER)
  2349. {
  2350. if (handler->ts.kind != gfc_c_int_kind)
  2351. gfc_convert_type (handler, &ts, 2);
  2352. name = gfc_get_string (PREFIX ("alarm_sub_int_i%d"),
  2353. gfc_default_integer_kind);
  2354. }
  2355. else
  2356. name = gfc_get_string (PREFIX ("alarm_sub_i%d"),
  2357. gfc_default_integer_kind);
  2358. if (seconds->ts.kind != gfc_c_int_kind)
  2359. gfc_convert_type (seconds, &ts, 2);
  2360. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2361. }
  2362. void
  2363. gfc_resolve_cpu_time (gfc_code *c)
  2364. {
  2365. const char *name;
  2366. name = gfc_get_string (PREFIX ("cpu_time_%d"), c->ext.actual->expr->ts.kind);
  2367. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2368. }
  2369. /* Create a formal arglist based on an actual one and set the INTENTs given. */
  2370. static gfc_formal_arglist*
  2371. create_formal_for_intents (gfc_actual_arglist* actual, const sym_intent* ints)
  2372. {
  2373. gfc_formal_arglist* head;
  2374. gfc_formal_arglist* tail;
  2375. int i;
  2376. if (!actual)
  2377. return NULL;
  2378. head = tail = gfc_get_formal_arglist ();
  2379. for (i = 0; actual; actual = actual->next, tail = tail->next, ++i)
  2380. {
  2381. gfc_symbol* sym;
  2382. sym = gfc_new_symbol ("dummyarg", NULL);
  2383. sym->ts = actual->expr->ts;
  2384. sym->attr.intent = ints[i];
  2385. tail->sym = sym;
  2386. if (actual->next)
  2387. tail->next = gfc_get_formal_arglist ();
  2388. }
  2389. return head;
  2390. }
  2391. void
  2392. gfc_resolve_atomic_def (gfc_code *c)
  2393. {
  2394. const char *name = "atomic_define";
  2395. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2396. }
  2397. void
  2398. gfc_resolve_atomic_ref (gfc_code *c)
  2399. {
  2400. const char *name = "atomic_ref";
  2401. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2402. }
  2403. void
  2404. gfc_resolve_mvbits (gfc_code *c)
  2405. {
  2406. static const sym_intent INTENTS[] = {INTENT_IN, INTENT_IN, INTENT_IN,
  2407. INTENT_INOUT, INTENT_IN};
  2408. const char *name;
  2409. gfc_typespec ts;
  2410. gfc_clear_ts (&ts);
  2411. /* FROMPOS, LEN and TOPOS are restricted to small values. As such,
  2412. they will be converted so that they fit into a C int. */
  2413. ts.type = BT_INTEGER;
  2414. ts.kind = gfc_c_int_kind;
  2415. if (c->ext.actual->next->expr->ts.kind != gfc_c_int_kind)
  2416. gfc_convert_type (c->ext.actual->next->expr, &ts, 2);
  2417. if (c->ext.actual->next->next->expr->ts.kind != gfc_c_int_kind)
  2418. gfc_convert_type (c->ext.actual->next->next->expr, &ts, 2);
  2419. if (c->ext.actual->next->next->next->next->expr->ts.kind != gfc_c_int_kind)
  2420. gfc_convert_type (c->ext.actual->next->next->next->next->expr, &ts, 2);
  2421. /* TO and FROM are guaranteed to have the same kind parameter. */
  2422. name = gfc_get_string (PREFIX ("mvbits_i%d"),
  2423. c->ext.actual->expr->ts.kind);
  2424. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2425. /* Mark as elemental subroutine as this does not happen automatically. */
  2426. c->resolved_sym->attr.elemental = 1;
  2427. /* Create a dummy formal arglist so the INTENTs are known later for purpose
  2428. of creating temporaries. */
  2429. c->resolved_sym->formal = create_formal_for_intents (c->ext.actual, INTENTS);
  2430. }
  2431. void
  2432. gfc_resolve_random_number (gfc_code *c)
  2433. {
  2434. const char *name;
  2435. int kind;
  2436. kind = c->ext.actual->expr->ts.kind;
  2437. if (c->ext.actual->expr->rank == 0)
  2438. name = gfc_get_string (PREFIX ("random_r%d"), kind);
  2439. else
  2440. name = gfc_get_string (PREFIX ("arandom_r%d"), kind);
  2441. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2442. }
  2443. void
  2444. gfc_resolve_random_seed (gfc_code *c)
  2445. {
  2446. const char *name;
  2447. name = gfc_get_string (PREFIX ("random_seed_i%d"), gfc_default_integer_kind);
  2448. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2449. }
  2450. void
  2451. gfc_resolve_rename_sub (gfc_code *c)
  2452. {
  2453. const char *name;
  2454. int kind;
  2455. if (c->ext.actual->next->next->expr != NULL)
  2456. kind = c->ext.actual->next->next->expr->ts.kind;
  2457. else
  2458. kind = gfc_default_integer_kind;
  2459. name = gfc_get_string (PREFIX ("rename_i%d_sub"), kind);
  2460. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2461. }
  2462. void
  2463. gfc_resolve_kill_sub (gfc_code *c)
  2464. {
  2465. const char *name;
  2466. int kind;
  2467. if (c->ext.actual->next->next->expr != NULL)
  2468. kind = c->ext.actual->next->next->expr->ts.kind;
  2469. else
  2470. kind = gfc_default_integer_kind;
  2471. name = gfc_get_string (PREFIX ("kill_i%d_sub"), kind);
  2472. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2473. }
  2474. void
  2475. gfc_resolve_link_sub (gfc_code *c)
  2476. {
  2477. const char *name;
  2478. int kind;
  2479. if (c->ext.actual->next->next->expr != NULL)
  2480. kind = c->ext.actual->next->next->expr->ts.kind;
  2481. else
  2482. kind = gfc_default_integer_kind;
  2483. name = gfc_get_string (PREFIX ("link_i%d_sub"), kind);
  2484. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2485. }
  2486. void
  2487. gfc_resolve_symlnk_sub (gfc_code *c)
  2488. {
  2489. const char *name;
  2490. int kind;
  2491. if (c->ext.actual->next->next->expr != NULL)
  2492. kind = c->ext.actual->next->next->expr->ts.kind;
  2493. else
  2494. kind = gfc_default_integer_kind;
  2495. name = gfc_get_string (PREFIX ("symlnk_i%d_sub"), kind);
  2496. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2497. }
  2498. /* G77 compatibility subroutines dtime() and etime(). */
  2499. void
  2500. gfc_resolve_dtime_sub (gfc_code *c)
  2501. {
  2502. const char *name;
  2503. name = gfc_get_string (PREFIX ("dtime_sub"));
  2504. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2505. }
  2506. void
  2507. gfc_resolve_etime_sub (gfc_code *c)
  2508. {
  2509. const char *name;
  2510. name = gfc_get_string (PREFIX ("etime_sub"));
  2511. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2512. }
  2513. /* G77 compatibility subroutines itime(), idate(), ltime() and gmtime(). */
  2514. void
  2515. gfc_resolve_itime (gfc_code *c)
  2516. {
  2517. c->resolved_sym
  2518. = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("itime_i%d"),
  2519. gfc_default_integer_kind));
  2520. }
  2521. void
  2522. gfc_resolve_idate (gfc_code *c)
  2523. {
  2524. c->resolved_sym
  2525. = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("idate_i%d"),
  2526. gfc_default_integer_kind));
  2527. }
  2528. void
  2529. gfc_resolve_ltime (gfc_code *c)
  2530. {
  2531. c->resolved_sym
  2532. = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("ltime_i%d"),
  2533. gfc_default_integer_kind));
  2534. }
  2535. void
  2536. gfc_resolve_gmtime (gfc_code *c)
  2537. {
  2538. c->resolved_sym
  2539. = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("gmtime_i%d"),
  2540. gfc_default_integer_kind));
  2541. }
  2542. /* G77 compatibility subroutine second(). */
  2543. void
  2544. gfc_resolve_second_sub (gfc_code *c)
  2545. {
  2546. const char *name;
  2547. name = gfc_get_string (PREFIX ("second_sub"));
  2548. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2549. }
  2550. void
  2551. gfc_resolve_sleep_sub (gfc_code *c)
  2552. {
  2553. const char *name;
  2554. int kind;
  2555. if (c->ext.actual->expr != NULL)
  2556. kind = c->ext.actual->expr->ts.kind;
  2557. else
  2558. kind = gfc_default_integer_kind;
  2559. name = gfc_get_string (PREFIX ("sleep_i%d_sub"), kind);
  2560. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2561. }
  2562. /* G77 compatibility function srand(). */
  2563. void
  2564. gfc_resolve_srand (gfc_code *c)
  2565. {
  2566. const char *name;
  2567. name = gfc_get_string (PREFIX ("srand"));
  2568. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2569. }
  2570. /* Resolve the getarg intrinsic subroutine. */
  2571. void
  2572. gfc_resolve_getarg (gfc_code *c)
  2573. {
  2574. const char *name;
  2575. if (c->ext.actual->expr->ts.kind != gfc_default_integer_kind)
  2576. {
  2577. gfc_typespec ts;
  2578. gfc_clear_ts (&ts);
  2579. ts.type = BT_INTEGER;
  2580. ts.kind = gfc_default_integer_kind;
  2581. gfc_convert_type (c->ext.actual->expr, &ts, 2);
  2582. }
  2583. name = gfc_get_string (PREFIX ("getarg_i%d"), gfc_default_integer_kind);
  2584. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2585. }
  2586. /* Resolve the getcwd intrinsic subroutine. */
  2587. void
  2588. gfc_resolve_getcwd_sub (gfc_code *c)
  2589. {
  2590. const char *name;
  2591. int kind;
  2592. if (c->ext.actual->next->expr != NULL)
  2593. kind = c->ext.actual->next->expr->ts.kind;
  2594. else
  2595. kind = gfc_default_integer_kind;
  2596. name = gfc_get_string (PREFIX ("getcwd_i%d_sub"), kind);
  2597. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2598. }
  2599. /* Resolve the get_command intrinsic subroutine. */
  2600. void
  2601. gfc_resolve_get_command (gfc_code *c)
  2602. {
  2603. const char *name;
  2604. int kind;
  2605. kind = gfc_default_integer_kind;
  2606. name = gfc_get_string (PREFIX ("get_command_i%d"), kind);
  2607. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2608. }
  2609. /* Resolve the get_command_argument intrinsic subroutine. */
  2610. void
  2611. gfc_resolve_get_command_argument (gfc_code *c)
  2612. {
  2613. const char *name;
  2614. int kind;
  2615. kind = gfc_default_integer_kind;
  2616. name = gfc_get_string (PREFIX ("get_command_argument_i%d"), kind);
  2617. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2618. }
  2619. /* Resolve the get_environment_variable intrinsic subroutine. */
  2620. void
  2621. gfc_resolve_get_environment_variable (gfc_code *code)
  2622. {
  2623. const char *name;
  2624. int kind;
  2625. kind = gfc_default_integer_kind;
  2626. name = gfc_get_string (PREFIX ("get_environment_variable_i%d"), kind);
  2627. code->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2628. }
  2629. void
  2630. gfc_resolve_signal_sub (gfc_code *c)
  2631. {
  2632. const char *name;
  2633. gfc_expr *number, *handler, *status;
  2634. gfc_typespec ts;
  2635. gfc_clear_ts (&ts);
  2636. number = c->ext.actual->expr;
  2637. handler = c->ext.actual->next->expr;
  2638. status = c->ext.actual->next->next->expr;
  2639. ts.type = BT_INTEGER;
  2640. ts.kind = gfc_c_int_kind;
  2641. /* handler can be either BT_INTEGER or BT_PROCEDURE */
  2642. if (handler->ts.type == BT_INTEGER)
  2643. {
  2644. if (handler->ts.kind != gfc_c_int_kind)
  2645. gfc_convert_type (handler, &ts, 2);
  2646. name = gfc_get_string (PREFIX ("signal_sub_int"));
  2647. }
  2648. else
  2649. name = gfc_get_string (PREFIX ("signal_sub"));
  2650. if (number->ts.kind != gfc_c_int_kind)
  2651. gfc_convert_type (number, &ts, 2);
  2652. if (status != NULL && status->ts.kind != gfc_c_int_kind)
  2653. gfc_convert_type (status, &ts, 2);
  2654. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2655. }
  2656. /* Resolve the SYSTEM intrinsic subroutine. */
  2657. void
  2658. gfc_resolve_system_sub (gfc_code *c)
  2659. {
  2660. const char *name;
  2661. name = gfc_get_string (PREFIX ("system_sub"));
  2662. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2663. }
  2664. /* Determine if the arguments to SYSTEM_CLOCK are INTEGER(4) or INTEGER(8) */
  2665. void
  2666. gfc_resolve_system_clock (gfc_code *c)
  2667. {
  2668. const char *name;
  2669. int kind;
  2670. gfc_expr *count = c->ext.actual->expr;
  2671. gfc_expr *count_max = c->ext.actual->next->next->expr;
  2672. /* The INTEGER(8) version has higher precision, it is used if both COUNT
  2673. and COUNT_MAX can hold 64-bit values, or are absent. */
  2674. if ((!count || count->ts.kind >= 8)
  2675. && (!count_max || count_max->ts.kind >= 8))
  2676. kind = 8;
  2677. else
  2678. kind = gfc_default_integer_kind;
  2679. name = gfc_get_string (PREFIX ("system_clock_%d"), kind);
  2680. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2681. }
  2682. /* Resolve the EXECUTE_COMMAND_LINE intrinsic subroutine. */
  2683. void
  2684. gfc_resolve_execute_command_line (gfc_code *c)
  2685. {
  2686. const char *name;
  2687. name = gfc_get_string (PREFIX ("execute_command_line_i%d"),
  2688. gfc_default_integer_kind);
  2689. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2690. }
  2691. /* Resolve the EXIT intrinsic subroutine. */
  2692. void
  2693. gfc_resolve_exit (gfc_code *c)
  2694. {
  2695. const char *name;
  2696. gfc_typespec ts;
  2697. gfc_expr *n;
  2698. gfc_clear_ts (&ts);
  2699. /* The STATUS argument has to be of default kind. If it is not,
  2700. we convert it. */
  2701. ts.type = BT_INTEGER;
  2702. ts.kind = gfc_default_integer_kind;
  2703. n = c->ext.actual->expr;
  2704. if (n != NULL && n->ts.kind != ts.kind)
  2705. gfc_convert_type (n, &ts, 2);
  2706. name = gfc_get_string (PREFIX ("exit_i%d"), ts.kind);
  2707. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2708. }
  2709. /* Resolve the FLUSH intrinsic subroutine. */
  2710. void
  2711. gfc_resolve_flush (gfc_code *c)
  2712. {
  2713. const char *name;
  2714. gfc_typespec ts;
  2715. gfc_expr *n;
  2716. gfc_clear_ts (&ts);
  2717. ts.type = BT_INTEGER;
  2718. ts.kind = gfc_default_integer_kind;
  2719. n = c->ext.actual->expr;
  2720. if (n != NULL && n->ts.kind != ts.kind)
  2721. gfc_convert_type (n, &ts, 2);
  2722. name = gfc_get_string (PREFIX ("flush_i%d"), ts.kind);
  2723. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2724. }
  2725. void
  2726. gfc_resolve_free (gfc_code *c)
  2727. {
  2728. gfc_typespec ts;
  2729. gfc_expr *n;
  2730. gfc_clear_ts (&ts);
  2731. ts.type = BT_INTEGER;
  2732. ts.kind = gfc_index_integer_kind;
  2733. n = c->ext.actual->expr;
  2734. if (n->ts.kind != ts.kind)
  2735. gfc_convert_type (n, &ts, 2);
  2736. c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("free"));
  2737. }
  2738. void
  2739. gfc_resolve_ctime_sub (gfc_code *c)
  2740. {
  2741. gfc_typespec ts;
  2742. gfc_clear_ts (&ts);
  2743. /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
  2744. if (c->ext.actual->expr->ts.kind != 8)
  2745. {
  2746. ts.type = BT_INTEGER;
  2747. ts.kind = 8;
  2748. ts.u.derived = NULL;
  2749. ts.u.cl = NULL;
  2750. gfc_convert_type (c->ext.actual->expr, &ts, 2);
  2751. }
  2752. c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ctime_sub"));
  2753. }
  2754. void
  2755. gfc_resolve_fdate_sub (gfc_code *c)
  2756. {
  2757. c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fdate_sub"));
  2758. }
  2759. void
  2760. gfc_resolve_gerror (gfc_code *c)
  2761. {
  2762. c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("gerror"));
  2763. }
  2764. void
  2765. gfc_resolve_getlog (gfc_code *c)
  2766. {
  2767. c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("getlog"));
  2768. }
  2769. void
  2770. gfc_resolve_hostnm_sub (gfc_code *c)
  2771. {
  2772. const char *name;
  2773. int kind;
  2774. if (c->ext.actual->next->expr != NULL)
  2775. kind = c->ext.actual->next->expr->ts.kind;
  2776. else
  2777. kind = gfc_default_integer_kind;
  2778. name = gfc_get_string (PREFIX ("hostnm_i%d_sub"), kind);
  2779. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2780. }
  2781. void
  2782. gfc_resolve_perror (gfc_code *c)
  2783. {
  2784. c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("perror_sub"));
  2785. }
  2786. /* Resolve the STAT and FSTAT intrinsic subroutines. */
  2787. void
  2788. gfc_resolve_stat_sub (gfc_code *c)
  2789. {
  2790. const char *name;
  2791. name = gfc_get_string (PREFIX ("stat_i%d_sub"), gfc_default_integer_kind);
  2792. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2793. }
  2794. void
  2795. gfc_resolve_lstat_sub (gfc_code *c)
  2796. {
  2797. const char *name;
  2798. name = gfc_get_string (PREFIX ("lstat_i%d_sub"), gfc_default_integer_kind);
  2799. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2800. }
  2801. void
  2802. gfc_resolve_fstat_sub (gfc_code *c)
  2803. {
  2804. const char *name;
  2805. gfc_expr *u;
  2806. gfc_typespec *ts;
  2807. u = c->ext.actual->expr;
  2808. ts = &c->ext.actual->next->expr->ts;
  2809. if (u->ts.kind != ts->kind)
  2810. gfc_convert_type (u, ts, 2);
  2811. name = gfc_get_string (PREFIX ("fstat_i%d_sub"), ts->kind);
  2812. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2813. }
  2814. void
  2815. gfc_resolve_fgetc_sub (gfc_code *c)
  2816. {
  2817. const char *name;
  2818. gfc_typespec ts;
  2819. gfc_expr *u, *st;
  2820. gfc_clear_ts (&ts);
  2821. u = c->ext.actual->expr;
  2822. st = c->ext.actual->next->next->expr;
  2823. if (u->ts.kind != gfc_c_int_kind)
  2824. {
  2825. ts.type = BT_INTEGER;
  2826. ts.kind = gfc_c_int_kind;
  2827. ts.u.derived = NULL;
  2828. ts.u.cl = NULL;
  2829. gfc_convert_type (u, &ts, 2);
  2830. }
  2831. if (st != NULL)
  2832. name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), st->ts.kind);
  2833. else
  2834. name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), gfc_default_integer_kind);
  2835. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2836. }
  2837. void
  2838. gfc_resolve_fget_sub (gfc_code *c)
  2839. {
  2840. const char *name;
  2841. gfc_expr *st;
  2842. st = c->ext.actual->next->expr;
  2843. if (st != NULL)
  2844. name = gfc_get_string (PREFIX ("fget_i%d_sub"), st->ts.kind);
  2845. else
  2846. name = gfc_get_string (PREFIX ("fget_i%d_sub"), gfc_default_integer_kind);
  2847. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2848. }
  2849. void
  2850. gfc_resolve_fputc_sub (gfc_code *c)
  2851. {
  2852. const char *name;
  2853. gfc_typespec ts;
  2854. gfc_expr *u, *st;
  2855. gfc_clear_ts (&ts);
  2856. u = c->ext.actual->expr;
  2857. st = c->ext.actual->next->next->expr;
  2858. if (u->ts.kind != gfc_c_int_kind)
  2859. {
  2860. ts.type = BT_INTEGER;
  2861. ts.kind = gfc_c_int_kind;
  2862. ts.u.derived = NULL;
  2863. ts.u.cl = NULL;
  2864. gfc_convert_type (u, &ts, 2);
  2865. }
  2866. if (st != NULL)
  2867. name = gfc_get_string (PREFIX ("fputc_i%d_sub"), st->ts.kind);
  2868. else
  2869. name = gfc_get_string (PREFIX ("fputc_i%d_sub"), gfc_default_integer_kind);
  2870. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2871. }
  2872. void
  2873. gfc_resolve_fput_sub (gfc_code *c)
  2874. {
  2875. const char *name;
  2876. gfc_expr *st;
  2877. st = c->ext.actual->next->expr;
  2878. if (st != NULL)
  2879. name = gfc_get_string (PREFIX ("fput_i%d_sub"), st->ts.kind);
  2880. else
  2881. name = gfc_get_string (PREFIX ("fput_i%d_sub"), gfc_default_integer_kind);
  2882. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2883. }
  2884. void
  2885. gfc_resolve_fseek_sub (gfc_code *c)
  2886. {
  2887. gfc_expr *unit;
  2888. gfc_expr *offset;
  2889. gfc_expr *whence;
  2890. gfc_typespec ts;
  2891. gfc_clear_ts (&ts);
  2892. unit = c->ext.actual->expr;
  2893. offset = c->ext.actual->next->expr;
  2894. whence = c->ext.actual->next->next->expr;
  2895. if (unit->ts.kind != gfc_c_int_kind)
  2896. {
  2897. ts.type = BT_INTEGER;
  2898. ts.kind = gfc_c_int_kind;
  2899. ts.u.derived = NULL;
  2900. ts.u.cl = NULL;
  2901. gfc_convert_type (unit, &ts, 2);
  2902. }
  2903. if (offset->ts.kind != gfc_intio_kind)
  2904. {
  2905. ts.type = BT_INTEGER;
  2906. ts.kind = gfc_intio_kind;
  2907. ts.u.derived = NULL;
  2908. ts.u.cl = NULL;
  2909. gfc_convert_type (offset, &ts, 2);
  2910. }
  2911. if (whence->ts.kind != gfc_c_int_kind)
  2912. {
  2913. ts.type = BT_INTEGER;
  2914. ts.kind = gfc_c_int_kind;
  2915. ts.u.derived = NULL;
  2916. ts.u.cl = NULL;
  2917. gfc_convert_type (whence, &ts, 2);
  2918. }
  2919. c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fseek_sub"));
  2920. }
  2921. void
  2922. gfc_resolve_ftell_sub (gfc_code *c)
  2923. {
  2924. const char *name;
  2925. gfc_expr *unit;
  2926. gfc_expr *offset;
  2927. gfc_typespec ts;
  2928. gfc_clear_ts (&ts);
  2929. unit = c->ext.actual->expr;
  2930. offset = c->ext.actual->next->expr;
  2931. if (unit->ts.kind != gfc_c_int_kind)
  2932. {
  2933. ts.type = BT_INTEGER;
  2934. ts.kind = gfc_c_int_kind;
  2935. ts.u.derived = NULL;
  2936. ts.u.cl = NULL;
  2937. gfc_convert_type (unit, &ts, 2);
  2938. }
  2939. name = gfc_get_string (PREFIX ("ftell_i%d_sub"), offset->ts.kind);
  2940. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2941. }
  2942. void
  2943. gfc_resolve_ttynam_sub (gfc_code *c)
  2944. {
  2945. gfc_typespec ts;
  2946. gfc_clear_ts (&ts);
  2947. if (c->ext.actual->expr->ts.kind != gfc_c_int_kind)
  2948. {
  2949. ts.type = BT_INTEGER;
  2950. ts.kind = gfc_c_int_kind;
  2951. ts.u.derived = NULL;
  2952. ts.u.cl = NULL;
  2953. gfc_convert_type (c->ext.actual->expr, &ts, 2);
  2954. }
  2955. c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ttynam_sub"));
  2956. }
  2957. /* Resolve the UMASK intrinsic subroutine. */
  2958. void
  2959. gfc_resolve_umask_sub (gfc_code *c)
  2960. {
  2961. const char *name;
  2962. int kind;
  2963. if (c->ext.actual->next->expr != NULL)
  2964. kind = c->ext.actual->next->expr->ts.kind;
  2965. else
  2966. kind = gfc_default_integer_kind;
  2967. name = gfc_get_string (PREFIX ("umask_i%d_sub"), kind);
  2968. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2969. }
  2970. /* Resolve the UNLINK intrinsic subroutine. */
  2971. void
  2972. gfc_resolve_unlink_sub (gfc_code *c)
  2973. {
  2974. const char *name;
  2975. int kind;
  2976. if (c->ext.actual->next->expr != NULL)
  2977. kind = c->ext.actual->next->expr->ts.kind;
  2978. else
  2979. kind = gfc_default_integer_kind;
  2980. name = gfc_get_string (PREFIX ("unlink_i%d_sub"), kind);
  2981. c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
  2982. }