• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/base/SkStringView.h"
9 #include "src/sksl/SkSLIntrinsicList.h"
10 
11 namespace SkSL {
12 
GetIntrinsicMap()13 const IntrinsicMap& GetIntrinsicMap() {
14     #define SKSL_INTRINSIC(name) {#name, k_##name##_IntrinsicKind},
15     static const auto* kAllIntrinsics = new SkTHashMap<std::string_view, IntrinsicKind>{
16         SKSL_INTRINSIC_LIST
17     };
18     #undef SKSL_INTRINSIC
19 
20     return *kAllIntrinsics;
21 }
22 
FindIntrinsicKind(std::string_view functionName)23 IntrinsicKind FindIntrinsicKind(std::string_view functionName) {
24     if (skstd::starts_with(functionName, '$')) {
25         functionName.remove_prefix(1);
26     }
27 
28     const IntrinsicMap& intrinsicMap = GetIntrinsicMap();
29     IntrinsicKind* kind = intrinsicMap.find(functionName);
30     return kind ? *kind : kNotIntrinsic;
31 }
32 
33 }  // namespace SkSL
34