From 801aa3b44254341018a1acbe754f2ce3b0900e2a Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 16 Nov 2022 12:17:49 -0800 Subject: 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 --- source/slang/slang-ast-support-types.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'source/slang/slang-ast-support-types.cpp') 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 workListSet; + while (auto higherOrder = as(expr)) + { + if (workListSet.Add(higherOrder)) + { + expr = higherOrder->baseFunction; + } + else + { + // Circularity, return null. + return nullptr; + } + } + return expr; +} + +UnownedStringSlice getHigherOrderOperatorName(HigherOrderInvokeExpr* expr) +{ + if (as(expr)) + return UnownedStringSlice("fwd_diff"); + else if (as(expr)) + return UnownedStringSlice("bwd_diff"); + return UnownedStringSlice(); +} } -- cgit v1.2.3