Add test for object literal's debug info

Issue:https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I8XS3C

Signed-off-by: huyunhui <huyunhui1@huawei.com>
Change-Id: I7514af8772cf9b5c90e2c9a05747a331e003d4b4
This commit is contained in:
huyunhui 2024-01-28 07:14:43 +00:00
parent 24e71e8c60
commit 4562f6669c
5 changed files with 88 additions and 0 deletions

View File

@ -1946,4 +1946,15 @@ std::vector<size_t> Disassembler::GetColumnNumber()
return columnNumber;
}
std::vector<size_t> Disassembler::GetLineNumber()
{
std::vector<size_t> lineNumber;
for (const auto &method_info : prog_info_.methods_info) {
for (const auto &line_number : method_info.second.line_number_table) {
lineNumber.push_back(line_number.line);
}
}
return lineNumber;
}
} // namespace panda::disasm

View File

@ -80,6 +80,7 @@ public:
}
std::vector<size_t> GetColumnNumber();
std::vector<size_t> GetLineNumber();
private:
void GetLiteralArrays();

View File

@ -34,6 +34,7 @@ disasm_column_test_js_files = [
"column-number3",
"column-number4",
"column-number5",
"line-number1",
]
disasm_test_js_files = [
@ -109,6 +110,7 @@ disasm_include_dirs = [
script_sources = [
"disassembler_annotations_test.cpp",
"disassembler_column_number_test.cpp",
"disassembler_line_number_test.cpp",
"disassembler_string_test.cpp",
]

View File

@ -0,0 +1,56 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <gtest/gtest.h>
#include <string>
#include "disassembler.h"
using namespace testing::ext;
namespace panda::disasm {
class DisasmTest : public testing::Test {
public:
static void SetUpTestCase(void) {};
static void TearDownTestCase(void) {};
void SetUp() {};
void TearDown() {};
};
/**
* @tc.name: disassembler_line_number_test_001
* @tc.desc: Check abc file line number function.
* @tc.type: FUNC
* @tc.require: file path and name
*/
HWTEST_F(DisasmTest, disassembler_line_number_test_001, TestSize.Level1)
{
const std::string file_name = GRAPH_TEST_ABC_DIR "line-number1.abc";
panda::disasm::Disassembler disasm {};
disasm.Disassemble(file_name, false, false);
disasm.CollectInfo();
// The known line number in the abc file
std::vector<size_t> expectedLineNumber = {-1, 15, -1, 15};
std::vector<size_t> lineNumber = disasm.GetLineNumber();
EXPECT_TRUE(expectedLineNumber.size() == lineNumber.size());
bool res = true;
for (size_t i = 0; i < lineNumber.size(); ++i) {
if (expectedLineNumber[i] != lineNumber[i]) {
res = false;
break;
}
}
EXPECT_TRUE(res);
}
}

View File

@ -0,0 +1,18 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
let obj = {
a: -1
}