| 1 |
//===--- CXX.h - Public interfaces for the C++ grammar -----------*- 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 |
// This file defines public interfaces for the C++ grammar |
| 10 |
// (pseudo/lib/cxx/cxx.bnf). It provides a fast way to access core building |
| 11 |
// pieces of the LR parser, e.g. Grammar, LRTable, rather than parsing the |
| 12 |
// grammar file at the runtime. |
| 13 |
// |
| 14 |
// We do a compilation of the C++ BNF grammar at build time, and generate |
| 15 |
// critical data sources. The implementation of the interfaces are based on the |
| 16 |
// generated data sources. |
| 17 |
// |
| 18 |
// FIXME: not everything is fully compiled yet. The implementation of the |
| 19 |
// interfaces are still parsing the grammar file at the runtime. |
| 20 |
// |
| 21 |
//===----------------------------------------------------------------------===// |
| 22 |
|
| 23 |
#ifndef CLANG_PSEUDO_CXX_CXX_H |
| 24 |
#define CLANG_PSEUDO_CXX_CXX_H |
| 25 |
|
| 26 |
#include "clang-pseudo/Language.h" |
| 27 |
#include "clang-pseudo/grammar/Grammar.h" |
| 28 |
|
| 29 |
namespace clang { |
| 30 |
namespace pseudo { |
| 31 |
namespace cxx { |
| 32 |
|
| 33 |
// We want enums to be scoped but implicitly convertible to RuleID etc. |
| 34 |
// So create regular (unscoped) enums inside subnamespaces of `detail`. |
| 35 |
// Then add aliases for them outside `detail`. |
| 36 |
namespace detail { |
| 37 |
namespace symbols { |
| 38 |
enum Symbol : SymbolID { |
| 39 |
#define NONTERMINAL(X, Y) X = Y, |
| 40 |
#include "CXXSymbols.inc" |
| 41 |
#undef NONTERMINAL |
| 42 |
}; |
| 43 |
} // namespace symbols |
| 44 |
|
| 45 |
namespace extensions { |
| 46 |
enum Extension : ExtensionID { |
| 47 |
#define EXTENSION(X, Y) X = Y, |
| 48 |
#include "CXXSymbols.inc" |
| 49 |
#undef EXTENSION |
| 50 |
}; |
| 51 |
} // namespace extensions |
| 52 |
|
| 53 |
namespace rules { |
| 54 |
// For each symbol we close the last symbol's enum+namespace and open new ones. |
| 55 |
// We need a dummy namespace+enum so that this works for the first rule. |
| 56 |
namespace dummy { |
| 57 |
enum Dummy { |
| 58 |
//clang-format off |
| 59 |
#define NONTERMINAL(NAME, ID) \ |
| 60 |
}; \ |
| 61 |
} \ |
| 62 |
namespace NAME { \ |
| 63 |
enum Rule : RuleID { |
| 64 |
//clang-format on |
| 65 |
#define RULE(LHS, RHS, ID) RHS = ID, |
| 66 |
#include "CXXSymbols.inc" |
| 67 |
}; |
| 68 |
} |
| 69 |
} // namespace rules |
| 70 |
} // namespace detail |
| 71 |
|
| 72 |
// Symbol represents nonterminal symbols in the C++ grammar. |
| 73 |
// It provides a simple uniform way to access a particular nonterminal. |
| 74 |
using Symbol = detail::symbols::Symbol; |
| 75 |
|
| 76 |
using Extension = detail::extensions::Extension; |
| 77 |
|
| 78 |
namespace rule { |
| 79 |
#define NONTERMINAL(NAME, ID) using NAME = detail::rules::NAME::Rule; |
| 80 |
#include "CXXSymbols.inc" |
| 81 |
} // namespace rule |
| 82 |
|
| 83 |
// Returns the Language for the cxx.bnf grammar. |
| 84 |
const Language &getLanguage(); |
| 85 |
|
| 86 |
} // namespace cxx |
| 87 |
|
| 88 |
} // namespace pseudo |
| 89 |
} // namespace clang |
| 90 |
|
| 91 |
#endif // CLANG_PSEUDO_CXX_CXX_H |