/src/skia/src/sksl/ir/SkSLProgram.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 2022 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/SkSLPool.h" |
10 | | #include "src/sksl/SkSLProgramSettings.h" |
11 | | #include "src/sksl/analysis/SkSLProgramUsage.h" |
12 | | #include "src/sksl/ir/SkSLFunctionDeclaration.h" |
13 | | #include "src/sksl/ir/SkSLProgram.h" |
14 | | #include "src/sksl/ir/SkSLProgramElement.h" |
15 | | #include "src/sksl/ir/SkSLSymbol.h" |
16 | | #include "src/sksl/ir/SkSLSymbolTable.h" // IWYU pragma: keep |
17 | | |
18 | | #include <utility> |
19 | | |
20 | | namespace SkSL { |
21 | | |
22 | | Program::Program(std::unique_ptr<std::string> source, |
23 | | std::unique_ptr<ProgramConfig> config, |
24 | | std::shared_ptr<Context> context, |
25 | | std::vector<std::unique_ptr<ProgramElement>> elements, |
26 | | std::unique_ptr<SymbolTable> symbols, |
27 | | std::unique_ptr<Pool> pool) |
28 | | : fSource(std::move(source)) |
29 | | , fConfig(std::move(config)) |
30 | | , fContext(context) |
31 | | , fSymbols(std::move(symbols)) |
32 | | , fPool(std::move(pool)) |
33 | 340 | , fOwnedElements(std::move(elements)) { |
34 | 340 | fUsage = Analysis::GetUsage(*this); |
35 | 340 | } |
36 | | |
37 | 211 | Program::~Program() { |
38 | | // Some or all of the program elements are in the pool. To free them safely, we must attach |
39 | | // the pool before destroying any program elements. (Otherwise, we may accidentally call |
40 | | // delete on a pooled node.) |
41 | 211 | AutoAttachPoolToThread attach(fPool.get()); |
42 | | |
43 | 211 | fOwnedElements.clear(); |
44 | 211 | fContext.reset(); |
45 | 211 | fSymbols.reset(); |
46 | 211 | } |
47 | | |
48 | 0 | std::string Program::description() const { |
49 | 0 | std::string result = fConfig->versionDescription(); |
50 | 0 | for (const ProgramElement* e : this->elements()) { |
51 | 0 | result += e->description(); |
52 | 0 | } |
53 | 0 | return result; |
54 | 0 | } |
55 | | |
56 | 306 | const FunctionDeclaration* Program::getFunction(const char* functionName) const { |
57 | 306 | const Symbol* symbol = fSymbols->find(functionName); |
58 | 306 | bool valid = symbol && symbol->is<FunctionDeclaration>() && |
59 | 306 | symbol->as<FunctionDeclaration>().definition(); |
60 | 306 | return valid ? &symbol->as<FunctionDeclaration>() : nullptr; |
61 | 306 | } |
62 | | |
63 | | } // namespace SkSL |