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(std::string_view attribute)51 bool IsAnnotationRecordAttribute([[maybe_unused]] std::string_view attribute) const override 52 { 53 return false; 54 } 55 IsAnnotationIdAttribute(std::string_view attribute)56 bool IsAnnotationIdAttribute([[maybe_unused]] std::string_view attribute) const override 57 { 58 return false; 59 } 60 IsAnnotationElementNameAttribute(std::string_view attribute)61 bool IsAnnotationElementNameAttribute([[maybe_unused]] std::string_view attribute) const override 62 { 63 return false; 64 } 65 IsAnnotationElementTypeAttribute(std::string_view attribute)66 bool IsAnnotationElementTypeAttribute([[maybe_unused]] std::string_view attribute) const override 67 { 68 return false; 69 } 70 IsAnnotationElementArrayComponentTypeAttribute(std::string_view attribute)71 bool IsAnnotationElementArrayComponentTypeAttribute([[maybe_unused]] std::string_view attribute) const override 72 { 73 return false; 74 } 75 IsAnnotationElementValueAttribute(std::string_view attribute)76 bool IsAnnotationElementValueAttribute([[maybe_unused]] std::string_view attribute) const override 77 { 78 return false; 79 } 80 81 std::optional<Error> Validate(std::string_view attribute) const override; 82 83 std::optional<Error> Validate(std::string_view attribute, std::string_view value) const override; 84 85 void SetFlags(std::string_view attribute) override; 86 87 void SetFlags(std::string_view attribute, std::string_view value) override; 88 89 void RemoveFlags(std::string_view attribute) override; 90 91 void RemoveFlags(std::string_view attribute, std::string_view value) override; 92 }; 93 94 class FieldMetadata : public pandasm::FieldMetadata { 95 protected: IsAnnotationRecordAttribute(std::string_view attribute)96 bool IsAnnotationRecordAttribute([[maybe_unused]] std::string_view attribute) const override 97 { 98 return false; 99 } 100 IsAnnotationIdAttribute(std::string_view attribute)101 bool IsAnnotationIdAttribute([[maybe_unused]] std::string_view attribute) const override 102 { 103 return false; 104 } 105 IsAnnotationElementNameAttribute(std::string_view attribute)106 bool IsAnnotationElementNameAttribute([[maybe_unused]] std::string_view attribute) const override 107 { 108 return false; 109 } 110 IsAnnotationElementTypeAttribute(std::string_view attribute)111 bool IsAnnotationElementTypeAttribute([[maybe_unused]] std::string_view attribute) const override 112 { 113 return false; 114 } 115 IsAnnotationElementArrayComponentTypeAttribute(std::string_view attribute)116 bool IsAnnotationElementArrayComponentTypeAttribute([[maybe_unused]] std::string_view attribute) const override 117 { 118 return false; 119 } 120 IsAnnotationElementValueAttribute(std::string_view attribute)121 bool IsAnnotationElementValueAttribute([[maybe_unused]] std::string_view attribute) const override 122 { 123 return false; 124 } 125 126 std::optional<Error> Validate(std::string_view attribute) const override; 127 128 std::optional<Error> Validate(std::string_view attribute, std::string_view value) const override; 129 130 void SetFlags(std::string_view attribute) override; 131 132 void SetFlags(std::string_view attribute, std::string_view value) override; 133 134 void RemoveFlags(std::string_view attribute) override; 135 136 void RemoveFlags(std::string_view attribute, std::string_view value) override; 137 }; 138 139 class FunctionMetadata : public pandasm::FunctionMetadata { 140 protected: IsAnnotationRecordAttribute(std::string_view attribute)141 bool IsAnnotationRecordAttribute([[maybe_unused]] std::string_view attribute) const override 142 { 143 return false; 144 } 145 IsAnnotationIdAttribute(std::string_view attribute)146 bool IsAnnotationIdAttribute([[maybe_unused]] std::string_view attribute) const override 147 { 148 return false; 149 } 150 IsAnnotationElementNameAttribute(std::string_view attribute)151 bool IsAnnotationElementNameAttribute([[maybe_unused]] std::string_view attribute) const override 152 { 153 return false; 154 } 155 IsAnnotationElementTypeAttribute(std::string_view attribute)156 bool IsAnnotationElementTypeAttribute([[maybe_unused]] std::string_view attribute) const override 157 { 158 return false; 159 } 160 IsAnnotationElementArrayComponentTypeAttribute(std::string_view attribute)161 bool IsAnnotationElementArrayComponentTypeAttribute([[maybe_unused]] std::string_view attribute) const override 162 { 163 return false; 164 } 165 IsAnnotationElementValueAttribute(std::string_view attribute)166 bool IsAnnotationElementValueAttribute([[maybe_unused]] std::string_view attribute) const override 167 { 168 return false; 169 } 170 171 std::optional<Error> Validate(std::string_view attribute) const override; 172 173 std::optional<Error> Validate(std::string_view attribute, std::string_view value) const override; 174 175 void SetFlags(std::string_view attribute) override; 176 177 void SetFlags(std::string_view attribute, std::string_view value) override; 178 179 void RemoveFlags(std::string_view attribute) override; 180 181 void RemoveFlags(std::string_view attribute, std::string_view value) override; 182 }; 183 184 class ParamMetadata : public pandasm::ParamMetadata { 185 protected: IsAnnotationRecordAttribute(std::string_view attribute)186 bool IsAnnotationRecordAttribute([[maybe_unused]] std::string_view attribute) const override 187 { 188 return false; 189 } 190 IsAnnotationIdAttribute(std::string_view attribute)191 bool IsAnnotationIdAttribute([[maybe_unused]] std::string_view attribute) const override 192 { 193 return false; 194 } 195 IsAnnotationElementNameAttribute(std::string_view attribute)196 bool IsAnnotationElementNameAttribute([[maybe_unused]] std::string_view attribute) const override 197 { 198 return false; 199 } 200 IsAnnotationElementTypeAttribute(std::string_view attribute)201 bool IsAnnotationElementTypeAttribute([[maybe_unused]] std::string_view attribute) const override 202 { 203 return false; 204 } 205 IsAnnotationElementArrayComponentTypeAttribute(std::string_view attribute)206 bool IsAnnotationElementArrayComponentTypeAttribute([[maybe_unused]] std::string_view attribute) const override 207 { 208 return false; 209 } 210 IsAnnotationElementValueAttribute(std::string_view attribute)211 bool IsAnnotationElementValueAttribute([[maybe_unused]] std::string_view attribute) const override 212 { 213 return false; 214 } 215 216 std::optional<Error> Validate(std::string_view attribute) const override; 217 218 std::optional<Error> Validate(std::string_view attribute, std::string_view value) const override; 219 220 void SetFlags(std::string_view attribute) override; 221 222 void SetFlags(std::string_view attribute, std::string_view value) override; 223 224 void RemoveFlags(std::string_view attribute) override; 225 226 void RemoveFlags(std::string_view attribute, std::string_view value) override; 227 }; 228 229 } // namespace panda::pandasm::extensions::ecmascript 230 231 #endif // ASSEMBLER_EXTENSIONS_ECMASCRIPT_META_H 232