mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-11-23 10:09:54 +00:00
Add Type Infer Test Case
Description: 1.Add type infer test cases for bitwise_op, callfunctions, ldobjbyvalue and logic_op Issue: https://gitee.com/openharmony/ark_js_runtime/issues/I5B78L Signed-off-by: huoqingyi <huoqingyi@huawei.com> Change-Id: I486f6f91a32e1c7caa2446b12b8e6b33db8d47fe
This commit is contained in:
parent
471bc0ba6e
commit
6a99d6002d
@ -2202,7 +2202,7 @@ void BytecodeCircuitBuilder::NewReturn(BytecodeRegion &bb, const uint8_t *pc, Ga
|
||||
auto gate = circuit_.NewGate(OpCode(OpCode::RETURN), 0,
|
||||
{ state, depend, Circuit::NullGate(),
|
||||
Circuit::GetCircuitRoot(OpCode(OpCode::RETURN_LIST)) },
|
||||
GateType::Empty());
|
||||
GateType::AnyType());
|
||||
jsgateToBytecode_[gate] = {bb.id, pc};
|
||||
} else if (static_cast<EcmaOpcode>(bytecodeInfo.opcode) == EcmaOpcode::RETURNUNDEFINED_PREF) {
|
||||
// handle returnundefined bytecode
|
||||
@ -2213,7 +2213,7 @@ void BytecodeCircuitBuilder::NewReturn(BytecodeRegion &bb, const uint8_t *pc, Ga
|
||||
auto gate = circuit_.NewGate(OpCode(OpCode::RETURN), 0,
|
||||
{ state, depend, constant,
|
||||
Circuit::GetCircuitRoot(OpCode(OpCode::RETURN_LIST)) },
|
||||
GateType::Empty());
|
||||
GateType::AnyType());
|
||||
jsgateToBytecode_[gate] = {bb.id, pc};
|
||||
}
|
||||
}
|
||||
|
@ -24,4 +24,59 @@ bool Type::IsBitset() const
|
||||
}
|
||||
|
||||
Type::~Type() {}
|
||||
|
||||
std::string GateType::GetTypeStr() const
|
||||
{
|
||||
GlobalTSTypeRef gt = GlobalTSTypeRef(GetType());
|
||||
ASSERT(gt.GetFlag() == 0);
|
||||
if (IsPrimitiveTypeKind()) {
|
||||
auto primitive = static_cast<TSPrimitiveType>(gt.GetLocalId());
|
||||
switch (primitive) {
|
||||
case TSPrimitiveType::ANY:
|
||||
return "any";
|
||||
case TSPrimitiveType::NUMBER:
|
||||
return "number";
|
||||
case TSPrimitiveType::BOOLEAN:
|
||||
return "boolean";
|
||||
case TSPrimitiveType::VOID_TYPE:
|
||||
return "void";
|
||||
case TSPrimitiveType::STRING:
|
||||
return "string";
|
||||
case TSPrimitiveType::SYMBOL:
|
||||
return "symbol";
|
||||
case TSPrimitiveType::NULL_TYPE:
|
||||
return "null";
|
||||
case TSPrimitiveType::UNDEFINED:
|
||||
return "undefined";
|
||||
case TSPrimitiveType::INT:
|
||||
return "int";
|
||||
case TSPrimitiveType::BIG_INT:
|
||||
return "big_int";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
auto typeKind = static_cast<TSTypeKind>(gt.GetKind());
|
||||
switch (typeKind) {
|
||||
case TSTypeKind::CLASS:
|
||||
return "class";
|
||||
case TSTypeKind::CLASS_INSTANCE:
|
||||
return "class_instance";
|
||||
case TSTypeKind::FUNCTION:
|
||||
return "function";
|
||||
case TSTypeKind::UNION:
|
||||
return "union";
|
||||
case TSTypeKind::ARRAY:
|
||||
return "array";
|
||||
case TSTypeKind::OBJECT:
|
||||
return "object";
|
||||
case TSTypeKind::IMPORT:
|
||||
return "import";
|
||||
case TSTypeKind::INTERFACE_KIND:
|
||||
return "interface";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return "gatetype:" + std::to_string(gt.GetType());
|
||||
}
|
||||
}; // namespace panda::ecmascript::kungfu
|
@ -124,6 +124,13 @@ public:
|
||||
return GateType(TSPrimitiveType::BIG_INT);
|
||||
}
|
||||
|
||||
bool inline IsTSType() const
|
||||
{
|
||||
GlobalTSTypeRef gt = GlobalTSTypeRef(GetType());
|
||||
// 0: TS type
|
||||
return gt.GetFlag() == 0;
|
||||
}
|
||||
|
||||
bool inline IsAnyType() const
|
||||
{
|
||||
return type_ == static_cast<uint32_t>(TSPrimitiveType::ANY);
|
||||
@ -267,6 +274,8 @@ public:
|
||||
return type_ >= other.type_;
|
||||
}
|
||||
|
||||
std::string GetTypeStr() const;
|
||||
|
||||
private:
|
||||
uint32_t type_ {0};
|
||||
};
|
||||
|
@ -65,13 +65,15 @@ void TypeInfer::TypeInferPrint() const
|
||||
const auto &gateList = circuit_->GetAllGates();
|
||||
std::string log("TestInfer:");
|
||||
for (const auto &gate : gateList) {
|
||||
auto op = gateAccessor_.GetOpCode(gate);
|
||||
if (op == OpCode::JS_BYTECODE) {
|
||||
log += "&" + builder_->GetBytecodeStr(gate) + ":";
|
||||
auto gateType = gateAccessor_.GetGateType(gate);
|
||||
auto type = gateType.GetType() > GlobalTSTypeRef::TS_TYPE_RESERVED_COUNT ? "INF"
|
||||
: std::to_string(gateType.GetType());
|
||||
log += type;
|
||||
auto type = gateAccessor_.GetGateType(gate);
|
||||
if (ShouldInfer(gate) && type.IsTSType() && !type.IsAnyType()) {
|
||||
auto op = gateAccessor_.GetOpCode(gate);
|
||||
if (op == OpCode::VALUE_SELECTOR) {
|
||||
log += "&" + op.Str() + ":";
|
||||
} else {
|
||||
log += "&" + builder_->GetBytecodeStr(gate) + ":";
|
||||
}
|
||||
log += type.GetTypeStr();
|
||||
}
|
||||
}
|
||||
COMPILER_LOG(INFO) << std::dec << log;
|
||||
@ -93,7 +95,7 @@ bool TypeInfer::UpdateType(GateRef gate, const GlobalTSTypeRef &typeRef)
|
||||
return UpdateType(gate, type);
|
||||
}
|
||||
|
||||
bool TypeInfer::ShouldInfer(const GateRef gate)
|
||||
bool TypeInfer::ShouldInfer(const GateRef gate) const
|
||||
{
|
||||
auto op = gateAccessor_.GetOpCode(gate);
|
||||
// handle phi gates
|
||||
@ -104,9 +106,9 @@ bool TypeInfer::ShouldInfer(const GateRef gate)
|
||||
op == OpCode::CONSTANT ||
|
||||
op == OpCode::RETURN) {
|
||||
auto gateToBytecode = builder_->GetGateToBytecode();
|
||||
// handle gates generated by ecma.* bytecodes
|
||||
// handle gates generated by ecma.* bytecodes (not including Jump)
|
||||
if (gateToBytecode.find(gate) != gateToBytecode.end()) {
|
||||
return true;
|
||||
return !builder_->GetByteCodeInfo(gate).IsJump();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -40,7 +40,7 @@ public:
|
||||
private:
|
||||
bool UpdateType(GateRef gate, const GateType type);
|
||||
bool UpdateType(GateRef gate, const GlobalTSTypeRef &typeRef);
|
||||
bool ShouldInfer(const GateRef gate);
|
||||
bool ShouldInfer(const GateRef gate) const;
|
||||
bool Infer(GateRef gate);
|
||||
bool InferPhiGate(GateRef gate);
|
||||
bool SetNumberType(GateRef gate);
|
||||
|
@ -113,7 +113,7 @@ def judge_output(args):
|
||||
if "TestInfer:" in item:
|
||||
err_list.append(item.split("&")[1:])
|
||||
expect_output = expect_output.replace('\n', '')
|
||||
expect_list = [elements.split(",") for elements in expect_output.split("[")]
|
||||
expect_list = [elements.split(",") for elements in expect_output.split("----")]
|
||||
for obj1, obj2 in zip(err_list, expect_list):
|
||||
if not isSubSequence(obj1, obj2):
|
||||
print(">>>>> Expect :", end = " ")
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Copyright (c) 2022 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
|
||||
@ -13,5 +13,16 @@
|
||||
|
||||
group("ark_typeinfer_test") {
|
||||
testonly = true
|
||||
deps = [ "ldobjbyname:ldobjbynameAotTypeInferAction" ]
|
||||
deps = [
|
||||
"bitwise_op:bitwise_opAotTypeInferAction",
|
||||
"callarg0dyn:callarg0dynAotTypeInferAction",
|
||||
"callarg1dyn:callarg1dynAotTypeInferAction",
|
||||
"callargs2dyn:callargs2dynAotTypeInferAction",
|
||||
"callargs3dyn:callargs3dynAotTypeInferAction",
|
||||
"callirangedyn:callirangedynAotTypeInferAction",
|
||||
"callithisrange:callithisrangeAotTypeInferAction",
|
||||
"ldobjbyname:ldobjbynameAotTypeInferAction",
|
||||
"ldobjbyvalue:ldobjbyvalueAotTypeInferAction",
|
||||
"logic_op:logic_opAotTypeInferAction",
|
||||
]
|
||||
}
|
||||
|
18
test/typeinfer/bitwise_op/BUILD.gn
Normal file
18
test/typeinfer/bitwise_op/BUILD.gn
Normal file
@ -0,0 +1,18 @@
|
||||
# Copyright (c) 2022 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.
|
||||
|
||||
import("//ark/js_runtime/test/test_helper.gni")
|
||||
|
||||
host_typeinfer_test_action("bitwise_op") {
|
||||
deps = []
|
||||
}
|
39
test/typeinfer/bitwise_op/bitwise_op.ts
Normal file
39
test/typeinfer/bitwise_op/bitwise_op.ts
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 x:number = 123;
|
||||
let y:number = 2;
|
||||
let andRes = x & y;
|
||||
typeof(andRes);
|
||||
|
||||
let orRes = x | y;
|
||||
typeof(orRes);
|
||||
|
||||
let xorRes = x ^ y;
|
||||
typeof(xorRes);
|
||||
|
||||
let shlRes = x << y;
|
||||
typeof(shlRes);
|
||||
|
||||
let ashrRes = x >> y;
|
||||
typeof(ashrRes);
|
||||
|
||||
let shrRes = x >>> y;
|
||||
typeof(shrRes);
|
||||
|
||||
let notRes = ~x;
|
||||
typeof(notRes);
|
||||
}
|
19
test/typeinfer/bitwise_op/expect_output.txt
Normal file
19
test/typeinfer/bitwise_op/expect_output.txt
Normal file
@ -0,0 +1,19 @@
|
||||
# Copyright (c) 2022 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.
|
||||
|
||||
AND2DYN:number,
|
||||
OR2DYN:number,
|
||||
XOR2DYN:number,
|
||||
SHL2DYN:number,
|
||||
ASHR2DYN:number,
|
||||
SHR2DYN:number
|
18
test/typeinfer/callarg0dyn/BUILD.gn
Normal file
18
test/typeinfer/callarg0dyn/BUILD.gn
Normal file
@ -0,0 +1,18 @@
|
||||
# Copyright (c) 2022 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.
|
||||
|
||||
import("//ark/js_runtime/test/test_helper.gni")
|
||||
|
||||
host_typeinfer_test_action("callarg0dyn") {
|
||||
deps = []
|
||||
}
|
22
test/typeinfer/callarg0dyn/callarg0dyn.ts
Normal file
22
test/typeinfer/callarg0dyn/callarg0dyn.ts
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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.
|
||||
*/
|
||||
|
||||
{
|
||||
function foo():string
|
||||
{
|
||||
return "pass";
|
||||
}
|
||||
typeof(foo());
|
||||
}
|
14
test/typeinfer/callarg0dyn/expect_output.txt
Normal file
14
test/typeinfer/callarg0dyn/expect_output.txt
Normal file
@ -0,0 +1,14 @@
|
||||
# Copyright (c) 2022 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.
|
||||
|
||||
CALLARG0DYN:string
|
18
test/typeinfer/callarg1dyn/BUILD.gn
Normal file
18
test/typeinfer/callarg1dyn/BUILD.gn
Normal file
@ -0,0 +1,18 @@
|
||||
# Copyright (c) 2022 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.
|
||||
|
||||
import("//ark/js_runtime/test/test_helper.gni")
|
||||
|
||||
host_typeinfer_test_action("callarg1dyn") {
|
||||
deps = []
|
||||
}
|
22
test/typeinfer/callarg1dyn/callarg1dyn.ts
Normal file
22
test/typeinfer/callarg1dyn/callarg1dyn.ts
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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.
|
||||
*/
|
||||
|
||||
{
|
||||
function foo(v:number):number
|
||||
{
|
||||
return v + 1;
|
||||
}
|
||||
typeof(foo(0));
|
||||
}
|
14
test/typeinfer/callarg1dyn/expect_output.txt
Normal file
14
test/typeinfer/callarg1dyn/expect_output.txt
Normal file
@ -0,0 +1,14 @@
|
||||
# Copyright (c) 2022 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.
|
||||
|
||||
CALLARG1DYN:number
|
18
test/typeinfer/callargs2dyn/BUILD.gn
Normal file
18
test/typeinfer/callargs2dyn/BUILD.gn
Normal file
@ -0,0 +1,18 @@
|
||||
# Copyright (c) 2022 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.
|
||||
|
||||
import("//ark/js_runtime/test/test_helper.gni")
|
||||
|
||||
host_typeinfer_test_action("callargs2dyn") {
|
||||
deps = []
|
||||
}
|
22
test/typeinfer/callargs2dyn/callargs2dyn.ts
Normal file
22
test/typeinfer/callargs2dyn/callargs2dyn.ts
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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.
|
||||
*/
|
||||
|
||||
{
|
||||
function foo(flag1:boolean, flag2:boolean):boolean
|
||||
{
|
||||
return flag1 && flag2;
|
||||
}
|
||||
typeof(foo(true, false));
|
||||
}
|
14
test/typeinfer/callargs2dyn/expect_output.txt
Normal file
14
test/typeinfer/callargs2dyn/expect_output.txt
Normal file
@ -0,0 +1,14 @@
|
||||
# Copyright (c) 2022 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.
|
||||
|
||||
CALLARGS2DYN:boolean
|
18
test/typeinfer/callargs3dyn/BUILD.gn
Normal file
18
test/typeinfer/callargs3dyn/BUILD.gn
Normal file
@ -0,0 +1,18 @@
|
||||
# Copyright (c) 2022 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.
|
||||
|
||||
import("//ark/js_runtime/test/test_helper.gni")
|
||||
|
||||
host_typeinfer_test_action("callargs3dyn") {
|
||||
deps = []
|
||||
}
|
23
test/typeinfer/callargs3dyn/callargs3dyn.ts
Normal file
23
test/typeinfer/callargs3dyn/callargs3dyn.ts
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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.
|
||||
*/
|
||||
|
||||
{
|
||||
function foo(v1:number, v2:number, v3:number):number[]
|
||||
{
|
||||
let arr:number[] = [v1, v2, v3];
|
||||
return arr;
|
||||
}
|
||||
typeof(foo(0, 1, 2));
|
||||
}
|
14
test/typeinfer/callargs3dyn/expect_output.txt
Normal file
14
test/typeinfer/callargs3dyn/expect_output.txt
Normal file
@ -0,0 +1,14 @@
|
||||
# Copyright (c) 2022 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.
|
||||
|
||||
CALLARGS3DYN:array
|
18
test/typeinfer/callirangedyn/BUILD.gn
Normal file
18
test/typeinfer/callirangedyn/BUILD.gn
Normal file
@ -0,0 +1,18 @@
|
||||
# Copyright (c) 2022 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.
|
||||
|
||||
import("//ark/js_runtime/test/test_helper.gni")
|
||||
|
||||
host_typeinfer_test_action("callirangedyn") {
|
||||
deps = []
|
||||
}
|
35
test/typeinfer/callirangedyn/callirangedyn.ts
Normal file
35
test/typeinfer/callirangedyn/callirangedyn.ts
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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.
|
||||
*/
|
||||
|
||||
{
|
||||
class A {
|
||||
v1:number;
|
||||
v2:string;
|
||||
v3:boolean;
|
||||
v4:number;
|
||||
constructor(v1:number, v2:string, v3:boolean, v4:number) {
|
||||
this.v1 = v1;
|
||||
this.v2 = v2;
|
||||
this.v3 = v3;
|
||||
this.v4 = v4;
|
||||
}
|
||||
}
|
||||
function foo(v1:number, v2:string, v3:boolean, v4:number):A
|
||||
{
|
||||
let a = new A(v1, v2, v3, v4);
|
||||
return a;
|
||||
}
|
||||
typeof(foo(0, "1", true, 3));
|
||||
}
|
14
test/typeinfer/callirangedyn/expect_output.txt
Normal file
14
test/typeinfer/callirangedyn/expect_output.txt
Normal file
@ -0,0 +1,14 @@
|
||||
# Copyright (c) 2022 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.
|
||||
|
||||
CALLIRANGEDYN:class_instance
|
18
test/typeinfer/callithisrange/BUILD.gn
Normal file
18
test/typeinfer/callithisrange/BUILD.gn
Normal file
@ -0,0 +1,18 @@
|
||||
# Copyright (c) 2022 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.
|
||||
|
||||
import("//ark/js_runtime/test/test_helper.gni")
|
||||
|
||||
host_typeinfer_test_action("callithisrange") {
|
||||
deps = []
|
||||
}
|
40
test/typeinfer/callithisrange/callithisrange.ts
Normal file
40
test/typeinfer/callithisrange/callithisrange.ts
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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.
|
||||
*/
|
||||
|
||||
{
|
||||
class A {
|
||||
v:number;
|
||||
constructor(v:number) {
|
||||
this.v = v;
|
||||
}
|
||||
fun(value:number):number {
|
||||
return this.v + value;
|
||||
}
|
||||
fun1():void {
|
||||
this.v += 1;
|
||||
}
|
||||
fun2():string {
|
||||
return "hello";
|
||||
}
|
||||
fun3():boolean {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
let a = new A(1);
|
||||
typeof(a.fun(2));
|
||||
typeof(a.fun1());
|
||||
typeof(a.fun2());
|
||||
typeof(a.fun3());
|
||||
}
|
17
test/typeinfer/callithisrange/expect_output.txt
Normal file
17
test/typeinfer/callithisrange/expect_output.txt
Normal file
@ -0,0 +1,17 @@
|
||||
# Copyright (c) 2022 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.
|
||||
|
||||
CALLITHISRANGEDYN:number,
|
||||
CALLITHISRANGEDYN:void,
|
||||
CALLITHISRANGEDYN:string,
|
||||
CALLITHISRANGEDYN:boolean
|
@ -11,5 +11,4 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
LDLEXENVDYN:0,LDA_STR:4,DEFINECLASSWITHBUFFER:INF,LDA_STR:4,LDOBJBYNAME:4,TYPEOFDYN:4
|
||||
[LDLEXENVDYN:0
|
||||
LDOBJBYNAME:string
|
||||
|
18
test/typeinfer/ldobjbyvalue/BUILD.gn
Normal file
18
test/typeinfer/ldobjbyvalue/BUILD.gn
Normal file
@ -0,0 +1,18 @@
|
||||
# Copyright (c) 2022 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.
|
||||
|
||||
import("//ark/js_runtime/test/test_helper.gni")
|
||||
|
||||
host_typeinfer_test_action("ldobjbyvalue") {
|
||||
deps = []
|
||||
}
|
16
test/typeinfer/ldobjbyvalue/expect_output.txt
Normal file
16
test/typeinfer/ldobjbyvalue/expect_output.txt
Normal file
@ -0,0 +1,16 @@
|
||||
# Copyright (c) 2022 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.
|
||||
|
||||
LDOBJBYVALUE:string,
|
||||
LDOBJBYVALUE:number,
|
||||
LDOBJBYVALUE:boolean
|
24
test/typeinfer/ldobjbyvalue/ldobjbyvalue.ts
Normal file
24
test/typeinfer/ldobjbyvalue/ldobjbyvalue.ts
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 arr1:string[] = ["a", "b", "c"];
|
||||
let arr2:number[] = [1, 2, 3, 4];
|
||||
let arr3:boolean[] = [true, false, false];
|
||||
let t = 1;
|
||||
typeof(arr1[t]);
|
||||
typeof(arr2[t]);
|
||||
typeof(arr3[t]);
|
||||
}
|
18
test/typeinfer/logic_op/BUILD.gn
Normal file
18
test/typeinfer/logic_op/BUILD.gn
Normal file
@ -0,0 +1,18 @@
|
||||
# Copyright (c) 2022 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.
|
||||
|
||||
import("//ark/js_runtime/test/test_helper.gni")
|
||||
|
||||
host_typeinfer_test_action("logic_op") {
|
||||
deps = []
|
||||
}
|
21
test/typeinfer/logic_op/expect_output.txt
Normal file
21
test/typeinfer/logic_op/expect_output.txt
Normal file
@ -0,0 +1,21 @@
|
||||
# Copyright (c) 2022 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.
|
||||
|
||||
GREATEREQDYN:boolean,
|
||||
GREATERDYN:boolean,
|
||||
LESSDYN:boolean,
|
||||
LESSEQDYN:boolean,
|
||||
EQDYN:boolean,
|
||||
NOTEQDYN:boolean,
|
||||
STRICTEQDYN:boolean,
|
||||
STRICTNOTEQDYN:boolean
|
27
test/typeinfer/logic_op/logic_op.ts
Normal file
27
test/typeinfer/logic_op/logic_op.ts
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 num1:number = 1;
|
||||
let num2:number = 2;
|
||||
typeof(num1 >= num2);
|
||||
typeof(num1 > num2);
|
||||
typeof(num1 < num2);
|
||||
typeof(num1 <= num2);
|
||||
typeof(num1 == num2);
|
||||
typeof(num1 != num2);
|
||||
typeof(num1 === num2);
|
||||
typeof(num1 !== num2);
|
||||
}
|
Loading…
Reference in New Issue
Block a user