1 //
2 // Copyright 2020 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/TranslatorMetalDirect/DiscoverEnclosingFunctionTraverser.h"
8 
9 using namespace sh;
10 
DiscoverEnclosingFunctionTraverser(bool preVisit_,bool inVisit_,bool postVisit_,TSymbolTable * symbolTable)11 DiscoverEnclosingFunctionTraverser::DiscoverEnclosingFunctionTraverser(bool preVisit_,
12                                                                        bool inVisit_,
13                                                                        bool postVisit_,
14                                                                        TSymbolTable *symbolTable)
15     : TIntermTraverser(preVisit_, inVisit_, postVisit_, symbolTable)
16 {}
17 
discoverEnclosingFunction(TIntermNode * node)18 const TFunction *DiscoverEnclosingFunctionTraverser::discoverEnclosingFunction(TIntermNode *node)
19 {
20     ASSERT(!node->getAsFunctionDefinition());
21 
22     unsigned height = 0;
23     while (TIntermNode *ancestor = getAncestorNode(height))
24     {
25         if (TIntermFunctionDefinition *funcDefNode = ancestor->getAsFunctionDefinition())
26         {
27             return funcDefNode->getFunction();
28         }
29         ++height;
30     }
31 
32     return nullptr;
33 }
34