[all-commits] [llvm/llvm-project] 276d21: Generalize and harmonize sub-expression traversal

Kim Gräsman via All-commits all-commits at lists.llvm.org
Mon Mar 21 12:03:42 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 276d2143148fd1519af8eef124dabc41eabb1bb0
      https://github.com/llvm/llvm-project/commit/276d2143148fd1519af8eef124dabc41eabb1bb0
  Author: Kim Gräsman <kim.grasman at gmail.com>
  Date:   2022-03-21 (Mon, 21 Mar 2022)

  Changed paths:
    M clang/lib/AST/Expr.cpp

  Log Message:
  -----------
  Generalize and harmonize sub-expression traversal

CastExpr::getSubExprAsWritten and getConversionFunction used to have
disparate implementations to traverse the sub-expression chain and skip
so-called "implicit temporaries" (which are really implicit nodes added
by Sema to represent semantic details in the AST).

There's some friction in these algorithms that makes it hard to extend
and change them:

* skipImplicitTemporary is order-dependent; it can skip a
CXXBindTemporaryExpr nested inside a MaterializeTemporaryExpr, but not
vice versa
* skipImplicitTemporary only runs one pass, it does not traverse
multiple nested sequences of MTE/CBTE/MTE/CBTE, for example

Both of these weaknesses are void at this point, because this kind of
out-of-order multi-level nesting does not exist in the current AST.

Adding a new implicit expression to skip exacerbates the problem,
however, since a node X might show up in any and all locations between
the existing.

Thus;

* Harmonize the form of getSubExprAsWritten and getConversionFunction
so they both use a for loop
* Use the IgnoreExprNodes machinery to skip multiple nodes
* Rename skipImplicitTemporary to ignoreImplicitSemaNodes to generalize
* Update ignoreImplicitSemaNodes so it only skips one level per call,
to mirror existing Ignore functions and work better with
IgnoreExprNodes

This is a functional change, but one without visible effect.




More information about the All-commits mailing list