brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.9 KiB · 1a93344 Raw
106 lines · c
1//===-- lib/Parser/expr-parsers.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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef FORTRAN_PARSER_EXPR_PARSERS_H_10#define FORTRAN_PARSER_EXPR_PARSERS_H_11 12#include "basic-parsers.h"13#include "token-parsers.h"14#include "type-parsers.h"15#include "flang/Parser/parse-tree.h"16 17namespace Fortran::parser {18 19// R403 scalar-xyz -> xyz20// Also define constant-xyz, int-xyz, default-char-xyz.21template <typename PA> inline constexpr auto scalar(const PA &p) {22  return construct<Scalar<typename PA::resultType>>(p); // scalar-p23}24 25template <typename PA> inline constexpr auto constant(const PA &p) {26  return construct<Constant<typename PA::resultType>>(p); // constant-p27}28 29template <typename PA> inline constexpr auto integer(const PA &p) {30  return construct<Integer<typename PA::resultType>>(p); // int-p31}32 33template <typename PA> inline constexpr auto logical(const PA &p) {34  return construct<Logical<typename PA::resultType>>(p); // logical-p35}36 37template <typename PA> inline constexpr auto defaultChar(const PA &p) {38  return construct<DefaultChar<typename PA::resultType>>(p); // default-char-p39}40 41// N.B. charLiteralConstantWithoutKind does not skip preceding space.42constexpr auto charLiteralConstantWithoutKind{43    "'"_ch >> CharLiteral<'\''>{} || "\""_ch >> CharLiteral<'"'>{}};44 45// R904 logical-variable -> variable46// Appears only as part of scalar-logical-variable.47constexpr auto scalarLogicalVariable{scalar(logical(variable))};48 49// R906 default-char-variable -> variable50// Appears only as part of scalar-default-char-variable.51constexpr auto scalarDefaultCharVariable{scalar(defaultChar(variable))};52 53// R907 int-variable -> variable54// Appears only as part of scalar-int-variable.55constexpr auto scalarIntVariable{scalar(integer(variable))};56 57// R930 errmsg-variable -> scalar-default-char-variable58// R1207 iomsg-variable -> scalar-default-char-variable59constexpr auto msgVariable{construct<MsgVariable>(scalarDefaultCharVariable)};60 61// R1024 logical-expr -> expr62constexpr auto logicalExpr{logical(indirect(expr))};63constexpr auto scalarLogicalExpr{scalar(logicalExpr)};64 65// R1025 default-char-expr -> expr66constexpr auto defaultCharExpr{defaultChar(indirect(expr))};67constexpr auto scalarDefaultCharExpr{scalar(defaultCharExpr)};68 69// R1026 int-expr -> expr70constexpr auto intExpr{integer(indirect(expr))};71constexpr auto scalarIntExpr{scalar(intExpr)};72 73// R1029 constant-expr -> expr74constexpr auto constantExpr{constant(indirect(expr))};75constexpr auto scalarExpr{scalar(indirect(expr))};76 77// R1030 default-char-constant-expr -> default-char-expr78constexpr auto scalarDefaultCharConstantExpr{scalar(defaultChar(constantExpr))};79 80// R1031 int-constant-expr -> int-expr81constexpr auto intConstantExpr{integer(constantExpr)};82constexpr auto scalarIntConstantExpr{scalar(intConstantExpr)};83 84// R935 lower-bound-expr -> scalar-int-expr85// R936 upper-bound-expr -> scalar-int-expr86constexpr auto boundExpr{scalarIntExpr};87 88// R1115 team-value -> scalar-expr89constexpr auto teamValue{scalar(indirect(expr))};90 91// R1124 do-variable -> scalar-int-variable-name92constexpr auto doVariable{scalar(integer(name))};93 94// NOTE: In loop-control we allow REAL name and bounds too.95// This means parse them without the integer constraint and check later.96inline constexpr auto loopBounds(decltype(scalarExpr) &p) {97  return construct<LoopBounds<ScalarName, ScalarExpr>>(98      scalar(name) / "=", p / ",", p, maybe("," >> p));99}100template <typename PA> inline constexpr auto loopBounds(const PA &p) {101  return construct<LoopBounds<DoVariable, typename PA::resultType>>(102      doVariable / "=", p / ",", p, maybe("," >> p));103}104} // namespace Fortran::parser105#endif106