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