diff options
| author | Yong He <yonghe@outlook.com> | 2022-11-16 12:17:49 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-16 12:17:49 -0800 |
| commit | 801aa3b44254341018a1acbe754f2ce3b0900e2a (patch) | |
| tree | b3066778522edb99bf64c0ac80c91b0b4cb788f8 /source/slang/slang-ast-support-types.cpp | |
| parent | 09d8e048d2264d89886cda8e87e8a452d4f913c1 (diff) | |
Clean up type checking of higher order expressions. (#2519)
* Clean up type checking of higher order expressions.
* Replace `goto` with `break` to pacify clang.
* Fix.
* Fixes.
* Fix more tests.
* Fix lowerWitnessTable parameter error.
* Exclude attributes from ast printing.
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-ast-support-types.cpp')
| -rw-r--r-- | source/slang/slang-ast-support-types.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/source/slang/slang-ast-support-types.cpp b/source/slang/slang-ast-support-types.cpp index 1f30e0238..b550eaa68 100644 --- a/source/slang/slang-ast-support-types.cpp +++ b/source/slang/slang-ast-support-types.cpp @@ -1,6 +1,7 @@ #include "slang-ast-support-types.h" #include "slang-ast-base.h" #include "slang-ast-type.h" +#include "slang-ast-expr.h" namespace Slang { @@ -34,4 +35,31 @@ void removeModifier(ModifiableSyntaxNode* syntax, Modifier* toRemove) prev = modifier; } } + +Expr* getInnerMostExprFromHigherOrderExpr(Expr* expr) +{ + HashSet<Expr*> workListSet; + while (auto higherOrder = as<HigherOrderInvokeExpr>(expr)) + { + if (workListSet.Add(higherOrder)) + { + expr = higherOrder->baseFunction; + } + else + { + // Circularity, return null. + return nullptr; + } + } + return expr; +} + +UnownedStringSlice getHigherOrderOperatorName(HigherOrderInvokeExpr* expr) +{ + if (as<ForwardDifferentiateExpr>(expr)) + return UnownedStringSlice("fwd_diff"); + else if (as<BackwardDifferentiateExpr>(expr)) + return UnownedStringSlice("bwd_diff"); + return UnownedStringSlice(); +} } |
