expr-parsers.h
3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//===-- lib/Parser/expr-parsers.h -------------------------------*- C++ -*-===//
//
// 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
//
//===----------------------------------------------------------------------===//
#ifndef FORTRAN_PARSER_EXPR_PARSERS_H_
#define FORTRAN_PARSER_EXPR_PARSERS_H_
#include "basic-parsers.h"
#include "token-parsers.h"
#include "type-parsers.h"
#include "flang/Parser/parse-tree.h"
namespace Fortran::parser {
// R403 scalar-xyz -> xyz
// Also define constant-xyz, int-xyz, default-char-xyz.
template <typename PA> inline constexpr auto scalar(const PA &p) {
return construct<Scalar<typename PA::resultType>>(p); // scalar-p
}
template <typename PA> inline constexpr auto constant(const PA &p) {
return construct<Constant<typename PA::resultType>>(p); // constant-p
}
template <typename PA> inline constexpr auto integer(const PA &p) {
return construct<Integer<typename PA::resultType>>(p); // int-p
}
template <typename PA> inline constexpr auto logical(const PA &p) {
return construct<Logical<typename PA::resultType>>(p); // logical-p
}
template <typename PA> inline constexpr auto defaultChar(const PA &p) {
return construct<DefaultChar<typename PA::resultType>>(p); // default-char-p
}
// N.B. charLiteralConstantWithoutKind does not skip preceding space.
constexpr auto charLiteralConstantWithoutKind{
"'"_ch >> CharLiteral<'\''>{} || "\""_ch >> CharLiteral<'"'>{}};
// R904 logical-variable -> variable
// Appears only as part of scalar-logical-variable.
constexpr auto scalarLogicalVariable{scalar(logical(variable))};
// R906 default-char-variable -> variable
// Appears only as part of scalar-default-char-variable.
constexpr auto scalarDefaultCharVariable{scalar(defaultChar(variable))};
// R907 int-variable -> variable
// Appears only as part of scalar-int-variable.
constexpr auto scalarIntVariable{scalar(integer(variable))};
// R930 errmsg-variable -> scalar-default-char-variable
// R1207 iomsg-variable -> scalar-default-char-variable
constexpr auto msgVariable{construct<MsgVariable>(scalarDefaultCharVariable)};
// R1024 logical-expr -> expr
constexpr auto logicalExpr{logical(indirect(expr))};
constexpr auto scalarLogicalExpr{scalar(logicalExpr)};
// R1025 default-char-expr -> expr
constexpr auto defaultCharExpr{defaultChar(indirect(expr))};
constexpr auto scalarDefaultCharExpr{scalar(defaultCharExpr)};
// R1026 int-expr -> expr
constexpr auto intExpr{integer(indirect(expr))};
constexpr auto scalarIntExpr{scalar(intExpr)};
// R1029 constant-expr -> expr
constexpr auto constantExpr{constant(indirect(expr))};
constexpr auto scalarExpr{scalar(indirect(expr))};
// R1030 default-char-constant-expr -> default-char-expr
constexpr auto scalarDefaultCharConstantExpr{scalar(defaultChar(constantExpr))};
// R1031 int-constant-expr -> int-expr
constexpr auto intConstantExpr{integer(constantExpr)};
constexpr auto scalarIntConstantExpr{scalar(intConstantExpr)};
// R935 lower-bound-expr -> scalar-int-expr
// R936 upper-bound-expr -> scalar-int-expr
constexpr auto boundExpr{scalarIntExpr};
// R1115 team-value -> scalar-expr
constexpr auto teamValue{scalar(indirect(expr))};
// R1124 do-variable -> scalar-int-variable-name
constexpr auto doVariable{scalar(integer(name))};
// NOTE: In loop-control we allow REAL name and bounds too.
// This means parse them without the integer constraint and check later.
inline constexpr auto loopBounds(decltype(scalarExpr) &p) {
return construct<LoopBounds<ScalarName, ScalarExpr>>(
scalar(name) / "=", p / ",", p, maybe("," >> p));
}
template <typename PA> inline constexpr auto loopBounds(const PA &p) {
return construct<LoopBounds<DoVariable, typename PA::resultType>>(
doVariable / "=", p / ",", p, maybe("," >> p));
}
} // namespace Fortran::parser
#endif