• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 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 PANDA_RUNTIME_VTABLE_BUILDER_INTERFACE_H
16 #define PANDA_RUNTIME_VTABLE_BUILDER_INTERFACE_H
17 
18 #include "runtime/include/method.h"
19 
20 namespace ark {
21 
22 class ClassLinker;
23 class ClassLinkerContext;
24 class ClassLinkerErrorHandler;
25 
26 struct CopiedMethod {
27     CopiedMethod() = default;
CopiedMethodCopiedMethod28     explicit CopiedMethod(Method *cpMethod) : method_(cpMethod) {}
29 
30     enum class Status {
31         ORDINARY = 0,
32         ABSTRACT,
33         CONFLICT,
34     };
35 
GetMethodCopiedMethod36     Method *GetMethod() const
37     {
38         return method_;
39     }
40 
GetStatusCopiedMethod41     Status GetStatus() const
42     {
43         return status_;
44     }
45 
SetStatusCopiedMethod46     void SetStatus(Status status)
47     {
48         status_ = status;
49     }
50 
51 private:
52     Method *method_ {};
53     Status status_ {Status::ORDINARY};
54 };
55 
56 class VTableBuilder {
57 public:
58     VTableBuilder() = default;
59 
60     [[nodiscard]] virtual bool Build(panda_file::ClassDataAccessor *cda, Class *baseClass, ITable itable,
61                                      ClassLinkerContext *ctx) = 0;
62 
63     [[nodiscard]] virtual bool Build(Span<Method> methods, Class *baseClass, ITable itable, bool isInterface) = 0;
64 
65     virtual void UpdateClass(Class *klass) const = 0;
66 
67     virtual size_t GetNumVirtualMethods() const = 0;
68 
69     virtual size_t GetVTableSize() const = 0;
70 
71     virtual Span<const CopiedMethod> GetCopiedMethods() const = 0;
72 
73     virtual ~VTableBuilder() = default;
74 
75     NO_COPY_SEMANTIC(VTableBuilder);
76     NO_MOVE_SEMANTIC(VTableBuilder);
77 };
78 
79 }  // namespace ark
80 
81 #endif  // PANDA_RUNTIME_VTABLE_BUILDER_INTERFACE_H
82