• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef ES2PANDA_UTIL_PLUGINS_H
16 #define ES2PANDA_UTIL_PLUGINS_H
17 
18 #include "macros.h"
19 #include "os/library_loader.h"
20 #include "public/es2panda_lib.h"
21 #include "util/ustring.h"
22 
23 namespace ark::es2panda::util {
24 
25 class Plugin {
26 public:
27     explicit Plugin(util::StringView const &name);
28     ~Plugin() = default;
29 
30     NO_COPY_SEMANTIC(Plugin);
31     DEFAULT_MOVE_SEMANTIC(Plugin);
32 
IsOk()33     bool IsOk()
34     {
35         return ok_;
36     }
37 
Error()38     os::Error Error()
39     {
40         return err_;
41     }
42 
Initialize()43     void Initialize() const
44     {
45         if (initialize_ != nullptr) {
46             initialize_();
47         }
48     }
49 
AfterParse(es2panda_Context * context)50     void AfterParse(es2panda_Context *context) const
51     {
52         if (afterParse_ != nullptr) {
53             afterParse_(context);
54         }
55     }
56 
AfterCheck(es2panda_Context * context)57     void AfterCheck(es2panda_Context *context) const
58     {
59         if (afterCheck_ != nullptr) {
60             afterCheck_(context);
61         }
62     }
63 
AfterLowerings(es2panda_Context * context)64     void AfterLowerings(es2panda_Context *context) const
65     {
66         if (afterLowerings_ != nullptr) {
67             afterLowerings_(context);
68         }
69     }
70 
71 private:
72     std::string FullNameForProcedure(std::string const &shortName);
73 
74     util::StringView name_;
75     bool ok_ {true};
76     os::Error err_;
77     os::library_loader::LibraryHandle h_;
78 
79     void (*initialize_)() = nullptr;
80     void (*afterParse_)(es2panda_Context *) = nullptr;
81     void (*afterCheck_)(es2panda_Context *) = nullptr;
82     void (*afterLowerings_)(es2panda_Context *) = nullptr;
83 };
84 
85 }  // namespace ark::es2panda::util
86 
87 #endif
88