Skip to content

Commit 726d630

Browse files
author
Mandeep Singh Grang
authored
Compare Expressions: Rename BinaryNode to OperatorNode [NFC] (checkedc#946)
The preorder AST is an n-ary tree. Hence, calling an operator node as BinaryNode is not correct. So we rename BinaryNode to OperatorNode.
1 parent 800f484 commit 726d630

File tree

2 files changed

+107
-114
lines changed

2 files changed

+107
-114
lines changed

clang/include/clang/AST/PreorderAST.h

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,32 @@
2323

2424
namespace clang {
2525
using Result = Lexicographic::Result;
26+
class OperatorNode;
2627

2728
class Node {
2829
public:
29-
enum class NodeKind { BinaryNode, LeafExprNode };
30+
enum class NodeKind { OperatorNode, LeafExprNode };
3031

3132
NodeKind Kind;
32-
Node *Parent;
33+
OperatorNode *Parent;
3334

34-
Node(NodeKind Kind, Node *Parent) :
35+
Node(NodeKind Kind, OperatorNode *Parent) :
3536
Kind(Kind), Parent(Parent) {}
3637
};
3738

38-
class BinaryNode : public Node {
39+
class OperatorNode : public Node {
3940
public:
4041
BinaryOperator::Opcode Opc;
42+
// Note: An OperatorNode has a list of children because the preorder AST is
43+
// an n-ary tree.
4144
llvm::SmallVector<Node *, 2> Children;
4245

43-
BinaryNode(BinaryOperator::Opcode Opc, Node *Parent) :
44-
Node(NodeKind::BinaryNode, Parent),
46+
OperatorNode(BinaryOperator::Opcode Opc, OperatorNode *Parent) :
47+
Node(NodeKind::OperatorNode, Parent),
4548
Opc(Opc) {}
4649

4750
static bool classof(const Node *N) {
48-
return N->Kind == NodeKind::BinaryNode;
51+
return N->Kind == NodeKind::OperatorNode;
4952
}
5053

5154
// Is the operator commutative and associative?
@@ -58,7 +61,7 @@ namespace clang {
5861
public:
5962
Expr *E;
6063

61-
LeafExprNode(Expr *E, Node *Parent) :
64+
LeafExprNode(Expr *E, OperatorNode *Parent) :
6265
Node(NodeKind::LeafExprNode, Parent),
6366
E(E) {}
6467

@@ -81,32 +84,32 @@ namespace clang {
8184
// Create a PreorderAST for the expression E.
8285
// @param[in] E is the sub expression to be added to a new node.
8386
// @param[in] Parent is the parent of the new node.
84-
void Create(Expr *E, Node *Parent = nullptr);
87+
void Create(Expr *E, OperatorNode *Parent = nullptr);
8588

8689
// Add a new node to the AST.
8790
// @param[in] Node is the current node to be added.
8891
// @param[in] Parent is the parent of the node to be added.
89-
void AddNode(Node *N, Node *Parent);
92+
void AddNode(Node *N, OperatorNode *Parent);
9093

91-
// Coalesce the BinaryNode B with its parent. This involves moving the
92-
// children (if any) of node B to its parent and then removing B.
93-
// @param[in] B is the current node. B should be a BinaryNode.
94-
void CoalesceNode(BinaryNode *B);
94+
// Coalesce the OperatorNode O with its parent. This involves moving the
95+
// children (if any) of node O to its parent and then removing O.
96+
// @param[in] O is the current node. O should be a OperatorNode.
97+
void CoalesceNode(OperatorNode *O);
9598

96-
// Determines if a BinaryNode could be coalesced into its parent.
97-
// @param[in] B is the current node. B should be a BinaryNode.
98-
// @return Return true if B can be coalesced into its parent, false
99+
// Determines if a OperatorNode could be coalesced into its parent.
100+
// @param[in] O is the current node. O should be a OperatorNode.
101+
// @return Return true if O can be coalesced into its parent, false
99102
// otherwise.
100-
bool CanCoalesceNode(BinaryNode *B);
103+
bool CanCoalesceNode(OperatorNode *O);
101104

102-
// Recursively coalesce binary nodes having the same commutative and
105+
// Recursively coalesce OperatoreNodes having the same commutative and
103106
// associative operator.
104107
// @param[in] N is current node of the AST. Initial value is Root.
105108
// @param[in] Changed indicates whether a node was coalesced. We need this
106109
// to control when to stop recursive coalescing.
107110
void Coalesce(Node *N, bool &Changed);
108111

109-
// Sort the children expressions in a binary node of the AST.
112+
// Sort the children expressions in a OperatorNode of the AST.
110113
// @param[in] N is current node of the AST. Initial value is Root.
111114
void Sort(Node *N);
112115

0 commit comments

Comments
 (0)