blob: a1b1628083b73f1b269bdd1bc7d6ae09066584ca [file] [log] [blame]
peter klauslerf9d6c0a2019-01-18 20:40:471// Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved.
peter klauslerf24cd7d2018-07-11 21:50:082//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef FORTRAN_EVALUATE_INTRINSICS_H_
16#define FORTRAN_EVALUATE_INTRINSICS_H_
17
peter klauslera62636f2018-10-08 22:35:1918#include "call.h"
peter klauslerba56b912019-02-22 23:45:3019#include "type.h"
peter klauslerf9d6c0a2019-01-18 20:40:4720#include "../common/default-kinds.h"
peter klauslerd804c9d2018-10-18 20:03:5121#include "../parser/char-block.h"
peter klauslercb308d32018-10-05 18:32:5422#include "../parser/message.h"
peter klauslera70f5962018-10-04 20:43:3323#include <optional>
peter klauslerad9aede2018-10-11 21:51:1424#include <ostream>
peter klausler42b33da2018-09-29 00:02:1125
peter klauslerf24cd7d2018-07-11 21:50:0826namespace Fortran::evaluate {
27
peter klausler42b33da2018-09-29 00:02:1128struct CallCharacteristics {
peter klausler42b33da2018-09-29 00:02:1129 parser::CharBlock name;
peter klauslera62636f2018-10-08 22:35:1930 bool isSubroutineCall{false};
peter klausler42b33da2018-09-29 00:02:1131};
32
peter klausleref9dd9d2018-10-17 22:09:4833struct SpecificCall {
34 SpecificCall(SpecificIntrinsic &&si, ActualArguments &&as)
35 : specificIntrinsic{std::move(si)}, arguments{std::move(as)} {}
36 SpecificIntrinsic specificIntrinsic;
37 ActualArguments arguments;
peter klausler42b33da2018-09-29 00:02:1138};
39
peter klauslerba56b912019-02-22 23:45:3040struct UnrestrictedSpecificIntrinsicFunctionInterface {
41 std::string genericName;
42 int numArguments; // 1 or 2
43 // These are the types of the argument(s) and the function result.
44 // If there are multiple arguments, they all have the same type.
45 // All are intrinsic types with default kinds.
46 DynamicType argumentType, resultType;
47};
48
peter klauslera62636f2018-10-08 22:35:1949class IntrinsicProcTable {
peter klausler42b33da2018-09-29 00:02:1150private:
peter klauslerba56b912019-02-22 23:45:3051 class Implementation;
peter klausler42b33da2018-09-29 00:02:1152
53public:
peter klauslera62636f2018-10-08 22:35:1954 ~IntrinsicProcTable();
peter klauslerbf339f82018-10-15 22:28:4755 static IntrinsicProcTable Configure(
peter klauslerf9d6c0a2019-01-18 20:40:4756 const common::IntrinsicTypeDefaultKinds &);
peter klausleref9dd9d2018-10-17 22:09:4857
58 // Probe the intrinsics for a match against a specific call.
59 // On success, the actual arguments are transferred to the result
60 // in dummy argument order.
61 std::optional<SpecificCall> Probe(const CallCharacteristics &,
62 ActualArguments &, parser::ContextualMessages *messages = nullptr) const;
peter klauslerba56b912019-02-22 23:45:3063
64 // Probe the intrinsics with the name of a potential unrestricted specific
65 // intrinsic.
66 std::optional<UnrestrictedSpecificIntrinsicFunctionInterface>
67 IsUnrestrictedSpecificIntrinsicFunction(const std::string &) const;
68
peter klausler7bda1b32018-10-12 23:01:5569 std::ostream &Dump(std::ostream &) const;
peter klausler42b33da2018-09-29 00:02:1170
71private:
peter klausler75a32092018-10-05 16:57:5372 Implementation *impl_{nullptr}; // owning pointer
peter klausler42b33da2018-09-29 00:02:1173};
Jean Perierf7e7cb32018-10-25 12:55:2374}
peter klauslerf24cd7d2018-07-11 21:50:0875#endif // FORTRAN_EVALUATE_INTRINSICS_H_