tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

IsASTDepthBelowLimit.cpp (861B)


      1 //
      2 // Copyright 2017 The ANGLE Project Authors. All rights reserved.
      3 // Use of this source code is governed by a BSD-style license that can be
      4 // found in the LICENSE file.
      5 //
      6 
      7 #include "compiler/translator/IsASTDepthBelowLimit.h"
      8 
      9 #include "compiler/translator/tree_util/IntermTraverse.h"
     10 
     11 namespace sh
     12 {
     13 
     14 namespace
     15 {
     16 
     17 // Traverse the tree and compute max depth. Takes a maximum depth limit to prevent stack overflow.
     18 class MaxDepthTraverser : public TIntermTraverser
     19 {
     20  public:
     21    MaxDepthTraverser(int depthLimit) : TIntermTraverser(true, false, false, nullptr)
     22    {
     23        setMaxAllowedDepth(depthLimit);
     24    }
     25 };
     26 
     27 }  // anonymous namespace
     28 
     29 bool IsASTDepthBelowLimit(TIntermNode *root, int maxDepth)
     30 {
     31    MaxDepthTraverser traverser(maxDepth + 1);
     32    root->traverse(&traverser);
     33 
     34    return traverser.getMaxDepth() <= maxDepth;
     35 }
     36 
     37 }  // namespace sh