| 1 |
//===-- lib/Parser/type-parser-implementation.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-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
// Macros for implementing per-type parsers |
| 10 |
|
| 11 |
#ifndef FORTRAN_PARSER_TYPE_PARSER_IMPLEMENTATION_H_ |
| 12 |
#define FORTRAN_PARSER_TYPE_PARSER_IMPLEMENTATION_H_ |
| 13 |
|
| 14 |
#include "type-parsers.h" |
| 15 |
|
| 16 |
#undef TYPE_PARSER |
| 17 |
#undef TYPE_CONTEXT_PARSER |
| 18 |
|
| 19 |
// The result type of a parser combinator expression is determined |
| 20 |
// here via "decltype(attempt(pexpr))" to work around a g++ bug that |
| 21 |
// causes it to crash on "decltype(pexpr)" when pexpr's top-level |
| 22 |
// operator is an overridden || of parsing alternatives. |
| 23 |
#define TYPE_PARSER(pexpr) \ |
| 24 |
template <> \ |
| 25 |
auto Parser<typename decltype(attempt(pexpr))::resultType>::Parse( \ |
| 26 |
ParseState &state) \ |
| 27 |
->std::optional<resultType> { \ |
| 28 |
static constexpr auto parser{(pexpr)}; \ |
| 29 |
return parser.Parse(state); \ |
| 30 |
} |
| 31 |
|
| 32 |
#define TYPE_CONTEXT_PARSER(contextText, pexpr) \ |
| 33 |
TYPE_PARSER(CONTEXT_PARSER((contextText), (pexpr))) |
| 34 |
|
| 35 |
#endif |