Mapping literal array with record name

Issue I9JSP6
Unittest and test262 pass

Change-Id: I1136617d20c79c4f453f4693a3110c179f0c2dbc
Signed-off-by: l00680486 <litengfei26@huawei.com>
This commit is contained in:
l00680486 2024-04-25 11:06:19 +08:00
parent 007cbe91ec
commit a5d4ebebe5
9 changed files with 43 additions and 26 deletions

View File

@ -33,7 +33,6 @@ bool AbcFileProcessor::FillProgramData()
{
program_->lang = panda_file::SourceLang::ECMASCRIPT;
FillClassesData();
FillLiteralArrayTable();
return true;
}
@ -53,8 +52,11 @@ void AbcFileProcessor::FillClassesData()
if (file_->IsExternal(record_id)) {
continue;
}
entity_container_.SetCurrentClassId(class_idx);
entity_container_.ClearLiteralArrayIdSet();
AbcClassProcessor class_processor(record_id, entity_container_);
class_processor.FillProgramData();
FillLiteralArrayTable();
}
}

View File

@ -152,18 +152,4 @@ void AbcLiteralArrayProcessor::FillLiteralData(pandasm::LiteralArray *lit_array,
lit_array->literals_.emplace_back(value_lit);
}
void AbcLiteralArrayProcessor::FillLiteralData4Method(const panda_file::LiteralDataAccessor::LiteralValue &value,
pandasm::LiteralArray::Literal &lit) const
{
panda_file::MethodDataAccessor mda(*file_, panda_file::File::EntityId(std::get<uint32_t>(value)));
lit.value_ = string_table_->GetStringById(mda.GetNameId());
}
void AbcLiteralArrayProcessor::FillLiteralData4LiteralArray(const panda_file::LiteralDataAccessor::LiteralValue &value,
pandasm::LiteralArray::Literal &lit) const
{
uint32_t literal_array_id = std::get<uint32_t>(value);
lit.value_ = entity_container_.GetLiteralArrayIdName(literal_array_id);
}
} // namespace panda::abc2program

View File

@ -34,10 +34,6 @@ private:
const panda_file::LiteralDataAccessor::LiteralValue &value) const;
void FillLiteralData(pandasm::LiteralArray *lit_array, const panda_file::LiteralDataAccessor::LiteralValue &value,
const panda_file::LiteralTag &tag) const;
void FillLiteralData4Method(const panda_file::LiteralDataAccessor::LiteralValue &value,
pandasm::LiteralArray::Literal &lit) const;
void FillLiteralData4LiteralArray(const panda_file::LiteralDataAccessor::LiteralValue &value,
pandasm::LiteralArray::Literal &lit) const;
panda_file::LiteralDataAccessor &literal_data_accessor_;
pandasm::LiteralArray literal_array_;
};

View File

@ -210,15 +210,15 @@ void Abc2ProgramEntityContainer::TryAddUnprocessedNestedLiteralArrayId(uint32_t
unprocessed_nested_literal_array_id_set_.insert(nested_literal_array_id);
}
std::string Abc2ProgramEntityContainer::GetLiteralArrayIdName(uint32_t literal_array_id) const
std::string Abc2ProgramEntityContainer::GetLiteralArrayIdName(uint32_t literal_array_id)
{
std::stringstream name;
const std::string file_abs_path = GetAbcFileAbsolutePath();
name << file_abs_path << STR_LITERAL_ARRAY_ID << "0x" << std::hex << literal_array_id;
auto cur_record_name = GetFullRecordNameById(panda_file::File::EntityId(current_class_id_));
name << cur_record_name << UNDERLINE << literal_array_id;
return name.str();
}
std::string Abc2ProgramEntityContainer::GetLiteralArrayIdName(const panda_file::File::EntityId &literal_array_id) const
std::string Abc2ProgramEntityContainer::GetLiteralArrayIdName(const panda_file::File::EntityId &literal_array_id)
{
return GetLiteralArrayIdName(literal_array_id.GetOffset());
}
@ -233,4 +233,17 @@ std::string Abc2ProgramEntityContainer::GetAbcFileAbsolutePath() const
return os::file::File::GetAbsolutePath(file_.GetFilename()).Value();
}
void Abc2ProgramEntityContainer::SetCurrentClassId(uint32_t class_id)
{
current_class_id_ = class_id;
}
void Abc2ProgramEntityContainer::ClearLiteralArrayIdSet()
{
module_literal_array_id_set_.clear();
unnested_literal_array_id_set_.clear();
processed_nested_literal_array_id_set_.clear();
unprocessed_nested_literal_array_id_set_.clear();
}
} // namespace panda::abc2program

View File

