[clang] [NFC][Clang][TableGen] Refactor ClangASTNodesEmitter (PR #108580)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 13 11:12:14 PDT 2024


================
@@ -93,34 +87,31 @@ class ClangASTNodesEmitter {
 // Called recursively to ensure that nodes remain contiguous
 std::pair<ASTNode, ASTNode> ClangASTNodesEmitter::EmitNode(raw_ostream &OS,
                                                            ASTNode Base) {
-  std::string BaseName = macroName(std::string(Base.getName()));
+  std::string BaseName = macroName(Base.getName());
 
-  ChildIterator i = Tree.lower_bound(Base), e = Tree.upper_bound(Base);
-  bool HasChildren = (i != e);
+  auto [II, E] = Tree.equal_range(Base);
+  bool HasChildren = II != E;
 
   ASTNode First, Last;
   if (!Base.isAbstract())
     First = Last = Base;
 
-  auto comp = [this](ASTNode LHS, ASTNode RHS) {
-    auto LHSPrioritized = PrioritizedClasses.count(LHS) > 0;
-    auto RHSPrioritized = PrioritizedClasses.count(RHS) > 0;
-    if (LHSPrioritized && !RHSPrioritized)
-      return true;
-    if (!LHSPrioritized && RHSPrioritized)
-      return false;
-
+  auto Comp = [this](const ASTNode &LHS, const ASTNode &RHS) {
+    bool LHSPrioritized = PrioritizedClasses.count(LHS) > 0;
+    bool RHSPrioritized = PrioritizedClasses.count(RHS) > 0;
+    if (LHSPrioritized != RHSPrioritized)
+      return LHSPrioritized < RHSPrioritized;
----------------
AaronBallman wrote:

Didn't the logic here change? Assume `LHS` is true and `RHS` is false, it used to be:
```
if (true && !false) return true;
```
and now it's
```
if (true != false) return true < false; // which is false
```

https://github.com/llvm/llvm-project/pull/108580


More information about the cfe-commits mailing list