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 16 #ifndef PANDA_ASSEMBLER_EXTENSIONS_ETS_META_H_ 17 #define PANDA_ASSEMBLER_EXTENSIONS_ETS_META_H_ 18 19 #include "meta.h" 20 21 namespace ark::pandasm::extensions::ets { 22 23 class AnnotationHelper { 24 public: IsAnnotationRecordAttribute(std::string_view attribute)25 static bool IsAnnotationRecordAttribute(std::string_view attribute) 26 { 27 return attribute == "ets.annotation.class"; 28 } 29 IsAnnotationIdAttribute(std::string_view attribute)30 static bool IsAnnotationIdAttribute(std::string_view attribute) 31 { 32 return attribute == "ets.annotation.id"; 33 } 34 IsAnnotationElementTypeAttribute(std::string_view attribute)35 static bool IsAnnotationElementTypeAttribute(std::string_view attribute) 36 { 37 return attribute == "ets.annotation.element.type"; 38 } 39 IsAnnotationElementArrayComponentTypeAttribute(std::string_view attribute)40 static bool IsAnnotationElementArrayComponentTypeAttribute(std::string_view attribute) 41 { 42 return attribute == "ets.annotation.element.array.component.type"; 43 } 44 IsAnnotationElementNameAttribute(std::string_view attribute)45 static bool IsAnnotationElementNameAttribute(std::string_view attribute) 46 { 47 return attribute == "ets.annotation.element.name"; 48 } 49 IsAnnotationElementValueAttribute(std::string_view attribute)50 static bool IsAnnotationElementValueAttribute(std::string_view attribute) 51 { 52 return attribute == "ets.annotation.element.value"; 53 } 54 }; 55 56 class RecordMetadata : public pandasm::RecordMetadata { 57 public: GetBase()58 std::string GetBase() const override 59 { 60 auto base = GetAttributeValue("ets.extends"); 61 if (base) { 62 return base.value(); 63 } 64 65 return ""; 66 } 67 GetInterfaces()68 std::vector<std::string> GetInterfaces() const override 69 { 70 return GetAttributeValues("ets.implements"); 71 } 72 IsAnnotation()73 bool IsAnnotation() const override 74 { 75 return (GetAccessFlags() & ACC_ANNOTATION) != 0; 76 } 77 IsRuntimeAnnotation()78 bool IsRuntimeAnnotation() const override 79 { 80 auto type = GetAttributeValue("ets.annotation.type"); 81 if (type) { 82 return type.value() == "runtime"; 83 } 84 85 return false; 86 } 87 IsTypeAnnotation()88 bool IsTypeAnnotation() const override 89 { 90 auto type = GetAttributeValue("ets.annotation.type"); 91 if (type) { 92 return type.value() == "type"; 93 } 94 95 return false; 96 } 97 98 protected: IsAnnotationRecordAttribute(std::string_view attribute)99 bool IsAnnotationRecordAttribute([[maybe_unused]] std::string_view attribute) const override 100 { 101 return AnnotationHelper::IsAnnotationRecordAttribute(attribute); 102 } 103 IsAnnotationIdAttribute(std::string_view attribute)104 bool IsAnnotationIdAttribute([[maybe_unused]] std::string_view attribute) const override 105 { 106 return AnnotationHelper::IsAnnotationIdAttribute(attribute); 107 } 108 IsAnnotationElementNameAttribute(std::string_view attribute)109 bool IsAnnotationElementNameAttribute([[maybe_unused]] std::string_view attribute) const override 110 { 111 return AnnotationHelper::IsAnnotationElementNameAttribute(attribute); 112 } 113 IsAnnotationElementTypeAttribute(std::string_view attribute)114 bool IsAnnotationElementTypeAttribute([[maybe_unused]] std::string_view attribute) const override 115 { 116 return AnnotationHelper::IsAnnotationElementTypeAttribute(attribute); 117 } 118 IsAnnotationElementArrayComponentTypeAttribute(std::string_view attribute)119 bool IsAnnotationElementArrayComponentTypeAttribute([[maybe_unused]] std::string_view attribute) const override 120 { 121 return AnnotationHelper::IsAnnotationElementArrayComponentTypeAttribute(attribute); 122 } 123 IsAnnotationElementValueAttribute(std::string_view attribute)124 bool IsAnnotationElementValueAttribute([[maybe_unused]] std::string_view attribute) const override 125 { 126 return AnnotationHelper::IsAnnotationElementValueAttribute(attribute); 127 } 128 129 std::optional<Error> Validate(std::string_view attribute) const override; 130 131 std::optional<Error> Validate(std::string_view attribute, std::string_view value) const override; 132 133 void SetFlags(std::string_view attribute) override; 134 135 void SetFlags(std::string_view attribute, std::string_view value) override; 136 137 void RemoveFlags(std::string_view attribute) override; 138 139 void RemoveFlags(std::string_view attribute, std::string_view value) override; 140 }; 141 142 class FieldMetadata : public pandasm::FieldMetadata { 143 protected: IsAnnotationRecordAttribute(std::string_view attribute)144 bool IsAnnotationRecordAttribute([[maybe_unused]] std::string_view attribute) const override 145 { 146 return AnnotationHelper::IsAnnotationRecordAttribute(attribute); 147 } 148 IsAnnotationIdAttribute(std::string_view attribute)149 bool IsAnnotationIdAttribute([[maybe_unused]] std::string_view attribute) const override 150 { 151 return AnnotationHelper::IsAnnotationIdAttribute(attribute); 152 } 153 IsAnnotationElementNameAttribute(std::string_view attribute)154 bool IsAnnotationElementNameAttribute([[maybe_unused]] std::string_view attribute) const override 155 { 156 return AnnotationHelper::IsAnnotationElementNameAttribute(attribute); 157 } 158 IsAnnotationElementTypeAttribute(std::string_view attribute)159 bool IsAnnotationElementTypeAttribute([[maybe_unused]] std::string_view attribute) const override 160 { 161 return AnnotationHelper::IsAnnotationElementTypeAttribute(attribute); 162 } 163 IsAnnotationElementArrayComponentTypeAttribute(std::string_view attribute)164 bool IsAnnotationElementArrayComponentTypeAttribute([[maybe_unused]] std::string_view attribute) const override 165 { 166 return AnnotationHelper::IsAnnotationElementArrayComponentTypeAttribute(attribute); 167 } 168 IsAnnotationElementValueAttribute(std::string_view attribute)169 bool IsAnnotationElementValueAttribute([[maybe_unused]] std::string_view attribute) const override 170 { 171 return AnnotationHelper::IsAnnotationElementValueAttribute(attribute); 172 } 173 174 std::optional<Error> Validate(std::string_view attribute) const override; 175 176 std::optional<Error> Validate(std::string_view attribute, std::string_view value) const override; 177 178 void SetFlags(std::string_view attribute) override; 179 180 void SetFlags(std::string_view attribute, std::string_view value) override; 181 182 void RemoveFlags(std::string_view attribute) override; 183 184 void RemoveFlags(std::string_view attribute, std::string_view value) override; 185 }; 186 187 class FunctionMetadata : public pandasm::FunctionMetadata { 188 protected: IsAnnotationRecordAttribute(std::string_view attribute)189 bool IsAnnotationRecordAttribute([[maybe_unused]] std::string_view attribute) const override 190 { 191 return AnnotationHelper::IsAnnotationRecordAttribute(attribute); 192 } 193 IsAnnotationIdAttribute(std::string_view attribute)194 bool IsAnnotationIdAttribute([[maybe_unused]] std::string_view attribute) const override 195 { 196 return AnnotationHelper::IsAnnotationIdAttribute(attribute); 197 } 198 IsAnnotationElementNameAttribute(std::string_view attribute)199 bool IsAnnotationElementNameAttribute([[maybe_unused]] std::string_view attribute) const override 200 { 201 return AnnotationHelper::IsAnnotationElementNameAttribute(attribute); 202 } 203 IsAnnotationElementTypeAttribute(std::string_view attribute)204 bool IsAnnotationElementTypeAttribute([[maybe_unused]] std::string_view attribute) const override 205 { 206 return AnnotationHelper::IsAnnotationElementTypeAttribute(attribute); 207 } 208 IsAnnotationElementArrayComponentTypeAttribute(std::string_view attribute)209 bool IsAnnotationElementArrayComponentTypeAttribute([[maybe_unused]] std::string_view attribute) const override 210 { 211 return AnnotationHelper::IsAnnotationElementArrayComponentTypeAttribute(attribute); 212 } 213 IsAnnotationElementValueAttribute(std::string_view attribute)214 bool IsAnnotationElementValueAttribute([[maybe_unused]] std::string_view attribute) const override 215 { 216 return AnnotationHelper::IsAnnotationElementValueAttribute(attribute); 217 } 218 219 std::optional<Error> Validate(std::string_view attribute) const override; 220 221 std::optional<Error> Validate(std::string_view attribute, std::string_view value) const override; 222 223 void SetFlags(std::string_view attribute) override; 224 225 void SetFlags(std::string_view attribute, std::string_view value) override; 226 227 void RemoveFlags(std::string_view attribute) override; 228 229 void RemoveFlags(std::string_view attribute, std::string_view value) override; 230 }; 231 232 class ParamMetadata : public pandasm::ParamMetadata { 233 protected: IsAnnotationRecordAttribute(std::string_view attribute)234 bool IsAnnotationRecordAttribute([[maybe_unused]] std::string_view attribute) const override 235 { 236 return AnnotationHelper::IsAnnotationRecordAttribute(attribute); 237 } 238 IsAnnotationIdAttribute(std::string_view attribute)239 bool IsAnnotationIdAttribute([[maybe_unused]] std::string_view attribute) const override 240 { 241 return AnnotationHelper::IsAnnotationIdAttribute(attribute); 242 } 243 IsAnnotationElementNameAttribute(std::string_view attribute)244 bool IsAnnotationElementNameAttribute([[maybe_unused]] std::string_view attribute) const override 245 { 246 return AnnotationHelper::IsAnnotationElementNameAttribute(attribute); 247 } 248 IsAnnotationElementTypeAttribute(std::string_view attribute)249 bool IsAnnotationElementTypeAttribute([[maybe_unused]] std::string_view attribute) const override 250 { 251 return AnnotationHelper::IsAnnotationElementTypeAttribute(attribute); 252 } 253 IsAnnotationElementArrayComponentTypeAttribute(std::string_view attribute)254 bool IsAnnotationElementArrayComponentTypeAttribute([[maybe_unused]] std::string_view attribute) const override 255 { 256 return AnnotationHelper::IsAnnotationElementArrayComponentTypeAttribute(attribute); 257 } 258 IsAnnotationElementValueAttribute(std::string_view attribute)259 bool IsAnnotationElementValueAttribute([[maybe_unused]] std::string_view attribute) const override 260 { 261 return AnnotationHelper::IsAnnotationElementValueAttribute(attribute); 262 } 263 264 std::optional<Error> Validate(std::string_view attribute) const override; 265 266 std::optional<Error> Validate(std::string_view attribute, std::string_view value) const override; 267 268 void SetFlags(std::string_view attribute) override; 269 270 void SetFlags(std::string_view attribute, std::string_view value) override; 271 272 void RemoveFlags(std::string_view attribute) override; 273 274 void RemoveFlags(std::string_view attribute, std::string_view value) override; 275 }; 276 277 } // namespace ark::pandasm::extensions::ets 278 279 #endif // PANDA_ASSEMBLER_EXTENSIONS_ETS_META_H_ 280