@ -61,11 +61,14 @@ public:
void AddUnnestedLiteralArrayId(const panda_file::File::EntityId &literal_array_id);
void AddProcessedNestedLiteralArrayId(uint32_t nested_literal_array_id);
void TryAddUnprocessedNestedLiteralArrayId(uint32_t nested_literal_array_id);
std::string GetLiteralArrayIdName(uint32_t literal_array_id) const;
std::string GetLiteralArrayIdName(const panda_file::File::EntityId &literal_array_id) const;
std::string GetLiteralArrayIdName(uint32_t literal_array_id);
std::string GetLiteralArrayIdName(const panda_file::File::EntityId &literal_array_id);
std::string GetAbcFileAbsolutePath() const;
panda_file::DebugInfoExtractor &GetDebugInfoExtractor() const;
void SetCurrentClassId(uint32_t class_id);
void ClearLiteralArrayIdSet();
private:
std::string ConcatFullMethodNameById(const panda_file::File::EntityId &method_id);
const panda_file::File &file_;
@ -81,6 +84,7 @@ private:
std::unordered_set<uint32_t> unnested_literal_array_id_set_;
std::unordered_set<uint32_t> processed_nested_literal_array_id_set_;
std::unordered_set<uint32_t> unprocessed_nested_literal_array_id_set_;
uint32_t current_class_id_{0};
}; // class Abc2ProgramEntityContainer
} // namespace panda::abc2program

View File

@ -78,9 +78,11 @@ constexpr std::string_view DUMP_CONTENT_CATCH_END_LABEL = "catch_end_label : ";
constexpr std::string_view DUMP_CONTENT_LOCAL_VAR_TABLE = "#\t Start Length Register Name Signature\n";
constexpr std::string_view DUMP_CONTENT_LINE_NUMBER = " # line: ";
constexpr std::string_view DUMP_CONTENT_COLUMN_NUMBER = " # column: ";
constexpr std::string_view STR_LITERAL_ARRAY_ID = ".LITERAL_ARRAY_ID:";
constexpr std::string_view DUMP_CONTENT_NESTED_LITERALARRAY = "$$NESTED-LITERALARRAY$$";
// literal array name
constexpr std::string_view UNDERLINE = "_";
// width constant
constexpr uint32_t LINE_WIDTH = 40;
constexpr uint32_t COLUMN_WIDTH = 10;

View File

@ -31,6 +31,10 @@ std::set<std::string> Abc2ProgramTestUtils::helloworld_expected_program_strings_
std::vector<std::string> Abc2ProgramTestUtils::helloworld_expected_record_names_ = {"_ESModuleRecord",
"_ESSlotNumberAnnotation",
"_GLOBAL"};
std::vector<std::string> Abc2ProgramTestUtils::helloworld_expected_literal_array_keys_ = {"_ESModuleRecord_2247",
"_GLOBAL_2327",
"_GLOBAL_2336",
"_GLOBAL_2345"};
std::set<size_t> Abc2ProgramTestUtils::helloworld_expected_literals_sizes_ = {2, 8, 21};
@ -59,6 +63,11 @@ bool Abc2ProgramTestUtils::ValidateRecordNames(const std::vector<std::string> &r
return ValidateStrings(record_names, helloworld_expected_record_names_);
}
bool Abc2ProgramTestUtils::ValidateLiteralArrayKeys(const std::vector<std::string> &literal_array_keys)
{
return ValidateStrings(literal_array_keys, helloworld_expected_literal_array_keys_);
}
bool Abc2ProgramTestUtils::ValidateLiteralsSizes(const std::set<size_t> &literal_array_sizes)
{
return (literal_array_sizes == helloworld_expected_literals_sizes_);

View File

@ -28,12 +28,14 @@ class Abc2ProgramTestUtils {
public:
static bool ValidateProgramStrings(const std::set<std::string> &program_strings);
static bool ValidateRecordNames(const std::vector<std::string> &record_names);
static bool ValidateLiteralArrayKeys(const std::vector<std::string> &literal_array_keys);
static bool ValidateLiteralsSizes(const std::set<size_t> &literals_sizes);
private:
template <typename T>
static bool ValidateStrings(const T &strings, const T &expected_strings);
static std::set<std::string> helloworld_expected_program_strings_;
static std::vector<std::string> helloworld_expected_record_names_;
static std::vector<std::string> helloworld_expected_literal_array_keys_;
static std::set<size_t> helloworld_expected_literals_sizes_;
}; // class Abc2ProgramTestUtils

View File

@ -141,12 +141,15 @@ HWTEST_F(Abc2ProgramHelloWorldTest, abc2program_hello_world_test_lang, TestSize.
HWTEST_F(Abc2ProgramHelloWorldTest, abc2program_hello_world_test_literalarray_table, TestSize.Level1)
{
std::set<size_t> literals_sizes;
std::vector<std::string> literal_array_keys;
for (const auto &it : prog_->literalarray_table) {
const pandasm::LiteralArray &literal_array = it.second;
size_t literals_size = literal_array.literals_.size();
literals_sizes.insert(literals_size);
literal_array_keys.emplace_back(it.first);
}
EXPECT_TRUE(Abc2ProgramTestUtils::ValidateLiteralsSizes(literals_sizes));
EXPECT_TRUE(Abc2ProgramTestUtils::ValidateLiteralArrayKeys(literal_array_keys));
}
/**