Fix codeCheck warnings

Issue: I6SOYD
Test: libark_defect_scan_aux
Signed-off-by: songqi <songqi32@huawei.com>
Change-Id: Icca8d763a3f1250f9653cf718edb43cc89c64ee8
This commit is contained in:
songqi 2023-04-03 21:36:56 +08:00
parent 8dae8d0353
commit b03ddd8e09
11 changed files with 263 additions and 255 deletions

View File

@ -13,18 +13,19 @@
* limitations under the License.
*/
import * as db from './database';
import { UserInput } from './user_input';
function getData(store, userInput) {
let name = userInput.getText();
let sql = "select * from user_data where name = '" + name + "'";
let result = store.querySql(sql);
return result;
let name = userInput.getText();
let sql = "select * from user_data where name = '" + name + "'";
let result = store.querySql(sql);
return result;
}
function FuncEntry() {
let store = db.getDatabaseInstance();
let user_input = new UserInput();
getData(store, user_input);
function funcEntry() {
let store = db.getDatabaseInstance();
let userInput = new UserInput();
getData(store, userInput);
}

View File

@ -13,24 +13,25 @@
* limitations under the License.
*/
class Database {
addData(data) {
console.log("addData: ", data);
}
addData(data) {
console.log('addData: ', data);
}
removeData(data) {
console.log("removeData: ", data);
}
removeData(data) {
console.log('removeData: ', data);
}
querySql(sql) {
return "querySql: " + sql;
}
querySql(sql) {
return 'querySql: ' + sql;
}
updateData(old_data, new_data) {
console.log("updateData: ", old_data, "->", new_data);
}
updateData(oldData, newData) {
console.log('updateData: ', oldData, '->', newData);
}
}
export function getDatabaseInstance() {
return new Database();
return new Database();
}

View File

@ -13,16 +13,17 @@
* limitations under the License.
*/
export class UserInput {
constructor(text) {
this.text = text;
}
constructor(text) {
this.text = text;
}
getText() {
return this.text;
}
getText() {
return this.text;
}
setText(text) {
this.text = text;
}
setText(text) {
this.text = text;
}
}

View File

@ -13,47 +13,48 @@
* limitations under the License.
*/
class Database {
addData(data) {
console.log("addData: ", data);
}
addData(data) {
console.log('addData: ', data);
}
removeData(data) {
console.log("removeData: ", data);
}
removeData(data) {
console.log('removeData: ', data);
}
querySql(sql) {
return "querySql: " + sql;
}
querySql(sql) {
return 'querySql: ' + sql;
}
updateData(old_data, new_data) {
console.log("updateData: ", old_data, new_data);
}
updateData(oldData, newData) {
console.log('updateData: ', oldData, newData);
}
}
class UserInput {
constructor(text) {
this.text = text;
}
constructor(text) {
this.text = text;
}
getText() {
return this.text;
}
getText() {
return this.text;
}
setText(text) {
this.text = text;
}
setText(text) {
this.text = text;
}
}
function getData(store, user_input) {
let name = user_input.getText();
let sql = "select * from user_data where name = '" + name + "'";
let result = store.querySql(sql);
return result;
function getData(store, userInput) {
let name = userInput.getText();
let sql = "select * from user_data where name = '" + name + "'";
let result = store.querySql(sql);
return result;
}
function funcEntry() {
let store = new Database();
let user_input = new UserInput("UserInput");
getData(store, user_input);
let store = new Database();
let userInput = new UserInput('UserInput');
getData(store, userInput);
}

View File

@ -13,104 +13,105 @@
* limitations under the License.
*/
import * as ns from '../../mod1'
import { bar as bar2 } from './mod2'
import * as ns from '../../mod1';
import { bar as bar2 } from './mod2';
function func1(o1, o2) { }
// call scope-defined function/global function
function foo(o1, o2) {
let func2 = (x) => { return x * 2; }
func2(o2.x);
let func2 = (x) => { return x * 2; };
func2(o2.x);
// call func from global variable
console.log("log");
globalvar.hilog.logd("logd");
// call func from global variable
console.log('log');
globalvar.hilog.logd('logd');
let func3 = func2
let func4 = func3;
func4(o1.x);
let func3 = func2;
let func4 = func3;
func4(o1.x);
let a = o1.x;
if (a) {
func1(2, o2.y);
o2.bar();
}
let a = o1.x;
if (a) {
func1(2, o2.y);
o2.bar();
}
}
// indirect call via 'apply' or 'call'
function foo1(o1, o2, o3) {
let obj = { z: 2 };
function fn(x, y) {
print(x + y + this.z);
}
let obj = { z: 2 };
function fn(x, y) {
print(x + y + this.z);
}
fn.call(obj, 2, 3);
fn.apply(obj, [2, 3]);
let bound = fn.bind(obj, 4);
fn.call(obj, 2, 3);
fn.apply(obj, [2, 3]);
let bound = fn.bind(obj, 4);
}
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
constructor(x, y) {
this.x = x;
this.y = y;
}
get getCoordinateX() {
return this.x;
}
get getCoordinateX() {
return this.x;
}
set setCoordinateX(x) {
return this.x = x;
}
set setCoordinateX(x) {
return this.x = x;
}
plus(other) {
this.x += other.x;
this.y += other.y;
}
plus(other) {
this.x += other.x;
this.y += other.y;
}
}
function func5() {
// call super
class ColorPoint extends Point {
constructor(x, y, color) {
super(x, y);
this.color = color;
}
// call super
class ColorPoint extends Point {
constructor(x, y, color) {
super(x, y);
this.color = color;
}
}
}
// call function of across module
function func6(o1, o2) {
bar2();
bar2();
function func7() {
var func8 = ns.math.sum;
func8(1, 2);
ns.sub(o2, o1);
}
function func7() {
let func8 = ns.math.sum;
func8(1, 2);
ns.sub(o2, o1);
}
}
// call member function
function func9() {
let point = new Point(2, 3);
let point = new Point(2, 3);
function callMemberFunc1(p) {
let x = point.getCoordinateX();
point.setCoordinateX(x);
let point2 = point
function callMemberFunc1(p) {
let x = point.getCoordinateX();
point.setCoordinateX(x);
let point2 = point;
function callMemberFunc2(p) {
point2.plus(p);
point2.sub(p);
}
function callMemberFunc2(p) {
point2.plus(p);
point2.sub(p);
}
}
}
function func10(o1, o2) {
let service = new ns.PhoneService();
function callExClassMemberFunc1(o) {
service.makePhoneCall(o);
}
let service = new ns.PhoneService();
function callExClassMemberFunc1(o) {
service.makePhoneCall(o);
}
}

View File

@ -13,64 +13,65 @@
* limitations under the License.
*/
function func1(o1, o2) {
console.log(o1 + o2);
console.log(o1 + o2);
}
async function func2() { }
let func3 = (o1, o2, o3, o4, o5) => { }
let func3 = (o1, o2, o3, o4, o5) => { };
function foo(o1, o2) {
const a = 1;
const b = 2;
let c = 0;
if (o1.x > a + b) {
c = o1.x;
} else if (o2.x < a + b) {
c = o2.x;
} else {
c = a + b + func2();
}
const a = 1;
const b = 2;
let c = 0;
if (o1.x > a + b) {
c = o1.x;
} else if (o2.x < a + b) {
c = o2.x;
} else {
c = a + b + func2();
}
let arr = [a, b]
var m = "123"; func1(...arr); // written on the same line for testing
let arr = [a, b];
let m = '123'; func1(...arr); // written on the same line for testing
func3(a, b, c, c, m);
func3(a, b, c, c, m);
}
class DataBase {
constructor(x) {
this.x = x;
}
constructor(x) {
this.x = x;
}
add(o) {
this.x += o;
}
add(o) {
this.x += o;
}
sub(o) {
this.x -= o;
}
sub(o) {
this.x -= o;
}
}
function bar(o) {
class Data extends DataBase {
constructor(x, y) {
super(x);
this.y = y;
}
class Data extends DataBase {
constructor(x, y) {
super(x);
this.y = y;
}
}
let data = new Data();
// multiple blank lines here are for testing
let data = new Data();
// multiple blank lines here are for testing
data.sub(o);
data.sub(o);
var b = data.x;
if (o) {
b += 1;
console.log(b);
}
let b = data.x;
if (o) {
b += 1;
console.log(b);
}
}

View File

@ -172,7 +172,7 @@ int main()
TestHelper::ExpectEqual(mod_name1, "./mod2");
std::string mod_name2 = abc_file->GetModuleNameByInternalName("var3");
TestHelper::ExpectEqual(mod_name2, "../mod3");
std::string mod_name3 = abc_file->GetModuleNameByInternalName("local_var4");
std::string mod_name3 = abc_file->GetModuleNameByInternalName("localVar4");
TestHelper::ExpectEqual(mod_name3, "../../mod4");
// GetImportNameByInternalName
@ -180,7 +180,7 @@ int main()
TestHelper::ExpectEqual(im_name0, "default");
std::string im_name1 = abc_file->GetImportNameByInternalName("var3");
TestHelper::ExpectEqual(im_name1, "var3");
std::string im_name2 = abc_file->GetImportNameByInternalName("local_var4");
std::string im_name2 = abc_file->GetImportNameByInternalName("localVar4");
TestHelper::ExpectEqual(im_name2, "var4");
// GetImportNameByExportName
std::string ind_im_name0 = abc_file->GetImportNameByExportName("v");
@ -443,28 +443,28 @@ int main()
TestHelper::ExpectEqual(f0->GetCalleeInfoCount(), 3);
auto ci0_0 = f0->GetCalleeInfoByIndex(0);
// callarg0
TestHelper::ExpectEqual(abc_file->GetLineNumberByInst(f0, ci0_0->GetCallInst()), 33);
TestHelper::ExpectEqual(abc_file->GetLineNumberByInst(f0, ci0_0->GetCallInst()), 34);
auto ci0_1 = f0->GetCalleeInfoByIndex(1);
// callspread
TestHelper::ExpectEqual(abc_file->GetLineNumberByInst(f0, ci0_1->GetCallInst()), 37);
TestHelper::ExpectEqual(abc_file->GetLineNumberByInst(f0, ci0_1->GetCallInst()), 38);
auto ci0_2 = f0->GetCalleeInfoByIndex(2);
// callirange
TestHelper::ExpectEqual(abc_file->GetLineNumberByInst(f0, ci0_2->GetCallInst()), 39);
TestHelper::ExpectEqual(abc_file->GetLineNumberByInst(f0, ci0_2->GetCallInst()), 40);
// ctor of Data
auto f1 = abc_file->GetFunctionByName("#2#Data");
TestHelper::ExpectEqual(f1->GetCalleeInfoCount(), 1);
auto ci1_0 = f1->GetCalleeInfoByIndex(0);
// supercall
TestHelper::ExpectEqual(abc_file->GetLineNumberByInst(f1, ci1_0->GetCallInst()), 59);
TestHelper::ExpectEqual(abc_file->GetLineNumberByInst(f1, ci1_0->GetCallInst()), 60);
// bar
auto f2 = abc_file->GetFunctionByName("bar");
TestHelper::ExpectEqual(f2->GetCalleeInfoCount(), 2);
auto ci2_0 = f2->GetCalleeInfoByIndex(0);
// callithisrange
TestHelper::ExpectEqual(abc_file->GetLineNumberByInst(f2, ci2_0->GetCallInst()), 69);
TestHelper::ExpectEqual(abc_file->GetLineNumberByInst(f2, ci2_0->GetCallInst()), 70);
auto ci2_1 = f2->GetCalleeInfoByIndex(1);
// callithisrange
TestHelper::ExpectEqual(abc_file->GetLineNumberByInst(f2, ci2_1->GetCallInst()), 74);
TestHelper::ExpectEqual(abc_file->GetLineNumberByInst(f2, ci2_1->GetCallInst()), 75);
std::cout << " --- Pass ---" << std::endl << std::endl;
}

View File

@ -13,68 +13,69 @@
* limitations under the License.
*/
import { BaseService } from '../base/service'
import * as ns from '../mod1'
import { BaseService } from '../base/service';
import * as ns from '../mod1';
async function func1() { }
function func2(o1, o2) {
let func3 = function* () { }
var obj = {
"num": 3,
"func4": (n1) => { return n1 * n1 }
}
let func3 = function* () { };
let obj = {
'num': 3,
'func4': (n1) => { return n1 * n1 },
};
}
class Bar {
constructor(name, color) {
this.name = name;
this.color = color;
}
constructor(name, color) {
this.name = name;
this.color = color;
}
func6() { }
func6() { }
get getName() {
return this.name;
}
set setName(name) {
this.name = name;
}
get getName() {
return this.name;
}
set setName(name) {
this.name = name;
}
func9(o1, o2, o3) { }
func9(o1, o2, o3) { }
}
var a = "func7"
var symbol = Symbol("func8");
let a = 'func7';
let symbol = Symbol('func8');
function func10() {
class Bar {
baseFoo1() { }
}
class Bar {
baseFoo1() { }
}
class Bar2 extends Bar {
func12(o1) { }
[a]() { }
[symbol]() { }
func15(o1, o2) { }
}
class Bar2 extends Bar {
func12(o1) { }
[a]() { }
[symbol]() { }
func15(o1, o2) { }
}
}
class ExampleClass1 {
func17() { }
func17() { }
}
function func18() {
class ExampleClass1 {
func19() { }
}
class ExampleClass1 {
func19() { }
}
function func20() {
class ExampleClass2 extends ExampleClass1 { }
}
function func20() {
class ExampleClass2 extends ExampleClass1 { }
}
}
function func21() {
class ExtendService extends BaseService { }
class ExtendPhoneService extends ns.Phone.PhoneService { }
class ExtendDataSource extends globalvar.BasicDataSource { }
class ExtendDataItem extends globalvar2.Data.DataItem { }
class ExtendService extends BaseService { }
class ExtendPhoneService extends ns.Phone.PhoneService { }
class ExtendDataSource extends globalvar.BasicDataSource { }
class ExtendDataItem extends globalvar2.Data.DataItem { }
}

View File

@ -13,46 +13,47 @@
* limitations under the License.
*/
import { doSomething } from './service'
import * as util from '../utils'
import { doSomething } from './service';
import * as util from '../utils';
class Data {
constructor(x, y) {
this.x = x;
this.y = y;
}
constructor(x, y) {
this.x = x;
this.y = y;
}
Add(o) {
this.x = o.x;
this.y = o.y;
}
Add(o) {
this.x = o.x;
this.y = o.y;
}
}
function foo(o1, o2) {
var a = 0;
let c = new Data(1, 2);
if (o1 > o2) {
c.Add(o1);
a = o2;
return c;
} else if (o1 < o2) {
c.Add(o2);
a = o1;
} else {
a = o1 + o2;
c.Add(new Data(1, 2));
}
let a = 0;
let c = new Data(1, 2);
if (o1 > o2) {
c.Add(o1);
a = o2;
return c;
} else if (o1 < o2) {
c.Add(o2);
a = o1;
} else {
a = o1 + o2;
c.Add(new Data(1, 2));
}
let func1 = function (o) {
function func2(o1, o2) {
console.log(o1, o2);
}
let bar = func2;
bar(c, o);
return c;
let func1 = function (o) {
function func2(o1, o2) {
console.log(o1, o2);
}
let res = func1();
let bar = func2;
bar(c, o);
return c;
};
let res = func1();
doSomething(a);
return util.sum(res, o2);
doSomething(a);
return util.sum(res, o2);
}

View File

@ -13,43 +13,44 @@
* limitations under the License.
*/
// default import
import var1 from './mod1'
import var1 from './mod1';
let a = var1;
// namespace import
import * as ns from './mod2'
import * as ns from './mod2';
ns.add(2);
// regular import
import { var3 } from '../mod3'
import { var3 } from '../mod3';
a = var3;
// rename import
import { var4 as local_var4 } from '../../mod4'
a = local_var4;
import { var4 as localVar4 } from '../../mod4';
a = localVar4;
// export variable
export var var5
var var6 = 100
export { var6 }
export let var5;
let var6 = 100;
export { var6 };
// export class
class InnerUserInput {
getTextBase() { }
getTextBase() { }
}
class UserInput extends InnerUserInput {
getText() { }
getText() { }
}
export { UserInput as UInput }
export { UserInput as UInput };
// export function
function func3() { }
export { func3 as exFunc3 }
export { func3 as exFunc3 };
export default function func1() { }
export function func2() { }
// indirect export
export { v5 as v } from './mod5'
export * from './mod6'
export { foo } from '../../mod7'
export { v5 as v } from './mod5';
export * from './mod6';
export { foo } from '../../mod7';

View File

@ -284,7 +284,6 @@ private:
bool operator()(IndexedItem *item1, IndexedItem *item2) const noexcept
{
auto index_type = item1->GetIndexType();
if (index_type == IndexType::CLASS) {
auto type_item1 = static_cast<TypeItem *>(item1);
auto type_item2 = static_cast<TypeItem *>(item2);