Ethan Nicholas | 58014fa | 2021-09-29 17:18:18 -0400 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2020 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 | #ifndef SKSL_INTRINSICMAP |
| 9 | #define SKSL_INTRINSICMAP |
| 10 | |
| 11 | #include <memory> |
| 12 | #include <unordered_map> |
| 13 | |
| 14 | namespace SkSL { |
| 15 | |
| 16 | class ProgramElement; |
| 17 | class String; |
| 18 | |
| 19 | /** |
| 20 | * Represents the intrinsics in the Context. |
| 21 | */ |
| 22 | class IntrinsicMap { |
| 23 | public: |
| 24 | IntrinsicMap(IntrinsicMap* parent) : fParent(parent) {} |
| 25 | |
| 26 | void insertOrDie(String key, std::unique_ptr<ProgramElement> element); |
| 27 | |
| 28 | const ProgramElement* find(const String& key); |
| 29 | |
| 30 | const ProgramElement* findAndInclude(const String& key); |
| 31 | |
| 32 | void resetAlreadyIncluded(); |
| 33 | |
| 34 | private: |
| 35 | struct Intrinsic { |
| 36 | std::unique_ptr<ProgramElement> fIntrinsic; |
| 37 | bool fAlreadyIncluded = false; |
| 38 | }; |
| 39 | |
| 40 | std::unordered_map<String, Intrinsic> fIntrinsics; |
| 41 | IntrinsicMap* fParent = nullptr; |
| 42 | }; |
| 43 | |
| 44 | } // namespace SkSL |
| 45 | |
| 46 | #endif |