diff --git a/assembler/annotation.cpp b/assembler/annotation.cpp index b9f4621973..61bfa8590a 100644 --- a/assembler/annotation.cpp +++ b/assembler/annotation.cpp @@ -258,4 +258,15 @@ void AnnotationData::SetOrAddElementByIndex(size_t ele_idx, AnnotationElement && } elements_[ele_idx] = std::forward(element); } + +void AnnotationData::DeleteAnnotationElementByName(const std::string_view &annotation_elem_name) +{ + auto annotation_elem_iter = std::find_if(elements_.begin(), elements_.end(), + [&](pandasm::AnnotationElement &annotation_element) -> bool { + return annotation_element.GetName() == annotation_elem_name; + }); + if (annotation_elem_iter != elements_.end()) { + (void)elements_.erase(annotation_elem_iter); + } +} } // namespace panda::pandasm diff --git a/assembler/annotation.h b/assembler/annotation.h index 80e4ba915e..8e750b4a11 100644 --- a/assembler/annotation.h +++ b/assembler/annotation.h @@ -61,6 +61,8 @@ public: elements_.push_back(std::forward(element)); } + void DeleteAnnotationElementByName(const std::string_view &annotation_elem_name); + void SetOrAddElementByIndex(size_t ele_idx, AnnotationElement &&element); private: @@ -363,6 +365,9 @@ public: case '@': type = Type::METHOD_HANDLE; break; + case '#': + type = Type::LITERALARRAY; + break; case '0': default: type = Type::UNKNOWN; diff --git a/assembler/meta.h b/assembler/meta.h index 24735cd07b..4b501043c0 100644 --- a/assembler/meta.h +++ b/assembler/meta.h @@ -208,6 +208,17 @@ public: annotations_.insert(annotations_.end(), annotations.begin(), annotations.end()); } + void DeleteAnnotationElementByName(std::string_view annotation_name, std::string_view annotation_elem_name) + { + auto annotation_iter = std::find_if(annotations_.begin(), annotations_.end(), + [&](pandasm::AnnotationData &annotation) -> bool { + return annotation.GetName() == annotation_name; + }); + if (annotation_iter != annotations_.end()) { + annotation_iter->DeleteAnnotationElementByName(annotation_elem_name); + } + } + void DeleteAnnotationByName(const std::string_view &annotation_name) { auto annotation_iter = std::find_if(annotations_.begin(), annotations_.end(), @@ -219,6 +230,17 @@ public: } } + void AddAnnotationElementByName(const std::string_view &annotation_name, AnnotationElement &&element) + { + auto annotation_iter = std::find_if(annotations_.begin(), annotations_.end(), + [&](pandasm::AnnotationData &annotation) -> bool { + return annotation.GetName() == annotation_name; + }); + if (annotation_iter != annotations_.end()) { + annotation_iter->AddElement(std::move(element)); + } + } + void SetOrAddAnnotationElementByIndex(size_t anno_idx, size_t ele_idx, AnnotationElement &&element) { ASSERT(anno_idx < annotations_.size());