diff options
| author | Ellie Hermaszewska <ellieh@nvidia.com> | 2024-10-29 14:49:26 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-29 14:49:26 +0800 |
| commit | f65d756bff8d4c5cbc15bd0322a2ae8e6b896a21 (patch) | |
| tree | ea1d61342cd29368e19135000ec2948813096205 /source/slang/slang-ir-check-recursive-type.cpp | |
| parent | a729c15e9dce9f5116a38afc66329ab2ca4cea54 (diff) | |
format
* format
* Minor test fixes
* enable checking cpp format in ci
Diffstat (limited to 'source/slang/slang-ir-check-recursive-type.cpp')
| -rw-r--r-- | source/slang/slang-ir-check-recursive-type.cpp | 82 |
1 files changed, 44 insertions, 38 deletions
diff --git a/source/slang/slang-ir-check-recursive-type.cpp b/source/slang/slang-ir-check-recursive-type.cpp index 8679801d0..ee4541735 100644 --- a/source/slang/slang-ir-check-recursive-type.cpp +++ b/source/slang/slang-ir-check-recursive-type.cpp @@ -1,59 +1,65 @@ #include "slang-ir-check-recursive-type.h" + #include "slang-ir-util.h" namespace Slang { - bool checkTypeRecursionImpl(HashSet<IRInst*>& checkedTypes, HashSet<IRInst*>& stack, IRInst* type, IRInst* field, DiagnosticSink* sink) +bool checkTypeRecursionImpl( + HashSet<IRInst*>& checkedTypes, + HashSet<IRInst*>& stack, + IRInst* type, + IRInst* field, + DiagnosticSink* sink) +{ + auto visitElementType = [&](IRInst* elementType, IRInst* field) -> bool { - auto visitElementType = [&](IRInst* elementType, IRInst* field) -> bool - { - if (!stack.add(elementType)) - { - sink->diagnose(field ? field : type, Diagnostics::recursiveType, type); - return false; - } - if (checkedTypes.add(elementType)) - checkTypeRecursionImpl(checkedTypes, stack, elementType, field, sink); - stack.remove(elementType); - return true; - }; - if (auto arrayType = as<IRArrayTypeBase>(type)) - { - return visitElementType(arrayType->getElementType(), field); - } - else if (auto structType = as<IRStructType>(type)) + if (!stack.add(elementType)) { - for (auto sfield : structType->getFields()) - if (!visitElementType(sfield->getFieldType(), sfield)) - return false; + sink->diagnose(field ? field : type, Diagnostics::recursiveType, type); + return false; } + if (checkedTypes.add(elementType)) + checkTypeRecursionImpl(checkedTypes, stack, elementType, field, sink); + stack.remove(elementType); return true; + }; + if (auto arrayType = as<IRArrayTypeBase>(type)) + { + return visitElementType(arrayType->getElementType(), field); + } + else if (auto structType = as<IRStructType>(type)) + { + for (auto sfield : structType->getFields()) + if (!visitElementType(sfield->getFieldType(), sfield)) + return false; } + return true; +} - void checkTypeRecursion(HashSet<IRInst*>& checkedTypes, IRInst* type, DiagnosticSink* sink) +void checkTypeRecursion(HashSet<IRInst*>& checkedTypes, IRInst* type, DiagnosticSink* sink) +{ + HashSet<IRInst*> stack; + if (checkedTypes.add(type)) { - HashSet<IRInst*> stack; - if (checkedTypes.add(type)) - { - stack.add(type); - checkTypeRecursionImpl(checkedTypes, stack, type, nullptr, sink); - } + stack.add(type); + checkTypeRecursionImpl(checkedTypes, stack, type, nullptr, sink); } +} - void checkForRecursiveTypes(IRModule* module, DiagnosticSink* sink) +void checkForRecursiveTypes(IRModule* module, DiagnosticSink* sink) +{ + HashSet<IRInst*> checkedTypes; + for (auto globalInst : module->getGlobalInsts()) { - HashSet<IRInst*> checkedTypes; - for (auto globalInst : module->getGlobalInsts()) + switch (globalInst->getOp()) { - switch (globalInst->getOp()) + case kIROp_StructType: { - case kIROp_StructType: - { - checkTypeRecursion(checkedTypes, globalInst, sink); - } - break; + checkTypeRecursion(checkedTypes, globalInst, sink); } + break; } } - } + +} // namespace Slang |
