peter klausler | f9d6c0a | 2019-01-18 20:40:47 | [diff] [blame] | 1 | // Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved. |
peter klausler | f24cd7d | 2018-07-11 21:50:08 | [diff] [blame] | 2 | // |
| 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 klausler | a62636f | 2018-10-08 22:35:19 | [diff] [blame] | 18 | #include "call.h" |
peter klausler | ba56b91 | 2019-02-22 23:45:30 | [diff] [blame^] | 19 | #include "type.h" |
peter klausler | f9d6c0a | 2019-01-18 20:40:47 | [diff] [blame] | 20 | #include "../common/default-kinds.h" |
peter klausler | d804c9d | 2018-10-18 20:03:51 | [diff] [blame] | 21 | #include "../parser/char-block.h" |
peter klausler | cb308d3 | 2018-10-05 18:32:54 | [diff] [blame] | 22 | #include "../parser/message.h" |
peter klausler | a70f596 | 2018-10-04 20:43:33 | [diff] [blame] | 23 | #include <optional> |
peter klausler | ad9aede | 2018-10-11 21:51:14 | [diff] [blame] | 24 | #include <ostream> |
peter klausler | 42b33da | 2018-09-29 00:02:11 | [diff] [blame] | 25 | |
peter klausler | f24cd7d | 2018-07-11 21:50:08 | [diff] [blame] | 26 | namespace Fortran::evaluate { |
| 27 | |
peter klausler | 42b33da | 2018-09-29 00:02:11 | [diff] [blame] | 28 | struct CallCharacteristics { |
peter klausler | 42b33da | 2018-09-29 00:02:11 | [diff] [blame] | 29 | parser::CharBlock name; |
peter klausler | a62636f | 2018-10-08 22:35:19 | [diff] [blame] | 30 | bool isSubroutineCall{false}; |
peter klausler | 42b33da | 2018-09-29 00:02:11 | [diff] [blame] | 31 | }; |
| 32 | |
peter klausler | ef9dd9d | 2018-10-17 22:09:48 | [diff] [blame] | 33 | struct SpecificCall { |
| 34 | SpecificCall(SpecificIntrinsic &&si, ActualArguments &&as) |
| 35 | : specificIntrinsic{std::move(si)}, arguments{std::move(as)} {} |
| 36 | SpecificIntrinsic specificIntrinsic; |
| 37 | ActualArguments arguments; |
peter klausler | 42b33da | 2018-09-29 00:02:11 | [diff] [blame] | 38 | }; |
| 39 | |
peter klausler | ba56b91 | 2019-02-22 23:45:30 | [diff] [blame^] | 40 | struct 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 klausler | a62636f | 2018-10-08 22:35:19 | [diff] [blame] | 49 | class IntrinsicProcTable { |
peter klausler | 42b33da | 2018-09-29 00:02:11 | [diff] [blame] | 50 | private: |
peter klausler | ba56b91 | 2019-02-22 23:45:30 | [diff] [blame^] | 51 | class Implementation; |
peter klausler | 42b33da | 2018-09-29 00:02:11 | [diff] [blame] | 52 | |
| 53 | public: |
peter klausler | a62636f | 2018-10-08 22:35:19 | [diff] [blame] | 54 | ~IntrinsicProcTable(); |
peter klausler | bf339f8 | 2018-10-15 22:28:47 | [diff] [blame] | 55 | static IntrinsicProcTable Configure( |
peter klausler | f9d6c0a | 2019-01-18 20:40:47 | [diff] [blame] | 56 | const common::IntrinsicTypeDefaultKinds &); |
peter klausler | ef9dd9d | 2018-10-17 22:09:48 | [diff] [blame] | 57 | |
| 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 klausler | ba56b91 | 2019-02-22 23:45:30 | [diff] [blame^] | 63 | |
| 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 klausler | 7bda1b3 | 2018-10-12 23:01:55 | [diff] [blame] | 69 | std::ostream &Dump(std::ostream &) const; |
peter klausler | 42b33da | 2018-09-29 00:02:11 | [diff] [blame] | 70 | |
| 71 | private: |
peter klausler | 75a3209 | 2018-10-05 16:57:53 | [diff] [blame] | 72 | Implementation *impl_{nullptr}; // owning pointer |
peter klausler | 42b33da | 2018-09-29 00:02:11 | [diff] [blame] | 73 | }; |
Jean Perier | f7e7cb3 | 2018-10-25 12:55:23 | [diff] [blame] | 74 | } |
peter klausler | f24cd7d | 2018-07-11 21:50:08 | [diff] [blame] | 75 | #endif // FORTRAN_EVALUATE_INTRINSICS_H_ |