blob: dc7701cdfa5f9fe27768158435fc28ba90cb6223 [file] [log] [blame]
Ethan Nicholas58014fa2021-09-29 17:18:18 -04001/*
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
14namespace SkSL {
15
16class ProgramElement;
17class String;
18
19/**
20 * Represents the intrinsics in the Context.
21 */
22class IntrinsicMap {
23public:
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
34private:
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