• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 
16 #ifndef PANDA_RUNTIME_INCLUDE_TOOLING_PT_LANG_EXTENSION_H_
17 #define PANDA_RUNTIME_INCLUDE_TOOLING_PT_LANG_EXTENSION_H_
18 
19 #include "libpandabase/macros.h"
20 #include "runtime/include/mem/panda_containers.h"
21 #include "runtime/include/tooling/pt_class.h"
22 #include "runtime/include/tooling/pt_object.h"
23 #include "runtime/include/tooling/pt_property.h"
24 #include "runtime/include/tooling/pt_value.h"
25 
26 namespace panda::tooling {
27 class PtLangExt {
28 public:
29     PtLangExt() = default;
30     virtual ~PtLangExt() = default;
31 
32     // PtValue API
33     virtual PtObject ValueToObject(PtValue value) const = 0;
34 
35     // PtClass API
36     virtual PtClass GetClass(PtObject object) const = 0;
37     virtual PtClass GetClass(PtProperty property) const = 0;
38     virtual void ReleaseClass(PtClass klass) const = 0;
39     virtual const char *GetClassDescriptor(PtClass klass) const = 0;
40 
41     // PtObject API
42     virtual PandaList<PtProperty> GetProperties(PtObject object) const = 0;
43     virtual PtProperty GetProperty(PtObject object, const char *propertyName) const = 0;
44     virtual bool AddProperty(PtObject object, const char *propertyName, PtValue value) const = 0;
45     virtual bool RemoveProperty(PtObject object, const char *propertyName) const = 0;
46 
47     // PtProperty API
48     virtual const char *GetPropertyName(PtProperty property) const = 0;
49     virtual PtValue GetPropertyValue(PtProperty property) const = 0;
50     virtual void SetPropertyPtValue(PtProperty property, PtValue value) const = 0;
51     virtual void ReleasePtValue(const PtValue *value) const = 0;
52 
53     NO_COPY_SEMANTIC(PtLangExt);
54     NO_MOVE_SEMANTIC(PtLangExt);
55 };
56 
57 class PtScopedValue {
58 public:
PtScopedValue(PtLangExt * ext,PtValue value)59     PtScopedValue(PtLangExt *ext, PtValue value) : ext_(ext), value_(value) {}
~PtScopedValue()60     ~PtScopedValue()
61     {
62         ext_->ReleasePtValue(&value_);
63     }
64 
GetValue()65     PtValue &GetValue()
66     {
67         return value_;
68     }
69 
70     NO_COPY_SEMANTIC(PtScopedValue);
71     NO_MOVE_SEMANTIC(PtScopedValue);
72 
73 private:
74     PtLangExt *ext_;
75     PtValue value_;
76 };
77 
78 }  // namespace panda::tooling
79 
80 #endif  // PANDA_RUNTIME_INCLUDE_TOOLING_PT_LANG_EXTENSION_H_
81