| //===-- lib/Evaluate/intrinsics.cpp ---------------------------------------===// |
| // |
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| // See https://llvm.org/LICENSE.txt for license information. |
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| // |
| //===----------------------------------------------------------------------===// |
| |
| #include "flang/Evaluate/intrinsics.h" |
| #include "flang/Common/Fortran.h" |
| #include "flang/Common/enum-set.h" |
| #include "flang/Common/idioms.h" |
| #include "flang/Evaluate/check-expression.h" |
| #include "flang/Evaluate/common.h" |
| #include "flang/Evaluate/expression.h" |
| #include "flang/Evaluate/fold.h" |
| #include "flang/Evaluate/shape.h" |
| #include "flang/Evaluate/tools.h" |
| #include "flang/Evaluate/type.h" |
| #include "flang/Semantics/scope.h" |
| #include "flang/Semantics/tools.h" |
| #include "llvm/Support/raw_ostream.h" |
| #include <algorithm> |
| #include <cmath> |
| #include <map> |
| #include <string> |
| #include <utility> |
| |
| using namespace Fortran::parser::literals; |
| |
| namespace Fortran::evaluate { |
| |
| class FoldingContext; |
| |
| // This file defines the supported intrinsic procedures and implements |
| // their recognition and validation. It is largely table-driven. See |
| // docs/intrinsics.md and section 16 of the Fortran 2018 standard |
| // for full details on each of the intrinsics. Be advised, they have |
| // complicated details, and the design of these tables has to accommodate |
| // that complexity. |
| |
| // Dummy arguments to generic intrinsic procedures are each specified by |
| // their keyword name (rarely used, but always defined), allowable type |
| // categories, a kind pattern, a rank pattern, and information about |
| // optionality and defaults. The kind and rank patterns are represented |
| // here with code values that are significant to the matching/validation engine. |
| |
| // An actual argument to an intrinsic procedure may be a procedure itself |
| // only if the dummy argument is Rank::reduceOperation, |
| // KindCode::addressable, or the special case of NULL(MOLD=procedurePointer). |
| |
| // These are small bit-sets of type category enumerators. |
| // Note that typeless (BOZ literal) values don't have a distinct type category. |
| // These typeless arguments are represented in the tables as if they were |
| // INTEGER with a special "typeless" kind code. Arguments of intrinsic types |
| // that can also be typeless values are encoded with an "elementalOrBOZ" |
| // rank pattern. |
| // Assumed-type (TYPE(*)) dummy arguments can be forwarded along to some |
| // intrinsic functions that accept AnyType + Rank::anyOrAssumedRank, |
| // AnyType + Rank::arrayOrAssumedRank, or AnyType + Kind::addressable. |
| using CategorySet = common::EnumSet<TypeCategory, 8>; |
| static constexpr CategorySet IntType{TypeCategory::Integer}; |
| static constexpr CategorySet RealType{TypeCategory::Real}; |
| static constexpr CategorySet ComplexType{TypeCategory::Complex}; |
| static constexpr CategorySet CharType{TypeCategory::Character}; |
| static constexpr CategorySet LogicalType{TypeCategory::Logical}; |
| static constexpr CategorySet IntOrRealType{IntType | RealType}; |
| static constexpr CategorySet IntOrRealOrCharType{IntType | RealType | CharType}; |
| static constexpr CategorySet IntOrLogicalType{IntType | LogicalType}; |
| static constexpr CategorySet FloatingType{RealType | ComplexType}; |
| static constexpr CategorySet NumericType{IntType | RealType | ComplexType}; |
| static constexpr CategorySet RelatableType{IntType | RealType | CharType}; |
| static constexpr CategorySet DerivedType{TypeCategory::Derived}; |
| static constexpr CategorySet IntrinsicType{ |
| IntType | RealType | ComplexType | CharType | LogicalType}; |
| static constexpr CategorySet AnyType{IntrinsicType | DerivedType}; |
| |
| ENUM_CLASS(KindCode, none, defaultIntegerKind, |
| defaultRealKind, // is also the default COMPLEX kind |
| doublePrecision, defaultCharKind, defaultLogicalKind, |
| greaterOrEqualToKind, // match kind value greater than or equal to a single |
| // explicit kind value |
| any, // matches any kind value; each instance is independent |
| // match any kind, but all "same" kinds must be equal. For characters, also |
| // implies that lengths must be equal. |
| same, |
| // for characters that only require the same kind, not length |
| sameKind, |
| operand, // match any kind, with promotion (non-standard) |
| typeless, // BOZ literals are INTEGER with this kind |
| ieeeFlagType, // IEEE_FLAG_TYPE from ISO_FORTRAN_EXCEPTION |
| ieeeRoundType, // IEEE_ROUND_TYPE from ISO_FORTRAN_ARITHMETIC |
| teamType, // TEAM_TYPE from module ISO_FORTRAN_ENV (for coarrays) |
| kindArg, // this argument is KIND= |
| effectiveKind, // for function results: "kindArg" value, possibly defaulted |
| dimArg, // this argument is DIM= |
| likeMultiply, // for DOT_PRODUCT and MATMUL |
| subscript, // address-sized integer |
| size, // default KIND= for SIZE(), UBOUND, &c. |
| addressable, // for PRESENT(), &c.; anything (incl. procedure) but BOZ |
| nullPointerType, // for ASSOCIATED(NULL()) |
| exactKind, // a single explicit exactKindValue |
| atomicIntKind, // atomic_int_kind from iso_fortran_env |
| atomicIntOrLogicalKind, // atomic_int_kind or atomic_logical_kind |
| sameAtom, // same type and kind as atom |
| ) |
| |
| struct TypePattern { |
| CategorySet categorySet; |
| KindCode kindCode{KindCode::none}; |
| int kindValue{0}; // for KindCode::exactKind and greaterOrEqualToKind |
| llvm::raw_ostream &Dump(llvm::raw_ostream &) const; |
| }; |
| |
| // Abbreviations for argument and result patterns in the intrinsic prototypes: |
| |
| // Match specific kinds of intrinsic types |
| static constexpr TypePattern DefaultInt{IntType, KindCode::defaultIntegerKind}; |
| static constexpr TypePattern DefaultReal{RealType, KindCode::defaultRealKind}; |
| static constexpr TypePattern DefaultComplex{ |
| ComplexType, KindCode::defaultRealKind}; |
| static constexpr TypePattern DefaultChar{CharType, KindCode::defaultCharKind}; |
| static constexpr TypePattern DefaultLogical{ |
| LogicalType, KindCode::defaultLogicalKind}; |
| static constexpr TypePattern BOZ{IntType, KindCode::typeless}; |
| static constexpr TypePattern IeeeFlagType{DerivedType, KindCode::ieeeFlagType}; |
| static constexpr TypePattern IeeeRoundType{ |
| DerivedType, KindCode::ieeeRoundType}; |
| static constexpr TypePattern TeamType{DerivedType, KindCode::teamType}; |
| static constexpr TypePattern DoublePrecision{ |
| RealType, KindCode::doublePrecision}; |
| static constexpr TypePattern DoublePrecisionComplex{ |
| ComplexType, KindCode::doublePrecision}; |
| static constexpr TypePattern SubscriptInt{IntType, KindCode::subscript}; |
| |
| // Match any kind of some intrinsic or derived types |
| static constexpr TypePattern AnyInt{IntType, KindCode::any}; |
| static constexpr TypePattern AnyReal{RealType, KindCode::any}; |
| static constexpr TypePattern AnyIntOrReal{IntOrRealType, KindCode::any}; |
| static constexpr TypePattern AnyIntOrRealOrChar{ |
| IntOrRealOrCharType, KindCode::any}; |
| static constexpr TypePattern AnyIntOrLogical{IntOrLogicalType, KindCode::any}; |
| static constexpr TypePattern AnyComplex{ComplexType, KindCode::any}; |
| static constexpr TypePattern AnyFloating{FloatingType, KindCode::any}; |
| static constexpr TypePattern AnyNumeric{NumericType, KindCode::any}; |
| static constexpr TypePattern AnyChar{CharType, KindCode::any}; |
| static constexpr TypePattern AnyLogical{LogicalType, KindCode::any}; |
| static constexpr TypePattern AnyRelatable{RelatableType, KindCode::any}; |
| static constexpr TypePattern AnyIntrinsic{IntrinsicType, KindCode::any}; |
| static constexpr TypePattern ExtensibleDerived{DerivedType, KindCode::any}; |
| static constexpr TypePattern AnyData{AnyType, KindCode::any}; |
| |
| // Type is irrelevant, but not BOZ (for PRESENT(), OPTIONAL(), &c.) |
| static constexpr TypePattern Addressable{AnyType, KindCode::addressable}; |
| |
| // Match some kind of some intrinsic type(s); all "Same" values must match, |
| // even when not in the same category (e.g., SameComplex and SameReal). |
| // Can be used to specify a result so long as at least one argument is |
| // a "Same". |
| static constexpr TypePattern SameInt{IntType, KindCode::same}; |
| static constexpr TypePattern SameReal{RealType, KindCode::same}; |
| static constexpr TypePattern SameIntOrReal{IntOrRealType, KindCode::same}; |
| static constexpr TypePattern SameComplex{ComplexType, KindCode::same}; |
| static constexpr TypePattern SameFloating{FloatingType, KindCode::same}; |
| static constexpr TypePattern SameNumeric{NumericType, KindCode::same}; |
| static constexpr TypePattern SameChar{CharType, KindCode::same}; |
| static constexpr TypePattern SameCharNoLen{CharType, KindCode::sameKind}; |
| static constexpr TypePattern SameLogical{LogicalType, KindCode::same}; |
| static constexpr TypePattern SameRelatable{RelatableType, KindCode::same}; |
| static constexpr TypePattern SameIntrinsic{IntrinsicType, KindCode::same}; |
| static constexpr TypePattern SameType{AnyType, KindCode::same}; |
| |
| // Match some kind of some INTEGER or REAL type(s); when argument types |
| // &/or kinds differ, their values are converted as if they were operands to |
| // an intrinsic operation like addition. This is a nonstandard but nearly |
| // universal extension feature. |
| static constexpr TypePattern OperandReal{RealType, KindCode::operand}; |
| static constexpr TypePattern OperandInt{IntType, KindCode::operand}; |
| static constexpr TypePattern OperandIntOrReal{IntOrRealType, KindCode::operand}; |
| |
| // For ASSOCIATED, the first argument is a typeless pointer |
| static constexpr TypePattern AnyPointer{AnyType, KindCode::nullPointerType}; |
| |
| // For DOT_PRODUCT and MATMUL, the result type depends on the arguments |
| static constexpr TypePattern ResultLogical{LogicalType, KindCode::likeMultiply}; |
| static constexpr TypePattern ResultNumeric{NumericType, KindCode::likeMultiply}; |
| |
| // Result types with known category and KIND= |
| static constexpr TypePattern KINDInt{IntType, KindCode::effectiveKind}; |
| static constexpr TypePattern KINDReal{RealType, KindCode::effectiveKind}; |
| static constexpr TypePattern KINDComplex{ComplexType, KindCode::effectiveKind}; |
| static constexpr TypePattern KINDChar{CharType, KindCode::effectiveKind}; |
| static constexpr TypePattern KINDLogical{LogicalType, KindCode::effectiveKind}; |
| |
| static constexpr TypePattern AtomicInt{IntType, KindCode::atomicIntKind}; |
| static constexpr TypePattern AtomicIntOrLogical{ |
| IntOrLogicalType, KindCode::atomicIntOrLogicalKind}; |
| static constexpr TypePattern SameAtom{IntOrLogicalType, KindCode::sameAtom}; |
| |
| // The default rank pattern for dummy arguments and function results is |
| // "elemental". |
| ENUM_CLASS(Rank, |
| elemental, // scalar, or array that conforms with other array arguments |
| elementalOrBOZ, // elemental, or typeless BOZ literal scalar |
| scalar, vector, |
| shape, // INTEGER vector of known length and no negative element |
| matrix, |
| array, // not scalar, rank is known and greater than zero |
| coarray, // rank is known and can be scalar; has nonzero corank |
| atom, // is scalar and has nonzero corank or is coindexed |
| known, // rank is known and can be scalar |
| anyOrAssumedRank, // any rank, or assumed; assumed-type TYPE(*) allowed |
| arrayOrAssumedRank, // rank >= 1 or assumed; assumed-type TYPE(*) allowed |
| conformable, // scalar, or array of same rank & shape as "array" argument |
| reduceOperation, // a pure function with constraints for REDUCE |
| dimReduced, // scalar if no DIM= argument, else rank(array)-1 |
| dimRemovedOrScalar, // rank(array)-1 (less DIM) or scalar |
| scalarIfDim, // scalar if DIM= argument is present, else rank one array |
| locReduced, // vector(1:rank) if no DIM= argument, else rank(array)-1 |
| rankPlus1, // rank(known)+1 |
| shaped, // rank is length of SHAPE vector |
| ) |
| |
| ENUM_CLASS(Optionality, required, |
| optional, // unless DIM= for SIZE(assumedSize) |
| missing, // for DIM= cases like FINDLOC |
| repeats, // for MAX/MIN and their several variants |
| ) |
| |
| ENUM_CLASS(ArgFlag, none, |
| canBeNull, // actual argument can be NULL(with or without MOLD=) |
| canBeMoldNull, // actual argument can be NULL(with MOLD=) |
| defaultsToSameKind, // for MatchingDefaultKIND |
| defaultsToSizeKind, // for SizeDefaultKIND |
| defaultsToDefaultForResult, // for DefaultingKIND |
| notAssumedSize) |
| |
| struct IntrinsicDummyArgument { |
| const char *keyword{nullptr}; |
| TypePattern typePattern; |
| Rank rank{Rank::elemental}; |
| Optionality optionality{Optionality::required}; |
| common::Intent intent{common::Intent::In}; |
| common::EnumSet<ArgFlag, 32> flags{}; |
| llvm::raw_ostream &Dump(llvm::raw_ostream &) const; |
| }; |
| |
| // constexpr abbreviations for popular arguments: |
| // DefaultingKIND is a KIND= argument whose default value is the appropriate |
| // KIND(0), KIND(0.0), KIND(''), &c. value for the function result. |
| static constexpr IntrinsicDummyArgument DefaultingKIND{"kind", |
| {IntType, KindCode::kindArg}, Rank::scalar, Optionality::optional, |
| common::Intent::In, {ArgFlag::defaultsToDefaultForResult}}; |
| // MatchingDefaultKIND is a KIND= argument whose default value is the |
| // kind of any "Same" function argument (viz., the one whose kind pattern is |
| // "same"). |
| static constexpr IntrinsicDummyArgument MatchingDefaultKIND{"kind", |
| {IntType, KindCode::kindArg}, Rank::scalar, Optionality::optional, |
| common::Intent::In, {ArgFlag::defaultsToSameKind}}; |
| // SizeDefaultKind is a KIND= argument whose default value should be |
| // the kind of INTEGER used for address calculations, and can be |
| // set so with a compiler flag; but the standard mandates the |
| // kind of default INTEGER. |
| static constexpr IntrinsicDummyArgument SizeDefaultKIND{"kind", |
| {IntType, KindCode::kindArg}, Rank::scalar, Optionality::optional, |
| common::Intent::In, {ArgFlag::defaultsToSizeKind}}; |
| static constexpr IntrinsicDummyArgument RequiredDIM{"dim", |
| {IntType, KindCode::dimArg}, Rank::scalar, Optionality::required, |
| common::Intent::In}; |
| static constexpr IntrinsicDummyArgument OptionalDIM{"dim", |
| {IntType, KindCode::dimArg}, Rank::scalar, Optionality::optional, |
| common::Intent::In}; |
| static constexpr IntrinsicDummyArgument MissingDIM{"dim", |
| {IntType, KindCode::dimArg}, Rank::scalar, Optionality::missing, |
| common::Intent::In}; |
| static constexpr IntrinsicDummyArgument OptionalMASK{"mask", AnyLogical, |
| Rank::conformable, Optionality::optional, common::Intent::In}; |
| static constexpr IntrinsicDummyArgument OptionalTEAM{ |
| "team", TeamType, Rank::scalar, Optionality::optional, common::Intent::In}; |
| |
| struct IntrinsicInterface { |
| static constexpr int maxArguments{7}; // if not a MAX/MIN(...) |
| const char *name{nullptr}; |
| IntrinsicDummyArgument dummy[maxArguments]; |
| TypePattern result; |
| Rank rank{Rank::elemental}; |
| IntrinsicClass intrinsicClass{IntrinsicClass::elementalFunction}; |
| std::optional<SpecificCall> Match(const CallCharacteristics &, |
| const common::IntrinsicTypeDefaultKinds &, ActualArguments &, |
| FoldingContext &context, const semantics::Scope *builtins) const; |
| int CountArguments() const; |
| llvm::raw_ostream &Dump(llvm::raw_ostream &) const; |
| }; |
| |
| int IntrinsicInterface::CountArguments() const { |
| int n{0}; |
| while (n < maxArguments && dummy[n].keyword) { |
| ++n; |
| } |
| return n; |
| } |
| |
| // GENERIC INTRINSIC FUNCTION INTERFACES |
| // Each entry in this table defines a pattern. Some intrinsic |
| // functions have more than one such pattern. Besides the name |
| // of the intrinsic function, each pattern has specifications for |
| // the dummy arguments and for the result of the function. |
| // The dummy argument patterns each have a name (these are from the |
| // standard, but rarely appear in actual code), a type and kind |
| // pattern, allowable ranks, and optionality indicators. |
| // Be advised, the default rank pattern is "elemental". |
| static const IntrinsicInterface genericIntrinsicFunction[]{ |
| {"abs", {{"a", SameIntOrReal}}, SameIntOrReal}, |
| {"abs", {{"a", SameComplex}}, SameReal}, |
| {"achar", {{"i", AnyInt, Rank::elementalOrBOZ}, DefaultingKIND}, KINDChar}, |
| {"acos", {{"x", SameFloating}}, SameFloating}, |
| {"acosd", {{"x", SameFloating}}, SameFloating}, |
| {"acosh", {{"x", SameFloating}}, SameFloating}, |
| {"adjustl", {{"string", SameChar}}, SameChar}, |
| {"adjustr", {{"string", SameChar}}, SameChar}, |
| {"aimag", {{"z", SameComplex}}, SameReal}, |
| {"aint", {{"a", SameReal}, MatchingDefaultKIND}, KINDReal}, |
| {"all", {{"mask", SameLogical, Rank::array}, OptionalDIM}, SameLogical, |
| Rank::dimReduced, IntrinsicClass::transformationalFunction}, |
| {"allocated", {{"scalar", AnyData, Rank::scalar}}, DefaultLogical, |
| Rank::elemental, IntrinsicClass::inquiryFunction}, |
| {"allocated", {{"array", AnyData, Rank::anyOrAssumedRank}}, DefaultLogical, |
| Rank::elemental, IntrinsicClass::inquiryFunction}, |
| {"anint", {{"a", SameReal}, MatchingDefaultKIND}, KINDReal}, |
| {"any", {{"mask", SameLogical, Rank::array}, OptionalDIM}, SameLogical, |
| Rank::dimReduced, IntrinsicClass::transformationalFunction}, |
| {"asin", {{"x", SameFloating}}, SameFloating}, |
| {"asind", {{"x", SameFloating}}, SameFloating}, |
| {"asinh", {{"x", SameFloating}}, SameFloating}, |
| {"associated", |
| {{"pointer", AnyPointer, Rank::anyOrAssumedRank, Optionality::required, |
| common::Intent::In, {ArgFlag::canBeNull}}, |
| {"target", Addressable, Rank::anyOrAssumedRank, |
| Optionality::optional, common::Intent::In, |
| {ArgFlag::canBeNull}}}, |
| DefaultLogical, Rank::elemental, IntrinsicClass::inquiryFunction}, |
| {"atan", {{"x", SameFloating}}, SameFloating}, |
| {"atan", {{"y", OperandReal}, {"x", OperandReal}}, OperandReal}, |
| {"atand", {{"x", SameFloating}}, SameFloating}, |
| {"atand", {{"y", OperandReal}, {"x", OperandReal}}, OperandReal}, |
| {"atan2", {{"y", OperandReal}, {"x", OperandReal}}, OperandReal}, |
| {"atan2d", {{"y", OperandReal}, {"x", OperandReal}}, OperandReal}, |
| {"atanpi", {{"x", SameFloating}}, SameFloating}, |
| {"atanpi", {{"y", OperandReal}, {"x", OperandReal}}, OperandReal}, |
| {"atan2pi", {{"y", OperandReal}, {"x", OperandReal}}, OperandReal}, |
| {"atanh", {{"x", SameFloating}}, SameFloating}, |
| {"bessel_j0", {{"x", SameReal}}, SameReal}, |
| {"bessel_j1", {{"x", SameReal}}, SameReal}, |
| {"bessel_jn", {{"n", AnyInt}, {"x", SameReal}}, SameReal}, |
| {"bessel_jn", |
| {{"n1", AnyInt, Rank::scalar}, {"n2", AnyInt, Rank::scalar}, |
| {"x", SameReal, Rank::scalar}}, |
| SameReal, Rank::vector, IntrinsicClass::transformationalFunction}, |
| {"bessel_y0", {{"x", SameReal}}, SameReal}, |
| {"bessel_y1", {{"x", SameReal}}, SameReal}, |
| {"bessel_yn", {{"n", AnyInt}, {"x", SameReal}}, SameReal}, |
| {"bessel_yn", |
| {{"n1", AnyInt, Rank::scalar}, {"n2", AnyInt, Rank::scalar}, |
| {"x", SameReal, Rank::scalar}}, |
| SameReal, Rank::vector, IntrinsicClass::transformationalFunction}, |
| {"bge", |
| {{"i", AnyInt, Rank::elementalOrBOZ}, |
| {"j", AnyInt, Rank::elementalOrBOZ}}, |
| DefaultLogical}, |
| {"bgt", |
| {{"i", AnyInt, Rank::elementalOrBOZ}, |
| {"j", AnyInt, Rank::elementalOrBOZ}}, |
| DefaultLogical}, |
| {"bit_size", |
| {{"i", SameInt, Rank::anyOrAssumedRank, Optionality::required, |
| common::Intent::In, {ArgFlag::canBeMoldNull}}}, |
| SameInt, Rank::scalar, IntrinsicClass::inquiryFunction}, |
| {"ble", |
| {{"i", AnyInt, Rank::elementalOrBOZ}, |
| {"j", AnyInt, Rank::elementalOrBOZ}}, |
| DefaultLogical}, |
| {"blt", |
| {{"i", AnyInt, Rank::elementalOrBOZ}, |
| {"j", AnyInt, Rank::elementalOrBOZ}}, |
| DefaultLogical}, |
| {"btest", {{"i", AnyInt, Rank::elementalOrBOZ}, {"pos", AnyInt}}, |
| DefaultLogical}, |
| {"ceiling", {{"a", AnyReal}, DefaultingKIND}, KINDInt}, |
| {"char", {{"i", AnyInt, Rank::elementalOrBOZ}, DefaultingKIND}, KINDChar}, |
| {"cmplx", {{"x", AnyComplex}, DefaultingKIND}, KINDComplex}, |
| {"cmplx", |
| {{"x", AnyIntOrReal, Rank::elementalOrBOZ}, |
| {"y", AnyIntOrReal, Rank::elementalOrBOZ, Optionality::optional}, |
| DefaultingKIND}, |
| KINDComplex}, |
| {"command_argument_count", {}, DefaultInt, Rank::scalar, |
| IntrinsicClass::transformationalFunction}, |
| {"conjg", {{"z", SameComplex}}, SameComplex}, |
| {"cos", {{"x", SameFloating}}, SameFloating}, |
| {"cosd", {{"x", SameFloating}}, SameFloating}, |
| {"cosh", {{"x", SameFloating}}, SameFloating}, |
| {"count", {{"mask", AnyLogical, Rank::array}, OptionalDIM, DefaultingKIND}, |
| KINDInt, Rank::dimReduced, IntrinsicClass::transformationalFunction}, |
| {"cshift", |
| {{"array", SameType, Rank::array}, |
| {"shift", AnyInt, Rank::dimRemovedOrScalar}, OptionalDIM}, |
| SameType, Rank::conformable, IntrinsicClass::transformationalFunction}, |
| {"dble", {{"a", AnyNumeric, Rank::elementalOrBOZ}}, DoublePrecision}, |
| {"digits", |
| {{"x", AnyIntOrReal, Rank::anyOrAssumedRank, Optionality::required, |
| common::Intent::In, {ArgFlag::canBeMoldNull}}}, |
| DefaultInt, Rank::scalar, IntrinsicClass::inquiryFunction}, |
| {"dim", {{"x", OperandIntOrReal}, {"y", OperandIntOrReal}}, |
| OperandIntOrReal}, |
| {"dot_product", |
| {{"vector_a", AnyLogical, Rank::vector}, |
| {"vector_b", AnyLogical, Rank::vector}}, |
| ResultLogical, Rank::scalar, IntrinsicClass::transformationalFunction}, |
| {"dot_product", |
| {{"vector_a", AnyComplex, Rank::vector}, |
| {"vector_b", AnyNumeric, Rank::vector}}, |
| ResultNumeric, Rank::scalar, // conjugates vector_a |
| IntrinsicClass::transformationalFunction}, |
| {"dot_product", |
| {{"vector_a", AnyIntOrReal, Rank::vector}, |
| {"vector_b", AnyNumeric, Rank::vector}}, |
| ResultNumeric, Rank::scalar, IntrinsicClass::transformationalFunction}, |
| {"dprod", {{"x", DefaultReal}, {"y", DefaultReal}}, DoublePrecision}, |
| {"dshiftl", |
| {{"i", SameInt}, {"j", SameInt, Rank::elementalOrBOZ}, |
| {"shift", AnyInt}}, |
| SameInt}, |
| {"dshiftl", {{"i", BOZ}, {"j", SameInt}, {"shift", AnyInt}}, SameInt}, |
| {"dshiftr", |
| {{"i", SameInt}, {"j", SameInt, Rank::elementalOrBOZ}, |
| {"shift", AnyInt}}, |
| SameInt}, |
| {"dshiftr", {{"i", BOZ}, {"j", SameInt}, {"shift", AnyInt}}, SameInt}, |
| {"eoshift", |
| {{"array", SameType, Rank::array}, |
| {"shift", AnyInt, Rank::dimRemovedOrScalar}, |
| // BOUNDARY= is not optional for non-intrinsic types |
| {"boundary", SameType, Rank::dimRemovedOrScalar}, OptionalDIM}, |
| SameType, Rank::conformable, IntrinsicClass::transformationalFunction}, |
| {"eoshift", |
| {{"array", SameIntrinsic, Rank::array}, |
| {"shift", AnyInt, Rank::dimRemovedOrScalar}, |
| {"boundary", SameIntrinsic, Rank::dimRemovedOrScalar, |
| Optionality::optional}, |
| OptionalDIM}, |
| SameIntrinsic, Rank::conformable, |
| IntrinsicClass::transformationalFunction}, |
| {"epsilon", |
| {{"x", SameReal, Rank::anyOrAssumedRank, Optionality::required, |
| common::Intent::In, {ArgFlag::canBeMoldNull}}}, |
| SameReal, Rank::scalar, IntrinsicClass::inquiryFunction}, |
| {"erf", {{"x", SameReal}}, SameReal}, |
| {"erfc", {{"x", SameReal}}, SameReal}, |
| {"erfc_scaled", {{"x", SameReal}}, SameReal}, |
| {"etime", |
| {{"values", TypePattern{RealType, KindCode::exactKind, 4}, Rank::vector, |
| Optionality::required, common::Intent::Out}}, |
| TypePattern{RealType, KindCode::exactKind, 4}}, |
| {"exp", {{"x", SameFloating}}, SameFloating}, |
| {"exp", {{"x", SameFloating}}, SameFloating}, |
| {"exponent", {{"x", AnyReal}}, DefaultInt}, |
| {"exp", {{"x", SameFloating}}, SameFloating}, |
| {"extends_type_of", |
| {{"a", ExtensibleDerived, Rank::anyOrAssumedRank, Optionality::required, |
| common::Intent::In, {ArgFlag::canBeMoldNull}}, |
| {"mold", ExtensibleDerived, Rank::anyOrAssumedRank, |
| Optionality::required, common::Intent::In, |
| {ArgFlag::canBeMoldNull}}}, |
| DefaultLogical, Rank::scalar, IntrinsicClass::inquiryFunction}, |
| {"failed_images", {OptionalTEAM, SizeDefaultKIND}, KINDInt, Rank::vector, |
| IntrinsicClass::transformationalFunction}, |
| {"findloc", |
| {{"array", AnyNumeric, Rank::array}, |
| {"value", AnyNumeric, Rank::scalar}, RequiredDIM, OptionalMASK, |
| SizeDefaultKIND, |
| {"back", AnyLogical, Rank::scalar, Optionality::optional}}, |
| KINDInt, Rank::locReduced, IntrinsicClass::transformationalFunction}, |
| {"findloc", |
| {{"array", AnyNumeric, Rank::array}, |
| {"value", AnyNumeric, Rank::scalar}, MissingDIM, OptionalMASK, |
| SizeDefaultKIND, |
| {"back", AnyLogical, Rank::scalar, Optionality::optional}}, |
| KINDInt, Rank::vector, IntrinsicClass::transformationalFunction}, |
| {"findloc", |
| {{"array", SameCharNoLen, Rank::array}, |
| {"value", SameCharNoLen, Rank::scalar}, RequiredDIM, OptionalMASK, |
| SizeDefaultKIND, |
| {"back", AnyLogical, Rank::scalar, Optionality::optional}}, |
| KINDInt, Rank::locReduced, IntrinsicClass::transformationalFunction}, |
| {"findloc", |
| {{"array", SameCharNoLen, Rank::array}, |
| {"value", SameCharNoLen, Rank::scalar}, MissingDIM, OptionalMASK, |
| SizeDefaultKIND, |
| {"back", AnyLogical, Rank::scalar, Optionality::optional}}, |
| KINDInt, Rank::vector, IntrinsicClass::transformationalFunction}, |
| {"findloc", |
| {{"array", AnyLogical, Rank::array}, |
| {"value", AnyLogical, Rank::scalar}, RequiredDIM, OptionalMASK, |
| SizeDefaultKIND, |
| {"back", AnyLogical, Rank::scalar, Optionality::optional}}, |
| KINDInt, Rank::locReduced, IntrinsicClass::transformationalFunction}, |
| {"findloc", |
| {{"array", AnyLogical, Rank::array}, |
| {"value", AnyLogical, Rank::scalar}, MissingDIM, OptionalMASK, |
| SizeDefaultKIND, |
| {"back", AnyLogical, Rank::scalar, Optionality::optional}}, |
| KINDInt, Rank::vector, IntrinsicClass::transformationalFunction}, |
| {"floor", {{"a", AnyReal}, DefaultingKIND}, KINDInt}, |
| {"fraction", {{"x", SameReal}}, SameReal}, |
| {"gamma", {{"x", SameReal}}, SameReal}, |
| {"get_team", {{"level", DefaultInt, Rank::scalar, Optionality::optional}}, |
| TeamType, Rank::scalar, IntrinsicClass::transformationalFunction}, |
| {"getcwd", |
| {{"c", DefaultChar, Rank::scalar, Optionality::required, |
| common::Intent::Out}}, |
| TypePattern{IntType, KindCode::greaterOrEqualToKind, 4}}, |
| {"getgid", {}, DefaultInt}, |
| {"getpid", {}, DefaultInt}, |
| {"getuid", {}, DefaultInt}, |
| {"huge", |
| {{"x", SameIntOrReal, Rank::anyOrAssumedRank, Optionality::required, |
| common::Intent::In, {ArgFlag::canBeMoldNull}}}, |
| SameIntOrReal, Rank::scalar, IntrinsicClass::inquiryFunction}, |
| {"hypot", {{"x", OperandReal}, {"y", OperandReal}}, OperandReal}, |
| {"iachar", {{"c", AnyChar}, DefaultingKIND}, KINDInt}, |
| {"iall", {{"array", SameInt, Rank::array}, RequiredDIM, OptionalMASK}, |
| SameInt, Rank::dimReduced, IntrinsicClass::transformationalFunction}, |
| {"iall", {{"array", SameInt, Rank::array}, MissingDIM, OptionalMASK}, |
| SameInt, Rank::scalar, IntrinsicClass::transformationalFunction}, |
| {"iany", {{"array", SameInt, Rank::array}, RequiredDIM, OptionalMASK}, |
| SameInt, Rank::dimReduced, IntrinsicClass::transformationalFunction}, |
| {"iany", {{"array", SameInt, Rank::array}, MissingDIM, OptionalMASK}, |
| SameInt, Rank::scalar, IntrinsicClass::transformationalFunction}, |
| {"iparity", {{"array", SameInt, Rank::array}, RequiredDIM, OptionalMASK}, |
| SameInt, Rank::dimReduced, IntrinsicClass::transformationalFunction}, |
| {"iparity", {{"array", SameInt, Rank::array}, MissingDIM, OptionalMASK}, |
| SameInt, Rank::scalar, IntrinsicClass::transformationalFunction}, |
| {"iand", {{"i", OperandInt}, {"j", OperandInt, Rank::elementalOrBOZ}}, |
| OperandInt}, |
| {"iand", {{"i", BOZ}, {"j", SameInt}}, SameInt}, |
| {"ibclr", {{"i", SameInt}, {"pos", AnyInt}}, SameInt}, |
| {"ibits", {{"i", SameInt}, {"pos", AnyInt}, {"len", AnyInt}}, SameInt}, |
| {"ibset", {{"i", SameInt}, {"pos", AnyInt}}, SameInt}, |
| {"ichar", {{"c", AnyChar}, DefaultingKIND}, KINDInt}, |
| {"ieor", {{"i", OperandInt}, {"j", OperandInt, Rank::elementalOrBOZ}}, |
| OperandInt}, |
| {"ieor", {{"i", BOZ}, {"j", SameInt}}, SameInt}, |
| {"image_index", |
| {{"coarray", AnyData, Rank::coarray}, {"sub", AnyInt, Rank::vector}}, |
| DefaultInt, Rank::scalar, IntrinsicClass::transformationalFunction}, |
| {"image_index", |
| {{"coarray", AnyData, Rank::coarray}, {"sub", AnyInt, Rank::vector}, |
| {"team", TeamType, Rank::scalar}}, |
| DefaultInt, Rank::scalar, IntrinsicClass::transformationalFunction}, |
| {"image_index", |
| {{"coarray", AnyData, Rank::coarray}, {"sub", AnyInt, Rank::vector}, |
| {"team_number", AnyInt, Rank::scalar}}, |
| DefaultInt, Rank::scalar, IntrinsicClass::transformationalFunction}, |
| {"image_status", {{"image", SameInt}, OptionalTEAM}, DefaultInt}, |
| {"index", |
| {{"string", SameCharNoLen}, {"substring", SameCharNoLen}, |
| {"back", AnyLogical, Rank::elemental, Optionality::optional}, |
| DefaultingKIND}, |
| KINDInt}, |
| {"int", {{"a", AnyNumeric, Rank::elementalOrBOZ}, DefaultingKIND}, KINDInt}, |
| {"int2", {{"a", AnyNumeric, Rank::elementalOrBOZ}}, |
| TypePattern{IntType, KindCode::exactKind, 2}}, |
| {"int8", {{"a", AnyNumeric, Rank::elementalOrBOZ}}, |
| TypePattern{IntType, KindCode::exactKind, 8}}, |
| {"int_ptr_kind", {}, DefaultInt, Rank::scalar}, |
| {"ior", {{"i", OperandInt}, {"j", OperandInt, Rank::elementalOrBOZ}}, |
| OperandInt}, |
| {"ior", {{"i", BOZ}, {"j", SameInt}}, SameInt}, |
| {"ishft", {{"i", SameInt}, {"shift", AnyInt}}, SameInt}, |
| {"ishftc", |
| {{"i", SameInt}, {"shift", AnyInt}, |
| {"size", AnyInt, Rank::elemental, Optionality::optional}}, |
| SameInt}, |
| {"isnan", {{"a", AnyFloating}}, DefaultLogical}, |
| {"is_contiguous", {{"array", Addressable, Rank::anyOrAssumedRank}}, |
| DefaultLogical, Rank::elemental, IntrinsicClass::inquiryFunction}, |
| {"is_iostat_end", {{"i", AnyInt}}, DefaultLogical}, |
| {"is_iostat_eor", {{"i", AnyInt}}, DefaultLogical}, |
| {"izext", {{"i", AnyInt}}, TypePattern{IntType, KindCode::exactKind, 2}}, |
| {"jzext", {{"i", AnyInt}}, DefaultInt}, |
| {"kind", |
| {{"x", AnyIntrinsic, Rank::anyOrAssumedRank, Optionality::required, |
| common::Intent::In, {ArgFlag::canBeMoldNull}}}, |
| DefaultInt, Rank::elemental, IntrinsicClass::inquiryFunction}, |
| {"lbound", |
| {{"array", AnyData, Rank::anyOrAssumedRank}, RequiredDIM, |
| SizeDefaultKIND}, |
| KINDInt, Rank::scalar, IntrinsicClass::inquiryFunction}, |
| {"lbound", {{"array", AnyData, Rank::arrayOrAssumedRank}, SizeDefaultKIND}, |
| KINDInt, Rank::vector, IntrinsicClass::inquiryFunction}, |
| {"lcobound", |
| {{"coarray", AnyData, Rank::coarray}, OptionalDIM, SizeDefaultKIND}, |
| KINDInt, Rank::scalarIfDim, IntrinsicClass::inquiryFunction}, |
| {"leadz", {{"i", AnyInt}}, DefaultInt}, |
| {"len", |
| {{"string", AnyChar, Rank::anyOrAssumedRank, Optionality::required, |
| common::Intent::In, {ArgFlag::canBeMoldNull}}, |
| DefaultingKIND}, |
| KINDInt, Rank::scalar, IntrinsicClass::inquiryFunction}, |
| {"len_trim", {{"string", AnyChar}, DefaultingKIND}, KINDInt}, |
| {"lge", {{"string_a", SameCharNoLen}, {"string_b", SameCharNoLen}}, |
| DefaultLogical}, |
| {"lgt", {{"string_a", SameCharNoLen}, {"string_b", SameCharNoLen}}, |
| DefaultLogical}, |
| {"lle", {{"string_a", SameCharNoLen}, {"string_b", SameCharNoLen}}, |
| DefaultLogical}, |
| {"llt", {{"string_a", SameCharNoLen}, {"string_b", SameCharNoLen}}, |
| DefaultLogical}, |
| {"lnblnk", {{"string", AnyChar}}, DefaultInt}, |
| {"loc", {{"x", Addressable, Rank::anyOrAssumedRank}}, SubscriptInt, |
| Rank::scalar}, |
| {"log", {{"x", SameFloating}}, SameFloating}, |
| {"log10", {{"x", SameReal}}, SameReal}, |
| {"logical", {{"l", AnyLogical}, DefaultingKIND}, KINDLogical}, |
| {"log_gamma", {{"x", SameReal}}, SameReal}, |
| {"malloc", {{"size", AnyInt}}, SubscriptInt}, |
| {"matmul", |
| {{"matrix_a", AnyLogical, Rank::vector}, |
| {"matrix_b", AnyLogical, Rank::matrix}}, |
| ResultLogical, Rank::vector, IntrinsicClass::transformationalFunction}, |
| {"matmul", |
| {{"matrix_a", AnyLogical, Rank::matrix}, |
| {"matrix_b", AnyLogical, Rank::vector}}, |
| ResultLogical, Rank::vector, IntrinsicClass::transformationalFunction}, |
| {"matmul", |
| {{"matrix_a", AnyLogical, Rank::matrix}, |
| {"matrix_b", AnyLogical, Rank::matrix}}, |
| ResultLogical, Rank::matrix, IntrinsicClass::transformationalFunction}, |
| {"matmul", |
| {{"matrix_a", AnyNumeric, Rank::vector}, |
| {"matrix_b", AnyNumeric, Rank::matrix}}, |
| ResultNumeric, Rank::vector, IntrinsicClass::transformationalFunction}, |
| {"matmul", |
| {{"matrix_a", AnyNumeric, Rank::matrix}, |
| {"matrix_b", AnyNumeric, Rank::vector}}, |
| ResultNumeric, Rank::vector, IntrinsicClass::transformationalFunction}, |
| {"matmul", |
| {{"matrix_a", AnyNumeric, Rank::matrix}, |
| {"matrix_b", AnyNumeric, Rank::matrix}}, |
| ResultNumeric, Rank::matrix, IntrinsicClass::transformationalFunction}, |
| {"maskl", {{"i", AnyInt}, DefaultingKIND}, KINDInt}, |
| {"maskr", {{"i", AnyInt}, DefaultingKIND}, KINDInt}, |
| {"max", |
| {{"a1", OperandIntOrReal}, {"a2", OperandIntOrReal}, |
| {"a3", OperandIntOrReal, Rank::elemental, Optionality::repeats}}, |
| OperandIntOrReal}, |
| {"max", |
| {{"a1", SameCharNoLen}, {"a2", SameCharNoLen}, |
| {"a3", SameCharNoLen, Rank::elemental, Optionality::repeats}}, |
| SameCharNoLen}, |
| {"maxexponent", |
| {{"x", AnyReal, Rank::anyOrAssumedRank, Optionality::required, |
| common::Intent::In, {ArgFlag::canBeMoldNull}}}, |
| DefaultInt, Rank::scalar, IntrinsicClass::inquiryFunction}, |
| {"maxloc", |
| {{"array", AnyRelatable, Rank::array}, RequiredDIM, OptionalMASK, |
| SizeDefaultKIND, |
| {"back", AnyLogical, Rank::scalar, Optionality::optional}}, |
| KINDInt, Rank::locReduced, IntrinsicClass::transformationalFunction}, |
| {"maxloc", |
| {{"array", AnyRelatable, Rank::array}, MissingDIM, OptionalMASK, |
| SizeDefaultKIND, |
| {"back", AnyLogical, Rank::scalar, Optionality::optional}}, |
| KINDInt, Rank::locReduced, IntrinsicClass::transformationalFunction}, |
| {"maxval", |
| {{"array", SameRelatable, Rank::array}, RequiredDIM, OptionalMASK}, |
| SameRelatable, Rank::dimReduced, |
| IntrinsicClass::transformationalFunction}, |
| {"maxval", |
| {{"array", SameRelatable, Rank::array}, MissingDIM, OptionalMASK}, |
| SameRelatable, Rank::scalar, IntrinsicClass::transformationalFunction}, |
| {"merge", |
| {{"tsource", SameType}, {"fsource", SameType}, {"mask", AnyLogical}}, |
| SameType}, |
| {"merge_bits", |
| {{"i", SameInt}, {"j", SameInt, Rank::elementalOrBOZ}, |
| {"mask", SameInt, Rank::elementalOrBOZ}}, |
| SameInt}, |
| {"merge_bits", |
| {{"i", BOZ}, {"j", SameInt}, {"mask", SameInt, Rank::elementalOrBOZ}}, |
| SameInt}, |
| {"min", |
| {{"a1", OperandIntOrReal}, {"a2", OperandIntOrReal}, |
| {"a3", OperandIntOrReal, Rank::elemental, Optionality::repeats}}, |
| OperandIntOrReal}, |
| {"min", |
| {{"a1", SameCharNoLen}, {"a2", SameCharNoLen}, |
| {"a3", SameCharNoLen, Rank::elemental, Optionality::repeats}}, |
| SameCharNoLen}, |
| {"minexponent", |
| {{"x", AnyReal, Rank::anyOrAssumedRank, Optionality::required, |
| common::Intent::In, {ArgFlag::canBeMoldNull}}}, |
| DefaultInt, Rank::scalar, IntrinsicClass::inquiryFunction}, |
| {"minloc", |
| {{"array", AnyRelatable, Rank::array}, RequiredDIM, OptionalMASK, |
| SizeDefaultKIND, |
| {"back", AnyLogical, Rank::scalar, Optionality::optional}}, |
| KINDInt, Rank::locReduced, IntrinsicClass::transformationalFunction}, |
| {"minloc", |
| {{"array", AnyRelatable, Rank::array}, MissingDIM, OptionalMASK, |
| SizeDefaultKIND, |
| {"back", AnyLogical, Rank::scalar, Optionality::optional}}, |
| KINDInt, Rank::locReduced, IntrinsicClass::transformationalFunction}, |
| {"minval", |
| {{"array", SameRelatable, Rank::array}, RequiredDIM, OptionalMASK}, |
| SameRelatable, Rank::dimReduced, |
| IntrinsicClass::transformationalFunction}, |
| {"minval", |
| {{"array", SameRelatable, Rank::array}, MissingDIM, OptionalMASK}, |
| SameRelatable, Rank::scalar, IntrinsicClass::transformationalFunction}, |
| {"mod", {{"a", OperandIntOrReal}, {"p", OperandIntOrReal}}, |
| OperandIntOrReal}, |
| {"modulo", {{"a", OperandIntOrReal}, {"p", OperandIntOrReal}}, |
| OperandIntOrReal}, |
| {"nearest", {{"x", SameReal}, {"s", AnyReal}}, SameReal}, |
| {"new_line", |
| {{"a", SameCharNoLen, Rank::anyOrAssumedRank, Optionality::required, |
| common::Intent::In, {ArgFlag::canBeMoldNull}}}, |
| SameCharNoLen, Rank::scalar, IntrinsicClass::inquiryFunction}, |
| {"nint", {{"a", AnyReal}, DefaultingKIND}, KINDInt}, |
| {"norm2", {{"x", SameReal, Rank::array}, RequiredDIM}, SameReal, |
| Rank::dimReduced, IntrinsicClass::transformationalFunction}, |
| {"norm2", {{"x", SameReal, Rank::array}, MissingDIM}, SameReal, |
| Rank::scalar, IntrinsicClass::transformationalFunction}, |
| {"not", {{"i", SameInt}}, SameInt}, |
| // NULL() is a special case handled in Probe() below |
| {"num_images", {}, DefaultInt, Rank::scalar, |
| IntrinsicClass::transformationalFunction}, |
| {"num_images", {{"team", TeamType, Rank::scalar}}, DefaultInt, Rank::scalar, |
| IntrinsicClass::transformationalFunction}, |
| {"num_images", {{"team_number", AnyInt, Rank::scalar}}, DefaultInt, |
| Rank::scalar, IntrinsicClass::transformationalFunction}, |
| {"out_of_range", |
| {{"x", AnyIntOrReal}, {"mold", AnyIntOrReal, Rank::scalar}}, |
| DefaultLogical}, |
| {"out_of_range", |
| {{"x", AnyReal}, {"mold", AnyInt, Rank::scalar}, |
| {"round", AnyLogical, Rank::scalar, Optionality::optional}}, |
| DefaultLogical}, |
| {"out_of_range", {{"x", AnyReal}, {"mold", AnyReal}}, DefaultLogical}, |
| {"pack", |
| {{"array", SameType, Rank::array}, |
| {"mask", AnyLogical, Rank::conformable}, |
| {"vector", SameType, Rank::vector, Optionality::optional}}, |
| SameType, Rank::vector, IntrinsicClass::transformationalFunction}, |
| {"parity", {{"mask", SameLogical, Rank::array}, OptionalDIM}, SameLogical, |
| Rank::dimReduced, IntrinsicClass::transformationalFunction}, |
| {"popcnt", {{"i", AnyInt}}, DefaultInt}, |
| {"poppar", {{"i", AnyInt}}, DefaultInt}, |
| {"product", |
| {{"array", SameNumeric, Rank::array}, RequiredDIM, OptionalMASK}, |
| SameNumeric, Rank::dimReduced, |
| IntrinsicClass::transformationalFunction}, |
| {"product", {{"array", SameNumeric, Rank::array}, MissingDIM, OptionalMASK}, |
| SameNumeric, Rank::scalar, IntrinsicClass::transformationalFunction}, |
| {"precision", |
| {{"x", AnyFloating, Rank::anyOrAssumedRank, Optionality::required, |
| common::Intent::In, {ArgFlag::canBeMoldNull}}}, |
| DefaultInt, Rank::scalar, IntrinsicClass::inquiryFunction}, |
| {"present", {{"a", Addressable, Rank::anyOrAssumedRank}}, DefaultLogical, |
| Rank::scalar, IntrinsicClass::inquiryFunction}, |
| {"radix", |
| {{"x", AnyIntOrReal, Rank::anyOrAssumedRank, Optionality::required, |
| common::Intent::In, {ArgFlag::canBeMoldNull}}}, |
| DefaultInt, Rank::scalar, IntrinsicClass::inquiryFunction}, |
| {"range", |
| {{"x", AnyNumeric, Rank::anyOrAssumedRank, Optionality::required, |
| common::Intent::In, {ArgFlag::canBeMoldNull}}}, |
| DefaultInt, Rank::scalar, IntrinsicClass::inquiryFunction}, |
| {"rank", |
| {{"a", AnyData, Rank::anyOrAssumedRank, Optionality::required, |
| common::Intent::In, {ArgFlag::canBeMoldNull}}}, |
| DefaultInt, Rank::scalar, IntrinsicClass::inquiryFunction}, |
| {"real", {{"a", SameComplex, Rank::elemental}}, |
| SameReal}, // 16.9.160(4)(ii) |
| {"real", {{"a", AnyNumeric, Rank::elementalOrBOZ}, DefaultingKIND}, |
| KINDReal}, |
| {"reduce", |
| {{"array", SameType, Rank::array}, |
| {"operation", SameType, Rank::reduceOperation}, RequiredDIM, |
| OptionalMASK, |
| {"identity", SameType, Rank::scalar, Optionality::optional}, |
| {"ordered", AnyLogical, Rank::scalar, Optionality::optional}}, |
| SameType, Rank::dimReduced, IntrinsicClass::transformationalFunction}, |
| {"reduce", |
| {{"array", SameType, Rank::array}, |
| {"operation", SameType, Rank::reduceOperation}, MissingDIM, |
| OptionalMASK, |
| {"identity", SameType, Rank::scalar, Optionality::optional}, |
| {"ordered", AnyLogical, Rank::scalar, Optionality::optional}}, |
| SameType, Rank::scalar, IntrinsicClass::transformationalFunction}, |
| {"rename", |
| {{"path1", DefaultChar, Rank::scalar}, |
| {"path2", DefaultChar, Rank::scalar}}, |
| DefaultInt, Rank::scalar}, |
| {"repeat", |
| {{"string", SameCharNoLen, Rank::scalar}, |
| {"ncopies", AnyInt, Rank::scalar}}, |
| SameCharNoLen, Rank::scalar, IntrinsicClass::transformationalFunction}, |
| {"reshape", |
| {{"source", SameType, Rank::array}, {"shape", AnyInt, Rank::shape}, |
| {"pad", SameType, Rank::array, Optionality::optional}, |
| {"order", AnyInt, Rank::vector, Optionality::optional}}, |
| SameType, Rank::shaped, IntrinsicClass::transformationalFunction}, |
| {"rrspacing", {{"x", SameReal}}, SameReal}, |
| {"same_type_as", |
| {{"a", ExtensibleDerived, Rank::anyOrAssumedRank, Optionality::required, |
| common::Intent::In, {ArgFlag::canBeMoldNull}}, |
| {"b", ExtensibleDerived, Rank::anyOrAssumedRank, |
| Optionality::required, common::Intent::In, |
| {ArgFlag::canBeMoldNull}}}, |
| DefaultLogical, Rank::scalar, IntrinsicClass::inquiryFunction}, |
| {"scale", {{"x", SameReal}, {"i", AnyInt}}, SameReal}, // == IEEE_SCALB() |
| {"scan", |
| {{"string", SameCharNoLen}, {"set", SameCharNoLen}, |
| {"back", AnyLogical, Rank::elemental, Optionality::optional}, |
| DefaultingKIND}, |
| KINDInt}, |
| {"second", {}, DefaultReal, Rank::scalar}, |
| {"selected_char_kind", {{"name", DefaultChar, Rank::scalar}}, DefaultInt, |
| Rank::scalar, IntrinsicClass::transformationalFunction}, |
| {"selected_int_kind", {{"r", AnyInt, Rank::scalar}}, DefaultInt, |
| Rank::scalar, IntrinsicClass::transformationalFunction}, |
| {"selected_logical_kind", {{"bits", AnyInt, Rank::scalar}}, DefaultInt, |
| Rank::scalar, IntrinsicClass::transformationalFunction}, |
| {"selected_real_kind", |
| {{"p", AnyInt, Rank::scalar}, |
| {"r", AnyInt, Rank::scalar, Optionality::optional}, |
| {"radix", AnyInt, Rank::scalar, Optionality::optional}}, |
| DefaultInt, Rank::scalar, IntrinsicClass::transformationalFunction}, |
| {"selected_real_kind", |
| {{"p", AnyInt, Rank::scalar, Optionality::optional}, |
| {"r", AnyInt, Rank::scalar}, |
| {"radix", AnyInt, Rank::scalar, Optionality::optional}}, |
| DefaultInt, Rank::scalar, IntrinsicClass::transformationalFunction}, |
| {"selected_real_kind", |
| {{"p", AnyInt, Rank::scalar, Optionality::optional}, |
| {"r", AnyInt, Rank::scalar, Optionality::optional}, |
| {"radix", AnyInt, Rank::scalar}}, |
| DefaultInt, Rank::scalar, IntrinsicClass::transformationalFunction}, |
| {"set_exponent", {{"x", SameReal}, {"i", AnyInt}}, SameReal}, |
| {"shape", {{"source", AnyData, Rank::anyOrAssumedRank}, SizeDefaultKIND}, |
| KINDInt, Rank::vector, IntrinsicClass::inquiryFunction}, |
| {"shifta", {{"i", SameInt}, {"shift", AnyInt}}, SameInt}, |
| {"shiftl", {{"i", SameInt}, {"shift", AnyInt}}, SameInt}, |
| {"shiftr", {{"i", SameInt}, {"shift", AnyInt}}, SameInt}, |
| {"sign", {{"a", SameInt}, {"b", AnyInt}}, SameInt}, |
| {"sign", {{"a", SameReal}, {"b", AnyReal}}, SameReal}, |
| {"sin", {{"x", SameFloating}}, SameFloating}, |
| {"sind", {{"x", SameFloating}}, SameFloating}, |
| {"sinh", {{"x", SameFloating}}, SameFloating}, |
| {"size", |
| {{"array", AnyData, Rank::arrayOrAssumedRank}, |
| OptionalDIM, // unless array is assumed-size |
| SizeDefaultKIND}, |
| KINDInt, Rank::scalar, IntrinsicClass::inquiryFunction}, |
| {"sizeof", {{"a", AnyData, Rank::anyOrAssumedRank}}, SubscriptInt, |
| Rank::scalar, IntrinsicClass::inquiryFunction}, |
| {"spacing", {{"x", SameReal}}, SameReal}, |
| {"spread", |
| {{"source", SameType, Rank::known, Optionality::required, |
| common::Intent::In, {ArgFlag::notAssumedSize}}, |
| RequiredDIM, {"ncopies", AnyInt, Rank::scalar}}, |
| SameType, Rank::rankPlus1, IntrinsicClass::transformationalFunction}, |
| {"sqrt", {{"x", SameFloating}}, SameFloating}, |
| {"stopped_images", {OptionalTEAM, SizeDefaultKIND}, KINDInt, Rank::vector, |
| IntrinsicClass::transformationalFunction}, |
| {"storage_size", |
| {{"a", AnyData, Rank::anyOrAssumedRank, Optionality::required, |
| common::Intent::In, {ArgFlag::canBeMoldNull}}, |
| SizeDefaultKIND}, |
| KINDInt, Rank::scalar, IntrinsicClass::inquiryFunction}, |
| {"sum", {{"array", SameNumeric, Rank::array}, RequiredDIM, OptionalMASK}, |
| SameNumeric, Rank::dimReduced, |
| IntrinsicClass::transformationalFunction}, |
| {"sum", {{"array", SameNumeric, Rank::array}, MissingDIM, OptionalMASK}, |
| SameNumeric, Rank::scalar, IntrinsicClass::transformationalFunction}, |
| {"system", {{"command", DefaultChar, Rank::scalar}}, DefaultInt, |
| Rank::scalar}, |
| {"tan", {{"x", SameFloating}}, SameFloating}, |
| {"tand", {{"x", SameFloating}}, SameFloating}, |
| {"tanh", {{"x", SameFloating}}, SameFloating}, |
| {"team_number", {OptionalTEAM}, DefaultInt, Rank::scalar, |
| IntrinsicClass::transformationalFunction}, |
| {"this_image", |
| {{"coarray", AnyData, Rank::coarray}, RequiredDIM, OptionalTEAM}, |
| DefaultInt, Rank::scalar, IntrinsicClass::transformationalFunction}, |
| {"this_image", {{"coarray", AnyData, Rank::coarray}, OptionalTEAM}, |
| DefaultInt, Rank::scalar, IntrinsicClass::transformationalFunction}, |
| {"this_image", {OptionalTEAM}, DefaultInt, Rank::scalar, |
| IntrinsicClass::transformationalFunction}, |
| {"tiny", |
| {{"x", SameReal, Rank::anyOrAssumedRank, Optionality::required, |
| common::Intent::In, {ArgFlag::canBeMoldNull}}}, |
| SameReal, Rank::scalar, IntrinsicClass::inquiryFunction}, |
| {"trailz", {{"i", AnyInt}}, DefaultInt}, |
| {"transfer", |
| {{"source", AnyData, Rank::known}, {"mold", SameType, Rank::scalar}}, |
| SameType, Rank::scalar, IntrinsicClass::transformationalFunction}, |
| {"transfer", |
| {{"source", AnyData, Rank::known}, {"mold", SameType, Rank::array}}, |
| SameType, Rank::vector, IntrinsicClass::transformationalFunction}, |
| {"transfer", |
| {{"source", AnyData, Rank::anyOrAssumedRank}, |
| {"mold", SameType, Rank::anyOrAssumedRank}, |
| {"size", AnyInt, Rank::scalar}}, |
| SameType, Rank::vector, IntrinsicClass::transformationalFunction}, |
| {"transpose", {{"matrix", SameType, Rank::matrix}}, SameType, Rank::matrix, |
| IntrinsicClass::transformationalFunction}, |
| {"trim", {{"string", SameCharNoLen, Rank::scalar}}, SameCharNoLen, |
| Rank::scalar, IntrinsicClass::transformationalFunction}, |
| {"ubound", |
| {{"array", AnyData, Rank::anyOrAssumedRank}, RequiredDIM, |
| SizeDefaultKIND}, |
| KINDInt, Rank::scalar, IntrinsicClass::inquiryFunction}, |
| {"ubound", {{"array", AnyData, Rank::arrayOrAssumedRank}, SizeDefaultKIND}, |
| KINDInt, Rank::vector, IntrinsicClass::inquiryFunction}, |
| {"ucobound", |
| {{"coarray", AnyData, Rank::coarray}, OptionalDIM, SizeDefaultKIND}, |
| KINDInt, Rank::scalarIfDim, IntrinsicClass::inquiryFunction}, |
| {"unpack", |
| {{"vector", SameType, Rank::vector}, {"mask", AnyLogical, Rank::array}, |
| {"field", SameType, Rank::conformable}}, |
| SameType, Rank::conformable, IntrinsicClass::transformationalFunction}, |
| {"verify", |
| {{"string", SameCharNoLen}, {"set", SameCharNoLen}, |
| {"back", AnyLogical, Rank::elemental, Optionality::optional}, |
| DefaultingKIND}, |
| KINDInt}, |
| {"__builtin_compiler_options", {}, DefaultChar}, |
| {"__builtin_compiler_version", {}, DefaultChar}, |
| {"__builtin_fma", {{"f1", SameReal}, {"f2", SameReal}, {"f3", SameReal}}, |
| SameReal}, |
| {"__builtin_ieee_int", |
| {{"a", AnyFloating}, {"round", IeeeRoundType}, DefaultingKIND}, |
| KINDInt}, |
| {"__builtin_ieee_is_nan", {{"a", AnyFloating}}, DefaultLogical}, |
| {"__builtin_ieee_is_negative", {{"a", AnyFloating}}, DefaultLogical}, |
| {"__builtin_ieee_is_normal", {{"a", AnyFloating}}, DefaultLogical}, |
| {"__builtin_ieee_next_after", {{"x", SameReal}, {"y", AnyReal}}, SameReal}, |
| {"__builtin_ieee_next_down", {{"x", SameReal}}, SameReal}, |
| {"__builtin_ieee_next_up", {{"x", SameReal}}, SameReal}, |
| {"__builtin_ieee_real", {{"a", AnyIntOrReal}, DefaultingKIND}, KINDReal}, |
| {"__builtin_ieee_support_datatype", |
| {{"x", AnyReal, Rank::elemental, Optionality::optional}}, |
| DefaultLogical}, |
| {"__builtin_ieee_support_denormal", |
| {{"x", AnyReal, Rank::elemental, Optionality::optional}}, |
| DefaultLogical}, |
| {"__builtin_ieee_support_divide", |
| {{"x", AnyReal, Rank::elemental, Optionality::optional}}, |
| DefaultLogical}, |
| {"__builtin_ieee_support_flag", |
| {{"flag", IeeeFlagType, Rank::scalar}, |
| {"x", AnyReal, Rank::elemental, Optionality::optional}}, |
| DefaultLogical}, |
| {"__builtin_ieee_support_halting", {{"flag", IeeeFlagType, Rank::scalar}}, |
| DefaultLogical}, |
| {"__builtin_ieee_support_inf", |
| {{"x", AnyReal, Rank::elemental, Optionality::optional}}, |
| DefaultLogical}, |
| {"__builtin_ieee_support_io", |
| {{"x", AnyReal, Rank::elemental, Optionality::optional}}, |
| DefaultLogical}, |
| {"__builtin_ieee_support_nan", |
| {{"x", AnyReal, Rank::elemental, Optionality::optional}}, |
| DefaultLogical}, |
| {"__builtin_ieee_support_rounding", |
| {{"round_value", IeeeRoundType, Rank::scalar}, |
| {"x", AnyReal, Rank::elemental, Optionality::optional}}, |
| DefaultLogical}, |
| {"__builtin_ieee_support_sqrt", |
| {{"x", AnyReal, Rank::elemental, Optionality::optional}}, |
| DefaultLogical}, |
| {"__builtin_ieee_support_standard", |
| {{"x", AnyReal, Rank::elemental, Optionality::optional}}, |
| DefaultLogical}, |
| {"__builtin_ieee_support_subnormal", |
| {{"x", AnyReal, Rank::elemental, Optionality::optional}}, |
| DefaultLogical}, |
| {"__builtin_ieee_support_underflow_control", |
| {{"x", AnyReal, Rank::elemental, Optionality::optional}}, |
| DefaultLogical}, |
| {"__builtin_numeric_storage_size", {}, DefaultInt}, |
| }; |
| |
| // TODO: Coarray intrinsic functions |
| // COSHAPE |
| // TODO: Non-standard intrinsic functions |
| // SHIFT, |
| // COMPL, EQV, NEQV, INT8, JINT, JNINT, KNINT, |
| // QCMPLX, QEXT, QFLOAT, QREAL, DNUM, |
| // INUM, JNUM, KNUM, QNUM, RNUM, RAN, RANF, ILEN, |
| // MCLOCK, SECNDS, COTAN, IBCHNG, ISHA, ISHC, ISHL, IXOR |
| // IARG, IARGC, NARGS, NUMARG, BADDRESS, IADDR, CACHESIZE, |
| // EOF, FP_CLASS, INT_PTR_KIND, MALLOC |
| // probably more (these are PGI + Intel, possibly incomplete) |
| // TODO: Optionally warn on use of non-standard intrinsics: |
| // LOC, probably others |
| // TODO: Optionally warn on operand promotion extension |
| |
| // Aliases for a few generic intrinsic functions for legacy |
| // compatibility and builtins. |
| static const std::pair<const char *, const char *> genericAlias[]{ |
| {"and", "iand"}, |
| {"getenv", "get_environment_variable"}, |
| {"imag", "aimag"}, |
| {"lshift", "shiftl"}, |
| {"or", "ior"}, |
| {"rshift", "shifta"}, |
| {"xor", "ieor"}, |
| {"__builtin_ieee_selected_real_kind", "selected_real_kind"}, |
| }; |
| |
| // The following table contains the intrinsic functions listed in |
| // Tables 16.2 and 16.3 in Fortran 2018. The "unrestricted" functions |
| // in Table 16.2 can be used as actual arguments, PROCEDURE() interfaces, |
| // and procedure pointer targets. |
| // Note that the restricted conversion functions dcmplx, dreal, float, idint, |
| // ifix, and sngl are extended to accept any argument kind because this is a |
| // common Fortran compilers behavior, and as far as we can tell, is safe and |
| // useful. |
| struct SpecificIntrinsicInterface : public IntrinsicInterface { |
| const char *generic{nullptr}; |
| bool isRestrictedSpecific{false}; |
| // Exact actual/dummy type matching is required by default for specific |
| // intrinsics. If useGenericAndForceResultType is set, then the probing will |
| // also attempt to use the related generic intrinsic and to convert the result |
| // to the specific intrinsic result type if needed. This also prevents |
| // using the generic name so that folding can insert the conversion on the |
| // result and not the arguments. |
| // |
| // This is not enabled on all specific intrinsics because an alternative |
| // is to convert the actual arguments to the required dummy types and this is |
| // not numerically equivalent. |
| // e.g. IABS(INT(i, 4)) not equiv to INT(ABS(i), 4). |
| // This is allowed for restricted min/max specific functions because |
| // the expected behavior is clear from their definitions. A warning is though |
| // always emitted because other compilers' behavior is not ubiquitous here and |
| // the results in case of conversion overflow might not be equivalent. |
| // e.g for MIN0: INT(MIN(2147483647_8, 2*2147483647_8), 4) = 2147483647_4 |
| // but: MIN(INT(2147483647_8, 4), INT(2*2147483647_8, 4)) = -2_4 |
| // xlf and ifort return the first, and pgfortran the later. f18 will return |
| // the first because this matches more closely the MIN0 definition in |
| // Fortran 2018 table 16.3 (although it is still an extension to allow |
| // non default integer argument in MIN0). |
| bool useGenericAndForceResultType{false}; |
| }; |
| |
| static const SpecificIntrinsicInterface specificIntrinsicFunction[]{ |
| {{"abs", {{"a", DefaultReal}}, DefaultReal}}, |
| {{"acos", {{"x", DefaultReal}}, DefaultReal}}, |
| {{"aimag", {{"z", DefaultComplex}}, DefaultReal}}, |
| {{"aint", {{"a", DefaultReal}}, DefaultReal}}, |
| {{"alog", {{"x", DefaultReal}}, DefaultReal}, "log"}, |
| {{"alog10", {{"x", DefaultReal}}, DefaultReal}, "log10"}, |
| {{"amax0", |
| {{"a1", DefaultInt}, {"a2", DefaultInt}, |
| {"a3", DefaultInt, Rank::elemental, Optionality::repeats}}, |
| DefaultReal}, |
| "max", true, true}, |
| {{"amax1", |
| {{"a1", DefaultReal}, {"a2", DefaultReal}, |
| {"a3", DefaultReal, Rank::elemental, Optionality::repeats}}, |
| DefaultReal}, |
| "max", true, true}, |
| {{"amin0", |
| {{"a1", DefaultInt}, {"a2", DefaultInt}, |
| {"a3", DefaultInt, Rank::elemental, Optionality::repeats}}, |
| DefaultReal}, |
| "min", true, true}, |
| {{"amin1", |
| {{"a1", DefaultReal}, {"a2", DefaultReal}, |
| {"a3", DefaultReal, Rank::elemental, Optionality::repeats}}, |
| DefaultReal}, |
| "min", true, true}, |
| {{"amod", {{"a", DefaultReal}, {"p", DefaultReal}}, DefaultReal}, "mod"}, |
| {{"anint", {{"a", DefaultReal}}, DefaultReal}}, |
| {{"asin", {{"x", DefaultReal}}, DefaultReal}}, |
| {{"atan", {{"x", DefaultReal}}, DefaultReal}}, |
| {{"atan2", {{"y", DefaultReal}, {"x", DefaultReal}}, DefaultReal}}, |
| {{"babs", {{"a", TypePattern{IntType, KindCode::exactKind, 1}}}, |
| TypePattern{IntType, KindCode::exactKind, 1}}, |
| "abs"}, |
| {{"cabs", {{"a", DefaultComplex}}, DefaultReal}, "abs"}, |
| {{"ccos", {{"x", DefaultComplex}}, DefaultComplex}, "cos"}, |
| {{"cdabs", {{"a", DoublePrecisionComplex}}, DoublePrecision}, "abs"}, |
| {{"cdcos", {{"x", DoublePrecisionComplex}}, DoublePrecisionComplex}, "cos"}, |
| {{"cdexp", {{"x", DoublePrecisionComplex}}, DoublePrecisionComplex}, "exp"}, |
| {{"cdlog", {{"x", DoublePrecisionComplex}}, DoublePrecisionComplex}, "log"}, |
| {{"cdsin", {{"x", DoublePrecisionComplex}}, DoublePrecisionComplex}, "sin"}, |
| {{"cdsqrt", {{"x", DoublePrecisionComplex}}, DoublePrecisionComplex}, |
| "sqrt"}, |
| {{"cexp", {{"x", DefaultComplex}}, DefaultComplex}, "exp"}, |
| {{"clog", {{"x", DefaultComplex}}, DefaultComplex}, "log"}, |
| {{"conjg", {{"z", DefaultComplex}}, DefaultComplex}}, |
| {{"cos", {{"x", DefaultReal}}, DefaultReal}}, |
| {{"cosh", {{"x", DefaultReal}}, DefaultReal}}, |
| {{"csin", {{"x", DefaultComplex}}, DefaultComplex}, "sin"}, |
| {{"csqrt", {{"x", DefaultComplex}}, DefaultComplex}, "sqrt"}, |
| {{"ctan", {{"x", DefaultComplex}}, DefaultComplex}, "tan"}, |
| {{"dabs", {{"a", DoublePrecision}}, DoublePrecision}, "abs"}, |
| {{"dacos", {{"x", DoublePrecision}}, DoublePrecision}, "acos"}, |
| {{"dasin", {{"x", DoublePrecision}}, DoublePrecision}, "asin"}, |
| {{"datan", {{"x", DoublePrecision}}, DoublePrecision}, "atan"}, |
| {{"datan2", {{"y", DoublePrecision}, {"x", DoublePrecision}}, |
| DoublePrecision}, |
| "atan2"}, |
| {{"dcmplx", {{"x", AnyComplex}}, DoublePrecisionComplex}, "cmplx", true}, |
| {{"dcmplx", |
| {{"x", AnyIntOrReal, Rank::elementalOrBOZ}, |
| {"y", AnyIntOrReal, Rank::elementalOrBOZ, Optionality::optional}}, |
| DoublePrecisionComplex}, |
| "cmplx", true}, |
| {{"dconjg", {{"z", DoublePrecisionComplex}}, DoublePrecisionComplex}, |
| "conjg"}, |
| {{"dcos", {{"x", DoublePrecision}}, DoublePrecision}, "cos"}, |
| {{"dcosh", {{"x", DoublePrecision}}, DoublePrecision}, "cosh"}, |
| {{"ddim", {{"x", DoublePrecision}, {"y", DoublePrecision}}, |
| DoublePrecision}, |
| "dim"}, |
| {{"derf", {{"x", DoublePrecision}}, DoublePrecision}, "erf"}, |
| {{"dexp", {{"x", DoublePrecision}}, DoublePrecision}, "exp"}, |
| {{"dfloat", {{"a", AnyInt}}, DoublePrecision}, "real", true}, |
| {{"dim", {{"x", DefaultReal}, {"y", DefaultReal}}, DefaultReal}}, |
| {{"dimag", {{"z", DoublePrecisionComplex}}, DoublePrecision}, "aimag"}, |
| {{"dint", {{"a", DoublePrecision}}, DoublePrecision}, "aint"}, |
| {{"dlog", {{"x", DoublePrecision}}, DoublePrecision}, "log"}, |
| {{"dlog10", {{"x", DoublePrecision}}, DoublePrecision}, "log10"}, |
| {{"dmax1", |
| {{"a1", DoublePrecision}, {"a2", DoublePrecision}, |
| {"a3", DoublePrecision, Rank::elemental, Optionality::repeats}}, |
| DoublePrecision}, |
| "max", true, true}, |
| {{"dmin1", |
| {{"a1", DoublePrecision}, {"a2", DoublePrecision}, |
| {"a3", DoublePrecision, Rank::elemental, Optionality::repeats}}, |
| DoublePrecision}, |
| "min", true, true}, |
| {{"dmod", {{"a", DoublePrecision}, {"p", DoublePrecision}}, |
| DoublePrecision}, |
| "mod"}, |
| {{"dnint", {{"a", DoublePrecision}}, DoublePrecision}, "anint"}, |
| {{"dprod", {{"x", DefaultReal}, {"y", DefaultReal}}, DoublePrecision}}, |
| {{"dreal", {{"a", AnyComplex}}, DoublePrecision}, "real", true}, |
| {{"dsign", {{"a", DoublePrecision}, {"b", DoublePrecision}}, |
| DoublePrecision}, |
| "sign"}, |
| {{"dsin", {{"x", DoublePrecision}}, DoublePrecision}, "sin"}, |
| {{"dsinh", {{"x", DoublePrecision}}, DoublePrecision}, "sinh"}, |
| {{"dsqrt", {{"x", DoublePrecision}}, DoublePrecision}, "sqrt"}, |
| {{"dtan", {{"x", DoublePrecision}}, DoublePrecision}, "tan"}, |
| {{"dtanh", {{"x", DoublePrecision}}, DoublePrecision}, "tanh"}, |
| {{"exp", {{"x", DefaultReal}}, DefaultReal}}, |
| {{"float", {{"a", AnyInt}}, DefaultReal}, "real", true}, |
| {{"iabs", {{"a", DefaultInt}}, DefaultInt}, "abs"}, |
| {{"idim", {{"x", DefaultInt}, {"y", DefaultInt}}, DefaultInt}, "dim"}, |
| {{"idint", {{"a", AnyReal}}, DefaultInt}, "int", true}, |
| {{"idnint", {{"a", DoublePrecision}}, DefaultInt}, "nint"}, |
| {{"ifix", {{"a", AnyReal}}, DefaultInt}, "int", true}, |
| {{"iiabs", {{"a", TypePattern{IntType, KindCode::exactKind, 2}}}, |
| TypePattern{IntType, KindCode::exactKind, 2}}, |
| "abs"}, |
| // The definition of the unrestricted specific intrinsic function INDEX |
| // in F'77 and F'90 has only two arguments; later standards omit the |
| // argument information for all unrestricted specific intrinsic |
| // procedures. No compiler supports an implementation that allows |
| // INDEX with BACK= to work when associated as an actual procedure or |
| // procedure pointer target. |
| {{"index", {{"string", DefaultChar}, {"substring", DefaultChar}}, |
| DefaultInt}}, |
| {{"isign", {{"a", DefaultInt}, {"b", DefaultInt}}, DefaultInt}, "sign"}, |
| {{"jiabs", {{"a", TypePattern{IntType, KindCode::exactKind, 4}}}, |
| TypePattern{IntType, KindCode::exactKind, 4}}, |
| "abs"}, |
| {{"kiabs", {{"a", TypePattern{IntType, KindCode::exactKind, 8}}}, |
| TypePattern{IntType, KindCode::exactKind, 8}}, |
| "abs"}, |
| {{"kidnnt", {{"a", DoublePrecision}}, |
| TypePattern{IntType, KindCode::exactKind, 8}}, |
| "nint"}, |
| {{"knint", {{"a", DefaultReal}}, |
| TypePattern{IntType, KindCode::exactKind, 8}}, |
| "nint"}, |
| {{"len", {{"string", DefaultChar, Rank::anyOrAssumedRank}}, DefaultInt, |
| Rank::scalar, IntrinsicClass::inquiryFunction}}, |
| {{"lge", {{"string_a", DefaultChar}, {"string_b", DefaultChar}}, |
| DefaultLogical}, |
| "lge", true}, |
| {{"lgt", {{"string_a", DefaultChar}, {"string_b", DefaultChar}}, |
| DefaultLogical}, |
| "lgt", true}, |
| {{"lle", {{"string_a", DefaultChar}, {"string_b", DefaultChar}}, |
| DefaultLogical}, |
| "lle", true}, |
| {{"llt", {{"string_a", DefaultChar}, {"string_b", DefaultChar}}, |
| DefaultLogical}, |
| "llt", true}, |
| {{"log", {{"x", DefaultReal}}, DefaultReal}}, |
| {{"log10", {{"x", DefaultReal}}, DefaultReal}}, |
| {{"max0", |
| {{"a1", DefaultInt}, {"a2", DefaultInt}, |
| {"a3", DefaultInt, Rank::elemental, Optionality::repeats}}, |
| DefaultInt}, |
| "max", true, true}, |
| {{"max1", |
| {{"a1", DefaultReal}, {"a2", DefaultReal}, |
| {"a3", DefaultReal, Rank::elemental, Optionality::repeats}}, |
| DefaultInt}, |
| "max", true, true}, |
| {{"min0", |
| {{"a1", DefaultInt}, {"a2", DefaultInt}, |
| {"a3", DefaultInt, Rank::elemental, Optionality::repeats}}, |
| DefaultInt}, |
| "min", true, true}, |
| {{"min1", |
| {{"a1", DefaultReal}, {"a2", DefaultReal}, |
| {"a3", DefaultReal, Rank::elemental, Optionality::repeats}}, |
| DefaultInt}, |
| "min", true, true}, |
| {{"mod", {{"a", DefaultInt}, {"p", DefaultInt}}, DefaultInt}}, |
| {{"nint", {{"a", DefaultReal}}, DefaultInt}}, |
| {{"sign", {{"a", DefaultReal}, {"b", DefaultReal}}, DefaultReal}}, |
| {{"sin", {{"x", DefaultReal}}, DefaultReal}}, |
| {{"sinh", {{"x", DefaultReal}}, DefaultReal}}, |
| {{"sngl", {{"a", AnyReal}}, DefaultReal}, "real", true}, |
| {{"sqrt", {{"x", DefaultReal}}, DefaultReal}}, |
| {{"tan", {{"x", DefaultReal}}, DefaultReal}}, |
| {{"tanh", {{"x", DefaultReal}}, DefaultReal}}, |
| {{"zabs", {{"a", TypePattern{ComplexType, KindCode::exactKind, 8}}}, |
| TypePattern{RealType, KindCode::exactKind, 8}}, |
| "abs"}, |
| }; |
| |
| static const IntrinsicInterface intrinsicSubroutine[]{ |
| {"abort", {}, {}, Rank::elemental, IntrinsicClass::impureSubroutine}, |
| {"atomic_and", |
| {{"atom", AtomicInt, Rank::atom, Optionality::required, |
| common::Intent::InOut}, |
| {"value", AnyInt, Rank::scalar, Optionality::required, |
| common::Intent::In}, |
| {"stat", AnyInt, Rank::scalar, Optionality::optional, |
| common::Intent::Out}}, |
| {}, Rank::elemental, IntrinsicClass::atomicSubroutine}, |
| {"atomic_cas", |
| {{"atom", SameAtom, Rank::atom, Optionality::required, |
| common::Intent::InOut}, |
| {"old", SameAtom, Rank::scalar, Optionality::required, |
| common::Intent::Out}, |
| {"compare", SameAtom, Rank::scalar, Optionality::required, |
| common::Intent::In}, |
| {"new", SameAtom, Rank::scalar, Optionality::required, |
| common::Intent::In}, |
| {"stat", AnyInt, Rank::scalar, Optionality::optional, |
| common::Intent::Out}}, |
| {}, Rank::elemental, IntrinsicClass::atomicSubroutine}, |
| {"atomic_define", |
| {{"atom", AtomicIntOrLogical, Rank::atom, Optionality::required, |
| common::Intent::Out}, |
| {"value", AnyIntOrLogical, Rank::scalar, Optionality::required, |
| common::Intent::In}, |
| {"stat", AnyInt, Rank::scalar, Optionality::optional, |
| common::Intent::Out}}, |
| {}, Rank::elemental, IntrinsicClass::atomicSubroutine}, |
| {"atomic_fetch_add", |
| {{"atom", AtomicInt, Rank::atom, Optionality::required, |
| common::Intent::InOut}, |
| {"value", AnyInt, Rank::scalar, Optionality::required, |
| common::Intent::In}, |
| {"old", AtomicInt, Rank::scalar, Optionality::required, |
| common::Intent::Out}, |
| {"stat", AnyInt, Rank::scalar, Optionality::optional, |
| common::Intent::Out}}, |
| {}, Rank::elemental, IntrinsicClass::atomicSubroutine}, |
| {"atomic_fetch_and", |
| {{"atom", AtomicInt, Rank::atom, Optionality::required, |
| common::Intent::InOut}, |
| {"value", AnyInt, Rank::scalar, Optionality::required, |
| common::Intent::In}, |
| {"old", AtomicInt, Rank::scalar, Optionality::required, |
| common::Intent::Out}, |
| {"stat", AnyInt, Rank::scalar, Optionality::optional, |
| common::Intent::Out}}, |
| {}, Rank::elemental, IntrinsicClass::atomicSubroutine}, |
| {"atomic_fetch_or", |
| {{"atom", AtomicInt, Rank::atom, Optionality::required, |
| common::Intent::InOut}, |
| {"value", AnyInt, Rank::scalar, Optionality::required, |
| common::Intent::In}, |
| {"old", AtomicInt, Rank::scalar, Optionality::required, |
| common::Intent::Out}, |
| {"stat", AnyInt, Rank::scalar, Optionality::optional, |
| common::Intent::Out}}, |
| {}, Rank::elemental, IntrinsicClass::atomicSubroutine}, |
| {"atomic_fetch_xor", |
| {{"atom", AtomicInt, Rank::atom, Optionality::required, |
| common::Intent::InOut}, |
| {"value", AnyInt, Rank::scalar, Optionality::required, |
| common::Intent::In}, |
| {"old", AtomicInt, Rank::scalar, Optionality::required, |
| common::Intent::Out}, |
| {"stat", AnyInt, Rank::scalar, Optionality::optional, |
| common::Intent::Out}}, |
| {}, Rank::elemental, IntrinsicClass::atomicSubroutine}, |
| {"atomic_or", |
| {{"atom", AtomicInt, Rank::atom, Optionality::required, |
| common::Intent::InOut}, |
| {"value", AnyInt, Rank::scalar, Optionality::required, |
| common::Intent::In}, |
| {"stat", AnyInt, Rank::scalar, Optionality::optional, |
| common::Intent::Out}}, |
| {}, Rank::elemental, IntrinsicClass::atomicSubroutine}, |
| {"atomic_ref", |
| {{"value", AnyIntOrLogical, Rank::scalar, Optionality::required, |
| common::Intent::Out}, |
| {"atom", AtomicIntOrLogical, Rank::atom, Optionality::required, |
| common::Intent::In}, |
| {"stat", AnyInt, Rank::scalar, Optionality::optional, |
| common::Intent::Out}}, |
| {}, Rank::elemental, IntrinsicClass::atomicSubroutine}, |
| {"atomic_xor", |
| {{"atom", AtomicInt, Rank::atom, Optionality::required, |
| common::Intent::InOut}, |
| {"value", AnyInt, Rank::scalar, Optionality::required, |
| common::Intent::In}, |
| {"stat", AnyInt, Rank::scalar, Optionality::optional, |
| common::Intent::Out}}, |
| {}, Rank::elemental, IntrinsicClass::atomicSubroutine}, |
| {"co_broadcast", |
| {{"a", AnyData, Rank::anyOrAssumedRank, Optionality::required, |
| common::Intent::InOut}, |
| {"source_image", AnyInt, Rank::scalar, Optionality::required, |
| common::Intent::In}, |
| {"stat", AnyInt, Rank::scalar, Optionality::optional, |
| common::Intent::Out}, |
| {"errmsg", DefaultChar, Rank::scalar, Optionality::optional, |
| common::Intent::InOut}}, |
| {}, Rank::elemental, IntrinsicClass::collectiveSubroutine}, |
| {"co_max", |
| {{"a", AnyIntOrRealOrChar, Rank::anyOrAssumedRank, |
| Optionality::required, common::Intent::InOut}, |
| {"result_image", AnyInt, Rank::scalar, Optionality::optional, |
| common::Intent::In}, |
| {"stat", AnyInt, Rank::scalar, Optionality::optional, |
| common::Intent::Out}, |
| {"errmsg", DefaultChar, Rank::scalar, Optionality::optional, |
| common::Intent::InOut}}, |
| {}, Rank::elemental, IntrinsicClass::collectiveSubroutine}, |
| {"co_min", |
| {{"a", AnyIntOrRealOrChar, Rank::anyOrAssumedRank, |
| Optionality::required, common::Intent::InOut}, |
| {"result_image", AnyInt, Rank::scalar, Optionality::optional, |
| common::Intent::In}, |
| {"stat", AnyInt, Rank::scalar, Optionality::optional, |
| common::Intent::Out}, |
| {"errmsg", DefaultChar, Rank::scalar, Optionality::optional, |
| common::Intent::InOut}}, |
| {}, Rank::elemental, IntrinsicClass::collectiveSubroutine}, |
| {"co_sum", |
| {{"a", AnyNumeric, Rank::anyOrAssumedRank, Optionality::required, |
| common::Intent::InOut}, |
| {"result_image", AnyInt, Rank::scalar, Optionality::optional, |
| common::Intent::In}, |
| {"stat", AnyInt, Rank::scalar, Optionality::optional, |
| common::Intent::Out}, |
| {"errmsg", DefaultChar, Rank::scalar, Optionality::optional, |
| common::Intent::InOut}}, |
| {}, Rank::elemental, IntrinsicClass::collectiveSubroutine}, |
| {"cpu_time", |
| {{"time", AnyReal, Rank::scalar, Optionality::required, |
| common::Intent::Out}}, |
| {}, Rank::elemental, IntrinsicClass::impureSubroutine}, |
| {"date_and_time", |
| {{"date", DefaultChar, Rank::scalar, Optionality::optional, |
| common::Intent::Out}, |
| {"time", DefaultChar, Rank::scalar, Optionality::optional, |
| common::Intent::Out}, |
| {"zone", DefaultChar, Rank::scalar, Optionality::optional, |
| common::Intent::Out}, |
| {"values", AnyInt, Rank::vector, Optionality::optional, |
| common::Intent::Out}}, |
| {}, Rank::elemental, IntrinsicClass::impureSubroutine}, |
| {"etime", |
| {{"values", TypePattern{RealType, KindCode::exactKind, 4}, Rank::vector, |
| Optionality::required, common::Intent::Out}, |
| {"time", TypePattern{RealType, KindCode::exactKind, 4}, |
| Rank::scalar, Optionality::required, common::Intent::Out}}, |
| {}, Rank::elemental, IntrinsicClass::impureSubroutine}, |
| {"execute_command_line", |
| {{"command", DefaultChar, Rank::scalar}, |
| {"wait", AnyLogical, Rank::scalar, Optionality::optional}, |
| {"exitstat", |
| TypePattern{IntType, KindCode::greaterOrEqualToKind, 4}, |
| Rank::scalar, Optionality::optional, common::Intent::InOut}, |
| {"cmdstat", TypePattern{IntType, KindCode::greaterOrEqualToKind, 2}, |
| Rank::scalar, Optionality::optional, common::Intent::Out}, |
| {"cmdmsg", DefaultChar, Rank::scalar, Optionality::optional, |
| common::Intent::InOut}}, |
| {}, Rank::elemental, IntrinsicClass::impureSubroutine}, |
| {"exit", {{"status", DefaultInt, Rank::scalar, Optionality::optional}}, {}, |
| Rank::elemental, IntrinsicClass::impureSubroutine}, |
| {"free", {{"ptr", Addressable}}, {}}, |
| {"get_command", |
| {{"command", DefaultChar, Rank::scalar, Optionality::optional, |
| common::Intent::Out}, |
| {"length", AnyInt, Rank::scalar, Optionality::optional, |
| common::Intent::Out}, |
| {"status", AnyInt, Rank::scalar, Optionality::optional, |
| common::Intent::Out}, |
| {"errmsg", DefaultChar, Rank::scalar, Optionality::optional, |
| common::Intent::InOut}}, |
| {}, Rank::elemental, IntrinsicClass::impureSubroutine}, |
| {"get_command_argument", |
| {{"number", AnyInt, Rank::scalar}, |
| {"value", DefaultChar, Rank::scalar, Optionality::optional, |
| common::Intent::Out}, |
| {"length", AnyInt, Rank::scalar, Optionality::optional, |
| common::Intent::Out}, |
| {"status", AnyInt, Rank::scalar, Optionality::optional, |
| common::Intent::Out}, |
| {"errmsg", DefaultChar, Rank::scalar, Optionality::optional, |
| common::Intent::InOut}}, |
| {}, Rank::elemental, IntrinsicClass::impureSubroutine}, |
| {"get_environment_variable", |
| {{"name", DefaultChar, Rank::scalar}, |
| {"value", DefaultChar, Rank::scalar, Optionality::optional, |
| common::Intent::Out}, |
| {"length", AnyInt, Rank::scalar, Optionality::optional, |
| common::Intent::Out}, |
| {"status", AnyInt, Rank::scalar, Optionality::optional, |
| common::Intent::Out}, |
| {"trim_name", AnyLogical, Rank::scalar, Optionality::optional}, |
| {"errmsg", DefaultChar, Rank::scalar, Optionality::optional, |
| common::Intent::InOut}}, |
| {}, Rank::elemental, IntrinsicClass::impureSubroutine}, |
| {"getcwd", |
| {{"c", DefaultChar, Rank::scalar, Optionality::required, |
| common::Intent::Out}, |
| {"status", TypePattern{IntType, KindCode::greaterOrEqualToKind, 4}, |
| Rank::scalar, Optionality::optional, common::Intent::Out}}, |
| {}, Rank::elemental, IntrinsicClass::impureSubroutine}, |
| {"move_alloc", |
| {{"from", SameType, Rank::known, Optionality::required, |
| common::Intent::InOut}, |
| {"to", SameType, Rank::known, Optionality::required, |
| common::Intent::Out}, |
| {"stat", AnyInt, Rank::scalar, Optionality::optional, |
| common::Intent::Out}, |
| {"errmsg", DefaultChar, Rank::scalar, Optionality::optional, |
| common::Intent::InOut}}, |
| {}, Rank::elemental, IntrinsicClass::pureSubroutine}, |
| {"mvbits", |
| {{"from", SameInt}, {"frompos", AnyInt}, {"len", AnyInt}, |
| {"to", SameInt, Rank::elemental, Optionality::required, |
| common::Intent::Out}, |
| {"topos", AnyInt}}, |
| {}, Rank::elemental, IntrinsicClass::elementalSubroutine}, // elemental |
| {"random_init", |
| {{"repeatable", AnyLogical, Rank::scalar}, |
| {"image_distinct", AnyLogical, Rank::scalar}}, |
| {}, Rank::elemental, IntrinsicClass::impureSubroutine}, |
| {"random_number", |
| {{"harvest", AnyReal, Rank::known, Optionality::required, |
| common::Intent::Out, {ArgFlag::notAssumedSize}}}, |
| {}, Rank::elemental, IntrinsicClass::impureSubroutine}, |
| {"random_seed", |
| {{"size", DefaultInt, Rank::scalar, Optionality::optional, |
| common::Intent::Out}, |
| {"put", DefaultInt, Rank::vector, Optionality::optional}, |
| {"get", DefaultInt, Rank::vector, Optionality::optional, |
| common::Intent::Out}}, |
| {}, Rank::elemental, IntrinsicClass::impureSubroutine}, |
| {"rename", |
| {{"path1", DefaultChar, Rank::scalar}, |
| {"path2", DefaultChar, Rank::scalar}, |
| {"status", DefaultInt, Rank::scalar, Optionality::optional, |
| common::Intent::Out}}, |
| {}, Rank::scalar, IntrinsicClass::impureSubroutine}, |
| {"second", {{"time", DefaultReal, Rank::scalar}}, {}, Rank::scalar, |
| IntrinsicClass::impureSubroutine}, |
| {"system", |
| {{"command", DefaultChar, Rank::scalar}, |
| {"exitstat", DefaultInt, Rank::scalar, Optionality::optional, |
| common::Intent::Out}}, |
| {}, Rank::elemental, IntrinsicClass::impureSubroutine}, |
| {"system_clock", |
| {{"count", AnyInt, Rank::scalar, Optionality::optional, |
| common::Intent::Out}, |
| {"count_rate", AnyIntOrReal, Rank::scalar, Optionality::optional, |
| common::Intent::Out}, |
| {"count_max", AnyInt, Rank::scalar, Optionality::optional, |
| common::Intent::Out}}, |
| {}, Rank::elemental, IntrinsicClass::impureSubroutine}, |
| {"signal", |
| {{"number", AnyInt, Rank::scalar, Optionality::required, |
| common::Intent::In}, |
| // note: any pointer also accepts AnyInt |
| {"handler", AnyPointer, Rank::scalar, Optionality::required, |
| common::Intent::In}, |
| {"status", AnyInt, Rank::scalar, Optionality::optional, |
| common::Intent::Out}}, |
| {}, Rank::elemental, IntrinsicClass::impureSubroutine}, |
| {"sleep", |
| {{"seconds", AnyInt, Rank::scalar, Optionality::required, |
| common::Intent::In}}, |
| {}, Rank::elemental, IntrinsicClass::impureSubroutine}, |
| }; |
| |
| // TODO: Intrinsic subroutine EVENT_QUERY |
| // TODO: Atomic intrinsic subroutines: ATOMIC_ADD |
| // TODO: Collective intrinsic subroutines: co_reduce |
| |
| // Finds a built-in derived type and returns it as a DynamicType. |
| static DynamicType GetBuiltinDerivedType( |
| const semantics::Scope *builtinsScope, const char *which) { |
| if (!builtinsScope) { |
| common::die("INTERNAL: The __fortran_builtins module was not found, and " |
| "the type '%s' was required", |
| which); |
| } |
| auto iter{ |
| builtinsScope->find(semantics::SourceName{which, std::strlen(which)})}; |
| if (iter == builtinsScope->cend()) { |
| // keep the string all together |
| // clang-format off |
| common::die( |
| "INTERNAL: The __fortran_builtins module does not define the type '%s'", |
| which); |
| // clang-format on |
| } |
| const semantics::Symbol &symbol{*iter->second}; |
| const semantics::Scope &scope{DEREF(symbol.scope())}; |
| const semantics::DerivedTypeSpec &derived{DEREF(scope.derivedTypeSpec())}; |
| return DynamicType{derived}; |
| } |
| |
| static std::int64_t GetBuiltinKind( |
| const semantics::Scope *builtinsScope, const char *which) { |
| if (!builtinsScope) { |
| common::die("INTERNAL: The __fortran_builtins module was not found, and " |
| "the kind '%s' was required", |
| which); |
| } |
| auto iter{ |
| builtinsScope->find(semantics::SourceName{which, std::strlen(which)})}; |
| if (iter == builtinsScope->cend()) { |
| common::die( |
| "INTERNAL: The __fortran_builtins module does not define the kind '%s'", |
| which); |
| } |
| const semantics::Symbol &symbol{*iter->second}; |
| const auto &details{ |
| DEREF(symbol.detailsIf<semantics::ObjectEntityDetails>())}; |
| if (const auto kind{ToInt64(details.init())}) { |
| return *kind; |
| } else { |
| common::die( |
| "INTERNAL: The __fortran_builtins module does not define the kind '%s'", |
| which); |
| return -1; |
| } |
| } |
| |
| // Ensure that the keywords of arguments to MAX/MIN and their variants |
| // are of the form A123 with no duplicates or leading zeroes. |
| static bool CheckMaxMinArgument(parser::CharBlock keyword, |
| std::set<parser::CharBlock> &set, const char *intrinsicName, |
| parser::ContextualMessages &messages) { |
| std::size_t j{1}; |
| for (; j < keyword.size(); ++j) { |
| char ch{(keyword)[j]}; |
| if (ch < (j == 1 ? '1' : '0') || ch > '9') { |
| break; |
| } |
| } |
| if (keyword.size() < 2 || (keyword)[0] != 'a' || j < keyword.size()) { |
| messages.Say(keyword, |
| "argument keyword '%s=' is not known in call to '%s'"_err_en_US, |
| keyword, intrinsicName); |
| return false; |
| } |
| if (!set.insert(keyword).second) { |
| messages.Say(keyword, |
| "argument keyword '%s=' was repeated in call to '%s'"_err_en_US, |
| keyword, intrinsicName); |
| return false; |
| } |
| return true; |
| } |
| |
| // Validate the keyword, if any, and ensure that A1 and A2 are always placed in |
| // first and second position in actualForDummy. A1 and A2 are special since they |
| // are not optional. The rest of the arguments are not sorted, there are no |
| // differences between them. |
| static bool CheckAndPushMinMaxArgument(ActualArgument &arg, |
| std::vector<ActualArgument *> &actualForDummy, |
| std::set<parser::CharBlock> &set, const char *intrinsicName, |
| parser::ContextualMessages &messages) { |
| if (std::optional<parser::CharBlock> keyword{arg.keyword()}) { |
| if (!CheckMaxMinArgument(*keyword, set, intrinsicName, messages)) { |
| return false; |
| } |
| const bool isA1{*keyword == parser::CharBlock{"a1", 2}}; |
| if (isA1 && !actualForDummy[0]) { |
| actualForDummy[0] = &arg; |
| return true; |
| } |
| const bool isA2{*keyword == parser::CharBlock{"a2", 2}}; |
| if (isA2 && !actualForDummy[1]) { |
| actualForDummy[1] = &arg; |
| return true; |
| } |
| if (isA1 || isA2) { |
| // Note that for arguments other than a1 and a2, this error will be caught |
| // later in check-call.cpp. |
| messages.Say(*keyword, |
| "keyword argument '%s=' to intrinsic '%s' was supplied " |
| "positionally by an earlier actual argument"_err_en_US, |
| *keyword, intrinsicName); |
| return false; |
| } |
| } else { |
| if (actualForDummy.size() == 2) { |
| if (!actualForDummy[0] && !actualForDummy[1]) { |
| actualForDummy[0] = &arg; |
| return true; |
| } else if (!actualForDummy[1]) { |
| actualForDummy[1] = &arg; |
| return true; |
| } |
| } |
| } |
| actualForDummy.push_back(&arg); |
| return true; |
| } |
| |
| static bool CheckAtomicKind(const ActualArgument &arg, |
| const semantics::Scope *builtinsScope, |
| parser::ContextualMessages &messages) { |
| std::string atomicKindStr; |
| std::optional<DynamicType> type{arg.GetType()}; |
| |
| if (type->category() == TypeCategory::Integer) { |
| atomicKindStr = "atomic_int_kind"; |
| } else if (type->category() == TypeCategory::Logical) { |
| atomicKindStr = "atomic_logical_kind"; |
| } else { |
| common::die("atomic_int_kind or atomic_logical_kind from iso_fortran_env " |
| "must be used with IntType or LogicalType"); |
| } |
| |
| bool argOk = type->kind() == |
| GetBuiltinKind(builtinsScope, ("__builtin_" + atomicKindStr).c_str()); |
| if (!argOk) { |
| messages.Say(arg.sourceLocation(), |
| "Actual argument for 'atom=' must have kind=atomic_int_kind or atomic_logical_kind, but is '%s'"_err_en_US, |
| type->AsFortran()); |
| } |
| return argOk; |
| } |
| |
| // Intrinsic interface matching against the arguments of a particular |
| // procedure reference. |
| std::optional<SpecificCall> IntrinsicInterface::Match( |
| const CallCharacteristics &call, |
| const common::IntrinsicTypeDefaultKinds &defaults, |
| ActualArguments &arguments, FoldingContext &context, |
| const semantics::Scope *builtinsScope) const { |
| auto &messages{context.messages()}; |
| // Attempt to construct a 1-1 correspondence between the dummy arguments in |
| // a particular intrinsic procedure's generic interface and the actual |
| // arguments in a procedure reference. |
| std::size_t dummyArgPatterns{0}; |
| for (; dummyArgPatterns < maxArguments && dummy[dummyArgPatterns].keyword; |
| ++dummyArgPatterns) { |
| } |
| // MAX and MIN (and others that map to them) allow their last argument to |
| // be repeated indefinitely. The actualForDummy vector is sized |
| // and null-initialized to the non-repeated dummy argument count |
| // for other intrinsics. |
| bool isMaxMin{dummyArgPatterns > 0 && |
| dummy[dummyArgPatterns - 1].optionality == Optionality::repeats}; |
| std::vector<ActualArgument *> actualForDummy( |
| isMaxMin ? 2 : dummyArgPatterns, nullptr); |
| bool anyMissingActualArgument{false}; |
| std::set<parser::CharBlock> maxMinKeywords; |
| bool anyKeyword{false}; |
| int which{0}; |
| for (std::optional<ActualArgument> &arg : arguments) { |
| ++which; |
| if (arg) { |
| if (arg->isAlternateReturn()) { |
| messages.Say(arg->sourceLocation(), |
| "alternate return specifier not acceptable on call to intrinsic '%s'"_err_en_US, |
| name); |
| return std::nullopt; |
| } |
| if (arg->keyword()) { |
| anyKeyword = true; |
| } else if (anyKeyword) { |
| messages.Say(arg ? arg->sourceLocation() : std::nullopt, |
| "actual argument #%d without a keyword may not follow an actual argument with a keyword"_err_en_US, |
| which); |
| return std::nullopt; |
| } |
| } else { |
| anyMissingActualArgument = true; |
| continue; |
| } |
| if (isMaxMin) { |
| if (!CheckAndPushMinMaxArgument( |
| *arg, actualForDummy, maxMinKeywords, name, messages)) { |
| return std::nullopt; |
| } |
| } else { |
| bool found{false}; |
| for (std::size_t j{0}; j < dummyArgPatterns && !found; ++j) { |
| if (dummy[j].optionality == Optionality::missing) { |
| continue; |
| } |
| if (arg->keyword()) { |
| found = *arg->keyword() == dummy[j].keyword; |
| if (found) { |
| if (const auto *previous{actualForDummy[j]}) { |
| if (previous->keyword()) { |
| messages.Say(*arg->keyword(), |
| "repeated keyword argument to intrinsic '%s'"_err_en_US, |
| name); |
| } else { |
| messages.Say(*arg->keyword(), |
| "keyword argument to intrinsic '%s' was supplied " |
| "positionally by an earlier actual argument"_err_en_US, |
| name); |
| } |
| return std::nullopt; |
| } |
| } |
| } else { |
| found = !actualForDummy[j] && !anyMissingActualArgument; |
| } |
| if (found) { |
| actualForDummy[j] = &*arg; |
| } |
| } |
| if (!found) { |
| if (arg->keyword()) { |
| messages.Say(*arg->keyword(), |
| "unknown keyword argument to intrinsic '%s'"_err_en_US, name); |
| } else { |
| messages.Say( |
| "too many actual arguments for intrinsic '%s'"_err_en_US, name); |
| } |
| return std::nullopt; |
| } |
| } |
| } |
| |
| std::size_t dummies{actualForDummy.size()}; |
| |
| // Check types and kinds of the actual arguments against the intrinsic's |
| // interface. Ensure that two or more arguments that have to have the same |
| // (or compatible) type and kind do so. Check for missing non-optional |
| // arguments now, too. |
| const ActualArgument *sameArg{nullptr}; |
| const ActualArgument *operandArg{nullptr}; |
| const IntrinsicDummyArgument *kindDummyArg{nullptr}; |
| const ActualArgument *kindArg{nullptr}; |
| std::optional<int> dimArg; |
| for (std::size_t j{0}; j < dummies; ++j) { |
| const IntrinsicDummyArgument &d{dummy[std::min(j, dummyArgPatterns - 1)]}; |
| if (d.typePattern.kindCode == KindCode::kindArg) { |
| CHECK(!kindDummyArg); |
| kindDummyArg = &d; |
| } |
| const ActualArgument *arg{actualForDummy[j]}; |
| if (!arg) { |
| if (d.optionality == Optionality::required) { |
| std::string kw{d.keyword}; |
| if (isMaxMin && !actualForDummy[0] && !actualForDummy[1]) { |
| messages.Say("missing mandatory 'a1=' and 'a2=' arguments"_err_en_US); |
| } else { |
| messages.Say( |
| "missing mandatory '%s=' argument"_err_en_US, kw.c_str()); |
| } |
| return std::nullopt; // missing non-OPTIONAL argument |
| } else { |
| continue; |
| } |
| } |
| if (d.optionality == Optionality::missing) { |
| messages.Say(arg->sourceLocation(), "unexpected '%s=' argument"_err_en_US, |
| d.keyword); |
| return std::nullopt; |
| } |
| if (!d.flags.test(ArgFlag::canBeNull)) { |
| if (const auto *expr{arg->UnwrapExpr()}; expr && IsNullPointer(*expr)) { |
| if (!IsBareNullPointer(expr) && IsNullObjectPointer(*expr) && |
| d.flags.test(ArgFlag::canBeMoldNull)) { |
| // ok |
| } else { |
| messages.Say(arg->sourceLocation(), |
| "A NULL() pointer is not allowed for '%s=' intrinsic argument"_err_en_US, |
| d.keyword); |
| return std::nullopt; |
| } |
| } |
| } |
| if (d.flags.test(ArgFlag::notAssumedSize)) { |
| if (auto named{ExtractNamedEntity(*arg)}) { |
| if (semantics::IsAssumedSizeArray(named->GetLastSymbol())) { |
| messages.Say(arg->sourceLocation(), |
| "The '%s=' argument to the intrinsic procedure '%s' may not be assumed-size"_err_en_US, |
| d.keyword, name); |
| return std::nullopt; |
| } |
| } |
| } |
| if (arg->GetAssumedTypeDummy()) { |
| // TYPE(*) assumed-type dummy argument forwarded to intrinsic |
| if (d.typePattern.categorySet == AnyType && |
| (d.rank == Rank::anyOrAssumedRank || |
| d.rank == Rank::arrayOrAssumedRank) && |
| (d.typePattern.kindCode == KindCode::any || |
| d.typePattern.kindCode == KindCode::addressable)) { |
| continue; |
| } else { |
| messages.Say(arg->sourceLocation(), |
| "Assumed type TYPE(*) dummy argument not allowed for '%s=' intrinsic argument"_err_en_US, |
| d.keyword); |
| return std::nullopt; |
| } |
| } |
| std::optional<DynamicType> type{arg->GetType()}; |
| if (!type) { |
| CHECK(arg->Rank() == 0); |
| const Expr<SomeType> &expr{DEREF(arg->UnwrapExpr())}; |
| if (IsBOZLiteral(expr)) { |
| if (d.typePattern.kindCode == KindCode::typeless || |
| d.rank == Rank::elementalOrBOZ) { |
| continue; |
| } else { |
| const IntrinsicDummyArgument *nextParam{ |
| j + 1 < dummies ? &dummy[j + 1] : nullptr}; |
| if (nextParam && nextParam->rank == Rank::elementalOrBOZ) { |
| messages.Say(arg->sourceLocation(), |
| "Typeless (BOZ) not allowed for both '%s=' & '%s=' arguments"_err_en_US, // C7109 |
| d.keyword, nextParam->keyword); |
| } else { |
| messages.Say(arg->sourceLocation(), |
| "Typeless (BOZ) not allowed for '%s=' argument"_err_en_US, |
| d.keyword); |
| } |
| } |
| } else { |
| // NULL(no MOLD=), procedure, or procedure pointer |
| CHECK(IsProcedurePointerTarget(expr)); |
| if (d.typePattern.kindCode == KindCode::addressable || |
| d.rank == Rank::reduceOperation) { |
| continue; |
| } else if (d.typePattern.kindCode == KindCode::nullPointerType) { |
| continue; |
| } else if (IsBareNullPointer(&expr)) { |
| // checked elsewhere |
| continue; |
| } else { |
| CHECK(IsProcedure(expr) || IsProcedurePointer(expr)); |
| messages.Say(arg->sourceLocation(), |
| "Actual argument for '%s=' may not be a procedure"_err_en_US, |
| d.keyword); |
| } |
| } |
| return std::nullopt; |
| } else if (!d.typePattern.categorySet.test(type->category())) { |
| messages.Say(arg->sourceLocation(), |
| "Actual argument for '%s=' has bad type '%s'"_err_en_US, d.keyword, |
| type->AsFortran()); |
| return std::nullopt; // argument has invalid type category |
| } |
| bool argOk{false}; |
| switch (d.typePattern.kindCode) { |
| case KindCode::none: |
| case KindCode::typeless: |
| argOk = false; |
| break; |
| case KindCode::ieeeFlagType: |
| argOk = !type->IsUnlimitedPolymorphic() && |
| type->category() == TypeCategory::Derived && |
| semantics::IsIeeeFlagType(&type->GetDerivedTypeSpec()); |
| break; |
| case KindCode::ieeeRoundType: |
| argOk = !type->IsUnlimitedPolymorphic() && |
| type->category() == TypeCategory::Derived && |
| semantics::IsIeeeRoundType(&type->GetDerivedTypeSpec()); |
| break; |
| case KindCode::teamType: |
| argOk = !type->IsUnlimitedPolymorphic() && |
| type->category() == TypeCategory::Derived && |
| semantics::IsTeamType(&type->GetDerivedTypeSpec()); |
| break; |
| case KindCode::defaultIntegerKind: |
| argOk = type->kind() == defaults.GetDefaultKind(TypeCategory::Integer); |
| break; |
| case KindCode::defaultRealKind: |
| argOk = type->kind() == defaults.GetDefaultKind(TypeCategory::Real); |
| break; |
| case KindCode::doublePrecision: |
| argOk = type->kind() == defaults.doublePrecisionKind(); |
| break; |
| case KindCode::defaultCharKind: |
| argOk = type->kind() == defaults.GetDefaultKind(TypeCategory::Character); |
| break; |
| case KindCode::defaultLogicalKind: |
| argOk = type->kind() == defaults.GetDefaultKind(TypeCategory::Logical); |
| break; |
| case KindCode::any: |
| argOk = true; |
| break; |
| case KindCode::kindArg: |
| CHECK(type->category() == TypeCategory::Integer); |
| CHECK(!kindArg); |
| kindArg = arg; |
| argOk = true; |
| break; |
| case KindCode::dimArg: |
| CHECK(type->category() == TypeCategory::Integer); |
| dimArg = j; |
| argOk = true; |
| break; |
| case KindCode::same: { |
| if (!sameArg) { |
| sameArg = arg; |
| } |
| // Check both ways so that a CLASS(*) actuals to |
| // MOVE_ALLOC and EOSHIFT both work. |
| auto sameType{sameArg->GetType().value()}; |
| argOk = sameType.IsTkLenCompatibleWith(*type) || |
| type->IsTkLenCompatibleWith(sameType); |
| } break; |
| case KindCode::sameKind: |
| if (!sameArg) { |
| sameArg = arg; |
| } |
| argOk = type->IsTkCompatibleWith(sameArg->GetType().value()); |
| break; |
| case KindCode::operand: |
| if (!operandArg) { |
| operandArg = arg; |
| } else if (auto prev{operandArg->GetType()}) { |
| if (type->category() == prev->category()) { |
| if (type->kind() > prev->kind()) { |
| operandArg = arg; |
| } |
| } else if (prev->category() == TypeCategory::Integer) { |
| operandArg = arg; |
| } |
| } |
| argOk = true; |
| break; |
| case KindCode::effectiveKind: |
| common::die("INTERNAL: KindCode::effectiveKind appears on argument '%s' " |
| "for intrinsic '%s'", |
| d.keyword, name); |
| break; |
| case KindCode::addressable: |
| case KindCode::nullPointerType: |
| argOk = true; |
| break; |
| case KindCode::exactKind: |
| argOk = type->kind() == d.typePattern.kindValue; |
| break; |
| case KindCode::greaterOrEqualToKind: |
| argOk = type->kind() >= d.typePattern.kindValue; |
| break; |
| case KindCode::sameAtom: |
| if (!sameArg) { |
| sameArg = arg; |
| argOk = CheckAtomicKind(DEREF(arg), builtinsScope, messages); |
| } else { |
| argOk = type->IsTkCompatibleWith(sameArg->GetType().value()); |
| if (!argOk) { |
| messages.Say(arg->sourceLocation(), |
| "Actual argument for '%s=' must have same type and kind as 'atom=', but is '%s'"_err_en_US, |
| d.keyword, type->AsFortran()); |
| } |
| } |
| if (!argOk) |
| return std::nullopt; |
| break; |
| case KindCode::atomicIntKind: |
| argOk = type->kind() == |
| GetBuiltinKind(builtinsScope, "__builtin_atomic_int_kind"); |
| if (!argOk) { |
| messages.Say(arg->sourceLocation(), |
| "Actual argument for '%s=' must have kind=atomic_int_kind, but is '%s'"_err_en_US, |
| d.keyword, type->AsFortran()); |
| return std::nullopt; |
| } |
| break; |
| case KindCode::atomicIntOrLogicalKind: |
| argOk = CheckAtomicKind(DEREF(arg), builtinsScope, messages); |
| if (!argOk) |
| return std::nullopt; |
| break; |
| default: |
| CRASH_NO_CASE; |
| } |
| if (!argOk) { |
| messages.Say(arg->sourceLocation(), |
| "Actual argument for '%s=' has bad type or kind '%s'"_err_en_US, |
| d.keyword, type->AsFortran()); |
| return std::nullopt; |
| } |
| } |
| |
| // Check the ranks of the arguments against the intrinsic's interface. |
| const ActualArgument *arrayArg{nullptr}; |
| const char *arrayArgName{nullptr}; |
| const ActualArgument *knownArg{nullptr}; |
| std::optional<int> shapeArgSize; |
| int elementalRank{0}; |
| for (std::size_t j{0}; j < dummies; ++j) { |
| const IntrinsicDummyArgument &d{dummy[std::min(j, dummyArgPatterns - 1)]}; |
| if (const ActualArgument *arg{actualForDummy[j]}) { |
| bool isAssumedRank{IsAssumedRank(*arg)}; |
| if (isAssumedRank && d.rank != Rank::anyOrAssumedRank && |
| d.rank != Rank::arrayOrAssumedRank) { |
| messages.Say(arg->sourceLocation(), |
| "Assumed-rank array cannot be forwarded to '%s=' argument"_err_en_US, |
| d.keyword); |
| return std::nullopt; |
| } |
| int rank{arg->Rank()}; |
| bool argOk{false}; |
| switch (d.rank) { |
| case Rank::elemental: |
| case Rank::elementalOrBOZ: |
| if (elementalRank == 0) { |
| elementalRank = rank; |
| } |
| argOk = rank == 0 || rank == elementalRank; |
| break; |
| case Rank::scalar: |
| argOk = rank == 0; |
| break; |
| case Rank::vector: |
| argOk = rank == 1; |
| break; |
| case Rank::shape: |
| CHECK(!shapeArgSize); |
| if (rank != 1) { |
| messages.Say(arg->sourceLocation(), |
| "'shape=' argument must be an array of rank 1"_err_en_US); |
| return std::nullopt; |
| } else { |
| if (auto shape{GetShape(context, *arg)}) { |
| if (auto constShape{AsConstantShape(context, *shape)}) { |
| shapeArgSize = constShape->At(ConstantSubscripts{1}).ToInt64(); |
| CHECK(*shapeArgSize >= 0); |
| argOk = true; |
| } |
| } |
| } |
| if (!argOk) { |
| messages.Say(arg->sourceLocation(), |
| "'shape=' argument must be a vector of known size"_err_en_US); |
| return std::nullopt; |
| } |
| break; |
| case Rank::matrix: |
| argOk = rank == 2; |
| break; |
| case Rank::array: |
| argOk = rank > 0; |
| if (!arrayArg) { |
| arrayArg = arg; |
| arrayArgName = d.keyword; |
| } |
| break; |
| case Rank::coarray: |
| argOk = IsCoarray(*arg); |
| if (!argOk) { |
| messages.Say(arg->sourceLocation(), |
| "'coarray=' argument must have corank > 0 for intrinsic '%s'"_err_en_US, |
| name); |
| return std::nullopt; |
| } |
| break; |
| case Rank::atom: |
| argOk = rank == 0 && (IsCoarray(*arg) || ExtractCoarrayRef(*arg)); |
| if (!argOk) { |
| messages.Say(arg->sourceLocation(), |
| "'%s=' argument must be a scalar coarray or coindexed object for intrinsic '%s'"_err_en_US, |
| d.keyword, name); |
| return std::nullopt; |
| } |
| break; |
| case Rank::known: |
| if (!knownArg) { |
| knownArg = arg; |
| } |
| argOk = !isAssumedRank && rank == knownArg->Rank(); |
| break; |
| case Rank::anyOrAssumedRank: |
| case Rank::arrayOrAssumedRank: |
| if (isAssumedRank) { |
| argOk = true; |
| break; |
| } |
| if (d.rank == Rank::arrayOrAssumedRank && rank == 0) { |
| argOk = false; |
| break; |
| } |
| if (!knownArg) { |
| knownArg = arg; |
| } |
| if (!dimArg && rank > 0 && |
| (std::strcmp(name, "shape") == 0 || |
| std::strcmp(name, "size") == 0 || |
| std::strcmp(name, "ubound") == 0)) { |
| // Check for a whole assumed-size array argument. |
| // These are disallowed for SHAPE, and require DIM= for |
| // SIZE and UBOUND. |
| // (A previous error message for UBOUND will take precedence |
| // over this one, as this error is caught by the second entry |
| // for UBOUND.) |
| if (auto named{ExtractNamedEntity(*arg)}) { |
| if (semantics::IsAssumedSizeArray(named->GetLastSymbol())) { |
| if (strcmp(name, "shape") == 0) { |
| messages.Say(arg->sourceLocation(), |
| "The 'source=' argument to the intrinsic function 'shape' may not be assumed-size"_err_en_US); |
| } else { |
| messages.Say(arg->sourceLocation(), |
| "A dim= argument is required for '%s' when the array is assumed-size"_err_en_US, |
| name); |
| } |
| return std::nullopt; |
| } |
| } |
| } |
| argOk = true; |
| break; |
| case Rank::conformable: // arg must be conformable with previous arrayArg |
| CHECK(arrayArg); |
| CHECK(arrayArgName); |
| if (const std::optional<Shape> &arrayArgShape{ |
| GetShape(context, *arrayArg)}) { |
| if (std::optional<Shape> argShape{GetShape(context, *arg)}) { |
| std::string arrayArgMsg{"'"}; |
| arrayArgMsg = arrayArgMsg + arrayArgName + "='" + " argument"; |
| std::string argMsg{"'"}; |
| argMsg = argMsg + d.keyword + "='" + " argument"; |
| CheckConformance(context.messages(), *arrayArgShape, *argShape, |
| CheckConformanceFlags::RightScalarExpandable, |
| arrayArgMsg.c_str(), argMsg.c_str()); |
| } |
| } |
| argOk = true; // Avoid an additional error message |
| break; |
| case Rank::dimReduced: |
| case Rank::dimRemovedOrScalar: |
| CHECK(arrayArg); |
| argOk = rank == 0 || rank + 1 == arrayArg->Rank(); |
| break; |
| case Rank::reduceOperation: |
| // The reduction function is validated in ApplySpecificChecks(). |
| argOk = true; |
| break; |
| case Rank::scalarIfDim: |
| case Rank::locReduced: |
| case Rank::rankPlus1: |
| case Rank::shaped: |
| common::die("INTERNAL: result-only rank code appears on argument '%s' " |
| "for intrinsic '%s'", |
| d.keyword, name); |
| } |
| if (!argOk) { |
| messages.Say(arg->sourceLocation(), |
| "'%s=' argument has unacceptable rank %d"_err_en_US, d.keyword, |
| rank); |
| return std::nullopt; |
| } |
| } |
| } |
| |
| // Calculate the characteristics of the function result, if any |
| std::optional<DynamicType> resultType; |
| if (auto category{result.categorySet.LeastElement()}) { |
| // The intrinsic is not a subroutine. |
| if (call.isSubroutineCall) { |
| return std::nullopt; |
| } |
| switch (result.kindCode) { |
| case KindCode::defaultIntegerKind: |
| CHECK(result.categorySet == IntType); |
| CHECK(*category == TypeCategory::Integer); |
| resultType = DynamicType{TypeCategory::Integer, |
| defaults.GetDefaultKind(TypeCategory::Integer)}; |
| break; |
| case KindCode::defaultRealKind: |
| CHECK(result.categorySet == CategorySet{*category}); |
| CHECK(FloatingType.test(*category)); |
| resultType = |
| DynamicType{*category, defaults.GetDefaultKind(TypeCategory::Real)}; |
| break; |
| case KindCode::doublePrecision: |
| CHECK(result.categorySet == CategorySet{*category}); |
| CHECK(FloatingType.test(*category)); |
| resultType = DynamicType{*category, defaults.doublePrecisionKind()}; |
| break; |
| case KindCode::defaultLogicalKind: |
| CHECK(result.categorySet == LogicalType); |
| CHECK(*category == TypeCategory::Logical); |
| resultType = DynamicType{TypeCategory::Logical, |
| defaults.GetDefaultKind(TypeCategory::Logical)}; |
| break; |
| case KindCode::defaultCharKind: |
| CHECK(result.categorySet == CharType); |
| CHECK(*category == TypeCategory::Character); |
| resultType = DynamicType{TypeCategory::Character, |
| defaults.GetDefaultKind(TypeCategory::Character)}; |
| break; |
| case KindCode::same: |
| CHECK(sameArg); |
| if (std::optional<DynamicType> |