Try to move towards the Google style guide declaration order. (#221)

This patch tries to make everything adhere to the Google declaration
order. This is tricky as there doesn't appear to be a `clang-tidy` check
that helps us here at all.

One of the complex cases are the `enum`-wrapping classes we use. These
need to have a *public* conversion operator to the nested `enum` type to support
`switch` statements and the like. However, this makes it impossible to
fully respect the Google declaration order. We need to define the enum
type before the public API in order to use it in contexts like the
conversion operator. Even defining out-of-line won't help avoid this. It
is weird to have a type in the public API that is private, but again
this is only intended to be used for implicit conversions within
a `switch` statement or a `case` label. In one case, we had the
non-conforming order of declaration. I've added a comment to explain why
there. In the other case, the conversion operator is actually *private*
rather than public, which doesn't actually work in practice. I've made
this public and moved the declaration order to match with a matching
comment.
This commit is contained in:
Chandler Carruth
2020-12-08 15:35:26 -08:00
committed by GitHub
parent 03f77d7b25
commit c3d951599d
6 changed files with 38 additions and 34 deletions
+9 -9
View File
@@ -140,6 +140,10 @@ class ParseTree {
// The in-memory representation of data used for a particular node in the
// tree.
struct NodeImpl {
explicit NodeImpl(ParseNodeKind k, TokenizedBuffer::Token t,
int subtree_size_arg)
: kind(k), token(t), subtree_size(subtree_size_arg) {}
// The kind of this node. Note that this is only a single byte.
ParseNodeKind kind;
@@ -179,10 +183,6 @@ class ParseTree {
// This field should always be a positive integer as at least this node is
// part of its subtree.
int32_t subtree_size;
explicit NodeImpl(ParseNodeKind k, TokenizedBuffer::Token t,
int subtree_size_arg)
: kind(k), token(t), subtree_size(subtree_size_arg) {}
};
static_assert(sizeof(NodeImpl) == 12,
@@ -301,9 +301,9 @@ class ParseTree::PostorderIterator
private:
friend class ParseTree;
Node node;
explicit PostorderIterator(Node n) : node(n) {}
Node node;
};
// A forward iterator across the silbings at a particular level in the parse
@@ -343,12 +343,12 @@ class ParseTree::SiblingIterator
private:
friend class ParseTree;
explicit SiblingIterator(const ParseTree& tree_arg, Node n)
: tree(&tree_arg), node(n) {}
const ParseTree* tree;
Node node;
explicit SiblingIterator(const ParseTree& tree_arg, Node n)
: tree(&tree_arg), node(n) {}
};
} // namespace Carbon