Switch constexpr factory functions to constexpr values. (#2581)

Using the same const/constexpr done in EnumBase, adds Invalid and Builtin* values to replace Make functions that produced the same. This should make it clearer at call sites what the cost actually is, and reduces the syntactic overhead for MakeBuiltinReference in particular.

Really, this is that MakeBuiltinReference has been feeling pretty verbose, so I did that, and then one MakeInvalid is right next to it, and then obviously I should replace the other MakeInvalid for consistency...
This commit is contained in:
Jon Ross-Perkins
2023-02-06 15:57:33 -08:00
committed by GitHub
parent 1a8a41a5a6
commit 5a0613283b
4 changed files with 33 additions and 29 deletions
+5 -2
View File
@@ -242,12 +242,15 @@ class ParseTree {
// That said, nodes can be compared and are part of a depth-first pre-order
// sequence across all nodes in the parse tree.
struct ParseTree::Node : public ComparableIndexBase {
// Constructs an explicitly invalid instance.
static auto MakeInvalid() -> Node { return Node(); }
// An explicitly invalid instance.
// NOLINTNEXTLINE(readability-identifier-naming)
static const Node Invalid;
using ComparableIndexBase::ComparableIndexBase;
};
constexpr ParseTree::Node ParseTree::Node::Invalid;
// A random-access iterator to the depth-first postorder sequence of parse nodes
// in the parse tree. It produces `ParseTree::Node` objects which are opaque
// handles and must be used in conjunction with the `ParseTree` itself.