FLANG

intrinsics.h
1 //===-- include/flang/Evaluate/intrinsics.h ---------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef FORTRAN_EVALUATE_INTRINSICS_H_
10 #define FORTRAN_EVALUATE_INTRINSICS_H_
11
12 #include "call.h"
13 #include "characteristics.h"
14 #include "type.h"
15 #include "flang/Common/default-kinds.h"
16 #include "flang/Parser/char-block.h"
17 #include "flang/Parser/message.h"
18 #include <optional>
19 #include <string>
20
21 namespace llvm {
22 class raw_ostream;
23 }
24
25 namespace Fortran::evaluate {
26
27 class FoldingContext;
28
29 // Utility for checking for missing, excess, and duplicated arguments,
30 // and rearranging the actual arguments into dummy argument order.
31 bool CheckAndRearrangeArguments(ActualArguments &, parser::ContextualMessages &,
32 const char *const dummyKeywords[] /* null terminated */,
33 std::size_t trailingOptionals = 0);
34
35 struct CallCharacteristics {
36 std::string name;
37 bool isSubroutineCall{false};
38 };
39
40 struct SpecificCall {
41 SpecificCall(SpecificIntrinsic &&si, ActualArguments &&as)
42 : specificIntrinsic{std::move(si)}, arguments{std::move(as)} {}
43 SpecificIntrinsic specificIntrinsic;
44 ActualArguments arguments;
45 };
46
47 struct SpecificIntrinsicFunctionInterface : public characteristics::Procedure {
48 SpecificIntrinsicFunctionInterface(
49 characteristics::Procedure &&p, std::string n, bool isRestrictedSpecific)
50 : characteristics::Procedure{std::move(p)}, genericName{n},
51 isRestrictedSpecific{isRestrictedSpecific} {}
52 std::string genericName;
53 bool isRestrictedSpecific;
54 // N.B. If there are multiple arguments, they all have the same type.
55 // All argument and result types are intrinsic types with default kinds.
56 };
57
58 // Generic intrinsic classes from table 16.1
59 ENUM_CLASS(IntrinsicClass, atomicSubroutine, collectiveSubroutine,
60 elementalFunction, elementalSubroutine, inquiryFunction, pureSubroutine,
61 impureSubroutine, transformationalFunction, noClass)
62
63 class IntrinsicProcTable {
64 private:
65 class Implementation;
66
67 public:
68 ~IntrinsicProcTable();
69 static IntrinsicProcTable Configure(
70 const common::IntrinsicTypeDefaultKinds &);
71
72 // Check whether a name should be allowed to appear on an INTRINSIC
73 // statement.
74 bool IsIntrinsic(const std::string &) const;
75
76 // Inquiry intrinsics are defined in section 16.7, table 16.1
77 IntrinsicClass GetIntrinsicClass(const std::string &) const;
78
79 // Probe the intrinsics for a match against a specific call.
80 // On success, the actual arguments are transferred to the result
81 // in dummy argument order; on failure, the actual arguments remain
82 // untouched.
83 std::optional<SpecificCall> Probe(
84 const CallCharacteristics &, ActualArguments &, FoldingContext &) const;
85
86 // Probe the intrinsics with the name of a potential specific intrinsic.
87 std::optional<SpecificIntrinsicFunctionInterface> IsSpecificIntrinsicFunction(
88 const std::string &) const;
89
90 llvm::raw_ostream &Dump(llvm::raw_ostream &) const;
91
92 private:
93 Implementation *impl_{nullptr}; // owning pointer
94 };
95 } // namespace Fortran::evaluate
96 #endif // FORTRAN_EVALUATE_INTRINSICS_H_
Fortran::evaluate::characteristics::Procedure
Definition: characteristics.h:260
Fortran::evaluate::SpecificIntrinsic
Definition: call.h:147
Fortran::common::IntrinsicTypeDefaultKinds
Definition: default-kinds.h:26
Fortran::evaluate::FoldingContext
Definition: common.h:209
Fortran::evaluate::SpecificCall
Definition: intrinsics.h:40
Fortran::evaluate::CallCharacteristics
Definition: intrinsics.h:35
Fortran::evaluate::SpecificIntrinsicFunctionInterface
Definition: intrinsics.h:47