mirror of
https://gitee.com/openharmony/arkcompiler_runtime_core
synced 2024-11-27 08:50:45 +00:00
Fix gen abc in multi-thread failed
Issue:https://gitee.com/open_harmony/dashboard?issue_id=I6LQWC Signed-off-by: chenqy930 <chenqiuyao@huawei.com> Change-Id: Ib5223dd7f0276f2a1776336bb4bd74a071bf4635
This commit is contained in:
parent
3069e58811
commit
b1a00b33c4
@ -218,7 +218,7 @@ ScalarValueItem *AsmEmitter::CreateScalarStringValueItem(ItemContainer *containe
|
||||
{
|
||||
auto *string_item = container->GetOrCreateStringItem(value->GetAsScalar()->GetValue<std::string>());
|
||||
if (out != nullptr) {
|
||||
out->emplace_back(string_item);
|
||||
out->emplace_back(string_item, container);
|
||||
return &out->back();
|
||||
}
|
||||
|
||||
@ -245,7 +245,7 @@ ScalarValueItem *AsmEmitter::CreateScalarRecordValueItem(
|
||||
}
|
||||
|
||||
if (out != nullptr) {
|
||||
out->emplace_back(class_item);
|
||||
out->emplace_back(class_item, container);
|
||||
return &out->back();
|
||||
}
|
||||
|
||||
@ -268,7 +268,7 @@ ScalarValueItem *AsmEmitter::CreateScalarMethodValueItem(
|
||||
|
||||
auto *method_item = it->second;
|
||||
if (out != nullptr) {
|
||||
out->emplace_back(method_item);
|
||||
out->emplace_back(method_item, container);
|
||||
return &out->back();
|
||||
}
|
||||
|
||||
@ -285,7 +285,7 @@ ScalarValueItem *AsmEmitter::CreateScalarLiteralArrayItem(
|
||||
ASSERT(it != literalarrays.end());
|
||||
auto *literalarray_item = it->second;
|
||||
if (out != nullptr) {
|
||||
out->emplace_back(literalarray_item);
|
||||
out->emplace_back(literalarray_item, container);
|
||||
return &out->back();
|
||||
}
|
||||
|
||||
@ -305,7 +305,7 @@ ScalarValueItem *AsmEmitter::CreateScalarEnumValueItem(ItemContainer *container,
|
||||
|
||||
auto *field_item = it->second;
|
||||
if (out != nullptr) {
|
||||
out->emplace_back(field_item);
|
||||
out->emplace_back(field_item, container);
|
||||
return &out->back();
|
||||
}
|
||||
|
||||
@ -324,7 +324,7 @@ ScalarValueItem *AsmEmitter::CreateScalarAnnotationValueItem(
|
||||
}
|
||||
|
||||
if (out != nullptr) {
|
||||
out->emplace_back(annotation_item);
|
||||
out->emplace_back(annotation_item, container);
|
||||
return &out->back();
|
||||
}
|
||||
|
||||
|
@ -164,7 +164,7 @@ private:
|
||||
static_assert(std::is_arithmetic<PrimType>::value);
|
||||
auto v = value->GetAsScalar()->GetValue<PrimType>();
|
||||
if (out != nullptr) {
|
||||
out->emplace_back(v);
|
||||
out->emplace_back(v, container);
|
||||
return &out->back();
|
||||
}
|
||||
|
||||
|
@ -174,12 +174,12 @@ ItemContainer::ItemContainer()
|
||||
|
||||
ClassItem *ItemContainer::GetOrCreateClassItem(const std::string &str)
|
||||
{
|
||||
return GetOrInsert<ClassItem>(class_map_, items_, items_end_, str, false, str);
|
||||
return GetOrInsert<ClassItem>(class_map_, items_, items_end_, str, false, str, this);
|
||||
}
|
||||
|
||||
ForeignClassItem *ItemContainer::GetOrCreateForeignClassItem(const std::string &str)
|
||||
{
|
||||
return GetOrInsert<ForeignClassItem>(class_map_, foreign_items_, foreign_items_.end(), str, true, str);
|
||||
return GetOrInsert<ForeignClassItem>(class_map_, foreign_items_, foreign_items_.end(), str, true, str, this);
|
||||
}
|
||||
|
||||
StringItem *ItemContainer::GetOrCreateStringItem(const std::string &str)
|
||||
@ -189,43 +189,43 @@ StringItem *ItemContainer::GetOrCreateStringItem(const std::string &str)
|
||||
return it->second->GetNameItem();
|
||||
}
|
||||
|
||||
return GetOrInsert<StringItem>(string_map_, items_, items_end_, str, false, str);
|
||||
return GetOrInsert<StringItem>(string_map_, items_, items_end_, str, false, str, this);
|
||||
}
|
||||
|
||||
LiteralArrayItem *ItemContainer::GetOrCreateLiteralArrayItem(const std::string &id)
|
||||
{
|
||||
return GetOrInsert<LiteralArrayItem>(literalarray_map_, items_, items_end_, id, false);
|
||||
return GetOrInsert<LiteralArrayItem>(literalarray_map_, items_, items_end_, id, false, this);
|
||||
}
|
||||
|
||||
ScalarValueItem *ItemContainer::GetOrCreateIntegerValueItem(uint32_t v)
|
||||
{
|
||||
return GetOrInsert<ScalarValueItem>(int_value_map_, items_, items_end_, v, false, v);
|
||||
return GetOrInsert<ScalarValueItem>(int_value_map_, items_, items_end_, v, false, v, this);
|
||||
}
|
||||
|
||||
ScalarValueItem *ItemContainer::GetOrCreateLongValueItem(uint64_t v)
|
||||
{
|
||||
return GetOrInsert<ScalarValueItem>(long_value_map_, items_, items_end_, v, false, v);
|
||||
return GetOrInsert<ScalarValueItem>(long_value_map_, items_, items_end_, v, false, v, this);
|
||||
}
|
||||
|
||||
ScalarValueItem *ItemContainer::GetOrCreateFloatValueItem(float v)
|
||||
{
|
||||
return GetOrInsert<ScalarValueItem>(float_value_map_, items_, items_end_, bit_cast<uint32_t>(v), false, v);
|
||||
return GetOrInsert<ScalarValueItem>(float_value_map_, items_, items_end_, bit_cast<uint32_t>(v), false, v, this);
|
||||
}
|
||||
|
||||
ScalarValueItem *ItemContainer::GetOrCreateDoubleValueItem(double v)
|
||||
{
|
||||
return GetOrInsert<ScalarValueItem>(double_value_map_, items_, items_end_, bit_cast<uint64_t>(v), false, v);
|
||||
return GetOrInsert<ScalarValueItem>(double_value_map_, items_, items_end_, bit_cast<uint64_t>(v), false, v, this);
|
||||
}
|
||||
|
||||
ScalarValueItem *ItemContainer::GetOrCreateIdValueItem(BaseItem *v)
|
||||
{
|
||||
return GetOrInsert<ScalarValueItem>(id_value_map_, items_, items_end_, v, false, v);
|
||||
return GetOrInsert<ScalarValueItem>(id_value_map_, items_, items_end_, v, false, v, this);
|
||||
}
|
||||
|
||||
ProtoItem *ItemContainer::GetOrCreateProtoItem(TypeItem *ret_type, const std::vector<MethodParamItem> ¶ms)
|
||||
{
|
||||
ProtoKey key(ret_type, params);
|
||||
return GetOrInsert<ProtoItem>(proto_map_, items_, items_end_, key, false, ret_type, params);
|
||||
return GetOrInsert<ProtoItem>(proto_map_, items_, items_end_, key, false, ret_type, params, this);
|
||||
}
|
||||
|
||||
PrimitiveTypeItem *ItemContainer::GetOrCreatePrimitiveTypeItem(Type type)
|
||||
@ -235,12 +235,12 @@ PrimitiveTypeItem *ItemContainer::GetOrCreatePrimitiveTypeItem(Type type)
|
||||
|
||||
PrimitiveTypeItem *ItemContainer::GetOrCreatePrimitiveTypeItem(Type::TypeId type)
|
||||
{
|
||||
return GetOrInsert<PrimitiveTypeItem>(primitive_type_map_, items_, items_end_, type, false, type);
|
||||
return GetOrInsert<PrimitiveTypeItem>(primitive_type_map_, items_, items_end_, type, false, type, this);
|
||||
}
|
||||
|
||||
LineNumberProgramItem *ItemContainer::CreateLineNumberProgramItem()
|
||||
{
|
||||
auto it = items_.insert(debug_items_end_, std::make_unique<LineNumberProgramItem>());
|
||||
auto it = items_.insert(debug_items_end_, std::make_unique<LineNumberProgramItem>(this));
|
||||
auto *item = static_cast<LineNumberProgramItem *>(it->get());
|
||||
[[maybe_unused]] auto res = line_number_program_index_item_.Add(item);
|
||||
ASSERT(res);
|
||||
|
@ -86,7 +86,15 @@ public:
|
||||
static_assert(!std::is_same_v<T, MethodItem>, "Use ClassItem instance to create MethodItem");
|
||||
static_assert(!std::is_same_v<T, FieldItem>, "Use ClassItem instance to create FieldItem");
|
||||
|
||||
auto ptr = std::make_unique<T>(std::forward<Args>(args)...);
|
||||
std::unique_ptr<T> ptr = nullptr;
|
||||
if constexpr (std::is_same_v<T, ForeignFieldItem> || std::is_same_v<T, ForeignMethodItem> ||
|
||||
std::is_same_v<T, ScalarValueItem> || std::is_same_v<T, ArrayValueItem> ||
|
||||
std::is_same_v<T, LiteralArrayItem>) {
|
||||
ptr = std::make_unique<T>(std::forward<Args>(args)..., this);
|
||||
} else {
|
||||
ptr = std::make_unique<T>(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
auto ret = ptr.get();
|
||||
if (ptr->IsForeign()) {
|
||||
foreign_items_.emplace_back(std::move(ptr));
|
||||
@ -186,6 +194,16 @@ public:
|
||||
void DeduplicateDebugInfo(MethodItem *method, ItemDeduper *debug_info_deduper,
|
||||
ItemDeduper *line_number_program_deduper);
|
||||
|
||||
size_t GetIndexedItemCount() const
|
||||
{
|
||||
return indexed_item_count_;
|
||||
}
|
||||
|
||||
void IncIndexedItemCount()
|
||||
{
|
||||
indexed_item_count_++;
|
||||
}
|
||||
|
||||
private:
|
||||
template <class T>
|
||||
auto GetInsertPosition()
|
||||
@ -551,6 +569,7 @@ private:
|
||||
std::list<std::unique_ptr<BaseItem>>::iterator debug_items_end_;
|
||||
|
||||
BaseItem *end_;
|
||||
size_t indexed_item_count_ {0};
|
||||
};
|
||||
|
||||
} // namespace panda::panda_file
|
||||
|
@ -14,6 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "file_items.h"
|
||||
#include "file_item_container.h"
|
||||
#include "macros.h"
|
||||
#include "utils/bit_utils.h"
|
||||
#include "utils/leb128.h"
|
||||
@ -23,8 +24,6 @@
|
||||
|
||||
namespace panda::panda_file {
|
||||
|
||||
size_t IndexedItem::indexed_item_count_ = 0;
|
||||
|
||||
bool IsDynamicLanguage(panda::panda_file::SourceLang lang)
|
||||
{
|
||||
return lang == panda::panda_file::SourceLang::ECMASCRIPT;
|
||||
@ -182,7 +181,15 @@ std::string BaseItem::GetName() const
|
||||
return ItemTypeToString(GetItemType());
|
||||
}
|
||||
|
||||
StringItem::StringItem(std::string str) : str_(std::move(str))
|
||||
IndexedItem::IndexedItem(ItemContainer *container)
|
||||
{
|
||||
if (container != nullptr) {
|
||||
item_global_index_ = container->GetIndexedItemCount();
|
||||
container->IncIndexedItemCount();
|
||||
}
|
||||
}
|
||||
|
||||
StringItem::StringItem(std::string str, ItemContainer *container) : IndexedItem(container), str_(std::move(str))
|
||||
{
|
||||
str_.push_back(0);
|
||||
utf16_length_ = utf::MUtf8ToUtf16Size(utf::CStringAsMutf8(str_.data()));
|
||||
@ -196,8 +203,8 @@ StringItem::StringItem(std::string str) : str_(std::move(str))
|
||||
}
|
||||
}
|
||||
|
||||
StringItem::StringItem(File::StringData data)
|
||||
: str_(reinterpret_cast<const char *>(data.data)), utf16_length_(data.utf16_length)
|
||||
StringItem::StringItem(File::StringData data, ItemContainer *container)
|
||||
: IndexedItem(container), str_(reinterpret_cast<const char *>(data.data)), utf16_length_(data.utf16_length)
|
||||
{
|
||||
}
|
||||
|
||||
@ -485,7 +492,8 @@ bool ParamAnnotationsItem::Write(Writer *writer)
|
||||
return true;
|
||||
}
|
||||
|
||||
ProtoItem::ProtoItem(TypeItem *ret_type, const std::vector<MethodParamItem> ¶ms)
|
||||
ProtoItem::ProtoItem(TypeItem *ret_type, const std::vector<MethodParamItem> ¶ms, ItemContainer *itemContainer)
|
||||
: IndexedItem(itemContainer)
|
||||
{
|
||||
size_t n = 0;
|
||||
shorty_.push_back(0);
|
||||
@ -537,8 +545,9 @@ bool ProtoItem::Write(Writer *writer)
|
||||
return true;
|
||||
}
|
||||
|
||||
BaseMethodItem::BaseMethodItem(BaseClassItem *cls, StringItem *name, ProtoItem *proto, uint32_t access_flags)
|
||||
: class_(cls), name_(name), proto_(proto), access_flags_(access_flags)
|
||||
BaseMethodItem::BaseMethodItem(BaseClassItem *cls, StringItem *name, ProtoItem *proto, uint32_t access_flags,
|
||||
ItemContainer *container)
|
||||
: IndexedItem(container), class_(cls), name_(name), proto_(proto), access_flags_(access_flags)
|
||||
{
|
||||
AddIndexDependency(cls);
|
||||
AddIndexDependency(proto);
|
||||
@ -576,8 +585,8 @@ bool BaseMethodItem::Write(Writer *writer)
|
||||
}
|
||||
|
||||
MethodItem::MethodItem(ClassItem *cls, StringItem *name, ProtoItem *proto, uint32_t access_flags,
|
||||
std::vector<MethodParamItem> params)
|
||||
: BaseMethodItem(cls, name, proto, access_flags),
|
||||
std::vector<MethodParamItem> params, ItemContainer *container)
|
||||
: BaseMethodItem(cls, name, proto, access_flags, container),
|
||||
params_(std::move(params)),
|
||||
source_lang_(SourceLang::PANDA_ASSEMBLY),
|
||||
code_(nullptr),
|
||||
@ -1225,8 +1234,8 @@ bool LiteralArrayItem::Write(Writer *writer)
|
||||
return true;
|
||||
}
|
||||
|
||||
BaseFieldItem::BaseFieldItem(BaseClassItem *cls, StringItem *name, TypeItem *type)
|
||||
: class_(cls), name_(name), type_(type)
|
||||
BaseFieldItem::BaseFieldItem(BaseClassItem *cls, StringItem *name, TypeItem *type, ItemContainer *container)
|
||||
: IndexedItem(container), class_(cls), name_(name), type_(type)
|
||||
{
|
||||
AddIndexDependency(cls);
|
||||
AddIndexDependency(type);
|
||||
@ -1255,8 +1264,8 @@ bool BaseFieldItem::Write(Writer *writer)
|
||||
return writer->Write(name_->GetOffset());
|
||||
}
|
||||
|
||||
FieldItem::FieldItem(ClassItem *cls, StringItem *name, TypeItem *type, uint32_t access_flags)
|
||||
: BaseFieldItem(cls, name, type), access_flags_(access_flags), value_(nullptr)
|
||||
FieldItem::FieldItem(ClassItem *cls, StringItem *name, TypeItem *type, uint32_t access_flags, ItemContainer *container)
|
||||
: BaseFieldItem(cls, name, type, container), access_flags_(access_flags), value_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -157,6 +157,7 @@ enum class IndexType {
|
||||
static constexpr size_t INDEX_COUNT_16 = static_cast<size_t>(IndexType::LAST_16) + 1;
|
||||
|
||||
class IndexedItem;
|
||||
class ItemContainer;
|
||||
|
||||
class BaseItem {
|
||||
public:
|
||||
@ -279,10 +280,7 @@ private:
|
||||
|
||||
class IndexedItem : public BaseItem {
|
||||
public:
|
||||
IndexedItem()
|
||||
{
|
||||
item_index_ = indexed_item_count_++;
|
||||
}
|
||||
explicit IndexedItem(ItemContainer *itemContainer);
|
||||
|
||||
uint32_t GetIndex(const BaseItem *item) const
|
||||
{
|
||||
@ -330,7 +328,7 @@ public:
|
||||
|
||||
size_t GetIndexedItemCount() const
|
||||
{
|
||||
return item_index_;
|
||||
return item_global_index_;
|
||||
}
|
||||
|
||||
private:
|
||||
@ -372,15 +370,14 @@ private:
|
||||
|
||||
std::vector<Index> indexes_;
|
||||
size_t ref_count_ {1};
|
||||
size_t item_index_ {0};
|
||||
static size_t indexed_item_count_;
|
||||
size_t item_global_index_ {0};
|
||||
};
|
||||
|
||||
class TypeItem : public IndexedItem {
|
||||
public:
|
||||
explicit TypeItem(Type type) : type_(type) {}
|
||||
explicit TypeItem(Type type, ItemContainer *container) : IndexedItem(container), type_(type) {}
|
||||
|
||||
explicit TypeItem(Type::TypeId type_id) : type_(type_id) {}
|
||||
explicit TypeItem(Type::TypeId type_id, ItemContainer *container) : IndexedItem(container), type_(type_id) {}
|
||||
|
||||
~TypeItem() override = default;
|
||||
|
||||
@ -403,9 +400,9 @@ private:
|
||||
|
||||
class PrimitiveTypeItem : public TypeItem {
|
||||
public:
|
||||
explicit PrimitiveTypeItem(Type type) : PrimitiveTypeItem(type.GetId()) {}
|
||||
explicit PrimitiveTypeItem(Type type, ItemContainer *container) : PrimitiveTypeItem(type.GetId(), container) {}
|
||||
|
||||
explicit PrimitiveTypeItem(Type::TypeId type_id) : TypeItem(type_id)
|
||||
explicit PrimitiveTypeItem(Type::TypeId type_id, ItemContainer *container) : TypeItem(type_id, container)
|
||||
{
|
||||
ASSERT(GetType().IsPrimitive());
|
||||
SetNeedsEmit(false);
|
||||
@ -435,9 +432,9 @@ public:
|
||||
|
||||
class StringItem : public IndexedItem {
|
||||
public:
|
||||
explicit StringItem(std::string str);
|
||||
explicit StringItem(std::string str, ItemContainer *container);
|
||||
|
||||
explicit StringItem(File::StringData data);
|
||||
explicit StringItem(File::StringData data, ItemContainer *container);
|
||||
|
||||
~StringItem() override = default;
|
||||
|
||||
@ -498,7 +495,7 @@ public:
|
||||
DEFAULT_COPY_SEMANTIC(BaseFieldItem);
|
||||
|
||||
protected:
|
||||
BaseFieldItem(BaseClassItem *cls, StringItem *name, TypeItem *type);
|
||||
BaseFieldItem(BaseClassItem *cls, StringItem *name, TypeItem *type, ItemContainer *container);
|
||||
|
||||
size_t CalculateSize() const override;
|
||||
|
||||
@ -512,7 +509,7 @@ private:
|
||||
|
||||
class FieldItem : public BaseFieldItem {
|
||||
public:
|
||||
FieldItem(ClassItem *cls, StringItem *name, TypeItem *type, uint32_t access_flags);
|
||||
FieldItem(ClassItem *cls, StringItem *name, TypeItem *type, uint32_t access_flags, ItemContainer *container);
|
||||
|
||||
~FieldItem() override = default;
|
||||
|
||||
@ -610,6 +607,8 @@ public:
|
||||
static constexpr int32_t LINE_RANGE = 15;
|
||||
static constexpr int32_t LINE_BASE = -4;
|
||||
|
||||
explicit LineNumberProgramItem(ItemContainer *container) : IndexedItem(container) {}
|
||||
|
||||
void EmitEnd();
|
||||
|
||||
void EmitAdvancePc(std::vector<uint8_t> *constant_pool, uint32_t value);
|
||||
@ -773,7 +772,8 @@ public:
|
||||
DEFAULT_COPY_SEMANTIC(BaseMethodItem);
|
||||
|
||||
protected:
|
||||
BaseMethodItem(BaseClassItem *cls, StringItem *name, ProtoItem *proto, uint32_t access_flags);
|
||||
BaseMethodItem(BaseClassItem *cls, StringItem *name, ProtoItem *proto, uint32_t access_flags,
|
||||
ItemContainer *container);
|
||||
|
||||
size_t CalculateSize() const override;
|
||||
|
||||
@ -854,7 +854,7 @@ class BaseClassItem;
|
||||
class MethodItem : public BaseMethodItem {
|
||||
public:
|
||||
MethodItem(ClassItem *cls, StringItem *name, ProtoItem *proto, uint32_t access_flags,
|
||||
std::vector<MethodParamItem> params);
|
||||
std::vector<MethodParamItem> params, ItemContainer *container);
|
||||
|
||||
~MethodItem() override = default;
|
||||
|
||||
@ -990,7 +990,8 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
explicit BaseClassItem(const std::string &name) : TypeItem(Type::TypeId::REFERENCE), name_(name) {}
|
||||
explicit BaseClassItem(const std::string &name, ItemContainer *container)
|
||||
: TypeItem(Type::TypeId::REFERENCE, container), name_(name, container) {}
|
||||
|
||||
~BaseClassItem() override = default;
|
||||
|
||||
@ -1009,12 +1010,13 @@ private:
|
||||
|
||||
class ClassItem : public BaseClassItem {
|
||||
public:
|
||||
explicit ClassItem(const std::string &name)
|
||||
: BaseClassItem(name),
|
||||
explicit ClassItem(const std::string &name, ItemContainer *container)
|
||||
: BaseClassItem(name, container),
|
||||
super_class_(nullptr),
|
||||
access_flags_(0),
|
||||
source_lang_(SourceLang::PANDA_ASSEMBLY),
|
||||
source_file_(nullptr)
|
||||
source_file_(nullptr),
|
||||
container_(container)
|
||||
{
|
||||
}
|
||||
|
||||
@ -1064,7 +1066,7 @@ public:
|
||||
template <class... Args>
|
||||
FieldItem *AddField(Args... args)
|
||||
{
|
||||
fields_.emplace_back(std::make_unique<FieldItem>(this, std::forward<Args>(args)...));
|
||||
fields_.emplace_back(std::make_unique<FieldItem>(this, std::forward<Args>(args)..., container_));
|
||||
return fields_.back().get();
|
||||
}
|
||||
|
||||
@ -1072,7 +1074,7 @@ public:
|
||||
MethodItem *AddMethod(Args... args)
|
||||
{
|
||||
// insert new method to set ordered by method name
|
||||
return methods_.insert(std::make_unique<MethodItem>(this, std::forward<Args>(args)...))->get();
|
||||
return methods_.insert(std::make_unique<MethodItem>(this, std::forward<Args>(args)..., container_))->get();
|
||||
}
|
||||
|
||||
void SetSourceFile(StringItem *item)
|
||||
@ -1170,11 +1172,12 @@ private:
|
||||
StringItem *source_file_;
|
||||
std::vector<std::unique_ptr<FieldItem>> fields_;
|
||||
std::multiset<std::unique_ptr<MethodItem>, MethodCompByName> methods_;
|
||||
ItemContainer *container_;
|
||||
};
|
||||
|
||||
class ForeignClassItem : public BaseClassItem {
|
||||
public:
|
||||
explicit ForeignClassItem(const std::string &name) : BaseClassItem(name) {}
|
||||
explicit ForeignClassItem(const std::string &name, ItemContainer *container) : BaseClassItem(name, container) {}
|
||||
|
||||
~ForeignClassItem() override = default;
|
||||
|
||||
@ -1194,7 +1197,8 @@ public:
|
||||
|
||||
class ForeignFieldItem : public BaseFieldItem {
|
||||
public:
|
||||
ForeignFieldItem(BaseClassItem *cls, StringItem *name, TypeItem *type) : BaseFieldItem(cls, name, type) {}
|
||||
ForeignFieldItem(BaseClassItem *cls, StringItem *name, TypeItem *type, ItemContainer *container)
|
||||
: BaseFieldItem(cls, name, type, container) {}
|
||||
|
||||
~ForeignFieldItem() override = default;
|
||||
|
||||
@ -1214,8 +1218,8 @@ public:
|
||||
|
||||
class ForeignMethodItem : public BaseMethodItem {
|
||||
public:
|
||||
ForeignMethodItem(BaseClassItem *cls, StringItem *name, ProtoItem *proto, uint32_t access_flags)
|
||||
: BaseMethodItem(cls, name, proto, access_flags)
|
||||
ForeignMethodItem(BaseClassItem *cls, StringItem *name, ProtoItem *proto, uint32_t access_flags,
|
||||
ItemContainer *container) : BaseMethodItem(cls, name, proto, access_flags, container)
|
||||
{
|
||||
}
|
||||
|
||||
@ -1261,7 +1265,7 @@ private:
|
||||
|
||||
class ProtoItem : public IndexedItem {
|
||||
public:
|
||||
ProtoItem(TypeItem *ret_type, const std::vector<MethodParamItem> ¶ms);
|
||||
ProtoItem(TypeItem *ret_type, const std::vector<MethodParamItem> ¶ms, ItemContainer *itemContainer);
|
||||
|
||||
~ProtoItem() override = default;
|
||||
|
||||
@ -1463,7 +1467,7 @@ class ValueItem : public IndexedItem {
|
||||
public:
|
||||
enum class Type { INTEGER, LONG, FLOAT, DOUBLE, ID, ARRAY };
|
||||
|
||||
explicit ValueItem(Type type) : type_(type) {}
|
||||
explicit ValueItem(Type type, ItemContainer *container) : IndexedItem(container), type_(type) {}
|
||||
|
||||
~ValueItem() override = default;
|
||||
|
||||
@ -1500,15 +1504,15 @@ private:
|
||||
|
||||
class ScalarValueItem : public ValueItem {
|
||||
public:
|
||||
explicit ScalarValueItem(uint32_t v) : ValueItem(Type::INTEGER), value_(v) {}
|
||||
explicit ScalarValueItem(uint32_t v, ItemContainer *container) : ValueItem(Type::INTEGER, container), value_(v) {}
|
||||
|
||||
explicit ScalarValueItem(uint64_t v) : ValueItem(Type::LONG), value_(v) {}
|
||||
explicit ScalarValueItem(uint64_t v, ItemContainer *container) : ValueItem(Type::LONG, container), value_(v) {}
|
||||
|
||||
explicit ScalarValueItem(float v) : ValueItem(Type::FLOAT), value_(v) {}
|
||||
explicit ScalarValueItem(float v, ItemContainer *container) : ValueItem(Type::FLOAT, container), value_(v) {}
|
||||
|
||||
explicit ScalarValueItem(double v) : ValueItem(Type::DOUBLE), value_(v) {}
|
||||
explicit ScalarValueItem(double v, ItemContainer *container) : ValueItem(Type::DOUBLE, container), value_(v) {}
|
||||
|
||||
explicit ScalarValueItem(BaseItem *v) : ValueItem(Type::ID), value_(v) {}
|
||||
explicit ScalarValueItem(BaseItem *v, ItemContainer *container) : ValueItem(Type::ID, container), value_(v) {}
|
||||
|
||||
~ScalarValueItem() override = default;
|
||||
|
||||
@ -1544,8 +1548,8 @@ private:
|
||||
|
||||
class ArrayValueItem : public ValueItem {
|
||||
public:
|
||||
ArrayValueItem(panda_file::Type component_type, std::vector<ScalarValueItem> items)
|
||||
: ValueItem(Type::ARRAY), component_type_(component_type), items_(std::move(items))
|
||||
ArrayValueItem(panda_file::Type component_type, std::vector<ScalarValueItem> items, ItemContainer *container)
|
||||
: ValueItem(Type::ARRAY, container), component_type_(component_type), items_(std::move(items))
|
||||
{
|
||||
}
|
||||
|
||||
@ -1634,7 +1638,7 @@ private:
|
||||
|
||||
class LiteralArrayItem : public ValueItem {
|
||||
public:
|
||||
explicit LiteralArrayItem() : ValueItem(Type::ARRAY) {}
|
||||
explicit LiteralArrayItem(ItemContainer *container) : ValueItem(Type::ARRAY, container) {}
|
||||
|
||||
~LiteralArrayItem() override = default;
|
||||
|
||||
|
@ -1059,4 +1059,73 @@ HWTEST(ItemContainer, GettersTest, testing::ext::TestSize.Level0)
|
||||
rclass_item->VisitFields(cb_field);
|
||||
}
|
||||
|
||||
HWTEST(ItemContainer, IndexedItemGlobalIndexTest, testing::ext::TestSize.Level0)
|
||||
{
|
||||
ItemContainer container;
|
||||
EXPECT_EQ(container.GetIndexedItemCount(), 0U);
|
||||
|
||||
// Create foreign class
|
||||
ForeignClassItem *foreign_class_item = container.GetOrCreateForeignClassItem("foreign_class");
|
||||
EXPECT_EQ(foreign_class_item->GetIndexedItemCount(), 0U);
|
||||
// BaseClassItem will initialize one StringItem member, which will increase the count by 1.
|
||||
EXPECT_EQ(container.GetIndexedItemCount(), foreign_class_item->GetIndexedItemCount() + 2);
|
||||
|
||||
// Create foreign field
|
||||
StringItem *foreign_field_name = container.GetOrCreateStringItem("foreign_field");
|
||||
PrimitiveTypeItem *foreign_field_type = container.GetOrCreatePrimitiveTypeItem(Type::TypeId::I32);
|
||||
ForeignFieldItem *foreign_field_item = container.CreateItem<ForeignFieldItem>(foreign_class_item,
|
||||
foreign_field_name, foreign_field_type);
|
||||
EXPECT_EQ(foreign_field_item->GetIndexedItemCount(), 4U);
|
||||
EXPECT_EQ(container.GetIndexedItemCount(), foreign_field_item->GetIndexedItemCount() + 1);
|
||||
|
||||
// Create foreign method
|
||||
StringItem *foreign_method_name = container.GetOrCreateStringItem("foreign_method");
|
||||
PrimitiveTypeItem *foreign_ret_type = container.GetOrCreatePrimitiveTypeItem(Type::TypeId::VOID);
|
||||
std::vector<MethodParamItem> foreign_params;
|
||||
foreign_params.emplace_back(container.GetOrCreatePrimitiveTypeItem(Type::TypeId::I64));
|
||||
ProtoItem *foreign_proto_item = container.GetOrCreateProtoItem(foreign_ret_type, foreign_params);
|
||||
ForeignMethodItem *foreign_method_item = container.CreateItem<ForeignMethodItem>(foreign_class_item,
|
||||
foreign_method_name, foreign_proto_item, 0);
|
||||
EXPECT_EQ(foreign_method_item->GetIndexedItemCount(), 9U);
|
||||
EXPECT_EQ(container.GetIndexedItemCount(), foreign_method_item->GetIndexedItemCount() + 1);
|
||||
|
||||
// Create class
|
||||
ClassItem *class_item = container.GetOrCreateClassItem("classA");
|
||||
EXPECT_EQ(class_item->GetIndexedItemCount(), 10U);
|
||||
EXPECT_EQ(container.GetIndexedItemCount(), class_item->GetIndexedItemCount() + 2);
|
||||
|
||||
// Create method
|
||||
StringItem *method_name = container.GetOrCreateStringItem("a");
|
||||
// TypeId::VOID is repeated, count won't increase
|
||||
PrimitiveTypeItem *ret_type = container.GetOrCreatePrimitiveTypeItem(Type::TypeId::VOID);
|
||||
std::vector<MethodParamItem> params;
|
||||
ProtoItem *proto_item = container.GetOrCreateProtoItem(ret_type, params);
|
||||
MethodItem *method_item = class_item->AddMethod(method_name, proto_item, ACC_PUBLIC | ACC_STATIC, params);
|
||||
EXPECT_EQ(method_item->GetIndexedItemCount(), 14U);
|
||||
EXPECT_EQ(container.GetIndexedItemCount(), method_item->GetIndexedItemCount() + 1);
|
||||
|
||||
// Create field
|
||||
StringItem *field_name = container.GetOrCreateStringItem("field");
|
||||
PrimitiveTypeItem *field_type = container.GetOrCreatePrimitiveTypeItem(Type::TypeId::I32);
|
||||
FieldItem *field_item = class_item->AddField(field_name, field_type, ACC_PUBLIC);
|
||||
EXPECT_EQ(field_item->GetIndexedItemCount(), 16U);
|
||||
EXPECT_EQ(container.GetIndexedItemCount(), field_item->GetIndexedItemCount() + 1);
|
||||
|
||||
// Create code, item count is not expected to increase
|
||||
std::vector<uint8_t> instructions {1, 2, 3, 4};
|
||||
CodeItem *code_item = container.CreateItem<CodeItem>(0, 2, instructions);
|
||||
method_item->SetCode(code_item);
|
||||
EXPECT_EQ(container.GetIndexedItemCount(), field_item->GetIndexedItemCount() + 1);
|
||||
|
||||
// Create line number program
|
||||
LineNumberProgramItem *line_number_program_item = container.CreateLineNumberProgramItem();
|
||||
EXPECT_EQ(line_number_program_item->GetIndexedItemCount(), 17U);
|
||||
EXPECT_EQ(container.GetIndexedItemCount(), line_number_program_item->GetIndexedItemCount() + 1);
|
||||
|
||||
// Create value items
|
||||
ScalarValueItem *scalarValueItem = container.CreateItem<ScalarValueItem>(1.0);
|
||||
EXPECT_EQ(scalarValueItem->GetIndexedItemCount(), 18U);
|
||||
EXPECT_EQ(container.GetIndexedItemCount(), scalarValueItem->GetIndexedItemCount() + 1);
|
||||
}
|
||||
|
||||
} // namespace panda::panda_file::test
|
||||
|
@ -27,7 +27,7 @@ namespace panda::panda_file::test {
|
||||
|
||||
HWTEST(LineNumberProgramItem, EmitSpecialOpcode, testing::ext::TestSize.Level0)
|
||||
{
|
||||
LineNumberProgramItem item;
|
||||
LineNumberProgramItem item(nullptr);
|
||||
|
||||
constexpr int32_t LINE_MAX_INC = LineNumberProgramItem::LINE_RANGE + LineNumberProgramItem::LINE_BASE - 1;
|
||||
constexpr int32_t LINE_MIN_INC = LineNumberProgramItem::LINE_BASE;
|
||||
|
Loading…
Reference in New Issue
Block a user