blob: 2ac4cd7e09bff5c7ccfc87dd114ef0c64a15a43f [file] [log] [blame]
peter klauslera62636f2018-10-08 22:35:191// Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
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_CALL_H_
16#define FORTRAN_EVALUATE_CALL_H_
17
18#include "common.h"
19#include "type.h"
20#include "../common/indirection.h"
21#include "../parser/char-block.h"
peter klauslerd804c9d2018-10-18 20:03:5122#include "../semantics/attr.h"
peter klauslera62636f2018-10-08 22:35:1923#include <optional>
24#include <ostream>
25#include <vector>
26
peter klauslerd804c9d2018-10-18 20:03:5127namespace Fortran::semantics {
28class Symbol;
29}
30
peter klauslera62636f2018-10-08 22:35:1931namespace Fortran::evaluate {
32
33struct ActualArgument {
peter klausler62425d62018-10-12 00:01:3134 explicit ActualArgument(Expr<SomeType> &&x) : value{std::move(x)} {}
peter klauslera62636f2018-10-08 22:35:1935 explicit ActualArgument(CopyableIndirection<Expr<SomeType>> &&v)
36 : value{std::move(v)} {}
peter klausler84ea49d2018-10-18 17:50:5537
peter klauslera62636f2018-10-08 22:35:1938 std::optional<DynamicType> GetType() const;
39 int Rank() const;
40 std::ostream &Dump(std::ostream &) const;
peter klauslerad9aede2018-10-11 21:51:1441 std::optional<int> VectorSize() const;
peter klauslera62636f2018-10-08 22:35:1942
43 std::optional<parser::CharBlock> keyword;
peter klausler84ea49d2018-10-18 17:50:5544 bool isAssumedRank{false}; // TODO: make into a function of the value
peter klauslerd804c9d2018-10-18 20:03:5145 bool isAlternateReturn{false}; // when true, "value" is a label number
46
47 // TODO: Mark legacy %VAL and %REF arguments
peter klauslerad9aede2018-10-11 21:51:1448
49 // Subtlety: There is a distinction that must be maintained here between an
50 // actual argument expression that is a variable and one that is not,
51 // e.g. between X and (X). The parser attempts to parse each argument
52 // first as a variable, then as an expression, and the distinction appears
53 // in the parse tree.
peter klauslera62636f2018-10-08 22:35:1954 CopyableIndirection<Expr<SomeType>> value;
55};
56
peter klausleref9dd9d2018-10-17 22:09:4857using ActualArguments = std::vector<std::optional<ActualArgument>>;
peter klauslerd804c9d2018-10-18 20:03:5158
59// Intrinsics are identified by their names and the characteristics
60// of their arguments, at least for now.
61using IntrinsicProcedure = const char *; // not an owning pointer
62
63struct SpecificIntrinsic {
64 explicit SpecificIntrinsic(IntrinsicProcedure n) : name{n} {}
65 SpecificIntrinsic(IntrinsicProcedure n, std::optional<DynamicType> &&dt,
66 int r, semantics::Attrs a)
67 : name{n}, type{std::move(dt)}, rank{r}, attrs{a} {}
68 std::ostream &Dump(std::ostream &) const;
69
70 IntrinsicProcedure name;
71 bool isRestrictedSpecific{false}; // if true, can only call it
72 std::optional<DynamicType> type; // absent if and only if subroutine call
73 int rank{0};
74 semantics::Attrs attrs; // ELEMENTAL, POINTER
75};
76
77struct ProcedureDesignator {
78 EVALUATE_UNION_CLASS_BOILERPLATE(ProcedureDesignator)
79 explicit ProcedureDesignator(SpecificIntrinsic &&i) : u{std::move(i)} {}
80 explicit ProcedureDesignator(const semantics::Symbol &n) : u{&n} {}
81 std::optional<DynamicType> GetType() const;
82 int Rank() const;
83 bool IsElemental() const;
84 Expr<SubscriptInteger> LEN() const;
85 const semantics::Symbol *GetSymbol() const;
86 std::ostream &Dump(std::ostream &) const;
87
88 // TODO: When calling X%F, pass X as PASS argument unless NOPASS
89 std::variant<SpecificIntrinsic, const semantics::Symbol *> u;
90};
Jean Perierf7e7cb32018-10-25 12:55:2391}
peter klauslera62636f2018-10-08 22:35:1992#endif // FORTRAN_EVALUATE_CALL_H_