1 /**
2 * Copyright (c) 2021-2022 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 #include "ecmascript_meta.h"
17
18 namespace panda::pandasm::extensions::ecmascript {
19
Validate(const std::string_view & attribute) const20 std::optional<Metadata::Error> RecordMetadata::Validate(const std::string_view &attribute) const
21 {
22 if (attribute == "ecmascript.annotation") {
23 if (HasAttribute(attribute)) {
24 return Error("Attribute 'ecmascript.annotation' already defined",
25 Error::Type::MULTIPLE_ATTRIBUTE);
26 }
27 return {};
28 }
29
30 if (attribute == "ecmascript.extends") {
31 return Error("Attribute 'ecmascript.extends' must have a value",
32 Error::Type::MISSING_VALUE);
33 }
34
35 return pandasm::RecordMetadata::Validate(attribute);
36 }
37
Validate(const std::string_view & attribute,const std::string_view & value) const38 std::optional<Metadata::Error> RecordMetadata::Validate(const std::string_view &attribute,
39 const std::string_view &value) const
40 {
41 if (attribute == "ecmascript.extends") {
42 if (HasAttribute(attribute)) {
43 return Error("Attribute 'ecmascript.extends' already defined",
44 Error::Type::MULTIPLE_ATTRIBUTE);
45 }
46 return {};
47 }
48
49 if (attribute == "ecmascript.annotation") {
50 return Error("Attribute 'ecmascript.annotation' must not have a value",
51 Error::Type::UNEXPECTED_VALUE);
52 }
53
54 return pandasm::RecordMetadata::Validate(attribute, value);
55 }
56
Validate(const std::string_view & attribute) const57 std::optional<Metadata::Error> FieldMetadata::Validate(const std::string_view &attribute) const
58 {
59 return pandasm::FieldMetadata::Validate(attribute);
60 }
61
Validate(const std::string_view & attribute,const std::string_view & value) const62 std::optional<Metadata::Error> FieldMetadata::Validate(const std::string_view &attribute,
63 const std::string_view &value) const
64 {
65 return pandasm::FieldMetadata::Validate(attribute, value);
66 }
67
Validate(const std::string_view & attribute) const68 std::optional<Metadata::Error> FunctionMetadata::Validate(const std::string_view &attribute) const
69 {
70 return pandasm::FunctionMetadata::Validate(attribute);
71 }
72
Validate(const std::string_view & attribute,const std::string_view & value) const73 std::optional<Metadata::Error> FunctionMetadata::Validate(const std::string_view &attribute,
74 const std::string_view &value) const
75 {
76 return pandasm::FunctionMetadata::Validate(attribute, value);
77 }
78
Validate(const std::string_view & attribute) const79 std::optional<Metadata::Error> ParamMetadata::Validate(const std::string_view &attribute) const
80 {
81 return pandasm::ParamMetadata::Validate(attribute);
82 }
83
Validate(const std::string_view & attribute,const std::string_view & value) const84 std::optional<Metadata::Error> ParamMetadata::Validate(const std::string_view &attribute,
85 const std::string_view &value) const
86 {
87 return pandasm::ParamMetadata::Validate(attribute, value);
88 }
89
SetFlags(const std::string_view & attribute)90 void RecordMetadata::SetFlags(const std::string_view &attribute)
91 {
92 if (attribute == "ecmascript.annotation") {
93 SetAccessFlags(GetAccessFlags() | ACC_ANNOTATION);
94 }
95 pandasm::RecordMetadata::SetFlags(attribute);
96 }
97
SetFlags(const std::string_view & attribute,const std::string_view & value)98 void RecordMetadata::SetFlags(const std::string_view &attribute, const std::string_view &value)
99 {
100 pandasm::RecordMetadata::SetFlags(attribute, value);
101 }
102
RemoveFlags(const std::string_view & attribute)103 void RecordMetadata::RemoveFlags(const std::string_view &attribute)
104 {
105 if (attribute == "ecmascript.annotation") {
106 if ((GetAccessFlags() & ACC_ANNOTATION) != 0) {
107 SetAccessFlags(GetAccessFlags() ^ (ACC_ANNOTATION));
108 }
109 }
110 pandasm::RecordMetadata::RemoveFlags(attribute);
111 }
112
RemoveFlags(const std::string_view & attribute,const std::string_view & value)113 void RecordMetadata::RemoveFlags(const std::string_view &attribute, const std::string_view &value)
114 {
115 pandasm::RecordMetadata::RemoveFlags(attribute, value);
116 }
117
SetFlags(const std::string_view & attribute)118 void FieldMetadata::SetFlags(const std::string_view &attribute)
119 {
120 pandasm::FieldMetadata::SetFlags(attribute);
121 }
122
SetFlags(const std::string_view & attribute,const std::string_view & value)123 void FieldMetadata::SetFlags(const std::string_view &attribute, const std::string_view &value)
124 {
125 pandasm::FieldMetadata::SetFlags(attribute, value);
126 }
127
RemoveFlags(const std::string_view & attribute)128 void FieldMetadata::RemoveFlags(const std::string_view &attribute)
129 {
130 pandasm::FieldMetadata::RemoveFlags(attribute);
131 }
132
RemoveFlags(const std::string_view & attribute,const std::string_view & value)133 void FieldMetadata::RemoveFlags(const std::string_view &attribute, const std::string_view &value)
134 {
135 pandasm::FieldMetadata::RemoveFlags(attribute, value);
136 }
137
SetFlags(const std::string_view & attribute)138 void FunctionMetadata::SetFlags(const std::string_view &attribute)
139 {
140 pandasm::FunctionMetadata::SetFlags(attribute);
141 }
142
SetFlags(const std::string_view & attribute,const std::string_view & value)143 void FunctionMetadata::SetFlags(const std::string_view &attribute, const std::string_view &value)
144 {
145 pandasm::FunctionMetadata::SetFlags(attribute, value);
146 }
147
RemoveFlags(const std::string_view & attribute)148 void FunctionMetadata::RemoveFlags(const std::string_view &attribute)
149 {
150 pandasm::FunctionMetadata::RemoveFlags(attribute);
151 }
152
RemoveFlags(const std::string_view & attribute,const std::string_view & value)153 void FunctionMetadata::RemoveFlags(const std::string_view &attribute, const std::string_view &value)
154 {
155 pandasm::FunctionMetadata::RemoveFlags(attribute, value);
156 }
157
SetFlags(const std::string_view & attribute)158 void ParamMetadata::SetFlags(const std::string_view &attribute)
159 {
160 pandasm::ParamMetadata::SetFlags(attribute);
161 }
162
SetFlags(const std::string_view & attribute,const std::string_view & value)163 void ParamMetadata::SetFlags(const std::string_view &attribute, const std::string_view &value)
164 {
165 pandasm::ParamMetadata::SetFlags(attribute, value);
166 }
167
RemoveFlags(const std::string_view & attribute)168 void ParamMetadata::RemoveFlags(const std::string_view &attribute)
169 {
170 pandasm::ParamMetadata::RemoveFlags(attribute);
171 }
172
RemoveFlags(const std::string_view & attribute,const std::string_view & value)173 void ParamMetadata::RemoveFlags(const std::string_view &attribute, const std::string_view &value)
174 {
175 pandasm::ParamMetadata::RemoveFlags(attribute, value);
176 }
177
178 } // namespace panda::pandasm::extensions::ecmascript
179