| 1 |
/* |
| 2 |
* Copyright 2021 Google LLC |
| 3 |
* |
| 4 |
* Use of this source code is governed by a BSD-style license that can be |
| 5 |
* found in the LICENSE file. |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "src/sksl/SkSLAnalysis.h" |
| 9 |
#include "src/sksl/ir/SkSLBlock.h" |
| 10 |
#include "src/sksl/ir/SkSLForStatement.h" |
| 11 |
#include "src/sksl/ir/SkSLIRNode.h" |
| 12 |
#include "src/sksl/ir/SkSLStatement.h" |
| 13 |
|
| 14 |
#include <vector> |
| 15 |
|
| 16 |
namespace SkSL { |
| 17 |
|
| 18 |
class SymbolTable; |
| 19 |
|
| 20 |
namespace Analysis { |
| 21 |
|
| 22 |
SymbolTableStackBuilder::SymbolTableStackBuilder(const Statement* stmt, |
| 23 |
std::vector<SymbolTable*>* stack) { |
| 24 |
if (stmt) { |
| 25 |
switch (stmt->kind()) { |
| 26 |
case Statement::Kind::kBlock: |
| 27 |
if (SymbolTable* symbols = stmt->as<Block>().symbolTable()) { |
| 28 |
stack->push_back(symbols); |
| 29 |
fStackToPop = stack; |
| 30 |
} |
| 31 |
break; |
| 32 |
|
| 33 |
case Statement::Kind::kFor: |
| 34 |
if (SymbolTable* symbols = stmt->as<ForStatement>().symbols()) { |
| 35 |
stack->push_back(symbols); |
| 36 |
fStackToPop = stack; |
| 37 |
} |
| 38 |
break; |
| 39 |
|
| 40 |
default: |
| 41 |
break; |
| 42 |
} |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
SymbolTableStackBuilder::~SymbolTableStackBuilder() { |
| 47 |
if (fStackToPop) { |
| 48 |
fStackToPop->pop_back(); |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
} // namespace Analysis |
| 53 |
} // namespace SkSL |